yh 2 недель назад
Родитель
Сommit
4ad083b115

+ 47 - 2
fs-admin/src/main/java/com/fs/tenant/TenantInfoController.java

@@ -8,14 +8,21 @@ import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.enums.DataSourceType;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.framework.datasource.TenantDataSourceManager;
 import com.fs.tenant.domain.TenantInfo;
+import com.fs.tenant.dto.MenuDto;
+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.Arrays;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * 租户基础信息Controller(SaaS 下租户表仅在主库,强制走主库)
@@ -31,6 +38,11 @@ public class TenantInfoController extends BaseController
     @Autowired
     private TenantInfoService tenantInfoService;
 
+    @Autowired
+    private TenantInfoMapper tenantInfoMapper;
+
+    @Autowired
+    private TenantDataSourceManager tenantDataSourceManager;
     /**
      * 查询租户基础信息列表
      */
@@ -92,7 +104,7 @@ public class TenantInfoController extends BaseController
      * 修改租户基础信息
      */
     @PreAuthorize("@ss.hasPermi('tenant:tenant:edit')")
-    @Log(title = "租户基础信息", businessType = BusinessType.UPDATE)
+    @Log(title = "修改租户基础信息", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody TenantInfo tenantInfo)
     {
@@ -103,10 +115,43 @@ public class TenantInfoController extends BaseController
      * 删除租户基础信息
      */
     @PreAuthorize("@ss.hasPermi('tenant:tenant:remove')")
-    @Log(title = "租户基础信息", businessType = BusinessType.DELETE)
+    @Log(title = "删除租户基础信息", businessType = BusinessType.DELETE)
 	@DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable String[] ids)
     {
         return toAjax(tenantInfoService.deleteTenantInfoByIds(ids));
     }
+
+    /**
+     * 租户菜单修改(获取租户菜单)
+     */
+    @PreAuthorize("@ss.hasPermi('tenant:tenant:edit')")
+    @GetMapping("/menu/{id}")
+    public R menuChange(@PathVariable String id)
+    {
+        TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(id);
+        if (tenantInfo.getStatus() == 2) {
+            throw new CustomException("租户初始化中");
+        }
+        tenantDataSourceManager.switchTenant(tenantInfo);
+        return tenantInfoService.menuChange(id);
+    }
+
+    /**
+     * 租户菜单修改
+     */
+    @PreAuthorize("@ss.hasPermi('tenant:tenant:edit')")
+    @PostMapping("/menu/edit")
+    public R menuEdit(@RequestBody MenuDto menuDto)
+    {
+        TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(menuDto.getId());
+
+        if (tenantInfo.getStatus() == 2) {
+            throw new CustomException("租户初始化中");
+        }
+        tenantDataSourceManager.switchTenant(tenantInfo);
+        List<Long> selected = menuDto.getSelected();
+        List<Long> unSelected = menuDto.getUnSelected();
+        return tenantInfoService.menuEdit(selected, unSelected);
+    }
 }

+ 24 - 0
fs-common/src/main/java/com/fs/common/core/domain/TreeSelect.java

@@ -22,6 +22,12 @@ public class TreeSelect implements Serializable
     /** 节点名称 */
     private String label;
 
+    /** 菜单状态(0显示 1隐藏) */
+    private String visible;
+
+    /** 菜单状态(0显示 1停用) */
+    private String status;
+
     /** 子节点 */
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
     private List<TreeSelect> children;
@@ -43,6 +49,8 @@ public class TreeSelect implements Serializable
         this.id = menu.getMenuId();
         this.label = menu.getMenuName();
         this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
+        this.visible = menu.getVisible();
+        this.status = menu.getStatus();
     }
 
     public Long getId()
@@ -60,6 +68,22 @@ public class TreeSelect implements Serializable
         return label;
     }
 
