add(hwmom-mes): 增加数据校验逻辑

- 在多个服务实现类中添加了编码唯一性的校验逻辑
- 优化了删除操作的业务校验,树型表页面增加了对子节点存在的判断(BaseMaterialTypeServiceImpl和BaseMeasurementUnitInfoServiceImpl)
- 统一使用 ServiceException 抛出业务异常
master
zch 5 days ago
parent 6438bd6e8f
commit ff86026d4f

@ -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<BaseClassTeamInfo> lqw = buildQueryWrapper(query);
BaseClassTeamInfo baseClassTeamInfo = baseMapper.selectOne(lqw);
if (baseClassTeamInfo != null
&& !baseClassTeamInfo.getClassTeamId().equals(entity.getClassTeamId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

@ -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<BaseMaterialType> 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<Long> 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;
}

@ -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) {

@ -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<BaseShiftInfo> lqw = buildQueryWrapper(query);
BaseShiftInfo baseShiftInfo = baseMapper.selectOne(lqw);
if (baseShiftInfo != null && !baseShiftInfo.getShiftId().equals(entity.getShiftId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

@ -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<BaseSupplierInfo> lqw = buildQueryWrapper(query);
BaseSupplierInfo baseSupplierInfo = baseMapper.selectOne(lqw);
if (baseSupplierInfo != null && !baseSupplierInfo.getSupplierId().equals(entity.getSupplierId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

@ -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<BaseToolingInfo> lqw = buildQueryWrapper(query);
BaseToolingInfo baseToolingInfo = baseMapper.selectOne(lqw);
if (baseToolingInfo != null && !baseToolingInfo.getToolingId().equals(entity.getToolingId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

@ -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<ProdBaseFactoryInfo> lqw = buildQueryWrapper(query);
ProdBaseFactoryInfo baseProdBaseFactoryInfo = baseMapper.selectOne(lqw);
if (baseProdBaseFactoryInfo != null && !baseProdBaseFactoryInfo.getFactoryId().equals(entity.getFactoryId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

@ -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<ProdBaseProcessInfo> lqw = buildQueryWrapper(query);
ProdBaseProcessInfo prodBaseProcessInfo = baseMapper.selectOne(lqw);
if (prodBaseProcessInfo != null && !prodBaseProcessInfo.getProcessId().equals(entity.getProcessId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

@ -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<ProdBaseProdLineInfo> lqw = buildQueryWrapper(query);
ProdBaseProdLineInfo prodBaseProdLineInfo = baseMapper.selectOne(lqw);
if (prodBaseProdLineInfo != null
&& !prodBaseProdLineInfo.getProdLineId().equals(entity.getProdLineId())) {
throw new ServiceException("编码已存在");
}
}
}
/**

Loading…
Cancel
Save