Blame view

src/main/java/com/huaheng/pc/task/taskHeader/service/TaskHeaderServiceImpl.java 70.5 KB
mahuandong authored
1
2
package com.huaheng.pc.task.taskHeader.service;
pengcheng authored
3
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
wangyanxiong authored
4
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
5
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
pengcheng authored
6
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
wangyanxiong authored
7
import com.huaheng.common.exception.service.ServiceException;
wangyanxiong authored
8
import com.huaheng.common.utils.DataUtils;
wangyanxiong authored
9
import com.huaheng.common.utils.StringUtils;
pengcheng authored
10
11
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
xqs authored
12
import com.huaheng.pc.config.container.domain.Container;
wangyanxiong authored
13
import com.huaheng.pc.config.container.service.ContainerService;
pengcheng authored
14
15
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
xqs authored
16
17
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
18
import com.huaheng.pc.inventory.cycleCountHeader.domain.CycleCountHeader;
19
import com.huaheng.pc.inventory.cycleCountHeader.service.CycleCountHeaderService;
pengcheng authored
20
21
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
22
23
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
wangyanxiong authored
24
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
25
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
xqs authored
26
27
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
mahuandong authored
28
29
30
31
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
xqs authored
32
33
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
pengcheng authored
34
35
36
37
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
wangyanxiong authored
38
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
39
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
40
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
41
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
pengcheng authored
42
43
44
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
xqs authored
45
import org.apache.poi.ss.formula.functions.T;
46
import org.jsoup.helper.DataUtil;
mahuandong authored
47
import org.springframework.stereotype.Service;
pengcheng authored
48
import java.math.BigDecimal;
wangyanxiong authored
49
50
import java.text.SimpleDateFormat;
import java.util.ArrayList;
pengcheng authored
51
import java.util.Date;
mahuandong authored
52
import java.util.List;
wangyanxiong authored
53
import java.util.Map;
54
import java.util.*;
xqs authored
55
56
import java.util.concurrent.CopyOnWriteArrayList;
mahuandong authored
57
58
59
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
pengcheng authored
60
61
import org.springframework.transaction.annotation.Transactional;
wangyanxiong authored
62
63
import javax.annotation.Resource;
mahuandong authored
64
@Service
wangyanxiong authored
65
public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHeader> implements TaskHeaderService {
mahuandong authored
66
xqs authored
67
68
69
    @Resource
pengcheng authored
70
    private ShipmentContainerHeaderService shipmentContainerHeaderService;
71
    @Resource
pengcheng authored
72
    private ShipmentContainerDetailService shipmentContainerDetailService;
73
    @Resource
pengcheng authored
74
    private LocationService locationService;
75
    @Resource
xqs authored
76
77
    private ContainerService containerService;
    @Resource
pengcheng authored
78
    private TaskDetailService taskDetailService;
79
    @Resource
wangyanxiong authored
80
    private TaskHeaderService taskHeaderService;
81
    @Resource
82
    private InventoryHeaderService inventoryHeaderService;
83
84
85
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
xqs authored
86
    private InventoryTransactionService inventoryTransactionService;
87
    @Resource
xqs authored
88
    private ReceiptHeaderService receiptHeaderService;
mahuandong authored
89
90
    @Resource
    private ReceiptDetailService receiptDetailService;
xqs authored
91
    @Resource
xqs authored
92
    private ReceiptContainerDetailService receiptContainerDetailService;
93
94
95
96
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
xqs authored
97
98
    @Resource
    private CycleCountDetailService cycleCountDetailService;
mahuandong authored
99
    @Resource
100
101
    private CycleCountHeaderService cycleCountHeaderService;
    @Resource
mahuandong authored
102
    private ReceiptContainerHeaderService receiptContainerHeaderService;
xqs authored
103
    @Resource
104
    private TaskHeaderMapper taskHeaderMapper;
xqs authored
105
mahuandong authored
106
xqs authored
107
pengcheng authored
108
    /**
xqs authored
109
     * 查询容器有无任务
xqs authored
110
     */
xqs authored
111
112
113
114
    @Override
    public Integer UncompleteCount(String ContainerCode) {
        return taskHeaderMapper.UncompleteCount(ContainerCode, ShiroUtils.getWarehouseCode());
    }
wangyanxiong authored
115
116
117
118
119
    /**
     * 取消任务
     * */
    @Override
xqs authored
120
    @Transactional
121
122
123
124
125
126
127
128
129
    public AjaxResult cancelTask(Integer[] taskIds) {
        for(int taskId : taskIds){
            TaskHeader taskHeader = taskHeaderService.getById(taskId);
            if(taskHeader==null){
                return AjaxResult.error("任务"+taskId+"未找到,操作中止");
            }
            if(taskHeader.getStatus() > 9){
                return AjaxResult.error("存在任务"+taskHeader.getId()+"已下发或执行,操作中止");
            }
xqs authored
130
131
132
133
134
135
136
137
138
139
140
            //查出任务明细
            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);
            TaskDetail taskDetail = taskDetailList.get(0);
            if(taskDetail == null){
                throw new ServiceException("任务明细条目错误");
            }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
            //删除子任务
            LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(TaskDetail::getTaskId,taskHeader.getId());
            taskDetailService.remove(lambdaQueryWrapper);
            //删除主任务
            taskHeaderService.removeById(taskHeader.getId());
            // 更改库位状态(整盘入库任务除外)
            if(taskHeader.getInternalTaskType() == 100 )
            {
                ReceiptContainerHeader record =new ReceiptContainerHeader();
                record.setStatus((short)0);
                record.setId(taskHeader.getAllocationHeadId());
                receiptContainerHeaderService.updateById(record);
            }
            //根据任务类型来更新货箱状态
            //修改关联的货箱状态
            if(taskHeader.getInternalTaskType() == 200)  {
                ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
                shipmentContainerHeader.setId(taskHeader.getAllocationHeadId());
                shipmentContainerHeader.setStatus(0);
                shipmentContainerHeaderService.updateById(shipmentContainerHeader);
            }
xqs authored
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
            //盘点取消任务,恢复明细状态为1
            if(taskHeader.getInternalTaskType() == 700)   {

                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.setTaskHeaderId(null);
                    item.setLastUpdated(new Date());
                    item.setLastUpdatedBy(ShiroUtils.getLoginName());
                    item.setEnableStatus(1);
                    cycleCountDetailService.saveOrUpdate(item);
                }

            }
185
186
187
188
189
190
191
192
193
194
195
196
197
198
            if(taskHeader.getInternalTaskType()==100||taskHeader.getInternalTaskType()==200){
                if(taskHeader.getToLocation()!=null){
                    //更新托盘、库位状态
                    locationService.updateStatus(taskHeader.getToLocation(), "empty");
                }
            }
//            if(task.getType()==900){
//                //出库查看任务没有关联的货箱,不做处理
//            }
        }

        return AjaxResult.success("取消任务成功!");
    }
pengcheng authored
199
200
    /**
     * 生成出库任务
wangyanxiong authored
201
     *
pengcheng authored
202
203
204
205
206
     * @param shipmentTaskCreateModel
     * @return
     */
    @Override
    @Transactional
wangyanxiong authored
207
    public AjaxResult createTaskFromShipmentContainers(ShipmentTaskCreateModel shipmentTaskCreateModel) {
pengcheng authored
208
209
210
        Integer shipmentContainerHeaderId = shipmentTaskCreateModel.getShipmentContainerHeaderIds();
        //获取表头
        ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(shipmentContainerHeaderId);
wangyanxiong authored
211
        if (shipmentContainerHeader == null) {
pengcheng authored
212
213
            return AjaxResult.error("出库货箱" + shipmentContainerHeaderId + "未找到,操作中止");
        }
wangyanxiong authored
214
        if (shipmentContainerHeader.getStatus() > 9) {
pengcheng authored
215
216
217
            return AjaxResult.error("出库货箱" + shipmentContainerHeader.getContainerCode() + "已经生成任务,请不要重复生成,操作中止");
        }
        //获取所有子货箱
wangyanxiong authored
218
219
        LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentContainerDetail::getShippingContainerId, shipmentContainerHeader.getId());
