ContainerServiceImpl.java
5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.huaheng.pc.config.container.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.exception.BusinessException;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.container.domain.ContainerStatus;
import com.huaheng.pc.config.location.domain.Location;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.mapper.ContainerMapper;
@Service
public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container> implements ContainerService{
@Resource
private ContainerTypeService containerTypeService;
@Resource
private ContainerMapper containerMapper;
@Override
public AjaxResult<List<Container>> insertContainer(String type, Integer quantity) {
List<Container> containerList = new ArrayList<>();
Integer number = getNumber(type);
for(int i=0; i<quantity; i++) {
number++;
Container container = new Container();
container.setContainerType(type);
container.setCode(String.format("%s%05d", type, number));
container.setStatus(ContainerStatus.empty.name());
container.setCreated(new Date());
container.setCreatedBy(ShiroUtils.getLoginName());
container.setLastUpdated(null);
container.setLastUpdatedBy(null);
container.setEnable(0);
container.setDeleted(false);
container.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
container.setWarehouseCode(ShiroUtils.getWarehouseCode());
this.save(container);
containerList.add(container);
}
return AjaxResult.success(containerList);
}
private Integer getNumber(String type) {
if (!containerTypeService.checkConfig(type))
throw new ServiceException("容器类型编码不存在");
LambdaQueryWrapper<Container> lambda = Wrappers.lambdaQuery();
lambda.select(Container::getCode).eq(Container::getContainerType, type)
.orderByDesc(Container::getId).last("Limit 1");
Container container = containerMapper.selectOne(lambda);
//如果指定类型的最后的code存在,那么 code = 容器类型 + (排序号 + 1)
if (container.getCode() != null) {
Integer number = Integer.valueOf(container.getCode().substring(container.getCode().length() - 5, container.getCode().length()));
return number;
} else {
return 0;
}
}
public String importMaterial(List<Container> containerList, Boolean updateSupport, String operName){
if (StringUtils.isNull(containerList) || containerList.size() == 0) {
throw new BusinessException("导入数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (Container container : containerList) {
try {
LambdaQueryWrapper<Container> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Container::getCode, container.getCode());
// 验证是否存在这个容器
Container m = this.getOne(lambdaQueryWrapper);
if (StringUtils.isNull(m)) {
System.out.println(ShiroUtils.getLoginName());
container.setCreatedBy(ShiroUtils.getUser().getLoginName());
container.setLastUpdatedBy(ShiroUtils.getLoginName());
this.save(container);
successNum++;
successMsg.append("<br/>" + successNum + "、编码 " + container.getCode() + " 导入成功");
} else {
String msg = "<br/>" + failureNum + "、编码" + container.getCode() + " 已存在:";
failureMsg.append(msg);
log.error(msg);
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、编码" + container.getCode() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
log.error(msg, e);
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new BusinessException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
/**
* 已入空容器展示
* */
@Override
public List<Location> getEmptyContainerInLocation(String containerCode, String locationCode, String warehouseCode) {
return containerMapper.getEmptyContainerInLocation(containerCode,locationCode,warehouseCode);
}
/**
* 修改容器库位和状态
* */
@Override
public void updateLocationCodeAndStatus(String containerCode, String locationCode, String status) {
if (StringUtils.isNotEmpty(containerCode) || StringUtils.isNotEmpty(locationCode))
containerMapper.updateLocationCodeAndStatus(ShiroUtils.getWarehouseCode(), containerCode, locationCode, status);
}
}