yangys
2024-03-31 53c8d3e3bd3596132b362f20e52aef380d493a84
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.qianwen.smartman.modules.system.controller;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.lang.invoke.SerializedLambda;
import java.util.List;
import java.util.Map;
import javax.validation.Valid;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.cache.SysCache;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.log.annotation.ApiLog;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.BladeUser;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tenant.annotation.NonDS;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.system.entity.Role;
import com.qianwen.smartman.modules.system.service.IRoleService;
import com.qianwen.smartman.modules.system.vo.GrantVO;
import com.qianwen.smartman.modules.system.vo.RoleVO;
import com.qianwen.smartman.modules.system.wrapper.RoleWrapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
 
@Api(value = "角色", tags = {"角色"})
@RestController
@ApiResource({"blade-system/role"})
@NonDS
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/controller/RoleController.class */
public class RoleController extends BladeController {
    private final IRoleService roleService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -1041904421:
                if (implMethodName.equals("getParentId")) {
                    z = true;
                    break;
                }
                break;
            case -75145708:
                if (implMethodName.equals("getSort")) {
                    z = false;
                    break;
                }
                break;
            case 98245393:
                if (implMethodName.equals("getId")) {
                    z = true;
                    break;
                }
                break;
            case 771206363:
                if (implMethodName.equals("getTenantId")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getSort();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getSort();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getSort();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getParentId();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public RoleController(final IRoleService roleService) {
        this.roleService = roleService;
    }
 
    @ApiOperationSupport(order = 1)
    @ApiLog("角色详情")
    @GetResource({"/detail"})
    @ApiOperation(value = "详情", notes = "传入role")
    public R<RoleVO> detail(Role role) {
        Role detail = (Role) this.roleService.getOne(Condition.getQueryWrapper(role));
        return R.data(RoleWrapper.build().entityVO(detail));
    }
 
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "roleName", value = "参数名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "roleAlias", value = "角色别名", paramType = "query", dataType = "string")})
    @ApiLog("角色列表")
    @GetResource({"/list"})
    @ApiOperation(value = "列表", notes = "传入role")
    public R<List<RoleVO>> list(@RequestParam @ApiIgnore Map<String, Object> role, BladeUser bladeUser) {
        QueryWrapper<Role> queryWrapper = Condition.getQueryWrapper(role, Role.class);
        List<Role> list = this.roleService.list(!bladeUser.getTenantId().equals("000000") ? (Wrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq((v0) -> {
            return v0.getTenantId();
        }, bladeUser.getTenantId())).orderByAsc((v0) -> {
            return v0.getSort();
        }) : (Wrapper) queryWrapper.lambda().orderByAsc((v0) -> {
            return v0.getSort();
        }));
        return R.data(RoleWrapper.build().listNodeVO(list));
    }
 
    @ApiOperationSupport(order = 3)
    @ApiLog("获取角色树形结构")
    @GetResource({"/tree"})
    @ApiOperation(value = "树形结构", notes = "树形结构")
    public R<List<RoleVO>> tree(String tenantId, BladeUser bladeUser) {
        List<RoleVO> tree = this.roleService.tree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()));
        return R.data(tree);
    }
 
    @ApiOperationSupport(order = 4)
    @ApiLog("获取指定角色树形结构")
    @GetResource({"/tree-by-id"})
    @ApiOperation(value = "树形结构", notes = "树形结构")
    public R<List<RoleVO>> treeById(Long roleId, BladeUser bladeUser) {
        Role role = SysCache.getRole(roleId);
        List<RoleVO> tree = this.roleService.tree(Func.notNull(role) ? role.getTenantId() : bladeUser.getTenantId());
        return R.data(tree);
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @PostResource({"/submit"})
    @ApiLog("新增或修改角色")
    @ApiOperation(value = "新增或修改", notes = "传入role")
    @PreAuth
    public R<Role> submit(@Valid @RequestBody Role role) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        return R.data(this.roleService.submit(role));
    }
 
    @ApiOperationSupport(order = 6)
    @PostResource({"/remove"})
    @ApiLog("删除角色")
    @ApiOperation(value = "删除", notes = "传入ids")
    @Transactional(rollbackFor = {Exception.class})
    @PreAuth
    public R remove(@RequestParam @ApiParam(value = "主键集合", required = true) String ids) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        this.roleService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getParentId();
        }, Func.toLongList(ids)));
        return R.status(this.roleService.removeByIds(Func.toLongList(ids)));
    }
 
    @ApiOperationSupport(order = 7)
    @PostResource({"/grant"})
    @ApiLog("设置角色权限")
    @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合")
    @PreAuth
    public R grant(@RequestBody GrantVO grantVO) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        boolean temp = this.roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getDataScopeIds(), grantVO.getApiScopeIds());
        return R.status(temp);
    }
 
    @ApiOperationSupport(order = 8)
    @GetResource({"/select"})
    @ApiOperation(value = "下拉数据源", notes = "传入id集合")
    public R<List<Role>> select(String roleId) {
        List<Role> list = this.roleService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, Func.toLongList(roleId))).orderByAsc((v0) -> {
            return v0.getSort();
        }));
        return R.data(list);
    }
}