OrderAssignApiService.java
14.5 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
package com.huaheng.api.SSP.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huaheng.api.SSP.domain.ConfirmHeaderModel;
import com.huaheng.api.SSP.domain.ConfirmModel;
import com.huaheng.api.SSP.domain.ConfirmTypeModel;
import com.huaheng.api.U8.domain.ICSReceiptHeader;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
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.inventory.inventory.domain.Inventory;
import com.huaheng.pc.inventory.inventory.service.IInventoryService;
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.service.IReceiptHeaderService;
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.service.IShipmentHeaderService;
import net.bytebuddy.implementation.bytecode.Throw;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/** 出入库单下发Service
*
* 1. 此Service的作用是将系统中未被钱柜扫描过的出入库单据发送给钱柜,目前考虑到系统资源,一次只能查询或发送一条单据,发送规则是根据子单的库区是否为钱柜
* 进行发送,发送成功后会将子单的状态改为100,若主单内的所有子单都不属于钱柜库区,则将不进行发送,但是无论发送与否,都会对主单的扫描标识进行修改,目前钱柜
* 的标识是1,若主单据的扫描标识的第一位为1则代表此单据被钱柜扫描过。1`
*
* 2. 目前此Service出入库单的下发逻辑是先扫描入库单据,若入库单据已全部下发成功,将自动扫描出库单据。
*
* 3. 目前钱柜编码写死为QG,默认为库区编码为QG的物料为钱柜的物料。
*/
@Transactional
@Service
public class OrderAssignApiService {
@Autowired
IReceiptHeaderService iReceiptHeaderService;
@Autowired
IReceiptDetailService iReceiptDetailService;
@Autowired
IShipmentHeaderService iShipmentHeaderService;
@Autowired
IShipmentDetailService iShipmentDetailService;
@Autowired
IMaterialService iMaterialService;
@Autowired
ItemDownloadApiService itemDownloadApiService;
@Autowired
IInventoryService inventoryService;
//private static String address="http://172.16.30.238:4322/api/SSP/";
@Transactional
public AjaxResult receiptAssign(String code){
//查询出一条未被钱柜扫描过的入库单
AjaxResult ajaxResult=new AjaxResult();
ReceiptHeader item = iReceiptHeaderService.selectNosScanSSP(code);
ConfirmHeaderModel cfh = new ConfirmHeaderModel();
cfh.setOrderHeaderId(item.getId());
cfh.setOrderCode(item.getCode());
cfh.setOrderType("receipt");
cfh.setWarehouseCode(item.getWarehouseCode());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cfh.setcDatetime(df.format(new Date()));
ConfirmModel confirmModel = new ConfirmModel();
// confirmModel.setConfirmHeaderModel(cfh);
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setReceiptId(item.getId());
receiptDetail.setZoneCode("QG");
List<ReceiptDetail> details = iReceiptDetailService.selectListEntityByEqual(receiptDetail);
List<ConfirmTypeModel> typeModels = new ArrayList<>();
//遍历入库子单
int i = 0;
List<Integer> list = new ArrayList();
for (ReceiptDetail ds:details){
Material material = new Material();
material.setCode(ds.getMaterialCode());
material=iMaterialService.selectFirstEntity(material);
if (material != null ) {
if(StringUtils.isEmpty(material.getZoneCode())){
material.setZoneCode("QG");
if(!itemDownloadApiService.sendMaterial(material).hasErr()){
// iMaterialService.updateByModel(material);
}else {
throw new ServiceException(material.getCode()+"物料同步失败");
}
}
if(StringUtils.isNotEmpty(material.getZoneCode()) && !material.getZoneCode().equals("QG") ){
if(itemDownloadApiService.sendMaterial(material).hasErr()){
throw new ServiceException(material.getCode()+"物料同步失败");
}
}
ConfirmTypeModel cft = new ConfirmTypeModel();
cft.setOrderDetailId(ds.getId());
cft.setCompanyCode(ds.getCompanyCode());
Inventory inventory=new Inventory();
inventory.setZoneCode("QG");
inventory.setWarehouseCode(ShiroUtils.getWarehouseCode());
inventory.setMaterialCode(material.getCode());
inventory=inventoryService.selectFirstEntity(inventory);
if(inventory!=null){
cft.setContainerCode(inventory.getContainerCode());
}else {
cft.setContainerCode("0");
}
cft.setItemCode(ds.getMaterialCode());
cft.setItemName(material.getName());
cft.setItemBarcode(material.getCode());
cft.setItemState("良品");
float a = Convert.toFloat(ds.getQty());
cft.setQty(a);
cft.setItemUnit(material.getMasterUnit());
typeModels.add(cft);
list.add(ds.getId());
i++;
}
}
//若此单据无钱柜物料 则修改状态
ReceiptHeader receiptHeaderOver = new ReceiptHeader();
receiptHeaderOver.setId(item.getId());
if (i < 1){
StringBuffer str = new StringBuffer();
str.append(item.getScanid());
str.replace(0, 1, "1");
receiptHeaderOver.setScanid(String.valueOf(str));
iReceiptHeaderService.updateByModel(receiptHeaderOver);
return AjaxResult.success("已扫描一条入单据,没有发现钱柜物料");
}else {
//此处将入库主单,入库子单整合成发送给钱柜的的实体
cfh.setCubeCode("QG");
confirmModel.setConfirmHeaderModel(cfh);
confirmModel.setOrderItems(typeModels);
try {
String url=itemDownloadApiService.getQGUrl()+"OrderAssign";
String JsonParam = JSON.toJSONString(confirmModel);
String result = HttpUtils.bodypost(url, JsonParam);
if(StringUtils.isEmpty(result)){
throw new ServiceException("接口地址错误");
}
ajaxResult = JSON.parseObject(result, AjaxResult.class);
if(ajaxResult.code==200) {
//修改已经下发的子单状态
short statusover = 100;
ReceiptDetail detail = new ReceiptDetail();
for (int j = 0; j < list.size(); j++) {
detail.setId(list.get(j));
detail.setStatus(statusover);
iReceiptDetailService.updateByModel(detail);
}
StringBuffer str = new StringBuffer();
str.append(item.getScanid());
str.replace(0, 1, "1");
receiptHeaderOver.setScanid(String.valueOf(str));
if (iReceiptHeaderService.updateByModel(receiptHeaderOver) < 1) {
throw new ServiceException("入库订单状态更新失败!");
}
}
} catch (Exception e) {
throw new ServiceException("入库订单下发发送失败!");
}
return ajaxResult;
}
}
@Transactional
public AjaxResult shipmentAssign(ShipmentHeader item,List<ShipmentDetail> shipmentDetails) {
//查询出一条未被钱柜扫描过的出库单
AjaxResult ajaxResult=new AjaxResult();
ConfirmHeaderModel cfh = new ConfirmHeaderModel();
cfh.setOrderHeaderId(item.getId());
cfh.setOrderCode(item.getCode());
cfh.setOrderType("shipment");
cfh.setWarehouseCode(item.getWarehouseCode());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cfh.setcDatetime(df.format(new Date()));
ConfirmModel confirmModel = new ConfirmModel();
// confirmModel.setConfirmHeaderModel(cfh);
List<ConfirmTypeModel> typeModels = new ArrayList<>();
//遍历出库子单
int i = 0;
List<Integer> list = new ArrayList();
for (ShipmentDetail ds : shipmentDetails) {
if(ds.getStatus()==0) {
Material material = new Material();
material.setCode(ds.getMaterialCode());
material = iMaterialService.selectFirstEntity(material);
if (material != null) {
if (StringUtils.isEmpty(material.getZoneCode())) {
material.setZoneCode("QG");
if (!itemDownloadApiService.sendMaterial(material).hasErr()) {
// iMaterialService.updateByModel(material);
} else {
throw new ServiceException(material.getCode() + "物料同步失败");
}
}
if (StringUtils.isNotEmpty(material.getZoneCode()) && !material.getZoneCode().equals("QG")) {
if (itemDownloadApiService.sendMaterial(material).hasErr()) {
throw new ServiceException(material.getCode() + "物料同步失败");
}
}
ConfirmTypeModel cft = new ConfirmTypeModel();
Inventory inventory = new Inventory();
inventory.setZoneCode("QG");
inventory.setWarehouseCode(ShiroUtils.getWarehouseCode());
inventory.setMaterialCode(material.getCode());
inventory = inventoryService.selectFirstEntity(inventory);
if (inventory == null) {
throw new ServiceException("该物料没有库存");
} else {
cft.setContainerCode(inventory.getContainerCode());
}
cft.setOrderDetailId(ds.getId());
cft.setCompanyCode(ds.getCompanyCode());
cft.setItemCode(ds.getMaterialCode());
cft.setItemName(material.getName());
cft.setItemBarcode(material.getCode());
cft.setItemState("良品");
float a = Convert.toFloat(ds.getQty());
cft.setQty(a);
cft.setItemUnit(material.getMasterUnit());
typeModels.add(cft);
list.add(ds.getId());
i++;
}
}
}
//若此单据无钱柜物料 则修改状态
// ShipmentHeader shipmentHeaderOver = new ShipmentHeader();
// shipmentHeaderOver.setId(item.getId());
if (i < 1) {
// StringBuffer str = new StringBuffer();
// str.append(item.getScanid());
// str.replace(0, 1, "1");
// shipmentHeaderOver.setScanid(String.valueOf(str));
// iShipmentHeaderService.updateByModel(shipmentHeaderOver);
return AjaxResult.success("选中的子单都已下发过");
} else {
//此处将出库主单,出库子单整合成发送给钱柜的的实体
cfh.setCubeCode("QG");
confirmModel.setConfirmHeaderModel(cfh);
confirmModel.setOrderItems(typeModels);
try {
String url = itemDownloadApiService.getQGUrl()+"OrderAssign";
String JsonParam = JSON.toJSONString(confirmModel);
String result = HttpUtils.bodypost(url, JsonParam);
if(StringUtils.isEmpty(result)){
throw new ServiceException("接口地址错误");
}
ajaxResult = JSON.parseObject(result, AjaxResult.class);
if (ajaxResult.code == 200) {
//修改已经下发的子单状态
short statusover = 100;
ShipmentDetail detail = new ShipmentDetail();
for (int j = 0; j < list.size(); j++) {
detail.setId(list.get(j));
detail.setStatus(statusover);
iShipmentDetailService.updateByModel(detail);
}
//如果该主单据的所有钱柜子单都已下发,则改变该主单的状态
ShipmentDetail dt=new ShipmentDetail();
dt.setShipmentCode(item.getCode());
dt.setZoneCode("QG");
dt.setStatus((short)0);
List<ShipmentDetail> details=iShipmentDetailService.selectListEntityByEqual(dt);
if(details==null) {
StringBuffer str = new StringBuffer();
str.append(item.getScanid());
str.replace(0, 1, "1");
item.setScanid(String.valueOf(str));
if (iShipmentHeaderService.updateByModel(item) < 1) {
throw new ServiceException("出库单据状态更新失败");
}
}
}
} catch (Exception e) {
throw new ServiceException("出库订单发送失败!");
}
}
return ajaxResult;
}
}