pengcheng authored
220
        List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(lambdaQueryWrapper);
wangyanxiong authored
221
        if (shipmentContainerDetails == null || shipmentContainerDetails.size() == 0) {
pengcheng authored
222
223
224
            return AjaxResult.error("货箱" + shipmentContainerHeader.getContainerCode() + "没有子任务,操作中止");
        }
        //检测库位
wangyanxiong authored
225
226
227
228
        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
        locationLambdaQueryWrapper.eq(Location::getCode, shipmentContainerHeader.getLocationCode())
                .eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(Location::getDeleted, false);
pengcheng authored
229
        Location location = locationService.getOne(locationLambdaQueryWrapper);
wangyanxiong authored
230
        if (location == null) {
pengcheng authored
231
232
233
234
235
236
            return AjaxResult.error("库位禁用或不存在!");
        }
        //创建任务头
        TaskHeader task = new TaskHeader();
        //分拣出库
        task.setTaskType(400);
237
        task.setFromLocation(shipmentContainerHeader.getLocationCode());
mahuandong authored
238
        task.setToLocation(shipmentContainerHeader.getLocationCode());
pengcheng authored
239
        //判断是否整出任务,钱柜和AGV不能整出
wangyanxiong authored
240
        if (shipmentContainerHeader.getStatus().intValue() == 300) {
pengcheng authored
241
242
243
244
245
246
            //表示整出优先
            //判断当前子货箱所有数量是否等于该托盘对应的所有库存的数量,
            //这里必须与库存的在库数量对比,后期可能存在一个配盘在执行任务,后一个配盘又在配这个的情况(这个时候不能整出)
            // 如果相等,则说明这个货箱包含了所有的数量,则可以整出,否则,创建拣选任务;
            //查询所有库存
            InventoryDetail inventoryCondition = new InventoryDetail();
wangyanxiong authored
247
248
249
            LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
            inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getLocationCode, shipmentContainerHeader.getLocationCode())
                    .eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
pengcheng authored
250
            List<InventoryDetail> inventories = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
wangyanxiong authored
251
252
            BigDecimal inventoryTotal = new BigDecimal("0");
            for (InventoryDetail item : inventories) {
pengcheng authored
253
254
255
                inventoryTotal = inventoryTotal.add(item.getQty());
            }
            BigDecimal containerTotal = new BigDecimal("0");
wangyanxiong authored
256
            for (ShipmentContainerDetail item : shipmentContainerDetails) {
pengcheng authored
257
258
                containerTotal = containerTotal.add(item.getQty());
            }
wangyanxiong authored
259
            if (inventoryTotal.compareTo(containerTotal) == 0) {
pengcheng authored
260
                task.setTaskType(300);//整盘出库
mahuandong authored
261
                task.setToLocation("");
pengcheng authored
262
263
            }
        }
264
        task.setInternalTaskType(200);
265
        task.setAllocationHeadId(shipmentContainerHeader.getId());
pengcheng authored
266
267
268
269
        task.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
        task.setCompanyCode(shipmentContainerHeader.getCompanyCode());
        task.setAssignedUser(ShiroUtils.getLoginName());
        task.setConfirmedBy(ShiroUtils.getLoginName());
270
        task.setStatus(0);
pengcheng authored
271
272
273
274
275
276
277
        task.setContainerCode(shipmentContainerHeader.getContainerCode());
        task.setCreatedBy(ShiroUtils.getLoginName());
        task.setCreated(new Date());
        task.setLastUpdatedBy(ShiroUtils.getLoginName());
        task.setLastUpdated(null);
        this.save(task);
        //遍历子货箱创建子任务
wangyanxiong authored
278
        for (ShipmentContainerDetail shipmentContainerDetail : shipmentContainerDetails) {
pengcheng authored
279
280
            TaskDetail taskDetail = new TaskDetail();
            taskDetail.setTaskId(task.getId());
281
            taskDetail.setInternalTaskType(task.getInternalTaskType());
pengcheng authored
282
283
            taskDetail.setWarehouseCode(task.getWarehouseCode());
            taskDetail.setCompanyCode(task.getCompanyCode());
284
            taskDetail.setTaskType(task.getTaskType());
pengcheng authored
285
            taskDetail.setToInventoryId(shipmentContainerDetail.getInventoryId());
286
            taskDetail.setAllocationId(shipmentContainerDetail.getId());
pengcheng authored
287
288
289
290
            taskDetail.setBillCode(shipmentContainerDetail.getShipmentCode());
            taskDetail.setBillDetailId(shipmentContainerDetail.getShipmentDetailId());
            taskDetail.setMaterialCode(shipmentContainerDetail.getMaterialCode());
            taskDetail.setMaterialName(shipmentContainerDetail.getMaterialName());
pengcheng authored
291
292
            taskDetail.setMaterialSpec(shipmentContainerDetail.getMaterialSpec());
            taskDetail.setMaterialUnit(shipmentContainerDetail.getMaterialUnit());
pengcheng authored
293
294
295
            taskDetail.setFromInventoryId(shipmentContainerDetail.getInventoryId());
            taskDetail.setQty(shipmentContainerDetail.getQty());
            taskDetail.setContainerCode(task.getContainerCode());
mahuandong authored
296
297
            taskDetail.setFromLocation(task.getFromLocation());
            taskDetail.setToLocation(task.getToLocation());
298
            taskDetail.setStatus(0);
pengcheng authored
299
            taskDetail.setInventorySts(shipmentContainerDetail.getInventorySts());
300
            taskDetail.setTaskType(task.getTaskType());
pengcheng authored
301
302
303
304
305
306
307
308
309
310
311
312
            taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
            taskDetail.setLastUpdated(null);
            taskDetailService.save(taskDetail);
        }
        //更新货位状态
        ShipmentContainerHeader record = new ShipmentContainerHeader();
        record.setId(shipmentContainerHeaderId);
        record.setStatus(10);
        shipmentContainerHeaderService.saveOrUpdate(record);
        return AjaxResult.success(task.getId());

    }
wangyanxiong authored
313
wangyanxiong authored
314
    /**
315
     *下发WCS执行任务
wangyanxiong authored
316
317
     * 执行任务
     * */
wangyanxiong authored
318
    @Override
319
    @Transactional
wangyanxiong authored
320
    public AjaxResult<TaskHeader> sendTaskToWcs(Integer[] taskIds) {
wangyanxiong authored
321
322
        TaskHeader task = null;
        for (Integer taskId : taskIds) {
wangyanxiong authored
323
            task = taskHeaderService.getById(taskId);
324
wangyanxiong authored
325
            if (task.getStatus() > 9) {
wangyanxiong authored
326
327
328
                return AjaxResult.error("任务" + taskId + "已经下发,请不要重复下发,操作中止");
            }
            //修改任务头表
329
            task.setId(taskId);
wangyanxiong authored
330
331
332
333
            task.setStatus(10);
            task.setStartPickDateTime(new Date());   //生成时间
            task.setLastUpdated(new Date());
            task.setLastUpdatedBy(ShiroUtils.getLoginName());
334
            taskHeaderService.saveOrUpdate(task);
wangyanxiong authored
335
            //修改任务明细状态
336
337
338
339
340
341
342
343
344
345
346
347
348
349
            LambdaQueryWrapper<TaskDetail> lambdaWrapper = Wrappers.lambdaQuery();
            lambdaWrapper.eq(TaskDetail::getTaskId, task.getId());
            List<TaskDetail> taskDetailList = taskDetailService.list(lambdaWrapper);
            List<TaskDetail> taskDetails = new ArrayList<>();
            for (TaskDetail item:taskDetailList){
                item.setStatus(10);
                item.setLastUpdated(new Date());
                item.setLastUpdatedBy(ShiroUtils.getLoginName());
                item.setProcessStamp("100");
                taskDetails.add(item);
                //盘点执行修改盘点单据状态为10
                if(task.getTaskType() == 700){
                    cycleCountDetailService.updataDetailStatus(item.getBillDetailId(),10);
                }
350
            }
351
            if (!taskDetailService.saveOrUpdateBatch(taskDetails)){
352
353
                throw new ServiceException("更新任务明细失败");
            }
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
//            //修改入库明细
//            if (task.getInternalTaskType()==100){
//                ReceiptDetail receiptDetail = receiptDetailService.queryflow(receiptDetailService.getById(record.getId()));
//                if (!receiptDetailService.updateById(receiptDetail)){
//                    throw new ServiceException("更新状态失败");
//                }
//                receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
//
//                //修改组盘表状态为20
//                ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
//                receiptContainerDetail.setStatus(20);
//                receiptContainerDetail.setLastUpdated(new Date());
//                receiptContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
//                LambdaUpdateWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
//                receiptContainerDetailLambdaUpdateWrapper.eq(ReceiptContainerDetail::getReceiptId,receiptDetail.getReceiptId());
//                if (! receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaUpdateWrapper))
//                    throw new ServiceException("更新组盘状态失败");
//            }
//
//            //修改出库单状态
//            if (task.getInternalTaskType()==200){
//                LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
//                taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId,task.getId());
//               List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
//
//                for (TaskDetail taskDeatails: taskDetailList) {
//                    LambdaQueryWrapper<ShipmentDetail> shipmentDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
//                    shipmentDetailLambdaQueryWrapper.eq(ShipmentDetail::getId,taskDeatails.getBillDetailId());
//
//                    ShipmentHeader shipmentHeader =new ShipmentHeader();
//                    shipmentHeader.setId(shipmentDetailService.getOne(shipmentDetailLambdaQueryWrapper).getShipmentId());
//                    shipmentHeader.setFirstStatus(100);
//                    shipmentHeader.setLastStatus(100);
//                    shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
//                    shipmentHeader.setLastUpdated(new Date());
//                    shipmentHeaderService.updateById(shipmentHeader);
//                }
//            }
wangyanxiong authored
395
        }
xqs authored
396
        return AjaxResult.success("执行下发任务成功", task);
wangyanxiong authored
397
398
399
    }

    @Override
