| | |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.workorder.vo.paramrecord.MesProWorkOrderParamRecordPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.workorder.vo.paramrecord.MesProWorkOrderParamRecordSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pd.processparam.MesPdProcessParamDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pd.processparamtemplate.MesPdProcessParamTemplateDetailDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pd.processparamtemplate.MesPdProcessParamTemplateDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessParamDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderParamRecordDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderParamRecordDetailDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.workorder.MesProWorkOrderParamRecordDetailMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.workorder.MesProWorkOrderParamRecordMapper; |
| | | import cn.iocoder.yudao.module.mes.service.pd.processparam.MesPdProcessParamService; |
| | | import cn.iocoder.yudao.module.mes.service.pd.processparamtemplate.MesPdProcessParamTemplateService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.task.MesProTaskService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | private MesProWorkOrderService workOrderService; |
| | | @Resource |
| | | private MesPdProcessParamTemplateService templateService; |
| | | @Resource |
| | | private MesPdProcessParamService pdProcessParamService; |
| | | @Autowired |
| | | private MesProTaskService mesProTaskService; |
| | | @Autowired |
| | | private MesProWorkOrderService mesProWorkOrderService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createTaskParamRecord(Long taskId, Long templateId) { |
| | | MesProTaskDO task = mesProTaskService.getTask(taskId); |
| | | if (task == null || templateId == null) { |
| | | return null; |
| | | } |
| | | MesProWorkOrderDO workOrder = mesProWorkOrderService.getWorkOrder(task.getWorkOrderId()); |
| | | MesPdProcessParamTemplateDO template = templateService.validateProcessParamTemplateExists(templateId); |
| | | List<MesPdProcessParamTemplateDetailDO> details = templateService.getProcessParamTemplateDetailListByTemplateId(templateId); |
| | | if (CollUtil.isEmpty(details)) { |
| | | throw exception(PRO_WORK_ORDER_PARAM_RECORD_TEMPLATE_NO_DETAIL); |
| | | } |
| | | MesProWorkOrderParamRecordDO record = MesProWorkOrderParamRecordDO.builder() |
| | | .workOrderId(workOrder != null ? workOrder.getId() : task.getWorkOrderId()) |
| | | .taskId(taskId) |
| | | .templateId(template.getId()) |
| | | .templateCode(template.getTemplateCode()) |
| | | .templateName(template.getTemplateName()) |
| | | .recordNo("TASK-" + taskId) |
| | | .remark("生产任务排产时生成的参数快照") |
| | | .build(); |
| | | paramRecordMapper.insert(record); |
| | | paramRecordDetailMapper.insertBatch(details.stream().map(detail -> MesProWorkOrderParamRecordDetailDO.builder() |
| | | .recordId(record.getId()) |
| | | .templateDetailId(detail.getId()) |
| | | .paramCode(detail.getParamCode()) |
| | | .paramName(detail.getParamName()) |
| | | .paramType(detail.getParamType()) |
| | | .required(detail.getRequired()) |
| | | .unitMeasureId(detail.getUnitMeasureId()) |
| | | .paramValue(null) |
| | | .remark(detail.getRemark()) |
| | | .build()).toList()); |
| | | return record.getId(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createTaskParamRecordFromProcessParams(Long taskId, List<MesProProcessParamDO> processParams) { |
| | | MesProTaskDO task = mesProTaskService.getTask(taskId); |
| | | if (task == null || CollUtil.isEmpty(processParams)) { |
| | | return null; |
| | | } |
| | | // 1. 批量获取工艺参数定义,过滤已删除的参数 |
| | | Map<Long, MesPdProcessParamDO> paramMap = pdProcessParamService.getProcessParamMap( |
| | | processParams.stream().map(MesProProcessParamDO::getProcessParamId).collect(Collectors.toSet())); |
| | | List<MesProProcessParamDO> valid = processParams.stream() |
| | | .filter(pp -> paramMap.containsKey(pp.getProcessParamId())) |
| | | .toList(); |
| | | if (CollUtil.isEmpty(valid)) { |
| | | return null; |
| | | } |
| | | // 2. 插入主表(无模板,template 相关字段为空) |
| | | MesProWorkOrderDO workOrder = mesProWorkOrderService.getWorkOrder(task.getWorkOrderId()); |
| | | MesProWorkOrderParamRecordDO record = MesProWorkOrderParamRecordDO.builder() |
| | | .workOrderId(workOrder != null ? workOrder.getId() : task.getWorkOrderId()) |
| | | .taskId(taskId) |
| | | .templateId(null) |
| | | .templateCode(null) |
| | | .templateName("工序绑定参数") |
| | | .recordNo("TASK-" + taskId) |
| | | .remark("生产任务按工序绑定参数生成的参数快照") |
| | | .build(); |
| | | paramRecordMapper.insert(record); |
| | | // 3. 插入明细(快照参数定义,required 优先取绑定值,其次取参数默认值) |
| | | paramRecordDetailMapper.insertBatch(valid.stream().map(pp -> { |
| | | MesPdProcessParamDO param = paramMap.get(pp.getProcessParamId()); |
| | | return MesProWorkOrderParamRecordDetailDO.builder() |
| | | .recordId(record.getId()) |
| | | .templateDetailId(null) |
| | | .paramCode(param.getParamCode()) |
| | | .paramName(param.getParamName()) |
| | | .paramType(param.getParamType()) |
| | | .required(pp.getRequired() != null ? pp.getRequired() : param.getRequired()) |
| | | .unitMeasureId(param.getUnitMeasureId()) |
| | | .paramValue(null) |
| | | .remark(pp.getRemark()) |
| | | .build(); |
| | | }).toList()); |
| | | return record.getId(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | .paramCode(templateDetail.getParamCode()) |
| | | .paramName(templateDetail.getParamName()) |
| | | .paramType(templateDetail.getParamType()) |
| | | .required(templateDetail.getRequired()) |
| | | .unitMeasureId(templateDetail.getUnitMeasureId()) |
| | | .paramValue(item.getParamValue()) |
| | | .build(); |
| | |
| | | .paramCode(templateDetail.getParamCode()) |
| | | .paramName(templateDetail.getParamName()) |
| | | .paramType(templateDetail.getParamType()) |
| | | .required(templateDetail.getRequired()) |
| | | .unitMeasureId(templateDetail.getUnitMeasureId()) |
| | | .paramValue(item.getParamValue()) |
| | | .build(); |
| | |
| | | return paramRecordMapper.selectListByWorkOrderId(workOrderId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateTaskParamValues(Long taskId, List<Long> detailIds, List<String> values) { |
| | | MesProWorkOrderParamRecordDO record = paramRecordMapper.selectFirstByTaskId(taskId); |
| | | if (record == null) { |
| | | return; // 任务无参数记录(未绑定参数),无需校验 |
| | | } |
| | | List<MesProWorkOrderParamRecordDetailDO> details = paramRecordDetailMapper.selectListByRecordId(record.getId()); |
| | | if (CollUtil.isEmpty(details)) { |
| | | return; |
| | | } |
| | | // 1. 构建提交明细映射(detailId -> 参数值) |
| | | Map<Long, String> valueMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(detailIds)) { |
| | | for (int i = 0; i < detailIds.size(); i++) { |
| | | valueMap.put(detailIds.get(i), values != null && values.size() > i ? values.get(i) : null); |
| | | } |
| | | } |
| | | // 2. 校验必填参数都有值(绑定参数或模板快照中的 required) |
| | | Map<Long, MesProWorkOrderParamRecordDetailDO> detailMap = details.stream() |
| | | .collect(Collectors.toMap(MesProWorkOrderParamRecordDetailDO::getId, d -> d)); |
| | | for (MesProWorkOrderParamRecordDetailDO detail : details) { |
| | | String value = valueMap.get(detail.getId()); |
| | | if (Boolean.TRUE.equals(detail.getRequired()) |
| | | && (value == null || value.isBlank())) { |
| | | throw exception(PRO_WORK_ORDER_PARAM_RECORD_REQUIRED_PARAM_MISSING, detail.getParamName()); |
| | | } |
| | | } |
| | | // 3. 更新提交的参数值 |
| | | for (Map.Entry<Long, String> entry : valueMap.entrySet()) { |
| | | MesProWorkOrderParamRecordDetailDO detail = detailMap.get(entry.getKey()); |
| | | if (detail == null) { |
| | | throw exception(PRO_WORK_ORDER_PARAM_RECORD_DETAIL_NOT_IN_TEMPLATE); |
| | | } |
| | | detail.setParamValue(entry.getValue()); |
| | | paramRecordDetailMapper.updateById(detail); |
| | | } |
| | | } |
| | | |
| | | // ==================== 校验方法 ==================== |
| | | |
| | | private MesProWorkOrderParamRecordDO validateParamRecordExists(Long id) { |