From 30a5ae7f0d5f14d2df8fbfabf8c60cc666018a90 Mon Sep 17 00:00:00 2001 From: lihao <3139678155@qq.com> Date: Tue, 31 Dec 2024 10:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=A6=E8=B4=A6=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gl/component.xml | 5 + .../AccountBalanceTotalQueryAction.java | 94 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 gl/component.xml create mode 100644 gl/src/client/nccloud/web/gl/accountrep/action/AccountBalanceTotalQueryAction.java diff --git a/gl/component.xml b/gl/component.xml new file mode 100644 index 0000000..fb3b954 --- /dev/null +++ b/gl/component.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/gl/src/client/nccloud/web/gl/accountrep/action/AccountBalanceTotalQueryAction.java b/gl/src/client/nccloud/web/gl/accountrep/action/AccountBalanceTotalQueryAction.java new file mode 100644 index 0000000..4afac1d --- /dev/null +++ b/gl/src/client/nccloud/web/gl/accountrep/action/AccountBalanceTotalQueryAction.java @@ -0,0 +1,94 @@ +package nccloud.web.gl.accountrep.action; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import nc.vo.pub.BusinessException; +import nccloud.framework.service.ServiceLocator; +import nccloud.pubitf.gl.account.IAccountReportWebService; + +public class AccountBalanceTotalQueryAction { + public AccountBalanceTotalQueryAction() { + } + + public Object doQuery(Map paraMap) throws BusinessException { + // 科目余额表数据 + Map result = ((IAccountReportWebService) ServiceLocator.find(IAccountReportWebService.class)).queryAccBalance(paraMap); + // 科目辅助余额表数据 + Map result1 = ((IAccountReportWebService) ServiceLocator.find(IAccountReportWebService.class)).querySubjAssBalanceBooks(paraMap); + List> data = (List>) result.get("data"); + List> data1 = (List>) result1.get("data"); + + // 过滤掉 data1 中 assname 为空的数据 + data1 = data1.stream() + .filter(item -> item.get("assname") != null && !item.get("assname").toString().trim().isEmpty()) + .collect(Collectors.toList()); + + // 创建一个映射,根据 acccode 快速查找 data 中的元素 + Map> dataMap = data.stream() + .collect(Collectors.toMap(item -> (String) item.get("acccode"), item -> item)); + + // 构造新的 Map,存储每个父级科目的期末余额之和 + Map sumMap = new HashMap<>(); + + // 构造新的列表 + List> mergedList = new ArrayList<>(); + + for (Map item : data1) { + Map linkMap = (Map) item.get("link"); + String acccode = (String) linkMap.get("acccode"); + String parentAcccode = acccode.substring(0, 4); // 假设父级科目编码是前4位 + + Map parentItem = dataMap.get(parentAcccode); + if (parentItem != null) { + String endlocamountStr = (String) item.get("endlocamount"); + double endlocamount = parseEndlocamount(endlocamountStr); + + // 更新 sumMap + sumMap.put(parentAcccode, sumMap.getOrDefault(parentAcccode, 0.0) + endlocamount); + + // 构造新的 Map + Map newItem = new HashMap<>(); + newItem.put("pacccode", parentAcccode); + newItem.put("paccname", parentItem.get("accname")); + newItem.put("pendlocamount", parentItem.get("endlocamount")); + newItem.put("acccode", acccode); + newItem.put("accname", parentItem.get("accname")); // 假设 data1 中没有 accname,使用父级的 accname + newItem.put("assname", item.get("assname")); + newItem.put("endlocamount", endlocamount); + mergedList.add(newItem); + } + } + + // 计算每个父级科目的 endlocamount 和所有关联 data1 中 endlocamount 的差值 + for (Map item : mergedList) { + String parentAcccode = (String) item.get("pacccode"); + double endlocamount = (double) item.get("pendlocamount"); + double sumEndlocamount = sumMap.get(parentAcccode); + double difference = sumEndlocamount - endlocamount; + item.put("difference", difference); + } + + // 输出合并后的列表 + for (Map item : mergedList) { + System.out.println(item); + } + return mergedList; + } + + // 解析 endlocamount 字符串为 double 类型 + private static double parseEndlocamount(String endlocamountStr) { + if (endlocamountStr == null || endlocamountStr.isEmpty()) { + return 0.0; + } + // 去除逗号 + endlocamountStr = endlocamountStr.replace(",", ""); + try { + return Double.parseDouble(endlocamountStr); + } catch (NumberFormatException e) { + return 0.0; + } + } +}