xqs authored
400
401
    @Transactional
    public AjaxResult completeTaskByWMS(Integer[] taskIds)  {
wangyanxiong authored
402
403
404
405
406
407
408
409
410
411
        for (int taskId : taskIds) {
            TaskHeader task = taskHeaderService.getById(taskId);
            if (task == null) {
                throw new ServiceException("任务" + taskId + "未找到,执行中止");
            }
            //如果已完成则不管
            if (task.getStatus() == 100) {
                throw new ServiceException("任务(" + taskId + ")任务已经是完成的!");
            }
            //如果没有库位不能完成
mahuandong authored
412
            if (StringUtils.isEmpty(task.getToLocation())) {
wangyanxiong authored
413
414
415
416
417
418
419
420
421
422
423
424
425
                throw new ServiceException("任务" + taskId + "没有库位,执行中止");
            }
            this.completeTask(task);
        }

        return AjaxResult.success("完成任务成功!");
    }

    /**
     * 完成任务
     *
     * @param task
     */
xqs authored
426
427
    @Transactional
    public void completeTask(TaskHeader task) {
wangyanxiong authored
428
        //区分任务类型
429
        if (task.getTaskType() == 100) {
wangyanxiong authored
430
431
432
            //入库任务
            completeReceiptTask(task);
        }
433
        if (task.getTaskType() == 200) {
434
435
//            出库任务
            completeShipmentTask(task);
wangyanxiong authored
436
        }
437
        // 900 出库查看,空托出库查看
438
439
        if ( task.getTaskType() == 900) {
            completeSeeOutTask(task);
wangyanxiong authored
440
        }
441
442
443
444
445
        // 700 盘点
        if ( task.getTaskType() == 700) {
            completeCycleCountTask(task);
        }
        if (task.getTaskType() == 800) {
xqs authored
446
//          //移库
447
            completeTransferTask(task);
wangyanxiong authored
448
        }
449
        if (task.getTaskType() == 500) {
xqs authored
450
451
            //空托盘入库
           completeEmptyIn(task);
wangyanxiong authored
452
        }
453
        if (task.getTaskType() == 600) {
xqs authored
454
455
           //空托盘出库
            completeEmptyOut(task);
wangyanxiong authored
456
457
458
        }
    }
459
460

    /**
461
     *完成入库任务
xqs authored
462
     */
wangyanxiong authored
463
    @Override
464
    @Transactional
xqs authored
465
    public AjaxResult completeReceiptTask(TaskHeader task){
xqs authored
466
467
        List<Map<String, Object>> taskReceiptContainerDetail = taskHeaderMapper.getReceiptTask(task.getId());
        if (taskReceiptContainerDetail.size() < 1) {
468
469
            return AjaxResult.success("未找到对应任务的入库单号!!!");
        }
wangyanxiong authored
470
471
472
        for (Map<String, Object> map : taskReceiptContainerDetail) {
            //将未完成的任务数量更新到库存表
            if (DataUtils.getInteger(map.get("status")) < 100) {
xqs authored
473
474
475
476
477
478
479
                LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
                inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
                        .eq(InventoryDetail::getLocationCode, task.getFromLocation())
                        .eq(InventoryDetail::getReceiptDetailId, DataUtils.getString(map.get("receiptDetailId")))
                        .eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("containerCode")));
                InventoryDetail detail = inventoryDetailService.getOne(inventory);
                if (detail == null) {
480
481
482
483
484
                    //添加库存单
                    InventoryHeader header = new InventoryHeader();
                    header.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));//仓库
                    header.setCompanyCode(task.getCompanyCode());//货主
                    header.setContainerCode(DataUtils.getString(map.get("containerCode")));//容器号
485
                    header.setLocationCode(task.getToLocation());
486
487
488
489
490
491
                    header.setTotalQty(DataUtils.getInteger(map.get("totalQty")));//总数量
                    header.setLocking(1);
                    header.setEnable(1);
                    header.setCreatedBy(ShiroUtils.getLoginName());
                    header.setCreated(new Date());
                    header.setLastUpdated(new Date());
wangyanxiong authored
492
493
494
                    if (!inventoryHeaderService.save(header))
                        throw new ServiceException("添加库存单失败");
495
496
497
498
499
                    //库存明细添加
                    detail = new InventoryDetail();
                    detail.setInventoryHeaderId(header.getId());//库存头ID
                    detail.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));//仓库
                    detail.setCompanyCode(task.getCompanyCode());//货主
mahuandong authored
500
                    detail.setLocationCode(task.getToLocation());//库位号
501
502
503
504
505
                    detail.setContainerCode(DataUtils.getString(map.get("containerCode")));//容器号
                    detail.setMaterialCode(DataUtils.getString(map.get("materialCode")));//物料号
                    detail.setMaterialName(DataUtils.getString(map.get("materialName")));//物料名称
                    detail.setMaterialSpec(DataUtils.getString(map.get("materialSpec")));//物料规格
                    detail.setReceiptCode(DataUtils.getString(map.get("receiptCode")));//入库单编码
xqs authored
506
                    detail.setReceiptDetailId(DataUtils.getInteger(map.get("receiptDetailId")));//入库单明细ID
507
508
509
                    detail.setBatch(DataUtils.getString(map.get("batch")));//批次
                    detail.setLot(DataUtils.getString(map.get("lot")));//批号
                    detail.setInventorySts(DataUtils.getString(map.get("inventorySts")));//库存状态
xqs authored
510
//                    detail.setManufactureDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("manufactureDate").toString()));//生产日期
511
//                    detail.setExpirationDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("expirationDate").toString()));//失效日期
512
                    detail.setQty(DataUtils.getBigDecimal(map.get("qty")));//数量
513
                    detail.setTaskQty(DataUtils.getBigDecimal(0));
514
515
                    detail.setCreatedBy(ShiroUtils.getLoginName());//创建人
                    detail.setLastUpdatedBy(ShiroUtils.getLoginName());//创建时间
wangyanxiong authored
516
517
                    if (!inventoryDetailService.save(detail))
                        throw new ServiceException("添加库存明细失败");
