| | |
| | | import cn.iocoder.yudao.module.hrm.service.salary.HrmSalaryCalculationService; |
| | | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| | | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.SALARY_CALCULATION_NOT_EXISTS; |
| | | |
| | | @Tag(name = "管理后台 - HRM 薪酬核算") |
| | | @RestController |
| | |
| | | private HrmEmployeeService employeeService; |
| | | @Resource |
| | | private DeptApi deptApi; |
| | | |
| | | @GetMapping("/my-page") |
| | | @Operation(summary = "获得我的薪资核算分页") |
| | | public CommonResult<PageResult<HrmSalaryCalculationRespVO>> getMySalaryCalculationPage(@Valid HrmSalaryCalculationPageReqVO pageReqVO) { |
| | | // 只查当前登录人自己的薪资,无需薪酬查询权限,登录即可访问 |
| | | PageResult<HrmSalaryCalculationDO> pageResult = salaryCalculationService |
| | | .getMySalaryCalculationPage(SecurityFrameworkUtils.getLoginUserId(), pageReqVO); |
| | | List<HrmSalaryCalculationRespVO> list = BeanUtils.toBean(pageResult.getList(), HrmSalaryCalculationRespVO.class); |
| | | return success(new PageResult<>(list, pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/my-get") |
| | | @Operation(summary = "获得我的薪资核算") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | public CommonResult<HrmSalaryCalculationRespVO> getMySalaryCalculation(@RequestParam("id") Long id) { |
| | | HrmSalaryCalculationDO calculation = salaryCalculationService |
| | | .getMySalaryCalculation(id, SecurityFrameworkUtils.getLoginUserId()); |
| | | // 记录不存在、或不属于当前登录人时统一返回“不存在”,避免泄露他人薪资是否存在 |
| | | if (calculation == null) { |
| | | throw exception(SALARY_CALCULATION_NOT_EXISTS); |
| | | } |
| | | return success(BeanUtils.toBean(calculation, HrmSalaryCalculationRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得薪酬核算分页") |
| | |
| | | * 填充员工和部门信息(userId 是员工ID) |
| | | */ |
| | | private void fillUserInfo(List<HrmSalaryCalculationRespVO> respList, List<HrmSalaryCalculationDO> calculationList) { |
| | | // userId 是员工ID,批量获取员工信息 |
| | | Set<Long> employeeIds = calculationList.stream() |
| | | // 注意:核算记录的 userId 存的是「系统账号 ID」(system_users.id), |
| | | // 不是员工档案主键(hrm_employee.id)。用 getEmployee 会永远查不到, |
| | | // 导致列表里「员工姓名」一列全空。必须用 getEmployeeByUserId。 |
| | | Set<Long> userIds = calculationList.stream() |
| | | .map(HrmSalaryCalculationDO::getUserId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, HrmEmployeeDO> employeeMap = new HashMap<>(); |
| | | for (Long employeeId : employeeIds) { |
| | | HrmEmployeeDO employee = employeeService.getEmployee(employeeId); |
| | | for (Long userId : userIds) { |
| | | HrmEmployeeDO employee = employeeService.getEmployeeByUserId(userId); |
| | | if (employee != null) { |
| | | employeeMap.put(employeeId, employee); |
| | | employeeMap.put(userId, employee); |
| | | } |
| | | } |
| | | |
| | |
| | | return success(null); |
| | | } |
| | | HrmSalaryCalculationRespVO respVO = BeanUtils.toBean(salaryCalculation, HrmSalaryCalculationRespVO.class); |
| | | // 填充员工和部门信息(userId 是员工ID) |
| | | // 填充员工和部门信息 |
| | | // 注意:核算记录的 userId 存的是「系统账号 ID」(system_users.id), |
| | | // 不是员工档案主键(hrm_employee.id),必须用 getEmployeeByUserId 查 |
| | | if (salaryCalculation.getUserId() != null) { |
| | | HrmEmployeeDO employee = employeeService.getEmployee(salaryCalculation.getUserId()); |
| | | HrmEmployeeDO employee = employeeService.getEmployeeByUserId(salaryCalculation.getUserId()); |
| | | if (employee != null) { |
| | | respVO.setUserName(employee.getName()); |
| | | } |