liyong
9 天以前 88e384da863bb2f7324cb1e1474885df3b7cce91
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
package cn.iocoder.yudao.module.hrm.controller.admin.approval;
 
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.hrm.controller.admin.approval.vo.HrmLeaveApplicationPageReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.approval.vo.HrmLeaveApplicationRespVO;
import cn.iocoder.yudao.module.hrm.controller.admin.approval.vo.HrmLeaveApplicationSaveReqVO;
import cn.iocoder.yudao.module.hrm.service.approval.HrmLeaveApplicationService;
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.servlet.http.HttpServletResponse;
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.io.IOException;
import java.util.List;
import java.util.Map;
 
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - HRM 请假申请")
@RestController
@RequestMapping("/hrm/leave")
@Validated
public class HrmLeaveApplicationController {
 
    @Resource
    private HrmLeaveApplicationService leaveApplicationService;
 
    @PostMapping("/create")
    @Operation(summary = "创建请假申请")
    @PreAuthorize("@ss.hasPermission('hrm:leave:create')")
    public CommonResult<Long> createLeaveApplication(@Valid @RequestBody HrmLeaveApplicationSaveReqVO createReqVO) {
        return success(leaveApplicationService.createLeaveApplication(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新请假申请")
    @PreAuthorize("@ss.hasPermission('hrm:leave:update')")
    public CommonResult<Boolean> updateLeaveApplication(@Valid @RequestBody HrmLeaveApplicationSaveReqVO updateReqVO) {
        leaveApplicationService.updateLeaveApplication(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除请假申请")
    @Parameter(name = "id", description = "申请ID", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:leave:delete')")
    public CommonResult<Boolean> deleteLeaveApplication(@RequestParam("id") Long id) {
        leaveApplicationService.deleteLeaveApplication(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得请假申请详情")
    @Parameter(name = "id", description = "申请ID", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:leave:query')")
    public CommonResult<HrmLeaveApplicationRespVO> getLeaveApplication(@RequestParam("id") Long id) {
        return success(leaveApplicationService.getLeaveApplicationDetail(id));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得请假申请分页")
    @PreAuthorize("@ss.hasPermission('hrm:leave:query')")
    public CommonResult<PageResult<HrmLeaveApplicationRespVO>> getLeaveApplicationPage(@Valid HrmLeaveApplicationPageReqVO pageReqVO) {
        return success(leaveApplicationService.getLeaveApplicationPage(pageReqVO));
    }
 
    @PostMapping("/submit")
    @Operation(summary = "提交请假申请审批")
    @Parameter(name = "id", description = "申请ID", required = true)
    @Parameter(name = "processDefinitionKey", description = "流程定义Key", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:leave:submit')")
    public CommonResult<Boolean> submitLeaveApplication(@RequestParam("id") Long id,
                                                         @RequestParam("processDefinitionKey") String processDefinitionKey) {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        leaveApplicationService.submitLeaveApplication(id, processDefinitionKey, userId);
        return success(true);
    }
 
    @GetMapping("/approve-process-definition-list")
    @Operation(summary = "获取可用的审批流程定义列表")
    @PreAuthorize("@ss.hasPermission('hrm:leave:query')")
    public CommonResult<List<Map<String, Object>>> getApproveProcessDefinitionList() {
        return success(leaveApplicationService.getApproveProcessDefinitionList());
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出请假申请 Excel")
    @PreAuthorize("@ss.hasPermission('hrm:leave:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportLeaveApplicationExcel(@Valid HrmLeaveApplicationPageReqVO pageReqVO,
                                             HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<HrmLeaveApplicationRespVO> list = leaveApplicationService.getLeaveApplicationPage(pageReqVO).getList();
        ExcelUtils.write(response, "请假申请.xls", "数据",
                HrmLeaveApplicationRespVO.class, list);
    }
 
}