Commit 25f030ddcfdec420bd97eb2b4ce0e215f8021c6b

Authored by YunaiV
1 parent b572669c

fix(hrm): 统一定薪调薪工资项范围

关联:https://t.zsxq.com/hhClm
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 @@ -265,7 +265,7 @@ public class HrmSalaryEmployeeInfoServiceImpl implements HrmSalaryEmployeeInfoSe
265 265
266 @Override 266 @Override
267 public List<HrmSalaryOptionDO> getSalaryImportOptionList() { 267 public List<HrmSalaryOptionDO> getSalaryImportOptionList() {
268 - List<HrmSalaryOptionDO> options = salaryOptionService.getSalaryOptionList(false); 268 + List<HrmSalaryOptionDO> options = salaryOptionService.getSalaryOptionList(true);
269 return filterList(options, option -> ObjectUtil.notEqual(option.getParentCode(), ROOT_PARENT_CODE) 269 return filterList(options, option -> ObjectUtil.notEqual(option.getParentCode(), ROOT_PARENT_CODE)
270 && Boolean.TRUE.equals(option.getCalculateEnabled()) 270 && Boolean.TRUE.equals(option.getCalculateEnabled())
271 && !HrmSalaryOptionCodeEnum.EMPLOYEE_INFO_IMPORT_EXCLUDED_PARENT_CODES.contains(option.getParentCode())); 271 && !HrmSalaryOptionCodeEnum.EMPLOYEE_INFO_IMPORT_EXCLUDED_PARENT_CODES.contains(option.getParentCode()));
@@ -762,7 +762,7 @@ public class HrmSalaryEmployeeInfoServiceImpl implements HrmSalaryEmployeeInfoSe @@ -762,7 +762,7 @@ public class HrmSalaryEmployeeInfoServiceImpl implements HrmSalaryEmployeeInfoSe
762 } 762 }
763 763
764 private Map<Integer, HrmSalaryOptionDO> getSalaryOptionMap() { 764 private Map<Integer, HrmSalaryOptionDO> getSalaryOptionMap() {
765 - return convertMap(salaryOptionService.getSalaryOptionList(false), HrmSalaryOptionDO::getCode); 765 + return convertMap(salaryOptionService.getSalaryOptionList(true), HrmSalaryOptionDO::getCode);
766 } 766 }
767 767
768 private HrmSalaryOptionValueVO buildSalaryOptionValueVO(HrmSalaryEmployeeInfoDO.SalaryOption optionDO) { 768 private HrmSalaryOptionValueVO buildSalaryOptionValueVO(HrmSalaryEmployeeInfoDO.SalaryOption optionDO) {
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 { @@ -154,13 +154,37 @@ public class HrmSalaryOptionServiceImplTest extends BaseDbUnitTest {
154 salaryOptionMapper.insert(createSalaryOption(100101, 100, "个人社保", false)); 154 salaryOptionMapper.insert(createSalaryOption(100101, 100, "个人社保", false));
155 salaryOptionMapper.insert(createSalaryOption(20, 0, "津贴", false).setEnabled(false)); 155 salaryOptionMapper.insert(createSalaryOption(20, 0, "津贴", false).setEnabled(false));
156 salaryOptionMapper.insert(createSalaryOption(20101, 20, "交通补贴", false)); 156 salaryOptionMapper.insert(createSalaryOption(20101, 20, "交通补贴", false));
  157 + salaryOptionMapper.insert(createSalaryOption(180, 0, "加班工资", true));
  158 + salaryOptionMapper.insert(createSalaryOption(180101, 180, "加班工资", true));
  159 + salaryOptionMapper.insert(createSalaryOption(190, 0, "考勤扣款", true));
  160 + for (int code = 190101; code <= 190106; code++) {
  161 + salaryOptionMapper.insert(createSalaryOption(code, 190, "考勤扣款", true).setVisible(false));
  162 + }
  163 + salaryOptionMapper.insert(createSalaryOption(10102, 10, "停用工资项", false).setEnabled(false));
  164 + salaryOptionMapper.insert(createSalaryOption(10103, 10, "隐藏工资项", false).setVisible(false));
157 165
158 // 调用 166 // 调用
159 List<HrmSalaryOptionDO> options = salaryOptionService.getSalaryOptionList(true); 167 List<HrmSalaryOptionDO> options = salaryOptionService.getSalaryOptionList(true);
160 168
161 // 断言 169 // 断言
162 - assertEquals(1, options.size()); 170 + assertEquals(2, options.size());
163 assertEquals(Integer.valueOf(10101), options.get(0).getCode()); 171 assertEquals(Integer.valueOf(10101), options.get(0).getCode());
  172 + assertEquals(Integer.valueOf(10103), options.get(1).getCode());
  173 + }
  174 +
  175 + @Test
  176 + public void testGetSalaryOptionList_adjustableCategoryDisabled() {
  177 + // mock 数据
  178 + salaryOptionMapper.insert(createSalaryOption(10, 0, "基本工资", false).setEnabled(false));
  179 + salaryOptionMapper.insert(createSalaryOption(10101, 10, "基本工资", false));
  180 + salaryOptionMapper.insert(createSalaryOption(180, 0, "加班工资", true));
  181 + salaryOptionMapper.insert(createSalaryOption(180101, 180, "加班工资", true));
  182 +
  183 + // 调用
  184 + List<HrmSalaryOptionDO> options = salaryOptionService.getSalaryOptionList(true);
  185 +
  186 + // 断言
  187 + assertTrue(options.isEmpty());
164 } 188 }
165 189
166 @Test 190 @Test
yudao-module-hrm/src/test/java/cn/iocoder/yudao/module/hrm/service/salary/employee/HrmSalaryEmployeeInfoServiceImplTest.java
@@ -40,6 +40,7 @@ import java.util.Map; @@ -40,6 +40,7 @@ import java.util.Map;
40 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; 40 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
41 import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CHANGE_EFFECT_DATE_INVALID; 41 import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CHANGE_EFFECT_DATE_INVALID;
42 import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CHANGE_RECORD_STATUS_INVALID; 42 import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CHANGE_RECORD_STATUS_INVALID;
  43 +import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_DATA_ILLEGAL;
43 import static org.junit.jupiter.api.Assertions.assertEquals; 44 import static org.junit.jupiter.api.Assertions.assertEquals;
44 import static org.junit.jupiter.api.Assertions.assertNotNull; 45 import static org.junit.jupiter.api.Assertions.assertNotNull;
45 import static org.junit.jupiter.api.Assertions.assertTrue; 46 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -166,6 +167,50 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest { @@ -166,6 +167,50 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest {
166 } 167 }
167 168
168 @Test 169 @Test
  170 + public void testUpdateSalaryEmployeeInfo_salaryOptionInvalid() {
  171 + // mock 数据
  172 + mockSalaryOptions();
  173 + HrmEmployeeDO employee = mockEmployee(1L, HrmEmployeeStatusEnum.REGULAR.getStatus());
  174 + // 准备参数
  175 + HrmSalaryEmployeeInfoUpdateReqVO reqVO = buildSetSalaryReqVO(employee.getId(),
  176 + new BigDecimal("8000"), new BigDecimal("2000"), new BigDecimal("6000"));
  177 +
  178 + // 调用,并断言加班工资、考勤扣款不能作为定薪项
  179 + for (Integer code : Arrays.asList(180101, 190101, 190102, 190103, 190104, 190105, 190106)) {
  180 + reqVO.setSalaryOptions(Collections.singletonList(
  181 + optionValue(code, "系统计算项", new BigDecimal("100"))));
  182 + assertServiceException(() -> salaryEmployeeInfoService.updateSalaryEmployeeInfo(reqVO),
  183 + SALARY_DATA_ILLEGAL);
  184 + }
  185 +
  186 + // 断言未写入薪资档案和调薪记录
  187 + assertEquals(0L, salaryEmployeeInfoMapper.selectCount());
  188 + verify(salaryChangeRecordService, never()).createSalaryChangeRecord(any());
  189 + }
  190 +
  191 + @Test
  192 + public void testUpdateSalaryEmployeeInfo_probationSalaryOptionInvalid() {
  193 + // mock 数据
  194 + mockSalaryOptions();
  195 + HrmEmployeeDO employee = mockEmployee(1L, HrmEmployeeStatusEnum.REGULAR.getStatus());
  196 + // 准备参数
  197 + HrmSalaryEmployeeInfoUpdateReqVO reqVO = buildSetSalaryReqVO(employee.getId(),
  198 + new BigDecimal("8000"), new BigDecimal("2000"), new BigDecimal("6000"));
  199 +
  200 + // 调用,并断言加班工资、考勤扣款不能作为定薪项
  201 + for (Integer code : Arrays.asList(180101, 190101, 190102, 190103, 190104, 190105, 190106)) {
  202 + reqVO.setProbationSalaryOptions(Collections.singletonList(
  203 + optionValue(code, "系统计算项", new BigDecimal("100"))));
  204 + assertServiceException(() -> salaryEmployeeInfoService.updateSalaryEmployeeInfo(reqVO),
  205 + SALARY_DATA_ILLEGAL);
  206 + }
  207 +
  208 + // 断言未写入薪资档案和调薪记录
  209 + assertEquals(0L, salaryEmployeeInfoMapper.selectCount());
  210 + verify(salaryChangeRecordService, never()).createSalaryChangeRecord(any());
  211 + }
  212 +
  213 + @Test
169 public void testUpdateSalaryEmployeeInfo_adjustmentPending() { 214 public void testUpdateSalaryEmployeeInfo_adjustmentPending() {
170 // mock 数据 215 // mock 数据
171 mockSalaryOptions(); 216 mockSalaryOptions();
@@ -317,7 +362,7 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest { @@ -317,7 +362,7 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest {
317 public void testGetSalaryImportOptionList() { 362 public void testGetSalaryImportOptionList() {
318 // mock 数据 363 // mock 数据
319 List<HrmSalaryOptionDO> options = buildSalaryOptions(); 364 List<HrmSalaryOptionDO> options = buildSalaryOptions();
320 - when(salaryOptionService.getSalaryOptionList(false)).thenReturn(options); 365 + when(salaryOptionService.getSalaryOptionList(true)).thenReturn(options);
321 366
322 // 调用 367 // 调用
323 List<HrmSalaryOptionDO> result = 368 List<HrmSalaryOptionDO> result =
@@ -435,7 +480,7 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest { @@ -435,7 +480,7 @@ public class HrmSalaryEmployeeInfoServiceImplTest extends BaseDbUnitTest {
435 } 480 }
436 481
437 private void mockSalaryOptions() { 482 private void mockSalaryOptions() {
438 - when(salaryOptionService.getSalaryOptionList(false)) 483 + when(salaryOptionService.getSalaryOptionList(true))
439 .thenReturn(buildSalaryOptions()); 484 .thenReturn(buildSalaryOptions());
440 } 485 }
441 486