@ -8,14 +8,12 @@ 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.WmsBaseLocation ;
import com.hw.wms.domain.WmsProductStock ;
import com.hw.wms.mapper.WmsBaseLocationMapper ;
import com.hw.wms.mapper.WmsProductStockMapper ;
import com.hw.wms.mapper.WmsTransferDetailMapper ;
import com.hw.wms.domain.* ;
import com.hw.wms.mapper.* ;
import com.hw.wms.service.IWmsTransactionalService ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@ -24,9 +22,6 @@ import java.util.ArrayList;
import com.hw.common.core.utils.StringUtils ;
import org.springframework.transaction.annotation.Transactional ;
import com.hw.wms.domain.WmsTransferDetail ;
import com.hw.wms.mapper.WmsTransferMapper ;
import com.hw.wms.domain.WmsTransfer ;
import com.hw.wms.service.IWmsTransferService ;
import javax.annotation.Resource ;
@ -54,6 +49,9 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
@Autowired
private IWmsTransactionalService wmsTransactionalService ;
@Autowired
private WmsBaseWarehouseMapper wmsBaseWarehouseMapper ;
@Resource
private RemoteMesService remoteMesService ;
@ -196,7 +194,8 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
public int transferOutstock ( WmsTransferDetail wmsTransferDetail ) {
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
String locationCode = wmsTransferDetail . getLocationCode ( ) ;
String oriLocationCode = wmsTransferDetail . getLocationCode ( ) ;
String materialBarcode = wmsTransferDetail . getMaterialBarcode ( ) ;
R < MesBaseBarcodeInfo > mesBaseBarcodeInfoR = remoteMesService . getBarcode ( materialBarcode , SecurityConstants . INNER ) ;
@ -208,39 +207,40 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
throw new ServiceException ( "物料编码错误" ) ;
}
String productBatch = mesBaseBarcodeInfo . getBatchCode ( ) ;
Long transferId = wmsTransferDetail . getTransferId ( ) ;
WmsTransfer wmsTransfer ;
if ( transferId = = null ) {
WmsTransfer queryTransfer = new WmsTransfer ( ) ;
queryTransfer . setOriLocationCode ( locationCode ) ;
queryTransfer . setProductBatch ( productBatch ) ;
queryTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_NOT_FINISH ) ;
List < WmsTransfer > wmsTransfers = wmsTransferMapper . selectWmsTransferList ( queryTransfer ) ;
if ( wmsTransfers = = null | | wmsTransfers . isEmpty ( ) ) {
throw new ServiceException ( "没有此任务" ) ;
}
if ( wmsTransfers . size ( ) > 1 ) {
throw new ServiceException ( "有多条此库位任务,请选择具体任务后点击出库" ) ;
}
wmsTransfer = wmsTransfers . get ( 0 ) ;
} else {
wmsTransfer = wmsTransferMapper . selectWmsTransferByTransferId ( transferId ) ;
WmsTransfer queryTransfer = new WmsTransfer ( ) ;
queryTransfer . setOriLocationCode ( oriLocationCode ) ;
queryTransfer . setProductBatch ( materialBarcode ) ;
queryTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_NOT_FINISH ) ;
List < WmsTransfer > wmsTransfers = wmsTransferMapper . selectWmsTransferList ( queryTransfer ) ;
if ( wmsTransfers ! = null & & ! wmsTransfers . isEmpty ( ) ) {
throw new ServiceException ( "有此库位出库任务,请不要重复出库" ) ;
}
BigDecimal applyQty = wmsTransfer . getApplyQty ( ) ;
BigDecimal outstockQty = wmsTransfer . getOutstockQty ( ) = = null ? BigDecimal . ZERO : wmsTransfer . getOutstockQty ( ) ;
BigDecimal currentOutstockQty = outstockQty . add ( BigDecimal . ONE ) ;
if ( applyQty . compareTo ( currentOutstockQty ) < 0 ) {
throw new ServiceException ( "已出库完成,不能多次出库" ) ;
WmsBaseLocation oriLocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( oriLocationCode ) ;
if ( oriLocation = = null ) {
throw new ServiceException ( "库位不存在" ) ;
}
WmsTransfer wmsTransfer = new WmsTransfer ( ) ;
wmsTransfer . setTaskCode ( Seq . getId ( Seq . wmsTransferSeqType , Seq . wmsTransferSeqCode ) ) ;
wmsTransfer . setOriWarehouseId ( oriLocation . getWarehouseId ( ) ) ;
wmsTransfer . setOriLocationCode ( oriLocationCode ) ;
wmsTransfer . setMaterialId ( mesBaseBarcodeInfo . getMaterialId ( ) ) ;
wmsTransfer . setProductBatch ( materialBarcode ) ;
wmsTransfer . setApplyQty ( BigDecimal . ONE ) ;
wmsTransfer . setOutstockQty ( BigDecimal . ONE ) ;
wmsTransfer . setOperationType ( WmsConstants . WMS_OPERATION_TYPE_MANUAL ) ;
wmsTransfer . setTransferType ( WmsConstants . WMS_TRANSFER_TYPE_OUT_TO_PRODUCT_STOCK ) ;
wmsTransfer . setAuditStatus ( WmsConstants . WMS_AUDIT_STATUS_PASS ) ;
wmsTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_EXECUTING ) ;
wmsTransfer . setApplyBy ( userName ) ;
wmsTransfer . setApplyDate ( currentDate ) ;
wmsTransfer . setBeginTime ( currentDate ) ;
wmsTransferMapper . insertWmsTransfer ( wmsTransfer ) ;
//插入转库任务明细
wmsTransferDetail . setTransferId ( wmsTransfer . getTransferId ( ) ) ;
wmsTransferDetail . setInstockBatch ( productBatch ) ;
wmsTransferDetail . setMaterialId ( mesBaseBarcodeInfo . getMaterialId ( ) ) ;
wmsTransferDetail . setRealAmount ( BigDecimal . ONE ) ;
wmsTransferDetail . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ;
@ -251,20 +251,10 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
wmsTransferDetail . setExecuteTime ( currentDate ) ;
wmsTransferDetailMapper . insertWmsTransferDetail ( wmsTransferDetail ) ;
//更新转库任务
wmsTransfer . setOutstockQty ( currentOutstockQty ) ;
wmsTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_EXECUTING ) ;
wmsTransfer . setUpdateDate ( currentDate ) ;
wmsTransfer . setUpdateBy ( userName ) ;
wmsTransferMapper . updateWmsTransfer ( wmsTransfer ) ;
//更新成品库存
WmsProductStock productStock = wmsProductStockMapper . selectProductStockByLocationAndBatch ( locationCode , productBatch , WmsConstants . PRODUCT_STOCK_STOCK_TYPE_SEMI ) ;
productStock . setTotalAmount ( productStock . getTotalAmount ( ) . subtract ( BigDecimal . ONE ) ) ;
productStock . setOccupyAmount ( productStock . getOccupyAmount ( ) . subtract ( BigDecimal . ONE ) ) ;
productStock . setUpdateDate ( currentDate ) ;
productStock . setUpdateBy ( userName ) ;
wmsProductStockMapper . updateWmsProductStock ( productStock ) ;
//删除成品库存
WmsProductStock productStock = wmsProductStockMapper . selectProductStockByBatch ( materialBarcode ) ;
wmsProductStockMapper . deleteWmsProductStockByProductStockId ( productStock . getProductStockId ( ) ) ;
return 1 ;
}
@ -280,7 +270,7 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
public int transferInstock ( WmsTransferDetail wmsTransferDetail ) {
String userName = SecurityUtils . getUsername ( ) ;
Date currentDate = new Date ( ) ;
String l ocationCode = wmsTransferDetail . getLocationCode ( ) ;
String targetL ocationCode = wmsTransferDetail . getLocationCode ( ) ;
String materialBarcode = wmsTransferDetail . getMaterialBarcode ( ) ;
R < MesBaseBarcodeInfo > mesBaseBarcodeInfoR = remoteMesService . getBarcode ( materialBarcode , SecurityConstants . INNER ) ;
@ -291,43 +281,39 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
if ( mesBaseBarcodeInfo = = null ) {
throw new ServiceException ( "物料编码错误" ) ;
}
String productBatch = mesBaseBarcodeInfo . getBatchCode ( ) ;
WmsBaseLocation location = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( locationCode ) ;
Long warehouseId = location . getWarehouseId ( ) ;
Long transferId = wmsTransferDetail . getTransferId ( ) ;
WmsTransfer wmsTransfer ;
if ( transferId = = null ) {
WmsTransfer queryTransfer = new WmsTransfer ( ) ;
queryTransfer . setTargetWarehouseId ( warehouseId ) ;
queryTransfer . setProductBatch ( productBatch ) ;
queryTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_EXECUTING ) ;
List < WmsTransfer > wmsTransfers = wmsTransferMapper . selectWmsTransferList ( queryTransfer ) ;
if ( wmsTransfers = = null | | wmsTransfers . isEmpty ( ) ) {
throw new ServiceException ( "没有此任务或者还未出库" ) ;
}
if ( wmsTransfers . size ( ) > 1 ) {
throw new ServiceException ( "有多条此库位任务,请选择具体任务后点击出库" ) ;
}
wmsTransfer = wmsTransfers . get ( 0 ) ;
} else {
wmsTransfer = wmsTransferMapper . selectWmsTransferByTransferId ( transferId ) ;
WmsBaseLocation targetLocation = wmsBaseLocationMapper . selectWmsBaseLocationByLocationCode ( targetLocationCode ) ;
if ( targetLocation = = null ) {
throw new ServiceException ( "库位不存在" ) ;
}
BigDecimal applyQty = wmsTransfer . getApplyQty ( ) ;
BigDecimal outstockQty = wmsTransfer . getOutstockQty ( ) = = null ? BigDecimal . ZERO : wmsTransfer . getOutstockQty ( ) ;
BigDecimal instockQty = wmsTransfer . getInstockQty ( ) ;
BigDecimal currentInstockQty = instockQty . add ( BigDecimal . ONE ) ;
if ( outstockQty . compareTo ( currentInstockQty ) < 0 ) {
throw new ServiceException ( "请先出库再入库" ) ;
/**判断有没有已出库的转库记录*/
WmsTransfer queryTransfer = new WmsTransfer ( ) ;
queryTransfer . setProductBatch ( materialBarcode ) ;
queryTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_NOT_FINISH ) ;
List < WmsTransfer > wmsTransfers = wmsTransferMapper . selectWmsTransferList ( queryTransfer ) ;
if ( wmsTransfers = = null | | wmsTransfers . isEmpty ( ) ) {
throw new ServiceException ( "没有此成品的转库出库记录,不能转库入库" ) ;
}
Long targetWarehouseId = targetLocation . getWarehouseId ( ) ;
WmsBaseWarehouse targetWarehouse = wmsBaseWarehouseMapper . selectWmsBaseWarehouseByWarehouseId ( targetWarehouseId ) ;
WmsTransfer wmsTransfer = wmsTransfers . get ( 0 ) ;
wmsTransfer . setTargetWarehouseId ( targetWarehouseId ) ;
wmsTransfer . setTargetLocationCode ( targetLocationCode ) ;
wmsTransfer . setInstockQty ( BigDecimal . ONE ) ;
wmsTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ;
wmsTransfer . setUpdateBy ( userName ) ;
wmsTransfer . setUpdateDate ( currentDate ) ;
wmsTransfer . setEndTime ( currentDate ) ;
wmsTransferMapper . updateWmsTransfer ( wmsTransfer ) ;
//插入转库任务明细
wmsTransferDetail . setTransferId ( wmsTransfer . getTransferId ( ) ) ;
wmsTransferDetail . setInstockBatch ( productBatch ) ;
wmsTransferDetail . setInstockBatch ( materialBarcode ) ;
wmsTransferDetail . setMaterialId ( mesBaseBarcodeInfo . getMaterialId ( ) ) ;
wmsTransferDetail . setRealAmount ( BigDecimal . ONE ) ;
wmsTransferDetail . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ;
@ -338,42 +324,25 @@ public class WmsTransferServiceImpl implements IWmsTransferService {
wmsTransferDetail . setExecuteTime ( currentDate ) ;
wmsTransferDetailMapper . insertWmsTransferDetail ( wmsTransferDetail ) ;
//更新转库任务
wmsTransfer . setInstockQty ( currentInstockQty ) ;
if ( applyQty . compareTo ( currentInstockQty ) = = 0 ) { //出库和入库都已完成
wmsTransfer . setExecuteStatus ( WmsConstants . WMS_EXECUTE_STATUS_FINISH ) ;
}
wmsTransfer . setUpdateDate ( currentDate ) ;
wmsTransfer . setUpdateBy ( userName ) ;
wmsTransferMapper . updateWmsTransfer ( wmsTransfer ) ;
//更新成品库存
WmsProductStock productStock = wmsProductStockMapper . selectProductStockByLocationAndBatch ( locationCode , productBatch , WmsConstants . PRODUCT_STOCK_STOCK_TYPE_PRODUCT ) ;
if ( productStock = = null ) {
productStock = new WmsProductStock ( ) ;
productStock . setTotalAmount ( BigDecimal . ONE ) ;
productStock . setWarehouseId ( warehouseId ) ;
productStock . setLocationCode ( locationCode ) ;
productStock . setStockType ( WmsConstants . PRODUCT_STOCK_STOCK_TYPE_PRODUCT ) ;
productStock . setProductBatch ( productBatch ) ;
// productStock.setQualityStatus();//todo: 获取质检状态
productStock . setProductId ( mesBaseBarcodeInfo . getMaterialId ( ) ) ;
productStock . setPlanCode ( mesBaseBarcodeInfo . getPlanCode ( ) ) ;
productStock . setPlanDetailCode ( mesBaseBarcodeInfo . getPlanDetailCode ( ) ) ;
productStock . setSaleorderCode ( mesBaseBarcodeInfo . getSaleorderCode ( ) ) ;
productStock . setCreateDate ( currentDate ) ;
productStock . setCreateBy ( userName ) ;
wmsProductStockMapper . insertWmsProductStock ( productStock ) ;
} else {
productStock . setTotalAmount ( productStock . getTotalAmount ( ) . add ( BigDecimal . ONE ) ) ;
productStock . setUpdateDate ( currentDate ) ;
productStock . setUpdateBy ( userName ) ;
wmsProductStockMapper . updateWmsProductStock ( productStock ) ;
}
//更新成品库存,一个成品一个条码,对应一条库存记录
WmsProductStock productStock = new WmsProductStock ( ) ;
productStock . setTotalAmount ( BigDecimal . ONE ) ;
productStock . setWarehouseId ( targetWarehouseId ) ;
productStock . setLocationCode ( targetLocationCode ) ;
productStock . setStockType ( WmsConstants . PRODUCT_STOCK_STOCK_TYPE_PRODUCT ) ;
productStock . setProductBatch ( materialBarcode ) ;
// productStock.setQualityStatus();//todo: 获取质检状态
productStock . setWarehouseFloor ( targetWarehouse . getWarehouseFloor ( ) ) ;
productStock . setProductId ( mesBaseBarcodeInfo . getMaterialId ( ) ) ;
productStock . setPlanCode ( mesBaseBarcodeInfo . getPlanCode ( ) ) ;
productStock . setPlanDetailCode ( mesBaseBarcodeInfo . getPlanDetailCode ( ) ) ;
productStock . setSaleOrderId ( mesBaseBarcodeInfo . getSaleOrderId ( ) ) ;
productStock . setSaleorderCode ( mesBaseBarcodeInfo . getSaleorderCode ( ) ) ;
productStock . setCreateDate ( currentDate ) ;
productStock . setCreateBy ( userName ) ;
wmsProductStockMapper . insertWmsProductStock ( productStock ) ;
//TODO:同步ERP库存
return 1 ;
}