#
Junjie
2024-08-01 fd5b35e658ac8cd3d9658c5cc5e1219c9d13915c
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/WorkServiceImpl.java
@@ -35,6 +35,12 @@
    private LocService locService;
    @Autowired
    private LocStsService locStsService;
    @Autowired
    private TaskLogService taskLogService;
    @Autowired
    private TaskDetlLogService taskDetlLogService;
    @Autowired
    private TaskDetlFieldLogService taskDetlFieldLogService;
    @Override
    public String generateTaskNo(Long taskType) {
@@ -155,6 +161,34 @@
    }
    @Override
    public boolean completeTask(Long taskId) {
        Task task = taskService.getById(taskId);
        if(task == null){
            throw new CoolException("任务不存在");
        }
        List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(taskId);
        if (taskDetls.isEmpty()) {
            throw new CoolException("任务明细不存在");
        }
        if (task.getTaskType() < 100) {
            //入库
            task.setTaskSts(99L);//99.入库完成
        }else {
            //出库
            task.setTaskSts(199L);//199.出库完成
        }
        task.setUpdateTime(new Date());
        if (!taskService.updateById(task)) {
            throw new CoolException("任务更新失败");
        }
        return true;
    }
    @Override
    @Transactional
    public boolean cancelTask(Long taskId) {
        Task task = taskService.getById(taskId);
@@ -236,10 +270,28 @@
                }
            }
            //删除明细扩展
            boolean removeField = taskDetlFieldService.remove(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
            if(!removeField){
                throw new CoolException("回滚扩展明细失败");
            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
            for (TaskDetlField detlField : detlFields) {
                //明细扩展字段数据保存至历史档
                TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog();
                taskDetlFieldLog.sync(detlField);
                if (!taskDetlFieldLogService.save(taskDetlFieldLog)) {
                    throw new CoolException("明细扩展字段转历史档案失败");
                }
                //删除明细扩展
                boolean removeField = taskDetlFieldService.removeById(detlField.getId());
                if(!removeField){
                    throw new CoolException("回滚扩展明细失败");
                }
            }
            //明细数据保存至历史档
            TaskDetlLog taskDetlLog = new TaskDetlLog();
            taskDetlLog.sync(taskDetl);
            if (!taskDetlLogService.save(taskDetlLog)) {
                throw new CoolException("明细数据转历史档案失败");
            }
            //删除明细
@@ -249,6 +301,13 @@
            }
        }
        //数据保存至历史档
        TaskLog taskLog = new TaskLog();
        taskLog.sync(task);
        if (!taskLogService.save(taskLog)) {
            throw new CoolException("任务档案转历史档案失败");
        }
        //删除任务
        boolean removeTask = taskService.removeById(taskId);
        if(!removeTask){