OrderConfirmService.java
10 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
package com.huaheng.api.SSP.service;
import com.huaheng.api.SSP.domain.*;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.pc.SSP.domain.SSPdetail;
import com.huaheng.pc.SSP.domain.SSPheader;
import com.huaheng.pc.SSP.mapper.SSPdetailMapperAuto;
import com.huaheng.pc.SSP.mapper.SSPheaderMapperAuto;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.receipt.receiptDetail.service.IReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.service.IReceiptHeaderService;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class OrderConfirmService {
@Resource
private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;
@Autowired
IReceiptDetailService detailService;
@Autowired
IReceiptHeaderService headerService;
@Resource
private SSPheaderMapperAuto ssPheaderMapperAuto;
@Resource
private SSPdetailMapperAuto ssPdetailMapperAuto;
//订单回传
public AjaxResult ocfm(ConfirmModel cfm) {
ConfirmHeaderModel headerModel = cfm.getConfirmHeaderModel();
List<ConfirmTypeModel> typeModels = cfm.getOrderItems();
if (headerModel == null||typeModels == null){
return AjaxResult.error("订单头表为空或订单明细表为空!");
}if (headerModel.getCubeCode()==null||headerModel.getCubeCode()==""){
return AjaxResult.error("钱柜编码不能为空!");
}if (headerModel.getId()==null||headerModel.getId()==""){
return AjaxResult.error("钱柜系统主表标识不能为空!");
}if (headerModel.getOrderHeaderId()<1){
return AjaxResult.error("订单头表标识不能为空!");
}if (headerModel.getOrderCode()==null||headerModel.getOrderCode()==""){
return AjaxResult.error("订单编码不能为空!");
}if (!headerModel.getOrderType().equals("receipt")&&!headerModel.getOrderType().equals("shipment")){
return AjaxResult.error("订单类型错误!");
}if (headerModel.getfDatetime()==null||headerModel.getcDatetime()==""){
return AjaxResult.error("完成的时间不能为空!");
}if (headerModel.getcDatetime()==null||headerModel.getcDatetime()==""){
return AjaxResult.error("交互的当前时间不能为空!");
}
String wc = headerModel.getWarehouseCode();
if (wc==null||wc==""){
return AjaxResult.error("warehouseCode不能为空!!");
}
WarehouseCompany warehouseCompany = new WarehouseCompany();
warehouseCompany.setWarehouseCode(wc);
List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
if (list == null || list.size() == 0) {
return AjaxResult.error("系统中没有该仓库:" + warehouseCompany.toString() + " 信息,请先录入仓库信息!");
}
SSPheader ssPheader = new SSPheader();
ssPheader.setWarehouseCode(headerModel.getWarehouseCode());
ssPheader.setCubeCode(headerModel.getCubeCode());
ssPheader.sethID(headerModel.getId());
ssPheader.setOrderHeaderId(headerModel.getOrderHeaderId());
ssPheader.setOrderCode(headerModel.getOrderCode());
ssPheader.setOrderType(headerModel.getOrderType());
ssPheader.setfDatetime(headerModel.getfDatetime());
ssPheader.setcDatetime(headerModel.getcDatetime());
if (ssPheader.getOrderType().equals("receipt")){
return receipt(ssPheader,typeModels);
}else {
return shipment(ssPheader,typeModels);
}
}
private AjaxResult receipt(SSPheader chm,List<ConfirmTypeModel> ctmlist){
for (ConfirmTypeModel ctm : ctmlist){
if (ctm.getItemId()==null||ctm.getItemId()==""){
return AjaxResult.error("钱柜系统明细标识不能为空!");
}if (ctm.getOrderDetailId()<1){
return AjaxResult.error("订单明细表标识不能为空!");
}if (ctm.getCompanyCode()==null||ctm.getCompanyCode()==""){
return AjaxResult.error("货主编码不能为空!");
}if (ctm.getContainerCode()==null||ctm.getContainerCode()==""){
return AjaxResult.error("容器编码不能为空!");
}if (ctm.getItemCode()==null||ctm.getItemCode()==""){
return AjaxResult.error("商品编码不能为空!");
}if (ctm.getItemBarcode()==null||ctm.getItemBarcode()=="") {
return AjaxResult.error("商品条码不能为空!");
}
SSPheader sh = new SSPheader();
sh.sethID(chm.gethID());
sh.setOrderHeaderId(chm.getOrderHeaderId());
sh.setOrderType(chm.getOrderType());
//组合入库子单
SSPdetail sd = new SSPdetail();
sd.setItemId(ctm.getItemId());
sd.setOrderDetailId(ctm.getOrderDetailId());
sd.setOrderHeaderId(chm.getOrderHeaderId());
sd.setCompanyCode(ctm.getCompanyCode());
sd.setContainerCode(ctm.getContainerCode());
sd.setItemCode(ctm.getItemCode());
sd.setItemName(ctm.getItemName());
sd.setItemBarcode(ctm.getItemBarcode());
sd.setItemState(ctm.getItemState());
sd.setQty(ctm.getQty());
sd.setItemUnit(ctm.getItemUnit());
sd.setOrderType("receipt");
//判断系统中是否已有该主单
try {
if (ssPheaderMapperAuto.selectListEntityByEqual(sh).size()<1){
ssPheaderMapperAuto.insert(chm);
ssPdetailMapperAuto.insert(sd);
}else {
SSPdetail sd1 = new SSPdetail();
sd1.setOrderDetailId(ctm.getOrderDetailId());
sd1.setOrderHeaderId(chm.getOrderHeaderId());
//判断系统中是否已有该子单
if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size() < 1) {
ssPdetailMapperAuto.insert(sd);
} else {
sd1.setItemId(ctm.getItemId());
sd1.setOrderType("receipt");
//如果有,再判断该子单是否是多次回传,以及是否是入库子单
if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size() < 1) {
ssPdetailMapperAuto.insert(sd);
}
}
}
}catch (Exception e){
throw new ServiceException("入库主单或子单新增失败!");
}
}
return AjaxResult.setResultCS(0,"入库单回传成功");
}
private AjaxResult shipment(SSPheader chm,List<ConfirmTypeModel> ctmlist){
for (ConfirmTypeModel ctm : ctmlist){
if (ctm.getItemId()==null||ctm.getItemId()==""){
return AjaxResult.error("钱柜系统明细标识不能为空!");
}if (ctm.getOrderDetailId()<1){
return AjaxResult.error("订单明细表标识不能为空!");
}if (ctm.getCompanyCode()==null||ctm.getCompanyCode()==""){
return AjaxResult.error("货主编码不能为空!");
}if (ctm.getContainerCode()==null||ctm.getContainerCode()==""){
return AjaxResult.error("容器编码不能为空!");
}if (ctm.getItemCode()==null||ctm.getItemCode()==""){
return AjaxResult.error("商品编码不能为空!");
}if (ctm.getItemBarcode()==null||ctm.getItemBarcode()=="") {
return AjaxResult.error("商品条码不能为空!");
}
SSPheader sh = new SSPheader();
sh.sethID(chm.gethID());
sh.setOrderHeaderId(chm.getOrderHeaderId());
sh.setOrderType(chm.getOrderType());
//组合入库子单
SSPdetail sd = new SSPdetail();
sd.setItemId(ctm.getItemId());
sd.setOrderDetailId(ctm.getOrderDetailId());
sd.setOrderHeaderId(chm.getOrderHeaderId());
sd.setCompanyCode(ctm.getCompanyCode());
sd.setContainerCode(ctm.getContainerCode());
sd.setItemCode(ctm.getItemCode());
sd.setItemName(ctm.getItemName());
sd.setItemBarcode(ctm.getItemBarcode());
sd.setItemState(ctm.getItemState());
sd.setQty(ctm.getQty());
sd.setItemUnit(ctm.getItemUnit());
sd.setOrderType("shipment");
//判断系统中是否已有该主单
try {
if (ssPheaderMapperAuto.selectListEntityByEqual(sh).size()<1){
ssPheaderMapperAuto.insert(chm);
ssPdetailMapperAuto.insert(sd);
}else {
SSPdetail sd1 = new SSPdetail();
sd1.setOrderDetailId(ctm.getOrderDetailId());
sd1.setOrderHeaderId(chm.getOrderHeaderId());
//判断系统中是否已有该子单
if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size()<1){
ssPdetailMapperAuto.insert(sd);
}else {
sd1.setItemId(ctm.getItemId());
sd1.setOrderType("shipment");
//如果有,再判断该子单是否是多次回传,以及是否是出库子单
if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size()<1) {
ssPdetailMapperAuto.insert(sd);
}
}
}
}catch (Exception e){
throw new ServiceException("出库主单或出库子单新增失败!");
}
}
return AjaxResult.setResultCS(0,"出库单回传成功");
}
}