ErpBackUpdateStatusServiceImpl.java
11.9 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
package com.huaheng.api.erp.service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import org.apache.xpath.operations.Bool;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.erp.domainBack.*;
import com.huaheng.api.erp.domainBack.finishedR.ParameterFinished;
import com.huaheng.api.erp.domainBack.inventoryScrapC.ParameterInventoryScrap;
import com.huaheng.api.erp.domainBack.issuanceC.ParameterIssuance;
import com.huaheng.api.erp.domainBack.miscellaneousR.ParameterMiscellaneous;
import com.huaheng.api.erp.domainBack.noticeWmsC.ParameterNotice;
import com.huaheng.api.erp.domainBack.purchaseWmsR.ParameterPurchase;
import com.huaheng.api.erp.domainBack.saleR.Parameter;
import com.huaheng.api.erp.domainBack.scrapC.ParameterScrap;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
/**
* @author 游杰
*/
@Service
public class ErpBackUpdateStatusServiceImpl implements IErpBackUpdateStatusService {
@Resource
private IErpBackTypeService erpBackTypeService;
@Resource
private IErpBackService erpBackService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Transactional(rollbackFor = Exception.class)
public AjaxResult backTaskUpdateStatus(TaskHeader task,List<BackTaskStatus> backTaskStatusList){
String msg=task.getBackInfo();
msg="";
if(StringUtils.isNotEmpty(msg)){
msg=msg+",";
}else{
msg="";
}
Integer status=0;
for(BackTaskStatus backTaskStatus:backTaskStatusList){
//更新入库或出库单表状态
switch (task.getInternalTaskType()){
case 100:
//成功了去检查详情有没有都完成
ReceiptHeader receiptHeader=new ReceiptHeader();
receiptHeader.setId(backTaskStatus.getBillId());
String backMsg="";
ReceiptHeader receiptHeader1=receiptHeaderService.getById(receiptHeader.getId());
if(receiptHeader1!=null&&StringUtils.isNotEmpty(receiptHeader1.getBackMsg())){
backMsg=receiptHeader1.getBackMsg()+",";
}
if(backTaskStatus.getIsSuccess()){
boolean tag=checkReceiptDetailComplete(backTaskStatus.getBillId(),task.getWarehouseCode());
if(backMsg.contains("失败")){
backMsg="";
}
receiptHeader.setBackMsg(backMsg+backTaskStatus.getMsg());
if(tag){
//更改入库单状态
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
}
compaleteAllTask(backTaskStatus,task,msg,status,receiptHeader,null);
}else{
//返回错误
// receiptHeader.setBackMsg("失败");
}
receiptHeaderService.updateById(receiptHeader);
break;
case 200:
//成功了去检查详情有没有都完成
ShipmentHeader shipmentHeader=new ShipmentHeader();
shipmentHeader.setId(backTaskStatus.getBillId());
String backMsg1="";
ShipmentHeader shipmentHeader1=shipmentHeaderService.getById(shipmentHeader.getId());
if(shipmentHeader1!=null&&StringUtils.isNotEmpty(shipmentHeader1.getBackMsg())){
backMsg1=shipmentHeader1.getBackMsg()+",";
}
if(backTaskStatus.getIsSuccess()){
boolean tag=checkShipmentDetailComplete(backTaskStatus.getBillId(),task.getWarehouseCode());
if(backMsg1.contains("失败")){
backMsg1="";
}
shipmentHeader.setBackMsg(backMsg1+backTaskStatus.getMsg());
if(tag){
//更改入库单状态
shipmentHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
shipmentHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
}
compaleteAllTask(backTaskStatus,task,msg,status,null,shipmentHeader);
}else{
// shipmentHeader.setBackMsg("失败");
}
shipmentHeaderService.updateById(shipmentHeader);
break;
default:
break;
}
msg+=backTaskStatus.getMsg()+",";
status=backTaskStatus.getStatus();
}
TaskHeader taskHeader1 = new TaskHeader();
taskHeader1.setId(task.getId());
taskHeader1.setBackQty(task.getBackQty() + 1);
taskHeader1.setBackInfo(msg);
if(msg.length()>600){
taskHeader1.setBackInfo("请求失败,具体信息请查看日志");
}else{
taskHeader1.setBackInfo(msg);
}
taskHeader1.setIsReturn(status);
//查找详情有上游号未回传的,有则为false
if(status!=QuantityConstant.SN_RETURN&&taskDetailAllBack(task.getWarehouseCode(),task.getId())){
//整单回传的,等待中,没有回传信息,则不更改状态
if(StringUtils.isNotEmpty(taskHeader1.getBackInfo())){
taskHeader1.setIsReturn(1);
}
}
taskHeaderService.updateById(taskHeader1);
if(status!=2){
return AjaxResult.error("请求失败,具体信息请查看日志:"+msg);
}
return AjaxResult.success(msg);
}
/**
* 更新该单据其他任务状态
*/
public void compaleteAllTask(BackTaskStatus backTaskStatus,TaskHeader task,String msg,Integer status,ReceiptHeader receiptHeader,ShipmentHeader shipmentHeader){
Set<Integer> taskIds=backTaskStatus.getTaskIds();
if(taskIds!=null && taskIds.size()>0){
//整单回传的该单据其他任务如果完成了,则查找该任务底下详情是否都已完成,已完成则更改任务状态
for(Integer taskId:taskIds){
if(taskId!=null&&taskId!=task.getId()){
//获取未回传任务集
Boolean tag=null;
if(receiptHeader!=null){
tag=erpBackService.taskAllComplete(receiptHeader.getCode(),receiptHeader.getWarehouseCode(),task.getId());
}else{
tag=erpBackService.taskAllComplete(shipmentHeader.getCode(),shipmentHeader.getWarehouseCode(),task.getId());
}
if(tag){
//同一个单据该任务还有未完成的
// TaskHeader taskHeader1 = new TaskHeader();
// taskHeader1.setId(taskId);
// taskHeader1.setBackQty(task.getBackQty() + 1);
// taskHeader1.setBackInfo(backmsg+msg);
// taskHeader1.setIsReturn(status);
// taskHeaderService.updateById(taskHeader1);
}
}
}
}
}
public Boolean checkReceiptDetailComplete(Integer billId,String warehouseCode){
LambdaQueryWrapper<ReceiptDetail> wrapper=new LambdaQueryWrapper<>();
wrapper.eq(ReceiptDetail::getWarehouseCode,warehouseCode);
wrapper.eq(ReceiptDetail::getReceiptId,billId);
List<ReceiptDetail> list=receiptDetailService.findByReceiptId(billId);
Boolean flag=true;
for(ReceiptDetail receiptDetail:list){
flag=isAllComplete(receiptDetail.getQty(),receiptDetail.getTaskQty(),receiptDetail.getBackQty());
if(!flag){
break;
}
}
return flag;
}
public Boolean checkShipmentDetailComplete(Integer billId,String warehouseCode){
List<ShipmentDetail> list=shipmentDetailService.getListByShipmentHeaderId(billId,warehouseCode);
Boolean flag=true;
for(ShipmentDetail shipmentDetail:list){
flag=isAllComplete(shipmentDetail.getQty(),shipmentDetail.getTaskQty(),shipmentDetail.getBackQty());
if(!flag){
break;
}
}
return flag;
}
private Boolean isAllComplete(BigDecimal qty,BigDecimal taskQty,BigDecimal backQty){
Boolean flag = false;
// 判断总数量 和 收货数量 是否一致
if(qty.compareTo(taskQty) != 0){
return false;
}
if(backQty.compareTo(qty)==0){
flag = true;
}else{
//判断 回传数量和总数量
if(qty.compareTo(backQty) == 0){
flag = true;
}else{
return false;
}
}
return flag;
}
/**
* 返回true则是还有未完成的,false则是空的
* @param warehouseCode
* @param taskid
* @return 返回空位false 有数据有true
*/
public boolean taskDetailAllBack(String warehouseCode,Integer taskid){
LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(TaskDetail::getWarehouseCode,warehouseCode)
.eq(TaskDetail::getTaskId,taskid)
.apply(" (billCode not like 'transfer_c%')")
.apply(" (referenceCode is not null and referenceCode!='')")
.eq(TaskDetail::getBack,0);
List<TaskDetail> taskDetails = taskDetailService.list(queryWrapper);
return !taskDetails.isEmpty();
}
/**
* 判断该出通单任务是否含有sn,有sn则仓库手动回传
* @param unbackTask
* @return
*/
public boolean shipmentHaveSn(List<TaskDetail> unbackTask){
for(TaskDetail taskDetail:unbackTask){
if(StringUtils.isNotEmpty(taskDetail.getSn())){
return true;
}
}
return false;
}
}