@ -7,6 +7,7 @@ import java.util.*;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import com.ruoyi.common.core.redis.RedisCache ;
import com.ruoyi.common.core.redis.RedisCache ;
import com.ruoyi.common.exception.BusinessException ;
import com.ruoyi.common.utils.DateUtils ;
import com.ruoyi.common.utils.DateUtils ;
import com.ruoyi.common.utils.ShiroUtils ;
import com.ruoyi.common.utils.ShiroUtils ;
import com.ruoyi.common.utils.StringUtils ;
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.domain.vo.ErpDevelopModifyorderVo ;
import com.ruoyi.erp.mapper.ErpDevelopModifyorderDetailMapper ;
import com.ruoyi.erp.mapper.ErpDevelopModifyorderDetailMapper ;
import com.ruoyi.erp.service.IErpBomService ;
import com.ruoyi.erp.service.IErpBomService ;
import com.ruoyi.purchase.controller.PurchaseQuoteController ;
import com.ruoyi.purchase.domain.PurchasePlan ;
import com.ruoyi.purchase.domain.PurchasePlan ;
import com.ruoyi.purchase.domain.PurchasePlanChild ;
import com.ruoyi.purchase.domain.PurchasePlanChild ;
import com.ruoyi.purchase.domain.PurchaseQuote ;
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.* ;
import com.ruoyi.system.domain.Vo.SysSupplierVo ;
import com.ruoyi.system.domain.Vo.SysSupplierVo ;
import com.ruoyi.system.mapper.SysMakeOrderMapper ;
import com.ruoyi.system.mapper.SysMakeOrderMapper ;
import com.ruoyi.system.mapper.SysMakeorderBomMapper ;
import com.ruoyi.system.mapper.SysSalesOrderChildMapper ;
import com.ruoyi.system.mapper.SysSalesOrderChildMapper ;
import com.ruoyi.system.mapper.SysSupplierMapper ;
import com.ruoyi.system.mapper.SysSupplierMapper ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeanUtils ;
@ -75,6 +78,13 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Autowired
@Autowired
private SysSupplierMapper sysSupplierMapper ;
private SysSupplierMapper sysSupplierMapper ;
@Autowired
private SysMakeorderBomMapper sysMakeorderBomMapper ;
/ * *
/ * *
* 查询采购计划单
* 查询采购计划单
*
*
@ -194,6 +204,11 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
purchasePlanCodeList = Arrays . asList ( splitSalesOrderCode ) ;
purchasePlanCodeList = Arrays . asList ( splitSalesOrderCode ) ;
}
}
String supplierCode = purchasePlan . getSupplierCode ( ) ;
List < PurchaseQuoteChild > purchaseQuoteChildList = purchaseQuoteChildMapper . selectQuoteChildBySupplierCode ( supplierCode ) ;
//采购计划子表数据
//采购计划子表数据
List < PurchasePlanChild > purchasePlanChildList = purchasePlanChildMapper . selectPurchasePlanChildPlanCodeList ( purchasePlanCodeList ) ;
List < PurchasePlanChild > purchasePlanChildList = purchasePlanChildMapper . selectPurchasePlanChildPlanCodeList ( purchasePlanCodeList ) ;
@ -235,7 +250,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
mergedList . forEach ( item - > {
mergedList . forEach ( item - > {
//字段(本次占用共享库存数):必填;默认为0,若共享可用库存数>0,则默认=共享可用库存数,可修改;需0<=本次占用共享库存数<=共享可用库存数
//字段(本次占用共享库存数):必填;默认为0,若共享可用库存数>0,则默认=共享可用库存数,可修改;需0<=本次占用共享库存数<=共享可用库存数
if ( item . getSharedAvailableInventoryNum ( ) > 0 ) {
if ( item . getSharedAvailableInventoryNum ( ) ! = null & & item . getSharedAvailableInventoryNum ( ) > 0 ) {
item . setSharedInventoryOccupancyNum ( item . getSharedAvailableInventoryNum ( ) ) ;
item . setSharedInventoryOccupancyNum ( item . getSharedAvailableInventoryNum ( ) ) ;
} else {
} else {
item . setSharedInventoryOccupancyNum ( 0 ) ;
item . setSharedInventoryOccupancyNum ( 0 ) ;
@ -337,106 +352,85 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
/ *
/ *
* 生产订单工程 审核后生成采购计划
* 生产订单采购 审核后生成采购计划
* * /
* * /
@Override
@Override
public void generatePurchasePlanByMakeOrder ( List < SysMakeorderBom > insertedSysMakeorderBoms ) {
public void generatePurchasePlanByMakeOrder ( SysMakeOrder makeOrder ) {
// 假设此处有一个 生成唯一采购计划单号的方法
// 生成唯一采购计划单号的方法
String purchasePlanCode = generateUniquePurchasePlanCode ( ) ;
String purchasePlanCode = generateUniquePurchasePlanCode ( ) ;
String loginName = ShiroUtils . getLoginName ( ) ;
List < SysMakeorderBom > uniqueBoms = insertedSysMakeorderBoms . stream ( )
PurchasePlan purchasePlan = new PurchasePlan ( ) ;
// 分组依据为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 ( ) ;
// 第一步:收集所有不同的salesOrderMaterialNo 利用set key值不重复的特性
Set < String > uniqueSalesOrderMaterialNos = new HashSet < > ( ) ;
for ( SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms ) {
uniqueSalesOrderMaterialNos . add ( filterSysMakeorderBom . getSalesOrderMaterialNo ( ) ) ;
}
// 第二步:查询每个salesOrderMaterialNo对应的SalesOrder数据
String makeNo = makeOrder . getMakeNo ( ) ;
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 ) ;
}
Integer purchasePlanMaterialSum = 0 ;
List < SysMakeorderBom > sysMakeorderBoms = sysMakeorderBomMapper . selectSysMakeorderBomByMakeNo ( makeNo ) ;
// 第三步:计算purchasePlanNum
for ( SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms ) {
//保留 只有采购的类型
String salesOrderMaterialNo = filterSysMakeorderBom . getSalesOrderMaterialNo ( ) ;
List < SysMakeorderBom > filterUniqueBoms = sysMakeorderBoms . stream ( ) . filter ( bom - > "0" . equals ( bom . getProcessMethod ( ) ) ) . collect ( Collectors . toList ( ) ) ;
SysSalesOrderChild sysSalesOrderChild = salesOrderChildByMaterialNo . get ( salesOrderMaterialNo ) ;
if ( sysSalesOrderChild ! = null ) {
List < PurchasePlanChild > purchasePlanChildList = new ArrayList < > ( ) ;
//物料数量
Integer materialNum = sysSalesOrderChild . getMaterialNum ( ) ;
for ( SysMakeorderBom filterUniqueBom : filterUniqueBoms ) {
//用量
PurchasePlanChild purchasePlanChild = new PurchasePlanChild ( ) ;
Integer useNum = filterSysMakeorderBom . getUseNum ( ) ;
String salesOrderMaterialNo = filterUniqueBom . getSalesOrderMaterialNo ( ) ;
String tempMakeNo = filterUniqueBom . getMakeNo ( ) ;
//采购计划数
Integer purchasePlanNum = materialNum * useNum ;
int orderNum = 0 ;
if ( StringUtils . isNotEmpty ( salesOrderMaterialNo ) ) {
// 立即创建PurchasePlanChild对象
SysMakeorderBom tempMakeorderBom = new SysMakeorderBom ( ) ;
PurchasePlanChild purchasePlanChild = new PurchasePlanChild ( ) ;
tempMakeorderBom . setMaterialNo ( salesOrderMaterialNo ) ;
purchasePlanChild . setPurchasePlanCode ( purchasePlanCode ) ;
tempMakeorderBom . setMakeNo ( tempMakeNo ) ;
purchasePlanChild . setMaterialNo ( filterSysMakeorderBom . getMaterialNo ( ) ) ;
SysMakeorderBom oldMakeorderBom = sysMakeorderBomMapper . selectSysMakeorderBomByNo ( tempMakeorderBom ) ;
orderNum = oldMakeorderBom . getOrderNum ( ) ;
PurchasePlanChild tempPurchasePlanChild = purchasePlanChildMapper . selectPurchasePlanChildByCodeAndNo ( purchasePlanChild ) ;
if ( tempPurchasePlanChild ! = null ) {
purchasePlanChild . setPlanPurchaseNum ( orderNum * filterUniqueBom . getUseNum ( ) ) ;
purchasePlanChild . setPurchaseNum ( orderNum * filterUniqueBom . getUseNum ( ) ) ;
purchasePlanChild . setPurchasePlanChildId ( tempPurchasePlanChild . getPurchasePlanChildId ( ) ) ;
} else {
//设置计划采购数
purchasePlanChild . setPlanPurchaseNum ( filterUniqueBom . getOrderNum ( ) ) ;
purchasePlanChildMapper . updatePurchasePlanChild ( purchasePlanChild ) ;
purchasePlanChild . setPurchaseNum ( filterUniqueBom . getOrderNum ( ) ) ;
} 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 . setCreateTime ( new Date ( ) ) ;
// 直接保存PurchasePlanChild对象
purchasePlanChildMapper . insertPurchasePlanChild ( purchasePlanChild ) ;
}
// 更新总和
purchasePlanMaterialSum + = purchasePlanNum ;
}
}
}
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 . setCreateBy ( loginName ) ;
purchasePlanChildList . add ( purchasePlanChild ) ;
}
int batchInsertPurchasePlanChildResult = purchasePlanChildMapper . batchInsertPurchasePlanChild ( purchasePlanChildList ) ;
if ( batchInsertPurchasePlanChildResult < = 0 ) {
throw new BusinessException ( "插入采购计划子表数据失败" ) ;
}
//计算计划采购总数
int planPurchaseSum = purchasePlanChildList . stream ( ) . mapToInt ( PurchasePlanChild : : getPlanPurchaseNum ) . sum ( ) ;
// 创建采购计划主记录
purchasePlan . setPurchaseSum ( planPurchaseSum ) ;
PurchasePlan purchasePlan = buildPurchasePlan ( sysMakeOrder , purchasePlanCode , materialAmount , purchasePlanMaterialSum ) ;
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 ( "插入采购计划数据失败" ) ;
}
}
}
}
/ * *
/ * *