518
519
                    }
                 else {
520
521
522
                    detail.setQty(detail.getQty().add(DataUtils.getBigDecimal(map.get("qty"))));
                    detail.setLastUpdatedBy(ShiroUtils.getLoginName());
                    LambdaUpdateWrapper<InventoryDetail> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
xqs authored
523
                    lambdaUpdateWrapper.eq(InventoryDetail::getId,DataUtils.getInteger(map.get("receiptDetailId")));
524
                    if (!inventoryDetailService.update(detail, lambdaUpdateWrapper))
wangyanxiong authored
525
                        throw new ServiceException("更新入库单明细失败");
526
527
528
529
530
531
532
                }
                //记录库存交易记录
                InventoryTransaction inventoryTransaction = new InventoryTransaction();
                inventoryTransaction.setTransactionType(10);
                inventoryTransaction.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));
                inventoryTransaction.setCompanyCode(task.getCompanyCode());
mahuandong authored
533
                inventoryTransaction.setLocationCode(task.getToLocation());
534
535
536
537
                inventoryTransaction.setContainerCode(DataUtils.getString(map.get("containerCode")));
                inventoryTransaction.setMaterialCode(DataUtils.getString(map.get("materialCode")));
                inventoryTransaction.setMaterialName(DataUtils.getString(map.get("materialName")));
                inventoryTransaction.setBillCode(DataUtils.getString(map.get("receiptCode")));
xqs authored
538
                inventoryTransaction.setBillDetailId(DataUtils.getInteger(map.get("receiptDetailId")));
539
540
                inventoryTransaction.setBatch(DataUtils.getString(map.get("batch")));
                inventoryTransaction.setLot(DataUtils.getString(map.get("lot")));
xqs authored
541
//                inventoryTransaction.setManufactureDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("manufactureDate").toString()));//生产日期
542
//                inventoryTransaction.setExpirationDate(DataUtils.getDateTime(map.get("expirationDate")));
543
                inventoryTransaction.setInventorySts(DataUtils.getString((map.get("inventorySts"))));
xqs authored
544
                inventoryTransaction.setTaskQty(DataUtils.getBigDecimal(map.get("qty")));
545
546
                inventoryTransaction.setCreated(new Date());
                inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
547
548
                if (!inventoryTransactionService.save(inventoryTransaction))
                    throw new ServiceException("新增库存记录失败");
xqs authored
549
550
551
552
553
554
                //修改任务明细的状态为完成
                TaskDetail taskDetail = new TaskDetail();
                taskDetail.setStatus(100);
                taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
                taskDetail.setAgingDate(new Date());   //入库时间
                LambdaUpdateWrapper<TaskDetail> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
555
                lambdaUpdateWrapper.eq(TaskDetail::getTaskId,task.getId());
xqs authored
556
                taskDetailService.update(taskDetail, lambdaUpdateWrapper);
557
558
559
                if ( !taskDetailService.update(taskDetail, lambdaUpdateWrapper)){
                    throw new ServiceException("修改入库单明细失败");
                }
xqs authored
560
xqs authored
561
                //修改任务主表状态,因为立库任务表单头只对应一个货箱,表单详情的任务会同时完成
xqs authored
562
563
564
565
566
                task.setStatus(100);
                task.setLastUpdatedBy(ShiroUtils.getLoginName());
                task.setLastUpdated(new Date());
                LambdaUpdateWrapper<TaskHeader> taskHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
                taskHeaderLambdaUpdateWrapper.eq(TaskHeader::getId, task.getId());
wangyanxiong authored
567
568
                if (!taskHeaderService.update(task, taskHeaderLambdaUpdateWrapper))
                    throw new ServiceException("更新任务主表失败");
569
570
571

                //修改库位状态和对应的容器
                Location location = new Location();
xqs authored
572
573
                location.setContainerCode(task.getContainerCode());
                location.setStatus("empty");
574
                LambdaUpdateWrapper<Location> locationLambdaUpdateWrapper = Wrappers.lambdaUpdate();
mahuandong authored
575
                locationLambdaUpdateWrapper.eq(Location::getCode, task.getToLocation());
576
                if (!locationService.update(location,locationLambdaUpdateWrapper))
wangyanxiong authored
577
                    throw new ServiceException("更新库位失败");
578
579
580

                //修改容器状态和对应的库位
                Container container = new Container();
mahuandong authored
581
                container.setLocationCode(task.getToLocation());
xqs authored
582
                container.setStatus("some");
583
                LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
wangyanxiong authored
584
                containerLambdaUpdateWrapper.eq(Container::getCode, task.getContainerCode());
585
                if (!containerService.update(container, containerLambdaUpdateWrapper)){
wangyanxiong authored
586
                    throw new ServiceException("更新容器失败");
587
588
                }
               //修改组盘表状态为20
mahuandong authored
589
                ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
wangyanxiong authored
590
                receiptContainerDetail.setStatus(30);
591
592
593
                receiptContainerDetail.setProcessStamp("0");
                receiptContainerDetail.setLastUpdated(new Date());
                receiptContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
mahuandong authored
594
                LambdaUpdateWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
xqs authored
595
                receiptContainerDetailLambdaUpdateWrapper.eq(ReceiptContainerDetail::getReceiptId, DataUtils.getInteger(map.get("receiptId")));
wangyanxiong authored
596
597
                if (! receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaUpdateWrapper))
                    throw new ServiceException("更新组盘状态失败");
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
                //修改入库单状态
                ReceiptHeader receiptHeader = new ReceiptHeader();
                receiptHeader.setFirstStatus(300);
                receiptHeader.setLastStatus(300);
                receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
                receiptHeader.setLastUpdated(new Date());
                LambdaUpdateWrapper<ReceiptHeader> receiptHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
                receiptHeaderLambdaUpdateWrapper.eq(ReceiptHeader::getId,DataUtils.getInteger(map.get("receiptId")));
                if (! receiptHeaderService.update(receiptHeader, receiptHeaderLambdaUpdateWrapper))
                    throw new ServiceException("更新入库状态失败");
//                if (task.getInternalTaskType()==100){
//                    //修改入库明细
//                    ReceiptDetail receiptDetail = receiptDetailService.queryflow(receiptDetailService.getById(DataUtils.getInteger(map.get("receiptDetailId"))));
//                    if (!receiptDetailService.updateById(receiptDetail)){
//                        throw new ServiceException("更新状态失败");
//                    }
//                    receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
616
//                }
617
618
619
620
            }
wangyanxiong authored
621
        }
mahuandong authored
622
        return AjaxResult.success("完成入库任务");
wangyanxiong authored
623
    }
wangyanxiong authored
624
625
626
627
628
629

//    @Override
//    public List<Map<String, Object>> getReceiptTask(Integer taskId) {
//        return taskHeaderMapper.getReceiptTask(taskId) ;
//    }
xqs authored
630
    /**
631
     * 生成
xqs authored
632
     * 立库移库
xqs authored
633
     */
xqs authored
634
    @Transactional
