|
|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|