@ -1,9 +1,13 @@
package com.aucma.production.service.impl ;
import java.math.BigDecimal ;
import java.util.List ;
import com.aucma.base.domain.BaseMaterialInfo ;
import com.aucma.base.domain.OrderBomInfo ;
import com.aucma.base.mapper.OrderBomInfoMapper ;
import com.aucma.base.mapper.BaseMaterialinfoMapper ;
import com.aucma.base.service.IOrderBomInfoService ;
import com.aucma.base.utils.MaterialConstants ;
import com.aucma.common.exception.ServiceException ;
import com.aucma.common.exception.base.BaseException ;
import com.aucma.common.utils.DateUtils ;
@ -21,13 +25,16 @@ import com.aucma.production.service.IBaseBomInfoService;
* @date 2023 - 0 9 - 28
* /
@Service
public class BaseBomInfoServiceImpl implements IBaseBomInfoService
{
public class BaseBomInfoServiceImpl implements IBaseBomInfoService {
@Autowired
private BaseBomInfoMapper baseBomInfoMapper ;
@Autowired
private OrderBomInfoMapper orderBomInfoMapper ;
private IOrderBomInfoService orderBomInfoService ;
@Autowired
private BaseMaterialinfoMapper materialInfoMapper ;
/ * *
* 查 询 生 产 BOM
*
@ -35,8 +42,7 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* @return 生 产 BOM
* /
@Override
public BaseBomInfo selectBaseBomInfoByObjId ( Long objId )
{
public BaseBomInfo selectBaseBomInfoByObjId ( Long objId ) {
return baseBomInfoMapper . selectBaseBomInfoByObjId ( objId ) ;
}
@ -47,11 +53,19 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* @return 生 产 BOM
* /
@Override
public List < BaseBomInfo > selectBaseBomInfoList ( BaseBomInfo baseBomInfo )
{
return baseBomInfoMapper . selectBaseBomInfoList ( baseBomInfo ) ;
public List < BaseBomInfo > selectBaseBomInfoList ( BaseBomInfo baseBomInfo ) {
baseBomInfo . setMaterialCode ( baseBomInfo . getMaterialCode ( ) ) ;
baseBomInfo . setAncestors ( null ) ;
List < BaseBomInfo > baseBomInfos = baseBomInfoMapper . selectBaseBomInfoList ( baseBomInfo ) ;
return baseBomInfos ;
}
// private List<BaseBomInfo> recursionSelectBaseBomInfoList(List<BaseBomInfo> baseBomInfo) {
// return null;
//
// }
/ * *
* 新 增 生 产 BOM
*
@ -59,18 +73,18 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* @return 结 果
* /
@Override
public int insertBaseBomInfo ( BaseBomInfo baseBomInfo )
{
public int insertBaseBomInfo ( BaseBomInfo baseBomInfo ) {
List < BaseBomInfo > baseBomInfos = baseBomInfoMapper . selectBaseBomInfoList ( baseBomInfo ) ;
if ( StringUtils. isNotNull ( baseBomInfos )) {
if ( baseBomInfos.size ( ) > 0 ) {
throw new BaseException ( "该物料编号:" + baseBomInfo . getMaterialCode ( ) + "已存在!" ) ;
}
if ( StringUtils . isNotNull ( baseBomInfo . getParentId ( ) ) ) {
BaseBomInfo info = baseBomInfoMapper . selectBaseBomInfoByMaterialCode ( baseBomInfo . getParentId ( ) ) ;
baseBomInfo . setAncestors ( info . getAncestors ( ) + "," + baseBomInfo . getMaterialCode ( ) ) ;
} else {
baseBomInfo . setAncestors ( baseBomInfo . getMaterialCode ( ) ) ;
}
// if (StringUtils.isNotNull(baseBomInfo.getParentId())) {
// BaseBomInfo info = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(baseBomInfo.getParentId());
// baseBomInfo.setAncestors(info.getAncestors() + "," + baseBomInfo.getMaterialCode());
// } else {
// baseBomInfo.setAncestors(baseBomInfo.getMaterialCode());
// }
baseBomInfo . setCreatedTime ( DateUtils . getNowDate ( ) ) ;
return baseBomInfoMapper . insertBaseBomInfo ( baseBomInfo ) ;
}
@ -81,22 +95,21 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* @return 结 果
* /
@Override
public int updateBaseBomInfo ( BaseBomInfo baseBomInfo )
{
String parentId = baseBomInfo . getParentId ( ) ;
if ( StringUtils . isNull ( parentId ) ) {
baseBomInfo . setAncestors ( baseBomInfo . getMaterialCode ( ) ) ;
} else {
BaseBomInfo newParentBomInfo = baseBomInfoMapper . selectBaseBomInfoByMaterialCode ( parentId ) ;
BaseBomInfo oldBomInfo = baseBomInfoMapper . selectBaseBomInfoByMaterialCode ( baseBomInfo . getMaterialCode ( ) ) ;
if ( StringUtils . isNotNull ( newParentBomInfo ) & & StringUtils . isNotNull ( oldBomInfo ) )
{
String newAncestors = newParentBomInfo . getAncestors ( ) + "," + baseBomInfo . getMaterialCode ( ) ;
String oldAncestors = oldBomInfo . getAncestors ( ) ;
baseBomInfo . setAncestors ( newAncestors ) ;
updateBomChildren ( baseBomInfo . getMaterialCode ( ) , newAncestors , oldAncestors ) ;
}
}
public int updateBaseBomInfo ( BaseBomInfo baseBomInfo ) {
// String parentId = baseBomInfo.getParentId();
// if (StringUtils.isNull(parentId)) {
// baseBomInfo.setAncestors(baseBomInfo.getMaterialCode());
// } else {
// BaseBomInfo newParentBomInfo = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(parentId);
// BaseBomInfo oldBomInfo = baseBomInfoMapper.selectBaseBomInfoByMaterialCode(baseBomInfo.getMaterialCode());
// if (StringUtils.isNotNull(newParentBomInfo) && StringUtils.isNotNull(oldBomInfo)) {
// String newAncestors = newParentBomInfo.getAncestors() + "," + baseBomInfo.getMaterialCode();
// String oldAncestors = oldBomInfo.getAncestors();
// baseBomInfo.setAncestors(newAncestors);
// updateBomChildren(baseBomInfo.getMaterialCode(), newAncestors, oldAncestors);
// }
// }
baseBomInfo . setUpdatedTime ( DateUtils . getNowDate ( ) ) ;
return baseBomInfoMapper . updateBaseBomInfo ( baseBomInfo ) ;
}
@ -109,12 +122,10 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* /
private void updateBomChildren ( String materialCode , String newAncestors , String oldAncestors ) {
List < BaseBomInfo > children = baseBomInfoMapper . selectChildrenBomById ( materialCode ) ;
for ( BaseBomInfo child : children )
{
for ( BaseBomInfo child : children ) {
child . setAncestors ( child . getAncestors ( ) . replaceFirst ( oldAncestors , newAncestors ) ) ;
}
if ( children . size ( ) > 0 )
{
if ( children . size ( ) > 0 ) {
baseBomInfoMapper . updateBomChildren ( children ) ;
}
@ -127,8 +138,7 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* @return 结 果
* /
@Override
public int deleteBaseBomInfoByObjIds ( Long [ ] objIds )
{
public int deleteBaseBomInfoByObjIds ( Long [ ] objIds ) {
return baseBomInfoMapper . deleteBaseBomInfoByObjIds ( objIds ) ;
}
@ -139,22 +149,19 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
* @return 结 果
* /
@Override
public int deleteBaseBomInfoByObjId ( Long objId )
{
public int deleteBaseBomInfoByObjId ( Long objId ) {
return baseBomInfoMapper . deleteBaseBomInfoByObjId ( objId ) ;
}
/ * *
* 检 查 生 产 BOM 是 否 满 足 下 计 划 条 件
*
* @param baseBomInfoList
* /
@Override
public void checkBomInfo ( List < BaseBomInfo > baseBomInfoList ) {
for ( BaseBomInfo baseBomInfo : baseBomInfoList ) {
if ( baseBomInfo . getStandardAmount ( ) < 1 ) {
throw new ServiceException ( "生产BOM: " + baseBomInfo . getMaterialName ( ) + " 标准数量小于1! " ) ;
}
if ( StringUtils . isEmpty ( baseBomInfo . getProductLineCode ( ) ) ) {
if ( StringUtils . isEmpty ( baseBomInfo . getProductLineCode ( ) ) ) {
throw new ServiceException ( "生产BOM: " + baseBomInfo . getMaterialName ( ) + " 未分配工位!" ) ;
}
}
@ -162,36 +169,145 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService
/ * *
* 自 动 同 步 生 产 BOM
*
* @param baseBomInfo
* @return
* /
@Override
public List < BaseBomInfo > addAutomaticSynchronizationBOM ( BaseBomInfo baseBomInfo ) {
// 获取成品BOM
OrderBomInfo bomInfo = new OrderBomInfo ( ) ;
bomInfo . setMaterialCode ( "90" ) ;
List < OrderBomInfo > orderBomInfos = orderBomInfoMapper . selectFinishedProductBomInfoList ( bomInfo ) ;
// 获取成品物料
BaseMaterialInfo materialInfo = new BaseMaterialInfo ( ) ;
materialInfo . setMaterialSubclass ( MaterialConstants . FP_MATERIAL_TYPE ) ;
List < BaseMaterialInfo > baseMaterialInfos = materialInfoMapper . selectBaseMaterialInfoList ( materialInfo ) ;
// 保存成品BOM信息
for ( OrderBomInfo orderBomInfo : orderBomInfos ) {
try {
for ( BaseMaterialInfo baseMaterialInfo : baseMaterialInfos ) {
BaseBomInfo bomInfo = new BaseBomInfo ( ) ;
bomInfo . setMaterialCode ( baseMaterialInfo . getMaterialCode ( ) ) ;
List < BaseBomInfo > baseBomInfos = baseBomInfoMapper . selectBaseBomInfoList ( bomInfo ) ;
if ( StringUtils . isNull ( baseBomInfos ) ) {
BaseBomInfo info = new BaseBomInfo ( ) ;
info . setBomCode ( orderBomInfo . getMaterialCode ( ) ) ;
info . setMaterialCode ( orderBomInfo . getMaterialCode ( ) ) ;
info . setMaterialName ( orderBom Info. getMaterialName ( ) ) ;
info . setMaterialType ( "100" ) ;
info . setStandardAmount ( 1L ) ;
info . setPlantCode ( info. getPlantCode ( ) ) ;
info . setBomCode ( baseMaterial Info. getMaterialCode ( ) ) ;
info . setMaterialCode ( baseMaterial Info. getMaterialCode ( ) ) ;
info . setMaterialName ( baseMaterial Info. getMaterialName ( ) ) ;
info . setMaterialType ( MaterialConstants . FP_MATERIAL_TYPE ) ;
info . setStandardAmount ( new BigDecimal ( 1 ) ) ;
info . setPlantCode ( baseMater ialI nfo. getPlantCode ( ) ) ;
info . setCreatedTime ( DateUtils . getNowDate ( ) ) ;
try {
this . insertBaseBomInfo ( info ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
// 获取子BOM信息
}
for ( BaseMaterialInfo baseMaterialInfo : baseMaterialInfos ) {
OrderBomInfo cpPomInfo = new OrderBomInfo ( ) ;
cpPomInfo . setParentId ( baseMaterialInfo . getMaterialCode ( ) ) ;
List < OrderBomInfo > orderBomInfos = orderBomInfoService . selectOrderBomInfoList ( cpPomInfo ) ;
if ( orderBomInfos . size ( ) = = 0 ) {
continue ;
}
//根据成品产品BOM存箱体、门体
for ( OrderBomInfo orderBomInfo : orderBomInfos ) {
//箱体
if ( orderBomInfo . getMaterialType ( ) . equals ( MaterialConstants . BOX_MATERIAL_TYPE ) ) {
this . saveBaseBomInfoByMaterialType ( orderBomInfo , MaterialConstants . BOX_MATERIAL_TYPE ) ;
}
//门体
if ( orderBomInfo . getMaterialType ( ) . equals ( MaterialConstants . DOOR_MATERIAL_TYPE ) ) {
this . saveBaseBomInfoByMaterialType ( orderBomInfo , MaterialConstants . DOOR_MATERIAL_TYPE ) ;
}
}
}
//获取箱体产品BOM信息
BaseBomInfo selectBoxBomInfo = new BaseBomInfo ( ) ;
selectBoxBomInfo . setMaterialType ( MaterialConstants . BOX_MATERIAL_TYPE ) ;
List < BaseBomInfo > boxBaseBomInfoList = baseBomInfoMapper . selectBaseBomInfoList ( selectBoxBomInfo ) ;
for ( BaseBomInfo boxBomInfo : boxBaseBomInfoList ) {
OrderBomInfo selectBomInfo = new OrderBomInfo ( ) ;
selectBomInfo . setParentId ( boxBomInfo . getMaterialCode ( ) ) ;
List < OrderBomInfo > bomInfoList = orderBomInfoService . selectOrderBomInfoList ( selectBomInfo ) ;
//Boolean flag = false; // 判断BOM是否含有预装箱体
for ( OrderBomInfo orderBomInfo : bomInfoList ) {
//内胆
if ( orderBomInfo . getMaterialType ( ) . equals ( MaterialConstants . LINER_MATERIAL_TYPE ) ) {
this . saveBaseBomInfoByMaterialType ( orderBomInfo , MaterialConstants . LINER_MATERIAL_TYPE ) ;
}
//围板
if ( orderBomInfo . getMaterialType ( ) . equals ( MaterialConstants . COAMING_MATERIAL_TYPE ) ) {
this . saveBaseBomInfoByMaterialType ( orderBomInfo , MaterialConstants . COAMING_MATERIAL_TYPE ) ;
}
}
}
// 保存子成品BOM信息
//获取围板产品BOM信息
BaseBomInfo selectWBomInfo = new BaseBomInfo ( ) ;
selectWBomInfo . setMaterialType ( MaterialConstants . COAMING_MATERIAL_TYPE ) ;
List < BaseBomInfo > boxBaseWBomInfoList = baseBomInfoMapper . selectBaseBomInfoList ( selectWBomInfo ) ;
for ( BaseBomInfo boxBomInfo : boxBaseWBomInfoList ) {
OrderBomInfo selectBomInfo = new OrderBomInfo ( ) ;
selectBomInfo . setParentId ( boxBomInfo . getMaterialCode ( ) ) ;
List < OrderBomInfo > bomInfoList = orderBomInfoService . selectOrderBomInfoList ( selectBomInfo ) ;
for ( OrderBomInfo orderBomInfo : bomInfoList ) {
//前板
if ( orderBomInfo . getMaterialType ( ) . equals ( MaterialConstants . FORMER_MATERIAL_TYPE ) ) {
this . saveBaseBomInfoByMaterialType ( orderBomInfo , MaterialConstants . FORMER_MATERIAL_TYPE ) ;
}
//后板
if ( orderBomInfo . getMaterialType ( ) . equals ( MaterialConstants . AFTER_MATERIAL_TYPE ) ) {
this . saveBaseBomInfoByMaterialType ( orderBomInfo , MaterialConstants . AFTER_MATERIAL_TYPE ) ;
}
}
}
return null ;
}
/ * *
* 根 据 物 料 类 型 存 生 产 BOM
*
* @param orderBomInfo
* @param materialType
* /
private void saveBaseBomInfoByMaterialType ( OrderBomInfo orderBomInfo , String materialType ) {
List < BaseBomInfo > baseBomInfos = this . checkDuplicateBaseBom ( orderBomInfo ) ;
if ( baseBomInfos . size ( ) > 0 ) {
// 排除异常情况: 生产BOM信息重复
return ;
}
// 保存BOM信息
BaseBomInfo info = new BaseBomInfo ( ) ;
info . setBomCode ( orderBomInfo . getMaterialCode ( ) ) ;
info . setMaterialCode ( orderBomInfo . getMaterialCode ( ) ) ;
info . setMaterialName ( orderBomInfo . getMaterialName ( ) ) ;
info . setMaterialType ( materialType ) ;
info . setParentId ( orderBomInfo . getParentId ( ) ) ;
info . setStandardAmount ( orderBomInfo . getStandardAmount ( ) ) ;
info . setPlantCode ( orderBomInfo . getFactoryCode ( ) ) ;
try {
info . setCreatedTime ( DateUtils . getNowDate ( ) ) ;
baseBomInfoMapper . insertBaseBomInfo ( info ) ;
} catch ( Exception e ) {
System . out . println ( "+++++根据物料类型存生产BOM异常++++: " + e ) ;
;
}
}
/ * *
* 检 测 重 复 生 产 BOM
*
* @param bomInfo
* @return
* /
private List < BaseBomInfo > checkDuplicateBaseBom ( OrderBomInfo bomInfo ) {
BaseBomInfo baseBomOne = new BaseBomInfo ( ) ;
baseBomOne . setMaterialCode ( bomInfo . getMaterialCode ( ) ) ;
baseBomOne . setParentId ( bomInfo . getParentId ( ) ) ;
baseBomOne . setPlantCode ( bomInfo . getFactoryCode ( ) ) ;
return baseBomInfoMapper . selectBaseBomInfoList ( baseBomOne ) ;
}
}