@ -52,6 +52,9 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
@Autowired
private WmsBaseLocationMapper wmsBaseLocationMapper ;
@Autowired
private WmsStockTotalMapper wmsStockTotalMapper ;
@Autowired
private WmsConfig wmsConfig ;
@ -467,6 +470,7 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
* 申 请 领 料
* 在 申 请 领 料 时 , 不 管 是 否 需 要 审 核 , 都 需 要 锁 定 库 位 和 修 改 占 用 数 量 ( 但 审 核 不 通 过 的 话 需 要 解 锁 库 位 和 更 新 占 用 数 量 )
* 申 请 时 没 有 保 存 wms_raw_outstock_detail 表 , 没 有 指 定 库 位
*
* @param wmsRawOutstock 原 材 料 出 库 记 录
* @return 结 果
* /
@ -476,8 +480,8 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
String planCode = wmsRawOutstock . getPlanCode ( ) ;
String planDetailCode = wmsRawOutstock . getPlanDetailCode ( ) ;
if ( StringUtils . isEmpty ( planCode ) ) {
throw new ServiceException ( "请选择 生产详 细信息再领料") ;
if ( StringUtils . isEmpty ( planCode ) | | StringUtils . isEmpty ( planDetailCode ) ) {
throw new ServiceException ( "请选择 计划明 细信息再领料") ;
}
Long warehouseId = wmsRawOutstock . getWarehouseId ( ) ;
@ -501,87 +505,40 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
String taskCode = Seq . getId ( Seq . rawOutstockSeqType , Seq . rawOutstockSeqCode ) ;
//传入的申请领料list遍历
rawOutstockDetails . forEach ( rawOutstockDetail - > {
Long stockTotalId = rawOutstockDetail . getStockTotalId ( ) ;
WmsStockTotal wmsStockTotal = wmsStockTotalMapper . selectWmsStockTotalByStockTotalId ( stockTotalId ) ;
BigDecimal totalAmount = wmsStockTotal . getTotalAmount ( ) ;
BigDecimal frozenAmount = wmsStockTotal . getFrozenAmount ( ) = = null ? BigDecimal . ZERO : wmsStockTotal . getFrozenAmount ( ) ;
BigDecimal occupyAmount = wmsStockTotal . getOccupyAmount ( ) = = null ? BigDecimal . ZERO : wmsStockTotal . getOccupyAmount ( ) ;
BigDecimal availableAmount = totalAmount . subtract ( frozenAmount ) . subtract ( occupyAmount ) ;
BigDecimal planAmount = rawOutstockDetail . getPlanAmount ( ) = = null ?
BigDecimal . ZERO : rawOutstockDetail . getPlanAmount ( ) ; //申请数量
Long materialId = rawOutstockDetail . getMaterialId ( ) ;
if ( planAmount . compareTo ( BigDecimal . ZERO ) > 0 ) {
BigDecimal realRawStock = BigDecimal . ZERO ; //实际库存总量
WmsRawStock queryRawStock = new WmsRawStock ( ) ;
queryRawStock . setWarehouseId ( warehouseId ) ;
queryRawStock . setMaterialId ( materialId ) ;
queryRawStock . setCompleteFlag ( WmsConstants . WMS_RAW_STOCK_COMPLETE_FLAY_YES ) ;
// queryRawStock.setQualityStatus(queryQualityStatus);//todo: 先不过滤质检状态
//TODO:需要先查看wms_raw_stock_occupy, 是否有此生产订单的占用明细,有的话需要计算并且更新
//判断库位和可用数量(总数量减冻结数量和占用数量),按先进先出(按入库时间排序获取)
List < WmsRawStock > wmsRawStocks = wmsRawStockMapper . selectWmsRawStocks4Apply ( queryRawStock ) ;
if ( wmsRawStocks ! = null & & ! wmsRawStocks . isEmpty ( ) ) {
for ( WmsRawStock wmsRawStock : wmsRawStocks ) {
BigDecimal totalAmount = wmsRawStock . getTotalAmount ( ) ;
BigDecimal frozenAmount = wmsRawStock . getFrozenAmount ( ) = = null ? BigDecimal . ZERO : wmsRawStock . getFrozenAmount ( ) ;
BigDecimal occupyAmount = wmsRawStock . getOccupyAmount ( ) = = null ? BigDecimal . ZERO : wmsRawStock . getOccupyAmount ( ) ;
BigDecimal availableAmount = totalAmount . subtract ( frozenAmount ) . subtract ( occupyAmount ) ;
realRawStock = realRawStock . add ( availableAmount ) ;
//可出库数量大于0
if ( availableAmount . compareTo ( BigDecimal . ZERO ) > 0 ) {
//如果申请数量大于此库位可出库的数量则继续进行下一库位判断
if ( planAmount . compareTo ( availableAmount ) > 0 ) {
//占用数量更改
wmsRawStock . setOccupyAmount ( occupyAmount . add ( availableAmount ) ) ;
wmsRawStock . setUpdateDate ( currentDate ) ;
wmsRawStock . setUpdateBy ( userName ) ;
//如果同一个物料有多条记录的处理(最好避免前端可以传多条同一个物料的申请),
//提前更新(主要是更新数量等信息,避免在下一次判断中还使用上次的数量),放在事务中
wmsRawStockMapper . updateWmsRawStock ( wmsRawStock ) ;
//原材料出库记录(有break, 以下方法需要写在此处)
WmsRawOutstock toInsertedRawOutstock = getWmsRawOutstock ( wmsRawStock , baseWarehouse , planCode , planDetailCode , materialId , taskCode , taskType ,
planAmount , currentDate , userName ) ;
toInsertedRawOutstocks . add ( toInsertedRawOutstock ) ;
planAmount = planAmount . subtract ( availableAmount ) ;
} else if ( planAmount . compareTo ( availableAmount ) = = 0 ) { //计划数量等于可出库数量
//占用数量更改
wmsRawStock . setOccupyAmount ( occupyAmount . add ( availableAmount ) ) ;
wmsRawStock . setUpdateDate ( currentDate ) ;
wmsRawStock . setUpdateBy ( userName ) ;
//如果同一个物料有多条记录的处理,提前更新(主要是更新数量等信息,避免在下一次判断中还使用上次的数量),放在事务中
wmsRawStockMapper . updateWmsRawStock ( wmsRawStock ) ;
//原材料出库记录(有break, 以下方法需要写在此处)
WmsRawOutstock toInsertedRawOutstock = getWmsRawOutstock ( wmsRawStock , baseWarehouse , planCode , planDetailCode , materialId , taskCode , taskType ,
planAmount , currentDate , userName ) ;
toInsertedRawOutstocks . add ( toInsertedRawOutstock ) ;
planAmount = BigDecimal . ZERO ;
break ;
} else if ( planAmount . compareTo ( availableAmount ) < 0 ) {
//占用数量更改
wmsRawStock . setOccupyAmount ( occupyAmount . add ( planAmount ) ) ;
wmsRawStock . setUpdateDate ( currentDate ) ;
wmsRawStock . setUpdateBy ( userName ) ;
//如果同一个物料有多条记录的处理,提前更新(主要是更新数量等信息,避免在下一次判断中还使用上次的数量),放在事务中
wmsRawStockMapper . updateWmsRawStock ( wmsRawStock ) ;
//原材料出库记录(有break, 以下方法需要写在此处)
WmsRawOutstock toInsertedRawOutstock = getWmsRawOutstock ( wmsRawStock , baseWarehouse , planCode , planDetailCode , materialId , taskCode , taskType ,
planAmount , currentDate , userName ) ;
toInsertedRawOutstocks . add ( toInsertedRawOutstock ) ;
planAmount = BigDecimal . ZERO ;
break ;
}
}
}
//可出库数量大于0
if ( planAmount . compareTo ( availableAmount ) < = 0 ) {
//占用数量更改
wmsStockTotal . setOccupyAmount ( occupyAmount . add ( availableAmount ) ) ;
wmsStockTotal . setUpdateDate ( currentDate ) ;
wmsStockTotal . setUpdateBy ( userName ) ;
wmsStockTotalMapper . updateWmsStockTotal ( wmsStockTotal ) ;
WmsRawOutstock toInsertedRawOutstock = getWmsRawOutstock ( baseWarehouse , planCode , planDetailCode ,
rawOutstockDetail . getMaterialId ( ) , taskCode , taskType , wmsRawOutstock . getApplyReason ( ) ,
planAmount , currentDate , userName ) ;
toInsertedRawOutstocks . add ( toInsertedRawOutstock ) ;
} else {
throw new ServiceException ( "物料[" + rawOutstockDetail . getMaterialName ( ) + "]库存不够,申请数量不能大于" + availableAmount ) ;
}
//以上将申请的数量跟库存数量比对, 如果库存数量足够则planAmount减去库存会=0,如果不够则剩余的planAmount会>0
if ( planAmount . compareTo ( BigDecimal . ZERO ) > 0 ) {
throw new ServiceException ( "物料名称为[" + rawOutstockDetail . getMaterialName ( ) + "]库存不足,只有" + realRawStock ) ;
}
}
} ) ;
wmsRawOutstockMapper . batchWmsRawOutstock ( toInsertedRawOutstocks ) ;
if ( ! toInsertedRawOutstocks . isEmpty ( ) ) {
wmsRawOutstockMapper . batchWmsRawOutstock ( toInsertedRawOutstocks ) ;
}
return 1 ;
}
@ -590,7 +547,6 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
/ * *
* 获 取 待 保 存 的 原 材 料 出 库 记 录
*
* @param wmsRawStock
* @param baseWarehouse
* @param planCode
* @param planDetailCode
@ -601,8 +557,8 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
* @param userName
* @return
* /
private WmsRawOutstock getWmsRawOutstock ( Wms RawStock wmsRawStock , Wms BaseWarehouse baseWarehouse ,
String planCode , String planDetailCode , Long materialId , String taskCode , String taskType ,
private WmsRawOutstock getWmsRawOutstock ( Wms BaseWarehouse baseWarehouse ,
String planCode , String planDetailCode , Long materialId , String taskCode , String taskType , String applyReason ,
BigDecimal planAmount , Date currentDate , String userName ) {
//出库要求 ( 0申请出库, 1申请审核出库, 2直接出库)
String outRequirement = baseWarehouse . getOutRequirement ( ) ;
@ -624,19 +580,20 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
}
toInsertedRawOutstock . setTaskCode ( taskCode ) ;
toInsertedRawOutstock . setWarehouseId ( wmsRawStock . getWarehouseId ( ) ) ;
toInsertedRawOutstock . setLocationCode ( wmsRawStock . getLocationCode ( ) ) ;
toInsertedRawOutstock . setWarehouseId ( baseWarehouse . getWarehouseId ( ) ) ;
// toInsertedRawOutstock.setLocationCode(wmsRawStock.getLocationCode());
toInsertedRawOutstock . setStationId ( SecurityUtils . getStationId ( ) ) ;
toInsertedRawOutstock . setPalletInfoCode ( wmsRawStock . getPalletInfoCode ( ) ) ;
// toInsertedRawOutstock.setPalletInfoCode(wmsRawStock.getPalletInfoCode());
toInsertedRawOutstock . setOperationType ( operationType ) ;
toInsertedRawOutstock . setApplyBy ( userName ) ;
toInsertedRawOutstock . setApplyReason ( applyReason ) ;
toInsertedRawOutstock . setApplyDate ( currentDate ) ;
toInsertedRawOutstock . setEndStationCode ( SecurityUtils . getStationCode ( ) ) ;
toInsertedRawOutstock . setMaterialId ( materialId ) ;
toInsertedRawOutstock . setOutstockAmount ( planAmount ) ;
toInsertedRawOutstock . setPlanCode ( planCode ) ;
toInsertedRawOutstock . setPlanDetailCode ( planDetailCode ) ;
toInsertedRawOutstock . setMaterialBatch ( wmsRawStock . getInstockBatch ( ) ) ;
// toInsertedRawOutstock.setMaterialBatch(wmsRawStock.getInstockBatch());
toInsertedRawOutstock . setTaskType ( taskType ) ;
toInsertedRawOutstock . setCreateTime ( currentDate ) ;
toInsertedRawOutstock . setCreateBy ( userName ) ;
@ -833,7 +790,8 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
}
private WmsRawOutstock agvRawOutstock ( WmsAgvRawOutstockVo wmsAgvRawOutstockVo , WmsBaseLocation oriBaseLocation , String moveMaterialBarcode , Long moveMaterialId ,
private WmsRawOutstock agvRawOutstock ( WmsAgvRawOutstockVo wmsAgvRawOutstockVo , WmsBaseLocation
oriBaseLocation , String moveMaterialBarcode , Long moveMaterialId ,
String taskType , String userName , Date currentDate ) {
WmsRawOutstock rawOutstock = new WmsRawOutstock ( ) ;
rawOutstock . setWarehouseId ( oriBaseLocation . getWarehouseId ( ) ) ;
@ -863,7 +821,8 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
}
private WmsRawInstock agvRawInstock ( WmsAgvRawOutstockVo wmsAgvRawOutstockVo , WmsBaseLocation targetBaseLocation , String moveMaterialBarcode , Long moveMaterialId ,
private WmsRawInstock agvRawInstock ( WmsAgvRawOutstockVo wmsAgvRawOutstockVo , WmsBaseLocation
targetBaseLocation , String moveMaterialBarcode , Long moveMaterialId ,
String userName , Date currentDate ) {
WmsRawInstock rawInstock = new WmsRawInstock ( ) ;
rawInstock . setWarehouseId ( wmsAgvRawOutstockVo . getWarehouseId ( ) ) ;