10 小时以前 74ad846852f42b4e2258bfddd5c2a33cc1ce9847
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/task/MesProTaskServiceImpl.java
@@ -12,6 +12,8 @@
import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationMachineDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessParamDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO;
import cn.iocoder.yudao.module.mes.dal.mysql.pro.task.MesProTaskMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.pro.feedback.MesProFeedbackMapper;
@@ -24,6 +26,7 @@
import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationMachineService;
import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService;
import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService;
import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessParamService;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO;
@@ -50,11 +53,13 @@
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_FEEDBACK_CANNOT_CREATE_WHEN_PAUSED;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_TASK_ALREADY_FINISHED;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_TASK_CANNOT_PAUSE;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_TASK_HAS_FEEDBACK;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_TASK_NOT_EXISTS;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_TASK_NOT_PAUSED;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_TASK_WAIT_NOT_CONFIGURED;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskPauseRecordDO;
@@ -111,6 +116,9 @@
    @Lazy
    private MesProWorkOrderParamRecordService workOrderParamRecordService;
    @Resource
    @Lazy
    private MesProProcessParamService processParamService;
    @Resource
    private MesMdAutoCodeRecordService autoCodeRecordService;
    @Resource
    private MesMdWorkstationMachineService workstationMachineService;
@@ -150,14 +158,28 @@
        }
        // 2.2 插入
        taskMapper.insert(task);
        if (task.getParamTemplateId() != null) {
            workOrderParamRecordService.createTaskParamRecord(task.getId(), task.getParamTemplateId());
        }
        // 2.2.1 参数快照:优先使用模板;无模板时回退到工序主数据绑定的工艺参数
        createTaskParamRecordWithFallback(task);
        // 2.3 保存指定报工人员
        updateTaskAssignees(task.getId(), createReqVO.getAssigneeUserIds());
        return task.getId();
    }
    /**
     * 为任务固化参数快照:优先使用路线/工单工序绑定的参数模板;无模板时回退到工序主数据绑定的工艺参数
     */
    private void createTaskParamRecordWithFallback(MesProTaskDO task) {
        if (task.getParamTemplateId() != null) {
            workOrderParamRecordService.createTaskParamRecord(task.getId(), task.getParamTemplateId());
            return;
        }
        // 无模板:从工序主数据解析绑定的工艺参数
        List<MesProProcessParamDO> processParams = processParamService.getProcessParamListByProcessId(task.getProcessId());
        if (CollUtil.isNotEmpty(processParams)) {
            workOrderParamRecordService.createTaskParamRecordFromProcessParams(task.getId(), processParams);
        }
    }
    @Override
@@ -498,9 +520,8 @@
                    .setClientId(workOrder.getClientId())
                    .setColorCode(rp.getColorCode());
            taskMapper.insert(task);
            if (task.getParamTemplateId() != null) {
                workOrderParamRecordService.createTaskParamRecord(task.getId(), task.getParamTemplateId());
            }
            // 参数快照:优先使用模板;无模板时回退到工序主数据绑定的工艺参数
            createTaskParamRecordWithFallback(task);
            taskIds.add(task.getId());
        }
        // 7. 更新工单已排产数量
@@ -556,4 +577,25 @@
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public LocalDateTime startWaitCountdown(Long taskId) {
        // 1. 校验任务存在且未终态
        MesProTaskDO task = validateTaskNotFinished(taskId);
        // 2. 校验停工状态不能报工
        if (!MesProTaskStatusEnum.canFeedback(task.getStatus())) {
            throw exception(PRO_FEEDBACK_CANNOT_CREATE_WHEN_PAUSED);
        }
        // 3. 校验工序配置了等待时长
        MesProProcessDO process = processService.getProcess(task.getProcessId());
        if (process == null || process.getWaitDuration() == null
                || process.getWaitDuration().compareTo(BigDecimal.ZERO) <= 0) {
            throw exception(PRO_TASK_WAIT_NOT_CONFIGURED);
        }
        // 4. 记录倒计时开始时间(重复点击重置)
        LocalDateTime now = LocalDateTime.now();
        taskMapper.updateById(new MesProTaskDO().setId(taskId).setWaitStartTime(now));
        return now;
    }
}