From 25f030ddcfdec420bd97eb2b4ce0e215f8021c6b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 26 Sep 2026 22:21:50 +0800 Subject: [PATCH] fix(hrm): 统一定薪调薪工资项范围 --- yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImpl.java | 4 ++-- yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/config/HrmSalaryOptionServiceImplTest.java | 26 +++++++++++++++++++++++++- yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImplTest.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImpl.java b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImpl.java index 73e3c2d..fe7b451 100644 --- a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImpl.java +++ b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImpl.java @@ -265,7 +265,7 @@ public class HrmSalaryEmployeeInfoServiceImpl implements HrmSalaryEmployeeInfoSe @Override public List getSalaryImportOptionList() { - List options = salaryOptionService.getSalaryOptionList(false); + List options = salaryOptionService.getSalaryOptionList(true); return filterList(options, option -> ObjectUtil.notEqual(option.getParentCode(), ROOT_PARENT_CODE) && Boolean.TRUE.equals(option.getCalculateEnabled()) && !HrmSalaryOptionCodeEnum.EMPLOYEE_INFO_IMPORT_EXCLUDED_PARENT_CODES.contains(option.getParentCode())); @@ -762,7 +762,7 @@ public class HrmSalaryEmployeeInfoServiceImpl implements HrmSalaryEmployeeInfoSe } private Map getSalaryOptionMap() { - return convertMap(salaryOptionService.getSalaryOptionList(false), HrmSalaryOptionDO::getCode); + return convertMap(salaryOptionService.getSalaryOptionList(true), HrmSalaryOptionDO::getCode); } private HrmSalaryOptionValueVO buildSalaryOptionValueVO(HrmSalaryEmployeeInfoDO.SalaryOption optionDO) { diff --git a/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/config/HrmSalaryOptionServiceImplTest.java b/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/config/HrmSalaryOptionServiceImplTest.java index abf1e97..4b0f2f1 100644 --- a/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/config/HrmSalaryOptionServiceImplTest.java +++ b/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/config/HrmSalaryOptionServiceImplTest.java @@ -154,13 +154,37 @@ public class HrmSalaryOptionServiceImplTest extends BaseDbUnitTest { salaryOptionMapper.insert(createSalaryOption(100101, 100, "个人社保", false)); salaryOptionMapper.insert(createSalaryOption(20, 0, "津贴", false).setEnabled(false)); salaryOptionMapper.insert(createSalaryOption(20101, 20, "交通补贴", false)); + salaryOptionMapper.insert(createSalaryOption(180, 0, "加班工资", true)); + salaryOptionMapper.insert(createSalaryOption(180101, 180, "加班工资", true)); + salaryOptionMapper.insert(createSalaryOption(190, 0, "考勤扣款", true)); + for (int code = 190101; code <= 190106; code++) { + salaryOptionMapper.insert(createSalaryOption(code, 190, "考勤扣款", true).setVisible(false)); + } + salaryOptionMapper.insert(createSalaryOption(10102, 10, "停用工资项", false).setEnabled(false)); + salaryOptionMapper.insert(createSalaryOption(10103, 10, "隐藏工资项", false).setVisible(false)); // 调用 List options = salaryOptionService.getSalaryOptionList(true); // 断言 - assertEquals(1, options.size()); + assertEquals(2, options.size()); assertEquals(Integer.valueOf(10101), options.get(0).getCode()); + assertEquals(Integer.valueOf(10103), options.get(1).getCode()); + } + + @Test + public void testGetSalaryOptionList_adjustableCategoryDisabled() { + // mock 数据 + salaryOptionMapper.insert(createSalaryOption(10, 0, "基本工资", false).setEnabled(false)); + salaryOptionMapper.insert(createSalaryOption(10101, 10, "基本工资", false)); + salaryOptionMapper.insert(createSalaryOption(180, 0, "加班工资", true)); + salaryOptionMapper.insert(createSalaryOption(180101, 180, "加班工资", true)); + + // 调用 + List options = salaryOptionService.getSalaryOptionList(true); + + // 断言 + assertTrue(options.isEmpty()); } @Test diff --git a/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImplTest.java b/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImplTest.java index 064fae2..520acd8 100644 --- a/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImplTest.java +++ b/yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImplTest.java @@ -40,6 +40,7 @@ import java.util.Map; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CHANGE_EFFECT_DATE_INVALID; import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CHANGE_RECORD_STATUS_INVALID; +import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_DATA_ILLEGAL; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -166,6 +167,50 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest { } @Test + public void testUpdateSalaryEmployeeInfo_salaryOptionInvalid() { + // mock 数据 + mockSalaryOptions(); + HrmEmployeeDO employee = mockEmployee(1L, HrmEmployeeStatusEnum.REGULAR.getStatus()); + // 准备参数 + HrmSalaryEmployeeInfoUpdateReqVO reqVO = buildSetSalaryReqVO(employee.getId(), + new BigDecimal("8000"), new BigDecimal("2000"), new BigDecimal("6000")); + + // 调用,并断言加班工资、考勤扣款不能作为定薪项 + for (Integer code : Arrays.asList(180101, 190101, 190102, 190103, 190104, 190105, 190106)) { + reqVO.setSalaryOptions(Collections.singletonList( + optionValue(code, "系统计算项", new BigDecimal("100")))); + assertServiceException(() -> salaryEmployeeInfoService.updateSalaryEmployeeInfo(reqVO), + SALARY_DATA_ILLEGAL); + } + + // 断言未写入薪资档案和调薪记录 + assertEquals(0L, salaryEmployeeInfoMapper.selectCount()); + verify(salaryChangeRecordService, never()).createSalaryChangeRecord(any()); + } + + @Test + public void testUpdateSalaryEmployeeInfo_probationSalaryOptionInvalid() { + // mock 数据 + mockSalaryOptions(); + HrmEmployeeDO employee = mockEmployee(1L, HrmEmployeeStatusEnum.REGULAR.getStatus()); + // 准备参数 + HrmSalaryEmployeeInfoUpdateReqVO reqVO = buildSetSalaryReqVO(employee.getId(), + new BigDecimal("8000"), new BigDecimal("2000"), new BigDecimal("6000")); + + // 调用,并断言加班工资、考勤扣款不能作为定薪项 + for (Integer code : Arrays.asList(180101, 190101, 190102, 190103, 190104, 190105, 190106)) { + reqVO.setProbationSalaryOptions(Collections.singletonList( + optionValue(code, "系统计算项", new BigDecimal("100")))); + assertServiceException(() -> salaryEmployeeInfoService.updateSalaryEmployeeInfo(reqVO), + SALARY_DATA_ILLEGAL); + } + + // 断言未写入薪资档案和调薪记录 + assertEquals(0L, salaryEmployeeInfoMapper.selectCount()); + verify(salaryChangeRecordService, never()).createSalaryChangeRecord(any()); + } + + @Test public void testUpdateSalaryEmployeeInfo_adjustmentPending() { // mock 数据 mockSalaryOptions(); @@ -317,7 +362,7 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest { public void testGetSalaryImportOptionList() { // mock 数据 List options = buildSalaryOptions(); - when(salaryOptionService.getSalaryOptionList(false)).thenReturn(options); + when(salaryOptionService.getSalaryOptionList(true)).thenReturn(options); // 调用 List result = @@ -435,7 +480,7 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest { } private void mockSalaryOptions() { - when(salaryOptionService.getSalaryOptionList(false)) + when(salaryOptionService.getSalaryOptionList(true)) .thenReturn(buildSalaryOptions()); } -- libgit2 0.21.4