+    public String getVisible() {
+        return visible;
+    }
+
+    public void setVisible(String visible) {
+        this.visible = visible;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
     public void setLabel(String label)
     {
         this.label = label;

+ 12 - 0
fs-service/src/main/java/com/fs/tenant/dto/MenuDto.java

@@ -0,0 +1,12 @@
+package com.fs.tenant.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class MenuDto {
+    private String id; // 租户ID
+    private List<Long> selected;  // 已选中菜单ID
+    private List<Long> unSelected;// 未选中菜单ID
+}

+ 8 - 0
fs-service/src/main/java/com/fs/tenant/mapper/TenantInfoMapper.java

@@ -1,8 +1,10 @@
 package com.fs.tenant.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fs.common.core.domain.entity.SysMenu;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.vo.TenantInfoShowVo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -62,6 +64,12 @@ public interface TenantInfoMapper extends BaseMapper<TenantInfo> {
     int deleteTenantInfoByIds(String[] ids);
 
     List<TenantInfoShowVo> tenantList(TenantInfo tenantInfo);
+
+    List<SysMenu> selectTenantMenu();
+
+    int updatePitchMenu(@Param("selected") List<Long> selected);
+
+    int updateUnPitchMenu(@Param("unSelected") List<Long> unSelected);
 }
 
 

+ 5 - 0
fs-service/src/main/java/com/fs/tenant/service/TenantInfoService.java

@@ -1,6 +1,7 @@
 package com.fs.tenant.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.common.core.domain.R;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.vo.TenantInfoShowVo;
 
@@ -61,4 +62,8 @@ public interface TenantInfoService extends IService<TenantInfo> {
     int deleteTenantInfoById(String id);
 
     List<TenantInfoShowVo> tenantList(TenantInfo tenantInfo);
+
+    R menuChange(String id);
+
+    R menuEdit(List<Long> selected, List<Long> unSelected);
 }

+ 20 - 0
fs-service/src/main/java/com/fs/tenant/service/impl/TenantInfoServiceImpl.java

@@ -3,10 +3,12 @@ package com.fs.tenant.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.TreeSelect;
 import com.fs.common.core.domain.entity.SysMenu;
 import com.fs.common.enums.DataSourceType;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
+import com.fs.system.service.ISysMenuService;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.mapper.TenantInfoMapper;
 import com.fs.tenant.service.TenantAsyncService;
@@ -30,6 +32,8 @@ import java.util.List;
 public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantInfo> implements TenantInfoService {
     @Autowired
     private TenantAsyncService tenantAsyncService;
+    @Autowired
+    private ISysMenuService menuService;
 
     /**
      * 查询租户基础信息
@@ -151,6 +155,22 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
     public List<TenantInfoShowVo> tenantList(TenantInfo tenantInfo) {
         return baseMapper.tenantList(tenantInfo);
     }
+
+    @Override
+    public R menuChange(String id) {
+        List<SysMenu> menuList = baseMapper.selectTenantMenu();
+        List<TreeSelect> treeSelects = menuService.buildMenuTreeSelect(menuList);
+        return R.ok().put("menus", treeSelects);
+    }
+
+    @Override
+    public R menuEdit(List<Long> selected, List<Long> unSelected) {
+        // 更新选中的
+        int pitch = baseMapper.updatePitchMenu(selected);
+        // 更新未选中的
+        int unPitchMenu = baseMapper.updateUnPitchMenu(unSelected);
+        return R.ok();
+    }
 }
 
 

+ 20 - 0
fs-service/src/main/resources/mapper/tenant/TenantInfoMapper.xml

@@ -57,6 +57,12 @@
         </where>
     </select>
 
+    <select id="selectTenantMenu" resultType="com.fs.common.core.domain.entity.SysMenu">
+        select menu_id, menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time
+        from sys_menu
+        order by parent_id, order_num
+    </select>
+
 
     <insert id="insertTenantInfo" parameterType="TenantInfo" useGeneratedKeys="true" keyProperty="id">
         insert into tenant_info
@@ -112,6 +118,20 @@
         where id = #{id}
     </update>
 
+    <update id="updatePitchMenu">
+        update sys_menu set visible = 0, status = 0 where menu_id in
+        <foreach item="menuId" collection="selected" open="(" separator="," close=")">
+            #{menuId}
+        </foreach>
+    </update>
+
+    <update id="updateUnPitchMenu">
+        update sys_menu set visible = 1, status = 1 where menu_id in
+        <foreach item="menuId" collection="unSelected" open="(" separator="," close=")">
+            #{menuId}
+        </foreach>
+    </update>
+
     <delete id="deleteTenantInfoById" parameterType="String">
         delete from tenant_info where id = #{id}
     </delete>