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);
|
}
|
}
|