TransferTaskService.java
16.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
package com.huaheng.pc.task.taskHeader.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.huaheng.common.utils.Wrappers;
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.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.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
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 org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 移库任务
*/
@Service
public class TransferTaskService {
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private ContainerService containerService;
@Resource
private LocationService locationService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryTransactionService inventoryTransactionService;
/**
* 创建立库移库任务
* @param sourceLocationCode 源库位
* @param desLocationCode 目的库位
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult createTransferTask(String sourceLocationCode, String desLocationCode, String warehouseCode) {
Location sourceLocation = locationService.getLocationByCode(sourceLocationCode, warehouseCode);
Location desLocation = locationService.getLocationByCode(desLocationCode, warehouseCode);
Integer preTaskNo = 0;
if (StringUtils.isNull(sourceLocation)) {
return AjaxResult.error("移出(源)库位:" + sourceLocation + "未找到");
}
if (!QuantityConstant.STATUS_LOCATION_EMPTY.equals(sourceLocation.getStatus())) {
return AjaxResult.error("移出(源)库位:" + sourceLocation + "状态非空闲");
}
if (StringUtils.isEmpty(sourceLocation.getContainerCode())) {
return AjaxResult.error("移出(源)库位:" + sourceLocation + "不存在托盘");
}
//这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//校验入库组盘
if (inventoryHeaderService.getUncompleteReceiptContainer(sourceLocationCode, warehouseCode) > 0) {
return AjaxResult.error("移出(源)库位:" + sourceLocation + "存在入库组盘,不能移库");
}
if (inventoryHeaderService.getUncompleteShipmentContainer(sourceLocationCode, warehouseCode) > 0) {
return AjaxResult.error("移出(源)库位:" + sourceLocation + "存在出库组盘,不能移库");
}
if (StringUtils.isNull(desLocation)) {
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "未找到");
}
if (!QuantityConstant.STATUS_LOCATION_EMPTY.equals(desLocation.getStatus())) {
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "状态非空闲");
}
if (StringUtils.isNotEmpty(desLocation.getContainerCode())) {
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "存在托盘");
}
if (taskHeaderService.getUncompleteTaskInNear(desLocation) > 0) {
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "旁边存在任务,请完成任务以后再分配");
}
if(!sourceLocation.getRoadway().equals(desLocation.getRoadway())) {
return AjaxResult.error("移入(目标)库位和移出(源)库位不在同一个巷道");
}
if(!sourceLocation.getHigh().equals(desLocation.getHigh())) {
return AjaxResult.error("移入(目标)库位和移出(源)库位高度不一样");
}
if(!sourceLocation.getLocationType().equals(desLocation.getLocationType())) {
return AjaxResult.error("移入(目标)库位和移出(源)库位库位类型不一样");
}
if(!sourceLocation.getArea().equals(desLocation.getArea())) {
return AjaxResult.error("移入(目标)库位和移出(源)库位不在同一个区域");
}
//创建移库任务前,记录托盘的状态
Container container = containerService.getContainerByCode(sourceLocation.getContainerCode());
container.setLastStatus(container.getStatus());
containerService.updateById(container);
if(sourceLocation.getRowFlag() == QuantityConstant.ROW_OUT) {
Location location1 = locationService.getNear(sourceLocation); //内侧库位
String locationCode = location1.getCode();
if(StringUtils.isNotEmpty(location1.getContainerCode())) {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getFromLocation, locationCode)
.eq(TaskHeader::getWarehouseCode, warehouseCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
preTaskNo = taskHeader.getId();
} else {
return AjaxResult.error("移出(源)库位:" + sourceLocationCode + "旁边库位有托盘无法移库");
}
} else {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getToLocation, locationCode)
.eq(TaskHeader::getWarehouseCode, warehouseCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
return AjaxResult.error("移出(源)库位:" + sourceLocationCode + "旁边库位有任务无法移库");
}
}
}
TaskHeader taskHeader = new TaskHeader();
// taskHeader.setCompanyCode(in);
taskHeader.setWarehouseCode(warehouseCode);
taskHeader.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_WORK);
taskHeader.setZoneCode(sourceLocation.getZoneCode());
taskHeader.setContainerCode(sourceLocation.getContainerCode());
taskHeader.setFromLocation(sourceLocationCode);
taskHeader.setToLocation(desLocationCode);
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
taskHeader.setPreTaskNo(preTaskNo);
LambdaUpdateWrapper<InventoryDetail> detailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
detailLambdaUpdateWrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode);
detailLambdaUpdateWrapper.eq(InventoryDetail::getLocationCode, sourceLocationCode);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(detailLambdaUpdateWrapper);
if(inventoryDetailList!=null&&inventoryDetailList.size()>0){
taskHeader.setCompanyCode(inventoryDetailList.get(0).getCompanyCode());
}
if (!taskHeaderService.save(taskHeader)) {
throw new ServiceException("创建任务失败");
}
locationService.updateStatus(sourceLocationCode, QuantityConstant.STATUS_LOCATION_LOCK, warehouseCode);
locationService.updateStatus(desLocationCode, QuantityConstant.STATUS_LOCATION_LOCK, warehouseCode);
containerService.updateLocationCodeAndStatus(sourceLocation.getContainerCode(),
sourceLocationCode, QuantityConstant.STATUS_CONTAINER_LOCK, warehouseCode);
for (InventoryDetail inventoryDetail : inventoryDetailList) {
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(taskHeader.getId());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());;
taskDetail.setCompanyCode(inventoryDetail.getCompanyCode());
taskDetail.setMaterialCode(inventoryDetail.getMaterialCode());
taskDetail.setMaterialName(inventoryDetail.getMaterialName());
taskDetail.setMaterialSpec(inventoryDetail.getMaterialSpec());
taskDetail.setMaterialUnit(inventoryDetail.getMaterialUnit());
taskDetail.setQty(inventoryDetail.getQty());
taskDetail.setFromLocation(inventoryDetail.getLocationCode());
taskDetail.setToLocation(desLocationCode);
taskDetail.setContainerCode(inventoryDetail.getContainerCode());
taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
taskDetail.setReferenceCode(inventoryDetail.getReferCode());
taskDetail.setAttribute1(inventoryDetail.getAttribute1());
taskDetail.setAttribute2(inventoryDetail.getAttribute2());
taskDetail.setAttribute3(inventoryDetail.getAttribute3());
taskDetail.setBatch(inventoryDetail.getBatch());
taskDetail.setLot(inventoryDetail.getLot());
taskDetail.setProjectNo(inventoryDetail.getProjectNo());
taskDetail.setManufactureDate(inventoryDetail.getManufactureDate());
taskDetail.setExpirationDate(inventoryDetail.getExpirationDate());
taskDetail.setAgingDate(inventoryDetail.getAgingDate());
taskDetail.setInventorySts(inventoryDetail.getInventorySts());
taskDetail.setFromInventoryId(inventoryDetail.getId());
taskDetail.setToInventoryId(inventoryDetail.getId());
if (!taskDetailService.save(taskDetail) || !inventoryDetailService.updateById(inventoryDetail)) {
throw new ServiceException("创建任务失败");
}
}
return AjaxResult.success(taskHeader.getId());
}
/**
* 完成移库任务
* @param taskHeader
*/
public AjaxResult completeTransferTask(TaskHeader taskHeader) {
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskDetail> taskDetailList = taskDetailService.findByTaskId(taskHeader.getId());
/* 库存头表id*/
List<Integer> inventoryHeadIdList = new ArrayList<>();
String warehouseCode = taskHeader.getWarehouseCode();
InventoryDetail inventoryDetail = null;
Container container1 = containerService.getContainerByCode(
taskHeader.getContainerCode(), warehouseCode);
container1.setMovementCount(container1.getMovementCount() + 1);
containerService.updateById(container1);
for (TaskDetail taskDetail : taskDetailList) {
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
inventoryDetail = inventoryDetailService.getById(taskDetail.getToInventoryId());
inventoryHeadIdList.add(inventoryDetail.getInventoryHeaderId());
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setWarehouseCode(taskDetail.getWarehouseCode());
inventoryTransaction.setCompanyCode(taskDetail.getCompanyCode());
inventoryTransaction.setLocationCode(taskDetail.getToLocation());
inventoryTransaction.setContainerCode(taskDetail.getContainerCode());
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_TRANSFERINTO);
inventoryTransaction.setMaterialCode(taskDetail.getMaterialCode());
inventoryTransaction.setMaterialName(taskDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(taskDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(taskDetail.getMaterialUnit());
inventoryTransaction.setTaskQty(taskDetail.getQty());
inventoryTransaction.setInventorySts(taskDetail.getInventorySts());
inventoryTransaction.setReferCode(taskDetail.getReferenceCode());
inventoryTransaction.setBatch(taskDetail.getBatch());
inventoryTransaction.setLot(taskDetail.getLot());
inventoryTransaction.setProjectNo(taskDetail.getProjectNo());
inventoryTransaction.setQcCheck(taskDetail.getQcCheck());
inventoryTransaction.setManufactureDate(taskDetail.getManufactureDate());
inventoryTransaction.setExpirationDate(taskDetail.getExpirationDate());
inventoryTransaction.setAgingDate(taskDetail.getAgingDate());
inventoryTransaction.setAttributeId(String.valueOf(taskDetail.getAttributeId()));
inventoryTransaction.setAttribute1(taskDetail.getAttribute1());
inventoryTransaction.setAttribute2(taskDetail.getAttribute2());
inventoryTransaction.setAttribute3(taskDetail.getAttribute3());
inventoryTransactionService.save(inventoryTransaction);
inventoryTransaction.setLocationCode(taskDetail.getFromLocation());
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_TRANSFEROUT);
inventoryTransactionService.save(inventoryTransaction);
}
if (taskDetailList.size() != 0 ){
taskDetailService.saveOrUpdateBatch(taskDetailList);
}
if (!taskHeaderService.saveOrUpdate(taskHeader)) {
throw new ServiceException("任务单据状态更新失败!");
}
if(inventoryDetail != null) {
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),
taskHeader.getToLocation(), QuantityConstant.STATUS_CONTAINER_SOME, warehouseCode);
} else {
Container container = containerService.getContainerByCode(taskHeader.getContainerCode());
if(container.getLastStatus().equalsIgnoreCase(QuantityConstant.STATUS_CONTAINER_MANY)) {
//恢复托盘组的状态
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),
taskHeader.getToLocation(), QuantityConstant.STATUS_CONTAINER_MANY, warehouseCode);
container = containerService.getContainerByCode(taskHeader.getContainerCode());
container.setLastStatus(QuantityConstant.EMPTY_STRING);
containerService.updateById(container);
}else {
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),
taskHeader.getToLocation(), QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
}
}
locationService.updateContainerCodeAndStatus(taskHeader.getFromLocation(), "",
QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
locationService.updateContainerCodeAndStatus(taskHeader.getToLocation(), taskHeader.getContainerCode(),
QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
inventoryHeadIdList = inventoryHeadIdList.stream().distinct().collect(Collectors.toList());
LambdaUpdateWrapper<InventoryHeader> headerUpdateWrapper = Wrappers.lambdaUpdate();
headerUpdateWrapper.set(InventoryHeader::getLocationCode, taskHeader.getToLocation())
.in(InventoryHeader::getId, inventoryHeadIdList);
LambdaUpdateWrapper<InventoryDetail> detailUpdateWrapper = Wrappers.lambdaUpdate();
detailUpdateWrapper.set(InventoryDetail::getLocationCode, taskHeader.getToLocation())
.in(InventoryDetail::getInventoryHeaderId, inventoryHeadIdList);
if (inventoryHeadIdList.size() != 0) {
if (!inventoryHeaderService.update(headerUpdateWrapper) ||
!inventoryDetailService.update(detailUpdateWrapper)) {
throw new ServiceException("完成任务失败");
}
}
return AjaxResult.success("完成移库任务成功");
}
}