ShipmentApi.java
6.02 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
package com.huaheng.api.Common;
import com.alibaba.fastjson.JSON;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
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.pc.general.company.service.ICompanyService;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.IShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentModel;
import com.huaheng.pc.shipment.shipmentHeader.service.IShipmentHeaderService;
import com.huaheng.pc.system.dict.service.IDictDataService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
* 出库下发和回传接口
* @author huaheng
* @date 2018-12-18
*
*
*
*/
@RestController
@RequestMapping("/api/shipment")
@Api(tags = {"shipment"}, description = "出库接口")
public class ShipmentApi extends BaseController {
@Autowired
private IDictDataService dictDataService;
@Autowired
IShipmentDetailService shipmentDetailService;
@Autowired
ICompanyService companyService;
@Autowired
IShipmentHeaderService shipmentHeaderService;
@Autowired
private IMaterialService materialService;
//出库单下发
@Log(title = "出库单下发", action = BusinessType.INSERT)
@PostMapping("/insertShipment")
@ResponseBody
public AjaxResult insertShipment(ShipmentModel shipmentModel){
if(shipmentModel==null){
return AjaxResult.error("参数不对");
}
ShipmentHeader shipmentHeader=new ShipmentHeader();
List<ShipmentDetail> shipmentDetails=new ArrayList<>();
try {
shipmentHeader=shipmentModel.getShipmentHeader();
shipmentDetails=shipmentModel.getShipmentDetails();
}catch (Exception e){
return AjaxResult.error("出库主单或出库子单有问题");
}
if(dictDataService.checkConfig("shipmentType", shipmentHeader.getType()) == false)
{
return AjaxResult.error("没有对应的出库单类型");
}
int result = shipmentHeaderService.insert(shipmentHeader);
if(result<1){
return AjaxResult.error("新增主单失败");
}
//添加细表到shipmentDetail
for(ShipmentDetail shipmentDetail : shipmentDetails) {
ShipmentHeader shipmentHeaderB = shipmentHeaderService.selectEntityById(shipmentDetail.getShipmentId());
if (!shipmentHeaderB.equals(shipmentHeader)) {
return AjaxResult.error("找不到主单据");
}
if (shipmentHeaderB.getFirstStatus() > 100) {
//表示已经加入了波次
return AjaxResult.error("主单据状态不允许新增明细");
}
Material material = new Material();
material.setCode(shipmentDetail.getMaterialCode());
material.setWarehouseId(shipmentDetail.getWarehouseId());
material = materialService.selectFirstEntity(material);
if (material == null) {
return AjaxResult.error("物料未找到");
}
if (StringUtils.isNotEmpty(material.getCompanyCode()) &&
ShiroUtils.getCompanyCodeList().contains(material.getCompanyCode()) == false)
{
return AjaxResult.error("物料不属于当前货主!");
}
if (shipmentDetailService.insert(shipmentDetail) > 0){
//更新单据总行数与总数量
shipmentHeader.setTotalLines(shipmentHeader.getTotalLines() + 1);
shipmentHeader.setTotalQty(shipmentHeader.getTotalQty().add(shipmentDetail.getQty()));
shipmentHeaderService.updateByModel(shipmentHeader);
}
else {
return AjaxResult.error("新增单据明细失败");
}
}
return AjaxResult.success("出库单下发成功");
}
//出库单回传
@Log(title = "出库单回传", action = BusinessType.INSERT)
@PostMapping("/shipmentAssign")
@ResponseBody
public AjaxResult shipmentAssign(String url)
{
ShipmentHeader shipmentHeader = new ShipmentHeader();
shipmentHeader.setLastStatus(300);
shipmentHeader = shipmentHeaderService.selectFirstEntity(shipmentHeader);
if (shipmentHeader == null) {
return AjaxResult.error("出库回传主单不存在");
}
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail.setShipmentCode(shipmentHeader.getCode());
List<ShipmentDetail> shipmentDetails = shipmentDetailService.selectListEntityByEqual(shipmentDetail);
if (shipmentDetails == null) {
return AjaxResult.error("出库回传子单不存在");
}
ShipmentModel model=new ShipmentModel();
model.setShipmentHeader(shipmentHeader);
model.setShipmentDetails(shipmentDetails);
String JsonParam = JSON.toJSONString(model);
String result = HttpUtils.sendPost(url, JsonParam);
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
shipmentHeader.setFirstStatus(900);
shipmentHeader.setLastStatus(900);
shipmentHeaderService.updateByModel(shipmentHeader);
return ajaxResult;
}
}