|
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
|
import com.huaheng.pc.config.container.mapper.ContainerMapper;
|
|
15
|
import com.huaheng.pc.config.containerType.domain.ContainerType;
|
huhai
authored
|
16
|
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
|
|
17
|
import com.huaheng.pc.config.location.domain.Location;
|
|
18
|
import com.huaheng.pc.config.location.service.LocationService;
|
|
19
20
|
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
|
|
21
|
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerView;
|
|
22
23
|
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
|
|
24
|
import org.springframework.stereotype.Service;
|
huhai
authored
|
25
26
|
import org.springframework.transaction.annotation.Transactional;
|
|
27
28
29
30
|
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
|
|
31
|
|
|
32
33
34
35
36
37
38
|
@Service
public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container> implements ContainerService{
@Resource
private ContainerTypeService containerTypeService;
@Resource
private ContainerMapper containerMapper;
|
|
39
40
41
42
|
@Resource
private LocationService locationService;
@Resource
private TaskHeaderService taskHeaderService;
|
|
43
44
|
@Resource
private ZoneService zoneService;
|
|
45
46
47
|
@Override
public AjaxResult<List<Container>> insertContainer(String type, Integer quantity) {
|
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/**
* 获取容器类型
* 根据容器类型的库区获取库区
* 最后去库位编码
* */
String zoneCode = null;
ContainerType containerType = containerTypeService.getContainerTypeByCode(type, ShiroUtils.getWarehouseCode());
if(StringUtils.isNull(containerType)){
return AjaxResult.error(type + " 容器类型未找到");
}
Zone zone = zoneService.getZoneByArea(containerType.getArea());
if(StringUtils.isNull(zone)){
return AjaxResult.error("容器类型" + type +" 对应的库区编号:"+containerType.getArea()+"未找到");
}
zoneCode = zone.getCode();
|
|
65
|
List<Container> containerList = new ArrayList<>();
|
|
66
|
List<Container> containers =new ArrayList<>();
|
|
67
68
69
70
71
|
Integer number = getNumber(type);
for(int i=0; i<quantity; i++) {
number++;
Container container = new Container();
container.setContainerType(type);
|
|
72
|
container.setZoneCode(zoneCode);
|
周鸿
authored
|
73
|
container.setArea(zone.getArea());
|
|
74
75
76
77
78
79
|
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);
|
|
80
|
container.setEnable(true);
|
huhai
authored
|
81
|
//container.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
|
|
82
|
container.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
83
84
85
86
87
|
containers.add(container);
if( i>0 && (i%1000==0 || i == quantity-1)){
containerMapper.addList(containers);
containers = new ArrayList<>();
}
|
|
88
|
}
|
|
89
|
return AjaxResult.success(containers);
|
|
90
91
92
|
}
private Integer getNumber(String type) {
|
|
93
|
if (!containerTypeService.checkConfig(type)) {
|
|
94
|
throw new ServiceException("容器类型编码不存在");
|
|
95
|
}
|
|
96
97
|
LambdaQueryWrapper<Container> lambda = Wrappers.lambdaQuery();
lambda.select(Container::getCode).eq(Container::getContainerType, type)
|
|
98
99
|
.eq(Container::getWarehouseCode, ShiroUtils.getWarehouseCode())
.orderByDesc(Container::getId).last("Limit 1");
|
|
100
|
Container container = containerMapper.selectOne(lambda);
|
|
101
102
|
//如果指定类型的最后的code存在,那么 code = 容器类型 + (排序号 + 1)
|
|
103
|
if (container != null && container.getCode() != null) {
|
|
104
|
Integer number = Integer.valueOf(container.getCode().substring(container.getCode().length() - 5, container.getCode().length()));
|
|
105
106
107
108
109
|
return number;
} else {
return 0;
}
}
|
|
110
|
|
|
111
|
@Override
|
huhai
authored
|
112
|
public String importContainer(List<Container> containerList, Boolean updateSupport, String operName){
|
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
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)) {
|
|
128
|
// System.out.println(ShiroUtils.getLoginName());
|
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
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();
}
|
|
154
155
156
157
158
|
/**
* 已入空容器展示
* */
@Override
|
|
159
160
|
public List<Location> getEmptyContainerInLocation(String zoneCode, String containerCode, String locationCode,String locationType, String warehouseCode) {
return containerMapper.getEmptyContainerInLocation(zoneCode, containerCode,locationCode,locationType,warehouseCode);
|
|
161
162
|
}
|
|
163
164
165
166
167
|
/**
* 修改容器库位和状态
* */
@Override
public void updateLocationCodeAndStatus(String containerCode, String locationCode, String status) {
|
|
168
|
if (StringUtils.isNotEmpty(containerCode) || StringUtils.isNotEmpty(locationCode)) {
|
|
169
|
containerMapper.updateLocationCodeAndStatus(ShiroUtils.getWarehouseCode(), containerCode, locationCode, status);
|
|
170
|
}
|
|
171
172
|
}
|
|
173
174
|
@Override
public void updateLocationCodeAndStatus(String containerCode, String locationCode, String status, String warehouseCode) {
|
|
175
176
177
|
if (StringUtils.isNotEmpty(containerCode) || StringUtils.isNotEmpty(locationCode)) {
containerMapper.updateLocationCodeAndStatus(warehouseCode, containerCode, locationCode, status);
}
|
|
178
179
180
181
|
}
@Override
public boolean updateStatus(String containerCode, String status, String warehouseCode) {
|
|
182
|
LambdaQueryWrapper<Container> containerLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
183
184
|
containerLambdaQueryWrapper.eq(Container::getCode, containerCode)
.eq(Container::getWarehouseCode, warehouseCode);
|
|
185
|
Container container = getOne(containerLambdaQueryWrapper);
|
|
186
|
container.setStatus(status);
|
|
187
188
189
190
|
boolean result = update(container, containerLambdaQueryWrapper);
return result;
}
|
|
191
192
193
194
195
196
|
/**
* 如果为临时容器,在取消组盘和出库任务完成时删除容器
* @param containerType 容器类型
* @param containerCode 容器编码
* @return
*/
|
|
197
|
@Override
|
|
198
199
200
201
202
203
204
205
206
207
208
|
@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("删除临时容器失败");
}
}
}
|
|
209
|
@Override
|
|
210
|
public Container getContainerByCode(String code) {
|
|
211
|
return containerMapper.findAllByCode(code, ShiroUtils.getWarehouseCode());
|
|
212
|
}
|
|
213
|
|
|
214
215
216
217
218
|
@Override
public Container getContainerByCode(String containCode, String warehouseCode) {
return containerMapper.findAllByCode(containCode, warehouseCode);
}
|
|
219
|
@Override
|
|
220
|
public Container findContainerByCodeType(String containerCode, String containerType, String warehouseCode) {
|
|
221
222
|
Container one = this.getOne(new LambdaQueryWrapper<Container>()
.eq(Container::getCode, containerCode)
|
|
223
224
|
.eq(Container::getWarehouseCode, warehouseCode)
.eq(Container::getContainerType, containerType));
|
|
225
226
227
|
return one;
}
|
|
228
229
|
@Override
|
|
230
231
|
public List<Container> selectListShelf(String warehouseCode ) {
return containerMapper.selectListShelf(warehouseCode);
|
|
232
|
}
|
|
233
|
|
|
234
235
|
@Override
|
|
236
237
|
public Container emptyContainer(String warehouseCode ) {
return containerMapper.emptyContainer(warehouseCode);
|
|
238
|
}
|
|
239
240
241
242
243
244
|
@Override
public List<Container> selectEmptyList(Container container) {
return containerMapper.selectEmptyList(container);
}
@Override
|
|
245
246
247
248
249
250
251
252
253
254
|
public List<Container> selectListEntityByEqual(Container condition) {
LambdaQueryWrapper<Container> lambd = Wrappers.lambdaQuery();
lambd.eq(StringUtils.isNotEmpty(condition.getCode()),Container::getCode, condition.getCode())
.eq(StringUtils.isNotEmpty(condition.getWarehouseCode()),Container::getWarehouseCode, condition.getWarehouseCode())
.eq(StringUtils.isNotEmpty(condition.getGoodsShelfNo()),Container::getGoodsShelfNo, condition.getGoodsShelfNo())
.eq(StringUtils.isNotEmpty(condition.getContainerType()),Container::getContainerType, condition.getContainerType());
return this.list(lambd);
}
@Override
|
|
255
256
257
258
259
|
public Container selectFirstEntity(Container condition) {
LambdaQueryWrapper<Container> lambd = Wrappers.lambdaQuery();
lambd.eq(StringUtils.isNotEmpty(condition.getCode()),Container::getCode, condition.getCode())
.eq(StringUtils.isNotEmpty(condition.getWarehouseCode()),Container::getWarehouseCode, condition.getWarehouseCode())
.eq(StringUtils.isNotEmpty(condition.getContainerType()),Container::getContainerType, condition.getContainerType());
|
|
260
|
lambd.orderByDesc(Container::getCode);
|
|
261
262
263
264
|
lambd.last("limit 1");
return this.getOne(lambd);
}
|
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
@Override
public ReceiptContainerView check(ReceiptContainerView receiptContainerView, Container container) {
if(container.getContainerType().equals("M")) {
if(StringUtils.isEmpty(container.getLocationCode())) {
receiptContainerView.setTaskType((short) 100);
}else {
receiptContainerView.setTaskType((short) 200);
}
receiptContainerView.setZoneCode("LK");
}
if(container.getContainerType().equals("A")){
receiptContainerView.setZoneCode("AGV");
receiptContainerView.setTaskType((short) 200);
}
if(container.getContainerType().equals("D")){
receiptContainerView.setZoneCode("PK");
receiptContainerView.setTaskType((short) 200);
}
if(container.getContainerType().equals("Q")){
receiptContainerView.setZoneCode("QG");
receiptContainerView.setTaskType((short) 200);
}
if(container.getContainerType().equals("X")){
receiptContainerView.setZoneCode("XN");
receiptContainerView.setTaskType((short) 200);
}
return receiptContainerView;
}
|
|
294
295
296
297
298
299
300
301
302
303
|
@Override
public void updateContainerCommon(Integer[] ids,int status){
LambdaQueryWrapper<Container> lambd = Wrappers.lambdaQuery();
lambd.eq(Container::getWarehouseCode, ShiroUtils.getWarehouseCode())
.in(Container::getId, ids);
Container container=new Container();
container.setCommon(status);
this.update(container,lambd);
}
|
|
304
|
}
|