| | |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.materialstock.vo.MesWmStockSummaryRespVO; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.dto.SrmSupplierRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.api.category.MdmItemCategoryApi; |
| | | import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | |
| | |
| | | public class MesWmMaterialStockController { |
| | | |
| | | @Resource |
| | | private cn.iocoder.yudao.module.mes.dal.mysql.wm.transaction.MesWmTransactionMapper transactionMapper; |
| | | |
| | | @Resource |
| | | private MesWmMaterialStockService materialStockService; |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | @Resource |
| | | private MdmItemCategoryApi mdmItemCategoryApi; |
| | | @Resource |
| | | private MdmUnitMeasureApi mdmUnitMeasureApi; |
| | | @Resource |
| | |
| | | private SrmSupplierApi srmSupplierApi; |
| | | @Resource |
| | | private MesWmMaterialStockBagMapper materialStockBagMapper; |
| | | @Resource |
| | | private cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesLineService productSalesLineService; |
| | | @Resource private cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesDetailMapper salesDetailMapper; |
| | | @Resource private cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesMapper salesMapper; |
| | | @Resource private cn.iocoder.yudao.module.mes.dal.mysql.wm.productsales.MesWmProductSalesShipmentMapper shipmentMapper; |
| | | |
| | | @GetMapping("/picking-list") |
| | | @Operation(summary = "按销售出库单行查询合格库存") |
| | | @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:stock') and @ss.hasPermission('mes:wm-material-stock:query')") |
| | | public CommonResult<List<MesWmMaterialStockRespVO>> getPickingStocks(@RequestParam("lineId") Long lineId) { |
| | | var line = productSalesLineService.getProductSalesLine(lineId); |
| | | if (line == null) throw new IllegalArgumentException("出库单行不存在"); |
| | | return success(buildRespVOList(materialStockService.getQualifiedMaterialStockListByItemAndBatch(line.getItemId(), line.getBatchId()))); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得库存记录") |
| | |
| | | PageResult<MesWmMaterialStockBagRespVO> result = new PageResult<>(); |
| | | PageResult<cn.iocoder.yudao.module.mes.dal.dataobject.wm.materialstockbag.MesWmMaterialStockBagDO> page = |
| | | materialStockBagMapper.selectPage(pageReqVO); |
| | | return success(new PageResult<>(BeanUtils.toBean(page.getList(), MesWmMaterialStockBagRespVO.class), page.getTotal())); |
| | | var transactionIds = convertSet(page.getList(), cn.iocoder.yudao.module.mes.dal.dataobject.wm.materialstockbag.MesWmMaterialStockBagDO::getLastTransactionId); |
| | | Map<Long, cn.iocoder.yudao.module.mes.dal.dataobject.wm.transaction.MesWmTransactionDO> transactions = transactionIds.isEmpty() |
| | | ? Collections.emptyMap() : transactionMapper.selectBatchIds(transactionIds).stream() |
| | | .collect(Collectors.toMap(cn.iocoder.yudao.module.mes.dal.dataobject.wm.transaction.MesWmTransactionDO::getId, tx -> tx)); |
| | | var rows = BeanUtils.toBean(page.getList(), MesWmMaterialStockBagRespVO.class); |
| | | var bagIds = convertSet(page.getList(), cn.iocoder.yudao.module.mes.dal.dataobject.wm.materialstockbag.MesWmMaterialStockBagDO::getBagCodeId); |
| | | var pickingDetails = salesDetailMapper.selectByBagIds(bagIds); |
| | | var saleIds = convertSet(pickingDetails, cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDetailDO::getSalesId); |
| | | var shipmentIds = convertSet(pickingDetails, cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDetailDO::getShipmentId); |
| | | var saleMap = saleIds.isEmpty() ? Collections.<Long, cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDO>emptyMap() |
| | | : salesMapper.selectBatchIds(saleIds).stream().collect(Collectors.toMap(cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDO::getId, s -> s)); |
| | | var shipmentMap = shipmentIds.isEmpty() ? Collections.<Long, cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesShipmentDO>emptyMap() |
| | | : shipmentMapper.selectBatchIds(shipmentIds).stream().collect(Collectors.toMap(cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesShipmentDO::getId, s -> s)); |
| | | Map<Long, String> pickingByBag = new java.util.HashMap<>(); |
| | | for (var detail : pickingDetails) { |
| | | var sale = saleMap.get(detail.getSalesId()); |
| | | var shipment = detail.getShipmentId() == null ? null : shipmentMap.get(detail.getShipmentId()); |
| | | if (sale == null) continue; |
| | | if (detail.getShipmentId() == null && Integer.valueOf(2).equals(sale.getStatus())) pickingByBag.putIfAbsent(detail.getBagCodeId(), "PICKED"); |
| | | else if ((detail.getShipmentId() == null && (Integer.valueOf(10).equals(sale.getStatus()) || Integer.valueOf(3).equals(sale.getStatus()))) |
| | | || (shipment != null && (Integer.valueOf(10).equals(shipment.getStatus()) || Integer.valueOf(20).equals(shipment.getStatus())))) pickingByBag.put(detail.getBagCodeId(), "RESERVED"); |
| | | } |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | var bag = page.getList().get(i); |
| | | var tx = bag.getLastTransactionId() == null ? null : transactions.get(bag.getLastTransactionId()); |
| | | if (Integer.valueOf(2).equals(bag.getStatus()) && tx != null && Integer.valueOf(2).equals(tx.getType())) { |
| | | rows.get(i).setOutboundBizType(tx.getBizType()); |
| | | } |
| | | if (Integer.valueOf(1).equals(bag.getStatus())) rows.get(i).setPickingStatus(pickingByBag.get(bag.getBagCodeId())); |
| | | } |
| | | return success(new PageResult<>(rows, page.getTotal())); |
| | | } |
| | | |
| | | @PutMapping("/update-frozen") |
| | |
| | | // 1. 获得关联数据 |
| | | Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap( |
| | | convertSet(list, MesWmMaterialStockDO::getItemId)); |
| | | Map<Long, MdmItemCategoryRespDTO> itemCategoryMap = mdmItemCategoryApi.getItemCategoryList( |
| | | convertSet(itemMap.values(), MdmItemRespDTO::getCategoryId)).getCheckedData().stream() |
| | | .collect(Collectors.toMap(MdmItemCategoryRespDTO::getId, c -> c)); |
| | | Map<Long, MdmUnitMeasureRespDTO> unitMeasureMap = mdmUnitMeasureApi.getUnitMeasureList( |
| | | convertSet(itemMap.values(), MdmItemRespDTO::getUnitMeasureId)).getCheckedData() |
| | | .stream().collect(Collectors.toMap(MdmUnitMeasureRespDTO::getId, e -> e)); |
| | |
| | | convertSet(list, MesWmMaterialStockDO::getLocationId)); |
| | | Map<Long, MesWmWarehouseAreaDO> areaMap = areaService.getWarehouseAreaMap( |
| | | convertSet(list, MesWmMaterialStockDO::getAreaId)); |
| | | Map<Long, Long> bagCountMap = materialStockBagMapper.selectListByMaterialStockIds( |
| | | convertSet(list, MesWmMaterialStockDO::getId)).stream() |
| | | List<MesWmMaterialStockBagDO> bagHistory = materialStockBagMapper.selectHistoryByMaterialStockIds( |
| | | convertSet(list, MesWmMaterialStockDO::getId)); |
| | | Map<Long, Long> bagCountMap = bagHistory.stream().filter(bag -> Integer.valueOf(1).equals(bag.getStatus())) |
| | | .collect(Collectors.groupingBy(MesWmMaterialStockBagDO::getMaterialStockId, Collectors.counting())); |
| | | var stockIdsWithBagHistory = convertSet(bagHistory, MesWmMaterialStockBagDO::getMaterialStockId); |
| | | Map<Long, SrmSupplierRespDTO> vendorMap = srmSupplierApi.getSupplierList( |
| | | convertSet(list, MesWmMaterialStockDO::getVendorId)).getCheckedData().stream() |
| | | .collect(Collectors.toMap(SrmSupplierRespDTO::getId, s -> s)); |
| | |
| | | return BeanUtils.toBean(list, MesWmMaterialStockRespVO.class, vo -> { |
| | | MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { |
| | | vo.setItemCode(item.getCode()).setItemName(item.getName()).setSpecification(item.getSpecification()); |
| | | MapUtils.findAndThen(itemCategoryMap, item.getCategoryId(), |
| | | category -> vo.setItemTypeName(category.getName())); |
| | | MapUtils.findAndThen(unitMeasureMap, item.getUnitMeasureId(), |
| | | unitMeasure -> vo.setUnitMeasureName(unitMeasure.getName())); |
| | | }); |
| | |
| | | MapUtils.findAndThen(vendorMap, vo.getVendorId(), |
| | | vendor -> vo.setVendorName(vendor.getName())); |
| | | vo.setBagCount(bagCountMap.getOrDefault(vo.getId(), 0L)); |
| | | vo.setBagDetailSupported(bagCountMap.containsKey(vo.getId())); |
| | | vo.setBagDetailSupported(stockIdsWithBagHistory.contains(vo.getId())); |
| | | // 计算可用量 = 在库数量 - 冻结数量 - 占用量 |
| | | BigDecimal quantity = vo.getQuantity() != null ? vo.getQuantity() : BigDecimal.ZERO; |
| | | BigDecimal frozenQty = vo.getFrozenQuantity() != null ? vo.getFrozenQuantity() : BigDecimal.ZERO; |