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());
|
}
|
}
|
}
|
|
}
|