635
    public AjaxResult createTransferTask(String sourceLocation, String destinationLocation) {
xqs authored
636
637
638
        //源库位校验
        Location temp1 = new Location();
xqs authored
639
        temp1.setCode(sourceLocation);
640
641
642
        temp1.setWarehouseCode(ShiroUtils.getWarehouseCode());
        LambdaQueryWrapper<Location> lambda1 = Wrappers.lambdaQuery();
        Location loc1 = locationService.getOne(lambda1);
xqs authored
643
644
        if (loc1 == null) {
            return AjaxResult.error("源库位:" + sourceLocation + "未找到");
xqs authored
645
        }
xqs authored
646
647
        if (!loc1.getStatus().equals("empty")) {
            return AjaxResult.error("源库位:" + sourceLocation + "状态非空闲");
xqs authored
648
        }
xqs authored
649
650
        if (StringUtils.isEmpty(loc1.getContainerCode())) {
            return AjaxResult.error("源库位:" + sourceLocation + "不存在托盘");
xqs authored
651
652
653
        }
        //这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
        //校验入库组盘
xqs authored
654
655
656
        int count1 = inventoryHeaderService.getUncompleteReceiptContainer(sourceLocation, ShiroUtils.getWarehouseCode());
        if (count1 > 0) {
            return AjaxResult.error("源库位:" + sourceLocation + "存在入库组盘,不能移库");
xqs authored
657
        }
xqs authored
658
659
660
        int count2 = inventoryHeaderService.getUncompleteShipmentContainer(sourceLocation, ShiroUtils.getWarehouseCode());
        if (count2 > 0) {
            return AjaxResult.error("源库位:" + sourceLocation + "存在出库组盘,不能移库");
xqs authored
661
        }
662
        //目的库位校验
xqs authored
663
        Location temp2 = new Location();
664
        temp2.setWarehouseCode(ShiroUtils.getWarehouseCode());
xqs authored
665
        temp2.setCode(destinationLocation);
666
667
        LambdaQueryWrapper<Location> lambdaQueryWrapper2 = Wrappers.lambdaQuery(temp2);
        Location loc2 = locationService.getOne(lambdaQueryWrapper2);
xqs authored
668
669
        if (loc2 == null) {
            return AjaxResult.error("目标库位:" + destinationLocation + "未找到");
xqs authored
670
        }
xqs authored
671
672
        if (!loc2.getStatus().equals("empty")) {
            return AjaxResult.error("目标库位:" + destinationLocation + "状态非空闲");
xqs authored
673
        }
xqs authored
674
675
        if (StringUtils.isNotEmpty(loc2.getContainerCode())) {
            return AjaxResult.error("目标库位:" + destinationLocation + "已存在托盘");
xqs authored
676
        }
xqs authored
677
678
679
        int count3 = inventoryHeaderService.getUncompleteReceiptContainer(destinationLocation, ShiroUtils.getWarehouseCode());
        if (count3 > 0) {
            return AjaxResult.error("目标库位:" + sourceLocation + "存在入库组盘,不能移库");
xqs authored
680
        }
681
682
683
684
        //写入任务主表和明细表
        TaskHeader taskHeader = new TaskHeader();
        taskHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        taskHeader.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));//获取第一个货主
xqs authored
685
        taskHeader.setInternalTaskType(500);
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
        taskHeader.setTaskType(800);
        taskHeader.setContainerCode(loc1.getContainerCode());
        taskHeader.setStatus(1);
        taskHeader.setFromLocation(sourceLocation);
        taskHeader.setToLocation(destinationLocation);
        taskHeader.setCreated(new Date());
        taskHeader.setCreatedBy(ShiroUtils.getLoginName());
        taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        taskHeader.setLastUpdated(new Date());
        taskHeaderMapper.insert(taskHeader);

        //写入明细表
        TaskDetail taskDetail = new TaskDetail();
        taskDetail.setTaskId(taskHeader.getId());//主单ID
        taskDetail.setTaskType(taskHeader.getTaskType());
        taskDetail.setInternalTaskType(taskHeader.getTaskType());
        taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
        taskDetail.setCompanyCode(taskDetail.getCompanyCode());
        taskDetail.setFromLocation(sourceLocation);
        taskDetail.setToLocation(destinationLocation);
        taskDetail.setContainerCode(taskHeader.getContainerCode());
        taskDetail.setCreated(new Date());
        taskDetail.setCreatedBy(ShiroUtils.getLoginName());
        taskDetail.setLastUpdated(new Date());
        taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
        taskDetailService.save(taskDetail);
xqs authored
713
714
715
        //更新货位状态为预定
        loc1.setStatus("lock");
        loc2.setStatus("lock");
716
717
718
719
720
721
722
723
        locationService.saveOrUpdate(loc1);
        locationService.saveOrUpdate(loc2);
        return AjaxResult.success(taskHeader.getId());

    }

    /**
     * 完成移库任务
xqs authored
724
     *
725
726
     * @param task
     */
xqs authored
727
    @Transactional
xqs authored
728
    public void completeTransferTask(TaskHeader task) {
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
        //找到任务明细
        TaskDetail taskDetail = new TaskDetail();
        taskDetail.setTaskId(task.getId());
        taskDetail.setWarehouseCode(task.getWarehouseCode());
        taskDetail.setCompanyCode(task.getCompanyCode());
        taskDetail.setContainerCode(task.getContainerCode());
        LambdaQueryWrapper<TaskDetail> taskDetailLW = Wrappers.lambdaQuery(taskDetail);
        taskDetail = taskDetailService.getOne(taskDetailLW);
        //更新库存主表和明细的库位,更改更新用户和时间
        InventoryHeader inventoryHeader = new InventoryHeader();
        //主表
        inventoryHeader.setWarehouseCode(taskDetail.getWarehouseCode());
        inventoryHeader.setCompanyCode(taskDetail.getCompanyCode());
        inventoryHeader.setContainerCode(taskDetail.getContainerCode());
        inventoryHeader.setLocationCode(taskDetail.getFromLocation());//通过源库位查找库存
        LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryHeader);
        inventoryHeader = inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper);
        inventoryHeader.setLocationCode(taskDetail.getToLocation());//把目的库位写入库存
        inventoryHeader.setLastUpdated(new Date());
        inventoryHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        inventoryHeaderService.saveOrUpdate(inventoryHeader);//修改主表库位

        //明细表
        List<InventoryDetail> inventoryDetails = new ArrayList<>();
        InventoryDetail inventoryDetail = new InventoryDetail();
        inventoryDetail.setWarehouseCode(inventoryHeader.getWarehouseCode());
        inventoryDetail.setCompanyCode(inventoryHeader.getCompanyCode());
        inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryDetail);
xqs authored
758
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
759
760
        /*同时写入库存交易表*/
        List<InventoryTransaction> inventoryTransactionList = new ArrayList<>();
xqs authored
761
        for (InventoryDetail item : inventoryDetailList) {
762
763
764
765
            item.setLocationCode(inventoryHeader.getLocationCode());//修改明细表库位
            item.setLastUpdated(new Date());
            item.setLastUpdatedBy(ShiroUtils.getLoginName());
            inventoryDetails.add(item);
xqs authored
766
            /*----------*/
767
768
769
770
771
772
773
774
775
776
            InventoryTransaction inventoryTransaction = new InventoryTransaction();
            inventoryTransaction.setWarehouseCode(task.getWarehouseCode());
            inventoryTransaction.setLocationCode(taskDetail.getToLocation());
            inventoryTransaction.setContainerCode(taskDetail.getContainerCode());
            inventoryTransaction.setTransactionType(50);
            inventoryTransaction.setMaterialCode(item.getMaterialCode());
            inventoryTransaction.setManufactureDate(item.getManufactureDate());
            inventoryTransaction.setMaterialName(item.getMaterialName());
            inventoryTransaction.setMaterialSpec(item.getMaterialSpec());
            inventoryTransaction.setMaterialUnit(item.getMaterialUnit());
xqs authored
777
            inventoryTransaction.setTaskQty(BigDecimal.ZERO);
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
            inventoryTransaction.setInventorySts(item.getInventorySts());
            //inventoryTransaction.setReferCode();
            //inventoryTransaction.setQcCheck();
            inventoryTransaction.setReferDetailId(item.getId().toString());
            inventoryTransaction.setBatch(item.getBatch());
            inventoryTransaction.setLot(item.getLot());
            inventoryTransaction.setProjectNo(item.getProjectNo());
            inventoryTransaction.setWeight(item.getWeight());
            inventoryTransaction.setManufactureDate(item.getManufactureDate());
            inventoryTransaction.setExpirationDate(item.getExpirationDate());
            inventoryTransaction.setAgingDate(item.getCreated());
            inventoryTransaction.setAttributeId(item.getAttributeId());
            inventoryTransaction.setAttribute1(item.getAttribute1());
            inventoryTransaction.setAttribute2(item.getAttribute2());
            inventoryTransaction.setAttribute3(item.getAttribute3());
            inventoryTransaction.setCreated(new Date());
            inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
            //inventoryTransaction.setLockCode();
            inventoryTransaction.setBillCode(item.getInventoryHeaderId().toString());
            inventoryTransaction.setBillDetailId(item.getId());
            inventoryTransaction.setSupplierCode(item.getSupplierCode());
            inventoryDetailList.add(inventoryDetail);
        }
