| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createProcessParamTemplate(MesPdProcessParamTemplateSaveReqVO createReqVO) { |
| | | // 1. 生成模板编码 |
| | | String templateCode = autoCodeRecordService.generateAutoCode( |
| | | // 1. 使用手填编码,或自动生成编码 |
| | | String templateCode = createReqVO.getTemplateCode(); |
| | | if (StrUtil.isNotBlank(templateCode)) { |
| | | if (templateMapper.selectByTemplateCode(templateCode) != null) { |
| | | throw exception(PD_PROCESS_PARAM_TEMPLATE_CODE_DUPLICATE); |
| | | } |
| | | } else { |
| | | templateCode = autoCodeRecordService.generateAutoCode( |
| | | MesMdAutoCodeRuleCodeEnum.PD_PROCESS_PARAM_TEMPLATE_CODE.getCode()); |
| | | } |
| | | // 2. 插入模板主表 |
| | | MesPdProcessParamTemplateDO template = BeanUtils.toBean(createReqVO, MesPdProcessParamTemplateDO.class); |
| | | template.setTemplateCode(templateCode); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProcessParamTemplate(MesPdProcessParamTemplateSaveReqVO updateReqVO) { |
| | | // 1. 校验存在 |
| | | validateProcessParamTemplateExists(updateReqVO.getId()); |
| | | // 2. 更新模板主表 |
| | | MesPdProcessParamTemplateDO existing = validateProcessParamTemplateExists(updateReqVO.getId()); |
| | | // 2. 更新模板主表:编码留空或未变化则不修改;填写了新编码则校验唯一 |
| | | MesPdProcessParamTemplateDO updateObj = BeanUtils.toBean(updateReqVO, MesPdProcessParamTemplateDO.class); |
| | | String templateCode = updateReqVO.getTemplateCode(); |
| | | if (StrUtil.isNotBlank(templateCode) && !StrUtil.equals(templateCode, existing.getTemplateCode())) { |
| | | if (templateMapper.selectByTemplateCode(templateCode) != null) { |
| | | throw exception(PD_PROCESS_PARAM_TEMPLATE_CODE_DUPLICATE); |
| | | } |
| | | updateObj.setTemplateCode(templateCode); |
| | | } else { |
| | | // 置空,避免 MyBatis-Plus 更新时覆盖原编码 |
| | | updateObj.setTemplateCode(null); |
| | | } |
| | | templateMapper.updateById(updateObj); |
| | | // 3. 删除旧明细并重新插入(快照模式:先删后插) |
| | | detailMapper.deleteByTemplateId(updateReqVO.getId()); |