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

This commit is contained in:
dadiyang
2026-09-23 20:02:02 +08:00
parent 8e43004cf6
commit 7e7fa6be40
3 changed files with 24 additions and 5 deletions
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.fms.service.closing;
import cn.iocoder.yudao.module.fms.controller.admin.closing.vo.FmsClosingOverviewRespVO;
import cn.iocoder.yudao.module.fms.controller.admin.closing.vo.FmsClosingQueryReqVO;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.YearMonth;
@@ -57,6 +58,19 @@ public interface FmsClosingPeriodService {
*/
FmsClosingOverviewRespVO getClosingOverview(FmsClosingQueryReqVO queryReqVO, Long userId);
/**
* 获得指定会计期间的损益结转余额(末级损益科目本期借贷差额绝对值之和)
*
* 供报表勾稽逐月检查损益是否结转使用:直接查账簿余额,
* 不重入 getClosingOverview(后者内部会回调报表 check,构成无限递归)。
*
* @param accountSetId 账套编号
* @param month 会计期间
* @param userId 用户编号
* @return 损益余额
*/
BigDecimal getProfitLossBalance(Long accountSetId, String month, Long userId);
/**
* 结账
*
@@ -198,6 +198,11 @@ public class FmsClosingPeriodServiceImpl implements FmsClosingPeriodService {
.setCanClose(canClose);
}
@Override
public BigDecimal getProfitLossBalance(Long accountSetId, String month, Long userId) {
return calculateProfitLossBalance(accountSetId, LocalDateTimeUtils.parseYearMonth(month), userId);
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = FMS_CLOSING_TYPE, subType = FMS_CLOSING_PERIOD_CLOSE_SUB_TYPE,
@@ -302,12 +302,12 @@ public class FmsBalanceSheetServiceImpl implements FmsBalanceSheetService {
YearMonth endMonth = LocalDateTimeUtils.parseYearMonth(listReqVO.getEndMonth());
for (YearMonth currentMonth = LocalDateTimeUtils.parseYearMonth(listReqVO.getStartMonth());
!currentMonth.isAfter(endMonth); currentMonth = currentMonth.plusMonths(1)) {
FmsClosingQueryReqVO closingQueryReqVO = new FmsClosingQueryReqVO();
closingQueryReqVO.setAccountSetId(listReqVO.getAccountSetId());
closingQueryReqVO.setMonth(currentMonth.toString());
FmsClosingOverviewRespVO overview = closingPeriodService.getClosingOverview(closingQueryReqVO, userId);
// 直接查当月损益余额,不再重入 getClosingOverview
//(其内部会回调本类 checkBalanceSheet → 本方法,对同月构成无界自递归,栈溢出)
BigDecimal profitLossBalance = closingPeriodService.getProfitLossBalance(
listReqVO.getAccountSetId(), currentMonth.toString(), userId);
// 当月损益余额不为零时,说明存在尚未结转的损益
if (NumberUtils.zeroIfNull(overview.getProfitLossBalance()).signum() != 0) {
if (NumberUtils.zeroIfNull(profitLossBalance).signum() != 0) {
return false;
}
}