ICSReceiptAPIService.java
20 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
package com.huaheng.api.U8.Service;
import com.alibaba.fastjson.JSON;
import com.huaheng.api.U8.domain.*;
import com.huaheng.api.general.service.ReceiptAPIService;
import com.huaheng.common.exception.service.ServiceException;
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.company.service.ICompanyService;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.general.warehouse.domain.Warehouse;
import com.huaheng.pc.general.warehouse.service.IWarehouseService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* u8-wms入库下发或回传接口服务层
* @author huaheng
* @date 2019-1-4
*
*/
@Service
public class ICSReceiptAPIService {
@Autowired
private ICompanyService companyService;
@Autowired
private ICSReceiptHeaderService icsReceiptHeaderService;
@Autowired
private ICSReceiptDetailService icsReceiptDetailService;
@Autowired
private IMaterialService materialService;
@Autowired
private ReceiptAPIService receiptAPIservice;
@Autowired
private IReceiptHeaderService receiptHeaderService;
@Autowired
private IReceiptDetailService receiptDetailService;
@Autowired
private IWarehouseService warehouseService;
@Autowired
private ICSShipmentDetailService icsShipmentDetailService;
@Autowired
private ICSShipmentHeaderService icsShipmentHeaderService;
//入库单下发
@Transactional
public AjaxResult insertICSReceipt(@RequestBody ICSReceiptModel icsReceiptModel){
ICSReceiptHeader icsReceiptHeader=icsReceiptModel.getIcsReceiptHeader();
List<ICSReceiptDetail> icsReceiptDetails=icsReceiptModel.getIcsReceiptDetails();
//判断系统中有没有该货主
companyService.checkwarehouseCompany(icsReceiptHeader.getCompanyCode());
//将主表插入到新的接收主表里去
int result=icsReceiptHeaderService.insertModel(icsReceiptHeader);
if(result<1){
throw new ServiceException("入库主单传输失败!");
}
//将子表插入到新的接收子表里去
for(ICSReceiptDetail item : icsReceiptDetails){
if(icsReceiptHeader.getType().equals("TI")){
item.setcCode(icsReceiptHeader.getcTVCode());
}else {
item.setcCode(icsReceiptHeader.getcCode());
}
int result1=icsReceiptDetailService.insertModel(item);
if(result1<1){
throw new ServiceException("入库子单传输失败!");
}
}
//根据icsReceiptHeader生成receiptHeader
String type=icsReceiptHeader.getType();
ReceiptHeader receiptHeader=new ReceiptHeader();
if(!type.equals("PCI")){
String warehouseCode=null;
if(type.equals("TI")){
warehouseCode=icsReceiptHeader.getiWHCode();
}else if(type.equals("PI")){
warehouseCode="W0000";
}else {
warehouseCode=icsReceiptHeader.getcWHCode();
}
receiptHeader.setType(type);
receiptHeader.setId(null);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setCreatedBy(ShiroUtils.getLoginName());
receiptHeader.setSupplierCode(icsReceiptHeader.getcVenCode());
receiptHeader.setWarehouseCode(warehouseCode);
receiptHeader.setCompanyCode(icsReceiptHeader.getCompanyCode());
if (type.equals("TI")) {
receiptHeader.setSourceCode(icsReceiptHeader.getcTVCode());
}else {
receiptHeader.setSourceCode(icsReceiptHeader.getcCode());
}
if(StringUtils.isEmpty(receiptHeader.getSourceCode())){
throw new ServiceException("没有单号");
}
ReceiptHeader receiptHeaderB=new ReceiptHeader();
receiptHeaderB.setSourceCode(receiptHeader.getSourceCode());
if(receiptHeaderService.selectFirstEntity(receiptHeaderB)!=null){
throw new ServiceException("单号重复");
}
//根据icsShipmentDetail生成shipmentAetail
List<ReceiptDetail> receiptDetails=new ArrayList<ReceiptDetail>();
for(ICSReceiptDetail item : icsReceiptDetails) {
//查找物料
Warehouse warehouse=new Warehouse();
warehouse.setCode(item.getcWHCode());
if(warehouseService.selectFirstEntity(warehouse)==null){
throw new ServiceException("系统没有该仓库:"+item.getcWHCode());
}
//查找物料
Material material = new Material();
material.setCode(item.getcInvCode());
material.setWarehouseCode(item.getcWHCode());
material=materialService.selectFirstEntity(material);
if(material==null){
throw new ServiceException("该物料不存在:"+item.getcInvCode());
}
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setId(null);
receiptDetail.setWarehouseCode(warehouseCode);
receiptDetail.setMaterialCode(item.getcInvCode());
receiptDetail.setCreated(null);
receiptDetail.setCreatedBy(ShiroUtils.getLoginName());
receiptDetail.setLastUpdated(null);
receiptDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
if(!item.getCompanyCode().equals(icsReceiptHeader.getCompanyCode())){
throw new ServiceException("子单货主与主单不对应");
}
receiptDetail.setCompanyCode(item.getCompanyCode());
receiptDetail.setProject(item.getcItemName());
receiptDetail.setQty(item.getiQuantity().abs());
// receiptDetail.setQtyCompleted(item.getiQuantity());
receiptDetail.setInventoryStatus("good");
if (item.getIrowno()!=null && StringUtils.isNotEmpty(item.getIrowno().toString())) {
receiptDetail.setSourceLine(item.getIrowno().toString());
}
receiptDetails.add(receiptDetail);
}
//调用公共API
ReceiptModel receiptModel=new ReceiptModel();
receiptModel.setReceiptHeader(receiptHeader);
receiptModel.setReceiptDetails(receiptDetails);
return receiptAPIservice.insertReceipt(receiptModel);
}
return AjaxResult.success("入库单下发成功");
}
//出库单为销售出库时
@Transactional
public AjaxResult insertICSReceipts(ICSReceiptModel icsReceiptModel) {
ICSReceiptHeader icsReceiptHeader = icsReceiptModel.getIcsReceiptHeader();
List<ICSReceiptDetail> icsReceiptDetails = icsReceiptModel.getIcsReceiptDetails();
if (!icsReceiptHeader.getType().equals("SRI")) {
return AjaxResult.error("入库类型不匹配");
}
//判断系统中有没有该货主
companyService.checkwarehouseCompany(icsReceiptHeader.getCompanyCode());
if(icsReceiptHeader.getcDLCode()==null){
throw new ServiceException("没有单号");
}
ReceiptHeader receiptHeaderB=new ReceiptHeader();
receiptHeaderB.setSourceCode(icsReceiptHeader.getcDLCode());
if(receiptHeaderService.selectFirstEntity(receiptHeaderB)!=null){
throw new ServiceException("单号重复");
}
//判断仓库是否存在单据的物料编码
ReceiptHeader receiptHeader;
List<ReceiptDetail> receiptDetails;
Set<String> warehouseCodes = new HashSet<>();
for (ICSReceiptDetail item : icsReceiptDetails) {
//查找物料
Warehouse warehouse=new Warehouse();
warehouse.setCode(item.getcWHCode());
if(warehouseService.selectFirstEntity(warehouse)==null){
throw new ServiceException("系统没有该仓库:"+item.getcWHCode());
}
//查找物料
Material material = new Material();
material.setCode(item.getcInvCode());
material.setWarehouseCode(item.getcWHCode());
material=materialService.selectFirstEntity(material);
if(material==null){
throw new ServiceException("该物料不存在:"+item.getcInvCode());
}
warehouseCodes.add(item.getcWHCode());
}
//将主表插入到新的接收主表里去
int result = icsReceiptHeaderService.insertModel(icsReceiptHeader);
if (result < 1) {
throw new ServiceException("出库主单传输失败!");
}
//将子表插入到新的接收子表里去
for (ICSReceiptDetail item : icsReceiptDetails) {
int result1 = icsReceiptDetailService.insertModel(item);
if (result1 < 1) {
throw new ServiceException("出库子单传输失败!");
}
}
for (String warehouseCode : warehouseCodes) {
receiptDetails = new ArrayList<>();
//出库主单
receiptHeader = new ReceiptHeader();
receiptHeader.setType(icsReceiptHeader.getType());
receiptHeader.setId(null);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setCreatedBy(ShiroUtils.getLoginName());
receiptHeader.setSourceCode(icsReceiptHeader.getcDLCode());
receiptHeader.setSupplierCode(icsReceiptHeader.getcVenCode());
receiptHeader.setWarehouseCode(warehouseCode);
receiptHeader.setCompanyCode(icsReceiptHeader.getCompanyCode());
//细单
for (ICSReceiptDetail item : icsReceiptDetails) {
if (warehouseCode.equals(item.getcWHCode())) {
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setId(null);
receiptDetail.setWarehouseCode(item.getcWHCode());
receiptDetail.setMaterialCode(item.getcInvCode());
receiptDetail.setCreated(null);
receiptDetail.setCreatedBy(ShiroUtils.getLoginName());
receiptDetail.setLastUpdated(null);
receiptDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
if(!item.getCompanyCode().equals(icsReceiptHeader.getCompanyCode())){
throw new ServiceException("子单货主与主单不对应");
}
receiptDetail.setCompanyCode(item.getCompanyCode());
receiptDetail.setProject(item.getcItemName());
receiptDetail.setQty(item.getiQuantity().abs());
// receiptDetail.setQtyCompleted(item.getiQuantity());
receiptDetail.setInventoryStatus("good");
receiptDetails.add(receiptDetail);
}
}
//调用公共API
ReceiptModel receiptModel = new ReceiptModel();
receiptModel.setReceiptHeader(receiptHeader);
receiptModel.setReceiptDetails(receiptDetails);
return receiptAPIservice.insertReceipt(receiptModel);
}
return AjaxResult.success("销售入货单下发成功");
}
//入库单回传
public AjaxResult ConfirmICSReceipt(String url){
//先找到出库主单
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setLastStatus((short)800);
receiptHeader = receiptHeaderService.getReceipt(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("入库回传子单不存在");
}
ICSReceiptHeader icsReceiptHeader=new ICSReceiptHeader();
String type=receiptHeader.getType();
String code=receiptHeader.getSourceCode();
List<ICSReceiptDetail> icsReceiptDetails=new ArrayList<ICSReceiptDetail>();
ICSReceiptDetail icsReceiptDetail=new ICSReceiptDetail();
Warehouse warehouse=new Warehouse();
Material material=new Material();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
String dt = simpleDateFormat.format(receiptHeader.getCreated());
//入库类型为成品入库单
if(type.equals("SI")){
icsReceiptHeader.setcCode(receiptHeader.getCode());
icsReceiptHeader.setID(receiptHeader.getId());
icsReceiptHeader.setdPODate(receiptHeader.getLastUpdated().toString());
icsReceiptHeader.setcWHCode(receiptHeader.getWarehouseCode());
warehouse.setCode(receiptHeader.getWarehouseCode());
icsReceiptHeader.setcWHName(warehouseService.selectFirstEntity(warehouse).getName());
icsReceiptHeader.setcMemo(receiptHeader.getRemark());
icsReceiptHeader.setcBusType("产成品入库");
icsReceiptHeader.setcMaker(receiptHeader.getCreatedBy());
icsReceiptHeader.setCompanyCode(receiptHeader.getCompanyCode());
icsReceiptHeader.setcModifyDate(receiptHeader.getLastUpdated().toString());
icsReceiptHeader.setVoucherType("CreateICSRdRecord_10");
for(ReceiptDetail item: receiptDetails){
icsReceiptDetail.setID(item.getId());
icsReceiptDetail.setIrowno(Integer.valueOf(item.getSourceLine()));
ICSShipmentDetail icsShipmentDetail=new ICSShipmentDetail();
icsShipmentDetail.setMoCode(item.getSourceCode());
icsShipmentDetail.setIrowno(Integer.valueOf(item.getSourceLine()));
icsShipmentDetailService.selectModel(icsShipmentDetail);
icsReceiptDetail.setiMPoIds(icsShipmentDetail.getMoDId());
icsReceiptDetail.setcItemName(item.getProject());
icsReceiptDetail.setcInvCode(item.getMaterialCode());
material.setCode(item.getMaterialCode());
material=materialService.selectFirstEntity(material);
icsReceiptDetail.setcInvName(material.getName());
icsReceiptDetail.setcInvStd(material.getSpecification());
icsReceiptDetail.setiQuantity(item.getQtyCompleted());
icsReceiptDetail.setcComUnitName(material.getMasterUnit());
icsReceiptDetail.setCompanyCode(item.getCompanyCode());
icsReceiptDetail.setcModifyDate(item.getLastUpdated().toString());
icsReceiptDetails.add(icsReceiptDetail);
}
}
//入库类型为采购的主单和子单
if(type.equals("PI")){
icsReceiptHeader.setcCode(code);
icsReceiptHeader=icsReceiptHeaderService.selectModel(icsReceiptHeader);
icsReceiptHeader.setcWHCode(receiptHeader.getWarehouseCode());
icsReceiptHeader.setID(receiptHeader.getId());
warehouse.setCode(receiptHeader.getWarehouseCode());
icsReceiptHeader.setcWHName( warehouseService.selectFirstEntity(warehouse).getName());
icsReceiptHeader.setVoucherType("CreateICSRdRecord_01");
//子单
icsReceiptDetail.setcCode(code);
icsReceiptDetails=icsReceiptDetailService.selectList(icsReceiptDetail);
for(ICSReceiptDetail item :icsReceiptDetails){
receiptDetail.setReceiptCode(code);
receiptDetail.setSourceLine(item.getIrowno().toString());
receiptDetailService.selectFirstEntity(receiptDetail);
item.setID(receiptDetail.getId());
item.setiArrsId(item.getAutoID());
item.setiPOsID(item.getPODID());
}
}
//入库类型为材料或其他的主单和子单
if(type.equals("CI") || type.equals("QI")){
icsReceiptHeader.setcCode(code);
icsReceiptHeader.setcWHCode(receiptHeader.getWarehouseCode());
icsReceiptHeader=icsReceiptHeaderService.selectModel(icsReceiptHeader);
icsReceiptHeader.setdDate(dt);
icsReceiptDetail.setcCode(code);
icsReceiptDetails=icsReceiptDetailService.selectList(icsReceiptDetail);
}
if(type.equals("CI")){
icsReceiptHeader.setVoucherType("UpdateICSRdRecord_11_Return_Confirm");
}
if(type.equals("QI")){
icsReceiptHeader.setVoucherType("UpdateICSRdRecord_08_Confirm");
}
//入库类型为销售退货的主单和子单
if(type.equals("SRI")){
icsReceiptHeader.setcDLCode (code);
// icsReceiptHeader.setcWHCode(receiptHeader.getWarehouseCode());
icsReceiptHeader=icsReceiptHeaderService.selectModel(icsReceiptHeader);
icsReceiptHeader.setdDate(dt);
String warehouseCode=receiptHeader.getWarehouseCode();
icsReceiptHeader.setcWHCode(warehouseCode);
warehouse.setCode(warehouseCode);
icsReceiptHeader.setcWHName( warehouseService.selectFirstEntity(warehouse).getName());
icsReceiptHeader.setVoucherType("CreateICSRdRecord_32_Return");
icsReceiptHeader.setcCode(receiptHeader.getSourceCode());
icsReceiptHeader.setID(icsReceiptHeader.getDLID());
icsReceiptHeader.setdDate(icsReceiptHeader.getdPODate());
icsReceiptDetail.setcWHCode(receiptHeader.getWarehouseCode());
icsReceiptDetails=icsReceiptDetailService.selectList(icsReceiptDetail);
for(ICSReceiptDetail item :icsReceiptDetails){
item.setcCode(code);
item.setID(item.getDLID());
item.setAutoID(item.getAutoID());
}
}
//入库类型为调拨的主单和子单
if(type.equals("TI")){
ICSShipmentHeader icsShipmentHeader=new ICSShipmentHeader();
icsShipmentHeader.setcTVCode(code);
icsShipmentHeader=icsShipmentHeaderService.selectModel(icsShipmentHeader);
icsReceiptHeader.setcTVCode (code);
icsReceiptHeader.setiWHCode(receiptHeader.getWarehouseCode());
icsReceiptHeader=icsReceiptHeaderService.selectModel(icsReceiptHeader);
icsReceiptHeader.setcCode(receiptHeader.getSourceCode());
icsReceiptHeader.setVoucherType("CreateICSRdRecord_0809");
icsReceiptHeader.setcWHCode(icsShipmentHeader.getoWHCode());
icsReceiptHeader.setcWHName(icsShipmentHeader.getoWHName());
icsReceiptDetail.setcCode(code);
icsReceiptDetail.setID(icsReceiptHeader.getID());
icsReceiptDetails=icsReceiptDetailService.selectList(icsReceiptDetail);
}
ICSReceiptModel model=new ICSReceiptModel();
model.setIcsReceiptHeader(icsReceiptHeader);
model.setIcsReceiptDetails(icsReceiptDetails);
String JsonParam = JSON.toJSONString(model);
String result = HttpUtils.bodypost(url, JsonParam);
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if(!ajaxResult.hasErr()) {
receiptHeader.setFirstStatus((short) 900);
receiptHeader.setLastStatus((short) 900);
receiptHeaderService.updateByModel(receiptHeader);
}
return ajaxResult;
}
}