yangys
2024-04-01 86cdd920b68274185233383f69ddb974052b6b6f
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
package com.qianwen.smartman.modules.system.controller;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import javax.validation.Valid;
 
import org.smartboot.license.client.LicenseException;
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.metadata.IPage;
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.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
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.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.RegionCache;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.LicenseUtil;
import com.qianwen.smartman.modules.system.entity.Tenant;
import com.qianwen.smartman.modules.system.service.ITenantService;
 
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/tenant"})
@NonDS
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/controller/TenantController.class */
public class TenantController extends BladeController {
    private final ITenantService tenantService;
 
    
 
    public TenantController(final ITenantService tenantService) {
        this.tenantService = tenantService;
    }
 
    @ApiOperationSupport(order = 1)
    @GetResource({"/detail"})
    @ApiOperation(value = "详情", notes = "传入tenant")
    public R<Tenant> detail(Tenant tenant) {
        Tenant detail = (Tenant) this.tenantService.getOne(Condition.getQueryWrapper(tenant));
        return R.data(detail);
    }
 
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "tenantId", value = "参数名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "tenantName", value = "角色别名", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "contactNumber", value = "联系电话", paramType = "query", dataType = "string")})
    @GetResource({"/list"})
    @ApiOperation(value = "分页", notes = "传入tenant")
    public R<IPage<Tenant>> list(@RequestParam @ApiIgnore Map<String, Object> tenant, Query query, BladeUser bladeUser) {
        //Wrapper queryWrapper = Condition.getQueryWrapper(tenant, Tenant.class);
        QueryWrapper<Tenant> queryWrapper = Condition.getQueryWrapper(tenant, Tenant.class);
        IPage<Tenant> pages = this.tenantService.page(Condition.getPage(query), !bladeUser.getTenantId().equals("000000") ? queryWrapper.lambda().eq(Tenant::getTenantId, bladeUser.getTenantId()) : queryWrapper);
        /*
        IPage<Tenant> pages = this.tenantService.page(Condition.getPage(query), !bladeUser.getTenantId().equals("000000") ? (Wrapper) queryWrapper.lambda().eq((v0) -> {
            return v0.getTenantId();
        }, bladeUser.getTenantId()) : queryWrapper);*/
        return R.data(pages);
    }
 
    @ApiOperationSupport(order = 3)
    @GetResource({"/select"})
    @ApiOperation(value = "下拉数据源", notes = "传入tenant")
    public R<List<Tenant>> select(Tenant tenant, BladeUser bladeUser) {
        QueryWrapper<Tenant> queryWrapper = Condition.getQueryWrapper(tenant);
        List<Tenant> list = this.tenantService.list(!bladeUser.getTenantId().equals("000000") ? queryWrapper.lambda().eq(Tenant::getTenantId, bladeUser.getTenantId()) :queryWrapper);
        /*
        Wrapper queryWrapper = Condition.getQueryWrapper(tenant);
        List<Tenant> list = this.tenantService.list(!bladeUser.getTenantId().equals("000000") ? (Wrapper) queryWrapper.lambda().eq((v0) -> {
            return v0.getTenantId();
        }, bladeUser.getTenantId()) : queryWrapper);*/
        return R.data(list);
    }
 
    @ApiOperationSupport(order = 4)
    @GetResource({"/page"})
    @ApiOperation(value = "分页", notes = "传入tenant")
    public R<IPage<Tenant>> page(Tenant tenant, Query query) {
        IPage<Tenant> pages = this.tenantService.selectTenantPage(Condition.getPage(query), tenant);
        return R.data(pages);
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @PostResource({"/submit"})
    @ApiOperation(value = "新增或修改", notes = "传入tenant")
    public R submit(@Valid @RequestBody Tenant tenant) {
        return R.status(this.tenantService.submitTenant(tenant));
    }
 
    @ApiOperationSupport(order = 6)
    @PostResource({"/remove"})
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@RequestParam @ApiParam(value = "主键集合", required = true) String ids) {
        return R.status(this.tenantService.removeTenant(Func.toLongList(ids)));
    }
 
    @ApiOperationSupport(order = 7)
    @PostResource({"/setting"})
    @ApiOperation(value = "授权配置", notes = "传入ids,accountNumber,expireTime")
    public R setting(@RequestParam @ApiParam(value = "主键集合", required = true) String ids, @ApiParam("账号额度") Integer accountNumber, @ApiParam("过期时间") Date expireTime) {
        return R.status(this.tenantService.setting(accountNumber, expireTime, ids));
    }
 
    @ApiOperationSupport(order = 8)
    @PostResource({"datasource"})
    @ApiOperation(value = "数据源配置", notes = "传入datasource_id")
    public R datasource(@RequestParam @ApiParam(value = "租户ID", required = true) String tenantId, @RequestParam @ApiParam(value = "数据源ID", required = true) Long datasourceId) {
        CacheUtil.evict("blade:datasource", "tenant:exist:", tenantId, Boolean.FALSE);
        
        return R.status(this.tenantService.update(Wrappers.<Tenant>update().lambda().set(Tenant::getDatasourceId, datasourceId).eq(Tenant::getTenantId, tenantId)));
        /*
        return R.status(this.tenantService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
            return v0.getDatasourceId();
        }, datasourceId)).eq((v0) -> {
            return v0.getTenantId();
        }, tenantId)));*/
    }
 
    @ApiOperationSupport(order = 9)
    @GetResource({"/find-by-name"})
    @ApiOperation(value = "详情", notes = "传入tenant")
    public R<List<Tenant>> findByName(String name) {
        List<Tenant> list = this.tenantService.list(Wrappers.<Tenant>query().lambda().like(Tenant::getTenantName, name));
        /*
        List<Tenant> list = this.tenantService.list((Wrapper) Wrappers.query().lambda().like((v0) -> {
            return v0.getTenantName();
        }, name));*/
        return R.data(list);
    }
 
    @ApiOperationSupport(order = 10)
    @GetResource({"/info"})
    @ApiOperation(value = "配置信息", notes = "传入domain")
    public R<Kv> info(String domain) {
        Tenant tenant = (Tenant) this.tenantService.getOne(Lambda.eq((v0) -> {
            return v0.getTenantId();
        }, "000000"));
        Kv kv = Kv.create();
        if (tenant != null) {
            kv.set("tenantId", tenant.getTenantId()).set("domain", tenant.getDomainName()).set("backgroundUrl", tenant.getBackgroundUrl()).set("identify", LicenseUtil.getMac());
        }
        try {
            LicenseUtil.loadLicense("000000");
            kv.set("license", true);
        } catch (LicenseException e) {
            kv.set("license", false);
        }
        return R.data(kv);
    }
}