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
package cn.iocoder.yudao.module.system.controller.admin.approval;
 
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.system.controller.admin.approval.vo.ApprovalConfigPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.approval.vo.ApprovalConfigRespVO;
import cn.iocoder.yudao.module.system.controller.admin.approval.vo.ApprovalConfigSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.approval.ApprovalConfigDO;
import cn.iocoder.yudao.module.system.service.approval.ApprovalConfigService;
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.ArrayList;
import java.util.Set;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 
@Tag(name = "管理后台 - 通用审批配置")
@RestController
@RequestMapping("/system/approval-config")
@Validated
public class ApprovalConfigController {
 
    @Resource
    private ApprovalConfigService approvalConfigService;
 
    @PostMapping("/save")
    @Operation(summary = "保存审批配置(新增或修改),审批人整体覆盖")
    @PreAuthorize("@ss.hasPermission('system:approval-config:update')")
    public CommonResult<Long> saveApprovalConfig(@Valid @RequestBody ApprovalConfigSaveReqVO saveReqVO) {
        return success(approvalConfigService.saveApprovalConfig(saveReqVO));
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除审批配置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:approval-config:update')")
    public CommonResult<Boolean> deleteApprovalConfig(@RequestParam("id") Long id) {
        approvalConfigService.deleteApprovalConfig(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得审批配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('system:approval-config:query')")
    public CommonResult<ApprovalConfigRespVO> getApprovalConfig(@RequestParam("id") Long id) {
        ApprovalConfigDO config = approvalConfigService.getApprovalConfig(id);
        if (config == null) {
            return success(null);
        }
        ApprovalConfigRespVO vo = BeanUtils.toBean(config, ApprovalConfigRespVO.class);
        vo.setUserIds(new ArrayList<>(approvalConfigService.getApproverUserIds(config.getBizType())));
        return success(vo);
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得审批配置分页")
    @PreAuthorize("@ss.hasPermission('system:approval-config:query')")
    public CommonResult<PageResult<ApprovalConfigRespVO>> getApprovalConfigPage(
            @Valid ApprovalConfigPageReqVO pageReqVO) {
        return success(approvalConfigService.getApprovalConfigPage(pageReqVO));
    }
 
    @GetMapping("/approver-ids")
    @Operation(summary = "获得指定业务类型的审批人编号集合")
    @Parameter(name = "bizType", description = "业务类型编码", required = true, example = "purchase_plan_approve")
    @PreAuthorize("@ss.hasPermission('system:approval-config:query')")
    public CommonResult<Set<Long>> getApproverUserIds(@RequestParam("bizType") String bizType) {
        return success(approvalConfigService.getApproverUserIds(bizType));
    }
 
    @GetMapping("/is-approver")
    @Operation(summary = "判断当前登录用户是否为指定业务类型的审批人")
    @Parameter(name = "bizType", description = "业务类型编码", required = true, example = "purchase_plan_approve")
    @PreAuthorize("@ss.hasPermission('system:approval-config:query')")
    public CommonResult<Boolean> isApprover(@RequestParam("bizType") String bizType) {
        Set<Long> approverIds = approvalConfigService.getApproverUserIds(bizType);
        return success(approverIds.contains(getLoginUserId()));
    }
 
}