From ff86026d4fd564c89bb22a51ac627a05c012c43e Mon Sep 17 00:00:00 2001 From: zch Date: Tue, 14 Jan 2025 19:18:15 +0800 Subject: [PATCH] =?UTF-8?q?add(hwmom-mes):=20=E5=A2=9E=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在多个服务实现类中添加了编码唯一性的校验逻辑 - 优化了删除操作的业务校验,树型表页面增加了对子节点存在的判断(BaseMaterialTypeServiceImpl和BaseMeasurementUnitInfoServiceImpl) - 统一使用 ServiceException 抛出业务异常 --- .../impl/BaseClassTeamInfoServiceImpl.java | 12 ++++++++++++ .../impl/BaseMaterialTypeServiceImpl.java | 18 ++++++++++++++++++ .../BaseMeasurementUnitInfoServiceImpl.java | 3 ++- .../service/impl/BaseShiftInfoServiceImpl.java | 11 +++++++++++ .../impl/BaseSupplierInfoServiceImpl.java | 11 +++++++++++ .../impl/BaseToolingInfoServiceImpl.java | 11 +++++++++++ .../impl/ProdBaseFactoryInfoServiceImpl.java | 11 +++++++++++ .../impl/ProdBaseProcessInfoServiceImpl.java | 10 ++++++++++ .../impl/ProdBaseProdLineInfoServiceImpl.java | 12 ++++++++++++ 9 files changed, 98 insertions(+), 1 deletion(-) diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseClassTeamInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseClassTeamInfoServiceImpl.java index 0128cfdf..20ddccda 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseClassTeamInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseClassTeamInfoServiceImpl.java @@ -2,6 +2,7 @@ package org.dromara.mes.service.impl; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -138,6 +139,17 @@ public class BaseClassTeamInfoServiceImpl implements IBaseClassTeamInfoService { */ private void validEntityBeforeSave(BaseClassTeamInfo entity){ //TODO 做一些数据校验,如唯一约束 + // 校验编码是否重复 + if (StringUtils.isNotBlank(entity.getTeamCode())) { + BaseClassTeamInfoBo query = new BaseClassTeamInfoBo(); + query.setTeamCode(entity.getTeamCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + BaseClassTeamInfo baseClassTeamInfo = baseMapper.selectOne(lqw); + if (baseClassTeamInfo != null + && !baseClassTeamInfo.getClassTeamId().equals(entity.getClassTeamId())) { + throw new ServiceException("编码已存在"); + } + } } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMaterialTypeServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMaterialTypeServiceImpl.java index 7a3ec4e7..440f7907 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMaterialTypeServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMaterialTypeServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.mes.service.impl; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import com.github.yulichang.toolkit.JoinWrappers; @@ -111,6 +112,15 @@ public class BaseMaterialTypeServiceImpl implements IBaseMaterialTypeService { */ private void validEntityBeforeSave(BaseMaterialType entity){ //TODO 做一些数据校验,如唯一约束 + if (StringUtils.isNotBlank(entity.getMatrialTypeCode())) { + BaseMaterialTypeBo query = new BaseMaterialTypeBo(); + query.setMatrialTypeCode(entity.getMatrialTypeCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + BaseMaterialType baseMaterialType = baseMapper.selectOne(lqw); + if (baseMaterialType != null && !baseMaterialType.getMatrialTypeId().equals(entity.getMatrialTypeId())) { + throw new ServiceException("编码已存在"); + } + } } /** @@ -124,6 +134,14 @@ public class BaseMaterialTypeServiceImpl implements IBaseMaterialTypeService { public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if(isValid){ //TODO 做一些业务上的校验,判断是否需要校验 + for (Long id : ids) { + //TODO 校验是否需要删除 + BaseMaterialType query = new BaseMaterialType(); + query.setParentId(id); + if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) { + throw new ServiceException("存在子节点,不允许删除"); + } + } } return baseMapper.deleteByIds(ids) > 0; } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMeasurementUnitInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMeasurementUnitInfoServiceImpl.java index cae0bd7f..8d62ebd7 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMeasurementUnitInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseMeasurementUnitInfoServiceImpl.java @@ -115,6 +115,7 @@ public class BaseMeasurementUnitInfoServiceImpl implements IBaseMeasurementUnitI */ private void validEntityBeforeSave(BaseMeasurementUnitInfo entity){ //TODO 做一些数据校验,如唯一约束 + // 校验编码是否重复 if (StringUtils.isNotBlank(entity.getUnitCode())) { BaseMeasurementUnitInfoBo query = new BaseMeasurementUnitInfoBo(); query.setUnitCode(entity.getUnitCode()); @@ -138,7 +139,7 @@ public class BaseMeasurementUnitInfoServiceImpl implements IBaseMeasurementUnitI if(isValid){ //TODO 做一些业务上的校验,判断是否需要校验 for (Long id : ids) { - //TODO 校验是否需要删除 + // 判断是否存在子节点 BaseMeasurementUnitInfo query = new BaseMeasurementUnitInfo(); query.setParentId(id); if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) { diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseShiftInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseShiftInfoServiceImpl.java index cd0a182e..e38f9acf 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseShiftInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseShiftInfoServiceImpl.java @@ -3,6 +3,7 @@ package org.dromara.mes.service.impl; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; import lombok.val; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -130,6 +131,16 @@ public class BaseShiftInfoServiceImpl implements IBaseShiftInfoService { */ private void validEntityBeforeSave(BaseShiftInfo entity){ //TODO 做一些数据校验,如唯一约束 + //校验编码是否重复 + if (StringUtils.isNotBlank(entity.getShiftCode())) { + BaseShiftInfoBo query = new BaseShiftInfoBo(); + query.setShiftCode(entity.getShiftCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + BaseShiftInfo baseShiftInfo = baseMapper.selectOne(lqw); + if (baseShiftInfo != null && !baseShiftInfo.getShiftId().equals(entity.getShiftId())) { + throw new ServiceException("编码已存在"); + } + } } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseSupplierInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseSupplierInfoServiceImpl.java index 9185a33b..dedfae4d 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseSupplierInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseSupplierInfoServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.mes.service.impl; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -121,6 +122,16 @@ public class BaseSupplierInfoServiceImpl implements IBaseSupplierInfoService { */ private void validEntityBeforeSave(BaseSupplierInfo entity){ //TODO 做一些数据校验,如唯一约束 + //校验编码是否重复 + if (StringUtils.isNotBlank(entity.getSupplierCode())) { + BaseSupplierInfoBo query = new BaseSupplierInfoBo(); + query.setSupplierCode(entity.getSupplierCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + BaseSupplierInfo baseSupplierInfo = baseMapper.selectOne(lqw); + if (baseSupplierInfo != null && !baseSupplierInfo.getSupplierId().equals(entity.getSupplierId())) { + throw new ServiceException("编码已存在"); + } + } } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseToolingInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseToolingInfoServiceImpl.java index 687e5380..4398e9ad 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseToolingInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/BaseToolingInfoServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.mes.service.impl; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -122,6 +123,16 @@ public class BaseToolingInfoServiceImpl implements IBaseToolingInfoService { */ private void validEntityBeforeSave(BaseToolingInfo entity){ //TODO 做一些数据校验,如唯一约束 + // 校验编码是否已存在 + if (StringUtils.isNotBlank(entity.getToolingCode())) { + BaseToolingInfoBo query = new BaseToolingInfoBo(); + query.setToolingCode(entity.getToolingCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + BaseToolingInfo baseToolingInfo = baseMapper.selectOne(lqw); + if (baseToolingInfo != null && !baseToolingInfo.getToolingId().equals(entity.getToolingId())) { + throw new ServiceException("编码已存在"); + } + } } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseFactoryInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseFactoryInfoServiceImpl.java index 73f17fbd..3ba43bee 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseFactoryInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseFactoryInfoServiceImpl.java @@ -1,5 +1,7 @@ package org.dromara.mes.service.impl; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -118,6 +120,15 @@ public class ProdBaseFactoryInfoServiceImpl implements IProdBaseFactoryInfoServi */ private void validEntityBeforeSave(ProdBaseFactoryInfo entity){ //TODO 做一些数据校验,如唯一约束 + if (StringUtils.isNotBlank(entity.getFactoryCode())) { + ProdBaseFactoryInfoBo query = new ProdBaseFactoryInfoBo(); + query.setFactoryCode(entity.getFactoryCode()); + LambdaQueryWrapper lqw = buildQueryWrapper(query); + ProdBaseFactoryInfo baseProdBaseFactoryInfo = baseMapper.selectOne(lqw); + if (baseProdBaseFactoryInfo != null && !baseProdBaseFactoryInfo.getFactoryId().equals(entity.getFactoryId())) { + throw new ServiceException("编码已存在"); + } + } } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProcessInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProcessInfoServiceImpl.java index 0c784a44..15fe46fd 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProcessInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProcessInfoServiceImpl.java @@ -233,6 +233,16 @@ public class ProdBaseProcessInfoServiceImpl implements IProdBaseProcessInfoServi */ private void validEntityBeforeSave(ProdBaseProcessInfo entity){ //TODO 做一些数据校验,如唯一约束 + // 判断编码是否重复 + if (StringUtils.isNotBlank(entity.getProcessCode())) { + ProdBaseProcessInfoBo query = new ProdBaseProcessInfoBo(); + query.setProcessCode(entity.getProcessCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + ProdBaseProcessInfo prodBaseProcessInfo = baseMapper.selectOne(lqw); + if (prodBaseProcessInfo != null && !prodBaseProcessInfo.getProcessId().equals(entity.getProcessId())) { + throw new ServiceException("编码已存在"); + } + } } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProdLineInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProdLineInfoServiceImpl.java index e03bc026..c6029fbe 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProdLineInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdBaseProdLineInfoServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.mes.service.impl; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -121,6 +122,17 @@ public class ProdBaseProdLineInfoServiceImpl implements IProdBaseProdLineInfoSer */ private void validEntityBeforeSave(ProdBaseProdLineInfo entity){ //TODO 做一些数据校验,如唯一约束 + // 校验编码是否重复 + if (StringUtils.isNotBlank(entity.getProdLineCode())) { + ProdBaseProdLineInfoBo query = new ProdBaseProdLineInfoBo(); + query.setProdLineCode(entity.getProdLineCode()); + MPJLambdaWrapper lqw = buildQueryWrapper(query); + ProdBaseProdLineInfo prodBaseProdLineInfo = baseMapper.selectOne(lqw); + if (prodBaseProdLineInfo != null + && !prodBaseProdLineInfo.getProdLineId().equals(entity.getProdLineId())) { + throw new ServiceException("编码已存在"); + } + } } /**