|
|
@@ -6,10 +6,15 @@ import java.util.Map;
|
|
|
import com.fs.common.annotation.Log;
|
|
|
import com.fs.common.core.controller.BaseController;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.domain.entity.SysMenu;
|
|
|
+import com.fs.common.core.domain.entity.TenantCompanyMenu;
|
|
|
import com.fs.common.core.domain.model.LoginUser;
|
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
|
import com.fs.common.enums.BusinessType;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
+import com.fs.framework.datasource.TenantDataSourceContextHelper;
|
|
|
+import com.fs.framework.datasource.TenantDataSourceManager;
|
|
|
import com.fs.proxy.domain.Proxy;
|
|
|
import com.fs.proxy.domain.ProxyServicePrice;
|
|
|
import com.fs.proxy.domain.ProxyWithdraw;
|
|
|
@@ -18,11 +23,14 @@ import com.fs.proxy.service.ProxyService;
|
|
|
import com.fs.proxy.service.ProxyServicePriceService;
|
|
|
import com.fs.proxy.service.ProxyWithdrawService;
|
|
|
import com.fs.tenant.domain.TenantInfo;
|
|
|
+import com.fs.tenant.mapper.TenantInfoMapper;
|
|
|
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.util.ArrayList;
|
|
|
+
|
|
|
@RestController
|
|
|
@RequestMapping("/proxy")
|
|
|
public class ProxyController extends BaseController
|
|
|
@@ -42,6 +50,15 @@ public class ProxyController extends BaseController
|
|
|
@Autowired
|
|
|
private TenantInfoService tenantInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TenantInfoMapper tenantInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TenantDataSourceManager tenantDataSourceManager;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TenantDataSourceContextHelper tenantContextHelper;
|
|
|
+
|
|
|
@PreAuthorize("@ss.hasPermi('proxy:dashboard:view')")
|
|
|
@GetMapping("/dashboard")
|
|
|
public AjaxResult getDashboard() {
|
|
|
@@ -232,6 +249,108 @@ public class ProxyController extends BaseController
|
|
|
return AjaxResult.success(count);
|
|
|
}
|
|
|
|
|
|
+ // ==================== 租户菜单管理 ====================
|
|
|
+
|
|
|
+ @PreAuthorize("@ss.hasPermi('proxy:tenant:menu')")
|
|
|
+ @PostMapping("/tenants/{id}/menu")
|
|
|
+ public R tenantMenuChange(@PathVariable String id, @RequestBody Map<String, String> params) {
|
|
|
+ tenantDataSourceManager.clear();
|
|
|
+ Long proxyId = getCurrentProxyId();
|
|
|
+ String flag = params.getOrDefault("flag", "sys");
|
|
|
+ try {
|
|
|
+ TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(id);
|
|
|
+ if (tenantInfo == null) return R.error("租户不存在");
|
|
|
+ if (!proxyId.equals(tenantInfo.getProxyId())) return R.error("无权操作该租户");
|
|
|
+ if (tenantInfo.getStatus() != null && tenantInfo.getStatus() == 2) return R.error("租户初始化中");
|
|
|
+
|
|
|
+ if ("sys".equals(flag)) {
|
|
|
+ List<SysMenu> sysMenus = tenantInfoMapper.selectMenuList(new SysMenu());
|
|
|
+ tenantDataSourceManager.switchTenant(tenantInfo);
|
|
|
+ return tenantInfoService.menuChange(flag, sysMenus, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TenantCompanyMenu> companyMenus = tenantInfoMapper.selectCompanyMenuList(new TenantCompanyMenu());
|
|
|
+ tenantDataSourceManager.switchTenant(tenantInfo);
|
|
|
+ return tenantInfoService.menuChange(flag, null, companyMenus);
|
|
|
+ } finally {
|
|
|
+ tenantDataSourceManager.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PreAuthorize("@ss.hasPermi('proxy:tenant:menu')")
|
|
|
+ @Log(title = "编辑租户菜单", businessType = BusinessType.UPDATE)
|
|
|
+ @PostMapping("/tenants/{id}/menu/edit")
|
|
|
+ public R tenantMenuEdit(@PathVariable String id, @RequestBody Map<String, Object> params) {
|
|
|
+ String flag = (String) params.getOrDefault("flag", "sys");
|
|
|
+ List<Long> selected = toLongList(params.get("selected"));
|
|
|
+ Long proxyId = getCurrentProxyId();
|
|
|
+
|
|
|
+ TenantInfo tenantInfo = tenantContextHelper.executeInMaster(() -> tenantInfoMapper.selectTenantInfoById(id));
|
|
|
+ if (tenantInfo == null) return R.error("租户不存在");
|
|
|
+ if (!proxyId.equals(tenantInfo.getProxyId())) return R.error("无权操作该租户");
|
|
|
+ if (tenantInfo.getStatus() != null && tenantInfo.getStatus() == 2) return R.error("租户初始化中");
|
|
|
+
|
|
|
+ if ("sys".equals(flag)) {
|
|
|
+ List<SysMenu> allTemplateMenus = tenantContextHelper.executeInMaster(
|
|
|
+ () -> tenantInfoMapper.selectMenuList(new SysMenu()));
|
|
|
+ List<Long> expandedSelected = tenantInfoService.expandSysMenuIdsWithAncestors(selected, allTemplateMenus);
|
|
|
+ List<SysMenu> assignSysMenu = tenantContextHelper.executeInMaster(
|
|
|
+ () -> loadMasterSysMenus(expandedSelected));
|
|
|
+ List<Long> finalSelected = expandedSelected;
|
|
|
+ return tenantContextHelper.executeInTenant(tenantInfo,
|
|
|
+ () -> tenantInfoService.menuAssignReplace(finalSelected, flag, assignSysMenu, null));
|
|
|
+ }
|
|
|
+ List<TenantCompanyMenu> allTemplateMenus = tenantContextHelper.executeInMaster(
|
|
|
+ () -> tenantInfoMapper.selectCompanyMenuList(new TenantCompanyMenu()));
|
|
|
+ List<Long> expandedSelected = tenantInfoService.expandComMenuIdsWithAncestors(selected, allTemplateMenus);
|
|
|
+ List<TenantCompanyMenu> assignCompanyMenu = tenantContextHelper.executeInMaster(
|
|
|
+ () -> loadMasterCompanyMenus(expandedSelected));
|
|
|
+ List<Long> finalSelected = expandedSelected;
|
|
|
+ return tenantContextHelper.executeInTenant(tenantInfo,
|
|
|
+ () -> tenantInfoService.menuAssignReplace(finalSelected, flag, null, assignCompanyMenu));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SysMenu> loadMasterSysMenus(List<Long> selected) {
|
|
|
+ if (selected == null || selected.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return tenantInfoMapper.getTenSysMenuByIds(selected);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TenantCompanyMenu> loadMasterCompanyMenus(List<Long> selected) {
|
|
|
+ if (selected == null || selected.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return tenantInfoMapper.getTenComMenuByIds(selected);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Long> toLongList(Object raw) {
|
|
|
+ if (raw == null || !(raw instanceof List)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<?> list = (List<?>) raw;
|
|
|
+ List<Long> result = new ArrayList<>(list.size());
|
|
|
+ for (Object item : list) {
|
|
|
+ Long id = toLongId(item);
|
|
|
+ if (id != null) {
|
|
|
+ result.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Long toLongId(Object value) {
|
|
|
+ if (value == null) return null;
|
|
|
+ if (value instanceof Long) return (Long) value;
|
|
|
+ if (value instanceof Number) return ((Number) value).longValue();
|
|
|
+ if (value instanceof String) {
|
|
|
+ String s = ((String) value).trim();
|
|
|
+ if (s.isEmpty()) return null;
|
|
|
+ return Long.parseLong(s);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private Long getCurrentProxyId() {
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
if (loginUser != null && loginUser.getProxyId() != null) {
|