|
|
|
@ -13,14 +13,11 @@ import com.hw.common.security.utils.SecurityUtils;
|
|
|
|
|
import com.hw.mes.api.RemoteMesService;
|
|
|
|
|
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
|
|
|
|
|
import com.hw.wms.config.WmsConfig;
|
|
|
|
|
import com.hw.wms.domain.WmsBaseWarehouse;
|
|
|
|
|
import com.hw.wms.domain.WmsProductStock;
|
|
|
|
|
import com.hw.wms.domain.*;
|
|
|
|
|
import com.hw.wms.domain.vo.WmsProduceInstockVo;
|
|
|
|
|
import com.hw.wms.domain.vo.WmsProductOutstockAuditVo;
|
|
|
|
|
import com.hw.wms.domain.vo.WmsProductOutstockConfirmVo;
|
|
|
|
|
import com.hw.wms.mapper.WmsBaseWarehouseMapper;
|
|
|
|
|
import com.hw.wms.mapper.WmsProductOutstockDetailMapper;
|
|
|
|
|
import com.hw.wms.mapper.WmsProductStockMapper;
|
|
|
|
|
import com.hw.wms.mapper.*;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
@ -28,9 +25,6 @@ import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import com.hw.common.core.utils.StringUtils;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import com.hw.wms.domain.WmsProductOutstockDetail;
|
|
|
|
|
import com.hw.wms.mapper.WmsProductOutstockMapper;
|
|
|
|
|
import com.hw.wms.domain.WmsProductOutstock;
|
|
|
|
|
import com.hw.wms.service.IWmsProductOutstockService;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@ -52,6 +46,9 @@ public class WmsProductOutstockServiceImpl implements IWmsProductOutstockService
|
|
|
|
|
@Autowired
|
|
|
|
|
private WmsProductStockMapper wmsProductStockMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WmsStockTotalMapper wmsStockTotalMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WmsBaseWarehouseMapper wmsBaseWarehouseMapper;
|
|
|
|
|
|
|
|
|
@ -98,6 +95,7 @@ public class WmsProductOutstockServiceImpl implements IWmsProductOutstockService
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int insertWmsProductOutstock(WmsProductOutstock wmsProductOutstock) {
|
|
|
|
|
Long warehouseId = wmsProductOutstock.getWarehouseId();
|
|
|
|
|
String saleorderCode = wmsProductOutstock.getSaleorderCode();
|
|
|
|
@ -107,26 +105,22 @@ public class WmsProductOutstockServiceImpl implements IWmsProductOutstockService
|
|
|
|
|
throw new ServiceException("申请数量需大于0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WmsProductStock queryProductStock = new WmsProductStock();
|
|
|
|
|
queryProductStock.setWarehouseId(warehouseId);
|
|
|
|
|
queryProductStock.setSaleorderCode(saleorderCode);
|
|
|
|
|
queryProductStock.setProductId(productId);
|
|
|
|
|
queryProductStock.setSaleOrderId(wmsProductOutstock.getSaleOrderId());
|
|
|
|
|
|
|
|
|
|
//group by wps.warehouse_id,wps.sale_order_id,wps.product_id获取的以下库存信息
|
|
|
|
|
List<WmsProductStock> productStocks = wmsProductStockMapper.selectWmsProductStocksBySaleorder(queryProductStock);
|
|
|
|
|
if (productStocks == null || productStocks.isEmpty()) {
|
|
|
|
|
WmsStockTotal queryStockTotal = new WmsStockTotal();
|
|
|
|
|
queryStockTotal.setWarehouseId(warehouseId);
|
|
|
|
|
queryStockTotal.setMaterialId(productId);
|
|
|
|
|
queryStockTotal.setSaleOrderId(wmsProductOutstock.getSaleOrderId());
|
|
|
|
|
List<WmsStockTotal> wmsStockTotals = wmsStockTotalMapper.selectOnlyWmsStockTotalList(queryStockTotal);
|
|
|
|
|
if (wmsStockTotals == null || wmsStockTotals.isEmpty()) {
|
|
|
|
|
throw new ServiceException("没有库存");
|
|
|
|
|
}
|
|
|
|
|
WmsStockTotal wmsStockTotal = wmsStockTotals.get(0);
|
|
|
|
|
|
|
|
|
|
WmsProductStock productStock = productStocks.get(0);
|
|
|
|
|
BigDecimal orderAmount = productStock.getOrderAmount();
|
|
|
|
|
/*获取仓库可用库存数量*/
|
|
|
|
|
BigDecimal totalAmount = productStock.getTotalAmount() == null ? BigDecimal.ZERO : productStock.getTotalAmount();
|
|
|
|
|
BigDecimal frozenAmount = productStock.getFrozenAmount() == null ? BigDecimal.ZERO : productStock.getFrozenAmount();//冻结数量暂时没用
|
|
|
|
|
BigDecimal occupyAmount = productStock.getOccupyAmount() == null ? BigDecimal.ZERO : productStock.getOccupyAmount();//
|
|
|
|
|
BigDecimal totalAmount = wmsStockTotal.getTotalAmount() == null ? BigDecimal.ZERO : wmsStockTotal.getTotalAmount();
|
|
|
|
|
BigDecimal frozenAmount = wmsStockTotal.getFrozenAmount() == null ? BigDecimal.ZERO : wmsStockTotal.getFrozenAmount();//冻结数量暂时没用
|
|
|
|
|
BigDecimal occupyAmount = wmsStockTotal.getOccupyAmount() == null ? BigDecimal.ZERO : wmsStockTotal.getOccupyAmount();//
|
|
|
|
|
BigDecimal availableAmount = totalAmount.subtract(frozenAmount).subtract(occupyAmount);
|
|
|
|
|
BigDecimal sumApplyQty = productStock.getApplyAmount() == null ? BigDecimal.ZERO : productStock.getApplyAmount();//获取已申请出库数量
|
|
|
|
|
// BigDecimal sumApplyQty = productStock.getApplyAmount() == null ? BigDecimal.ZERO : productStock.getApplyAmount();//获取已申请出库数量
|
|
|
|
|
|
|
|
|
|
// WmsProductOutstock queryProductOutStock = new WmsProductOutstock();
|
|
|
|
|
// queryProductOutStock.setSaleorderCode(saleorderCode);
|
|
|
|
@ -136,11 +130,8 @@ public class WmsProductOutstockServiceImpl implements IWmsProductOutstockService
|
|
|
|
|
// List<WmsProductOutstock> wmsProductOutstocks = wmsProductOutstockMapper.selectWmsProductOutstockList(queryProductOutStock);
|
|
|
|
|
// BigDecimal sumApplyQty = wmsProductOutstocks.stream().map(WmsProductOutstock::getApplyQty).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
|
|
|
//可申请数量
|
|
|
|
|
BigDecimal availableApplyQty = availableAmount.subtract(sumApplyQty);
|
|
|
|
|
|
|
|
|
|
if (applyQty.compareTo(availableApplyQty) > 0) {
|
|
|
|
|
throw new ServiceException("可申请数量为" + availableApplyQty);
|
|
|
|
|
if (applyQty.compareTo(availableAmount) > 0) {
|
|
|
|
|
throw new ServiceException("可申请数量为" + availableAmount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WmsBaseWarehouse warehouse = wmsBaseWarehouseMapper.selectWmsBaseWarehouseByWarehouseId(warehouseId);
|
|
|
|
@ -165,6 +156,12 @@ public class WmsProductOutstockServiceImpl implements IWmsProductOutstockService
|
|
|
|
|
|
|
|
|
|
int rows = wmsProductOutstockMapper.insertWmsProductOutstock(wmsProductOutstock);
|
|
|
|
|
|
|
|
|
|
wmsStockTotal.setOccupyAmount(occupyAmount.add(applyQty));
|
|
|
|
|
wmsStockTotal.setUpdateBy(userName);
|
|
|
|
|
wmsStockTotal.setUpdateDate(currentDate);
|
|
|
|
|
|
|
|
|
|
wmsStockTotalMapper.updateWmsStockTotal(wmsStockTotal);
|
|
|
|
|
|
|
|
|
|
//如果是agv自动仓库,需要调用WCS轮询查询成品出库记录进行调度出库
|
|
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
|