@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service ;
import java.util.ArrayList ;
import java.util.stream.Collectors ;
import com.hw.common.core.utils.StringUtils ;
import org.springframework.transaction.annotation.Transactional ;
@ -157,7 +158,7 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
/ * *
* 新 增 成 品 入 库 记 录 ( 适 用 于 移 动 手 持 端 )
* 新 增 成 品 入 库 记 录 ( 适 用 于 移 动 手 持 端 , 适 用 于 5 楼 成 品 入 库 )
*
* @param wmsProductInstockVo 原 材 料 入 库 记 录
* @return 结 果
@ -181,7 +182,7 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
//todo 仓库可存储此物料判断是否可以入此库位
Date currentDate = new Date ( ) ;
String userName = SecurityUtils . getUsername ( ) ; //todo 是否改成nickname
String userName = SecurityUtils . getUsername ( ) ;
WmsProductInstock wmsProductInstock = new WmsProductInstock ( ) ;
wmsProductInstock . setWarehouseId ( baseLocation . getWarehouseId ( ) ) ;
wmsProductInstock . setLocationCode ( locationCode ) ;
@ -190,8 +191,11 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
wmsProductInstock . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ;
wmsProductInstock . setPlanCode ( baseBarcodeInfo . getPlanCode ( ) ) ;
wmsProductInstock . setPlanDetailCode ( baseBarcodeInfo . getPlanDetailCode ( ) ) ;
wmsProductInstock . setProductBatch ( materialBarcode ) ;
wmsProductInstock . setProductId ( productId ) ;
wmsProductInstock . setInstockType ( WmsConstants . PRODUCT_INSTOCK_INSTOCK_TYPE_PRODUCT ) ;
wmsProductInstock . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsProductInstock . setInstockAmount ( BigDecimal . ONE ) ;
wmsProductInstock . setApplyBy ( userName ) ;
wmsProductInstock . setApplyDate ( currentDate ) ;
@ -199,15 +203,15 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
int rows = wmsProductInstockMapper . insertWmsProductInstock ( wmsProductInstock ) ;
//插入明细
insertWmsProductInstockDetail ( wmsProductInstock , materialBarcode , productId , wmsProductInstockVo ) ;
// insertWmsProductInstockDetail(wmsProductInstock, materialBarcode, productId, wmsProductInstockVo);
//更新库存
updateProductStock ( wmsProductInstock , baseBarcodeInfo , baseLocation ,
materialBarcode , productId , userName , currentDate ) ;
updateProductStock ( baseBarcodeInfo , locationCode , baseLocation . getWarehouseId ( ) , baseLocation . getWarehouseFloor ( ) , userName , currentDate ) ;
return rows ;
}
/ * *
* 插 入 成 品 入 库 明 细 , 手 持 成 品 入 库 使 用 。 适 用 于 4 楼 成 品 入 库
*
@ -233,38 +237,45 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
/ * *
* 更 新 成 品 库 存
* 更 新 成 品 库 存 , 适 合 于 五 楼 PDA 扫 描 成 品 入 库
*
* @param wmsProductInstock
* @param baseLocation
* @param productBatch
* @param productId
* @param baseBarcodeInfo
* @param locationCode
* @param warehouseId
* @param warehouseFloor
* @param userName
* @param currentDate
* /
public void updateProductStock ( WmsProductInstock wmsProductInstock , MesBaseBarcodeInfo baseBarcodeInfo , WmsBaseLocation baseLocation ,
String productBatch, Long productId , String userName, Date currentDate ) {
String locationCode = wmsProductInstock . getLocationCode ( ) ;
public void updateProductStock ( MesBaseBarcodeInfo baseBarcodeInfo , String locationCode , Long warehouseId , Long warehouseFloor ,
String userName, Date currentDate ) {
BigDecimal instockAmount = new BigDecimal ( 1 ) ;
//判断此库位的数量限制,是否还能入库
// WmsProductStock queryProductStock = new WmsProductStock();
// queryProductStock.setLocationCode(locationCode);
// BigDecimal totalAmount = wmsProductStockMapper.getProductStockTotalAmount(queryProductStock);
// totalAmount = totalAmount == null ? BigDecimal.ZERO : totalAmount;
// if (totalAmount.add(instockAmount).compareTo(baseLocation.getQtyLimit()) > 0) {
// throw new ServiceException("已超出库位数量限制,请重新选择库位");
// }
String materialBarcode = baseBarcodeInfo . getBarcodeInfo ( ) ;
WmsProductStock queryProductStock = new WmsProductStock ( ) ;
queryProductStock . setLocationCode ( locationCode ) ;
BigDecimal totalAmount = wmsProductStockMapper . getProductStockTotalAmount ( queryProductStock ) ;
totalAmount = totalAmount = = null ? BigDecimal . ZERO : totalAmount ;
if ( totalAmount . add ( instockAmount ) . compareTo ( baseLocation . getQtyLimit ( ) ) > 0 ) {
throw new ServiceException ( "已超出库位数量限制,请重新选择库位" ) ;
queryProductStock . setProductBatch ( materialBarcode ) ;
WmsProductStock productStock = wmsProductStockMapper . selectProductStockByBatch ( materialBarcode ) ;
if ( productStock ! = null ) {
throw new ServiceException ( "此成品已经入库,无需重复入库" ) ;
}
//一个成品一个条码,对应一条库存信息
WmsProductStock wmsProductStock = new WmsProductStock ( ) ;
wmsProductStock . setWarehouseId ( w msProductInstock. getW arehouseId( ) ) ;
wmsProductStock . setWarehouseId ( w arehouseId) ;
wmsProductStock . setLocationCode ( locationCode ) ;
wmsProductStock . setStockType ( WmsConstants . PRODUCT_STOCK_STOCK_TYPE_PRODUCT ) ;
wmsProductStock . setProductId ( productId ) ;
wmsProductStock . setProductBatch ( productBatch ) ;
wmsProductStock . setProductId ( baseBarcodeInfo. getMaterialId ( ) ) ;
wmsProductStock . setProductBatch ( materialBarcode ) ;
wmsProductStock . setPlanCode ( baseBarcodeInfo . getPlanCode ( ) ) ;
wmsProductStock . setPlanDetailCode ( baseBarcodeInfo . getPlanDetailCode ( ) ) ;
wmsProductStock . setWarehouseFloor ( baseLocation. getWarehouseFloor ( ) ) ;
wmsProductStock . setWarehouseFloor ( warehouseFloor ) ;
wmsProductStock . setSaleorderCode ( baseBarcodeInfo . getSaleorderCode ( ) ) ;
// wmsProductStock.setQualityStatus(wmsRawInstockVo.getQualityStatus());
wmsProductStock . setTotalAmount ( instockAmount ) ;
@ -282,28 +293,96 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
* @return
* /
@Override
public int produceInstock ( WmsProduceInstockVo wmsProduceInstockVo ) {
public int fifthFloorProduceInstock ( WmsProduceInstockVo wmsProduceInstockVo ) {
Long warehouseId = wmsConfig . getFifthSemiWarehouseId ( ) ; //五楼半成品库
String productType = WmsConstants . PRODUCT_STOCK_STOCK_TYPE_SEMI ;
String operationType = WmsConstants . WMS_OPERATION_TYPE_AUTO ;
String executeStatus = WmsConstants . WMS_EXECUTE_STATUS_TOEXECUTE ;
return produceInstock ( wmsProduceInstockVo , warehouseId , productType , operationType , executeStatus , 5L ) ;
}
/ * *
* 新 增 成 品 入 库 记 录 ( 适 用 于 Web 端 , 适 用 于 1 楼 成 品 入 库 , 入 虚 拟 库 , 无 库 位 )
*
* @param wmsProduceInstockVo
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public int firstFloorProduceInstock ( WmsProduceInstockVo wmsProduceInstockVo ) {
Long warehouseId = wmsConfig . getFirstFloorProductWarehouseId ( ) ;
String productType = WmsConstants . PRODUCT_INSTOCK_STOCK_TYPE_PRODUCT ;
String operationType = WmsConstants . WMS_OPERATION_TYPE_MANUAL ;
String executeStatus = WmsConstants . WMS_EXECUTE_STATUS_FINISH ;
return produceInstock ( wmsProduceInstockVo , warehouseId , productType , operationType , executeStatus , 1L ) ;
}
/ * *
* 新 增 成 品 入 库 记 录 ( 适 用 于 Web 端 , 适 用 于 4 楼 成 品 入 库 , 入 虚 拟 库 , 无 库 位 )
*
* @param wmsProduceInstockVo
* @return
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public int fourthFloorProduceInstock ( WmsProduceInstockVo wmsProduceInstockVo ) {
Long warehouseId = wmsConfig . getFourthFloorProductWarehouseId ( ) ;
String productType = WmsConstants . PRODUCT_INSTOCK_STOCK_TYPE_PRODUCT ;
String operationType = WmsConstants . WMS_OPERATION_TYPE_MANUAL ;
String executeStatus = WmsConstants . WMS_EXECUTE_STATUS_FINISH ;
return produceInstock ( wmsProduceInstockVo , warehouseId , productType , operationType , executeStatus , 4L ) ;
}
/ * *
* 新 增 成 品 入 库 记 录
*
* @param wmsProduceInstockVo
* @param warehouseId
* @param productType
* @param operationType
* @param executeStatus
* @return
* /
public int produceInstock ( WmsProduceInstockVo wmsProduceInstockVo , Long warehouseId , String productType , String operationType , String executeStatus , Long warehouseFloor ) {
String materialBarcode = wmsProduceInstockVo . getMaterialBarcode ( ) ;
R < MesBaseBarcodeInfo > baseBarcodeInfoR = remoteMesService . getBarcode ( materialBarcode , SecurityConstants . INNER ) ;
if ( baseBarcodeInfoR = = null ) {
throw new ServiceException ( "物料编码有误" ) ;
}
MesBaseBarcodeInfo baseBarcodeInfo = baseBarcodeInfoR . getData ( ) ;
if ( baseBarcodeInfo = = null ) {
throw new ServiceException ( "物料编码有误" ) ;
}
WmsProductInstock queryProductInstock = new WmsProductInstock ( ) ;
queryProductInstock . setProductBatch ( materialBarcode ) ;
List < WmsProductInstock > wmsProductInstocks = wmsProductInstockMapper . selectWmsProductInstockList ( queryProductInstock ) ;
if ( wmsProductInstocks ! = null & & ! wmsProductInstocks . isEmpty ( ) ) {
throw new ServiceException ( "已经有此物料入库记录" ) ;
if ( baseBarcodeInfo . getBarcodeType ( ) . equals ( WmsConstants . RWA_STOCK_STOCK_TYPE_RAW ) ) {
throw new ServiceException ( "此物料条码为原材料,非成品条码" ) ;
}
Long warehouseId = wmsConfig . getFifthSemiWarehouseId ( ) ; //五楼半成品库
//如果执行状态不是已完成, 是agv入库, 则需要判断是否有入库记录, 避免重复提交; 如果执行状态是已完成( 人工入库) , 则判断是否有此成品条码库存即可
if ( ! executeStatus . equals ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ) {
WmsProductInstock queryProductInstock = new WmsProductInstock ( ) ;
queryProductInstock . setProductBatch ( materialBarcode ) ; //productbatch是索引, 查出来再过滤性能更快
List < WmsProductInstock > wmsProductInstocks = wmsProductInstockMapper . selectWmsProductInstockList ( queryProductInstock ) ;
if ( wmsProductInstocks ! = null & & ! wmsProductInstocks . isEmpty ( ) ) {
List < WmsProductInstock > incompleteProductInstocks = wmsProductInstocks . stream ( ) . filter (
wmsProductInstock - > ! wmsProductInstock . getExecuteStatus ( ) . equals ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ) . collect ( Collectors . toList ( ) ) ;
if ( incompleteProductInstocks ! = null & & ! incompleteProductInstocks . isEmpty ( ) ) {
throw new ServiceException ( "已经有此成品入库记录" ) ;
}
}
}
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
WmsProductInstock wmsProductInstock = new WmsProductInstock ( ) ;
wmsProductInstock . setTaskCode ( Seq . getId ( Seq . productInstockSeqType , Seq . productInstockCode ) ) ;
wmsProductInstock . setWarehouseId ( warehouseId ) ;
wmsProductInstock . setPalletInfoCode ( baseBarcodeInfo . getPalletInfoCode ( ) ) ;
wmsProductInstock . setProductType ( WmsConstants . PRODUCT_STOCK_STOCK_TYPE_SEMI ) ;
wmsProductInstock . setOperationType ( WmsConstants . WMS_OPERATION_TYPE_AUTO ) ;
wmsProductInstock . setProductType ( productType ) ;
wmsProductInstock . setOperationType ( operationType ) ;
wmsProductInstock . setPlanCode ( baseBarcodeInfo . getPlanCode ( ) ) ;
wmsProductInstock . setPlanDetailCode ( baseBarcodeInfo . getPlanDetailCode ( ) ) ;
wmsProductInstock . setInstockType ( WmsConstants . PRODUCT_INSTOCK_INSTOCK_TYPE_PRODUCT ) ;
@ -311,14 +390,16 @@ public class WmsProductInstockServiceImpl implements IWmsProductInstockService {
wmsProductInstock . setProductBatch ( materialBarcode ) ;
wmsProductInstock . setInstockAmount ( BigDecimal . ONE ) ;
wmsProductInstock . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsProductInstock . setExecuteStatus ( WmsConstants. WMS_EXECUTE_STATUS_TOEXECUTE ) ;
wmsProductInstock . setApplyBy ( SecurityUtils. getUsername ( ) ) ;
wmsProductInstock . setApplyDate ( new Date ( ) ) ;
wmsProductInstock . setExecuteStatus ( executeStatus ) ;
wmsProductInstock . setApplyBy ( userName ) ;
wmsProductInstock . setApplyDate ( currentDate ) ;
if ( executeStatus . equals ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ) {
updateProductStock ( baseBarcodeInfo , "" , warehouseId , warehouseFloor , userName , currentDate ) ;
}
return wmsProductInstockMapper . insertWmsProductInstock ( wmsProductInstock ) ;
}
public void syncToErp ( ) {
//todo 根据质检状态是通过的同步给ERP
}