xqs authored
801
        if (inventoryDetailService.saveOrUpdateBatch(inventoryDetails)) {
802
803
            //更新库存明细成功后,写入库存交易
            inventoryTransactionService.saveBatch(inventoryTransactionList);
xqs authored
804
        } else {
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
            throw new ServiceException("库存明细更新错误!");
        }

        //更新托盘、库位状态
        Location temp1 = new Location(); //源库位
        temp1.setCode(taskDetail.getFromLocation());
        temp1.setWarehouseCode(ShiroUtils.getWarehouseCode());
        LambdaQueryWrapper<Location> lambdaQueryWrapper1 = Wrappers.lambdaQuery(temp1);
        Location loc1 = locationService.getOne(lambdaQueryWrapper1);

        Location temp2 = new Location();//目的库位
        temp2.setCode(taskDetail.getToLocation());
        temp2.setWarehouseCode(ShiroUtils.getWarehouseCode());
        LambdaQueryWrapper<Location> lambdaQueryWrapper2 = Wrappers.lambdaQuery(temp2);
        Location loc2 = locationService.getOne(lambdaQueryWrapper2);
        loc2.setContainerCode(loc1.getContainerCode());
        loc2.setStatus("empty");
        loc1.setContainerCode("");
        loc1.setStatus("empty");
        locationService.saveOrUpdate(loc1);
        locationService.saveOrUpdate(loc2);
        //更新taskHeader状态
        task.setStatus(100);
        task.setLastUpdatedBy(ShiroUtils.getLoginName());
        task.setLastUpdated(new Date());
        taskHeaderService.saveOrUpdate(task);
        //更新taskDetail状态
        taskDetail.setStatus(100);
        taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
        taskDetail.setLastUpdated(new Date());
        taskDetailService.saveOrUpdate(taskDetail);
xqs authored
837
838
    }
839
    /**
xqs authored
840
841
     * 生成
     * 出库查看
842
     * 任务
xqs authored
843
     */
844
845
846
847
    @Override
    @Transactional
    public AjaxResult createCheckOutTask(String[] ids) {
xqs authored
848
849
        for (String id : ids) {
            InventoryHeader inventoryHeader = inventoryHeaderService.getById(Integer.parseInt(id));
850
851
852
853
854
855
            //检查库位容器
            Location temp = new Location();
            temp.setCode(inventoryHeader.getLocationCode());
            temp.setWarehouseCode(inventoryHeader.getWarehouseCode());
            LambdaQueryWrapper<Location> lambdaQueryWrapper = Wrappers.lambdaQuery(temp);
            Location loc = locationService.getOne(lambdaQueryWrapper);
xqs authored
856
            if (loc == null) {
857
858
                throw new ServiceException("库存没有库位!");
            }
xqs authored
859
860
            if (!loc.getStatus().equals("empty")) {
                throw new ServiceException(inventoryHeader.getLocationCode() + "状态非空闲,操作失败");
861
            }
xqs authored
862
863
            if (StringUtils.isEmpty(loc.getContainerCode())) {
                throw new ServiceException(inventoryHeader.getLocationCode() + "没有容器,操作失败");
864
865
866
867
868
869
870
            }
            //通过库存头,找到库存明细
            InventoryDetail inventoryDetail = new InventoryDetail();
            inventoryDetail.setWarehouseCode(inventoryHeader.getWarehouseCode());
            inventoryDetail.setCompanyCode(inventoryHeader.getCompanyCode());
            inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
            LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryDetail);
xqs authored
871
            List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
872
873
874
875
876

            //写入任务主表
            TaskHeader taskHeader = new TaskHeader();
            taskHeader.setWarehouseCode(inventoryHeader.getWarehouseCode());
            taskHeader.setCompanyCode(inventoryHeader.getCompanyCode());//货主
877
            taskHeader.setInternalTaskType(400);
878
879
880
881
882
883
884
885
886
887
888
889
            taskHeader.setTaskType(900);
            taskHeader.setContainerCode(inventoryHeader.getContainerCode());
            taskHeader.setStatus(1);
            taskHeader.setFromLocation(inventoryHeader.getLocationCode());
            taskHeader.setToLocation(inventoryHeader.getLocationCode());
            taskHeader.setCreated(new Date());
            taskHeader.setCreatedBy(ShiroUtils.getLoginName());
            taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
            taskHeader.setLastUpdated(new Date());
            taskHeaderMapper.insert(taskHeader);
            //分拆库存明细,并写入任务细表
            List<TaskDetail> taskDetails = new ArrayList<>();
xqs authored
890
            for (InventoryDetail item : inventoryDetailList) {
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
                TaskDetail taskDetail = new TaskDetail();
                taskDetail.setTaskId(taskHeader.getId());//主单ID
                taskDetail.setTaskType(taskHeader.getTaskType());
                taskDetail.setInternalTaskType(taskHeader.getTaskType());
                taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
                taskDetail.setCompanyCode(item.getCompanyCode());
                taskDetail.setFromLocation(taskHeader.getFromLocation());
                taskDetail.setToLocation(taskHeader.getToLocation());
                taskDetail.setContainerCode(taskHeader.getContainerCode());
                taskDetail.setCreated(new Date());
                taskDetail.setCreatedBy(ShiroUtils.getLoginName());
                taskDetail.setLastUpdated(new Date());
                taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
                taskDetails.add(taskDetail);
xqs authored
906
907
908
909
910
911
912
            }
            if (taskDetailService.saveBatch(taskDetails)) {
                //锁定库位状态
                locationService.updateStatus(loc.getContainerCode(), "lock");
            } else {
                throw new ServiceException("出库查看任务明细生成失败!");
            }
913
914
915
916
        }
        return AjaxResult.success("出库查看任务生成成功!");
    }
917
918
    /**
xqs authored
919
     * 完成
920
     * 出库查看
921
     * 更新状态即可
xqs authored
922
     */
923
924
    @Transactional
    @Override
925
    public AjaxResult completeSeeOutTask(TaskHeader taskHeader) {
926
927
928
929
930
931
932
933
934
935
        taskHeader.setStatus(100);
        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);//查询子单
936
937
        List<TaskDetail> list = new CopyOnWriteArrayList<>();
        for(TaskDetail item:taskDetailList){
938
939
940
            item.setStatus(100);
            item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
            item.setLastUpdated(new Date());   //更新时间
941
            list.add(item);
942
        }
943
944
        if (taskDetailService.saveOrUpdateBatch(list) == false ||
                taskHeaderService.saveOrUpdate(taskHeader) == false) {
945
946
            throw new ServiceException("任务单据状态更新失败!");
        }
947
948
        //释放库位状态
         locationService.updateStatus(taskHeader.getFromLocation(), "empty");
xqs authored
949
950
951
952
        return AjaxResult.success("完成出库查看任务");
    }

    /**
953
954
955
956
957
958
959
     * 盘点完成
     * @param taskHeader
     * @return
     */
    @Transactional
    @Override
    public AjaxResult completeCycleCountTask(TaskHeader taskHeader){
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
        /*盘点完成,传入任务主单,查出任务明细,通过任务明细查找盘点的明细单,
        完成任务同时,修改盘点细单和主单的状态,完成后库存锁复位*/
        //修改任务主单状态
        taskHeader.setStatus(100);
        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);//查询子单
        List<TaskDetail> list = new CopyOnWriteArrayList<>();
        //修改任务明细状态的同时查找到盘点明细的条目并修改状态,最后修改主单状态
        List<CycleCountDetail> cycleCountDetailList = new CopyOnWriteArrayList<>();
        for(TaskDetail item:taskDetailList){
            item.setStatus(100);
            item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
            item.setLastUpdated(new Date());   //更新时间
            list.add(item);
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
            CycleCountDetail cycleCountDetail = cycleCountDetailService.getById(item.getBillDetailId());//盘点明细
            cycleCountDetail.setEnableStatus(100);
            cycleCountDetail.setCompletedBy(ShiroUtils.getLoginName());
            cycleCountDetail.setCompletedAt(new Date());
            cycleCountDetailList.add(cycleCountDetail);
            //取消库存盘点锁
            InventoryDetail inventoryDetail = inventoryDetailService.getById(cycleCountDetail.getInventoryDetailId());
            inventoryDetail.setLockCode("");
            inventoryDetailService.saveOrUpdate(inventoryDetail);
        }
        if ( taskHeaderService.saveOrUpdate(taskHeader) == false ||
                taskDetailService.saveOrUpdateBatch(list) == false ||
                cycleCountDetailService.saveOrUpdateBatch(cycleCountDetailList) == false) {
            throw new ServiceException("盘点任务单据状态更新失败!");
        }
        //更新主单状态
        cycleCountHeaderService.updataHeaderStatus(cycleCountDetailList.get(0).getCycleCountHeadCode());
        //释放库位
        locationService.updateStatus(cycleCountDetailList.get(0).getLocationCode(), "empty");
        return AjaxResult.success("完成盘点任务");
