feat(hwmom-mes):增强计量单位管理功能

- 新增父节点信息继承功能,自动填充祖先节点
- 增加编码唯一性校验,防止重复编码
- 添加子节点存在性检查,避免删除有子节点的计量单位
master
zch 6 days ago
parent c6abb3aa7b
commit 51de612b84

@ -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;
@ -79,6 +80,16 @@ public class BaseMeasurementUnitInfoServiceImpl implements IBaseMeasurementUnitI
public Boolean insertByBo(BaseMeasurementUnitInfoBo bo) {
BaseMeasurementUnitInfo add = MapstructUtils.convert(bo, BaseMeasurementUnitInfo.class);
validEntityBeforeSave(add);
// 获取父节点信息
BaseMeasurementUnitInfoVo query = baseMapper.selectVoById(bo.getParentId());
if (query != null) {
//若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors
add.setAncestors(query.getAncestors() + "," + bo.getParentId());
}else{
//若父节点为空则ancestors仅有父节点id
add.setAncestors(bo.getParentId().toString());
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setUnitId(add.getUnitId());
@ -104,6 +115,15 @@ public class BaseMeasurementUnitInfoServiceImpl implements IBaseMeasurementUnitI
*/
private void validEntityBeforeSave(BaseMeasurementUnitInfo entity){
//TODO 做一些数据校验,如唯一约束
if (StringUtils.isNotBlank(entity.getUnitCode())) {
BaseMeasurementUnitInfoBo query = new BaseMeasurementUnitInfoBo();
query.setUnitCode(entity.getUnitCode());
MPJLambdaWrapper<BaseMeasurementUnitInfo> lqw = buildQueryWrapper(query);
BaseMeasurementUnitInfo baseMeasurementUnitInfo = baseMapper.selectOne(lqw);
if (baseMeasurementUnitInfo != null && !baseMeasurementUnitInfo.getUnitId().equals(entity.getUnitId())) {
throw new ServiceException("编码已存在");
}
}
}
/**
@ -117,6 +137,14 @@ public class BaseMeasurementUnitInfoServiceImpl implements IBaseMeasurementUnitI
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
for (Long id : ids) {
//TODO 校验是否需要删除
BaseMeasurementUnitInfo query = new BaseMeasurementUnitInfo();
query.setParentId(id);
if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) {
throw new ServiceException("存在子节点,不允许删除");
}
}
}
return baseMapper.deleteByIds(ids) > 0;
}

Loading…
Cancel
Save