|
|
@@ -7,35 +7,35 @@ import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
|
import com.fs.common.enums.BusinessType;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
-import com.fs.company.domain.Company;
|
|
|
-import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.tenant.domain.TenantInfo;
|
|
|
+import com.fs.tenant.service.TenantInfoService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * 总后台租户管理控制器
|
|
|
- * 管理所有租户,包括禁用启用租户
|
|
|
+ * 总后台租户管理控制器(SaaS 多租户版)
|
|
|
+ * 查询 tenant_info 表,不再查询 company 表
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/admin/company")
|
|
|
public class CompanyAdminController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
- private ICompanyService companyService;
|
|
|
+ private TenantInfoService tenantInfoService;
|
|
|
|
|
|
/**
|
|
|
* 查询所有租户列表
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:list')")
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo list(Company company) {
|
|
|
+ public TableDataInfo list(TenantInfo tenantInfo) {
|
|
|
startPage();
|
|
|
- List<Company> list = companyService.selectCompanyListWithStats(company);
|
|
|
+ List<TenantInfo> list = tenantInfoService.selectTenantInfoList(tenantInfo);
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
@@ -45,9 +45,9 @@ public class CompanyAdminController extends BaseController {
|
|
|
@Log(title = "导出租户列表", businessType = BusinessType.EXPORT)
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:list')")
|
|
|
@GetMapping("/export")
|
|
|
- public AjaxResult export(Company company) {
|
|
|
- List<Company> list = companyService.selectCompanyList(company);
|
|
|
- ExcelUtil<Company> util = new ExcelUtil<>(Company.class);
|
|
|
+ public AjaxResult export(TenantInfo tenantInfo) {
|
|
|
+ List<TenantInfo> list = tenantInfoService.selectTenantInfoList(tenantInfo);
|
|
|
+ ExcelUtil<TenantInfo> util = new ExcelUtil<>(TenantInfo.class);
|
|
|
return util.exportExcel(list, "租户列表数据");
|
|
|
}
|
|
|
|
|
|
@@ -55,9 +55,9 @@ public class CompanyAdminController extends BaseController {
|
|
|
* 获取租户详细信息
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:query')")
|
|
|
- @GetMapping(value = "/{companyId}")
|
|
|
- public AjaxResult getInfo(@PathVariable("companyId") Long companyId) {
|
|
|
- return AjaxResult.success(companyService.selectCompanyById(companyId));
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") String id) {
|
|
|
+ return AjaxResult.success(tenantInfoService.selectTenantInfoById(id));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -66,9 +66,9 @@ public class CompanyAdminController extends BaseController {
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:add')")
|
|
|
@Log(title = "租户管理", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
- public AjaxResult add(@RequestBody Company company) {
|
|
|
- companyService.insertCompany(company);
|
|
|
- return AjaxResult.success();
|
|
|
+ public R add(@RequestBody TenantInfo tenantInfo) {
|
|
|
+ int i = tenantInfoService.insertTenantInfo(tenantInfo);
|
|
|
+ return i > 0 ? R.ok("租户数据库初始化中,请稍后") : R.error("租户创建失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -77,8 +77,8 @@ public class CompanyAdminController extends BaseController {
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:edit')")
|
|
|
@Log(title = "租户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult edit(@RequestBody Company company) {
|
|
|
- return toAjax(companyService.updateCompany(company));
|
|
|
+ public AjaxResult edit(@RequestBody TenantInfo tenantInfo) {
|
|
|
+ return toAjax(tenantInfoService.updateTenantInfo(tenantInfo));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -86,9 +86,9 @@ public class CompanyAdminController extends BaseController {
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:remove')")
|
|
|
@Log(title = "租户管理", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{companyIds}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] companyIds) {
|
|
|
- return toAjax(companyService.deleteCompanyByIds(companyIds));
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable String[] ids) {
|
|
|
+ return toAjax(tenantInfoService.deleteTenantInfoByIds(ids));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -96,12 +96,12 @@ public class CompanyAdminController extends BaseController {
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:edit')")
|
|
|
@Log(title = "租户管理", businessType = BusinessType.UPDATE)
|
|
|
- @PutMapping("/status/{companyId}")
|
|
|
- public AjaxResult changeStatus(@PathVariable Long companyId, @RequestParam Integer status) {
|
|
|
- Company company = new Company();
|
|
|
- company.setCompanyId(companyId);
|
|
|
- company.setStatus(status);
|
|
|
- return toAjax(companyService.updateCompany(company));
|
|
|
+ @PutMapping("/status/{id}")
|
|
|
+ public AjaxResult changeStatus(@PathVariable String id, @RequestParam Integer status) {
|
|
|
+ TenantInfo tenantInfo = new TenantInfo();
|
|
|
+ tenantInfo.setId(Long.valueOf(id));
|
|
|
+ tenantInfo.setStatus(status);
|
|
|
+ return toAjax(tenantInfoService.updateTenantInfo(tenantInfo));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -110,9 +110,9 @@ public class CompanyAdminController extends BaseController {
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:query')")
|
|
|
@GetMapping("/options")
|
|
|
public AjaxResult getOptions() {
|
|
|
- Company company = new Company();
|
|
|
- company.setStatus(1);
|
|
|
- List<Company> list = companyService.selectCompanyList(company);
|
|
|
+ TenantInfo tenantInfo = new TenantInfo();
|
|
|
+ tenantInfo.setStatus(1);
|
|
|
+ List<TenantInfo> list = tenantInfoService.selectTenantInfoList(tenantInfo);
|
|
|
return AjaxResult.success(list);
|
|
|
}
|
|
|
|
|
|
@@ -122,10 +122,10 @@ public class CompanyAdminController extends BaseController {
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:query')")
|
|
|
@GetMapping("/statistics")
|
|
|
public AjaxResult statistics() {
|
|
|
- Company company = new Company();
|
|
|
- List<Company> all = companyService.selectCompanyList(company);
|
|
|
- long activeCount = all.stream().filter(c -> c.getStatus() != null && c.getStatus() == 1).count();
|
|
|
- java.util.Map<String, Object> result = new java.util.HashMap<>();
|
|
|
+ TenantInfo tenantInfo = new TenantInfo();
|
|
|
+ List<TenantInfo> all = tenantInfoService.selectTenantInfoList(tenantInfo);
|
|
|
+ long activeCount = all.stream().filter(t -> t.getStatus() != null && t.getStatus() == 1).count();
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
result.put("totalCount", all.size());
|
|
|
result.put("activeCount", activeCount);
|
|
|
result.put("disabledCount", all.size() - activeCount);
|
|
|
@@ -134,22 +134,13 @@ public class CompanyAdminController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 租户充值/扣款
|
|
|
+ * TODO 后续优化:需要切到租户库查询 company 表余额并操作充值/扣款
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('admin:company:edit')")
|
|
|
@Log(title = "租户管理", businessType = BusinessType.UPDATE)
|
|
|
- @PostMapping("/{companyId}/recharge")
|
|
|
- public AjaxResult rechargeCompany(@PathVariable Long companyId, @RequestBody Map<String, Object> params) {
|
|
|
- String operateType = (String) params.get("operateType");
|
|
|
- BigDecimal amount = null;
|
|
|
- Object amountObj = params.get("amount");
|
|
|
- if (amountObj != null) {
|
|
|
- amount = new BigDecimal(amountObj.toString());
|
|
|
- }
|
|
|
- String remark = (String) params.get("remark");
|
|
|
- R r = companyService.rechargeCompany(companyId, operateType, amount, remark);
|
|
|
- if (r != null && Integer.valueOf(200).equals(r.get("code"))) {
|
|
|
- return AjaxResult.success();
|
|
|
- }
|
|
|
- return AjaxResult.error(r != null ? (String) r.get("msg") : "操作失败");
|
|
|
+ @PostMapping("/{id}/recharge")
|
|
|
+ public AjaxResult rechargeCompany(@PathVariable String id, @RequestBody Map<String, Object> params) {
|
|
|
+ // TODO 后续优化:切到租户库执行充值/扣款逻辑
|
|
|
+ return AjaxResult.error("充值/扣款功能暂未对接多租户,后续优化");
|
|
|
}
|
|
|
-}
|
|
|
+}
|