OverrideHandleServiceImpl.java
10.7 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
package com.huaheng.api.wcs.service.overrideHandle;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.TaskFinishDomain;
import com.huaheng.api.wcs.service.warecellAllocation.WarecellAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.FilterConfigDetail.domain.FilterConfigDetail;
import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiving.service.ReceivingService;
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class OverrideHandleServiceImpl implements OverrideHandleService {
@Autowired
private TaskHeaderService taskHeaderService;
@Autowired
private TaskDetailService taskDetailService;
@Autowired
private LocationService locationService;
@Autowired
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Autowired
private ReceiptContainerDetailService receiptContainerDetailService;
@Resource
private WarecellAllocationService warecellAllocationService;
@Resource
private FilterConfigDetailService filterConfigDetailService;
@Resource
private LocationTypeService locationTypeService;
@Resource
private ReceivingService receivingService;
@Resource
private ContainerService containerService;
/**
* 重入处理
* 1、判断非空字段
* 2、根据任务号查找任务
* 3、修改任务目的库位,修改入库组盘的库位,修改库位状态
*/
@Override
@Transactional
public AjaxResult OverrideHandle(TaskFinishDomain taskFinishDomain) {
String taskNo = taskFinishDomain.getTaskNo();
//1、判断非空字段
if(StringUtils.isEmpty(taskNo)){
return AjaxResult.error("任务号为空");
}
//2、根据任务号查找任务
TaskHeader taskHeader = taskHeaderService.getById(taskNo);
if(taskHeader == null){
return AjaxResult.error("任务号错误,没有找到该任务");
}
int status = taskHeader.getStatus();
if(status == QuantityConstant.TASK_STATUS_COMPLETED){
return AjaxResult.error("任务已完成");
}
//3、修改任务目的库位,修改入库组盘的库位,修改库位状态
//修改原来目的库位的状态
LambdaQueryWrapper<Location> locationLam = Wrappers.lambdaQuery();
locationLam.eq(Location::getCode,taskHeader.getToLocation())
.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
Location location = locationService.getOne(locationLam);
if(location == null) {
return AjaxResult.error("此任务的原目的库位在系统中不存在");
}
location.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
location.setContainerCode("");
Boolean flag = locationService.updateById(location);
if(flag == false){
return AjaxResult.error("修改此任务的原目的库位错误");
}
/**
* 查看新库位有两种情况
* 1、重入的库位由wcs提供
* 2、重入的库位由wms提供
*/
Location newlocation = new Location();
String newLocationCode = null;
String redirectionLocation = taskFinishDomain.getRedirectionLocationCode();
//重入的库位由wcs提供
if(!"0".equals(redirectionLocation)) {
LambdaQueryWrapper<Location> locationLa = Wrappers.lambdaQuery();
locationLa.eq(Location::getCode, redirectionLocation)
.eq(Location::getStatus,QuantityConstant.STATUS_LOCATION_EMPTY)
.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
newlocation = locationService.getOne(locationLa);
if (newlocation == null) {
throw new ServiceException("新目的库位在系统中不存在或非空闲");
}
if(StringUtils.isNotEmpty(newlocation.getContainerCode())){
throw new ServiceException("新目的库位在系统中已经有容器");
}
}else {
//重入的库位由wms提供
//查询任务明细
LambdaQueryWrapper<TaskDetail> taskDetailLambda = Wrappers.lambdaQuery();
taskDetailLambda.eq(TaskDetail::getTaskId, taskFinishDomain.getTaskNo());
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambda);
String locatingRule = warecellAllocationService.taskPositioning();
String[] locatingRules = locatingRule.split("cut");
LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
locationLambda.last(locatingRules[0]);
locationLambda.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<Location> locationList = locationService.list(locationLambda);
List<Location> removeLocaationList = new ArrayList<>();
for(Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
removeLocaationList.add(location1);
} else {
break;
}
}
locationList.removeAll(removeLocaationList);
if (locationList == null || locationList.size() == 0) {
locationLambda.last(locatingRules[1]);
locationList = locationService.list(locationLambda);
removeLocaationList = new ArrayList<>();
for(Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
removeLocaationList.add(location1);
} else {
break;
}
}
locationList.removeAll(removeLocaationList);
}
LambdaQueryWrapper<LocationType> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper2);
//根据定位规则查询库位编码
QueryWrapper<Location> locationLambdaQueryWrapper = new QueryWrapper<>();
locationLambdaQueryWrapper.eq("1", 1).last(locatingRules[0]);
newlocation = locationService.getOne(locationLambdaQueryWrapper);
Container container = containerService.getContainerByCode(taskHeader.getContainerCode());
String locationCode = receivingService.filter(locationList, locationTypeList, container);
newLocationCode = locationCode;
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_RECEIPT)) {
//查询入库组盘明细
List<ReceiptContainerDetail> receiptContainerDetailList = new ArrayList<>();
for (TaskDetail taskDetail : taskDetailList) {
receiptContainerDetailList.add(receiptContainerDetailService.getById(taskDetail.getAllocationId()));
}
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(receiptContainerDetailList.get(0).getReceiptContainerId());
LambdaUpdateWrapper<ReceiptContainerDetail> wrapper = Wrappers.lambdaUpdate();
wrapper.set(ReceiptContainerDetail::getLocationCode, locationCode)
.in(ReceiptContainerDetail::getId, receiptContainerDetailList.stream().map(ReceiptContainerDetail::getId).collect(Collectors.toList()));
receiptContainerDetailService.update(wrapper);
receiptContainerHeader.setToLocation(locationCode);
receiptContainerHeaderService.updateById(receiptContainerHeader);
}
}
//修改任务
taskHeader.setToLocation(newLocationCode);
taskHeader.setExceptionCode("重入处理");
if(!taskHeaderService.updateById(taskHeader)){
throw new ServiceException("修改此任务错误");
}
//修改子任务
LambdaQueryWrapper<TaskDetail> taskDetailLam = Wrappers.lambdaQuery();
taskDetailLam.eq(TaskDetail::getWarehouseCode,ShiroUtils.getWarehouseCode())
.eq(TaskDetail::getTaskId,taskHeader.getId());
List<TaskDetail> taskDetails = taskDetailService.list(taskDetailLam);
List<TaskDetail> taskDetailList = new ArrayList<>();
if(taskDetails != null && taskDetails.size()> 0){
for(TaskDetail taskDetail : taskDetails){
taskDetail.setToLocation(newLocationCode);
taskDetailList.add(taskDetail);
}
if(!taskDetailService.updateBatchById(taskDetailList)){
throw new ServiceException("修改此任务的明细错误");
}
}
Map<String, String> map = new HashMap<>();
map.put("RedirectionLocationCode", newLocationCode);
map.put("taskNo", String.valueOf(taskHeader.getId()));
return AjaxResult.success("重入处理成功").setData(map);
}
}