ReceiptApi.java
5.65 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
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.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.IReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptModel;
import com.huaheng.pc.receipt.receiptHeader.service.IReceiptHeaderService;
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;
/**
* 入库下发和入传接口
* @author huaheng
* @date 2018-12-20
*
*
*
*/
import java.util.List;
@RestController
@RequestMapping("/api/receipt")
@Api(tags = {"receipt"}, description = "入库接口")
public class ReceiptApi extends BaseController {
@Autowired
private IDictDataService dictDataService;
@Autowired
private IReceiptHeaderService receiptHeaderService;
@Autowired
private IReceiptDetailService receiptDetailService;
@Autowired
private IMaterialService materialService;
@Log(title = "入库单下发", action = BusinessType.INSERT)
@PostMapping("/insertReceipt")
@ResponseBody
public AjaxResult insertReceipt(ReceiptModel receiptModel){
if(receiptModel==null){
return AjaxResult.error("参数不对");
}
ReceiptHeader receiptHeader=receiptModel.getReceiptHeader();
List<ReceiptDetail> receiptDetails=receiptModel.getReceiptDetails();
if(receiptHeader==null || receiptDetails==null){
return AjaxResult.error("入库主单或入库子单有问题");
}
if(dictDataService.checkConfig("receiptType", receiptHeader.getType()) == false)
{
return AjaxResult.error("没有对应的入库单类型");
}
Integer result = receiptHeaderService.insert(receiptHeader);
if(result<1){
return AjaxResult.error("新增主单失败");
}
for(ReceiptDetail item :receiptDetails){
ReceiptHeader receiptHeaderB=receiptHeaderService.selectEntityById(item.getReceiptId());
if(!receiptHeader.equals(receiptHeaderB)){
return AjaxResult.error("主子单据不匹配");
}
if (receiptHeader.getFirstStatus() > 100) {
//表示已经加入了波次
return AjaxResult.error("主单据状态不允许新增明细");
}
Material material = new Material();
material.setCode(item.getMaterialCode());
material.setWarehouseId(item.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(receiptDetailService.insert(item) > 0){
//更新表头的总行数和总数量统计
receiptHeader.setTotalQty(receiptHeader.getTotalQty().add(item.getQty()));
receiptHeader.setTotalLines(receiptHeader.getTotalLines() + 1);
receiptHeaderService.updateByModel(receiptHeader);
}
else {
return AjaxResult.error("新增单据明细失败");
}
}
return AjaxResult.success("入库单据下发成功");
}
//出库单回传
@Log(title = "入库单回传", action = BusinessType.INSERT)
@PostMapping("/shipmentAssign")
@ResponseBody
public AjaxResult shipmentAssign(String url)
{
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setLastStatus((short)300);
receiptHeader = receiptHeaderService.selectFirstEntity(receiptHeader);
if (receiptHeader == null) {
return AjaxResult.error("入库回传主单不存在");
}
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setReceiptCode(receiptHeader.getCode());
List<ReceiptDetail> receiptDetails = receiptDetailService.selectListEntityByEqual(receiptDetail);
if (receiptDetails == null) {
return AjaxResult.error("入库回传子单不存在");
}
ReceiptModel model=new ReceiptModel();
model.setReceiptHeader(receiptHeader);
model.setReceiptDetails(receiptDetails);
String JsonParam = JSON.toJSONString(model);
String result = HttpUtils.sendPost(url, JsonParam);
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
receiptHeader.setFirstStatus((short)900);
receiptHeader.setLastStatus((short)900);
receiptHeaderService.updateByModel(receiptHeader);
return ajaxResult;
}
}