|
@@ -1,5 +1,10 @@
|
|
package com.ruoyi.ams.order.service.impl;
|
|
package com.ruoyi.ams.order.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import cn.hutool.core.comparator.CompareUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.ruoyi.ams.asn.service.IWmsDocAsnHeaderService;
|
|
import com.ruoyi.ams.asn.service.IWmsDocAsnHeaderService;
|
|
import com.ruoyi.ams.box.domain.WmsBoxInfo;
|
|
import com.ruoyi.ams.box.domain.WmsBoxInfo;
|
|
import com.ruoyi.ams.box.mapper.WmsBoxInfoMapper;
|
|
import com.ruoyi.ams.box.mapper.WmsBoxInfoMapper;
|
|
@@ -18,36 +23,36 @@ import com.ruoyi.ams.inv.domain.InvLotLocId;
|
|
import com.ruoyi.ams.inv.domain.form.InvLocIdSearchFrom;
|
|
import com.ruoyi.ams.inv.domain.form.InvLocIdSearchFrom;
|
|
import com.ruoyi.ams.inv.domain.form.InvLotLocIdForm;
|
|
import com.ruoyi.ams.inv.domain.form.InvLotLocIdForm;
|
|
import com.ruoyi.ams.inv.domain.vo.InvLotLocIdLotattVO;
|
|
import com.ruoyi.ams.inv.domain.vo.InvLotLocIdLotattVO;
|
|
|
|
+import com.ruoyi.ams.inv.dto.InvLotAttPalletTotalDTO;
|
|
import com.ruoyi.ams.inv.mapper.InvLotAttMapper;
|
|
import com.ruoyi.ams.inv.mapper.InvLotAttMapper;
|
|
import com.ruoyi.ams.inv.mapper.InvLotLocIdMapper;
|
|
import com.ruoyi.ams.inv.mapper.InvLotLocIdMapper;
|
|
import com.ruoyi.ams.inv.service.IActTransactionLogService;
|
|
import com.ruoyi.ams.inv.service.IActTransactionLogService;
|
|
import com.ruoyi.ams.inv.service.IInvLotAttService;
|
|
import com.ruoyi.ams.inv.service.IInvLotAttService;
|
|
import com.ruoyi.ams.inv.service.IInvLotLocIdService;
|
|
import com.ruoyi.ams.inv.service.IInvLotLocIdService;
|
|
import com.ruoyi.ams.order.domain.ActAllocationDetails;
|
|
import com.ruoyi.ams.order.domain.ActAllocationDetails;
|
|
|
|
+import com.ruoyi.ams.order.domain.PalletMatchLog;
|
|
import com.ruoyi.ams.order.domain.WmsDocOrderDetails;
|
|
import com.ruoyi.ams.order.domain.WmsDocOrderDetails;
|
|
import com.ruoyi.ams.order.domain.WmsDocOrderHeader;
|
|
import com.ruoyi.ams.order.domain.WmsDocOrderHeader;
|
|
import com.ruoyi.ams.order.form.*;
|
|
import com.ruoyi.ams.order.form.*;
|
|
import com.ruoyi.ams.order.mapper.WmsDocOrderDetailsMapper;
|
|
import com.ruoyi.ams.order.mapper.WmsDocOrderDetailsMapper;
|
|
import com.ruoyi.ams.order.mapper.WmsDocOrderHeaderMapper;
|
|
import com.ruoyi.ams.order.mapper.WmsDocOrderHeaderMapper;
|
|
-import com.ruoyi.ams.order.service.IActAllocationDetailsService;
|
|
|
|
-import com.ruoyi.ams.order.service.IWmsDocOrderHeaderService;
|
|
|
|
-import com.ruoyi.ams.order.service.UpdateOrderStockingProcess;
|
|
|
|
|
|
+import com.ruoyi.ams.order.service.*;
|
|
import com.ruoyi.ams.order.vo.CheckOutVO;
|
|
import com.ruoyi.ams.order.vo.CheckOutVO;
|
|
import com.ruoyi.ams.order.vo.PickingListVO;
|
|
import com.ruoyi.ams.order.vo.PickingListVO;
|
|
import com.ruoyi.ams.order.vo.StockOrderVO;
|
|
import com.ruoyi.ams.order.vo.StockOrderVO;
|
|
import com.ruoyi.base.constant.Constant;
|
|
import com.ruoyi.base.constant.Constant;
|
|
import com.ruoyi.base.domain.BaseLocationInfo;
|
|
import com.ruoyi.base.domain.BaseLocationInfo;
|
|
-import com.ruoyi.base.domain.BaseSku;
|
|
|
|
import com.ruoyi.base.domain.vo.CodeSkuRelationshipSoVO;
|
|
import com.ruoyi.base.domain.vo.CodeSkuRelationshipSoVO;
|
|
import com.ruoyi.base.domain.vo.CodeSkuRelationshipVO;
|
|
import com.ruoyi.base.domain.vo.CodeSkuRelationshipVO;
|
|
import com.ruoyi.base.form.SnCheckSoForm;
|
|
import com.ruoyi.base.form.SnCheckSoForm;
|
|
import com.ruoyi.base.service.IBaseLocationInfoService;
|
|
import com.ruoyi.base.service.IBaseLocationInfoService;
|
|
-import com.ruoyi.base.service.IBaseSkuService;
|
|
|
|
import com.ruoyi.base.service.ICodeSkuRelationshipService;
|
|
import com.ruoyi.base.service.ICodeSkuRelationshipService;
|
|
import com.ruoyi.base.utils.IdSequenceUtils;
|
|
import com.ruoyi.base.utils.IdSequenceUtils;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
+import com.ruoyi.common.exception.base.BaseException;
|
|
|
|
+import com.ruoyi.common.utils.ConvertUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
@@ -78,6 +83,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
@Autowired
|
|
@Autowired
|
|
private WmsDocOrderDetailsMapper wmsDocOrderDetailsMapper;
|
|
private WmsDocOrderDetailsMapper wmsDocOrderDetailsMapper;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private IWmsDocOrderDetailsService wmsDocOrderDetailsService;
|
|
|
|
+ @Autowired
|
|
private IActAllocationDetailsService actAllocationDetailsService;
|
|
private IActAllocationDetailsService actAllocationDetailsService;
|
|
@Autowired
|
|
@Autowired
|
|
private IWmsDocOrderHeaderService wmsDocOrderHeaderService;
|
|
private IWmsDocOrderHeaderService wmsDocOrderHeaderService;
|
|
@@ -108,10 +115,11 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
@Autowired
|
|
@Autowired
|
|
private IWmsDocAsnHeaderService iWmsDocAsnHeaderService;
|
|
private IWmsDocAsnHeaderService iWmsDocAsnHeaderService;
|
|
@Autowired
|
|
@Autowired
|
|
- private IBaseSkuService baseSkuService;
|
|
|
|
- @Autowired
|
|
|
|
private UpdateOrderStockingProcess updateOrderStockingProcess;
|
|
private UpdateOrderStockingProcess updateOrderStockingProcess;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IPalletMatchLogService palletMatchLogService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询出库单头
|
|
* 查询出库单头
|
|
*
|
|
*
|
|
@@ -2727,4 +2735,71 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
|
|
|
|
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 库存分配
|
|
|
|
+ * @param orderList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean inventoryMatch(List<String> orderList) {
|
|
|
|
+ //根据erp单号获取出库单头列表
|
|
|
|
+ List<WmsDocOrderHeader> wmsDocOrderHeaderList = wmsDocOrderHeaderMapper.selectList(Wrappers.<WmsDocOrderHeader>lambdaQuery().in(WmsDocOrderHeader::getSoReference1, orderList).orderByDesc(WmsDocOrderHeader::getCreateTime));
|
|
|
|
+ if (CollectionUtil.isEmpty(wmsDocOrderHeaderList)) {
|
|
|
|
+ throw new BaseException("请扫描正确的出库单号");
|
|
|
|
+ }
|
|
|
|
+ List<WmsDocOrderHeader> wmsDocOrderHeaderFilterList = wmsDocOrderHeaderList.stream().filter(item -> item.getOrderStatus().equals(Constant.ORDER_STS.STS00.getValue())
|
|
|
|
+ || item.getOrderStatus().equals(Constant.ORDER_STS.STS10.getValue()) || item.getOrderStatus().equals(Constant.ORDER_STS.STS22.getValue())).collect(Collectors.toList());
|
|
|
|
+ if (CollectionUtil.isEmpty(wmsDocOrderHeaderFilterList)){
|
|
|
|
+ throw new BaseException("出库单状态不可分配!");
|
|
|
|
+ }
|
|
|
|
+ List<WmsDocOrderDetails> wmsDocOrderDetailsList = wmsDocOrderDetailsService.queryWmsDocOrderDetailsByOrderNoList(wmsDocOrderHeaderFilterList.stream().filter(item -> StringUtils.isNotBlank(item.getOrderNo())).map(WmsDocOrderHeader::getOrderNo).collect(Collectors.toList()));
|
|
|
|
+ if (CollectionUtil.isEmpty(wmsDocOrderDetailsList)){
|
|
|
|
+ throw new BaseException("出库单明细为空!");
|
|
|
|
+ }
|
|
|
|
+ Map<String, List<WmsDocOrderDetails>> wmsDocOrderDetailsGroupBySkuMap = wmsDocOrderDetailsList.stream().filter(item -> StringUtils.isNotBlank(item.getSku())).collect(Collectors.groupingBy(WmsDocOrderDetails::getSku));
|
|
|
|
+ if (CollectionUtil.isEmpty(wmsDocOrderDetailsGroupBySkuMap)){
|
|
|
|
+ throw new BaseException("出库单明细绑定sku为空!");
|
|
|
|
+ }
|
|
|
|
+ Map<String, List<InvLotAttPalletTotalDTO>> invLotAttPalletTotalMap = invLotAttService.buildInvLotAttPalletTotalMap(wmsDocOrderDetailsGroupBySkuMap.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toList()));
|
|
|
|
+ if (CollectionUtil.isEmpty(invLotAttPalletTotalMap)){
|
|
|
|
+ throw new BaseException("所选出库单绑定sku无库存!");
|
|
|
|
+ }
|
|
|
|
+ //所需出库托盘
|
|
|
|
+ List<InvLotAttPalletTotalDTO> result = new ArrayList<>();
|
|
|
|
+ for (Map.Entry<String, List<WmsDocOrderDetails>> wmsDocOrderDetailsGroupBySkuMapEntry : wmsDocOrderDetailsGroupBySkuMap.entrySet()) {
|
|
|
|
+ //扫描出库单各sku需求总数
|
|
|
|
+ BigDecimal total = wmsDocOrderDetailsGroupBySkuMapEntry.getValue().stream().filter(item -> ObjectUtil.isNotNull(item.getQtyOrdered())).map(item -> ObjectUtil.isNotNull(item.getQtyAllocated())
|
|
|
|
+ ? item.getQtyOrdered().subtract(item.getQtyAllocated()) : item.getQtyOrdered()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ if (CompareUtil.compare(total, BigDecimal.ZERO) <= 0) continue;
|
|
|
|
+ List<InvLotAttPalletTotalDTO> invLotAttPalletTotalDTOList = invLotAttPalletTotalMap.get(wmsDocOrderDetailsGroupBySkuMapEntry.getKey());
|
|
|
|
+ if (CollectionUtil.isEmpty(invLotAttPalletTotalDTOList)) continue;
|
|
|
|
+ for (InvLotAttPalletTotalDTO invLotAttPalletTotalDTO : invLotAttPalletTotalDTOList) {
|
|
|
|
+ BigDecimal palletTotal = invLotAttPalletTotalDTO.getTotalQty();
|
|
|
|
+ if (CompareUtil.compare(total, palletTotal) <= 0){
|
|
|
|
+ result.add(invLotAttPalletTotalDTO);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ total = total.subtract(palletTotal);
|
|
|
|
+ result.add(invLotAttPalletTotalDTO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return palletMatchLogService.insertBatch(buildPalletMatchLogList(result, orderList));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<PalletMatchLog> queryPalletMatchInfoList(String orderNos) {
|
|
|
|
+ return palletMatchLogService.queryPalletMatchLogByOrderNos(orderNos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<PalletMatchLog> buildPalletMatchLogList(List<InvLotAttPalletTotalDTO> invLotAttPalletTotalDTOList, List<String> orderList){
|
|
|
|
+ String orderNos = orderList.stream().collect(Collectors.joining(","));
|
|
|
|
+ Date createTime = DateUtils.getNowDate();
|
|
|
|
+ return invLotAttPalletTotalDTOList.stream().map(item -> {
|
|
|
|
+ PalletMatchLog palletMatchLog = ConvertUtils.sourceToTarget(item, PalletMatchLog.class);
|
|
|
|
+ palletMatchLog.setCreateTime(createTime);
|
|
|
|
+ palletMatchLog.setOrderNos(orderNos);
|
|
|
|
+ return palletMatchLog;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
}
|
|
}
|