| | |
| | | /** |
| | | * MES 生产工单参数记录 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | 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()) |
| | | .unitMeasureId(detail.getUnitMeasureId()) |
| | | .paramValue(null) |
| | | .remark(detail.getRemark()) |
| | | .build()).toList()); |
| | | return record.getId(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | return paramRecordMapper.selectListByWorkOrderId(workOrderId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateTaskParamValues(Long taskId, List<Long> detailIds, List<String> values) { |
| | | if (CollUtil.isEmpty(detailIds)) { |
| | | return; |
| | | } |
| | | MesProWorkOrderParamRecordDO record = paramRecordMapper.selectFirstByTaskId(taskId); |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | List<MesProWorkOrderParamRecordDetailDO> details = paramRecordDetailMapper.selectListByRecordId(record.getId()); |
| | | Map<Long, MesProWorkOrderParamRecordDetailDO> detailMap = details.stream() |
| | | .collect(Collectors.toMap(MesProWorkOrderParamRecordDetailDO::getId, d -> d)); |
| | | for (int i = 0; i < detailIds.size(); i++) { |
| | | MesProWorkOrderParamRecordDetailDO detail = detailMap.get(detailIds.get(i)); |
| | | if (detail == null) { |
| | | throw exception(PRO_WORK_ORDER_PARAM_RECORD_DETAIL_NOT_IN_TEMPLATE); |
| | | } |
| | | detail.setParamValue(values != null && values.size() > i ? values.get(i) : null); |
| | | paramRecordDetailMapper.updateById(detail); |
| | | } |
| | | } |
| | | |
| | | // ==================== 校验方法 ==================== |
| | | |
| | | private MesProWorkOrderParamRecordDO validateParamRecordExists(Long id) { |