CodingServiceImpl.java
5.79 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
package com.huaheng.api.jindie.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.huaheng.api.general.domain.ReceiptDomain;
import com.huaheng.api.general.domain.ShipmentDomain;
import com.huaheng.api.general.service.ReceiptApiService;
import com.huaheng.api.general.service.ShipmentApiService;
import com.huaheng.api.jindie.domain.GoodReceiptDomain;
import com.huaheng.api.jindie.domain.GoodReceiving;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CodingServiceImpl implements CodingService{
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptApiService receiptApiService;
@Resource
private ShipmentApiService shipmentApiService;
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult goodReceiving(GoodReceiving goodReceiving) {
Integer qc = goodReceiving.getQc();
Integer accessory = goodReceiving.getAccessory();
String referCode = goodReceiving.getReferCode();
ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, referCode));
if(receiptHeader==null){
// return AjaxResult.error("系统为查询到此单据:"+referCode);
return AjaxResult.success();
}
List<ReceiptDetail> receiptDetails = receiptDetailService.list(new LambdaQueryWrapper<ReceiptDetail>().eq(ReceiptDetail::getReferCode, referCode));
if(CollectionUtils.isEmpty(receiptDetails)){
// return AjaxResult.error("系统为查询到此单据明细:"+referCode);
return AjaxResult.success();
}
if(StringUtils.isNotNull(receiptHeader.getQc())&&StringUtils.isNotNull(receiptHeader.getAccessory())){
// return AjaxResult.error("已提交过质检:"+referCode);
return AjaxResult.success();
}
if(qc==null){
return AjaxResult.error("qc:为空:"+referCode);
}
if(accessory==null){
return AjaxResult.error("accessory:为空:"+referCode);
}
receiptHeader.setQc(qc);
receiptHeader.setAccessory(accessory);
receiptHeaderService.updateById(receiptHeader);
/** step1 判断是否合格 */
if(QuantityConstant.GOOD_RECEIVING_QC==qc){
/** step1.1 生成来料退货单*/
AjaxResult cgtl = createShipment(referCode, receiptHeader, receiptDetails, "CGTL");
if(cgtl.hasErr()){
return AjaxResult.error("质检不合格时生成退料单失败"+cgtl.getMsg());
}else {
return AjaxResult.success("质检不合格时生成退料单成功");
}
}
/** step2 判断是否配件包 */
if(QuantityConstant.GOOD_RECEIVING_ACCESSORY==accessory){
/** step2.1 是 生成调拨单 */
AjaxResult zjdb = createShipment(referCode, receiptHeader, receiptDetails, "ZJDB");
if(zjdb.hasErr()){
return AjaxResult.error("是配件包时生成调拨单失败"+zjdb.getMsg());
}else {
return AjaxResult.success("是配件包时生成调拨单成功");
}
}
return AjaxResult.success();
}
@Transactional(rollbackFor = Exception.class)
public AjaxResult createShipment(String referCode,ReceiptHeader receiptHeader,List<ReceiptDetail> receiptDetails,String shipmentType){
ShipmentDomain shipmentDomain=new ShipmentDomain();
ShipmentHeader shipmentHeader=new ShipmentHeader();
shipmentHeader.setWarehouseCode("CS0001");
shipmentHeader.setCompanyCode("WB");
shipmentHeader.setReferCode(referCode);
shipmentHeader.setReferCodeType(receiptHeader.getReceiptType());
shipmentHeader.setShipmentType(shipmentType);
shipmentHeader.setReferLineId(receiptHeader.getReferId());
shipmentHeader.setCreatedBy(receiptHeader.getCreatedBy());
shipmentHeader.setSourcePlatform("ERP");
shipmentDomain.setShipmentHeader(shipmentHeader);
List<ShipmentDetail> shipmentDetails=new ArrayList<>();
receiptDetails.forEach(receiptDetail -> {
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail.setWarehouseCode("CS0001");
shipmentDetail.setCompanyCode("WB");
shipmentDetail.setReferCode(referCode);
shipmentDetail.setMaterialCode(receiptDetail.getMaterialCode());
shipmentDetail.setMaterialName(receiptDetail.getMaterialName());
shipmentDetail.setBatch(receiptDetail.getBatch());
shipmentDetail.setLineId(receiptDetail.getLineId());
shipmentDetail.setShipQty(receiptDetail.getTotalQty());
shipmentDetails.add(shipmentDetail);
});
shipmentDomain.setShipmentDetails(shipmentDetails);
return shipmentApiService.shipment(shipmentDomain);
}
}