gongchunyi
22 小时以前 71e05a80df83069c9611ba5ef0fdc2a37eb6a3ae
src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -16,6 +16,7 @@
import com.ruoyi.basic.pojo.CustomerUser;
import com.ruoyi.basic.service.*;
import com.ruoyi.basic.vo.CustomerVo;
import com.ruoyi.common.utils.AmountUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -34,6 +35,7 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@@ -383,12 +385,64 @@
    @Override
    public IPage<CustomerTransactionsVo> customewTransactions(Page page, String customerName) {
        return customerMapper.customewTransactions(page, customerName);
        IPage<CustomerTransactionsVo> p = customerMapper.customewTransactions(page, customerName);
        List<CustomerTransactionsVo> records = p.getRecords();
        if (!CollectionUtils.isEmpty(records)) {
            List<Long> customerIds = records.stream().map(CustomerTransactionsVo::getCustomerId).collect(Collectors.toList());
            List<Map<String, Object>> shippedAmountList = customerMapper.getShippedAmountByCustomerIds(customerIds);
            Map<Long, BigDecimal> shippedAmountMap = new HashMap<>();
            for (Map<String, Object> map : shippedAmountList) {
                if (map.get("outboundAmount") != null) {
                    shippedAmountMap.put(((Number) map.get("customerId")).longValue(), new BigDecimal(String.valueOf(map.get("outboundAmount"))));
                }
            }
            for (CustomerTransactionsVo vo : records) {
                BigDecimal outboundAmount = shippedAmountMap.getOrDefault(vo.getCustomerId(), BigDecimal.ZERO);
                BigDecimal contractAmounts = AmountUtils.scaleMoney(vo.getContractAmounts());
                // 已出库金额按分(2位小数)处理,避免按含税单价累计出库金额产生误差导致全部发货后仍有未出库零头
                BigDecimal shippedAmount = AmountUtils.scaleMoney(outboundAmount);
                BigDecimal unshippedAmount = contractAmounts.subtract(shippedAmount);
                if (unshippedAmount.compareTo(BigDecimal.ZERO) < 0) {
                    unshippedAmount = BigDecimal.ZERO;
                }
                vo.setContractAmounts(contractAmounts);
                vo.setShippedAmount(shippedAmount);
                vo.setUnshippedAmount(unshippedAmount);
                AmountUtils.normalizeCustomerTransaction(vo);
            }
        }
        return p;
    }
    @Override
    public IPage<CustomerTransactionsDetailsVo> customewTransactionsDetails(Page page, Long customerId) {
        return customerMapper.customewTransactionsDetails(page, customerId);
        IPage<CustomerTransactionsDetailsVo> p = customerMapper.customewTransactionsDetails(page, customerId);
        List<CustomerTransactionsDetailsVo> records = p.getRecords();
        if (!CollectionUtils.isEmpty(records)) {
            List<Long> salesLedgerIds = records.stream().map(CustomerTransactionsDetailsVo::getSalesLedgerId).collect(Collectors.toList());
            List<Map<String, Object>> shippedAmountList = customerMapper.getShippedAmountBySalesLedgerIds(salesLedgerIds);
            Map<Long, BigDecimal> shippedAmountMap = new HashMap<>();
            for (Map<String, Object> map : shippedAmountList) {
                if (map.get("outboundAmount") != null) {
                    shippedAmountMap.put(((Number) map.get("salesLedgerId")).longValue(), new BigDecimal(String.valueOf(map.get("outboundAmount"))));
                }
            }
            for (CustomerTransactionsDetailsVo vo : records) {
                BigDecimal outboundAmount = shippedAmountMap.getOrDefault(vo.getSalesLedgerId(), BigDecimal.ZERO);
                BigDecimal contractAmount = AmountUtils.scaleMoney(vo.getContractAmount());
                // 已出库金额按分(2位小数)处理,避免按含税单价累计出库金额产生误差导致全部发货后仍有未出库零头
                BigDecimal shippedAmount = AmountUtils.scaleMoney(outboundAmount);
                BigDecimal unshippedAmount = contractAmount.subtract(shippedAmount);
                if (unshippedAmount.compareTo(BigDecimal.ZERO) < 0) {
                    unshippedAmount = BigDecimal.ZERO;
                }
                vo.setContractAmount(contractAmount);
                vo.setShippedAmount(shippedAmount);
                vo.setUnshippedAmount(unshippedAmount);
                AmountUtils.normalizeCustomerTransactionDetail(vo);
            }
        }
        return p;
    }
    /**