yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.system.controller;
 
import java.util.List;
import java.util.Map;
 
import javax.validation.Valid;
 
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
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.support.Kv;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.cache.DictCache;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.smartman.common.enums.DictEnum;
import com.qianwen.smartman.modules.system.entity.Dept;
import com.qianwen.smartman.modules.system.service.IDataScopeManagerService;
import com.qianwen.smartman.modules.system.vo.DataScopeGrantVO;
import com.qianwen.smartman.modules.system.vo.DeptVO;
import com.qianwen.smartman.modules.system.wrapper.DeptWrapper;
 
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 springfox.documentation.annotations.ApiIgnore;
 
@Api(value = "数据权限", tags = {"数据权限"})
@RestController
@ApiResource({"blade-system/data-scope-manager"})
@NonDS
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/controller/DataScopeManagerController.class */
public class DataScopeManagerController extends BladeController {
    private final IDataScopeManagerService dataScopeManagerService;
 
 
    public DataScopeManagerController(final IDataScopeManagerService dataScopeManagerService) {
        this.dataScopeManagerService = dataScopeManagerService;
    }
 
    @ApiOperationSupport(order = 1)
    @ApiLog("数据权限详情")
    @GetResource({"/detail"})
    @ApiOperation(value = "详情", notes = "传入dept")
    public R<DeptVO> detail(Dept dept) {
        Dept detail = (Dept) this.dataScopeManagerService.getOne(Condition.getQueryWrapper(dept));
        return R.data(DeptWrapper.build().entityVO(detail));
    }
 
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "deptName", value = "数据权限名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "fullName", value = "数据权限全称", paramType = "query", dataType = "string")})
    @ApiLog("数据权限列表")
    @GetResource({"/list"})
    @ApiOperation(value = "列表", notes = "传入dept")
    public R<List<DeptVO>> list(@RequestParam @ApiIgnore Map<String, Object> dept, BladeUser bladeUser) {
        QueryWrapper<Dept> queryWrapper = Condition.getQueryWrapper(dept, Dept.class);
        
        if (!bladeUser.getTenantId().equals("000000")) {
            queryWrapper.lambda().eq(Dept::getTenantId, bladeUser.getTenantId()).orderByAsc(Dept::getSort);
        } else {
            queryWrapper.lambda().orderByAsc(Dept::getSort);
        }
        
        /*
        Wrapper wrapper;
        QueryWrapper<Dept> queryWrapper = Condition.getQueryWrapper(dept, Dept.class);
        IDataScopeManagerService iDataScopeManagerService = this.dataScopeManagerService;
        if (!bladeUser.getTenantId().equals("000000")) {
            wrapper = (Wrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq((v0) -> {
                return v0.getTenantId();
            }, bladeUser.getTenantId())).orderByAsc((v0) -> {
                return v0.getSort();
            });
        } else {
            wrapper = (Wrapper) queryWrapper.lambda().orderByAsc((v0) -> {
                return v0.getSort();
            });
        }*/
        List<Dept> list = dataScopeManagerService.list(queryWrapper);
        return R.data(DeptWrapper.build().listNodeVO(list));
    }
 
    @ApiOperationSupport(order = 3)
    @ApiImplicitParams({@ApiImplicitParam(name = "deptName", value = "数据权限名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "fullName", value = "数据权限全称", paramType = "query", dataType = "string")})
    @ApiLog("数据权限列表")
    @GetResource({"/lazy-list"})
    @ApiOperation(value = "懒加载列表", notes = "传入dept")
    public R<List<DeptVO>> lazyList(@RequestParam @ApiIgnore Map<String, Object> dept, Long parentId, BladeUser bladeUser) {
        List<DeptVO> list = this.dataScopeManagerService.lazyList(bladeUser.getTenantId(), parentId, dept);
        return R.data(DeptWrapper.build().listNodeLazyVO(list));
    }
 
    @ApiOperationSupport(order = 4)
    @ApiLog("获取数据权限树形结构")
    @GetResource({"/tree"})
    @ApiOperation(value = "树形结构", notes = "树形结构")
    public R<List<DeptVO>> tree(String tenantId, BladeUser bladeUser) {
        List<DeptVO> tree = this.dataScopeManagerService.tree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()));
        return R.data(tree);
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @ApiLog("懒加载获取数据权限树形结构")
    @GetResource({"/lazy-tree"})
    @ApiOperation(value = "懒加载树形结构", notes = "树形结构")
    public R<List<DeptVO>> lazyTree(String tenantId, Long parentId, BladeUser bladeUser) {
        List<DeptVO> tree = this.dataScopeManagerService.lazyTree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()), parentId);
        return R.data(tree);
    }
 
    @ApiOperationSupport(order = 6)
    @PostResource({"/submit"})
    @ApiLog("新增或修改数据权限")
    @ApiOperation(value = "新增或修改", notes = "传入dept")
    public R submit(@Valid @RequestBody Dept dept) {
        if (this.dataScopeManagerService.submit(dept)) {
            CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
            Kv kv = Kv.create().set("id", String.valueOf(dept.getId())).set("tenantId", dept.getTenantId()).set("deptCategoryName", DictCache.getValue(DictEnum.DATA_SCOPE_CATEGORY, dept.getDeptCategory()));
            return R.data(kv);
        }
        return R.fail("操作失败");
    }
 
    @ApiOperationSupport(order = 7)
    @PostResource({"/remove"})
    @ApiLog("删除数据权限")
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(@RequestParam @ApiParam(value = "主键集合", required = true) String ids) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        return R.status(this.dataScopeManagerService.removeDept(ids));
    }
 
    @ApiOperationSupport(order = 8)
    @GetResource({"/select"})
    @ApiOperation(value = "下拉数据源", notes = "传入id集合")
    @PreAuth("permitAll()")
    public R<List<Dept>> select(String deptId) {
        List<Dept> list = this.dataScopeManagerService.list(Wrappers.<Dept>lambdaQuery().in(Dept::getId, Func.toLongList(deptId)));
        /*
        List<Dept> list = this.dataScopeManagerService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, Func.toLongList(deptId)));*/
        return R.data(list);
    }
 
    @GetResource({"/grant-select"})
    @ApiOperation("选中的权限")
    public R<List<String>> grantSelect(String deptId) {
        return R.data(this.dataScopeManagerService.grantSelect(deptId));
    }
 
    @PostResource({"/grant"})
    @ApiOperation("设置数据权限")
    public R<Boolean> grant(@RequestBody DataScopeGrantVO grantVO) {
        CacheUtil.clear("blade:sys");
        CacheUtil.clear("blade:sys", Boolean.FALSE);
        this.dataScopeManagerService.grant(grantVO);
        return R.status(true);
    }
}