CreateShipment.java
4.63 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
package com.huaheng.api.mts;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
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.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.shipment.lockingWorkOrder.domain.LockingWorkOrder;
import com.huaheng.pc.shipment.lockingWorkOrder.service.LockingWorkOrderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/API/MMS/create_shipment")
@Api(tags = {"mms"}, description = "mms接口")
public class CreateShipment extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(CreateShipment.class);
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private LockingWorkOrderService lockingWorkOrderService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Log(title = "mms创建备料出库单", action = BusinessType.INSERT)
@PostMapping("/createPreparationShipment")
@ApiOperation("mms创建出库单")
@ResponseBody
@ApiLogger(apiName = "mms创建手持出库单", from = "mms")
public AjaxResult createPreparationShipment(@RequestBody List<LockingWorkOrder> list)
{
logger.info("MMS发送数据:{}", list);
if (list.isEmpty()){
return AjaxResult.error("请勿传送空数据!");
}
// 创建出库单头表
ShipmentHeader header = null;
List<ShipmentDetail> details = new ArrayList<>();
for (LockingWorkOrder temp : list){
// LockingWorkOrder lockingWorkOrder = lockingWorkOrderService.selectEntitysById(temp );
// if (lockingWorkOrder == null){
// return AjaxResult.error("该"+temp.getId()+"数据未锁定工作令、请先锁定工作令在创建出库单!");
// }
// if (StringUtils.isEmpty(lockingWorkOrder.getWorkOrder()) ||
// StringUtils.isEmpty(lockingWorkOrder.getBomCode()) ||
// StringUtils.isEmpty(lockingWorkOrder.getInventoryId())){
// return AjaxResult.error("物料编码:"+lockingWorkOrder.getBomCode()+"、工作令:"+lockingWorkOrder.getWorkOrder()+"、库存id:"+lockingWorkOrder.getInventoryId()+"不能为空值!");
// }
// Inventory inventory = iInventoryService.selectEntityById(Integer.valueOf(lockingWorkOrder.getInventoryId()));
// if (inventory == null){
// return AjaxResult.error("查询不到绑定的库存!");
// }
// BigDecimal lockingNum = lockingWorkOrder.getLockingNum();
// BigDecimal qty = inventory.getQty().subtract(inventory.getTaskQty());
// // 判断库存数量是否大于锁定数量
// if (qty.compareTo(lockingNum) >= 0){
// 判断头表是否存在不存在创建
if (header == null){
header = shipmentHeaderService.createShipmentHeader(temp);
}
// 创建出库单详情
try {
ShipmentDetail detail = shipmentDetailService.createShipmentDetail(header, temp);
if (detail != null){
details.add(detail);
}
}catch (Exception e){
logger.error(e.getMessage());
return AjaxResult.error(e.getMessage());
}
// // }else {
// logger.error("库存数量:"+qty+"小于锁定数量:"+lockingNum+",无法创建出库单!");
// return AjaxResult.error("库存数量:"+qty+"小于锁定数量:"+lockingNum+",无法创建出库单!");
// }
}
if (details != null){
details.forEach(item->{
shipmentDetailService.save(item);
});
}
return AjaxResult.success("创建成功!");
}
}