Explorar o código

查询指定日期余额资产报表

24282 %!s(int64=2) %!d(string=hai) anos
pai
achega
93495af936

+ 88 - 56
bladex-saas-project/saas-business-tradeerp/src/main/java/com/fjhx/fundAccount/service/impl/FundAccountDetailServiceImpl.java

@@ -1167,6 +1167,8 @@ public class FundAccountDetailServiceImpl extends ServiceImpl<FundAccountDetailM
         String yearAndYear = dto.getYearAndYear();
         Assert.notEmpty(yearAndYear, "日期不能为空");
 
+        // 当前日期
+        Date nowDate = new Date();
         // 统计开始时间
         Date beginDate;
         // 统计结束时间
@@ -1178,6 +1180,10 @@ public class FundAccountDetailServiceImpl extends ServiceImpl<FundAccountDetailM
             throw new ServiceException("日期格式不正确");
         }
 
+        if (beginDate.after(nowDate)) {
+            throw new ServiceException("统计月份应在本月或本月之前");
+        }
+
         // 查询出租户交易 账号id、账号名、账号、人民币余额、美元余额、欧元余额
         List<FundAccount> accountList = iFundAccountService.list(Wrappers.<FundAccount>lambdaQuery()
                 .eq(FundAccount::getTenantId, AuthUtil.getTenantId())
@@ -1208,100 +1214,126 @@ public class FundAccountDetailServiceImpl extends ServiceImpl<FundAccountDetailM
             // Map<日期,Map<货币类型,Map<收支类型(1:支出 2:收入),改变数量>>>
             Map<String, Map<Integer, Map<Integer, BigDecimal>>> stringMapMap = incomingAndOutgoingsByMonth.get(item.getId());
 
-            String yearMonthDay = DateUtil.format(endDate, "yyyy-MM-dd");
-            String startYearMonthDayStr = DateUtil.format(DateUtil.offsetDay(beginDate, -1), "yyyy-MM-dd");
+            Date yearMonthDay = endDate.before(nowDate) ? endDate : nowDate;
             List<GetNewBalanceV2RewriteVo.Detail> detailList = new ArrayList<>();
-            int flag = -1;
 
             if (stringMapMap == null) {
-                while (!yearMonthDay.equals(startYearMonthDayStr)) {
+                while (yearMonthDay.equals(beginDate) || yearMonthDay.after(beginDate)) {
                     GetNewBalanceV2RewriteVo.Detail detail = new GetNewBalanceV2RewriteVo.Detail();
-                    detail.setYearMonthDay(yearMonthDay);
-                    detail.setRmbAmount(cn.hutool.core.util.ObjectUtil.defaultIfNull(item.getRmbAmount(), BigDecimal.ZERO));
-                    detail.setRmbIncome(BigDecimal.ZERO);
-                    detail.setRmbExpenditure(BigDecimal.ZERO);
-
-                    detail.setDollarAmount(cn.hutool.core.util.ObjectUtil.defaultIfNull(item.getDollarAmount(), BigDecimal.ZERO));
-                    detail.setDollarIncome(BigDecimal.ZERO);
-                    detail.setDollarExpenditure(BigDecimal.ZERO);
-
-                    detail.setEuroAmount(cn.hutool.core.util.ObjectUtil.defaultIfNull(item.getEuroAmount(), BigDecimal.ZERO));
-                    detail.setEuroIncome(BigDecimal.ZERO);
-                    detail.setEuroExpenditure(BigDecimal.ZERO);
+                    detail.setYearMonthDay(DateUtil.formatDate(yearMonthDay));
+                    detail.setRmbAmount(item.getRmbAmount());
+                    // detail.setRmbIncome(BigDecimal.ZERO);
+                    // detail.setRmbExpenditure(BigDecimal.ZERO);
+
+                    detail.setDollarAmount(item.getDollarAmount());
+                    // detail.setDollarIncome(BigDecimal.ZERO);
+                    // detail.setDollarExpenditure(BigDecimal.ZERO);
+
+                    detail.setEuroAmount(item.getEuroAmount());
+                    // detail.setEuroIncome(BigDecimal.ZERO);
+                    // detail.setEuroExpenditure(BigDecimal.ZERO);
                     detailList.add(detail);
 
-                    yearMonthDay = DateUtil.format(DateUtil.offsetDay(endDate, flag), "yyyy-MM-dd");
-                    flag--;
+                    yearMonthDay = DateUtil.offsetDay(yearMonthDay, -1);
                 }
             } else {
-                while (!yearMonthDay.equals(startYearMonthDayStr)) {
+                while (yearMonthDay.equals(beginDate) || yearMonthDay.after(beginDate)) {
                     // Map<货币类型,Map<收支类型(1:支出   2:收入),改变数量>>
-                    Map<Integer, Map<Integer, BigDecimal>> integerMapMap = stringMapMap.get(yearMonthDay);
+                    Map<Integer, Map<Integer, BigDecimal>> integerMapMap = stringMapMap.get(DateUtil.formatDate(yearMonthDay));
 
                     GetNewBalanceV2RewriteVo.Detail detail = new GetNewBalanceV2RewriteVo.Detail();
-                    detail.setYearMonthDay(yearMonthDay);
-
-                    detail.setRmbAmount(cn.hutool.core.util.ObjectUtil.defaultIfNull(item.getRmbAmount(), BigDecimal.ZERO));
-                    detail.setDollarAmount(cn.hutool.core.util.ObjectUtil.defaultIfNull(item.getDollarAmount(), BigDecimal.ZERO));
-                    detail.setEuroAmount(cn.hutool.core.util.ObjectUtil.defaultIfNull(item.getEuroAmount(), BigDecimal.ZERO));
-                    if (integerMapMap == null) {
-                        detail.setRmbIncome(BigDecimal.ZERO);
-                        detail.setRmbExpenditure(BigDecimal.ZERO);
-                        detail.setDollarIncome(BigDecimal.ZERO);
-                        detail.setDollarExpenditure(BigDecimal.ZERO);
-                        detail.setEuroIncome(BigDecimal.ZERO);
-                        detail.setEuroExpenditure(BigDecimal.ZERO);
-                    } else {
+                    detail.setYearMonthDay(DateUtil.formatDate(yearMonthDay));
+
+                    detail.setRmbAmount(item.getRmbAmount());
+                    detail.setDollarAmount(item.getDollarAmount());
+                    detail.setEuroAmount(item.getEuroAmount());
+                    // if (integerMapMap == null) {
+                    //     detail.setRmbIncome(BigDecimal.ZERO);
+                    //     detail.setRmbExpenditure(BigDecimal.ZERO);
+                    //     detail.setDollarIncome(BigDecimal.ZERO);
+                    //     detail.setDollarExpenditure(BigDecimal.ZERO);
+                    //     detail.setEuroIncome(BigDecimal.ZERO);
+                    //     detail.setEuroExpenditure(BigDecimal.ZERO);
+                    // }
+                    if (integerMapMap != null) {
                         // Map<收支类型(1:收入   2:支出),改变数量>
                         Map<Integer, BigDecimal> rmbMap = integerMapMap.get(CurrencyTypeEnum.RMB.getKey());
-                        if (rmbMap == null) {
-                            detail.setRmbIncome(BigDecimal.ZERO);
-                            detail.setRmbExpenditure(BigDecimal.ZERO);
-                        } else {
-                            BigDecimal expenditure = cn.hutool.core.util.ObjectUtil.defaultIfNull(rmbMap.get(2), BigDecimal.ZERO);
-                            BigDecimal income = cn.hutool.core.util.ObjectUtil.defaultIfNull(rmbMap.get(1), BigDecimal.ZERO);
+                        // if (rmbMap == null) {
+                        //     detail.setRmbIncome(BigDecimal.ZERO);
+                        //     detail.setRmbExpenditure(BigDecimal.ZERO);
+                        // }
+
+                        if (rmbMap != null) {
+                            BigDecimal expenditure = rmbMap.get(2);
+                            BigDecimal income = rmbMap.get(1);
 
                             detail.setRmbIncome(income);
                             detail.setRmbExpenditure(expenditure);
 
-                            item.setRmbAmount(item.getRmbAmount().subtract(income).add(expenditure));
+                            BigDecimal rmbAmount = item.getRmbAmount();
+                            if (rmbAmount != null) {
+                                if (income != null) {
+                                    rmbAmount = rmbAmount.subtract(income);
+                                }
+                                if (expenditure != null) {
+                                    rmbAmount = rmbAmount.add(expenditure);
+                                }
+                                item.setRmbAmount(rmbAmount);
+                            }
                         }
 
                         // Map<收支类型(1:收入   2:支出),改变数量>
                         Map<Integer, BigDecimal> dollarMap = integerMapMap.get(CurrencyTypeEnum.USA.getKey());
-                        if (dollarMap == null) {
-                            detail.setDollarIncome(BigDecimal.ZERO);
-                            detail.setRmbExpenditure(BigDecimal.ZERO);
-                        } else {
-                            BigDecimal expenditure = cn.hutool.core.util.ObjectUtil.defaultIfNull(dollarMap.get(2), BigDecimal.ZERO);
-                            BigDecimal income = cn.hutool.core.util.ObjectUtil.defaultIfNull(dollarMap.get(1), BigDecimal.ZERO);
+                        // if (dollarMap == null) {
+                        //     detail.setDollarIncome(BigDecimal.ZERO);
+                        //     detail.setRmbExpenditure(BigDecimal.ZERO);
+                        // }
+                        if (dollarMap != null) {
+                            BigDecimal expenditure = dollarMap.get(2);
+                            BigDecimal income = dollarMap.get(1);
 
                             detail.setDollarIncome(income);
                             detail.setDollarExpenditure(expenditure);
 
-                            item.setDollarAmount(item.getDollarAmount().subtract(income).add(expenditure));
+                            BigDecimal dollarAmount = item.getDollarAmount();
+                            if (dollarAmount != null) {
+                                if (income != null) {
+                                    dollarAmount = dollarAmount.subtract(income);
+                                }
+                                if (expenditure != null) {
+                                    dollarAmount = dollarAmount.add(expenditure);
+                                }
+                                item.setDollarAmount(dollarAmount);
+                            }
                         }
 
                         // Map<收支类型(1:收入   2:支出),改变数量>
                         Map<Integer, BigDecimal> euroMap = integerMapMap.get(CurrencyTypeEnum.EURO.getKey());
-                        if (euroMap == null) {
-                            detail.setEuroIncome(BigDecimal.ZERO);
-                            detail.setEuroExpenditure(BigDecimal.ZERO);
-                        } else {
+                        // if (euroMap == null) {
+                        //     detail.setEuroIncome(BigDecimal.ZERO);
+                        //     detail.setEuroExpenditure(BigDecimal.ZERO);
+                        // }
+                        if (euroMap != null) {
                             BigDecimal expenditure = cn.hutool.core.util.ObjectUtil.defaultIfNull(euroMap.get(2), BigDecimal.ZERO);
                             BigDecimal income = cn.hutool.core.util.ObjectUtil.defaultIfNull(euroMap.get(1), BigDecimal.ZERO);
 
                             detail.setEuroIncome(income);
                             detail.setEuroExpenditure(expenditure);
 
-                            item.setEuroAmount(item.getEuroAmount().subtract(income).add(expenditure));
+                            BigDecimal euroAmount = item.getEuroAmount();
+                            if (euroAmount != null) {
+                                if (income != null) {
+                                    euroAmount = euroAmount.subtract(income);
+                                }
+                                if (expenditure != null) {
+                                    euroAmount = euroAmount.add(expenditure);
+                                }
+                                item.setEuroAmount(euroAmount);
+                            }
                         }
                     }
-
                     detailList.add(detail);
-
-                    yearMonthDay = DateUtil.format(DateUtil.offsetDay(endDate, flag), "yyyy-MM-dd");
-                    flag--;
+                    yearMonthDay = DateUtil.offsetDay(yearMonthDay, -1);
                 }
             }