change(hwmom-mes): 添加物料信息更新逻辑

- 在物料信息更新时增加物料类型变更的校验
- 新增对已绑定物料 BOM(生产BOM) 的检查,防止更改物料类型
master
zch 2 days ago
parent 4e13e7b5f3
commit 61d39f6a4f

@ -1,28 +1,29 @@
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;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
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.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mes.domain.BaseMaterialInfo;
import org.dromara.mes.domain.BaseMaterialType;
import org.dromara.mes.domain.BaseMeasurementUnitInfo;
import org.dromara.mes.domain.ProdBaseFactoryInfo;
import org.springframework.stereotype.Service;
import org.dromara.mes.domain.ProdMaterialBom;
import org.dromara.mes.domain.bo.BaseMaterialInfoBo;
import org.dromara.mes.domain.vo.BaseMaterialInfoVo;
import org.dromara.mes.domain.BaseMaterialInfo;
import org.dromara.mes.mapper.BaseMaterialInfoMapper;
import org.dromara.mes.mapper.ProdMaterialBomMapper;
import org.dromara.mes.service.IBaseMaterialInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Collection;
/**
* Service
@ -36,6 +37,8 @@ public class BaseMaterialInfoServiceImpl implements IBaseMaterialInfoService {
private final BaseMaterialInfoMapper baseMapper;
private final ProdMaterialBomMapper prodMaterialBomMapper;
/**
*
*
@ -92,8 +95,6 @@ public class BaseMaterialInfoServiceImpl implements IBaseMaterialInfoService {
.leftJoin(BaseMeasurementUnitInfo.class, BaseMeasurementUnitInfo::getUnitId, BaseMaterialInfo::getMaterialUnitId)*/
.eq(bo.getMaterialId() != null, BaseMaterialInfo::getMaterialId, bo.getMaterialId())
.eq(StringUtils.isNotBlank(bo.getErpId()), BaseMaterialInfo::getErpId, bo.getErpId())
.eq(StringUtils.isNotBlank(bo.getMaterialCode()), BaseMaterialInfo::getMaterialCode, bo.getMaterialCode())
@ -173,6 +174,21 @@ public class BaseMaterialInfoServiceImpl implements IBaseMaterialInfoService {
public Boolean updateByBo(BaseMaterialInfoBo bo) {
BaseMaterialInfo update = MapstructUtils.convert(bo, BaseMaterialInfo.class);
validEntityBeforeSave(update);
//物料上的物料类型修改时 校验原类型是否关联的BOM
Long materialTypeId = bo.getMaterialTypeId();//修改后的物料类型id
//要修改的物料
Long materialId = bo.getMaterialId();
BaseMaterialInfoVo baseMaterialInfoVo = baseMapper.selectVoById(materialId);
//物料绑定的BOM
MPJLambdaWrapper<ProdMaterialBom> bom = new MPJLambdaWrapper<>();
bom.eq(ProdMaterialBom::getMaterialId, materialId);
List<ProdMaterialBom> boms = prodMaterialBomMapper.selectList(bom);
if ( !materialTypeId.equals(baseMaterialInfoVo.getMaterialTypeId())
&& !ObjectUtils.isEmpty(boms)) {
throw new ServiceException("已绑定物料BOM请勿更改物料类型");
}
return baseMapper.updateById(update) > 0;
}

Loading…
Cancel
Save