|
1
2
3
4
5
6
7
|
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.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
|
|
8
|
import com.huaheng.common.utils.Wrappers;
|
|
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
|
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.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetailChild;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailChildService;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
import com.huaheng.pc.inventory.cycleCountHeader.domain.CycleCountHeader;
import com.huaheng.pc.inventory.cycleCountHeader.service.CycleCountHeaderService;
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.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.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* 盘点服务层
|
|
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
|
@Service
public class CycleCountTaskService {
@Resource
private CycleCountDetailService cycleCountDetailService;
@Resource
private CycleCountHeaderService cycleCountHeaderService;
@Resource
private CycleCountDetailChildService cycleCountDetailChildService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private LocationService locationService;
@Resource
private ContainerService containerService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryDetailService inventoryDetailService;
/**
* 盘点任务取消
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult cycleCountCancelTask(Integer[] taskIds) {
for (int taskId : taskIds) {
TaskHeader taskHeader = taskHeaderService.getById(taskId);
if (taskHeader == null) {
return AjaxResult.error("任务" + taskId + "未找到,操作中止");
}
if (taskHeader.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
return AjaxResult.error("存在任务" + taskHeader.getId() + "已下发或执行,操作中止");
}
//查出任务明细
TaskDetail taskDetail1 = new TaskDetail();
taskDetail1.setTaskId(taskHeader.getId());
taskDetail1.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail1.setCompanyCode(taskHeader.getCompanyCode());
LambdaQueryWrapper<TaskDetail> td = Wrappers.lambdaQuery(taskDetail1);
List<TaskDetail> taskDetailList = taskDetailService.list(td);
if (taskDetailList.size() < 1) {
throw new ServiceException("任务明细条目错误");
}
TaskDetail taskDetail = taskDetailList.get(0);
//删除子任务
LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
taskDetailService.remove(lambdaQueryWrapper);
//删除主任务
taskHeaderService.removeById(taskHeader.getId());
//盘点取消任务,恢复明细状态为1
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_CYCLECOUNT)) {
CycleCountDetail cycleCountDetail = new CycleCountDetail();
cycleCountDetail.setCompanyCode(taskDetail.getCompanyCode());
cycleCountDetail.setWarehouseCode(taskDetail.getWarehouseCode());
cycleCountDetail.setLocationCode(taskDetail.getFromLocation());
cycleCountDetail.setContainerCode(taskDetail.getContainerCode());
cycleCountDetail.setCycleCountHeadCode(taskDetail.getBillCode());//盘点单Code
cycleCountDetail.setId(taskDetail.getBillDetailId());//盘点细单ID
LambdaQueryWrapper<CycleCountDetail> lam = Wrappers.lambdaQuery(cycleCountDetail);
List<CycleCountDetail> cycleCountDetailList = cycleCountDetailService.list(lam);//
for (CycleCountDetail item : cycleCountDetailList) {
item.setTaskHeaderId(null);
item.setTaskDetailId(null);
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setEnableStatus(1);
cycleCountDetailService.saveOrUpdate(item);
}
}
|
|
117
118
|
if (taskHeader.getToLocation() != null) {
//更新托盘、库位状态
|
|
119
|
locationService.updateStatus(taskHeader.getToLocation(), QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
120
121
122
123
124
|
}
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getContainerCode, taskHeader.getContainerCode());
InventoryHeader inventoryHeader = inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper);
Container container = new Container();
|
|
125
|
container.setStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
|
|
126
127
|
if (inventoryHeader != null) {
if (inventoryHeader.getContainerStatus().equals(QuantityConstant.STATUS_CONTAINER_SOME)) {
|
|
128
|
container.setStatus(QuantityConstant.STATUS_CONTAINER_SOME);
|
|
129
130
|
}
}
|
|
131
132
133
|
LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
containerUpdateWrapper.eq(Container::getCode, taskHeader.getContainerCode());
containerService.update(container, containerUpdateWrapper);
|
|
134
135
136
137
138
139
140
|
}
return AjaxResult.success("取消任务成功!");
}
/**
* 生成单条盘点任务
|
|
141
|
*
|
|
142
143
144
145
146
147
148
149
|
* @param cycleCoutDetailId
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult createCycleCoutTaskByDetailId(Integer cycleCoutDetailId) {
/*任务主表中存在库位,在盘点明细中生成任务时,不同的容器生成不同的主任务*/
//校验有没有相同容器正在执行任务.
CycleCountDetail cycleCountDetail = cycleCountDetailService.getById(cycleCoutDetailId);
|
|
150
|
if (StringUtils.isNull(cycleCountDetail)) {
|
|
151
152
153
154
155
156
157
158
|
return AjaxResult.error("盘点明细ID错误,没有该条明细");
}
//查出明细的子单
CycleCountDetailChild child = new CycleCountDetailChild();
child.setCycleCountHeadCode(cycleCountDetail.getCycleCountHeadCode());
child.setCycleCountDetailId(cycleCountDetail.getId());
LambdaQueryWrapper<CycleCountDetailChild> childLambdaQueryWrapper = Wrappers.lambdaQuery(child);
List<CycleCountDetailChild> childList = cycleCountDetailChildService.list(childLambdaQueryWrapper);
|
|
159
|
if (childList.size() < 1) {
|
|
160
161
|
return AjaxResult.error("盘点明细没有子单");
}
|
|
162
163
|
Location location = locationService.getLocationByCode(
cycleCountDetail.getLocationCode(), ShiroUtils.getWarehouseCode());
|
|
164
|
/*if(!loc.getStatus().equals(QuantityConstant.STATUS_EMPTY)){
|
|
165
166
|
return AjaxResult.error(cycleCountDetail.getLocationCode() + "库位不在空闲状态,请先完成其他任务,操作失败!");
}*/
|
|
167
|
if (StringUtils.isEmpty(location.getContainerCode())) {
|
|
168
169
170
|
return AjaxResult.error(cycleCountDetail.getLocationCode() + "库位中没有容器,操作失败!");
}
//生成任务同时锁定库位
|
|
171
|
locationService.updateStatus(location.getCode(), QuantityConstant.STATUS_LOCATION_LOCK);
|
|
172
173
174
175
176
|
//每个明细单生成一张主任务,子单就是任务明细。
TaskHeader task = new TaskHeader();
task.setWarehouseCode(ShiroUtils.getWarehouseCode());
task.setCompanyCode(cycleCountDetail.getCompanyCode());
task.setAllocationHeadId(cycleCountDetail.getId());//明细ID写入主任务
|
|
177
|
if (location != null) {
|
|
178
179
|
task.setZoneCode(location.getZoneCode());
}
|
|
180
181
182
183
184
185
186
187
|
task.setReferenceCode(cycleCountDetail.getCycleCountHeadCode()); //写入盘点主单号
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_CYCLECOUNT);
task.setTaskType(QuantityConstant.TASK_TYPE_CYCLECOUNT);
task.setContainerCode(cycleCountDetail.getContainerCode());
task.setStatus(QuantityConstant.TASK_STATUS_BUILD);
task.setFromLocation(cycleCountDetail.getLocationCode());
task.setToLocation(cycleCountDetail.getLocationCode());
task.setCreated(new Date());
|
|
188
|
task.setCreatedBy(ShiroUtils.getUserName());
|
|
189
190
|
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
|
|
191
|
if (taskHeaderService.save(task)) {
|
|
192
|
//锁定库位状态
|
|
193
|
locationService.updateStatus(location.getContainerCode(), QuantityConstant.STATUS_LOCATION_LOCK);
|
|
194
|
cycleCountDetail.setTaskHeaderId(task.getId()); //盘点明细修改状态task数据源
|
|
195
|
} else {
|
|
196
197
198
199
200
|
throw new ServiceException("盘点任务主表生成失败!");
}
//写入任务细表
TaskDetail taskDetail = new TaskDetail();
|
|
201
|
for (CycleCountDetailChild item : childList) {
|
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
taskDetail.setTaskId(task.getId());//主单ID
taskDetail.setTaskType(task.getTaskType());
taskDetail.setFromLocation(task.getFromLocation());
taskDetail.setToLocation(task.getToLocation());
taskDetail.setContainerCode(task.getContainerCode());
taskDetail.setInternalTaskType(task.getTaskType());
taskDetail.setWarehouseCode(task.getWarehouseCode());
taskDetail.setBillCode(item.getCycleCountHeadCode());
taskDetail.setBillDetailId(item.getCycleCountDetailId());
taskDetail.setMaterialCode(item.getMaterialCode());
taskDetail.setMaterialName(item.getMaterialName());
taskDetail.setMaterialSpec(item.getMaterialSpec());
taskDetail.setMaterialUnit(item.getMaterialUnit());
taskDetail.setQty(item.getSystemQty());
//taskDetail.setBatch(cycleCountDetail.getBatch());
//taskDetail.setFromInventoryId(cycleCountDetail.getInventoryDetailId());
//taskDetail.setLot(cycleCountDetail.getLot());
//taskDetail.setProjectNo(cycleCountDetail.getProjectNo());
taskDetail.setCompanyCode(cycleCountDetail.getCompanyCode());
taskDetail.setCreated(new Date());
taskDetail.setCreatedBy(ShiroUtils.getLoginName());
taskDetail.setLastUpdated(new Date());
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
226
|
if (taskDetailService.save(taskDetail) == false) {
|
|
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
|
throw new ServiceException("盘点任务明细生成失败!");
}
// 修改子单状态
item.setChildStatus(QuantityConstant.CYCLECOUNT_STATUS_BUILDTASK);
cycleCountDetailChildService.updateById(item);
}
//修改细单状态
cycleCountDetail.setTaskHeaderId(task.getId()); //盘点明细修改状态task数据源
cycleCountDetail.setLastUpdated(new Date());
cycleCountDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
cycleCountDetail.setEnableStatus(QuantityConstant.CYCLECOUNT_STATUS_BUILDTASK);
cycleCountDetail.setTaskHeaderId(task.getId());
//cycleCountDetail.setTaskDetailId(taskDetail.getId());
cycleCountDetailService.updateById(cycleCountDetail);
//修改主单状态
CycleCountHeader cycleCountHeader = new CycleCountHeader();
cycleCountHeader.setCode(cycleCountDetail.getCycleCountHeadCode());
cycleCountHeader.setWarehouseCode(cycleCountDetail.getWarehouseCode());
//cycleCountHeader.setCompanyCode(cycleCountDetail.getCompanyCode());
LambdaQueryWrapper<CycleCountHeader> lamb = Wrappers.lambdaQuery(cycleCountHeader);
cycleCountHeader = cycleCountHeaderService.getOne(lamb);
cycleCountHeader.setStatusCyc(QuantityConstant.CYCLECOUNT_STATUS_BUILDTASK);
cycleCountHeaderService.updateById(cycleCountHeader);
return AjaxResult.success("盘点任务生成成功");
}
/**
* 盘点完成
|
|
257
258
|
* 盘点有差异完成时状态为105
*
|
|
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
* @param taskHeader
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult completeCycleCountTask(TaskHeader taskHeader) {
/*盘点完成,传入任务主单,查出任务明细,通过任务明细查找盘点的明细单,
完成任务同时,修改盘点细单和主单的状态,完成后库存锁复位*/
//修改任务主单状态
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
taskHeader.setLastUpdated(new Date()); //更新时间
//task更新明细单状态
TaskDetail taskDetail = new TaskDetail();
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setTaskId(taskHeader.getId());
LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(taskDetail);
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaQueryWrapper);//查询子单
//盘点明细
CycleCountDetail cycleCountDetail = cycleCountDetailService.getById(taskHeader.getAllocationHeadId());
List<TaskDetail> list = new CopyOnWriteArrayList<>();
List<CycleCountDetailChild> cycChildList = new ArrayList<>();
boolean difference = false;
|
|
282
|
String warehouseCode = taskHeader.getWarehouseCode();
|
|
283
284
285
286
287
288
289
290
291
292
293
294
|
//修改任务明细状态的同时查找到盘点明细的条目并修改状态,最后修改主单状态
for (TaskDetail item : taskDetailList) {
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
list.add(item);
//盘点子单状态
CycleCountDetailChild cycleCountDetailChild = new CycleCountDetailChild();
cycleCountDetailChild.setCycleCountHeadCode(cycleCountDetail.getCycleCountHeadCode());
cycleCountDetailChild.setCycleCountDetailId(cycleCountDetail.getId());
LambdaQueryWrapper<CycleCountDetailChild> childLambdaQueryWrapper = Wrappers.lambdaQuery(cycleCountDetailChild);
List<CycleCountDetailChild> childList = cycleCountDetailChildService.list(childLambdaQueryWrapper);
|
|
295
296
|
if (childList.size() > 0) {
for (CycleCountDetailChild child : childList) {
|
|
297
|
//判断是否差异状态
|
|
298
|
if (child.getGapQty().compareTo(BigDecimal.ZERO) != 0) {
|
|
299
300
301
|
difference = true;
//有差异
child.setChildStatus(QuantityConstant.CYCLECOUNT_STATUS_DIFFERENCE);
|
|
302
|
} else {
|
|
303
304
305
306
307
308
309
|
child.setChildStatus(QuantityConstant.CYCLECOUNT_STATUS_COMPLETED);
}
cycChildList.add(child);
}
}
//取消库存盘点锁
InventoryHeader inventoryHeader = inventoryHeaderService.getById(cycleCountDetail.getInventoryDetailId());
|
|
310
|
if (StringUtils.isNull(inventoryHeader)) {
|
|
311
312
313
314
315
316
317
|
throw new ServiceException("库存头错误!");
}
inventoryHeader.setLocking(1);
inventoryHeader.setLockRemark("");
inventoryHeaderService.updateById(inventoryHeader);
//库存明细最后盘点时间
LambdaQueryWrapper<InventoryDetail> inventoryDetail = Wrappers.lambdaQuery();
|
|
318
319
|
inventoryDetail.eq(InventoryDetail::getWarehouseCode, inventoryHeader.getWarehouseCode())
.eq(InventoryDetail::getInventoryHeaderId, inventoryHeader.getId());
|
|
320
|
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetail);
|
|
321
|
if (inventoryDetailList.size() < 1) {
|
|
322
323
324
325
326
327
328
329
330
331
332
333
|
throw new ServiceException("盘点的库存明细错误!");
}
inventoryDetailList.stream().forEach(i -> i.setLastCycleCountDate(new Date()));
inventoryDetailService.updateBatchById(inventoryDetailList);
}
if (!taskHeaderService.saveOrUpdate(taskHeader) ||
!taskDetailService.saveOrUpdateBatch(list) ||
!cycleCountDetailChildService.saveOrUpdateBatch(cycChildList)
) {
throw new ServiceException("盘点任务单据状态更新失败!");
}
//盘点明细状态
|
|
334
|
if (difference) {
|
|
335
336
|
//有差异
cycleCountDetail.setEnableStatus(QuantityConstant.CYCLECOUNT_STATUS_DIFFERENCE);
|
|
337
|
} else {
|
|
338
339
340
341
342
343
344
345
|
cycleCountDetail.setEnableStatus(QuantityConstant.CYCLECOUNT_STATUS_COMPLETED);
}
cycleCountDetail.setCompletedBy(taskHeader.getCreatedBy());
cycleCountDetail.setCompletedAt(new Date());
cycleCountDetailService.updateById(cycleCountDetail);
//更新主单状态
cycleCountHeaderService.updataHeaderStatus(cycleCountDetail.getCycleCountHeadCode());
//释放库位
|
|
346
347
|
locationService.updateStatus(cycleCountDetail.getLocationCode(),
QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
|
|
348
349
350
351
352
353
354
|
return AjaxResult.success("完成盘点任务成功!");
}
}
|