liyong
2026-07-10 80ddf4c9c0bcb0f6c31524e0d9f5599c8001e904
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package cn.iocoder.yudao.module.hrm.controller.admin.salary;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSalaryPaymentDetailPageReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSalaryPaymentDetailRespVO;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSalaryPaymentPageReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSalaryPaymentRespVO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmSalaryPaymentDetailDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmSalaryPaymentDO;
import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService;
import cn.iocoder.yudao.module.hrm.service.salary.HrmSalaryPaymentService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - HRM 薪资发放")
@RestController
@RequestMapping("/hrm/salary/payment")
@Validated
public class HrmSalaryPaymentController {
 
    @Resource
    private HrmSalaryPaymentService salaryPaymentService;
    @Resource
    private HrmEmployeeService employeeService;
    @Resource
    private DeptApi deptApi;
 
    @GetMapping("/page")
    @Operation(summary = "获得薪资发放分页")
    @PreAuthorize("@ss.hasPermission('hrm:salary:query')")
    public CommonResult<PageResult<HrmSalaryPaymentRespVO>> getSalaryPaymentPage(@Valid HrmSalaryPaymentPageReqVO pageReqVO) {
        PageResult<HrmSalaryPaymentDO> pageResult = salaryPaymentService.getSalaryPaymentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, HrmSalaryPaymentRespVO.class));
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得薪资发放")
    @Parameter(name = "id", description = "发放ID", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:salary:query')")
    public CommonResult<HrmSalaryPaymentRespVO> getSalaryPayment(@RequestParam("id") Long id) {
        HrmSalaryPaymentDO salaryPayment = salaryPaymentService.getSalaryPayment(id);
        return success(BeanUtils.toBean(salaryPayment, HrmSalaryPaymentRespVO.class));
    }
 
    @PostMapping("/generate")
    @Operation(summary = "生成薪资发放台账")
    @Parameter(name = "period", description = "核算周期", required = true, example = "2024-01")
    @PreAuthorize("@ss.hasPermission('hrm:salary:generate')")
    public CommonResult<Long> generatePayment(@RequestParam("period") String period) {
        return success(salaryPaymentService.generatePayment(period));
    }
 
    @PostMapping("/pay")
    @Operation(summary = "发放薪资(整个台账)")
    @Parameter(name = "id", description = "发放台账ID", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:salary:pay')")
    public CommonResult<Boolean> paySalary(@RequestParam("id") Long id) {
        salaryPaymentService.paySalary(id);
        return success(true);
    }
 
    @PostMapping("/pay-detail")
    @Operation(summary = "批量发放薪资明细")
    @PreAuthorize("@ss.hasPermission('hrm:salary:pay')")
    public CommonResult<Boolean> paySalaryDetail(@RequestBody Map<String, List<Long>> request) {
        List<Long> detailIds = request.get("detailIds");
        salaryPaymentService.paySalaryDetail(detailIds);
        return success(true);
    }
 
    @PostMapping("/revoke-detail")
    @Operation(summary = "批量撤销薪资发放明细")
    @PreAuthorize("@ss.hasPermission('hrm:salary:pay')")
    public CommonResult<Boolean> revokeSalaryPaymentDetail(@RequestBody Map<String, List<Long>> request) {
        List<Long> detailIds = request.get("detailIds");
        salaryPaymentService.revokeSalaryPaymentDetail(detailIds);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除薪资发放台账")
    @Parameter(name = "id", description = "发放台账ID", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:salary:delete')")
    public CommonResult<Boolean> deleteSalaryPayment(@RequestParam("id") Long id) {
        salaryPaymentService.deleteSalaryPayment(id);
        return success(true);
    }
 
    @GetMapping("/detail/page")
    @Operation(summary = "获得薪资发放明细分页")
    @PreAuthorize("@ss.hasPermission('hrm:salary:query')")
    public CommonResult<PageResult<HrmSalaryPaymentDetailRespVO>> getSalaryPaymentDetailPage(@Valid HrmSalaryPaymentDetailPageReqVO pageReqVO) {
        PageResult<HrmSalaryPaymentDetailDO> pageResult = salaryPaymentService.getSalaryPaymentDetailPage(pageReqVO);
        List<HrmSalaryPaymentDetailRespVO> list = BeanUtils.toBean(pageResult.getList(), HrmSalaryPaymentDetailRespVO.class);
        // 填充员工和部门信息
        if (CollUtil.isNotEmpty(list)) {
            fillUserInfo(list, pageResult.getList());
        }
        return success(new PageResult<>(list, pageResult.getTotal()));
    }
 
    @GetMapping("/detail/list")
    @Operation(summary = "获得薪资发放明细列表")
    @Parameter(name = "paymentId", description = "发放台账ID", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:salary:query')")
    public CommonResult<List<HrmSalaryPaymentDetailRespVO>> getSalaryPaymentDetailList(@RequestParam("paymentId") Long paymentId) {
        List<HrmSalaryPaymentDetailDO> detailList = salaryPaymentService.getSalaryPaymentDetailListByPaymentId(paymentId);
        List<HrmSalaryPaymentDetailRespVO> list = BeanUtils.toBean(detailList, HrmSalaryPaymentDetailRespVO.class);
        // 填充员工和部门信息
        if (CollUtil.isNotEmpty(list)) {
            fillUserInfo(list, detailList);
        }
        return success(list);
    }
 
    /**
     * 填充员工和部门信息
     */
    private void fillUserInfo(List<HrmSalaryPaymentDetailRespVO> respList, List<HrmSalaryPaymentDetailDO> detailList) {
        // 批量获取员工信息
        Set<Long> employeeIds = detailList.stream()
                .map(HrmSalaryPaymentDetailDO::getUserId)
                .filter(Objects::nonNull)
                .collect(Collectors.toSet());
        Map<Long, HrmEmployeeDO> employeeMap = new HashMap<>();
        for (Long employeeId : employeeIds) {
            HrmEmployeeDO employee = employeeService.getEmployee(employeeId);
            if (employee != null) {
                employeeMap.put(employeeId, employee);
            }
        }
        // 批量获取部门信息
        Set<Long> deptIds = detailList.stream()
                .map(HrmSalaryPaymentDetailDO::getDeptId)
                .filter(Objects::nonNull)
                .collect(Collectors.toSet());
        Map<Long, DeptRespDTO> deptMap = CollUtil.isEmpty(deptIds) ? Collections.emptyMap() : deptApi.getDeptMap(deptIds);
 
        // 填充信息
        for (HrmSalaryPaymentDetailRespVO respVO : respList) {
            HrmEmployeeDO employee = employeeMap.get(respVO.getUserId());
            if (employee != null) {
                respVO.setUserName(employee.getName());
            }
            DeptRespDTO dept = deptMap.get(respVO.getDeptId());
            if (dept != null) {
                respVO.setDeptName(dept.getName());
            }
        }
    }
 
}