提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.controller.admin.tenant; |
H |
2 |
|
|
3 |
import com.iailab.framework.apilog.core.annotation.ApiAccessLog; |
|
4 |
import com.iailab.framework.common.pojo.CommonResult; |
|
5 |
import com.iailab.framework.common.pojo.PageParam; |
|
6 |
import com.iailab.framework.common.pojo.PageResult; |
|
7 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
8 |
import com.iailab.framework.excel.core.util.ExcelUtils; |
|
9 |
import com.iailab.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; |
|
10 |
import com.iailab.module.system.controller.admin.tenant.vo.tenant.TenantRespVO; |
|
11 |
import com.iailab.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; |
|
12 |
import com.iailab.module.system.controller.admin.tenant.vo.tenant.TenantSimpleRespVO; |
|
13 |
import com.iailab.module.system.dal.dataobject.tenant.TenantDO; |
|
14 |
import com.iailab.module.system.service.tenant.TenantService; |
|
15 |
import io.swagger.v3.oas.annotations.Operation; |
|
16 |
import io.swagger.v3.oas.annotations.Parameter; |
|
17 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
18 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
19 |
import org.springframework.web.bind.annotation.*; |
|
20 |
|
|
21 |
import javax.annotation.Resource; |
|
22 |
import javax.annotation.security.PermitAll; |
|
23 |
import javax.servlet.http.HttpServletResponse; |
|
24 |
import javax.validation.Valid; |
|
25 |
import java.io.IOException; |
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
|
29 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
30 |
|
|
31 |
@Tag(name = "管理后台 - 租户") |
|
32 |
@RestController |
|
33 |
@RequestMapping("/system/tenant") |
|
34 |
public class TenantController { |
|
35 |
|
|
36 |
@Resource |
|
37 |
private TenantService tenantService; |
|
38 |
|
|
39 |
@GetMapping("/get-id-by-name") |
|
40 |
@PermitAll |
|
41 |
@Operation(summary = "使用租户名,获得租户编号", description = "登录界面,根据用户的租户名,获得租户编号") |
|
42 |
@Parameter(name = "name", description = "租户名", required = true, example = "1024") |
|
43 |
public CommonResult<Long> getTenantIdByName(@RequestParam("name") String name) { |
|
44 |
TenantDO tenant = tenantService.getTenantByName(name); |
|
45 |
return success(tenant != null ? tenant.getId() : null); |
|
46 |
} |
|
47 |
|
|
48 |
@GetMapping("/get-by-website") |
|
49 |
@PermitAll |
|
50 |
@Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息") |
|
51 |
@Parameter(name = "website", description = "域名", required = true, example = "www.baidu.com") |
|
52 |
public CommonResult<TenantSimpleRespVO> getTenantByWebsite(@RequestParam("website") String website) { |
|
53 |
TenantDO tenant = tenantService.getTenantByWebsite(website); |
|
54 |
return success(BeanUtils.toBean(tenant, TenantSimpleRespVO.class)); |
|
55 |
} |
|
56 |
|
|
57 |
@PostMapping("/create") |
|
58 |
@Operation(summary = "创建租户") |
|
59 |
@PreAuthorize("@ss.hasPermission('system:tenant:create')") |
|
60 |
public CommonResult<Long> createTenant(@Valid @RequestBody TenantSaveReqVO createReqVO) { |
|
61 |
return success(tenantService.createTenant(createReqVO)); |
|
62 |
} |
|
63 |
|
|
64 |
@PutMapping("/update") |
|
65 |
@Operation(summary = "更新租户") |
|
66 |
@PreAuthorize("@ss.hasPermission('system:tenant:update')") |
|
67 |
public CommonResult<Boolean> updateTenant(@Valid @RequestBody TenantSaveReqVO updateReqVO) { |
|
68 |
tenantService.updateTenant(updateReqVO); |
|
69 |
return success(true); |
|
70 |
} |
|
71 |
|
|
72 |
@DeleteMapping("/delete") |
|
73 |
@Operation(summary = "删除租户") |
|
74 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
75 |
@PreAuthorize("@ss.hasPermission('system:tenant:delete')") |
|
76 |
public CommonResult<Boolean> deleteTenant(@RequestParam("id") Long id) { |
|
77 |
tenantService.deleteTenant(id); |
|
78 |
return success(true); |
|
79 |
} |
|
80 |
|
|
81 |
@GetMapping("/get") |
|
82 |
@Operation(summary = "获得租户") |
|
83 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
84 |
@PreAuthorize("@ss.hasPermission('system:tenant:query')") |
|
85 |
public CommonResult<TenantRespVO> getTenant(@RequestParam("id") Long id) { |
|
86 |
TenantDO tenant = tenantService.getTenant(id); |
|
87 |
return success(BeanUtils.toBean(tenant, TenantRespVO.class)); |
|
88 |
} |
|
89 |
|
|
90 |
@GetMapping("/page") |
|
91 |
@Operation(summary = "获得租户分页") |
|
92 |
@PreAuthorize("@ss.hasPermission('system:tenant:query')") |
|
93 |
public CommonResult<PageResult<TenantRespVO>> getTenantPage(@Valid TenantPageReqVO pageVO) { |
|
94 |
PageResult<TenantDO> pageResult = tenantService.getTenantPage(pageVO); |
|
95 |
return success(BeanUtils.toBean(pageResult, TenantRespVO.class)); |
|
96 |
} |
|
97 |
|
|
98 |
@GetMapping("/export-excel") |
|
99 |
@Operation(summary = "导出租户 Excel") |
|
100 |
@PreAuthorize("@ss.hasPermission('system:tenant:export')") |
|
101 |
@ApiAccessLog(operateType = EXPORT) |
|
102 |
public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO, |
|
103 |
HttpServletResponse response) throws IOException { |
|
104 |
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
105 |
List<TenantDO> list = tenantService.getTenantPage(exportReqVO).getList(); |
|
106 |
// 导出 Excel |
|
107 |
ExcelUtils.write(response, "租户.xls", "数据", TenantRespVO.class, |
|
108 |
BeanUtils.toBean(list, TenantRespVO.class)); |
|
109 |
} |
|
110 |
|
|
111 |
} |