QuickReceiptService.java
9.41 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
package com.huaheng.api.wcs.service.quickReceipt;
import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.receipt.ReceiptBill;
import com.huaheng.mobile.receipt.ReceiptJJBean;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerView;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
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.receipt.receiving.controller.ReceivingController;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class QuickReceiptService {
private static final Logger logger = LoggerFactory.getLogger(QuickReceiptService.class);
@Resource
private ContainerService containerService;
@Resource
private StationService stationService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Resource
private ReceiptTaskService receiptTaskService;
@Transactional(rollbackFor = Exception.class)
public AjaxResult quickReceiptJJ(List<ReceiptJJBean> receiptBills) {
String companyCode = receiptBills.get(0).getCompanyCode();
String containerCode = receiptBills.get(0).getContainerCode();
String warehosueCode = ShiroUtils.getWarehouseCode();
String fromPort = receiptBills.get(0).getFromPort();
String inventorySts = receiptBills.get(0).getInventorySts();
String referCode = receiptBills.get(0).getReferCode();
Container container = containerService.getContainerByCode(containerCode, warehosueCode);
int receiptHeaderId = receiptHeaderService.createTodayHeaderJJ(companyCode, container.getUWarehouseCode());
// if (!inventorySts.equals("good")) {
ReceiptHeader receiptHeader1 = new ReceiptHeader();
receiptHeader1.setId(receiptHeaderId);
receiptHeader1.setReferCode(referCode);
receiptHeaderService.updateById(receiptHeader1);
// }
List<Integer> receiptDetailIds = receiptDetailService.insertTodayReceiptDetailJJ(receiptHeaderId, receiptBills, false, companyCode);
if (receiptDetailIds != null && receiptDetailIds.size() > 0) {
for (Integer i : receiptDetailIds) {
//组盘
final ReceiptDetail receiptDetail = receiptDetailService.getById(Integer.valueOf(i));
ReceiptContainerView receiptContainerView = new ReceiptContainerView();
receiptContainerView.setReceiptCode(receiptDetail.getReceiptCode());
receiptContainerView.setQty(receiptDetail.getQty());
receiptContainerView.setContainerCode(containerCode);
receiptContainerView.setReceiptDetailId(Integer.valueOf(i));
// receiptContainerView.setPort(receiptBills.get(0).getFromPort());
AjaxResult ajaxResult = receiptContainerHeaderService.saveContainer(receiptContainerView);
if (ajaxResult.hasErr()) {
throw new ServiceException(ajaxResult.getMsg());
}
}
//创建任务
LambdaQueryWrapper<ReceiptContainerHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerHeader::getContainerCode, containerCode);
lambdaQueryWrapper.le(ReceiptContainerHeader::getStatus, 10);
lambdaQueryWrapper.last("limit 1");
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getOne(lambdaQueryWrapper);
if (receiptContainerHeader != null) {
String ids2 = receiptContainerHeader.getId().toString();
Integer[] idArray = Convert.toIntArray(ids2);
List<Integer> islist = Arrays.asList(idArray);
try {
AjaxResult ajaxResult1 = receiptTaskService.createReceiptTask(islist);
if (ajaxResult1.hasErr()) {
throw new ServiceException(ajaxResult1.getMsg());
}
List<String> taskIds = (List<String>) ajaxResult1.getData();
if (taskIds != null && taskIds.size() > 0) {
String taskId = taskIds.get(0);
TaskHeader taskHeader = new TaskHeader();
taskHeader.setId(Integer.valueOf(taskId));
taskHeader.setPort(fromPort);
taskHeader.setToPort(fromPort);
taskHeader.setPickingCartPos(fromPort);
taskHeaderService.updateById(taskHeader);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("receipt/receiving/save:idArray=" + idArray + "msg:" + e.getMessage());
}
}
return AjaxResult.success();
}
return AjaxResult.success();
}
public AjaxResult checkReceiptData(List<ReceiptJJBean> receiptBills) {
ReceiptJJBean receiptJJBean = receiptBills.get(0);
if (StringUtils.isEmpty(receiptJJBean.getContainerCode())) {
return AjaxResult.error("容器编码不能为空");
}
if (StringUtils.isEmpty(receiptJJBean.getCompanyCode())) {
return AjaxResult.error("货主编码不能为空");
}
if (StringUtils.isEmpty(receiptJJBean.getInventorySts())) {
return AjaxResult.error("合格标志不能为空");
}
if (StringUtils.isEmpty(receiptJJBean.getMaterialCode())) {
return AjaxResult.error("物料编码不能为空");
}
if (StringUtils.isEmpty(receiptJJBean.getFromPort())) {
return AjaxResult.error("起点不能为空");
}
if (receiptJJBean.getQty() == null) {
return AjaxResult.error("数量不能为空");
}
if (receiptJJBean.getQty().compareTo(BigDecimal.ZERO) <= 0) {
return AjaxResult.error("收货数量大于0");
}
LambdaQueryWrapper<Container> containerQueryWrapper = Wrappers.lambdaQuery();
containerQueryWrapper.eq(Container::getCode, receiptJJBean.getContainerCode());
containerQueryWrapper.eq(Container::getWarehouseCode, ShiroUtils.getWarehouseCode());
containerQueryWrapper.last("limit 1");
Container container = containerService.getOne(containerQueryWrapper);
if (container == null) {
return AjaxResult.error("不存在这个托盘:" + receiptJJBean.getContainerCode());
}
//pda入库增加托盘任务校验
List<TaskHeader> unfinishTask = taskHeaderService.getUnCompleteTaskList().stream().filter((t) -> {
return t.getContainerCode().equals(container.getCode());
}).collect(Collectors.toList());
if (unfinishTask.size() > 0) {
TaskHeader t = unfinishTask.get(0);
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(t.getCreated());
return AjaxResult.error(container.getCode() + "托盘已经有未完成的任务,请不要重复下发\n该托盘任务创建于:" + time);
}
LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
stationLambdaQueryWrapper.eq(Station::getCode, receiptJJBean.getFromPort());
stationLambdaQueryWrapper.eq(Station::getWarehouseCode, ShiroUtils.getWarehouseCode());
stationLambdaQueryWrapper.in(Station::getType, "4","1");
stationLambdaQueryWrapper.last("limit 1");
Station station = stationService.getOne(stationLambdaQueryWrapper);
if (station == null) {
return AjaxResult.error("不存在这个起点:" + receiptJJBean.getFromPort());
}
return AjaxResult.success();
}
}