@ -14,6 +14,7 @@ import com.hw.common.security.utils.SecurityUtils;
import com.hw.mes.api.RemoteMesService ;
import com.hw.mes.api.domain.MesBaseBarcodeInfo ;
import com.hw.wms.domain.* ;
import com.hw.wms.domain.vo.WmsMoveApplyVo ;
import com.hw.wms.domain.vo.WmsMoveVo ;
import com.hw.wms.mapper.* ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -157,28 +158,28 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
/ * *
* 查 询 移 库 合 库 记 录 列 表 , Join warehouse
* 查 询 移 库 合 库 记 录 列 表 , Join warehouse , group
*
* @param wmsMove 移 库 合 库 记 录
* @return 移 库 合 库 记 录
* /
@Override
public List < WmsMove > selectWmsMove JoinList( WmsMove wmsMove ) {
return wmsMoveMapper . selectWmsMove JoinList( wmsMove ) ;
public List < WmsMove > selectWmsMove Group JoinList( WmsMove wmsMove ) {
return wmsMoveMapper . selectWmsMove Group JoinList( wmsMove ) ;
}
/ * *
* 申 请 移 库
*
* @param wmsMove
* @param wmsMove ApplyVo
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public int applyMove ( WmsMove wmsMove ) {
String oriLocationCode = wmsMove . getOriLocationCode ( ) ;
String targetLocationCode = wmsMove . getTargetLocationCode ( ) ;
public int applyMove ( WmsMove ApplyVo wmsMove ApplyVo ) {
String oriLocationCode = wmsMove ApplyVo . getOriLocationCode ( ) ;
String targetLocationCode = wmsMove ApplyVo . getTargetLocationCode ( ) ;
if ( oriLocationCode . equals ( targetLocationCode ) ) {
throw new ServiceException ( "原库位与目标库位不能相同" ) ;
}
@ -207,9 +208,11 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
}
WmsBaseWarehouse baseWareHouse = wmsBaseWarehouseMapper .
selectWmsBaseWarehouseByWarehouseId ( wmsMove . getWarehouseId ( ) ) ;
selectWmsBaseWarehouseByWarehouseId ( wmsMove ApplyVo . getWarehouseId ( ) ) ;
String warehouseInstockType = baseWareHouse . getWarehouseInstockType ( ) ;
List < WmsMoveDetail > toInsertedMoveDetails = new ArrayList < > ( ) ;
List < WmsMove > toInsertedMoves = new ArrayList < > ( ) ;
Date currentDate = new Date ( ) ;
String userName = SecurityUtils . getUsername ( ) ;
if ( warehouseInstockType . equals ( WmsConstants . WMS_WAREHOUSE_INSTOCK_TYPE_RAW ) ) { //如果是原材料
WmsRawStock queryRawStock = new WmsRawStock ( ) ;
queryRawStock . setLocationCode ( oriLocationCode ) ;
@ -232,7 +235,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
throw new ServiceException ( "目标库位有库存,不能进行移库" ) ;
}
toInsertedMove Detail s = getMove Detail sByRawStocks( wmsRawStocks ) ;
toInsertedMove s = getMove sByRawStocks( wmsRawStocks , wmsMoveApplyVo , userName , currentDate ) ;
} else { //如果是成品
WmsProductStock queryProductStock = new WmsProductStock ( ) ;
queryProductStock . setLocationCode ( oriLocationCode ) ;
@ -255,11 +258,9 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
throw new ServiceException ( "目标库位有库存,不能进行移库" ) ;
}
toInsertedMove Detail s = getMove Detail sByProductStocks( productStocks ) ;
toInsertedMove s = getMove sByProductStocks( productStocks , wmsMoveApplyVo , userName , currentDate ) ;
}
Date currentDate = new Date ( ) ;
String userName = SecurityUtils . getUsername ( ) ;
oriLocation . setLocationStatus ( WmsConstants . WMS_BASE_LOCATION_STATUS_MOVE_LOCK ) ;
oriLocation . setUpdateTime ( currentDate ) ;
oriLocation . setUpdateBy ( userName ) ;
@ -270,47 +271,78 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
targetLocation . setUpdateBy ( userName ) ;
wmsBaseLocationMapper . updateWmsBaseLocation ( targetLocation ) ;
wmsMove . setTaskCode ( Seq . getId ( Seq . wmsMoveSeqType , Seq . wmsMoveSeqCode ) ) ;
wmsMove . setOperationType ( WmsConstants . WMS_OPERATION_TYPE_MANUAL ) ;
wmsMove . setMoveWay ( WmsConstants . WMS_MOVEMERGE_WAY_MANUAL ) ;
wmsMove . setMoveType ( WmsConstants . WMS_MOVEMERGE_TYPE_MOVE ) ;
wmsMove . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMove . setApplyBy ( userName ) ;
wmsMove . setApplyDate ( currentDate ) ;
int rows = wmsMoveMapper . insertWmsMove ( wmsMove ) ;
batchInsertMoveDetails ( toInsertedMoveDetails , wmsMove . getMoveId ( ) , userName , currentDate ) ;
int rows = wmsMoveMapper . batchWmsMove ( toInsertedMoves ) ;
return rows ;
}
public List < WmsMoveDetail > getMoveDetailsByRawStocks ( List < WmsRawStock > wmsRawStocks ) {
List < WmsMoveDetail > wmsMoveDetailList = new ArrayList < > ( ) ;
private List < WmsMove > getMovesByRawStocks ( List < WmsRawStock > wmsRawStocks , WmsMoveApplyVo wmsMoveApplyVo ,
String userName , Date currentDate ) {
List < WmsMove > wmsMoveList = new ArrayList < > ( ) ;
String taskCode = Seq . getId ( Seq . wmsMoveSeqType , Seq . wmsMoveSeqCode ) ;
wmsRawStocks . forEach ( wmsRawStock - > {
WmsMoveDetail wmsMoveDetail = new WmsMoveDetail ( ) ;
wmsMoveDetail . setInstockBatch ( wmsRawStock . getInstockBatch ( ) ) ;
wmsMoveDetail . setMaterialId ( wmsRawStock . getMaterialId ( ) ) ;
wmsMoveDetail . setPlanAmount ( wmsRawStock . getTotalAmount ( ) ) ;
wmsMoveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMoveDetailList . add ( wmsMoveDetail ) ;
WmsMove wmsMove = new WmsMove ( ) ;
wmsMove . setInstockBatch ( wmsRawStock . getInstockBatch ( ) ) ;
wmsMove . setMaterialId ( wmsRawStock . getMaterialId ( ) ) ;
wmsMove . setWarehouseId ( wmsRawStock . getWarehouseId ( ) ) ;
wmsMove . setOriLocationCode ( wmsMoveApplyVo . getOriLocationCode ( ) ) ;
wmsMove . setTargetLocationCode ( wmsMoveApplyVo . getTargetLocationCode ( ) ) ;
wmsMove . setPlanAmount ( wmsRawStock . getTotalAmount ( ) ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMove . setTaskCode ( taskCode ) ;
wmsMove . setOperationType ( WmsConstants . WMS_OPERATION_TYPE_MANUAL ) ;
wmsMove . setMoveWay ( WmsConstants . WMS_MOVEMERGE_WAY_MANUAL ) ;
wmsMove . setMoveType ( wmsMoveApplyVo . getMoveType ( ) ) ;
wmsMove . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMove . setApplyBy ( userName ) ;
wmsMove . setApplyDate ( currentDate ) ;
wmsMoveList . add ( wmsMove ) ;
} ) ;
return wmsMoveDetailList ;
return wmsMove List;
}
public List < WmsMoveDetail > getMoveDetailsByProductStocks ( List < WmsProductStock > wmsProductStocks ) {
List < WmsMoveDetail > wmsMoveDetailList = new ArrayList < > ( ) ;
private List < WmsMove > getMovesByProductStocks ( List < WmsProductStock > wmsProductStocks , WmsMoveApplyVo wmsMoveApplyVo ,
String userName , Date currentDate ) {
List < WmsMove > wmsMoveList = new ArrayList < > ( ) ;
String taskCode = Seq . getId ( Seq . wmsMoveSeqType , Seq . wmsMoveSeqCode ) ;
wmsProductStocks . forEach ( wmsProductStock - > {
WmsMoveDetail wmsMoveDetail = new WmsMoveDetail ( ) ;
wmsMoveDetail . setInstockBatch ( wmsProductStock . getProductBatch ( ) ) ;
wmsMoveDetail . setMaterialId ( wmsProductStock . getProductId ( ) ) ;
wmsMoveDetail . setPlanAmount ( wmsProductStock . getTotalAmount ( ) ) ;
wmsMoveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMoveDetailList . add ( wmsMoveDetail ) ;
WmsMove wmsMove = new WmsMove ( ) ;
wmsMove . setInstockBatch ( wmsProductStock . getProductBatch ( ) ) ;
wmsMove . setWarehouseId ( wmsProductStock . getWarehouseId ( ) ) ;
wmsMove . setOriLocationCode ( wmsMoveApplyVo . getOriLocationCode ( ) ) ;
wmsMove . setTargetLocationCode ( wmsMoveApplyVo . getTargetLocationCode ( ) ) ;
wmsMove . setMaterialId ( wmsProductStock . getProductId ( ) ) ;
wmsMove . setPlanAmount ( wmsProductStock . getTotalAmount ( ) ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMove . setTaskCode ( taskCode ) ;
wmsMove . setOperationType ( WmsConstants . WMS_OPERATION_TYPE_MANUAL ) ;
wmsMove . setMoveWay ( WmsConstants . WMS_MOVEMERGE_WAY_MANUAL ) ;
wmsMove . setMoveType ( wmsMoveApplyVo . getMoveType ( ) ) ;
wmsMove . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_TOEXECUTE ) ;
wmsMove . setApplyBy ( userName ) ;
wmsMove . setApplyDate ( currentDate ) ;
wmsMoveList . add ( wmsMove ) ;
} ) ;
return wmsMoveDetailList ;
return wmsMoveList ;
}
/ * *
* 查 询 移 库 合 库 记 录 列 表 , Join material , warehouse
*
* @param wmsMove 移 库 合 库 记 录
* @return 移 库 合 库 记 录
* /
@Override
public List < WmsMove > selectWmsMoveJoinList ( WmsMove wmsMove ) {
return wmsMoveMapper . selectWmsMoveJoinList ( wmsMove ) ;
}
public void batchInsertMoveDetails ( List < WmsMoveDetail > wmsMoveDetailList , Long moveId , String userName , Date currentDate ) {
wmsMoveDetailList . forEach ( moveDetail - > {
moveDetail . setMoveId ( moveId ) ;
@ -341,7 +373,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
@Override
@Transactional ( rollbackFor = Exception . class )
public int moveOutstock ( WmsMoveVo wmsMoveVo ) {
Long moveId = wmsMoveVo . getMoveId ( ) ;
String taskCode = wmsMoveVo . getTaskCode ( ) ;
String materialBarcode = wmsMoveVo . getMaterialBarcode ( ) ;
String locationCode = wmsMoveVo . getLocationCode ( ) ;
BigDecimal applyQty = wmsMoveVo . getApplyQty ( ) ;
@ -355,6 +387,13 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
throw new ServiceException ( "物料编码有误" ) ;
}
String batchFlag = baseBarcodeInfo . getBatchFlag ( ) ;
if ( ! batchFlag . equals ( MesConstants . IS_BATCH ) ) {
if ( applyQty . compareTo ( BigDecimal . ONE ) > 0 ) {
throw new ServiceException ( "出库数量需等于1" ) ;
}
}
WmsBaseLocation oriLocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
if ( oriLocation = = null ) {
throw new ServiceException ( "库位编码有误" ) ;
@ -362,74 +401,109 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
String barcodeType = baseBarcodeInfo . getBarcodeType ( ) ;
if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_RAW ) ) { //如果是原材料
moveOutUpdateRawStock ( locationCode , baseBarcodeInfo . getBatchCode ( ) , applyQty , userName , currentDate ) ;
} else { //如果是成品
moveOutUpdateProductStock ( locationCode , baseBarcodeInfo . getBatchCode ( ) , applyQty , userName , currentDate ) ;
}
WmsMoveDetail queryMoveDetail = new WmsMoveDetail ( ) ;
queryMoveDetail . setMoveId ( moveId ) ;
List < WmsMoveDetail > wmsMoveDetailList = wmsMoveDetailMapper . selectWmsMoveDetailList ( queryMoveDetail ) ;
if ( wmsMoveDetailList = = null | | wmsMoveDetailList . isEmpty ( ) ) {
String batchCode = baseBarcodeInfo . getBatchCode ( ) ;
WmsMove queryMove = new WmsMove ( ) ;
queryMove . setTaskCode ( taskCode ) ;
// queryMove.setInstockBatch(batchCode);
queryMove . setOriLocationCode ( locationCode ) ;
List < WmsMove > wmsMoveList = wmsMoveMapper . selectWmsMoveList ( queryMove ) ;
if ( wmsMoveList = = null | | wmsMoveList . isEmpty ( ) ) {
throw new ServiceException ( "没有此移库信息" ) ;
}
Map < String , WmsMoveDetail > moveDetailMap = wmsMoveDetailList . stream ( ) .
collect ( Collectors . toMap ( WmsMoveDetail : : getInstockBatch , wmsMoveDetail - > wmsMoveDetail ) ) ;
WmsMoveDetail moveDetail = moveDetailMap . get ( baseBarcodeInfo . getBatchCode ( ) ) ;
if ( moveDetail = = null ) {
WmsMove wmsMove = wmsMoveList . stream ( ) . filter ( move - >
move . getInstockBatch ( ) . equals ( batchCode ) ) . findFirst ( ) . get ( ) ;
if ( wmsMove = = null ) {
throw new ServiceException ( "没有此移库信息" ) ;
}
String executeStatus = moveDetail . getExecuteStatus ( ) ;
BigDecimal planAmount = moveDetail . getPlanAmount ( ) ;
BigDecimal realAmount = moveDetail . getRealAmount ( ) = = null ? BigDecimal . ZERO : moveDetail . getRealAmount ( ) ;
BigDecimal remainingAmount = planAmount . subtract ( realAmount ) ;
String executeStatus = wmsMove . getExecuteStatus ( ) ;
if ( executeStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ) {
throw new ServiceException ( " 已经移库出库完成,无需 再出库") ;
throw new ServiceException ( "此批次已移库出库完成,不能再出库" ) ;
}
if ( executeStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
throw new ServiceException ( " 已经移库入库完成,无需 再出库") ;
throw new ServiceException ( " 此批次已移库入库完成,不能 再出库") ;
}
if ( applyQty . compareTo ( remainingAmount ) > 0 ) {
throw new ServiceException ( "数量不能大于" + remainingAmount ) ;
BigDecimal planAmount = wmsMove . getPlanAmount ( ) ;
BigDecimal realOutstockAmount = wmsMove . getRealOutstockAmount ( ) ;
BigDecimal updateRealOutstockAmount = realOutstockAmount . add ( applyQty ) ;
if ( updateRealOutstockAmount . compareTo ( planAmount ) > 0 ) {
throw new ServiceException ( "数量不能大于" + planAmount . subtract ( realOutstockAmount ) ) ;
}
WmsMove wmsMove = wmsMoveMapper . selectWmsMoveByMoveId ( moveId ) ;
if ( ! locationCode . equals ( wmsMove . getOriLocationCode ( ) ) ) {
throw new ServiceException ( " 库位错误 ") ;
WmsMove Detail existedMoveDetail = wmsMoveDetailMapper . selectWmsMoveDetailByMoveIdAndBarCode ( wmsMove . getMoveId ( ) , materialBarcode ) ;
if ( existedMoveDetail ! = null ) {
throw new ServiceException ( " 此物料条码已经出库,不能重复出库 ") ;
}
String moveExecuteStatus = WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ;
if ( moveDetail . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE ) ) {
moveDetail . setExecuteTime ( currentDate ) ;
moveDetail . setExecutePerson ( userName ) ;
String barcodeType = baseBarcodeInfo . getBarcodeType ( ) ;
if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_RAW ) ) { //如果是原材料
moveOutUpdateRawStock ( locationCode , batchCode , applyQty , userName , currentDate ) ;
} else { //如果是成品
moveOutUpdateProductStock ( locationCode , batchCode , applyQty , userName , currentDate ) ;
}
if ( applyQty . compareTo ( remainingAmount ) < 0 ) {
moveDetail . setRealAmount ( applyQty . subtract ( realAmount ) ) ;
moveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_EXECUTING ) ;
} else {
moveDetail . setRealAmount ( applyQty . subtract ( realAmount ) ) ;
moveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ;
//插入移库合库明细记录
insertMoveDetail ( wmsMove . getMoveId ( ) , baseBarcodeInfo , applyQty , userName , currentDate ) ;
for ( WmsMoveDetail wmsMoveDetail : wmsMoveDetailList ) {
if ( ! wmsMoveDetail . getMoveDetailId ( ) . equals ( moveDetail . getMoveDetailId ( ) ) ) {
if ( wmsMoveDetail . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE )
| | wmsMoveDetail . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_EXECUTING ) ) {
moveExecuteStatus = WmsConstants . WMS_MOVE_EXECUTE_STATUS_EXECUTING ;
//更新移库合库记录,并判断是否解锁库位
outstockUpdateWmsMove ( wmsMove , wmsMoveList , oriLocation , applyQty , userName , currentDate ) ;
return 1 ;
}
public void insertMoveDetail ( Long moveId , MesBaseBarcodeInfo baseBarcodeInfo , BigDecimal applyQty ,
String userName , Date currentDate ) {
WmsMoveDetail toInsertedWmsMoveDetail = new WmsMoveDetail ( ) ;
toInsertedWmsMoveDetail . setMoveId ( moveId ) ;
toInsertedWmsMoveDetail . setMaterialBarcode ( baseBarcodeInfo . getBarcodeInfo ( ) ) ;
toInsertedWmsMoveDetail . setInstockBatch ( baseBarcodeInfo . getBatchCode ( ) ) ;
toInsertedWmsMoveDetail . setMaterialId ( baseBarcodeInfo . getMaterialId ( ) ) ;
toInsertedWmsMoveDetail . setPlanAmount ( applyQty ) ;
toInsertedWmsMoveDetail . setRealAmount ( applyQty ) ;
toInsertedWmsMoveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ;
toInsertedWmsMoveDetail . setExecutePerson ( userName ) ;
toInsertedWmsMoveDetail . setExecuteTime ( currentDate ) ;
wmsMoveDetailMapper . insertWmsMoveDetail ( toInsertedWmsMoveDetail ) ;
}
/ * *
* 在 移 库 出 库 时 更 新 移 库 合 库 记 录 , 判 断 是 否 解 锁 原 库 位
*
* @param wmsMove
* @param wmsMoveList
* @param oriLocation
* @param applyQty
* @param userName
* @param currentDate
* /
public void outstockUpdateWmsMove ( WmsMove wmsMove , List < WmsMove > wmsMoveList , WmsBaseLocation oriLocation ,
BigDecimal applyQty , String userName , Date currentDate ) {
BigDecimal planAmount = wmsMove . getPlanAmount ( ) ;
BigDecimal realOutstockAmount = wmsMove . getRealOutstockAmount ( ) ;
BigDecimal remainingAmount = planAmount . subtract ( realOutstockAmount ) ;
if ( applyQty . compareTo ( remainingAmount ) < 0 ) {
wmsMove . setRealOutstockAmount ( realOutstockAmount . add ( applyQty ) ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_EXECUTING ) ;
} else {
wmsMove . setRealOutstockAmount ( planAmount ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ;
boolean allOustocked = true ; //用来判断原库位是否都已出库完成
for ( WmsMove move : wmsMoveList ) {
if ( ! move . getMoveId ( ) . equals ( wmsMove . getMoveId ( ) ) ) {
if ( move . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE )
| | move . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_EXECUTING ) ) {
allOustocked = false ;
}
}
}
//解锁库位
if ( moveExecuteStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ) {
// 如果都已出库完成, 解锁库位
if ( allOustocked) {
oriLocation . setLocationStatus ( WmsConstants . WMS_BASE_LOCATION_STATUS_NORMAL ) ;
oriLocation . setUpdateBy ( userName ) ;
oriLocation . setUpdateTime ( currentDate ) ;
@ -437,21 +511,15 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
}
}
wmsMoveDetailMapper . updateWmsMoveDetail ( moveDetail ) ;
if ( ! wmsMove . getExecuteStatus ( ) . equals ( moveExecuteStatus ) ) {
if ( wmsMove . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_TOEXECUTE ) ) {
wmsMove . setBeginTime ( currentDate ) ;
}
wmsMove . setExecuteStatus ( moveExecuteStatus ) ;
wmsMoveMapper . updateWmsMove ( wmsMove ) ;
if ( wmsMove . getBeginTime ( ) = = null ) {
wmsMove . setBeginTime ( currentDate ) ;
}
return 1 ;
wmsMove . setUpdateDate ( currentDate ) ;
wmsMove . setUpdateBy ( userName ) ;
wmsMoveMapper . updateWmsMove ( wmsMove ) ;
}
public void moveOutUpdateRawStock ( String locationCode , String batchCode , BigDecimal applyQty ,
String userName , Date currentDate ) {
WmsRawStock wmsRawStock = wmsRawStockMapper . selectRawStockByLocationAndBatch ( locationCode , batchCode ) ;
@ -505,7 +573,6 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
wmsProductStock . setUpdateDate ( currentDate ) ;
wmsProductStockMapper . updateWmsProductStock ( wmsProductStock ) ;
}
}
@ -516,7 +583,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
* @return
* /
public int moveInstock ( WmsMoveVo wmsMoveVo ) {
Long moveId = wmsMoveVo . getMoveId ( ) ;
String taskCode = wmsMoveVo . getTaskCode ( ) ;
String materialBarcode = wmsMoveVo . getMaterialBarcode ( ) ;
String locationCode = wmsMoveVo . getLocationCode ( ) ;
BigDecimal applyQty = wmsMoveVo . getApplyQty ( ) ;
@ -530,228 +597,178 @@ public class WmsMoveServiceImpl implements IWmsMoveService {
throw new ServiceException ( "物料编码有误" ) ;
}
WmsBaseLocation l ocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
if ( l ocation = = null ) {
WmsBaseLocation targetL ocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
if ( targetL ocation = = null ) {
throw new ServiceException ( "库位编码有误" ) ;
}
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
String barcodeType = baseBarcodeInfo . getBarcodeType ( ) ;
String moveExecuteStatus = "" ;
String batchCode = baseBarcodeInfo . getBatchCode ( ) ;
WmsMoveDetail queryMoveDetail = new WmsMoveDetail ( ) ;
queryMoveDetail . setMoveId ( moveId ) ;
List < WmsMoveDetail > moveDetails = wmsMoveDetailMapper . selectWmsMoveDetailList ( queryMoveDetail ) ;
if ( moveDetails = = null | | moveDetails . isEmpty ( ) ) {
throw new ServiceException ( "没有移库出库记录" ) ;
WmsMove queryMove = new WmsMove ( ) ;
queryMove . setTaskCode ( taskCode ) ;
// queryMove.setInstockBatch(batchCode);
queryMove . setTargetLocationCode ( locationCode ) ;
List < WmsMove > wmsMoveList = wmsMoveMapper . selectWmsMoveList ( queryMove ) ;
if ( wmsMoveList = = null | | wmsMoveList . isEmpty ( ) ) {
throw new ServiceException ( "没有此移库信息" ) ;
}
Map < String , WmsMoveDetail > moveDetailMap = moveDetails . stream ( ) .
collect ( Collectors . toMap ( WmsMoveDetail : : getMaterialBarcode , wmsMoveDetail - > wmsMoveDetail ) ) ;
WmsMove wmsMove = wmsMoveList . stream ( ) . filter ( move - >
move . getInstockBatch ( ) . equals ( batchCode ) ) . findFirst ( ) . get ( ) ;
if ( wmsMove = = null ) {
throw new ServiceException ( "没有此移库信息" ) ;
}
WmsMoveDetail wmsMoveDetail = moveDetailMap . get ( materialBarcode ) ;
if ( wmsMoveDetail = = null ) {
throw new ServiceException ( " 没有移库出库记录 ") ;
String executeStatus = wmsMove . getExecuteStatus ( ) ;
if ( executeStatus. equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
throw new ServiceException ( " 此批次已移库入库完成,不能再入库 ") ;
}
moveDetailMap . remove ( wmsMoveDetail ) ;
BigDecimal planAmount = wmsMove . getPlanAmount ( ) ;
BigDecimal realInstockAmount = wmsMove . getRealInstockAmount ( ) ;
BigDecimal updateRealInstockAmount = realInstockAmount . add ( applyQty ) ;
if ( wmsMoveDetail . getPlanAmount ( ) . compareTo ( applyQty ) ! = 0 ) {
throw new ServiceException ( " 入库数量需等于" + wmsMoveDetail . getPlanAmount ( ) ) ;
if ( updateRealInstockAmount. compareTo ( planAmount ) > 0 ) {
throw new ServiceException ( " 数量不能大于" + planAmount . subtract ( realInstockAmount ) ) ;
}
WmsMoveDetail existedMoveDetail = wmsMoveDetailMapper . selectWmsMoveDetailByMoveIdAndBarCode ( wmsMove . getMoveId ( ) , materialBarcode ) ;
if ( existedMoveDetail = = null ) {
throw new ServiceException ( "此物料条码还未移库出库,不能移库入库" ) ;
}
if ( existedMoveDetail . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
throw new ServiceException ( "此物料条码已移库入库,不能重复入库" ) ;
}
if ( ! existedMoveDetail . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ) {
throw new ServiceException ( "此物料条码还未移库出库,不能移库入库" ) ;
}
if ( existedMoveDetail . getRealAmount ( ) . compareTo ( applyQty ) ! = 0 ) {
throw new ServiceException ( "数量需等于" + existedMoveDetail . getRealAmount ( ) ) ;
}
String barcodeType = baseBarcodeInfo . getBarcodeType ( ) ;
//更新库存
if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_RAW ) ) { //如果是原材料
// moveExecuteStatus = moveInUpdateRawStock(Map < String, WmsMoveDetail > moveDetailMap);
moveInUpdateRawStock ( targetLocation , baseBarcodeInfo , applyQty , userName , currentDate ) ;
} else { //如果是成品
// moveExecuteStatus = updateProductStock(locationCode, baseBarcodeInfo.getBatchCode(), applyQty, userName, currentDate, location);
moveInUpdateProductStock ( targetLocation , baseBarcodeInfo , applyQty , userName , currentDate ) ;
}
if ( moveExecuteStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
WmsMove wmsMove = wmsMoveMapper . selectWmsMoveByMoveId ( moveId ) ;
wmsMove . setEndTime ( currentDate ) ;
wmsMove . setExecuteStatus ( moveExecuteStatus ) ;
wmsMoveMapper . updateWmsMove ( wmsMove ) ;
}
//更新移库合库明细记录
existedMoveDetail . setRealInstockAmount ( applyQty ) ;
existedMoveDetail . setExecuteEndTime ( currentDate ) ;
existedMoveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ;
existedMoveDetail . setUpdateDate ( currentDate ) ;
existedMoveDetail . setUpdateBy ( userName ) ;
existedMoveDetail . setRealInstockAmount ( applyQty ) ;
wmsMoveDetailMapper . updateWmsMoveDetail ( existedMoveDetail ) ;
wmsMoveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ;
wmsMoveDetail . setExecuteEndTime ( currentDate ) ;
wmsMoveDetail . setUpdateBy ( userName ) ;
wmsMoveDetail . setUpdateDate ( currentDate ) ;
//更新移库合库记录,并判断是否解锁库位
instockUpdateWmsMove ( wmsMove , wmsMoveList , targetLocation , applyQty , userName , currentDate ) ;
return wmsMoveDetailMapper . updateWmsMoveDetail ( wmsMoveDetail ) ;
return 1 ;
}
public String moveInUpdateRawStock ( Map < String , WmsMoveDetail > moveDetailMap , String locationCode ,
MesBaseBarcodeInfo mesBaseBarcodeInfo ) {
String moveExecuteStatus = WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ;
//先判断是否已全部出库完成
if ( moveDetailMap ! = null | | ! moveDetailMap . isEmpty ( ) ) {
for ( Map . Entry < String , WmsMoveDetail > wmsMoveDetailEntry : moveDetailMap . entrySet ( ) ) {
WmsMoveDetail wmsMoveDetail = wmsMoveDetailEntry . getValue ( ) ;
if ( ! wmsMoveDetail . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
// moveExecuteStatus = WmsConstants.
}
}
}
public void moveInUpdateRawStock ( WmsBaseLocation location , MesBaseBarcodeInfo mesBaseBarcodeInfo ,
BigDecimal applyQty , String userName , Date currentDate ) {
String batchCode = mesBaseBarcodeInfo . getBatchCode ( ) ;
String locationCode = location . getLocationCode ( ) ;
WmsRawStock rawStock = wmsRawStockMapper . selectRawStockByLocationAndBatch ( locationCode , batchCode ) ;
if ( rawStock ! = null ) {
// rawStock.setTotalAmount();
// rawStock.setUpdateDate();
// rawStock.setUpdateBy();
rawStock . setTotalAmount ( rawStock . getTotalAmount ( ) . add ( applyQty ) ) ;
rawStock . setUpdateDate ( currentDate ) ;
rawStock . setUpdateBy ( userName ) ;
wmsRawStockMapper . updateWmsRawStock ( rawStock ) ;
} else {
rawStock = new WmsRawStock ( ) ;
// rawStock.setTotalAmount();
// rawStock.setLocationCode();
// rawStock.setInstockBatch();
// rawStock.setWarehouseId();
// rawStock.setWarehouseFloor();
// rawStock.setStockType();
// rawStock.setMaterialId();
// rawStock.setInstockDate();//条码中的入库时间
// rawStock.setLastOutstockTime();
rawStock . setTotalAmount ( applyQty ) ;
rawStock . setLocationCode ( locationCode ) ;
rawStock . setInstockBatch (mesBaseBarcodeInfo . getBatchCode ( ) ) ;
rawStock . setWarehouseId (location . getWarehouseId ( )) ;
rawStock . setWarehouseFloor (location . getWarehouseFloor ( )) ;
rawStock . setStockType (WmsConstants . RWA_STOCK_STOCK_TYPE_RAW ) ;
rawStock . setMaterialId (mesBaseBarcodeInfo . getMaterialId ( ) ) ;
rawStock . setInstockDate (mesBaseBarcodeInfo . getAcceptedDate ( )) ; //条码中的入库时间
rawStock . setLastOutstockTime (mesBaseBarcodeInfo . getLastOutstockDate ( )) ;
// rawStock.setQualityStatus();
// rawStock.setCompleteFlag();
// rawStock.setCreateDate();
// rawStock.setCreateBy();
rawStock . setCompleteFlag (WmsConstants . WMS_RAW_STOCK_COMPLETE_FLAG_YES ) ;
rawStock . setCreateDate (currentDate ) ;
rawStock . setCreateBy (userName ) ;
wmsRawStockMapper . insertWmsRawStock ( rawStock ) ;
}
return moveExecuteStatus ;
}
public void moveInUpdateProductStock ( WmsBaseLocation location , MesBaseBarcodeInfo mesBaseBarcodeInfo ,
BigDecimal applyQty , String userName , Date currentDate ) {
String materialBarcode = mesBaseBarcodeInfo . getBarcodeInfo ( ) ;
String locationCode = location . getLocationCode ( ) ;
WmsProductStock productStock = new WmsProductStock ( ) ;
productStock . setTotalAmount ( applyQty ) ;
productStock . setLocationCode ( locationCode ) ;
productStock . setProductBatch ( materialBarcode ) ;
productStock . setWarehouseId ( location . getWarehouseId ( ) ) ;
productStock . setWarehouseFloor ( location . getWarehouseFloor ( ) ) ;
productStock . setStockType ( mesBaseBarcodeInfo . getBarcodeType ( ) ) ;
productStock . setProductId ( mesBaseBarcodeInfo . getMaterialId ( ) ) ;
productStock . setInstockDate ( mesBaseBarcodeInfo . getAcceptedDate ( ) ) ; //条码中的入库时间
productStock . setPlanCode ( mesBaseBarcodeInfo . getPlanCode ( ) ) ;
productStock . setPlanDetailCode ( mesBaseBarcodeInfo . getPlanDetailCode ( ) ) ;
productStock . setSaleOrderId ( mesBaseBarcodeInfo . getSaleOrderId ( ) ) ;
productStock . setSaleorderCode ( mesBaseBarcodeInfo . getSaleorderCode ( ) ) ;
// rawStock.setQualityStatus();
productStock . setCreateDate ( currentDate ) ;
productStock . setCreateBy ( userName ) ;
wmsProductStockMapper . insertWmsProductStock ( productStock ) ;
}
/ * *
* 人 工 移 库 出 库
* 在移 库 入 库 时 更 新 移 库 合 库 记 录 , 判 断 是 否 解 锁 目 标 库 位
*
* @param wmsMoveVo
* @return
* @param wmsMove
* @param wmsMoveList
* @param oriLocation
* @param applyQty
* @param userName
* @param currentDate
* /
/ * @Override
@Transactional ( rollbackFor = Exception . class )
public int moveOutstock ( WmsMoveVo wmsMoveVo ) {
String materialBarcode = wmsMoveVo . getMaterialBarcode ( ) ;
String locationCode = wmsMoveVo . getLocationCode ( ) ;
BigDecimal applyQty = wmsMoveVo . getApplyQty ( ) ;
if ( applyQty . compareTo ( BigDecimal . ZERO ) < = 0 ) {
throw new ServiceException ( "出库数量需大于0" ) ;
}
R < MesBaseBarcodeInfo > baseBarcodeInfoR = remoteMesService . getBarcode ( materialBarcode , SecurityConstants . INNER ) ;
MesBaseBarcodeInfo baseBarcodeInfo = baseBarcodeInfoR . getData ( ) ;
if ( baseBarcodeInfo = = null ) {
throw new ServiceException ( "物料编码有误" ) ;
}
String batchFlag = baseBarcodeInfo . getBatchFlag ( ) ;
if ( ! batchFlag . equals ( MesConstants . IS_BATCH ) ) {
if ( applyQty . compareTo ( BigDecimal . ONE ) > 0 ) {
throw new ServiceException ( "出库数量需等于1" ) ;
}
}
WmsBaseLocation location = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
if ( location = = null ) {
throw new ServiceException ( "库位编码有误" ) ;
}
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
String barcodeType = baseBarcodeInfo . getBarcodeType ( ) ;
if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_RAW ) ) { //如果是原材料
WmsRawStock wmsRawStock = wmsRawStockMapper . selectRawStockByLocationAndBatch ( locationCode , baseBarcodeInfo . getBatchCode ( ) ) ;
if ( wmsRawStock = = null ) {
throw new ServiceException ( "无库存信息" ) ;
}
BigDecimal totalAmount = wmsRawStock . getTotalAmount ( ) = = null ? BigDecimal . ZERO : wmsRawStock . getTotalAmount ( ) ;
BigDecimal occupyAmount = wmsRawStock . getOccupyAmount ( ) = = null ? BigDecimal . ZERO : wmsRawStock . getOccupyAmount ( ) ;
BigDecimal frozenAmount = wmsRawStock . getFrozenAmount ( ) = = null ? BigDecimal . ZERO : wmsRawStock . getFrozenAmount ( ) ;
BigDecimal availableAmount = totalAmount . subtract ( occupyAmount ) . subtract ( frozenAmount ) ;
if ( applyQty . compareTo ( availableAmount ) > 0 ) {
throw new ServiceException ( "移库出库数量不能大于" + availableAmount ) ;
}
totalAmount = totalAmount . subtract ( applyQty ) ;
if ( totalAmount . compareTo ( BigDecimal . ZERO ) = = 0 ) {
wmsRawStockMapper . deleteWmsRawStockByRawStockId ( wmsRawStock . getRawStockId ( ) ) ;
} else {
wmsRawStock . setTotalAmount ( totalAmount ) ;
wmsRawStock . setUpdateBy ( userName ) ;
wmsRawStock . setUpdateDate ( currentDate ) ;
wmsRawStockMapper . updateWmsRawStock ( wmsRawStock ) ;
public void instockUpdateWmsMove ( WmsMove wmsMove , List < WmsMove > wmsMoveList , WmsBaseLocation targetLocation ,
BigDecimal applyQty , String userName , Date currentDate ) {
BigDecimal planAmount = wmsMove . getPlanAmount ( ) ;
BigDecimal realInstockAmount = wmsMove . getRealInstockAmount ( ) ;
BigDecimal remainingAmount = planAmount . subtract ( realInstockAmount ) ;
if ( applyQty . compareTo ( remainingAmount ) < 0 ) {
wmsMove . setRealInstockAmount ( realInstockAmount . add ( applyQty ) ) ;
} else {
wmsMove . setRealInstockAmount ( planAmount ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ;
wmsMove . setEndTime ( currentDate ) ;
boolean allInstocked = true ; //用来判断原库位是否都已入库完成
for ( WmsMove move : wmsMoveList ) {
if ( ! move . getMoveId ( ) . equals ( wmsMove . getMoveId ( ) ) ) {
if ( ! move . getExecuteStatus ( ) . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
allInstocked = false ;
}
}
}
} else { //如果是成品
WmsProductStock wmsProductStock = wmsProductStockMapper . selectProductStockByBatch ( materialBarcode ) ;
if ( wmsProductStock = = null | | ! wmsProductStock . getLocationCode ( ) . equals ( locationCode ) ) {
throw new ServiceException ( "无此库存信息" ) ;
}
BigDecimal totalAmount = wmsProductStock . getTotalAmount ( ) = = null ? BigDecimal . ZERO : wmsProductStock . getTotalAmount ( ) ;
BigDecimal occupyAmount = wmsProductStock . getOccupyAmount ( ) = = null ? BigDecimal . ZERO : wmsProductStock . getOccupyAmount ( ) ;
BigDecimal frozenAmount = wmsProductStock . getFrozenAmount ( ) = = null ? BigDecimal . ZERO : wmsProductStock . getFrozenAmount ( ) ;
BigDecimal availableAmount = totalAmount . subtract ( occupyAmount ) . subtract ( frozenAmount ) ;
if ( applyQty . compareTo ( availableAmount ) > 0 ) {
throw new ServiceException ( "移库出库数量不能大于" + availableAmount ) ;
}
totalAmount = totalAmount . subtract ( applyQty ) ;
if ( totalAmount . compareTo ( BigDecimal . ZERO ) = = 0 ) {
wmsProductStockMapper . deleteWmsProductStockByProductStockId ( wmsProductStock . getProductStockId ( ) ) ;
} else {
wmsProductStock . setTotalAmount ( totalAmount ) ;
wmsProductStock . setUpdateBy ( userName ) ;
wmsProductStock . setUpdateDate ( currentDate ) ;
wmsProductStockMapper . updateWmsProductStock ( wmsProductStock ) ;
//如果都已入库完成,解锁库位
if ( allInstocked ) {
targetLocation . setLocationStatus ( WmsConstants . WMS_BASE_LOCATION_STATUS_NORMAL ) ;
targetLocation . setUpdateBy ( userName ) ;
targetLocation . setUpdateTime ( currentDate ) ;
wmsBaseLocationMapper . updateWmsBaseLocation ( targetLocation ) ;
}
}
WmsMoveDetail queryMoveDetail = new WmsMoveDetail ( ) ;
queryMoveDetail . setMaterialBarcode ( materialBarcode ) ;
queryMoveDetail . setMoveExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_EXECUTING ) ; //移库合库记录执行状态正在执行中的,对于已完成的可以重复移库合库
List < WmsMoveDetail > wmsMoveDetails = wmsMoveDetailMapper . selectWmsMoveDetailList ( queryMoveDetail ) ;
if ( wmsMoveDetails ! = null & & ! wmsMoveDetails . isEmpty ( ) ) {
throw new ServiceException ( "已经有此物料信息的移库记录" ) ;
}
WmsMove wmsMove = new WmsMove ( ) ;
wmsMove . setTaskCode ( Seq . getId ( Seq . wmsMoveSeqType , Seq . wmsMoveSeqCode ) ) ;
wmsMove . setWarehouseId ( location . getWarehouseId ( ) ) ;
wmsMove . setOriLocationCode ( locationCode ) ;
wmsMove . setOperationType ( WmsConstants . WMS_OPERATION_TYPE_MANUAL ) ;
wmsMove . setMoveWay ( WmsConstants . WMS_MOVEMERGE_WAY_MANUAL ) ;
wmsMove . setMoveType ( WmsConstants . WMS_MOVEMERGE_TYPE_MOVE ) ;
wmsMove . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsMove . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_EXECUTING ) ;
wmsMove . setApplyBy ( userName ) ;
wmsMove . setApplyDate ( currentDate ) ;
wmsMove . setBeginTime ( currentDate ) ;
wmsMoveMapper . insertWmsMove ( wmsMove ) ;
WmsMoveDetail wmsMoveDetail = new WmsMoveDetail ( ) ;
wmsMoveDetail . setMoveId ( wmsMove . getMoveId ( ) ) ;
wmsMoveDetail . setLocationCode ( locationCode ) ;
wmsMoveDetail . setMaterialBarcode ( materialBarcode ) ;
wmsMoveDetail . setInstockBatch ( baseBarcodeInfo . getBatchCode ( ) ) ;
wmsMoveDetail . setMaterialId ( baseBarcodeInfo . getMaterialId ( ) ) ;
wmsMoveDetail . setPlanAmount ( applyQty ) ;
wmsMoveDetail . setRealAmount ( applyQty ) ;
wmsMoveDetail . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ;
wmsMoveDetail . setExecutePerson ( userName ) ;
wmsMoveDetail . setExecuteTime ( currentDate ) ;
wmsMoveDetail . setMoveDetailType ( WmsConstants . WMS_MOVE_DETAIL_TYPE_OUT ) ;
wmsMoveDetail . setCreateBy ( userName ) ;
wmsMoveDetail . setCreateDate ( currentDate ) ;
wmsMoveDetailMapper . insertWmsMoveDetail ( wmsMoveDetail ) ;
return 1 ;
} * /
wmsMove . setUpdateDate ( currentDate ) ;
wmsMove . setUpdateBy ( userName ) ;
wmsMoveMapper . updateWmsMove ( wmsMove ) ;
}
}