|
1
|
package com.huaheng.pc.config.container.service;
|
|
2
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
import com.huaheng.common.utils.Wrappers;
|
huhai
authored
|
5
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
6
|
import com.huaheng.common.constant.QuantityConstant;
|
|
7
|
import com.huaheng.common.exception.BusinessException;
|
|
8
|
import com.huaheng.common.exception.service.ServiceException;
|
|
9
|
import com.huaheng.common.utils.StringUtils;
|
|
10
11
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
huhai
authored
|
12
|
import com.huaheng.pc.config.container.domain.Container;
|
|
13
|
import com.huaheng.pc.config.container.domain.ContainerStatus;
|
huhai
authored
|
14
15
|
import com.huaheng.pc.config.container.mapper.ContainerMapper;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
|
|
16
|
import com.huaheng.pc.config.location.domain.Location;
|
|
17
18
19
|
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
|
|
20
|
import org.springframework.stereotype.Service;
|
huhai
authored
|
21
22
|
import org.springframework.transaction.annotation.Transactional;
|
|
23
24
25
26
|
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
|
|
27
|
|
|
28
29
30
31
32
33
34
|
@Service
public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container> implements ContainerService{
@Resource
private ContainerTypeService containerTypeService;
@Resource
private ContainerMapper containerMapper;
|
|
35
36
37
38
|
@Resource
private LocationService locationService;
@Resource
private TaskHeaderService taskHeaderService;
|
|
39
40
41
42
|
@Override
public AjaxResult<List<Container>> insertContainer(String type, Integer quantity) {
List<Container> containerList = new ArrayList<>();
|
|
43
|
List<Container> containers =new ArrayList<>();
|
|
44
45
46
47
48
49
50
51
52
53
54
|
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);
|
|
55
|
container.setEnable(true);
|
huhai
authored
|
56
|
//container.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
|
|
57
|
container.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
58
59
60
61
62
|
containers.add(container);
if( i>0 && (i%1000==0 || i == quantity-1)){
containerMapper.addList(containers);
containers = new ArrayList<>();
}
|
|
63
|
}
|
|
64
|
return AjaxResult.success(containers);
|
|
65
66
67
|
}
private Integer getNumber(String type) {
|
|
68
|
if (!containerTypeService.checkConfig(type)) {
|
|
69
|
throw new ServiceException("容器类型编码不存在");
|
|
70
|
}
|
|
71
72
|
LambdaQueryWrapper<Container> lambda = Wrappers.lambdaQuery();
lambda.select(Container::getCode).eq(Container::getContainerType, type)
|
|
73
74
|
.eq(Container::getWarehouseCode, ShiroUtils.getWarehouseCode())
.orderByDesc(Container::getId).last("Limit 1");
|
|
75
|
Container container = containerMapper.selectOne(lambda);
|
|
76
77
|
//如果指定类型的最后的code存在,那么 code = 容器类型 + (排序号 + 1)
|
|
78
|
if (container != null && container.getCode() != null) {
|
|
79
|
Integer number = Integer.valueOf(container.getCode().substring(container.getCode().length() - 5, container.getCode().length()));
|
|
80
81
82
83
84
|
return number;
} else {
return 0;
}
}
|
|
85
|
|
|
86
|
@Override
|
huhai
authored
|
87
|
public String importContainer(List<Container> containerList, Boolean updateSupport, String operName){
|
|
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
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)) {
|
|
103
|
// System.out.println(ShiroUtils.getLoginName());
|
|
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
|
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();
}
|
|
129
130
131
132
133
|
/**
* 已入空容器展示
* */
@Override
|
|
134
135
|
public List<Location> getEmptyContainerInLocation(String zoneCode, String containerCode, String locationCode, String warehouseCode) {
return containerMapper.getEmptyContainerInLocation(zoneCode, containerCode,locationCode,warehouseCode);
|
|
136
137
|
}
|
|
138
139
140
141
142
|
/**
* 修改容器库位和状态
* */
@Override
public void updateLocationCodeAndStatus(String containerCode, String locationCode, String status) {
|
|
143
|
if (StringUtils.isNotEmpty(containerCode) || StringUtils.isNotEmpty(locationCode)) {
|
|
144
|
containerMapper.updateLocationCodeAndStatus(ShiroUtils.getWarehouseCode(), containerCode, locationCode, status);
|
|
145
|
}
|
|
146
147
|
}
|
|
148
149
|
@Override
public void updateLocationCodeAndStatus(String containerCode, String locationCode, String status, String warehouseCode) {
|
|
150
151
152
|
if (StringUtils.isNotEmpty(containerCode) || StringUtils.isNotEmpty(locationCode)) {
containerMapper.updateLocationCodeAndStatus(warehouseCode, containerCode, locationCode, status);
}
|
|
153
154
155
156
|
}
@Override
public boolean updateStatus(String containerCode, String status, String warehouseCode) {
|
|
157
|
LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
158
159
|
containerLambdaQueryWrapper.eq(Container::getCode, containerCode)
.eq(Container::getWarehouseCode, warehouseCode);
|
|
160
|
Container container = getOne(containerLambdaQueryWrapper);
|
|
161
|
container.setStatus(status);
|
|
162
163
164
165
|
boolean result = update(container, containerLambdaQueryWrapper);
return result;
}
|
|
166
167
168
169
170
171
|
/**
* 如果为临时容器,在取消组盘和出库任务完成时删除容器
* @param containerType 容器类型
* @param containerCode 容器编码
* @return
*/
|
|
172
|
@Override
|
|
173
174
175
176
177
178
179
180
181
182
183
|
@Transactional
public void removeContainer(String containerType, String containerCode) {
if ("LS".equals(containerType)) {
LambdaQueryWrapper<Container> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Container::getCode,containerCode);
if (!this.remove(lambdaQueryWrapper)){
throw new ServiceException("删除临时容器失败");
}
}
}
|
|
184
|
@Override
|
|
185
|
public Container getContainerByCode(String code) {
|
|
186
|
return containerMapper.findAllByCode(code, ShiroUtils.getWarehouseCode());
|
|
187
|
}
|
|
188
|
|
|
189
190
191
192
193
|
@Override
public Container getContainerByCode(String containCode, String warehouseCode) {
return containerMapper.findAllByCode(containCode, warehouseCode);
}
|
|
194
195
196
197
198
|
@Override
public List<Container> selectListShelf() {
return containerMapper.selectListShelf();
}
|
|
199
200
201
202
203
|
@Override
public Container emptyContainer() {
return containerMapper.emptyContainer();
}
|
|
204
|
}
|