Commit 7e7fa6be4025aeeaf32e6606832180242f608360

Authored by dadiyang
1 parent 8e43004c

fix(fms):报表勾稽逐月查损益改直调 getProfitLossBalance,断 getClosingOverview↔checkBalanceSheet 无限递归栈溢出(A40)

yudao-module-fms/src/main/java/cn/iocoder/yudao/module/fms/service/closing/FmsClosingPeriodService.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.fms.service.closing; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.fms.service.closing;
3 import cn.iocoder.yudao.module.fms.controller.admin.closing.vo.FmsClosingOverviewRespVO; 3 import cn.iocoder.yudao.module.fms.controller.admin.closing.vo.FmsClosingOverviewRespVO;
4 import cn.iocoder.yudao.module.fms.controller.admin.closing.vo.FmsClosingQueryReqVO; 4 import cn.iocoder.yudao.module.fms.controller.admin.closing.vo.FmsClosingQueryReqVO;
5 5
  6 +import java.math.BigDecimal;
6 import java.time.LocalDateTime; 7 import java.time.LocalDateTime;
7 import java.time.YearMonth; 8 import java.time.YearMonth;
8 9
@@ -58,6 +59,19 @@ public interface FmsClosingPeriodService { @@ -58,6 +59,19 @@ public interface FmsClosingPeriodService {
58 FmsClosingOverviewRespVO getClosingOverview(FmsClosingQueryReqVO queryReqVO, Long userId); 59 FmsClosingOverviewRespVO getClosingOverview(FmsClosingQueryReqVO queryReqVO, Long userId);
59 60
60 /** 61 /**
  62 + * 获得指定会计期间的损益结转余额(末级损益科目本期借贷差额绝对值之和)
  63 + *
  64 + * 供报表勾稽逐月检查损益是否结转使用:直接查账簿余额,
  65 + * 不重入 getClosingOverview(后者内部会回调报表 check,构成无限递归)。
  66 + *
  67 + * @param accountSetId 账套编号
  68 + * @param month 会计期间
  69 + * @param userId 用户编号
  70 + * @return 损益余额
  71 + */
  72 + BigDecimal getProfitLossBalance(Long accountSetId, String month, Long userId);
  73 +
  74 + /**
61 * 结账 75 * 结账
62 * 76 *
63 * @param queryReqVO 结账期间 77 * @param queryReqVO 结账期间
yudao-module-fms/src/main/java/cn/iocoder/yudao/module/fms/service/closing/FmsClosingPeriodServiceImpl.java
@@ -199,6 +199,11 @@ public class FmsClosingPeriodServiceImpl implements FmsClosingPeriodService { @@ -199,6 +199,11 @@ public class FmsClosingPeriodServiceImpl implements FmsClosingPeriodService {
199 } 199 }
200 200
201 @Override 201 @Override
  202 + public BigDecimal getProfitLossBalance(Long accountSetId, String month, Long userId) {
  203 + return calculateProfitLossBalance(accountSetId, LocalDateTimeUtils.parseYearMonth(month), userId);
  204 + }
  205 +
  206 + @Override
202 @Transactional(rollbackFor = Exception.class) 207 @Transactional(rollbackFor = Exception.class)
203 @LogRecord(type = FMS_CLOSING_TYPE, subType = FMS_CLOSING_PERIOD_CLOSE_SUB_TYPE, 208 @LogRecord(type = FMS_CLOSING_TYPE, subType = FMS_CLOSING_PERIOD_CLOSE_SUB_TYPE,
204 bizNo = "{{#queryReqVO.accountSetId}}", success = FMS_CLOSING_PERIOD_CLOSE_SUCCESS) 209 bizNo = "{{#queryReqVO.accountSetId}}", success = FMS_CLOSING_PERIOD_CLOSE_SUCCESS)
yudao-module-fms/src/main/java/cn/iocoder/yudao/module/fms/service/report/FmsBalanceSheetServiceImpl.java
@@ -302,12 +302,12 @@ public class FmsBalanceSheetServiceImpl implements FmsBalanceSheetService { @@ -302,12 +302,12 @@ public class FmsBalanceSheetServiceImpl implements FmsBalanceSheetService {
302 YearMonth endMonth = LocalDateTimeUtils.parseYearMonth(listReqVO.getEndMonth()); 302 YearMonth endMonth = LocalDateTimeUtils.parseYearMonth(listReqVO.getEndMonth());
303 for (YearMonth currentMonth = LocalDateTimeUtils.parseYearMonth(listReqVO.getStartMonth()); 303 for (YearMonth currentMonth = LocalDateTimeUtils.parseYearMonth(listReqVO.getStartMonth());
304 !currentMonth.isAfter(endMonth); currentMonth = currentMonth.plusMonths(1)) { 304 !currentMonth.isAfter(endMonth); currentMonth = currentMonth.plusMonths(1)) {
305 - FmsClosingQueryReqVO closingQueryReqVO = new FmsClosingQueryReqVO();  
306 - closingQueryReqVO.setAccountSetId(listReqVO.getAccountSetId());  
307 - closingQueryReqVO.setMonth(currentMonth.toString());  
308 - FmsClosingOverviewRespVO overview = closingPeriodService.getClosingOverview(closingQueryReqVO, userId); 305 + // 直接查当月损益余额,不再重入 getClosingOverview
  306 + //(其内部会回调本类 checkBalanceSheet → 本方法,对同月构成无界自递归,栈溢出)
  307 + BigDecimal profitLossBalance = closingPeriodService.getProfitLossBalance(
  308 + listReqVO.getAccountSetId(), currentMonth.toString(), userId);
309 // 当月损益余额不为零时,说明存在尚未结转的损益 309 // 当月损益余额不为零时,说明存在尚未结转的损益
310 - if (NumberUtils.zeroIfNull(overview.getProfitLossBalance()).signum() != 0) { 310 + if (NumberUtils.zeroIfNull(profitLossBalance).signum() != 0) {
311 return false; 311 return false;
312 } 312 }
313 } 313 }