change(hwmom-mes):优化物料类型和计量单位信息的插入逻辑,使用 ObjectUtils.isNotEmpty() 替代空值检查

master
zch 1 month ago
parent 0cb9f6d654
commit 95a8fc0fb7

@ -1,5 +1,6 @@
package org.dromara.mes.service.impl; package org.dromara.mes.service.impl;
import org.apache.commons.lang3.ObjectUtils;
import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
@ -87,6 +88,17 @@ public class BaseMaterialTypeServiceImpl implements IBaseMaterialTypeService {
public Boolean insertByBo(BaseMaterialTypeBo bo) { public Boolean insertByBo(BaseMaterialTypeBo bo) {
BaseMaterialType add = MapstructUtils.convert(bo, BaseMaterialType.class); BaseMaterialType add = MapstructUtils.convert(bo, BaseMaterialType.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
//获取父节点信息
BaseMaterialTypeVo query = baseMapper.selectVoById(bo.getParentId());
if (ObjectUtils.isNotEmpty(query)) {
//若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors
add.setAncestors(query.getAncestors() + "," + bo.getParentId());
}else{
//若父节点为空则ancestors仅有父节点id
add.setAncestors(bo.getParentId().toString());
}
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (flag) { if (flag) {
bo.setMatrialTypeId(add.getMatrialTypeId()); bo.setMatrialTypeId(add.getMatrialTypeId());
@ -135,7 +147,7 @@ public class BaseMaterialTypeServiceImpl implements IBaseMaterialTypeService {
if(isValid){ if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验 //TODO 做一些业务上的校验,判断是否需要校验
for (Long id : ids) { for (Long id : ids) {
//TODO 校验是否需要删除 //监测删除的节点是否有子节点
BaseMaterialType query = new BaseMaterialType(); BaseMaterialType query = new BaseMaterialType();
query.setParentId(id); query.setParentId(id);
if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) { if (baseMapper.selectCount(Wrappers.lambdaQuery(query)) > 0) {

@ -1,5 +1,6 @@
package org.dromara.mes.service.impl; package org.dromara.mes.service.impl;
import org.apache.commons.lang3.ObjectUtils;
import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
@ -80,16 +81,17 @@ public class BaseMeasurementUnitInfoServiceImpl implements IBaseMeasurementUnitI
public Boolean insertByBo(BaseMeasurementUnitInfoBo bo) { public Boolean insertByBo(BaseMeasurementUnitInfoBo bo) {
BaseMeasurementUnitInfo add = MapstructUtils.convert(bo, BaseMeasurementUnitInfo.class); BaseMeasurementUnitInfo add = MapstructUtils.convert(bo, BaseMeasurementUnitInfo.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
// 获取父节点信息 // 获取父节点信息
BaseMeasurementUnitInfoVo query = baseMapper.selectVoById(bo.getParentId()); BaseMeasurementUnitInfoVo query = baseMapper.selectVoById(bo.getParentId());
if (ObjectUtils.isNotEmpty(query)) {
if (query != null) {
//若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors //若父节点不为空则将父节点的ancestors拼接父节点id拼接成ancestors
add.setAncestors(query.getAncestors() + "," + bo.getParentId()); add.setAncestors(query.getAncestors() + "," + bo.getParentId());
}else{ }else{
//若父节点为空则ancestors仅有父节点id //若父节点为空则ancestors仅有父节点id
add.setAncestors(bo.getParentId().toString()); add.setAncestors(bo.getParentId().toString());
} }
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (flag) { if (flag) {
bo.setUnitId(add.getUnitId()); bo.setUnitId(add.getUnitId());

Loading…
Cancel
Save