src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -9,7 +9,12 @@
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
import com.ruoyi.other.service.impl.TempFileServiceImpl;
import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper;
import com.ruoyi.procurementrecord.pojo.ReturnManagement;
import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.sales.dto.SalesLedgerProductDto;
import com.ruoyi.sales.dto.ShippingInfoDto;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.mapper.ShippingInfoDetailMapper;
@@ -26,10 +31,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -59,6 +61,58 @@
    @Autowired
    private ShippingInfoDetailService shippingInfoDetailService;
    @Autowired
    private ReturnManagementMapper returnManagementMapper;
    @Autowired
    private ReturnSaleProductMapper returnSaleProductMapper;
    @Override
    public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) {
        return shippingInfoMapper.getReturnManagementDtoById(shippingId );
    }
    /**
     * 获取销售产品单的已发货数量
     * @param id
     * @return
     */
    @Override
    public Map<String, BigDecimal> getNumberOfSalesLedgerProduct(Long salesLedgerProductId) {
        Map<String, BigDecimal> map = new HashMap<>();
        map.put("shippingNum",BigDecimal.ZERO); // 发货数量
        map.put("returnNum",BigDecimal.ZERO); // 退货数量
        List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                .eq(ShippingInfo::getSalesLedgerProductId, salesLedgerProductId)
                // 只筛选“发货中”和“已发货”两种状态
                .in(ShippingInfo::getStatus, "发货中", "已发货"));
        if(CollectionUtils.isEmpty(shippingInfos)){
            return map;
        }
        List<ShippingInfoDetail> shippingInfoDetails = shippingInfoDetailMapper.selectList(new LambdaQueryWrapper<ShippingInfoDetail>()
                .in(ShippingInfoDetail::getShippingInfoId, shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList())));
        if(CollectionUtils.isEmpty(shippingInfoDetails)){
            return map;
        }
        // 获取发货数量
        map.put("shippingNum",shippingInfoDetails.stream().map(ShippingInfoDetail::getShippingNum).reduce(BigDecimal.ZERO, BigDecimal::add));
        // 获取退货数量
        List<ReturnSaleProduct> returnSaleProducts = returnSaleProductMapper.selectList(new LambdaQueryWrapper<ReturnSaleProduct>()
                .eq(ReturnSaleProduct::getReturnSaleLedgerProductId, salesLedgerProductId)
                .eq(ReturnSaleProduct::getStatus,1));
        if(CollectionUtils.isEmpty(returnSaleProducts)){
            return map;
        }
        map.put("returnNum",returnSaleProducts.stream().map(ReturnSaleProduct::getNum).reduce(BigDecimal.ZERO, BigDecimal::add));
        return map;
    }
    @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);