feat:同步 hrm、fms 最新进度

This commit is contained in:
YunaiV
2026-08-14 23:14:13 +08:00
parent ae49ccd6d7
commit fe07c44e2a
4 changed files with 47 additions and 88 deletions
@@ -22,21 +22,13 @@ import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
/**
* {@link HrmAttendanceGroupServiceImpl} 的单元测试类
@@ -75,10 +67,10 @@ public class HrmAttendanceGroupServiceImplTest extends BaseMockitoUnitTest {
when(employeeService.getEmployeeMap(Arrays.asList(1L, 2L, 3L))).thenReturn(employeeMap);
when(attendanceGroupMapper.selectListOrderByDefaultStatusAndId())
.thenReturn(Arrays.asList(defaultGroup, directGroup, deptGroup));
when(deptApi.getParentDeptList(10L)).thenReturn(Collections.emptyList());
when(deptApi.getParentDeptList(20L)).thenReturn(Collections.singletonList(
new DeptRespDTO().setId(10L)));
when(deptApi.getParentDeptList(30L)).thenReturn(Collections.emptyList());
when(deptApi.getParentDeptList(10L)).thenReturn(success(Collections.emptyList()));
when(deptApi.getParentDeptList(20L)).thenReturn(success(Collections.singletonList(
new DeptRespDTO().setId(10L))));
when(deptApi.getParentDeptList(30L)).thenReturn(success(Collections.emptyList()));
// 调用
Map<Long, HrmAttendanceGroupDO> result =
@@ -153,7 +145,7 @@ public class HrmAttendanceGroupServiceImplTest extends BaseMockitoUnitTest {
group.setId(1L);
return 1;
});
when(deptApi.getChildDeptList(anyCollection())).thenReturn(Collections.emptyList());
when(deptApi.getChildDeptList(anyCollection())).thenReturn(success(Collections.emptyList()));
when(attendanceGroupMapper.selectListOrderByDefaultStatusAndId()).thenReturn(Collections.emptyList());
// 准备参数
@@ -219,7 +211,7 @@ public class HrmAttendanceGroupServiceImplTest extends BaseMockitoUnitTest {
.setName("考勤组 B").setDeptIds(Collections.emptyList())
.setEmployeeIds(Arrays.asList(10L, 11L)).setDefaultStatus(false);
when(attendanceGroupMapper.selectById(currentGroup.getId())).thenReturn(currentGroup);
when(deptApi.getChildDeptList(anyCollection())).thenReturn(Collections.emptyList());
when(deptApi.getChildDeptList(anyCollection())).thenReturn(success(Collections.emptyList()));
when(attendanceGroupMapper.selectListOrderByDefaultStatusAndId())
.thenReturn(Arrays.asList(currentGroup, otherGroup));
HrmAttendanceGroupSaveReqVO reqVO = new HrmAttendanceGroupSaveReqVO();
@@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
@@ -56,7 +57,7 @@ public class HrmAttendanceLeaveServiceImplTest extends BaseDbUnitTest {
HrmEmployeeDO employee = new HrmEmployeeDO().setId(randomLongId())
.setDeptId(randomLongId()).setName("张三");
when(employeeService.validateEmployeeBySelf(userId)).thenReturn(employee);
when(processInstanceApi.createProcessInstance(eq(userId), any())).thenReturn("leave-process");
when(processInstanceApi.createProcessInstance(eq(userId), any())).thenReturn(success("leave-process"));
// 准备参数
HrmAttendanceLeaveCreateReqVO reqVO = new HrmAttendanceLeaveCreateReqVO();
@@ -86,7 +87,7 @@ public class HrmAttendanceLeaveServiceImplTest extends BaseDbUnitTest {
HrmEmployeeDO employee = new HrmEmployeeDO().setId(randomLongId())
.setDeptId(randomLongId()).setName("张三");
when(employeeService.validateEmployeeBySelf(userId)).thenReturn(employee);
when(processInstanceApi.createProcessInstance(eq(userId), any())).thenReturn("leave-process");
when(processInstanceApi.createProcessInstance(eq(userId), any())).thenReturn(success("leave-process"));
// 准备参数
HrmAttendanceLeaveCreateReqVO reqVO = new HrmAttendanceLeaveCreateReqVO();
@@ -117,6 +118,8 @@ public class HrmAttendanceLeaveServiceImplTest extends BaseDbUnitTest {
HrmAttendanceLeaveCancelReqVO reqVO = new HrmAttendanceLeaveCancelReqVO();
reqVO.setId(attendanceLeave.getId());
reqVO.setReason("行程取消");
when(processInstanceApi.cancelProcessInstanceByStartUser(
userId, attendanceLeave.getProcessInstanceId(), reqVO.getReason())).thenReturn(success(true));
// 调用
attendanceLeaveService.cancelLeave(userId, reqVO);
@@ -1,9 +1,5 @@
package cn.iocoder.yudao.module.hrm.service.employee.info;
import cn.iocoder.yudao.module.hrm.service.employee.config.HrmEmployeeFieldConfigService;
import cn.iocoder.yudao.module.hrm.service.employee.employment.HrmEmployeeChangeRecordService;
import cn.iocoder.yudao.module.hrm.service.employee.employment.HrmEmployeeQuitInfoService;
import cn.iocoder.yudao.module.hrm.service.employee.employment.HrmEmployeeSalaryCardService;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
@@ -13,40 +9,26 @@ import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.changerecord.Hrm
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.changerecord.HrmEmployeeConvertToFullTimeReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.changerecord.HrmEmployeeRegularReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.changerecord.HrmEmployeeTransferReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeCreateFromUserReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeNotifyRespVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeCancelQuitReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeConfirmEntryReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeImportExcelVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeImportRespVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeListReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeePageReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.*;
import cn.iocoder.yudao.module.hrm.controller.admin.portal.employee.vo.employee.HrmPortalEmployeeUpdateReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeQuitReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeRehireReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.employee.HrmEmployeeSaveReqVO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.employment.HrmEmployeeChangeRecordDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.employment.HrmEmployeeQuitInfoDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.info.HrmEmployeeDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.insurance.config.HrmInsuranceSchemeDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.employment.HrmEmployeeQuitInfoDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.recruit.config.HrmRecruitChannelDO;
import cn.iocoder.yudao.module.hrm.dal.mysql.employee.employment.HrmEmployeeChangeRecordMapper;
import cn.iocoder.yudao.module.hrm.dal.mysql.employee.info.HrmEmployeeMapper;
import cn.iocoder.yudao.module.hrm.enums.employee.config.HrmEmployeeArchiveFieldEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.employment.HrmEmployeeChangeTypeEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.experience.HrmEmployeeEducationEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeTypeEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeEntryStatusEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeIdTypeEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeImportDuplicateStrategyEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeStatusEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeStatusTabEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeSurveyTypeEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.HrmEmployeeTodoTypeEnum;
import cn.iocoder.yudao.module.hrm.enums.recruit.candidate.HrmRecruitCandidateStatusEnum;
import cn.iocoder.yudao.module.hrm.enums.employee.info.*;
import cn.iocoder.yudao.module.hrm.framework.excel.core.HrmRecruitChannelExcelColumnSelectFunction;
import cn.iocoder.yudao.module.hrm.service.insurance.employee.HrmInsuranceEmployeeInfoService;
import cn.iocoder.yudao.module.hrm.service.employee.config.HrmEmployeeFieldConfigService;
import cn.iocoder.yudao.module.hrm.service.employee.employment.HrmEmployeeChangeRecordService;
import cn.iocoder.yudao.module.hrm.service.employee.employment.HrmEmployeeQuitInfoService;
import cn.iocoder.yudao.module.hrm.service.employee.employment.HrmEmployeeSalaryCardService;
import cn.iocoder.yudao.module.hrm.service.insurance.config.HrmInsuranceSchemeService;
import cn.iocoder.yudao.module.hrm.service.insurance.employee.HrmInsuranceEmployeeInfoService;
import cn.iocoder.yudao.module.hrm.service.recruit.candidate.HrmRecruitCandidateService;
import cn.iocoder.yudao.module.hrm.service.recruit.config.HrmRecruitChannelService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
@@ -56,12 +38,12 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.mzt.logapi.beans.LogRecord;
import com.mzt.logapi.service.ILogRecordService;
import jakarta.annotation.Resource;
import org.mockito.ArgumentCaptor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
@@ -69,52 +51,25 @@ import org.springframework.transaction.support.TransactionTemplate;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.util.List;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomEmail;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomMobile;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_CHANGE_TYPE_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_CONFIRM_ENTRY_STATUS_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_ENTRY_STATUS_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_IMPORT_LIST_IS_EMPTY;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_IMPORT_DUPLICATE_STRATEGY_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_JOB_NUMBER_DUPLICATE;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_LEADER_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_MOBILE_DUPLICATE;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_NOT_EXISTS;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_QUIT_CANCEL_STATUS_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_QUIT_STATUS_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_REHIRE_STATUS_INVALID;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_USER_DUPLICATE;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.RECRUIT_CHANNEL_NOT_EXISTS;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.hrm.enums.LogRecordConstants.HRM_EMPLOYEE_TYPE;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static java.util.Collections.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
/**
* {@link HrmEmployeeServiceImpl} 的单元测试类
@@ -757,7 +712,7 @@ public class HrmEmployeeServiceImplTest extends BaseDbUnitTest {
List<HrmEmployeeCreateFromUserReqVO> createReqVOList = asList(firstReqVO, secondReqVO);
// mock 方法
when(adminUserApi.getUserList(argThat(ids -> ids.containsAll(asList(firstUser.getId(), secondUser.getId())))))
.thenReturn(asList(firstUser, secondUser));
.thenReturn(success(asList(firstUser, secondUser)));
doAnswer(invocation -> {
HrmEmployeeSaveReqVO saveReqVO = invocation.getArgument(0);
assertNull(saveReqVO.getName());
@@ -1331,7 +1286,7 @@ public class HrmEmployeeServiceImplTest extends BaseDbUnitTest {
AdminUserRespDTO user = new AdminUserRespDTO();
user.setId(20L);
user.setMobile("15601691600");
when(adminUserApi.getUserByMobile(user.getMobile())).thenReturn(user);
when(adminUserApi.getUserByMobile(user.getMobile())).thenReturn(success(user));
HrmInsuranceSchemeDO scheme = randomPojo(HrmInsuranceSchemeDO.class,
o -> o.setId(30L).setName("杭州标准方案"));
when(insuranceSchemeService.getSchemeByName(scheme.getName())).thenReturn(scheme);
@@ -18,11 +18,13 @@ import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
@@ -32,6 +34,8 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.argThat;
/**
* {@link HrmSalaryGroupServiceImpl} 的单元测试类
@@ -60,6 +64,7 @@ public class HrmSalaryGroupServiceImplTest extends BaseDbUnitTest {
HrmSalaryGroupSaveReqVO reqVO = randomSalaryGroupSaveReqVO();
// mock 方法
mockSalaryTaxRule(reqVO.getTaxRuleId());
when(deptApi.getChildDeptList(anyCollection())).thenReturn(success(emptyList()));
// 调用
Long salaryGroupId = salaryGroupService.createSalaryGroup(reqVO);
@@ -115,8 +120,11 @@ public class HrmSalaryGroupServiceImplTest extends BaseDbUnitTest {
.setDeptIds(singletonList(childDeptId)).setEmployeeIds(emptyList()));
// mock 方法
mockSalaryTaxRule(reqVO.getTaxRuleId());
when(deptApi.getChildDeptList(Collections.singleton(parentDeptId)))
.thenReturn(singletonList(new DeptRespDTO().setId(childDeptId)));
when(deptApi.getChildDeptList(org.mockito.ArgumentMatchers.<Long>anyCollection()))
.thenReturn(success(emptyList()));
when(deptApi.getChildDeptList(org.mockito.ArgumentMatchers.<Collection<Long>>argThat(
ids -> ids.contains(parentDeptId))))
.thenReturn(success(singletonList(new DeptRespDTO().setId(childDeptId))));
// 调用,并断言异常
assertServiceException(() -> salaryGroupService.createSalaryGroup(reqVO),
@@ -132,6 +140,7 @@ public class HrmSalaryGroupServiceImplTest extends BaseDbUnitTest {
HrmSalaryGroupSaveReqVO reqVO = randomSalaryGroupSaveReqVO(o -> o.setId(dbSalaryGroup.getId()));
// mock 方法
mockSalaryTaxRule(reqVO.getTaxRuleId());
when(deptApi.getChildDeptList(anyCollection())).thenReturn(success(emptyList()));
// 调用
salaryGroupService.updateSalaryGroup(reqVO);
@@ -235,8 +244,8 @@ public class HrmSalaryGroupServiceImplTest extends BaseDbUnitTest {
HrmSalaryGroupDO parentSalaryGroup = randomSalaryGroupDO(o -> o
.setDeptIds(singletonList(parentDeptId)).setEmployeeIds(emptyList()));
salaryGroupMapper.insert(parentSalaryGroup);
when(deptApi.getParentDeptList(employeeDeptId)).thenReturn(Arrays.asList(
new DeptRespDTO().setId(parentDeptId), new DeptRespDTO().setId(rootDeptId)));
when(deptApi.getParentDeptList(employeeDeptId)).thenReturn(success(Arrays.asList(
new DeptRespDTO().setId(parentDeptId), new DeptRespDTO().setId(rootDeptId))));
// 调用
Map<Long, HrmSalaryGroupDO> result = salaryGroupService.getEmployeeSalaryGroupMap(