| | |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.process.MesProProcessMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProProcessBillingTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProcessService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | import java.util.Map; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | |
| | | /** |
| | | * MES 生产工序 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | validateProcessCodeUnique(saveReqVO.getId(), saveReqVO.getCode()); |
| | | // 2. 校验名称唯一 |
| | | validateProcessNameUnique(saveReqVO.getId(), saveReqVO.getName()); |
| | | // 3. 校验计费类型合法(1-计时 2-计件),否则报工无法确定工资算法 |
| | | if (MesProProcessBillingTypeEnum.valueOfType(saveReqVO.getBillingType()) == null) { |
| | | throw exception(PRO_PROCESS_BILLING_TYPE_INVALID, saveReqVO.getName(), saveReqVO.getBillingType()); |
| | | } |
| | | // 4. 校验工资定额非负(允许 0,表示暂未定价,此时报工工资为 0,核算时可按人调整) |
| | | if (saveReqVO.getWageRate() != null && saveReqVO.getWageRate().signum() < 0) { |
| | | throw exception(PRO_PROCESS_WAGE_RATE_INVALID, saveReqVO.getName(), saveReqVO.getWageRate()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public MesProProcessImportRespVO importProcessList(List<MesProProcessImportExcelVO> rows, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(rows)) { |
| | | throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400, "导入文件没有工序数据"); |
| | | } |
| | | MesProProcessImportRespVO result = MesProProcessImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | Set<String> seenCodes = new HashSet<>(); |
| | | for (int index = 0; index < rows.size(); index++) { |
| | | MesProProcessImportExcelVO row = rows.get(index); |
| | | String code = row.getCode() == null ? "" : row.getCode().trim(); |
| | | String key = code.isEmpty() ? "第 " + (index + 2) + " 行" : code; |
| | | try { |
| | | if (code.isEmpty() || row.getName() == null || row.getName().isBlank()) { |
| | | throw new IllegalArgumentException("工序编码和名称不能为空"); |
| | | } |
| | | if (!seenCodes.add(code)) throw new IllegalArgumentException("文件内工序编码重复"); |
| | | if (row.getBillingType() == null || row.getWageRate() == null) { |
| | | throw new IllegalArgumentException("计费类型和工资定额不能为空"); |
| | | } |
| | | if (row.getStatus() != null && row.getStatus() != 0 && row.getStatus() != 1) { |
| | | throw new IllegalArgumentException("状态只能填写 0 或 1"); |
| | | } |
| | | MesProProcessSaveReqVO save = BeanUtils.toBean(row, MesProProcessSaveReqVO.class); |
| | | save.setStdTimeMode(parseStdTimeMode(row.getStdTimeModeName())); |
| | | save.setCode(code); |
| | | save.setName(row.getName().trim()); |
| | | save.setStatus(row.getStatus() == null ? 0 : row.getStatus()); |
| | | MesProProcessDO existing = processMapper.selectByCode(code); |
| | | if (existing == null) { |
| | | createProcess(save); |
| | | result.getCreateCodes().add(code); |
| | | } else if (updateSupport) { |
| | | save.setId(existing.getId()); |
| | | updateProcess(save); |
| | | result.getUpdateCodes().add(code); |
| | | } else { |
| | | throw new IllegalArgumentException("工序编码已存在,勾选覆盖后可更新"); |
| | | } |
| | | } catch (RuntimeException ex) { |
| | | result.getFailureCodes().put(key, ex.getMessage()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Integer parseStdTimeMode(String value) { |
| | | if (value == null || value.isBlank()) return null; |
| | | String normalized = value.trim().replace(" ", "").replace("*", "×").replace("*", "×"); |
| | | return switch (normalized) { |
| | | case "0", "未启用" -> 0; |
| | | case "1", "转速×节距" -> 1; |
| | | case "2", "线速度直取" -> 2; |
| | | case "3", "满速百分比×节距" -> 3; |
| | | default -> throw new IllegalArgumentException("标准工时计算方式请填写:未启用、转速×节距、线速度直取、满速百分比×节距"); |
| | | }; |
| | | } |
| | | |
| | | @Override |
| | | public List<MesProProcessDO> getProcessListByStatus(Integer status) { |
| | | return processMapper.selectListByStatus(status); |
| | | } |