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