| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | 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.controller.admin.pro.process.vo.MesProProcessPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessSaveReqVO; |
| | | 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.service.pro.route.MesProRouteProcessService; |
| | | import cn.iocoder.yudao.module.mes.service.pd.processparamtemplate.MesPdProcessParamTemplateService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | 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 |
| | |
| | | |
| | | @Resource |
| | | private MesProProcessMapper processMapper; |
| | | |
| | | @Resource |
| | | private MesPdProcessParamTemplateService paramTemplateService; |
| | | |
| | | @Resource |
| | | private MesProProcessContentService processContentService; |
| | |
| | | validateProcessCodeUnique(saveReqVO.getId(), saveReqVO.getCode()); |
| | | // 2. 校验名称唯一 |
| | | validateProcessNameUnique(saveReqVO.getId(), saveReqVO.getName()); |
| | | validateParamConfiguration(saveReqVO); |
| | | } |
| | | |
| | | private void validateParamConfiguration(MesProProcessSaveReqVO req) { |
| | | // 兼容未发送新字段的旧客户端:更新时保留已有配置。 |
| | | if (req.getParamCollectMode() == null) { |
| | | if (req.getId() == null) req.setParamCollectMode(0); |
| | | else { |
| | | MesProProcessDO current = processMapper.selectById(req.getId()); |
| | | if (current != null) { |
| | | req.setParamCollectMode(current.getParamCollectMode() == null ? 0 : current.getParamCollectMode()); |
| | | req.setParamTemplateId(current.getParamTemplateId()); |
| | | } |
| | | } |
| | | } |
| | | Integer mode = req.getParamCollectMode(); |
| | | if (mode == null || mode < 0 || mode > 2) throw exception(PRO_PROCESS_PARAM_CONFIG_INVALID); |
| | | if (mode != 0) { |
| | | if (req.getParamTemplateId() == null) throw exception(PRO_PROCESS_PARAM_TEMPLATE_REQUIRED); |
| | | paramTemplateService.validateProcessParamTemplateExists(req.getParamTemplateId()); |
| | | if (CollUtil.isEmpty(paramTemplateService.getProcessParamTemplateDetailListByTemplateId(req.getParamTemplateId()))) { |
| | | throw exception(PRO_WORK_ORDER_PARAM_RECORD_TEMPLATE_NO_DETAIL); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public MesProProcessDO getProcessByName(String name) { |
| | | return processMapper.selectByName(name); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesProProcessDO> getProcessPage(MesProProcessPageReqVO pageReqVO) { |
| | | return processMapper.selectPage(pageReqVO); |
| | | } |
| | |
| | | return processMapper.selectListByStatus(status); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesProProcessImportRespVO importProcessList(List<MesProProcessImportExcelVO> importList, |
| | | boolean updateSupport) { |
| | | // 1. 校验非空 |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(PRO_PROCESS_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | |
| | | // 2. 逐行处理 |
| | | MesProProcessImportRespVO respVO = MesProProcessImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String key = StrUtil.blankToDefault(importItem.getCode(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getCode())) { |
| | | respVO.getFailureCodes().put(key, "工序编码不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getName())) { |
| | | respVO.getFailureCodes().put(key, "工序名称不能为空"); |
| | | return; |
| | | } |
| | | // 2.1 判断:创建 or 更新 |
| | | MesProProcessDO existProcess = processMapper.selectByCode(importItem.getCode()); |
| | | if (existProcess == null) { |
| | | // 2.1.1 新增 |
| | | MesProProcessDO process = BeanUtils.toBean(importItem, MesProProcessDO.class); |
| | | process.setId(null); |
| | | process.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus())); |
| | | processMapper.insert(process); |
| | | respVO.getCreateCodes().add(importItem.getCode()); |
| | | } else if (updateSupport) { |
| | | // 2.1.2 更新 |
| | | MesProProcessDO updateObj = BeanUtils.toBean(importItem, MesProProcessDO.class); |
| | | updateObj.setId(existProcess.getId()); |
| | | updateObj.setCode(existProcess.getCode()); |
| | | processMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(importItem.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "工序编码已存在"); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |