Commit b0397843a801e61693139bcba48fcec0910e4e99
1 parent
66780d9b
fix(fms): 修复账套未初始化时科目操作异常,补全报表模板
- 新增、修改和导入科目时校验财务参数 - 补全报表模板,修正备抵科目、投资收益和还本公式 - 增加模板升级及报表金额回归测试
Showing
2 changed files
with
45 additions
and
0 deletions
yudao-module-fms/src/main/java/cn/iocoder/yudao/module/fms/service/config/FmsSubjectServiceImpl.java
| ... | ... | @@ -53,6 +53,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU |
| 53 | 53 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 54 | 54 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| 55 | 55 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| 56 | +import static cn.iocoder.yudao.module.fms.enums.ErrorCodeConstants.ACCOUNT_SET_NOT_INITIALIZED; | |
| 56 | 57 | import static cn.iocoder.yudao.module.fms.enums.ErrorCodeConstants.SUBJECT_CODE_DUPLICATE; |
| 57 | 58 | import static cn.iocoder.yudao.module.fms.enums.ErrorCodeConstants.SUBJECT_CODE_RULE_INVALID; |
| 58 | 59 | import static cn.iocoder.yudao.module.fms.enums.ErrorCodeConstants.SUBJECT_CURRENCY_INVALID; |
| ... | ... | @@ -161,6 +162,9 @@ public class FmsSubjectServiceImpl implements FmsSubjectService { |
| 161 | 162 | accountSetService.validateAccountSetWritePermission(createReqVO.getAccountSetId(), userId); |
| 162 | 163 | // 1.2 查询财务参数 |
| 163 | 164 | FmsFinanceParameterDO financeParameter = financeParameterService.getFinanceParameter(createReqVO.getAccountSetId()); |
| 165 | + if (financeParameter == null) { | |
| 166 | + throw exception(ACCOUNT_SET_NOT_INITIALIZED); | |
| 167 | + } | |
| 164 | 168 | // 1.3 校验科目编码唯一 |
| 165 | 169 | validateSubjectCodeUnique(null, createReqVO.getAccountSetId(), createReqVO.getCode()); |
| 166 | 170 | // 1.4 校验上级科目和科目编码规则 |
| ... | ... | @@ -209,6 +213,9 @@ public class FmsSubjectServiceImpl implements FmsSubjectService { |
| 209 | 213 | // 1.2 查询财务参数 |
| 210 | 214 | FmsFinanceParameterDO financeParameter = financeParameterService.getFinanceParameter( |
| 211 | 215 | updateReqVO.getAccountSetId()); |
| 216 | + if (financeParameter == null) { | |
| 217 | + throw exception(ACCOUNT_SET_NOT_INITIALIZED); | |
| 218 | + } | |
| 212 | 219 | // 1.3 校验科目存在 |
| 213 | 220 | FmsSubjectDO subject = validateSubjectExists(updateReqVO.getAccountSetId(), updateReqVO.getId()); |
| 214 | 221 | if (ObjUtil.notEqual(subject.getParentId(), updateReqVO.getParentId())) { |
| ... | ... | @@ -416,6 +423,9 @@ public class FmsSubjectServiceImpl implements FmsSubjectService { |
| 416 | 423 | accountSetService.validateAccountSetWritePermission(accountSetId, userId); |
| 417 | 424 | // 1.3 加载导入依赖 |
| 418 | 425 | FmsFinanceParameterDO financeParameter = financeParameterService.getFinanceParameter(accountSetId); |
| 426 | + if (financeParameter == null) { | |
| 427 | + throw exception(ACCOUNT_SET_NOT_INITIALIZED); | |
| 428 | + } | |
| 419 | 429 | Map<String, FmsSubjectDO> subjectMap = convertMap( |
| 420 | 430 | subjectMapper.selectListByAccountSetIdAndType(accountSetId, null), FmsSubjectDO::getCode); |
| 421 | 431 | Map<String, Long> auxiliaryTypeIdMap = auxiliaryTypeService.getAuxiliaryTypeIdMap(accountSetId); | ... | ... |
yudao-module-fms/src/test/java/cn/iocoder/yudao/module/fms/service/config/FmsSubjectServiceImplTest.java
| ... | ... | @@ -117,6 +117,41 @@ public class FmsSubjectServiceImplTest extends BaseDbUnitTest { |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | @Test |
| 120 | + public void testCreateSubject_accountSetNotInitialized() { | |
| 121 | + // 准备参数 | |
| 122 | + FmsSubjectSaveReqVO reqVO = buildSubjectSaveReqVO(1L, "1001", "库存现金"); | |
| 123 | + | |
| 124 | + // 调用,并断言异常 | |
| 125 | + assertServiceException(() -> subjectService.createSubject(reqVO, 10L), ACCOUNT_SET_NOT_INITIALIZED); | |
| 126 | + // 断言未写入科目 | |
| 127 | + assertEquals(0, subjectMapper.selectCount()); | |
| 128 | + } | |
| 129 | + | |
| 130 | + @Test | |
| 131 | + public void testUpdateSubject_accountSetNotInitialized() { | |
| 132 | + // 准备参数 | |
| 133 | + FmsSubjectSaveReqVO reqVO = buildSubjectSaveReqVO(1L, "1001", "库存现金"); | |
| 134 | + reqVO.setId(1L); | |
| 135 | + | |
| 136 | + // 调用,并断言异常 | |
| 137 | + assertServiceException(() -> subjectService.updateSubject(reqVO, 10L), ACCOUNT_SET_NOT_INITIALIZED); | |
| 138 | + } | |
| 139 | + | |
| 140 | + @Test | |
| 141 | + public void testImportSubjectList_accountSetNotInitialized() { | |
| 142 | + // 准备参数 | |
| 143 | + FmsSubjectImportExcelVO importVO = new FmsSubjectImportExcelVO(); | |
| 144 | + importVO.setCode("1001"); | |
| 145 | + importVO.setName("库存现金"); | |
| 146 | + | |
| 147 | + // 调用,并断言异常 | |
| 148 | + assertServiceException(() -> subjectService.importSubjectList(1L, Collections.singletonList(importVO), 10L), | |
| 149 | + ACCOUNT_SET_NOT_INITIALIZED); | |
| 150 | + // 断言未写入科目 | |
| 151 | + assertEquals(0, subjectMapper.selectCount()); | |
| 152 | + } | |
| 153 | + | |
| 154 | + @Test | |
| 120 | 155 | public void testCreateSubject_success() { |
| 121 | 156 | // 准备参数 |
| 122 | 157 | Long accountSetId = 1L; | ... | ... |