@ -7,6 +7,7 @@ import java.util.*;
import java.util.stream.Collectors ;
import com.ruoyi.common.core.redis.RedisCache ;
import com.ruoyi.common.exception.BusinessException ;
import com.ruoyi.common.utils.DateUtils ;
import com.ruoyi.common.utils.ShiroUtils ;
import com.ruoyi.common.utils.StringUtils ;
@ -15,6 +16,7 @@ import com.ruoyi.erp.domain.ErpDevelopModifyorderDetail;
import com.ruoyi.erp.domain.vo.ErpDevelopModifyorderVo ;
import com.ruoyi.erp.mapper.ErpDevelopModifyorderDetailMapper ;
import com.ruoyi.erp.service.IErpBomService ;
import com.ruoyi.purchase.controller.PurchaseQuoteController ;
import com.ruoyi.purchase.domain.PurchasePlan ;
import com.ruoyi.purchase.domain.PurchasePlanChild ;
import com.ruoyi.purchase.domain.PurchaseQuote ;
@ -26,6 +28,7 @@ import com.ruoyi.purchase.mapper.PurchaseQuoteMapper;
import com.ruoyi.system.domain.* ;
import com.ruoyi.system.domain.Vo.SysSupplierVo ;
import com.ruoyi.system.mapper.SysMakeOrderMapper ;
import com.ruoyi.system.mapper.SysMakeorderBomMapper ;
import com.ruoyi.system.mapper.SysSalesOrderChildMapper ;
import com.ruoyi.system.mapper.SysSupplierMapper ;
import org.springframework.beans.BeanUtils ;
@ -75,6 +78,13 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Autowired
private SysSupplierMapper sysSupplierMapper ;
@Autowired
private SysMakeorderBomMapper sysMakeorderBomMapper ;
/ * *
* 查询采购计划单
*
@ -194,6 +204,11 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
purchasePlanCodeList = Arrays . asList ( splitSalesOrderCode ) ;
}
String supplierCode = purchasePlan . getSupplierCode ( ) ;
List < PurchaseQuoteChild > purchaseQuoteChildList = purchaseQuoteChildMapper . selectQuoteChildBySupplierCode ( supplierCode ) ;
//采购计划子表数据
List < PurchasePlanChild > purchasePlanChildList = purchasePlanChildMapper . selectPurchasePlanChildPlanCodeList ( purchasePlanCodeList ) ;
@ -235,7 +250,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
mergedList . forEach ( item - > {
//字段(本次占用共享库存数):必填;默认为0,若共享可用库存数>0,则默认=共享可用库存数,可修改;需0<=本次占用共享库存数<=共享可用库存数
if ( item . getSharedAvailableInventoryNum ( ) > 0 ) {
if ( item . getSharedAvailableInventoryNum ( ) ! = null & & item . getSharedAvailableInventoryNum ( ) > 0 ) {
item . setSharedInventoryOccupancyNum ( item . getSharedAvailableInventoryNum ( ) ) ;
} else {
item . setSharedInventoryOccupancyNum ( 0 ) ;
@ -337,106 +352,85 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
/ *
* 生产订单工程 审核后生成采购计划
* 生产订单采购 审核后生成采购计划
* * /
@Override
public void generatePurchasePlanByMakeOrder ( List < SysMakeorderBom > insertedSysMakeorderBoms ) {
// 假设此处有一个 生成唯一采购计划单号的方法
public void generatePurchasePlanByMakeOrder ( SysMakeOrder makeOrder ) {
// 生成唯一采购计划单号的方法
String purchasePlanCode = generateUniquePurchasePlanCode ( ) ;
String loginName = ShiroUtils . getLoginName ( ) ;
List < SysMakeorderBom > uniqueBoms = insertedSysMakeorderBoms . stream ( )
// 分组依据为MaterialNo
. collect ( Collectors . groupingBy ( SysMakeorderBom : : getMaterialNo ) )
// 把每个分组转为流,然后取第一个元素
. values ( ) . stream ( )
. map ( groupedBoms - > groupedBoms . stream ( ) . findFirst ( ) . orElse ( null ) )
// 过滤掉null值,以防万一某些分组是空的
. filter ( Objects : : nonNull )
. collect ( Collectors . toList ( ) ) ;
//过滤掉 只有采购的类型
List < SysMakeorderBom > filterUniqueBoms = uniqueBoms . stream ( ) . filter ( bom - > "0" . equals ( bom . getProcessMethod ( ) ) ) . collect ( Collectors . toList ( ) ) ;
//统计物料种类的数量
Integer materialAmount = filterUniqueBoms . size ( ) ;
// 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号
SysMakeOrder sysMakeOrder = sysMakeOrderMapper . selectMakeOrderByMakeNo ( insertedSysMakeorderBoms . get ( 0 ) . getMakeNo ( ) ) ;
//保存所有加工方式为采购的物料
List < SysMakeorderBom > filterSysMakeorderBoms = insertedSysMakeorderBoms . stream ( ) . filter ( bom - > "0" . equals ( bom . getProcessMethod ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( StringUtils . isNotEmpty ( filterUniqueBoms ) ) {
//所有数据的销售订单号相同,只需查一条的销售订单号
String quoteId = filterSysMakeorderBoms . get ( 0 ) . getSalesOrderCode ( ) ;
PurchasePlan purchasePlan = new PurchasePlan ( ) ;
// 第一步:收集所有不同的salesOrderMaterialNo 利用set key值不重复的特性
Set < String > uniqueSalesOrderMaterialNos = new HashSet < > ( ) ;
for ( SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms ) {
uniqueSalesOrderMaterialNos . add ( filterSysMakeorderBom . getSalesOrderMaterialNo ( ) ) ;
}
String makeNo = makeOrder . getMakeNo ( ) ;
// 第二步:查询每个salesOrderMaterialNo对应的SalesOrder数据
Map < String , SysSalesOrderChild > salesOrderChildByMaterialNo = new HashMap < > ( ) ;
for ( String salesOrderMaterialNo : uniqueSalesOrderMaterialNos ) {
SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild ( ) ;
sysSalesOrderChild . setMaterialCode ( salesOrderMaterialNo ) ;
sysSalesOrderChild . setQuoteId ( quoteId ) ;
SysSalesOrderChild salesOrderChild = salesOrderChildMapper . selectSalesOrderChildByCodeAndNo ( sysSalesOrderChild ) ;
salesOrderChildByMaterialNo . put ( salesOrderMaterialNo , salesOrderChild ) ;
}
List < SysMakeorderBom > sysMakeorderBoms = sysMakeorderBomMapper . selectSysMakeorderBomByMakeNo ( makeNo ) ;
Integer purchasePlanMaterialSum = 0 ;
// 第三步:计算purchasePlanNum
for ( SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms ) {
String salesOrderMaterialNo = filterSysMakeorderBom . getSalesOrderMaterialNo ( ) ;
SysSalesOrderChild sysSalesOrderChild = salesOrderChildByMaterialNo . get ( salesOrderMaterialNo ) ;
if ( sysSalesOrderChild ! = null ) {
//物料数量
Integer materialNum = sysSalesOrderChild . getMaterialNum ( ) ;
//用量
Integer useNum = filterSysMakeorderBom . getUseNum ( ) ;
//保留 只有采购的类型
List < SysMakeorderBom > filterUniqueBoms = sysMakeorderBoms . stream ( ) . filter ( bom - > "0" . equals ( bom . getProcessMethod ( ) ) ) . collect ( Collectors . toList ( ) ) ;
//采购计划数
Integer purchasePlanNum = materialNum * useNum ;
List < PurchasePlanChild > purchasePlanChildList = new ArrayList < > ( ) ;
// 立即创建PurchasePlanChild对象
for ( SysMakeorderBom filterUniqueBom : filterUniqueBoms ) {
PurchasePlanChild purchasePlanChild = new PurchasePlanChild ( ) ;
purchasePlanChild . setPurchasePlanCode ( purchasePlanCode ) ;
purchasePlanChild . setMaterialNo ( filterSysMakeorderBom . getMaterialNo ( ) ) ;
PurchasePlanChild tempPurchasePlanChild = purchasePlanChildMapper . selectPurchasePlanChildByCodeAndNo ( purchasePlanChild ) ;
if ( tempPurchasePlanChild ! = null ) {
purchasePlanChild . setPurchasePlanChildId ( tempPurchasePlanChild . getPurchasePlanChildId ( ) ) ;
//设置计划采购数
purchasePlanChildMapper . updatePurchasePlanChild ( purchasePlanChild ) ;
String salesOrderMaterialNo = filterUniqueBom . getSalesOrderMaterialNo ( ) ;
String tempMakeNo = filterUniqueBom . getMakeNo ( ) ;
int orderNum = 0 ;
if ( StringUtils . isNotEmpty ( salesOrderMaterialNo ) ) {
SysMakeorderBom tempMakeorderBom = new SysMakeorderBom ( ) ;
tempMakeorderBom . setMaterialNo ( salesOrderMaterialNo ) ;
tempMakeorderBom . setMakeNo ( tempMakeNo ) ;
SysMakeorderBom oldMakeorderBom = sysMakeorderBomMapper . selectSysMakeorderBomByNo ( tempMakeorderBom ) ;
orderNum = oldMakeorderBom . getOrderNum ( ) ;
purchasePlanChild . setPlanPurchaseNum ( orderNum * filterUniqueBom . getUseNum ( ) ) ;
purchasePlanChild . setPurchaseNum ( orderNum * filterUniqueBom . getUseNum ( ) ) ;
} else {
purchasePlanChild . setMaterialName ( filterSysMakeorderBom . getMaterialName ( ) ) ;
purchasePlanChild . setMaterialType ( filterSysMakeorderBom . getMaterialType ( ) ) ;
purchasePlanChild . setWarehouseDept ( filterSysMakeorderBom . getWarehouseDept ( ) ) ;
purchasePlanChild . setMaterialProcessMethod ( "0" ) ;
purchasePlanChild . setMaterialBrand ( filterSysMakeorderBom . getBrand ( ) ) ;
purchasePlanChild . setMaterialDescribe ( filterSysMakeorderBom . getDescribe ( ) ) ;
purchasePlanChild . setMaterialUnit ( filterSysMakeorderBom . getUnit ( ) ) ;
purchasePlanChild . setWarehouseDept ( filterSysMakeorderBom . getWarehouseDept ( ) ) ;
// 物料的计划采购数,使用计算出的purchasePlanNum
purchasePlanChild . setCreateBy ( ShiroUtils . getLoginName ( ) ) ;
purchasePlanChild . setPlanPurchaseNum ( filterUniqueBom . getOrderNum ( ) ) ;
purchasePlanChild . setPurchaseNum ( filterUniqueBom . getOrderNum ( ) ) ;
}
purchasePlanChild . setPurchasePlanStatus ( "0" ) ;
purchasePlanChild . setPurchasePlanCode ( purchasePlanCode ) ;
purchasePlanChild . setMaterialNo ( filterUniqueBom . getMaterialNo ( ) ) ;
purchasePlanChild . setMaterialName ( filterUniqueBom . getMaterialName ( ) ) ;
purchasePlanChild . setMaterialUnit ( filterUniqueBom . getUnit ( ) ) ;
purchasePlanChild . setMaterialDescribe ( filterUniqueBom . getDescribe ( ) ) ;
purchasePlanChild . setMaterialProcessMethod ( filterUniqueBom . getProcessMethod ( ) ) ;
purchasePlanChild . setMaterialBrand ( filterUniqueBom . getBrand ( ) ) ;
purchasePlanChild . setMaterialType ( filterUniqueBom . getMaterialType ( ) ) ;
purchasePlanChild . setMaterialPhotourl ( filterUniqueBom . getPhotoUrl ( ) ) ;
purchasePlanChild . setMaterialModel ( filterUniqueBom . getMaterialModel ( ) ) ;
purchasePlanChild . setWarehouseDept ( filterUniqueBom . getWarehouseDept ( ) ) ;
purchasePlanChild . setCreateTime ( new Date ( ) ) ;
// 直接保存PurchasePlanChild对象
purchasePlanChildMapper . insertPurchasePlanChild ( purchasePlanChild ) ;
purchasePlanChild . setCreateBy ( loginName ) ;
purchasePlanChildList . ad d( purchasePlanChild ) ;
}
// 更新总和
purchasePlanMaterialSum + = purchasePlanNum ;
}
int batchInsertPurchasePlanChildResult = purchasePlanChildMapper . batchInsertPurchasePlanChild ( purchasePlanChildList ) ;
if ( batchInsertPurchasePlanChildResult < = 0 ) {
throw new BusinessException ( "插入采购计划子表数据失败" ) ;
}
//计算计划采购总数
int planPurchaseSum = purchasePlanChildList . stream ( ) . mapToInt ( PurchasePlanChild : : getPlanPurchaseNum ) . sum ( ) ;
// 创建采购计划主记录
PurchasePlan purchasePlan = buildPurchasePlan ( sysMakeOrder , purchasePlanCode , materialAmount , purchasePlanMaterial Sum ) ;
purchasePlan . setPurchaseSum ( planPurchaseSum ) ;
purchasePlan . setPlanPurchaseSum ( planPurchase Sum) ;
purchasePlanMapper . insertPurchasePlan ( purchasePlan ) ;
purchasePlan . setMaterialSum ( filterUniqueBoms . size ( ) ) ;
purchasePlan . setPurchasePlanType ( "1" ) ; //生产单
purchasePlan . setPurchasePlanCode ( purchasePlanCode ) ;
purchasePlan . setPurchasePlanStatus ( "0" ) ;
purchasePlan . setCorrelationCode ( makeOrder . getMakeNo ( ) ) ;
purchasePlan . setCreateTime ( new Date ( ) ) ;
purchasePlan . setCreateBy ( loginName ) ;
int insertPurchasePlanResult = purchasePlanMapper . insertPurchasePlan ( purchasePlan ) ;
if ( insertPurchasePlanResult < = 0 ) {
throw new BusinessException ( "插入采购计划数据失败" ) ;
}
}
/ * *