1002
1003
1004
1005

    }

    /**
xqs authored
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
     * 完成空托盘入库任务
     * @param taskHeader
     */
    @Transactional
    public void completeEmptyIn(TaskHeader taskHeader) {

        //完成任务,修改主单和明细状态
        taskHeader.setStatus(100);
        taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        taskHeader.setLastUpdated(new Date());
        //taskHeaderService.saveOrUpdate(taskHeader);
        //taskDetail更新明细单总的状态
        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);//查询子单
        for (TaskDetail item : taskDetailList) {
            item.setStatus(100);
            item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
            item.setLastUpdated(new Date());   //更新时间
            taskDetailList.add(item);
        }
1030
1031
        if (taskDetailService.saveOrUpdateBatch(taskDetailList) == false ||
                taskHeaderService.saveOrUpdate(taskHeader) == false) {
xqs authored
1032
1033
            throw new ServiceException("任务单据状态更新失败!");
        }
1034
1035
1036
1037
        //解锁容器,更新库位
        containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),taskHeader.getToLocation(),"empty");
        //解锁库位,更新容器
        locationService.updateContainerCodeAndStatus(taskHeader.getToLocation(),taskHeader.getContainerCode(),"empty");
xqs authored
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067

    }

    /**
     * 完成空托盘出库任务
     * @param taskHeader
     */
    @Transactional
    public void completeEmptyOut(TaskHeader taskHeader) {

        taskHeader.setStatus(100);
        taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        taskHeader.setLastUpdated(new Date());
        //taskHeaderService.saveOrUpdate(taskHeader);
        //taskDetail更新明细单总的状态
        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);//查询子单
        for (TaskDetail item : taskDetailList) {
            item.setStatus(100);
            item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
            item.setLastUpdated(new Date());   //更新时间
            taskDetailList.add(item);
        }
        if (taskDetailService.saveOrUpdateBatch(taskDetailList) == false || taskHeaderService.saveOrUpdate(taskHeader) == false) {
            throw new ServiceException("任务单据状态更新失败!");
        }
1068
1069
1070
1071
1072
        //更新货位
        locationService.updateContainerCodeAndStatus(taskHeader.getFromLocation(), "", "empty");
        //更新容器信息
        containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(), "", "empty");
xqs authored
1073
1074
    }
mahuandong authored
1075
1076
1077
1078
1079
1080
    /**
     * 创建上架任务
     * @param ids
     * @return
     */
    @Override
1081
    @Transactional
mahuandong authored
1082
    public AjaxResult createReceiptTask(List<Integer> ids) {
xqs authored
1083
        for (Integer id : ids) {
mahuandong authored
1084
1085
1086
            ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(id);
            if (receiptContainerHeader == null)
                throw new ServiceException("任务不存在!");
1087
            if (!receiptContainerHeader.getWarehouseCode().equals(ShiroUtils.getWarehouseCode()))
mahuandong authored
1088
                throw new ServiceException("任务不在当前仓库!");
1089
1090
1091
1092
1093
1094
1095
1096
1097

            //锁定容器
            Container container = new Container();
            container.setStatus("lock");
            LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
            containerUpdateWrapper.eq(Container::getCode, receiptContainerHeader.getContainerCode());
            containerService.update(container, containerUpdateWrapper);

            //查询入库组盘明细
mahuandong authored
1098
            LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
xqs authored
1099
            containerDetailLambda.eq(ReceiptContainerDetail::getReceiptContainerId, id);
mahuandong authored
1100
            List<ReceiptContainerDetail> list = receiptContainerDetailService.list(containerDetailLambda);
1101
mahuandong authored
1102
1103
1104
1105
            if (list.size() < 1)
                throw new ServiceException("没有组盘明细,请先组盘!");
            if (receiptContainerHeader.getStatus() == 0) {
                if (receiptContainerHeader.getStatus().intValue() < 10) {
xqs authored
1106
                    receiptContainerHeader.setStatus((short) 10);
mahuandong authored
1107
1108
1109
1110
                    receiptContainerHeaderService.updateById(receiptContainerHeader);
                }
                //添加任务主表
                TaskHeader task = new TaskHeader();
1111
                task.setInternalTaskType(100);
mahuandong authored
1112
1113
1114
1115
1116
1117
1118
1119
1120
                task.setWarehouseCode(receiptContainerHeader.getWarehouseCode());
                task.setCompanyCode(receiptContainerHeader.getCompanyCode());
                task.setFromLocation(receiptContainerHeader.getFromLocation());
                task.setTaskType(Integer.valueOf(receiptContainerHeader.getTaskType()));
                task.setFromLocation(receiptContainerHeader.getFromLocation());
                task.setToLocation(receiptContainerHeader.getToLocation());
                task.setContainerCode(receiptContainerHeader.getContainerCode());
                task.setCreated(new Date());
                task.setCreatedBy(ShiroUtils.getLoginName());
1121
1122
1123
1124
1125
                if (this.save(task)){
                    //添加任务明细表
                    for(ReceiptContainerDetail item : list) {
                        TaskDetail taskDetail = new TaskDetail();
                        taskDetail.setTaskId(task.getId());
xqs authored
1126
                        taskDetail.setTaskType(Integer.valueOf(receiptContainerHeaderService.getById(item.getReceiptContainerId()).getTaskType()));
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
                        taskDetail.setInternalTaskType(100);
                        taskDetail.setWarehouseCode(task.getWarehouseCode());
                        taskDetail.setCompanyCode(task.getCompanyCode());
                        taskDetail.setCompanyCode(task.getCompanyCode());
                        taskDetail.setMaterialCode(item.getMaterialCode());
                        taskDetail.setMaterialName(item.getMaterialName());
                        taskDetail.setBillCode(item.getReceiptCode());
                        taskDetail.setBillDetailId(item.getReceiptDetailId());
                        taskDetail.setBillCode(item.getReceiptCode());
                        taskDetail.setQty(BigDecimal.valueOf(item.getQty()));
                        taskDetail.setContainerCode(task.getContainerCode());
                        taskDetail.setFromLocation(task.getFromLocation());
                        taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
                        taskDetail.setBatch(item.getBatch());
                        if (!taskDetailService.save(taskDetail)){
                            throw new ServiceException("生成任务明细失败");
                        }
mahuandong authored
1145
1146
                        //更新入库组盘明细状态
                        item.setStatus(10);
1147
1148
1149
                        if (!receiptContainerDetailService.updateById(item)){
                            throw new ServiceException("更新入库组盘明细状态出错");
                        }
mahuandong authored
1150
1151
1152
1153
1154
1155
1156
                        ReceiptDetail receiptDetail = receiptDetailService.getById(item.getReceiptDetailId());
                        if ("300".equals(receiptDetail.getProcessStamp())){
                            ReceiptDetail detail = receiptDetailService.queryflow(receiptDetail);
                            if (!receiptDetailService.updateById(detail)){
                                throw new ServiceException("更新入库单详情失败");
                            }
1157
                            //更新头表状态
1158
                            receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
mahuandong authored
1159
1160
                        }
                    }
1161
1162
                } else {
                    throw new ServiceException("生成任务头表失败");
mahuandong authored
1163
1164
1165
                }
            }
        }
xqs authored
1166
        return  AjaxResult.success("生成上架任务成功!");
mahuandong authored
1167
    }
