ZY
2024-08-16 7178ac3731005f2829fa9cca16dc125fc34ec12e
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java
@@ -21,18 +21,40 @@
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskDetlService taskDetlService;
    @Autowired
    private TaskDetlFieldService taskDetlFieldService;
    @Autowired
    private LocService locService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private LocDetlFieldService locDetlFieldService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    @Autowired
    private TaskDetlLogService taskDetlLogService;
    @Autowired
    private TaskDetlFieldLogService taskDetlFieldLogService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Scheduled(cron = "0/3 * * * * ? ")
    @Transactional
@@ -51,11 +73,11 @@
                switch (task.getTaskType().intValue()) {
                    case 1://入库
                        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId));
                        if(loc == null) {
                        if (loc == null) {
                            throw new CoolException("库位不存在");
                        }
                        if(loc.getLocStsId() != LocStsType.S.val()){
                        if (loc.getLocStsId() != LocStsType.S.val()) {
                            throw new CoolException("库位状态不处于S.入库预约");
                        }
@@ -68,7 +90,7 @@
                        List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId());
                        if(taskDetls.isEmpty()) {
                        if (taskDetls.isEmpty()) {
                            throw new CoolException("任务明细不存在");
                        }
@@ -94,6 +116,7 @@
                                locDetlField.setDetlId(locDetl.getId());
                                locDetlField.setFieldId(detlField.getFieldId());
                                locDetlField.setName(detlField.getName());
                                locDetlField.setValue(detlField.getValue());
                                locDetlField.setHostId(hostId);
                                if (!locDetlFieldService.save(locDetlField)) {
                                    throw new CoolException("插入明细扩展字段失败");
@@ -101,8 +124,21 @@
                            }
                        }
                        //删除组托通知档
                        waitPakinService.remove(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()).eq(WaitPakin::getHostId, hostId));
                        //组托通知档转历史档
                        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()).eq(WaitPakin::getHostId, hostId));
                        if (waitPakins.isEmpty()) {
                            throw new CoolException("组托通知档不存在");
                        }
                        for (WaitPakin waitPakin : waitPakins) {
                            WaitPakinLog waitPakinLog = new WaitPakinLog();
                            waitPakinLog.sync(waitPakin);
                            if (!waitPakinLogService.save(waitPakinLog)) {
                                throw new CoolException("组托通知档转历史档失败");
                            }
                            //删除组托通知档
                            waitPakinService.removeById(waitPakin.getId());
                        }
                        break;
                }
@@ -116,7 +152,7 @@
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }finally {
        } finally {
            InterceptorIgnoreHelper.clearIgnoreStrategy();
        }
    }
@@ -126,11 +162,60 @@
    public void outExecute() {
        InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
        try {
            //获取出库完成任务
            List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, 199));
            if (list.isEmpty()) {
                return;
            }
            for (Task task : list) {
                //同步数据
                Long hostId = task.getHostId();
                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
                if (loc == null) {
                    throw new CoolException("库位不存在");
                }
                if (loc.getLocStsId() != LocStsType.R.val()) {
                    throw new CoolException("库位状态不处于R.出库预约");
                }
                List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId());
                if (taskDetls.isEmpty()) {
                    throw new CoolException("任务明细不存在");
                }
                switch (task.getTaskType().intValue()) {
                    //出库
                    case 101:
                        loc.setLocStsId(LocStsType.O.val());
                        loc.setBarcode("");
                        if (!locService.updateById(loc)) {
                            throw new CoolException("库位状态更新失败");
                        }
                        List<LocDetl> detlList = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, loc.getId()).eq(LocDetl::getHostId, hostId));
                        //删除库存明细
                        for (LocDetl locDetl : detlList) {
                            if (!locDetlService.removeById(locDetl)) {
                                throw new CoolException("删除库存明细失败");
                            }
                            List<LocDetlField> detlFields = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId()).eq(LocDetlField::getHostId, hostId));
                            for (LocDetlField detlField : detlFields) {
                                if (!locDetlFieldService.removeById(detlField)) {
                                    throw new CoolException("删除明细扩展字段失败");
                                }
                            }
                        }
                        break;
                }
                task.setTaskSts(200L);//200.库存更新完成
                if (!taskService.updateById(task)) {
                    throw new CoolException("库存更新失败");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }finally {
        } finally {
            InterceptorIgnoreHelper.clearIgnoreStrategy();
        }
    }