mirror of
https://gitee.com/zhijiantianya/ruoyi-vue-pro.git
synced 2026-07-08 06:35:19 +08:00
✨ feat(mes): 新增设备方案类型唯一性校验逻辑
新增跨方案类型唯一性校验,确保同一设备不能在多个同类型的方案中重复添加。此变更提升了设备管理的准确性和一致性,避免了潜在的业务逻辑冲突。
This commit is contained in:
@ -27,10 +27,6 @@ public class MesDvCheckRecordSaveReqVO {
|
||||
@Schema(description = "点检人编号", example = "1")
|
||||
private Long userId;
|
||||
|
||||
// TODO @AI:这个字段,不允许提交
|
||||
@Schema(description = "状态", example = "10")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "测试备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
@ -32,6 +32,10 @@ public interface MesDvCheckPlanMachineryMapper extends BaseMapperX<MesDvCheckPla
|
||||
return selectCount(MesDvCheckPlanMachineryDO::getMachineryId, machineryId);
|
||||
}
|
||||
|
||||
default List<MesDvCheckPlanMachineryDO> selectListByMachineryId(Long machineryId) {
|
||||
return selectList(MesDvCheckPlanMachineryDO::getMachineryId, machineryId);
|
||||
}
|
||||
|
||||
default MesDvCheckPlanMachineryDO selectByPlanIdAndMachineryId(Long planId, Long machineryId) {
|
||||
return selectOne(new LambdaQueryWrapperX<MesDvCheckPlanMachineryDO>()
|
||||
.eq(MesDvCheckPlanMachineryDO::getPlanId, planId)
|
||||
|
||||
@ -170,6 +170,7 @@ public interface ErrorCodeConstants {
|
||||
// ========== MES 设备管理-点检方案设备(1-040-302-100) ==========
|
||||
ErrorCode DV_CHECK_PLAN_MACHINERY_NOT_EXISTS = new ErrorCode(1_040_302_100, "点检保养方案设备不存在");
|
||||
ErrorCode DV_CHECK_PLAN_MACHINERY_DUPLICATE = new ErrorCode(1_040_302_101, "该设备已关联到当前方案,请勿重复添加");
|
||||
ErrorCode DV_CHECK_PLAN_MACHINERY_EXISTS_IN_SAME_TYPE = new ErrorCode(1_040_302_102, "该设备已存在于同类型的其他启用的或草稿的方案中,不允许同一设备添加多个同类型的方案");
|
||||
// ========== MES 设备管理-点检方案项目(1-040-302-200) ==========
|
||||
ErrorCode DV_CHECK_PLAN_SUBJECT_NOT_EXISTS = new ErrorCode(1_040_302_200, "点检保养方案项目不存在");
|
||||
ErrorCode DV_CHECK_PLAN_SUBJECT_DUPLICATE = new ErrorCode(1_040_302_201, "该项目已关联到当前方案,请勿重复添加");
|
||||
|
||||
@ -59,4 +59,12 @@ public interface MesDvCheckPlanMachineryService {
|
||||
*/
|
||||
Long getCheckPlanMachineryCountByMachineryId(Long machineryId);
|
||||
|
||||
/**
|
||||
* 获得指定设备关联的方案设备列表
|
||||
*
|
||||
* @param machineryId 设备编号
|
||||
* @return 方案设备列表
|
||||
*/
|
||||
List<MesDvCheckPlanMachineryDO> getCheckPlanMachineryListByMachineryId(Long machineryId);
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package cn.iocoder.yudao.module.mes.service.dv.checkplan;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.machinery.MesDvCheckPlanMachinerySaveReqVO;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO;
|
||||
import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanMachineryDO;
|
||||
import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkplan.MesDvCheckPlanMachineryMapper;
|
||||
import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService;
|
||||
@ -26,6 +29,7 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine
|
||||
|
||||
@Resource
|
||||
private MesDvCheckPlanMachineryMapper checkPlanMachineryMapper;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private MesDvCheckPlanService checkPlanService;
|
||||
@ -35,13 +39,26 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine
|
||||
@Override
|
||||
public Long createCheckPlanMachinery(MesDvCheckPlanMachinerySaveReqVO createReqVO) {
|
||||
// 1.1 校验方案草稿状态
|
||||
checkPlanService.validateCheckPlanPrepare(createReqVO.getPlanId());
|
||||
MesDvCheckPlanDO currentPlan = checkPlanService.validateCheckPlanPrepare(createReqVO.getPlanId());
|
||||
// 1.2 校验设备存在
|
||||
machineryService.validateMachineryExists(createReqVO.getMachineryId());
|
||||
// 1.3 校验同一方案下设备不重复
|
||||
if (checkPlanMachineryMapper.selectByPlanIdAndMachineryId(createReqVO.getPlanId(), createReqVO.getMachineryId()) != null) {
|
||||
throw exception(DV_CHECK_PLAN_MACHINERY_DUPLICATE);
|
||||
}
|
||||
// 1.4 跨方案类型唯一性校验(对齐 KTG 业务约束:设备不能存在于同类型多个方案中)
|
||||
List<MesDvCheckPlanMachineryDO> existingMachineryList = getCheckPlanMachineryListByMachineryId(createReqVO.getMachineryId());
|
||||
if (CollUtil.isNotEmpty(existingMachineryList)) {
|
||||
List<Long> existingPlanIds = existingMachineryList.stream().map(MesDvCheckPlanMachineryDO::getPlanId).toList();
|
||||
List<MesDvCheckPlanDO> existingPlans = checkPlanService.getCheckPlanList(existingPlanIds);
|
||||
for (MesDvCheckPlanDO existPlan : existingPlans) {
|
||||
// 如果存在不同于当前方案、但类型一致的计划方案,则拦截(一机多计划,但不允许同一机多同类型计划)
|
||||
if (ObjUtil.notEqual(existPlan.getId(), currentPlan.getId())
|
||||
&& ObjUtil.equal(existPlan.getType(), currentPlan.getType())) {
|
||||
throw exception(DV_CHECK_PLAN_MACHINERY_EXISTS_IN_SAME_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 插入
|
||||
MesDvCheckPlanMachineryDO planMachinery = BeanUtils.toBean(createReqVO, MesDvCheckPlanMachineryDO.class);
|
||||
@ -83,4 +100,9 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine
|
||||
return checkPlanMachineryMapper.selectCountByMachineryId(machineryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MesDvCheckPlanMachineryDO> getCheckPlanMachineryListByMachineryId(Long machineryId) {
|
||||
return checkPlanMachineryMapper.selectListByMachineryId(machineryId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user