ShippingCombinationController.java
18.6 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
package com.huaheng.pc.shipment.shippingCombination.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.BusinessException;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.config.warehouse.domain.WarehouseU8;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailServiceImpl;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentContainerAdvice.service.ShipmentAdviceService;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
import com.huaheng.pc.task.taskHeader.service.ShipmentTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/shipment/shippingCombination")
public class ShippingCombinationController extends BaseController {
private String prefix = "shipment/shippingCombination";
@Resource
ShipmentDetailServiceImpl shipmentDetailService;
@Resource
ShippingCombinationService shippingCombinationService;
@Resource
ShipmentContainerHeaderService shipmentContainerHeaderService;
@Resource
ShipmentHeaderService shipmentHeaderService;
@Resource
private WarehouseU8Service warehouseU8Service;
@Resource
private ShipmentAdviceService shipmentAdviceService;
/**
* 打开出库组盘页面
*
* @param shipmentCode
* @param map
* @return
*/
@RequiresPermissions("shipment:shippingCombination:view")
@GetMapping()
public String ShippingCombination(String shipmentCode, ModelMap map) {
map.put("code", shipmentCode);
if (ShiroUtils.getWarehouseCode().equals(QuantityConstant.WAREHOUSE_KS)) {
return prefix + "/shippingCombination-new";
}
return prefix + "/shippingCombination";
}
/**
* 打开出库组盘页面
*
* @param shipmentCode
* @param map
* @return
*/
@RequiresPermissions("shipment:shippingCombination:view")
@GetMapping("/shippingAdvice")
public String shippingAdvice(String shipmentCode, ModelMap map) {
map.put("code", shipmentCode);
return prefix + "/shippingAdvice";
}
/**
* 获取单据列表
*
* @param code
* @return
*/
@GetMapping("/listShipmentDetail")
@ResponseBody
public AjaxResult listShipmentDetail(String code) {
if (StringUtils.isEmpty(code)) {
return null;
}
LambdaQueryWrapper<ShipmentDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ShipmentDetail::getShipmentCode, code)
.in(ShipmentDetail::getCompanyCode, ShiroUtils.getCompanyCodeList())
.eq(ShipmentDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(lambdaQueryWrapper);
return AjaxResult.success(shipmentDetails);
}
/**
* 获取能出库的库存列表
*
* @param code,id
* @return
*/
@PostMapping("/getInventory")
@ResponseBody
public TableDataInfo getInventory(String code, Integer id) {
//找到主单
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
.eq(ShipmentHeader::getCode, code)
.eq(ShipmentHeader::getWarehouseCode, ShiroUtils.getWarehouseCode()));
if (shipmentHeader == null) {
throw new ServiceException("找不到主单");
}
//找到子单
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail = shipmentDetailService.getById(id);
if (shipmentDetail == null) {
throw new ServiceException("找不到子单");
}
List<InventoryDetail> list = shippingCombinationService.getInventorys(shipmentDetail,false);
if (list.isEmpty()) {
throw new ServiceException("该物料没有库存或没有符合出库规则的库存");
}
list.forEach(s -> {
if (!StringUtils.isAnyEmpty(s.getUWarehouseCode(), s.getWarehouseCode(), s.getCompanyCode())) {
WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
.eq(WarehouseU8::getUWarehouseCode, s.getUWarehouseCode())
.eq(WarehouseU8::getWarehouseCode, s.getWarehouseCode())
.eq(WarehouseU8::getCompanyCode, s.getCompanyCode())
.last("limit 1")
);
if (warehouseU8 != null) {
s.setUWarehouseName(warehouseU8.getUWarehouseName());
}
}
});
// List<InventoryDetail> removeList = new ArrayList<>();
// for(InventoryDetail item : list){
// item.setQty(item.getQty().subtract(item.getTaskQty()));
// //查询容器有无任务,返回任务头状态大于10的任务数
// Integer number = taskHeaderService.UncompleteCount(item.getContainerCode());
// if(number >= 1) {
// removeList.add(item);
// }
// }
// //查询所有小于上架完成的入库组盘头 (status<20)
// List<ReceiptContainerHeader> unCompleteCombineList = receiptContainerHeaderService.getUnCompleteCombineList();
// if(unCompleteCombineList != null && unCompleteCombineList.size() > 0) {
// for(ReceiptContainerHeader receiptContainerHeader : unCompleteCombineList) {
// String containerCode = receiptContainerHeader.getContainerCode();
// for(InventoryDetail item : list) {
// if(containerCode.equals(item.getContainerCode())) {
// if(!removeList.contains(item)) {
// removeList.add(item);
// }
// break;
// }
// }
// }
// }
// list.removeAll(removeList);
return getDataTable(list);
}
/**
* 保存组盘
*
* @param shipmentCombinationModel
* @return
*/
@RequiresPermissions("shipment:shippingCombination:combination")
@PostMapping("/addcombination")
@ResponseBody
public AjaxResult addcombination(ShipmentCombinationModel shipmentCombinationModel) {
String taskKey = "addcombination";
AjaxResult ajaxResult = handleMultiProcessV1(taskKey, new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
ShipmentContainerHeader shipmentContainerHeader =
shipmentContainerHeaderService.combination(shipmentCombinationModel);
ShipmentTaskCreateModel shipmentTask = new ShipmentTaskCreateModel();
shipmentTask.setShipmentContainerHeaderIds(shipmentContainerHeader.getId());
//表头
List<Integer> idList = Arrays.asList(Convert.toIntArray(shipmentContainerHeader.getId().toString()));
if (shipmentContainerHeader.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
return AjaxResult.success("OK!");
// return AjaxResult.error("出库货箱编码(" + shipmentContainerHeader.getContainerCode() + ")已经生成任务,请不要重复生成,操作中止");
}
shipmentContainerHeaderService.createTask(idList);
return AjaxResult.success(shipmentContainerHeader.getId());
}
});
return ajaxResult;
}
/**
* 自动组盘并生成任务
*
* @param shipmentCode
* @return
*/
@RequiresPermissions("shipment:shippingCombination:combination")
@PostMapping("/autoCombinationAndCreateTask")
@ResponseBody
public AjaxResult autoCombinationAndCreateTask(String shipmentCode) {
String taskKey = "autoCombinationAndCreateTask";
AjaxResult ajaxResult = handleMultiProcessV1(taskKey, new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = shipmentContainerHeaderService.autoCombination(shipmentCode,false,ShiroUtils.getWarehouseCode());
// System.out.println(ShiroUtils.getUserName());
LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeader = Wrappers.lambdaQuery();
shipmentContainerHeader.eq(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD);
shipmentContainerHeader.eq(ShipmentContainerHeader::getCreatedBy, ShiroUtils.getUserName());
List<ShipmentContainerHeader> shipmentContainerHeaders = shipmentContainerHeaderService.list(shipmentContainerHeader);
for (ShipmentContainerHeader item : shipmentContainerHeaders) {
// ShipmentTaskCreateModel shipmentTask = new ShipmentTaskCreateModel();
// shipmentTask.setShipmentContainerHeaderIds(item.getId());
// AjaxResult ajaxResults = shipmentTaskService.createTaskFromShipmentContainers(shipmentTask);
List<Integer> idList = Arrays.asList(Convert.toIntArray(item.getId().toString()));
AjaxResult ajaxResults = shipmentContainerHeaderService.createTask(idList);
if (ajaxResults.hasErr()) {
throw new ServiceException("任务生成失败:" + ajaxResults.getMsg());
}
}
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 自动组盘并生成任务
*
* @param shipmentCode
* @return
*/
@RequiresPermissions("shipment:shippingCombination:combination")
@PostMapping("/autoCombination")
@ResponseBody
public AjaxResult autoCombination(String shipmentCode) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
return shipmentContainerHeaderService.autoCombination(shipmentCode,false,ShiroUtils.getWarehouseCode());
}
});
return ajaxResult;
}
/**
* 取消组盘
*
* @param shipmentContainerDetailIds
* @return
*/
@RequiresPermissions("shipment:shippingCombination:remove")
@PostMapping("/cancelCombination")
@ResponseBody
public AjaxResult cancelCombination(@RequestBody List<Integer> shipmentContainerDetailIds) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
return shipmentContainerHeaderService.cancelCombinationDetail(shipmentContainerDetailIds);
}
});
return ajaxResult;
}
/**
* 获取出库组盘信息
*/
@ResponseBody
@PostMapping("/getShipmentInfoByCode")
@Log(title = "出库-获取出库组盘信息", operating = "获取出库组盘信息", action = BusinessType.OTHER)
public AjaxResult getShipmentInfoByCode(String code) {
AjaxResult result = shipmentContainerHeaderService.getShipmentInfoByCode(code);
return result;
}
/**
* 选择出库口
*/
@GetMapping("/chooseStation/{ids}")
public String chooseStation(@PathVariable("ids") String ids, ModelMap mmap) {
List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
List<Integer> idsList = idList.stream().distinct().collect(Collectors.toList());
ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(idsList.get(0));
String containerCode = shipmentContainerHeader.getContainerCode();
mmap.put("containerCode", containerCode);
mmap.put("id", ids);
int taskType = shipmentContainerHeader.getTaskType().intValue();
if (taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT ||
taskType == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT) {
mmap.put("type", QuantityConstant.STATION_OUT);
} else if (taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT ||
taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT ||
taskType == QuantityConstant.TASK_TYPE_VIEW ||
taskType == QuantityConstant.TASK_TYPE_CYCLECOUNT) {
mmap.put("type", QuantityConstant.STATION_PICK);
} else {
throw new ServiceException("任务类型不需要选站台");
}
return prefix + "/chooseStation";
}
@Log(title = "设置站台", operating = "设置站台", action = BusinessType.GRANT)
@PostMapping("/setStation")
@ResponseBody
public AjaxResult setStation(String ids, String type, String containerCode, String port) {
List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
List<Integer> idsList = idList.stream().distinct().collect(Collectors.toList());
for (Integer id : idsList) {
LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentContainerHeaderLambdaQueryWrapper.eq(ShipmentContainerHeader::getId, id);
ShipmentContainerHeader shipmentContainerHeader1 = shipmentContainerHeaderService.getOne(shipmentContainerHeaderLambdaQueryWrapper);
shipmentContainerHeader1.setPort(port);
shipmentContainerHeaderService.update(shipmentContainerHeader1, shipmentContainerHeaderLambdaQueryWrapper);
}
return createTask(ids);
}
/**
* 生成任务
*/
@RequiresPermissions("shipment:container:add")
@Log(title = "出库-任务生成", operating = "批量生成任务", action = BusinessType.UPDATE)
@PostMapping("/createTask")
@ResponseBody
public AjaxResult createTask(String ids) {
AjaxResult ajaxResult = new AjaxResult();
if (StringUtils.isEmpty(ids)) {
return AjaxResult.error("id不能为空");
}
List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
for (Integer id : idList) {
//获取表头
ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(id);
if (shipmentContainerHeader == null) {
return AjaxResult.error("出库货箱id:" + id + "未找到,操作中止");
}
if (shipmentContainerHeader.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
// return AjaxResult.error("出库货箱编码(" + shipmentContainerHeader.getContainerCode() + ")已经生成任务,请不要重复生成,操作中止");
}
}
AjaxResult ajaxResult1 = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = shipmentContainerHeaderService.createTask(idList);
return ajaxResult;
}
});
return ajaxResult1;
}
/**
* 出库预配盘
* @return
*/
@ApiOperation(value = "自动预配盘出库", notes = "自动预配盘出库")
@RequiresPermissions("shipment:shippingCombination:view")
@PostMapping("/autoShipmentAdvice")
@ResponseBody
public AjaxResult autoShipmentAdvice(ShipmentHeader shipmentHeader) {
String warehouseCode=shipmentHeader.getWarehouseCode();
Integer shipmentId=shipmentHeader.getId();
AjaxResult ajaxResult1 = handleMultiProcessV1("autoCombinationAndCreateTask",new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = shipmentAdviceService.autoShipmentAdvice(shipmentId,warehouseCode);
return ajaxResult;
}
});
return ajaxResult1;
}
/**
* 出库预配盘:pda扫sn出库
* @return
*/
@ApiOperation(value = "根据序列号扣减预配盘的库存", notes = "根据序列号扣减预配盘的库存")
@RequiresPermissions("shipment:shippingCombination:view")
@PostMapping("/reduceInventoryDetailBySn")
@ResponseBody
public AjaxResult reduceInventoryDetailBySn( @RequestBody ShipmentHeader shipmentHeader) {
if (ShiroUtils.getUser() == null || StringUtils.isEmpty(ShiroUtils.getWarehouseCode())) {
throw new BusinessException("请登录仓库账号!");
}
String warehouseCode=ShiroUtils.getWarehouseCode();
String snList=shipmentHeader.getSnList();
if(StringUtils.isEmpty(snList)){
return AjaxResult.error("序列号不能为空");
}
AjaxResult ajaxResult1 = handleMultiProcessV1("reduceInventoryDetailBySn",new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = shipmentAdviceService.reduceInventoryDetailBySn(snList,warehouseCode);
return ajaxResult;
}
});
return ajaxResult1;
}
}