Explorar o código

平台全局不做租户字段拦截校验

dongxin hai 1 ano
pai
achega
fb8f97f521

+ 1 - 1
commons/src/main/java/com/jzg/aop/aspect/TenantAspect.java

@@ -7,7 +7,7 @@ import org.aspectj.lang.annotation.Aspect;
 import org.springframework.stereotype.Component;
 
 /**
- * 自定义注解切面类
+ * 忽略多租户校验 自定义注解切面类
  *
  * @author dongxin
  */

+ 6 - 0
commons/src/main/java/com/jzg/config/MultiTenantHandler.java

@@ -68,6 +68,12 @@ public class MultiTenantHandler implements TenantLineHandler {
             return true;
         }
 
+        // 平台默认忽略租户数据过滤
+        String system = controller.getUserLoginSystem();
+        if("PLATFORM".equals(system)) {
+            return true;
+        }
+
         // 可以自行增加一些校验比如获取不到用户就直接 return false 之类的。
         List<String> ignoreLoginNames = properties.getIgnoreLoginNames();
         // 忽略指定用户对租户的数据过滤

+ 1 - 0
commons/src/main/java/com/jzg/entity/properties/TenantProperties.java

@@ -38,4 +38,5 @@ public class TenantProperties {
      * 需要排除租户过滤的登录用户名
      */
     private List<String> ignoreLoginNames;
+
 }

+ 1 - 1
gateway/src/main/resources/application.yml

@@ -21,4 +21,4 @@ spring:
         - id: tenant_route
           uri: http://localhost:8084/
           predicates:
-            - Path=/tenant/**
+            - Path=/tenant/**,/dept/**

+ 1 - 1
platform/src/main/java/com/jzg/controller/SysUserController.java

@@ -42,7 +42,7 @@ public class SysUserController extends BaseController {
      * @return
      */
     @GetMapping(value = { "/userGet"})
-    @Operation(summary = "户信息查询")
+    @Operation(summary = "平台用户信息查询")
     public HttpResult userGet(@RequestBody String id) {
         return HttpResult.ok(sysUserService.queryById(id));
     }

+ 3 - 0
platform/src/main/java/com/jzg/entity/po/SysSystem.java

@@ -19,6 +19,9 @@ public class SysSystem extends BaseModel {
     @Schema(description = "租户id")
     private String id;
 
+    @Schema(description = "是否是租户 0-否 1-是")
+    private Integer isTenant;
+
     /** 租户Code */
     @Schema(description = "租户Code")
     private String sysCode;

+ 1 - 1
platform/src/main/java/com/jzg/service/SysSystemService.java

@@ -70,7 +70,7 @@ public interface SysSystemService extends IService<SysSystem> {
      * @param sysId
      * @return
      */
-    public String queryById(String sysId);
+    public SysSystem queryById(String sysId);
 
     /**
      * 租户新增

+ 6 - 3
platform/src/main/java/com/jzg/service/impl/SysSystemServiceImpl.java

@@ -110,20 +110,23 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
                 .eq(StringUtils.isNotEmpty(sysSystemVo.getContactValue()),
                         SysSystem::getContact, sysSystemVo.getContactValue()).or()
                 .eq(StringUtils.isNotEmpty(sysSystemVo.getContactValue()),
-                        SysSystem::getTelephone, sysSystemVo.getContactValue());
+                        SysSystem::getTelephone, sysSystemVo.getContactValue())
+                .eq(SysSystem::getIsTenant, 1);
         Page<SysSystem> sysPage = page(page, wrapper);
         return sysPage;
     }
 
     @Override
-    public String queryById(String sysId) {
-        return "";
+    public SysSystem queryById(String sysId) {
+        return this.baseMapper.selectById(sysId);
     }
 
     @Override
     public boolean sysAdd(SysSystemVo sysSystemVo) {
         SysSystem sysSystem = new SysSystem();
         BeanUtils.copyProperties(sysSystemVo, sysSystem);
+        sysSystem.setIsTenant(1);
+        sysSystem.setAvailable(1);
         this.save(sysSystem);
         /** 初始化租户管理员信息 */
         return this.initAdmin(sysSystem);

+ 11 - 4
tenant/organization/src/main/java/com/jzg/organization/controller/DeptController.java

@@ -1,5 +1,6 @@
 package com.jzg.organization.controller;
 
+import cn.hutool.core.lang.tree.Tree;
 import com.jzg.core.base.BaseController;
 import com.jzg.core.page.HttpResult;
 import com.jzg.organization.entity.po.SysDept;
@@ -7,10 +8,7 @@ import com.jzg.organization.entity.vo.SysDeptVo;
 import com.jzg.organization.service.DeptService;
 import io.swagger.v3.oas.annotations.Operation;
 import jakarta.annotation.Resource;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -62,4 +60,13 @@ public class DeptController extends BaseController {
     }
 
 
+    /**
+     * 获取租户机构树列表
+     */
+    @Operation(summary = "租户机构树形查询")
+    @GetMapping("/deptTree")
+    public HttpResult deptTree(String systemCode) {
+        return HttpResult.ok(deptService.selectDeptTreeList(systemCode));
+    }
+
 }

+ 1 - 0
tenant/organization/src/main/java/com/jzg/organization/service/impl/DeptServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.lang.tree.Tree;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jzg.annotation.IgnoreTenant;
 import com.jzg.core.page.HttpResult;
 import com.jzg.exception.SystemException;
 import com.jzg.organization.entity.po.SysDept;