|
|
@@ -1217,4 +1217,192 @@ public class VoyageStockBoardServiceImpl implements VoyageStockBoardService {
|
|
|
if (val == null) return "0.0";
|
|
|
return val.setScale(1, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
|
|
}
|
|
|
+
|
|
|
+ // ==================== 财务营收收款看板 ====================
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FinancialRevenueDashboardRespVO getFinancialRevenueDashboard(FinancialRevenueDashboardReqVO reqVO) {
|
|
|
+ FinancialRevenueDashboardRespVO respVO = new FinancialRevenueDashboardRespVO();
|
|
|
+
|
|
|
+ // 1. 查询已完成付款列表
|
|
|
+ List<FinancialRevenueDashboardRespVO.AgentPaymentItemVO> paidList =
|
|
|
+ voyageStockBoardMapper.selectPaidAgentList(reqVO);
|
|
|
+ // 2. 查询未付款列表
|
|
|
+ List<FinancialRevenueDashboardRespVO.AgentPaymentItemVO> unpaidList =
|
|
|
+ voyageStockBoardMapper.selectUnpaidAgentList(reqVO);
|
|
|
+ // 3. 查询部分付款列表
|
|
|
+ List<FinancialRevenueDashboardRespVO.AgentPaymentItemVO> partialPaidList =
|
|
|
+ voyageStockBoardMapper.selectPartialPaidAgentList(reqVO);
|
|
|
+
|
|
|
+ respVO.setPaidList(paidList != null ? paidList : Collections.emptyList());
|
|
|
+ respVO.setUnpaidList(unpaidList != null ? unpaidList : Collections.emptyList());
|
|
|
+ respVO.setPartialPaidList(partialPaidList != null ? partialPaidList : Collections.emptyList());
|
|
|
+
|
|
|
+ // 计算合计
|
|
|
+ respVO.setPaidTotal(sumAmount(respVO.getPaidList()));
|
|
|
+ respVO.setUnpaidTotal(sumAmount(respVO.getUnpaidList()));
|
|
|
+ respVO.setPartialPaidTotal(sumAmount(respVO.getPartialPaidList()));
|
|
|
+ respVO.setPartialDiffTotal(sumDiffAmount(respVO.getPartialPaidList()));
|
|
|
+
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 汇总金额
|
|
|
+ */
|
|
|
+ private BigDecimal sumAmount(List<FinancialRevenueDashboardRespVO.AgentPaymentItemVO> list) {
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ return list.stream()
|
|
|
+ .map(item -> item.getAmount() != null ? item.getAmount() : BigDecimal.ZERO)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 汇总差值金额
|
|
|
+ */
|
|
|
+ private BigDecimal sumDiffAmount(List<FinancialRevenueDashboardRespVO.AgentPaymentItemVO> list) {
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ return list.stream()
|
|
|
+ .map(item -> item.getDiffAmount() != null ? item.getDiffAmount() : BigDecimal.ZERO)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportFinancialRevenueDashboardExcel(FinancialRevenueDashboardReqVO reqVO, HttpServletResponse response) throws IOException {
|
|
|
+ FinancialRevenueDashboardRespVO data = getFinancialRevenueDashboard(reqVO);
|
|
|
+
|
|
|
+ response.addHeader("Content-Disposition",
|
|
|
+ "attachment;filename=" + URLEncoder.encode("收款情况.xlsx", StandardCharsets.UTF_8.name()));
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
|
|
|
+
|
|
|
+ // 构建自定义表头(匹配图片格式)
|
|
|
+ List<List<String>> head = buildFinancialRevenueHead();
|
|
|
+ // 构建导出数据
|
|
|
+ List<List<Object>> exportData = buildFinancialRevenueExportData(data);
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(exportData)) {
|
|
|
+ ExcelUtils.exportEmpty(response, "收款情况");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ EasyExcel.write(response.getOutputStream())
|
|
|
+ .head(head)
|
|
|
+ .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
|
|
+ .sheet("收款情况")
|
|
|
+ .doWrite(exportData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建财务营收收款看板导出表头
|
|
|
+ */
|
|
|
+ private List<List<String>> buildFinancialRevenueHead() {
|
|
|
+ List<List<String>> head = new ArrayList<>();
|
|
|
+ head.add(Collections.singletonList("代理商名称"));
|
|
|
+ head.add(Collections.singletonList("分类/说明"));
|
|
|
+ head.add(Collections.singletonList("金额"));
|
|
|
+ head.add(Collections.singletonList("差值"));
|
|
|
+ return head;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建财务营收收款看板导出数据
|
|
|
+ */
|
|
|
+ private List<List<Object>> buildFinancialRevenueExportData(FinancialRevenueDashboardRespVO data) {
|
|
|
+ List<List<Object>> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 标题行
|
|
|
+ List<Object> titleRow = new ArrayList<>();
|
|
|
+ titleRow.add("");
|
|
|
+ titleRow.add("收款情况");
|
|
|
+ titleRow.add("");
|
|
|
+ titleRow.add("");
|
|
|
+ result.add(titleRow);
|
|
|
+
|
|
|
+ // 1. 已完成付款
|
|
|
+ if (CollUtil.isNotEmpty(data.getPaidList())) {
|
|
|
+ List<Object> categoryRow = new ArrayList<>();
|
|
|
+ categoryRow.add("");
|
|
|
+ categoryRow.add("1. 已完成付款");
|
|
|
+ categoryRow.add("实际付款金额");
|
|
|
+ categoryRow.add("");
|
|
|
+ result.add(categoryRow);
|
|
|
+
|
|
|
+ for (FinancialRevenueDashboardRespVO.AgentPaymentItemVO item : data.getPaidList()) {
|
|
|
+ List<Object> row = new ArrayList<>();
|
|
|
+ row.add(item.getAgentName() != null ? item.getAgentName() : "");
|
|
|
+ row.add("");
|
|
|
+ row.add(item.getAmount() != null ? item.getAmount() : BigDecimal.ZERO);
|
|
|
+ row.add("");
|
|
|
+ result.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 小计
|
|
|
+ List<Object> subtotalRow = new ArrayList<>();
|
|
|
+ subtotalRow.add("");
|
|
|
+ subtotalRow.add("小计");
|
|
|
+ subtotalRow.add(data.getPaidTotal() != null ? data.getPaidTotal() : BigDecimal.ZERO);
|
|
|
+ subtotalRow.add("");
|
|
|
+ result.add(subtotalRow);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 未付款
|
|
|
+ if (CollUtil.isNotEmpty(data.getUnpaidList())) {
|
|
|
+ List<Object> categoryRow = new ArrayList<>();
|
|
|
+ categoryRow.add("");
|
|
|
+ categoryRow.add("2. 未付款");
|
|
|
+ categoryRow.add("未付款金额");
|
|
|
+ categoryRow.add("");
|
|
|
+ result.add(categoryRow);
|
|
|
+
|
|
|
+ for (FinancialRevenueDashboardRespVO.AgentPaymentItemVO item : data.getUnpaidList()) {
|
|
|
+ List<Object> row = new ArrayList<>();
|
|
|
+ row.add(item.getAgentName() != null ? item.getAgentName() : "");
|
|
|
+ row.add("");
|
|
|
+ row.add(item.getAmount() != null ? item.getAmount() : BigDecimal.ZERO);
|
|
|
+ row.add("");
|
|
|
+ result.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 小计
|
|
|
+ List<Object> subtotalRow = new ArrayList<>();
|
|
|
+ subtotalRow.add("");
|
|
|
+ subtotalRow.add("小计");
|
|
|
+ subtotalRow.add(data.getUnpaidTotal() != null ? data.getUnpaidTotal() : BigDecimal.ZERO);
|
|
|
+ subtotalRow.add("");
|
|
|
+ result.add(subtotalRow);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 部分付款
|
|
|
+ if (CollUtil.isNotEmpty(data.getPartialPaidList())) {
|
|
|
+ List<Object> categoryRow = new ArrayList<>();
|
|
|
+ categoryRow.add("");
|
|
|
+ categoryRow.add("3. 部分付款");
|
|
|
+ categoryRow.add("实际付款金额");
|
|
|
+ categoryRow.add("差值");
|
|
|
+ result.add(categoryRow);
|
|
|
+
|
|
|
+ for (FinancialRevenueDashboardRespVO.AgentPaymentItemVO item : data.getPartialPaidList()) {
|
|
|
+ List<Object> row = new ArrayList<>();
|
|
|
+ row.add(item.getAgentName() != null ? item.getAgentName() : "");
|
|
|
+ row.add("");
|
|
|
+ row.add(item.getAmount() != null ? item.getAmount() : BigDecimal.ZERO);
|
|
|
+ row.add(item.getDiffAmount() != null ? item.getDiffAmount() : BigDecimal.ZERO);
|
|
|
+ result.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 小计
|
|
|
+ List<Object> subtotalRow = new ArrayList<>();
|
|
|
+ subtotalRow.add("");
|
|
|
+ subtotalRow.add("小计");
|
|
|
+ subtotalRow.add(data.getPartialPaidTotal() != null ? data.getPartialPaidTotal() : BigDecimal.ZERO);
|
|
|
+ subtotalRow.add(data.getPartialDiffTotal() != null ? data.getPartialDiffTotal() : BigDecimal.ZERO);
|
|
|
+ result.add(subtotalRow);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|