| | |
| | | import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ReturnManagement; |
| | | import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct; |
| | | import com.ruoyi.procurementrecord.service.impl.ReturnManagementServiceImpl; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.sales.dto.SalesLedgerProductDto; |
| | | import com.ruoyi.sales.dto.ShippingInfoDto; |
| | |
| | | @Autowired |
| | | private ReturnSaleProductMapper returnSaleProductMapper; |
| | | |
| | | @Autowired |
| | | private ReturnManagementServiceImpl returnManagementService; |
| | | |
| | | @Override |
| | | public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) { |
| | | return shippingInfoMapper.getReturnManagementDtoById(shippingId ); |
| | |
| | | |
| | | /** |
| | | * 获取销售产品单的已发货数量 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, BigDecimal> getNumberOfSalesLedgerProduct(Long salesLedgerProductId) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ShippingInfoDto getDateil(Long id) { |
| | | ShippingInfoDto shippingInfoDto = shippingInfoMapper.getDateil(id); |
| | | if(shippingInfoDto != null){ |
| | | assembleDetails(shippingInfoDto); |
| | | } |
| | | return shippingInfoDto; |
| | | } |
| | | |
| | | @Override |
| | | public List<ShippingInfo> getShippingInfoByCustomerName(String customerName) { |
| | | return shippingInfoMapper.getShippingInfoByCustomerName(customerName); |
| | | } |
| | |
| | | @Override |
| | | public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) { |
| | | IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req); |
| | | listPage.getRecords().forEach(item ->{ |
| | | item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.SHIP.getValue())); |
| | | List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>() |
| | | .eq(ShippingInfoDetail::getShippingInfoId, item.getId())); |
| | | // 核心优化:层层防护空指针 + 处理空集合场景 |
| | | item.setShippingSuccessTotal(Optional.ofNullable(shippingInfoDetails) |
| | | .orElse(Collections.emptyList()) |
| | | .stream() |
| | | .filter(Objects::nonNull) |
| | | .map(ShippingInfoDetail::getShippingNum) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add)); // 用Lambda替代方法引用 |
| | | item.setWaitShippingTotal(item.getShippingTotal().subtract(item.getShippingSuccessTotal())); |
| | | |
| | | }); |
| | | listPage.getRecords().forEach(this::assembleDetails); |
| | | return listPage; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 封装详情 |
| | | * @param item |
| | | */ |
| | | public void assembleDetails(ShippingInfoDto item) { |
| | | item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.SHIP.getValue())); |
| | | List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>() |
| | | .eq(ShippingInfoDetail::getShippingInfoId, item.getId())); |
| | | // 核心优化:层层防护空指针 + 处理空集合场景 |
| | | item.setShippingSuccessTotal(Optional.ofNullable(shippingInfoDetails) |
| | | .orElse(Collections.emptyList()) |
| | | .stream() |
| | | .filter(Objects::nonNull) |
| | | .map(ShippingInfoDetail::getShippingNum) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add)); // 用Lambda替代方法引用 |
| | | item.setWaitShippingTotal(item.getShippingTotal().subtract(item.getShippingSuccessTotal())); |
| | | // 查询退货数量 |
| | | if(CollectionUtils.isNotEmpty(shippingInfoDetails)){ |
| | | item.setReturnTotal(returnManagementService.getReturnSaleProductCountByShippingId(shippingInfoDetails |
| | | .stream() |
| | | .map(ShippingInfoDetail::getId) |
| | | .collect(Collectors.toList()))); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | //扣减库存 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId()); |
| | | stockUtils.substractStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId()); |
| | | stockUtils.substractStock(salesLedgerProduct.getProductModelId(), req.getShippingTotal(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId()); |
| | | byId.setExpressNumber(req.getExpressNumber()); |
| | | byId.setExpressCompany(req.getExpressCompany()); |
| | | byId.setStatus(req.getStatus()); |