TaskBackQueue.java
5.06 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
package com.huaheng.pc.task.taskHeader.service;
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.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 org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class TaskBackQueue implements BackQueue{
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Override
public void receiveBack(int taskId, CallBack callBack) {
Integer receiptOrShipment = null;
AjaxResult ajaxResult = AjaxResult.success();
boolean flag = true;
String message = "成功";
Integer result = 0;
if(StringUtils.isNull(taskId)){
callBack.back(false,"任务id不能为空", QuantityConstant.ISRETURN_FAIL,receiptOrShipment);
return;
}
TaskHeader header = taskHeaderService.getById(taskId);
if(header == null){
callBack.back(false,"找不到任务id为:"+taskId+"的任务",QuantityConstant.ISRETURN_FAIL,receiptOrShipment);
return;
}
switch (header.getTaskType()){
case 500 :
case 600 :
case 800 :
case 900 :
case 1000 :
case 1100 :
case 1200 :
callBack.back(true,"无需回传",QuantityConstant.NOT_RETURN,receiptOrShipment);
return;
}
List<TaskDetail> taskDetails = taskDetailService.findByTaskId(taskId);
if(taskDetails==null || taskDetails.size()==0){
callBack.back(false,"找不到任务id为:"+taskId+"的任务,没有任务明细",QuantityConstant.ISRETURN_FAIL,receiptOrShipment);
return;
}
switch (header.getInternalTaskType()){
case 100 :
String receiptHeaderId = "";
ReceiptDetail receiptDetail = receiptDetailService.getById(taskDetails.get(0).getBillDetailId());
ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId());
if(StringUtils.isEmpty(receiptHeader.getReferCode())){
callBack.back(true,"无需回传",QuantityConstant.NOT_RETURN,receiptOrShipment);
return;
}
receiptHeaderId += receiptDetail.getReceiptId();
Map<Integer, BigDecimal> detailsQtyMap =new HashMap<>();
for (TaskDetail taskDetail : taskDetails) {
detailsQtyMap.put(taskDetail.getBillDetailId(),taskDetail.getQty());
}
ajaxResult = receiptHeaderService.postBack(receiptHeaderId, detailsQtyMap);
receiptOrShipment = 1;
break;
case 200 :
String shipmentHeaderId = "";
ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetails.get(0).getBillDetailId());
ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentDetail.getShipmentId());
if(StringUtils.isEmpty(shipmentHeader.getReferCode())){
callBack.back(true,"无需回传",QuantityConstant.NOT_RETURN,receiptOrShipment);
return;
}
shipmentHeaderId += shipmentDetail.getShipmentId();
Map<Integer, BigDecimal> detailsQtyMap1 =new HashMap<>();
for (TaskDetail taskDetail : taskDetails) {
detailsQtyMap1.put(taskDetail.getBillDetailId(),taskDetail.getQty());
}
ajaxResult = shipmentHeaderService.postBack(shipmentHeaderId,detailsQtyMap1);
receiptOrShipment = 2;
break;
}
flag = !ajaxResult.hasErr();
message = ajaxResult.getMsg();
result = flag ? QuantityConstant.ISRETURN_SUCC : QuantityConstant.ISRETURN_FAIL;
callBack.back(flag,message,result,receiptOrShipment);
}
}