@ -1,16 +1,35 @@
package com.hw.wms.service.impl ;
import java.math.BigDecimal ;
import java.util.Date ;
import java.util.List ;
import com.hw.common.core.constant.MesConstants ;
import com.hw.common.core.constant.SecurityConstants ;
import com.hw.common.core.constant.WmsConstants ;
import com.hw.common.core.domain.R ;
import com.hw.common.core.exception.ServiceException ;
import com.hw.common.core.utils.uuid.Seq ;
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.WmsMoveVo ;
import com.hw.wms.mapper.* ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import java.util.ArrayList ;
import java.util.Map ;
import java.util.concurrent.atomic.AtomicReference ;
import java.util.stream.Collectors ;
import com.hw.common.core.utils.StringUtils ;
import org.springframework.transaction.annotation.Transactional ;
import com.hw.wms.domain.WmsMoveDetail ;
import com.hw.wms.mapper.WmsMoveMapper ;
import com.hw.wms.domain.WmsMove ;
import com.hw.wms.service.IWmsMoveService ;
import javax.annotation.Resource ;
/ * *
* 移 库 合 库 记 录 Service 业 务 层 处 理
*
@ -18,11 +37,28 @@ import com.hw.wms.service.IWmsMoveService;
* @date 2024 - 01 - 0 9
* /
@Service
public class WmsMoveServiceImpl implements IWmsMoveService
{
public class WmsMoveServiceImpl implements IWmsMoveService {
@Autowired
private WmsMoveMapper wmsMoveMapper ;
@Autowired
private WmsMoveDetailMapper wmsMoveDetailMapper ;
@Autowired
private WmsBaseLocationMapper wmsBaseLocationMapper ;
@Autowired
private WmsBaseWarehouseMapper wmsBaseWarehouseMapper ;
@Autowired
private WmsRawStockMapper wmsRawStockMapper ;
@Autowired
private WmsProductStockMapper wmsProductStockMapper ;
@Resource
private RemoteMesService remoteMesService ;
/ * *
* 查 询 移 库 合 库 记 录
*
@ -30,8 +66,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService
* @return 移 库 合 库 记 录
* /
@Override
public WmsMove selectWmsMoveByMoveId ( Long moveId )
{
public WmsMove selectWmsMoveByMoveId ( Long moveId ) {
return wmsMoveMapper . selectWmsMoveByMoveId ( moveId ) ;
}
@ -42,8 +77,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService
* @return 移 库 合 库 记 录
* /
@Override
public List < WmsMove > selectWmsMoveList ( WmsMove wmsMove )
{
public List < WmsMove > selectWmsMoveList ( WmsMove wmsMove ) {
return wmsMoveMapper . selectWmsMoveList ( wmsMove ) ;
}
@ -55,8 +89,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService
* /
@Transactional
@Override
public int insertWmsMove ( WmsMove wmsMove )
{
public int insertWmsMove ( WmsMove wmsMove ) {
int rows = wmsMoveMapper . insertWmsMove ( wmsMove ) ;
insertWmsMoveDetail ( wmsMove ) ;
return rows ;
@ -70,8 +103,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService
* /
@Transactional
@Override
public int updateWmsMove ( WmsMove wmsMove )
{
public int updateWmsMove ( WmsMove wmsMove ) {
wmsMoveMapper . deleteWmsMoveDetailByMoveId ( wmsMove . getMoveId ( ) ) ;
insertWmsMoveDetail ( wmsMove ) ;
return wmsMoveMapper . updateWmsMove ( wmsMove ) ;
@ -85,8 +117,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService
* /
@Transactional
@Override
public int deleteWmsMoveByMoveIds ( Long [ ] moveIds )
{
public int deleteWmsMoveByMoveIds ( Long [ ] moveIds ) {
wmsMoveMapper . deleteWmsMoveDetailByMoveIds ( moveIds ) ;
return wmsMoveMapper . deleteWmsMoveByMoveIds ( moveIds ) ;
}
@ -99,8 +130,7 @@ public class WmsMoveServiceImpl implements IWmsMoveService
* /
@Transactional
@Override
public int deleteWmsMoveByMoveId ( Long moveId )
{
public int deleteWmsMoveByMoveId ( Long moveId ) {
wmsMoveMapper . deleteWmsMoveDetailByMoveId ( moveId ) ;
return wmsMoveMapper . deleteWmsMoveByMoveId ( moveId ) ;
}
@ -110,22 +140,618 @@ public class WmsMoveServiceImpl implements IWmsMoveService
*
* @param wmsMove 移 库 合 库 记 录 对 象
* /
public void insertWmsMoveDetail ( WmsMove wmsMove )
{
public void insertWmsMoveDetail ( WmsMove wmsMove ) {
List < WmsMoveDetail > wmsMoveDetailList = wmsMove . getWmsMoveDetailList ( ) ;
Long moveId = wmsMove . getMoveId ( ) ;
if ( StringUtils . isNotNull ( wmsMoveDetailList ) )
{
if ( StringUtils . isNotNull ( wmsMoveDetailList ) ) {
List < WmsMoveDetail > list = new ArrayList < WmsMoveDetail > ( ) ;
for ( WmsMoveDetail wmsMoveDetail : wmsMoveDetailList )
{
for ( WmsMoveDetail wmsMoveDetail : wmsMoveDetailList ) {
wmsMoveDetail . setMoveId ( moveId ) ;
list . add ( wmsMoveDetail ) ;
}
if ( list . size ( ) > 0 )
{
if ( list . size ( ) > 0 ) {
wmsMoveMapper . batchWmsMoveDetail ( list ) ;
}
}
}
/ * *
* 查 询 移 库 合 库 记 录 列 表 , Join warehouse
*
* @param wmsMove 移 库 合 库 记 录
* @return 移 库 合 库 记 录
* /
@Override
public List < WmsMove > selectWmsMoveJoinList ( WmsMove wmsMove ) {
return wmsMoveMapper . selectWmsMoveJoinList ( wmsMove ) ;
}
/ * *
* 申 请 移 库
*
* @param wmsMove
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public int applyMove ( WmsMove wmsMove ) {
String oriLocationCode = wmsMove . getOriLocationCode ( ) ;
String targetLocationCode = wmsMove . getTargetLocationCode ( ) ;
if ( oriLocationCode . equals ( targetLocationCode ) ) {
throw new ServiceException ( "原库位与目标库位不能相同" ) ;
}
WmsBaseLocation oriLocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( oriLocationCode ) ;
if ( oriLocation = = null ) {
throw new ServiceException ( "原库位不存在" ) ;
}
String oriLocationStatus = oriLocation . getLocationStatus ( ) ;
if ( ! oriLocationStatus . equals ( WmsConstants . WMS_BASE_LOCATION_STATUS_NORMAL ) ) {
throw new ServiceException ( "原库位已经锁定,不能进行移库" ) ;
}
WmsBaseLocation targetLocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( targetLocationCode ) ;
if ( targetLocation = = null ) {
throw new ServiceException ( "目标库位不存在" ) ;
}
String targetLocationStatus = targetLocation . getLocationStatus ( ) ;
if ( ! targetLocationStatus . equals ( WmsConstants . WMS_BASE_LOCATION_STATUS_NORMAL ) ) {
throw new ServiceException ( "目标库位已经锁定,不能进行移库" ) ;
}
if ( ! oriLocation . getWarehouseId ( ) . equals ( targetLocation . getWarehouseId ( ) ) ) {
throw new ServiceException ( "原库位和目标库位需为一个仓库" ) ;
}
WmsBaseWarehouse baseWareHouse = wmsBaseWarehouseMapper .
selectWmsBaseWarehouseByWarehouseId ( wmsMove . getWarehouseId ( ) ) ;
String warehouseInstockType = baseWareHouse . getWarehouseInstockType ( ) ;
List < WmsMoveDetail > toInsertedMoveDetails = new ArrayList < > ( ) ;
if ( warehouseInstockType . equals ( WmsConstants . WMS_WAREHOUSE_INSTOCK_TYPE_RAW ) ) { //如果是原材料
WmsRawStock queryRawStock = new WmsRawStock ( ) ;
queryRawStock . setLocationCode ( oriLocationCode ) ;
List < WmsRawStock > wmsRawStocks = wmsRawStockMapper . selectWmsRawStockInList ( queryRawStock ) ;
if ( wmsRawStocks = = null | | wmsRawStocks . isEmpty ( ) ) {
throw new ServiceException ( "原库位无库存信息,不能进行移库" ) ;
}
List < WmsRawStock > occupyRawStocks = wmsRawStocks . stream ( ) . filter
( e - > ( e . getOccupyAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 | | e . getFrozenAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) )
. collect ( Collectors . toList ( ) ) ;
if ( occupyRawStocks ! = null & & ! occupyRawStocks . isEmpty ( ) ) {
throw new ServiceException ( "原库位有占用库存信息,不能进行移库" ) ;
}
//目标库位需要是空库位
WmsRawStock queryTargetRawStock = new WmsRawStock ( ) ;
queryTargetRawStock . setLocationCode ( targetLocationCode ) ;
List < WmsRawStock > targetRawStocks = wmsRawStockMapper . selectWmsRawStockInList ( queryTargetRawStock ) ;
if ( targetRawStocks ! = null & & ! targetRawStocks . isEmpty ( ) ) {
throw new ServiceException ( "目标库位有库存,不能进行移库" ) ;
}
toInsertedMoveDetails = getMoveDetailsByRawStocks ( wmsRawStocks ) ;
} else { //如果是成品
WmsProductStock queryProductStock = new WmsProductStock ( ) ;
queryProductStock . setLocationCode ( oriLocationCode ) ;
List < WmsProductStock > productStocks = wmsProductStockMapper . selectWmsProductStockInList ( queryProductStock ) ;
if ( productStocks = = null | | productStocks . isEmpty ( ) ) {
throw new ServiceException ( "原库位无库存信息,不能进行移库" ) ;
}
List < WmsProductStock > occupyProductStocks = productStocks . stream ( ) . filter
( e - > ( e . getOccupyAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 | | e . getFrozenAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) )
. collect ( Collectors . toList ( ) ) ;
if ( occupyProductStocks ! = null & & ! occupyProductStocks . isEmpty ( ) ) {
throw new ServiceException ( "原库位有占用库存信息,不能进行移库" ) ;
}
//目标库位需要是空库位
WmsProductStock queryTargetProductStock = new WmsProductStock ( ) ;
queryTargetProductStock . setLocationCode ( targetLocationCode ) ;
List < WmsProductStock > targetProductStocks = wmsProductStockMapper . selectWmsProductStockInList ( queryTargetProductStock ) ;
if ( targetProductStocks ! = null & & ! targetProductStocks . isEmpty ( ) ) {
throw new ServiceException ( "目标库位有库存,不能进行移库" ) ;
}
toInsertedMoveDetails = getMoveDetailsByProductStocks ( productStocks ) ;
}
Date currentDate = new Date ( ) ;
String userName = SecurityUtils . getUsername ( ) ;
oriLocation . setLocationStatus ( WmsConstants . WMS_BASE_LOCATION_STATUS_MOVE_LOCK ) ;
oriLocation . setUpdateTime ( currentDate ) ;
oriLocation . setUpdateBy ( userName ) ;
wmsBaseLocationMapper . updateWmsBaseLocation ( oriLocation ) ;
targetLocation . setLocationStatus ( WmsConstants . WMS_BASE_LOCATION_STATUS_MOVE_LOCK ) ;
targetLocation . setUpdateTime ( currentDate ) ;
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 ) ;
return rows ;
}
public List < WmsMoveDetail > getMoveDetailsByRawStocks ( List < WmsRawStock > wmsRawStocks ) {
List < WmsMoveDetail > wmsMoveDetailList = new ArrayList < > ( ) ;
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 ) ;
} ) ;
return wmsMoveDetailList ;
}
public List < WmsMoveDetail > getMoveDetailsByProductStocks ( List < WmsProductStock > wmsProductStocks ) {
List < WmsMoveDetail > wmsMoveDetailList = new ArrayList < > ( ) ;
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 ) ;
} ) ;
return wmsMoveDetailList ;
}
public void batchInsertMoveDetails ( List < WmsMoveDetail > wmsMoveDetailList , Long moveId , String userName , Date currentDate ) {
wmsMoveDetailList . forEach ( moveDetail - > {
moveDetail . setMoveId ( moveId ) ;
moveDetail . setCreateBy ( userName ) ;
moveDetail . setCreateDate ( currentDate ) ;
} ) ;
wmsMoveMapper . batchWmsMoveDetail ( wmsMoveDetailList ) ;
}
/ * *
* 获 取 移 库 合 库 记 录 明 细 , join material
*
* @param wmsMoveDetail
* @return
* /
@Override
public List < WmsMoveDetail > selectWmsMoveDetailJoinList ( WmsMoveDetail wmsMoveDetail ) {
return wmsMoveDetailMapper . selectWmsMoveDetailJoinList ( wmsMoveDetail ) ;
}
/ * *
* 人 工 移 库 出 库
*
* @param wmsMoveVo
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public int moveOutstock ( WmsMoveVo wmsMoveVo ) {
Long moveId = wmsMoveVo . getMoveId ( ) ;
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 ( "物料编码有误" ) ;
}
WmsBaseLocation oriLocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
if ( oriLocation = = null ) {
throw new ServiceException ( "库位编码有误" ) ;
}
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 ( ) ) {
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 ) {
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 ) ;
if ( executeStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ) {
throw new ServiceException ( "已经移库出库完成,无需再出库" ) ;
}
if ( executeStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
throw new ServiceException ( "已经移库入库完成,无需再出库" ) ;
}
if ( applyQty . compareTo ( remainingAmount ) > 0 ) {
throw new ServiceException ( "数量不能大于" + remainingAmount ) ;
}
WmsMove wmsMove = wmsMoveMapper . selectWmsMoveByMoveId ( moveId ) ;
if ( ! locationCode . equals ( wmsMove . getOriLocationCode ( ) ) ) {
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 ) ;
}
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 ) ;
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 ;
}
}
}
//解锁库位
if ( moveExecuteStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_OUTSTOCK_FINISH ) ) {
oriLocation . setLocationStatus ( WmsConstants . WMS_BASE_LOCATION_STATUS_NORMAL ) ;
oriLocation . setUpdateBy ( userName ) ;
oriLocation . setUpdateTime ( currentDate ) ;
wmsBaseLocationMapper . updateWmsBaseLocation ( oriLocation ) ;
}
}
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 ) ;
}
return 1 ;
}
public void moveOutUpdateRawStock ( String locationCode , String batchCode , BigDecimal applyQty ,
String userName , Date currentDate ) {
WmsRawStock wmsRawStock = wmsRawStockMapper . selectRawStockByLocationAndBatch ( locationCode , batchCode ) ;
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 ( totalAmount ) > 0 ) {
throw new ServiceException ( "移库出库数量不能大于" + totalAmount ) ;
}
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 moveOutUpdateProductStock ( String locationCode , String batchCode , BigDecimal applyQty ,
String userName , Date currentDate ) {
WmsProductStock wmsProductStock = wmsProductStockMapper . selectProductStockByBatch ( batchCode ) ;
if ( wmsProductStock = = null ) {
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 ( totalAmount ) > 0 ) {
throw new ServiceException ( "移库出库数量不能大于" + totalAmount ) ;
}
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 ) ;
}
}
/ * *
* 人 工 移 库 入 库
*
* @param wmsMoveVo
* @return
* /
public int moveInstock ( WmsMoveVo wmsMoveVo ) {
Long moveId = wmsMoveVo . getMoveId ( ) ;
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 ( "物料编码有误" ) ;
}
WmsBaseLocation location = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
if ( location = = null ) {
throw new ServiceException ( "库位编码有误" ) ;
}
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
String barcodeType = baseBarcodeInfo . getBarcodeType ( ) ;
String moveExecuteStatus = "" ;
WmsMoveDetail queryMoveDetail = new WmsMoveDetail ( ) ;
queryMoveDetail . setMoveId ( moveId ) ;
List < WmsMoveDetail > moveDetails = wmsMoveDetailMapper . selectWmsMoveDetailList ( queryMoveDetail ) ;
if ( moveDetails = = null | | moveDetails . isEmpty ( ) ) {
throw new ServiceException ( "没有移库出库记录" ) ;
}
Map < String , WmsMoveDetail > moveDetailMap = moveDetails . stream ( ) .
collect ( Collectors . toMap ( WmsMoveDetail : : getMaterialBarcode , wmsMoveDetail - > wmsMoveDetail ) ) ;
WmsMoveDetail wmsMoveDetail = moveDetailMap . get ( materialBarcode ) ;
if ( wmsMoveDetail = = null ) {
throw new ServiceException ( "没有移库出库记录" ) ;
}
moveDetailMap . remove ( wmsMoveDetail ) ;
if ( wmsMoveDetail . getPlanAmount ( ) . compareTo ( applyQty ) ! = 0 ) {
throw new ServiceException ( "入库数量需等于" + wmsMoveDetail . getPlanAmount ( ) ) ;
}
if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_RAW ) ) { //如果是原材料
// moveExecuteStatus = moveInUpdateRawStock(Map < String, WmsMoveDetail > moveDetailMap);
} else { //如果是成品
// moveExecuteStatus = updateProductStock(locationCode, baseBarcodeInfo.getBatchCode(), applyQty, userName, currentDate, location);
}
if ( moveExecuteStatus . equals ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ) {
WmsMove wmsMove = wmsMoveMapper . selectWmsMoveByMoveId ( moveId ) ;
wmsMove . setEndTime ( currentDate ) ;
wmsMove . setExecuteStatus ( moveExecuteStatus ) ;
wmsMoveMapper . updateWmsMove ( wmsMove ) ;
}
wmsMoveDetail . setExecuteStatus ( WmsConstants . WMS_MOVE_EXECUTE_STATUS_INSTOCK_FINISH ) ;
wmsMoveDetail . setExecuteEndTime ( currentDate ) ;
wmsMoveDetail . setUpdateBy ( userName ) ;
wmsMoveDetail . setUpdateDate ( currentDate ) ;
return wmsMoveDetailMapper . updateWmsMoveDetail ( wmsMoveDetail ) ;
}
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.
}
}
}
String batchCode = mesBaseBarcodeInfo . getBatchCode ( ) ;
WmsRawStock rawStock = wmsRawStockMapper . selectRawStockByLocationAndBatch ( locationCode , batchCode ) ;
if ( rawStock ! = null ) {
// rawStock.setTotalAmount();
// rawStock.setUpdateDate();
// rawStock.setUpdateBy();
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.setQualityStatus();
// rawStock.setCompleteFlag();
// rawStock.setCreateDate();
// rawStock.setCreateBy();
wmsRawStockMapper . insertWmsRawStock ( rawStock ) ;
}
return moveExecuteStatus ;
}
/ * *
* 人 工 移 库 出 库
*
* @param wmsMoveVo
* @return
* /
/ * @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 ) ;
}
} 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 ) ;
}
}
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 ;
} * /
}