BackInvokeService.java
7.28 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
package com.huaheng.pc.task.taskHeader.service;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
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.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
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.TaskBackDomain;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class BackInvokeService {
@Resource
private BackQueue backQueue;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private ReceiptContainerDetailService receiptContainerDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ShipmentContainerDetailService shipmentContainerDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
public void invokeBack(int taskId){
new Thread(()->{
backQueue.receiveBack(taskId, new CallBack() {
@Override
public void back(TaskBackDomain domain) {
TaskHeader taskHeader = taskHeaderService.getById(taskId);
taskHeader.setBackQty(taskHeader.getBackQty()+1);
taskHeader.setBackInfo(domain.getMsg());
taskHeader.setIsReturn(domain.getBackNum());
taskHeaderService.updateById(taskHeader);
List<TaskDetail> taskDetails = taskDetailService.findByTaskId(taskId);
List<String> billCodes = taskDetails.stream().map(TaskDetail::getBillCode).collect(Collectors.toList());
if(StringUtils.isNotNull(domain.getType())){
if(domain.getType()==1){
//获取所有入库单
List<ReceiptHeader> receiptHeaders = receiptHeaderService.listByCodes(billCodes, taskHeader.getWarehouseCode());
for (ReceiptHeader receiptHeader : receiptHeaders) {
List<ReceiptDetail> details = receiptDetailService.findByReceiptId(receiptHeader.getId());
int isFlag = 0;
for (ReceiptDetail detail : details) {
isFlag = isComplete(detail.getQty(),detail.getTaskQty(),detail.getBackQty());
if(isFlag == 0){
break;
}
}
String s = domain.getMsgMaps().get(receiptHeader.getCode());
if(StringUtils.isNull(receiptHeader.getBackMsg())){
receiptHeader.setBackMsg(s);
}else{
if(!receiptHeader.getBackMsg().contains(s)){
receiptHeader.setBackMsg(receiptHeader.getBackMsg()+","+s);
}
}
if(domain.getIsSuc()){
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
if(isFlag==1){
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
}
}
receiptHeaderService.updateById(receiptHeader);
}
}else if(domain.getType()==2){
//获取所有入库单
List<ShipmentHeader> shipmentHeaders = shipmentHeaderService.listByCodes(billCodes, taskHeader.getWarehouseCode());
for (ShipmentHeader shipmentHeader : shipmentHeaders) {
List<ShipmentDetail> details = shipmentDetailService.getListByShipmentHeaderId(shipmentHeader.getId(),shipmentHeader.getWarehouseCode());
int isFlag = 0;
for (ShipmentDetail detail : details) {
// 判断总数量 和 收货数量 是否一致
isFlag = isComplete(detail.getQty(),detail.getTaskQty(),detail.getBackQty());
if(isFlag == 0){
break;
}
}
String msg = domain.getMsgMaps().get(shipmentHeader.getCode());
if(StringUtils.isNull(shipmentHeader.getBackMsg())){
shipmentHeader.setBackMsg(msg);
}else{
if(!shipmentHeader.getBackMsg().contains(msg)){
shipmentHeader.setBackMsg(shipmentHeader.getBackMsg()+","+msg);
}
}
if(domain.getIsSuc()){
shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
if(isFlag==1){
shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
}
}
shipmentHeaderService.updateById(shipmentHeader);
}
}
}
}
});
},"async-thread").start();
}
private int isComplete(BigDecimal qty,BigDecimal taskQty,BigDecimal backQty){
int num = 0;
// 判断总数量 和 收货数量 是否一致
if(qty.compareTo(taskQty) != 0){
return 0;
}
if(backQty.compareTo(qty)==0){
num = 1;
}else{
//判断 回传数量和总数量
if(qty.compareTo(backQty) == 0){
num = 1;
}else{
return 0;
}
}
return num;
}
}