xqs authored
1168
wangyanxiong authored
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
    /**
     *
     * 完成出库任务
     * */
    @Override
    public void completeShipmentTask(TaskHeader task) {
        //获取所有子任务
        TaskDetail condition = new TaskDetail();
        condition.setTaskId(task.getId());
        LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery(condition);
        List<TaskDetail> taskDetails = taskDetailService.list(lambdaQueryWrapper);
        List<Integer> shipmentHeadIds = new ArrayList<>();
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
        for(TaskDetail taskDetail : taskDetails){
            if(taskDetail.getStatus()<20){
                //获取出库子货箱
                ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getById(taskDetail.getAllocationId());
                //取出子单据
                ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetail.getBillDetailId());
                //暂存id,为更新单据状态准备
                shipmentHeadIds.add(shipmentDetail.getShipmentId());
                //获取对应库存记录
                InventoryDetail inventoryDetail = inventoryDetailService.getById(taskDetail.getToInventoryId());
                if (inventoryDetail == null)  {
                    throw new ServiceException("任务明细对应的库存ID【" + taskDetail.getToInventoryId().toString() + "】不存在!");
                }
                BigDecimal orignalQty = inventoryDetail.getQty();
wangyanxiong authored
1195
1196
1197
1198
                //减扣库存单
                InventoryHeader inventoryHeader = inventoryHeaderService.getById(inventoryDetail.getInventoryHeaderId());
                inventoryHeader.setTotalQty(inventoryDetail.getQty().subtract(taskDetail.getQty()).intValue());
                //扣减库存明细
1199
1200
1201
1202
1203
                inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().subtract(taskDetail.getQty()));
                inventoryDetail.setQty(inventoryDetail.getQty().subtract(taskDetail.getQty()));
                if(inventoryDetail.getQty().compareTo(new BigDecimal("0"))==0 && inventoryDetail.getTaskQty().compareTo(new BigDecimal("0"))==0){
                    //如果库存没有了,就删除这个库存
                    inventoryDetailService.removeById(inventoryDetail.getId());
wangyanxiong authored
1204
                    inventoryHeaderService.removeById(inventoryHeader.getId());
1205
1206
1207
                }else {
                    //否则更新这个库存
                    inventoryDetailService.updateById(inventoryDetail);
wangyanxiong authored
1208
                    inventoryHeaderService.updateById(inventoryHeader);
1209
1210
1211
1212
                }
                //设置子任务状态为已执行
                taskDetail.setStatus(100);
                taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
1213
                taskDetail.setLastUpdated(new Date());//完成时间
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
                taskDetailService.updateById(taskDetail);
                //记录库存交易记录
                InventoryTransaction inventoryTransaction = new InventoryTransaction();
                inventoryTransaction.setWarehouseCode(task.getWarehouseCode());
                inventoryTransaction.setCompanyCode(shipmentDetail.getCompanyCode());
                inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode());
                inventoryTransaction.setContainerCode(inventoryDetail.getContainerCode());
                inventoryTransaction.setTransactionType(20);
                inventoryTransaction.setMaterialCode(shipmentDetail.getMaterialCode());
                //inventory.setMaterialName(DataUtils.getString(taskDetail.getMaterialName()));//物料名称
                inventoryTransaction.setBillCode(taskDetail.getBillCode());
                inventoryTransaction.setBillDetailId(shipmentDetail.getId());
                inventoryTransaction.setBatch(shipmentDetail.getBatch());
                inventoryTransaction.setLot(shipmentDetail.getLot());
                inventoryTransaction.setManufactureDate(shipmentDetail.getManufactureDate());
                inventoryTransaction.setExpirationDate(shipmentDetail.getExpirationDate());
                inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts());
                //这里取反,更符合出库的语义,同时方便对记录进行统计
xqs authored
1232
                inventoryTransaction.setTaskQty(taskDetail.getQty());
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
//                inventoryTransaction.setCostPrice(shipmentDetail.);
                inventoryTransaction.setCreated(null);
                inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
                inventoryTransactionService.save(inventoryTransaction);
//                //更新单据状态
//                shipmentHeaderService.updateShipmentStatus(shipmentHeader.getId());
            }
        }
        //设置主任务为已执行
        task.setStatus(100);
        task.setLastUpdatedBy(ShiroUtils.getLoginName());
        task.setLastUpdated(new Date());
        taskHeaderService.updateById(task);
        //将库位状态改为空闲,如果是整出的对应的容器也清空
        Location locationRecord = new Location();
        locationRecord.setStatus("empty");
        if(task.getTaskType()==300) {
            locationRecord.setContainerCode("");
        }
        LambdaUpdateWrapper<Location> locationLambdaUpdateWrapper = Wrappers.lambdaUpdate();
                locationLambdaUpdateWrapper.eq(Location::getCode,task.getToLocation());
        locationService.update(locationLambdaUpdateWrapper);
        //如果是整出,删掉这个库位上的这个托盘,否则更改托盘状态
        Container containerRecord = new Container();
wangyanxiong authored
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
        if(task.getTaskType()==300) {
            containerService.updateLocationCodeAndStatus(task.getContainerCode(),"","empty");
        }
        else{
            //查询是否存在关联的库存,入如果没有就修改容器状态为empty
            InventoryDetail inventoryCondition = new InventoryDetail();
            inventoryCondition.setLocationCode(task.getToLocation());
            LambdaQueryWrapper<InventoryDetail> inventoryDetaillambdaQueryWrapper = Wrappers.lambdaQuery();
            inventoryDetaillambdaQueryWrapper.eq(InventoryDetail::getLocationCode,task.getToLocation());
            List<InventoryDetail> detailList= inventoryDetailService.list();
            //库存查询不到该容器就把容器状态改为可用
            if (detailList.size()<1) {
                Container container =new Container();
                container.setCode(task.getToLocation());
                condition.setToLocation("");
               LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
               containerLambdaUpdateWrapper.eq(Container::getCode,task.getToLocation());
               containerService.update(containerLambdaUpdateWrapper);
            }
        }
wangyanxiong authored
1277
        //设置出库货箱状态为拣货任务完成
1278
1279
1280
1281
1282
1283
1284
        ShipmentContainerDetail shipmentContainerDetail = new ShipmentContainerDetail();
        shipmentContainerDetail.setStatus(30);
        shipmentContainerDetail.setLastUpdated(new Date());
        shipmentContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
        LambdaUpdateWrapper<ShipmentContainerDetail> shipmentContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        shipmentContainerDetailLambdaUpdateWrapper.eq(ShipmentContainerDetail::getId,task.getAllocationHeadId());
        if (! shipmentContainerDetailService.update(shipmentContainerDetail, shipmentContainerDetailLambdaUpdateWrapper)){
wangyanxiong authored
1285
1286
1287
            throw new ServiceException("更新组盘明细状态失败");
        }
    //设置出库货箱表头状态为拣货任务完成
1288
1289
1290
1291
1292
1293
1294
        ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
        shipmentContainerHeader.setStatus(30);
        shipmentContainerHeader.setLastUpdated(new Date());
        shipmentContainerHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        LambdaUpdateWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        shipmentContainerHeaderLambdaUpdateWrapper.eq(ShipmentContainerHeader::getId,task.getAllocationHeadId());
        if (! shipmentContainerHeaderService.update(shipmentContainerHeader, shipmentContainerHeaderLambdaUpdateWrapper))
wangyanxiong authored
1295
            throw new ServiceException("更新组盘头状态失败");
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315


                   //修改出库单状态
                    LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
                    taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId,task.getId());
                    List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);

                for (TaskDetail taskDeatails: taskDetailList) {
                    LambdaQueryWrapper<ShipmentDetail> shipmentDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
                    shipmentDetailLambdaQueryWrapper.eq(ShipmentDetail::getId,taskDeatails.getBillDetailId());

                    ShipmentHeader shipmentHeader =new ShipmentHeader();
                    shipmentHeader.setId(shipmentDetailService.getOne(shipmentDetailLambdaQueryWrapper).getShipmentId());
                    shipmentHeader.setFirstStatus(100);
                    shipmentHeader.setLastStatus(100);
                    shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
                    shipmentHeader.setLastUpdated(new Date());
                    shipmentHeaderService.updateById(shipmentHeader);
                }
wangyanxiong authored
1316
1317
    }
wangyanxiong authored
1318
xqs authored
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
mahuandong authored
1334
}