Browse Source

后管、客户端、表单权限相关

liuyc 2 years ago
parent
commit
aa52aef4f9
15 changed files with 107 additions and 104 deletions
  1. 4 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTableOwnerRole.java
  2. 5 0
      blade-service-api/blade-system-api/pom.xml
  3. 6 17
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/CheckedTreeVO.java
  4. 7 20
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantTreeVO.java
  5. 4 17
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantVO.java
  6. 28 2
      blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java
  7. 1 16
      blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java
  8. 10 0
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/DictMapper.java
  9. 4 0
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/DictMapper.xml
  10. 0 1
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/RoleMapper.java
  11. 2 6
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/RoleMapper.xml
  12. 10 0
      blade-service/blade-system/src/main/java/org/springblade/system/service/IDictService.java
  13. 1 3
      blade-service/blade-system/src/main/java/org/springblade/system/service/IRoleService.java
  14. 6 0
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DictServiceImpl.java
  15. 19 22
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java

+ 4 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTableOwnerRole.java

@@ -17,4 +17,8 @@ public class WbsTableOwnerRole implements Serializable {
     @ApiModelProperty(value = "所属方value值")
     private String tableOwnerNumber;
 
+    @ApiModelProperty(value = "所属方name")
+    private String tableOwnerName;
+
+
 }

+ 5 - 0
blade-service-api/blade-system-api/pom.xml

@@ -19,6 +19,11 @@
             <groupId>org.springblade</groupId>
             <artifactId>blade-starter-cache</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-dict-api</artifactId>
+            <version>2.9.1.RELEASE</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 6 - 17
blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/CheckedTreeVO.java

@@ -1,19 +1,3 @@
-/*
- *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- *
- *  Redistributions of source code must retain the above copyright notice,
- *  this list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright
- *  notice, this list of conditions and the following disclaimer in the
- *  documentation and/or other materials provided with the distribution.
- *  Neither the name of the dreamlu.net developer nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- *  Author: Chill 庄骞 (smallchill@163.com)
- */
 package org.springblade.system.vo;
 
 import lombok.Data;
@@ -23,7 +7,7 @@ import java.util.List;
 /**
  * CheckedTreeVO
  *
- * @author Chill
+ * @author liuyc
  */
 @Data
 public class CheckedTreeVO {
@@ -34,4 +18,9 @@ public class CheckedTreeVO {
 
 	private List<String> apiScope;
 
+	private List<String> usermenu;
+
+	private List<String> tableOwners;
+
+
 }

+ 7 - 20
blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantTreeVO.java

@@ -1,19 +1,3 @@
-/*
- *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- *
- *  Redistributions of source code must retain the above copyright notice,
- *  this list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright
- *  notice, this list of conditions and the following disclaimer in the
- *  documentation and/or other materials provided with the distribution.
- *  Neither the name of the dreamlu.net developer nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- *  Author: Chill 庄骞 (smallchill@163.com)
- */
 package org.springblade.system.vo;
 
 import lombok.Data;
@@ -25,22 +9,25 @@ import java.util.List;
 /**
  * GrantTreeVO
  *
- * @author Chill
+ * @author liuyc
  */
 @Data
 public class GrantTreeVO implements Serializable {
 	private static final long serialVersionUID = 1L;
 
-	// 后管
+	//后管
 	private List<TreeNode> menu;
 
-	// 客户端
+	//客户端
 	private List<TreeNode> usermenu;
 
-	//
+	//数据
 	private List<TreeNode> dataScope;
 
 	//api
 	private List<TreeNode> apiScope;
 
+	//表单
+	private List<DictVO02> tableOwners;
+
 }

+ 4 - 17
blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/GrantVO.java

@@ -1,19 +1,3 @@
-/*
- *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- *
- *  Redistributions of source code must retain the above copyright notice,
- *  this list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright
- *  notice, this list of conditions and the following disclaimer in the
- *  documentation and/or other materials provided with the distribution.
- *  Neither the name of the dreamlu.net developer nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- *  Author: Chill 庄骞 (smallchill@163.com)
- */
 package org.springblade.system.vo;
 
 import io.swagger.annotations.ApiModelProperty;
@@ -25,7 +9,7 @@ import java.util.List;
 /**
  * GrantVO
  *
- * @author Chill
+ * @author liuyc
  */
 @Data
 public class GrantVO implements Serializable {
@@ -37,6 +21,9 @@ public class GrantVO implements Serializable {
     @ApiModelProperty(value = "menuIds集合")
     private List<Long> menuIds;
 
+    @ApiModelProperty(value = "menuClientIds集合")
+    private List<Long> menuClientIds;
+
     @ApiModelProperty(value = "topMenuIds集合")
     private List<Long> topMenuIds;
 

+ 28 - 2
blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java

@@ -31,11 +31,17 @@ import org.springblade.core.tool.constant.RoleConstant;
 import org.springblade.core.tool.node.TreeNode;
 import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.manager.entity.WbsTableOwnerRole;
+import org.springblade.system.entity.Dict;
 import org.springblade.system.entity.Menu;
 import org.springblade.system.entity.TopMenu;
+import org.springblade.system.mapper.RoleMapper;
+import org.springblade.system.service.IDictService;
 import org.springblade.system.service.IMenuService;
+import org.springblade.system.service.IRoleService;
 import org.springblade.system.service.ITopMenuService;
 import org.springblade.system.vo.CheckedTreeVO;
+import org.springblade.system.vo.DictVO02;
 import org.springblade.system.vo.GrantTreeVO;
 import org.springblade.system.vo.MenuVO;
 import org.springblade.system.wrapper.MenuWrapper;
@@ -43,7 +49,6 @@ import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
 import javax.validation.Valid;
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -66,6 +71,8 @@ public class MenuController extends BladeController {
 
     private final IMenuService menuService;
     private final ITopMenuService topMenuService;
+    private final IDictService dictService;
+    private final RoleMapper roleMapper;
 
     /**
      * 详情
@@ -210,6 +217,7 @@ public class MenuController extends BladeController {
 
     /**
      * 获取权限分配树形结构
+     *
      */
     @GetMapping("/grant-tree")
     @ApiOperationSupport(order = 12)
@@ -220,7 +228,6 @@ public class MenuController extends BladeController {
         List<TreeNode> treeMenu = new ArrayList<>();
         //获取所有菜单
         List<TreeNode> treeNodesAll = menuService.grantTree(user);
-
         for (TreeNode treeNode : treeNodesAll) {
             if (treeNode.getTitle().equals("质量管理") || treeNode.getTitle().equals("任务管理")) {
                 treeUserMenu.add(treeNode);
@@ -237,20 +244,39 @@ public class MenuController extends BladeController {
         vo.setDataScope(menuService.grantDataScopeTree(user));
         //接口
         vo.setApiScope(menuService.grantApiScopeTree(user));
+        //表单
+        List<DictVO02> ownerType = dictService.getList2("owner_type");
+        vo.setTableOwners(ownerType);
+
         return R.data(vo);
     }
 
     /**
      * 获取权限分配树形结构
+     *
      */
     @GetMapping("/role-tree-keys")
     @ApiOperationSupport(order = 13)
     @ApiOperation(value = "角色所分配的树", notes = "角色所分配的树")
     public R<CheckedTreeVO> roleTreeKeys(String roleIds) {
         CheckedTreeVO vo = new CheckedTreeVO();
+        //后台
         vo.setMenu(menuService.roleTreeKeys(roleIds));
+
+        //客户端
+        vo.setUsermenu(menuService.roleTreeKeys(roleIds));
+
+        //数据源
         vo.setDataScope(menuService.dataScopeTreeKeys(roleIds));
+
+        //接口
         vo.setApiScope(menuService.apiScopeTreeKeys(roleIds));
+
+        //表单
+        List<WbsTableOwnerRole> wbsTableOwnerRoles = roleMapper.selectRoleAndTableOwnerListByRoleId(Long.valueOf(roleIds));
+        List<String> collect = wbsTableOwnerRoles.stream().map(WbsTableOwnerRole::getTableOwnerNumber).collect(Collectors.toList());
+        vo.setTableOwners(collect);
+
         return R.data(vo);
     }
 

+ 1 - 16
blade-service/blade-system/src/main/java/org/springblade/system/controller/RoleController.java

@@ -186,7 +186,7 @@ public class RoleController extends BladeController {
     public R grant(@RequestBody GrantVO grantVO) {
         CacheUtil.clear(SYS_CACHE);
         CacheUtil.clear(SYS_CACHE, Boolean.FALSE);
-        boolean temp = roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getDataScopeIds(), grantVO.getApiScopeIds(),grantVO.getTableOwners());
+        boolean temp = roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getMenuClientIds(), grantVO.getDataScopeIds(), grantVO.getApiScopeIds(), grantVO.getTableOwners());
         return R.status(temp);
     }
 
@@ -207,19 +207,4 @@ public class RoleController extends BladeController {
     }
 
 
-    /**
-     * 获取角色绑定的表单所属方关系List
-     */
-    @GetMapping("/searchRoleAndTableOwnerList")
-    @ApiOperationSupport(order = 9)
-    @ApiOperation(value = "获取角色绑定的表单所属方关系List", notes = "传入角色id")
-    @ApiImplicitParams(value = {
-            @ApiImplicitParam(value = "roleId", name = "角色id")
-    })
-    @PreAuth(AuthConstant.PERMIT_ALL)
-    public R<List<WbsTableOwnerRole>> searchRoleAndTableOwnerList(String roleId) {
-        return R.data(roleService.searchRoleAndTableOwnerList(roleId));
-    }
-
-
 }

+ 10 - 0
blade-service/blade-system/src/main/java/org/springblade/system/mapper/DictMapper.java

@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.system.entity.Dict;
 import org.springblade.system.vo.DictVO;
+import org.springblade.system.vo.DictVO02;
 
 import java.util.List;
 
@@ -56,6 +57,15 @@ public interface DictMapper extends BaseMapper<Dict> {
 	 */
 	List<Dict> getList(String code);
 
+	/**
+	 * 获取字典表
+	 *
+	 * @param code 字典编号
+	 * @return
+	 */
+	List<DictVO02> getList2(String code);
+
+
 	/**
 	 * 获取树形节点
 	 *

+ 4 - 0
blade-service/blade-system/src/main/java/org/springblade/system/mapper/DictMapper.xml

@@ -51,4 +51,8 @@
         select id, parent_id, dict_value as title, id as "value", id as "key" from blade_dict where is_deleted = 0 and parent_id = 0
     </select>
 
+    <select id="getList2" resultType="org.springblade.system.vo.DictVO02">
+        select  dict_key AS "id", dict_value AS "title" from blade_dict where code = #{param1} and parent_id > 0 and is_sealed = 0 and is_deleted = 0
+    </select>
+
 </mapper>

+ 0 - 1
blade-service/blade-system/src/main/java/org/springblade/system/mapper/RoleMapper.java

@@ -77,6 +77,5 @@ public interface RoleMapper extends BaseMapper<Role> {
 
     List<WbsTableOwnerRole> selectRoleAndTableOwnerListByRoleId(Long roleId);
 
-    List<WbsTableOwnerRole> selectRoleAndTableOwnerList(String roleId);
 
 }

+ 2 - 6
blade-service/blade-system/src/main/java/org/springblade/system/mapper/RoleMapper.xml

@@ -79,13 +79,9 @@
     </select>
 
     <select id="selectRoleAndTableOwnerListByRoleId" resultType="org.springblade.manager.entity.WbsTableOwnerRole">
-        select * from m_wbs_table_owner_role where role_id = #{roleId}
-    </select>
-
-    <select id="selectRoleAndTableOwnerList" resultType="org.springblade.manager.entity.WbsTableOwnerRole">
         select id,role_id as "roleId",table_owner_number as "tableOwnerNumber"
-        from m_wbs_table_owner_role
-        where role_id = #{roleId}
+        from m_wbs_table_owner_role where role_id = #{roleId}
     </select>
 
+
 </mapper>

+ 10 - 0
blade-service/blade-system/src/main/java/org/springblade/system/service/IDictService.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import org.springblade.core.mp.support.Query;
 import org.springblade.system.entity.Dict;
 import org.springblade.system.vo.DictVO;
+import org.springblade.system.vo.DictVO02;
 
 import java.util.List;
 import java.util.Map;
@@ -72,6 +73,15 @@ public interface IDictService extends IService<Dict> {
 	 */
 	List<Dict> getList(String code);
 
+	/**
+	 * 获取字典表
+	 *
+	 * @param code 字典编号
+	 * @return
+	 */
+	List<DictVO02> getList2(String code);
+
+
 	/**
 	 * 新增或修改
 	 *

+ 1 - 3
blade-service/blade-system/src/main/java/org/springblade/system/service/IRoleService.java

@@ -60,7 +60,7 @@ public interface IRoleService extends IService<Role> {
      * @param apiScopeIds  接口权限id集合
      * @return 是否成功
      */
-    boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds, List<Long> tableOwners);
+    boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> menuClientIds, List<Long> dataScopeIds, List<Long> apiScopeIds, List<Long> tableOwners);
 
     /**
      * 获取角色ID
@@ -116,6 +116,4 @@ public interface IRoleService extends IService<Role> {
 
     List<Role> selectParentRole();
 
-    List<WbsTableOwnerRole> searchRoleAndTableOwnerList(String roleId);
-
 }

+ 6 - 0
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DictServiceImpl.java

@@ -34,6 +34,7 @@ import org.springblade.system.entity.Dict;
 import org.springblade.system.mapper.DictMapper;
 import org.springblade.system.service.IDictService;
 import org.springblade.system.vo.DictVO;
+import org.springblade.system.vo.DictVO02;
 import org.springblade.system.wrapper.DictWrapper;
 import org.springframework.stereotype.Service;
 
@@ -77,6 +78,11 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
 		return baseMapper.getList(code);
 	}
 
+	@Override
+	public List<DictVO02> getList2(String code) {
+		return baseMapper.getList2(code);
+	}
+
 	@Override
 	public boolean submit(Dict dict) {
 		LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());

+ 19 - 22
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/RoleServiceImpl.java

@@ -85,13 +85,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds, List<Long> tableOwners) {
-
-
-        return grantRoleMenu(roleIds, menuIds) && grantDataScope(roleIds, dataScopeIds) && grantApiScope(roleIds, apiScopeIds) && submitRoleAndTableOwner(roleIds, tableOwners);
+    public boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> menuClientIds, List<Long> dataScopeIds, List<Long> apiScopeIds, List<Long> tableOwners) {
+        return grantRoleMenu(roleIds, menuIds, menuClientIds) && grantDataScope(roleIds, dataScopeIds) && grantApiScope(roleIds, apiScopeIds) && submitRoleAndTableOwner(roleIds, tableOwners);
     }
 
-    private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds) {
+    private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds, List<Long> menuClientIds) {
         // 防止越权配置超管角色
         Long administratorCount = baseMapper.selectCount(Wrappers.<Role>query().lambda().eq(Role::getRoleAlias, RoleConstant.ADMINISTRATOR).in(Role::getId, roleIds));
         if (!AuthUtil.isAdministrator() && administratorCount > 0L) {
@@ -104,7 +102,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
         }
         // 删除角色配置的菜单集合
         roleMenuService.remove(Wrappers.<RoleMenu>update().lambda().in(RoleMenu::getRoleId, roleIds));
-        // 组装配置
+
+        // 组装配置 - 后台
         List<RoleMenu> roleMenus = new ArrayList<>();
         roleIds.forEach(roleId -> menuIds.forEach(menuId -> {
             RoleMenu roleMenu = new RoleMenu();
@@ -112,10 +111,22 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
             roleMenu.setMenuId(menuId);
             roleMenus.add(roleMenu);
         }));
+
+        // 组装配置-客户端
+        roleIds.forEach(roleId -> menuClientIds.forEach(menuIdC -> {
+            RoleMenu roleMenu = new RoleMenu();
+            roleMenu.setRoleId(roleId);
+            roleMenu.setMenuId(menuIdC);
+            roleMenus.add(roleMenu);
+        }));
+
         // 新增配置
         roleMenuService.saveBatch(roleMenus);
+
         // 递归设置下属角色菜单集合
         recursionRoleMenu(roleIds, menuIds);
+        recursionRoleMenu(roleIds, menuClientIds);
+
         return true;
     }
 
@@ -254,15 +265,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
         return baseMapper.selectList(Wrappers.<Role>query().lambda().eq(Role::getParentId, 0));
     }
 
-    private Boolean removeRoleAndPostByRid(String ids) {
-        Integer row = roleMapper.deleteRoleAndPostByRid(ids);
-        if (row > 0) {
-            return true;
-        }
-        return false;
-    }
-
-
+    @Transactional(rollbackFor = Exception.class)
     public Boolean submitRoleAndTableOwner(List<Long> roleIds, List<Long> tableOwners) {
         for (Long role : roleIds) {
             List<WbsTableOwnerRole> list = baseMapper.selectRoleAndTableOwnerListByRoleId(role);
@@ -285,7 +288,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
             }
 
             if (diffRent.size() == 0) {
-                throw new ServiceException("角色表单权限未进行任何操作");
+                return true;
             } else {
                 if (tableOwnerValuesOut.size() > tableOwnerValuesIn.size()) {
                     //新增
@@ -306,12 +309,6 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
         return false;
     }
 
-    @Override
-    public List<WbsTableOwnerRole> searchRoleAndTableOwnerList(String roleId) {
-        return baseMapper.selectRoleAndTableOwnerList(roleId);
-    }
-
-
     private static List<String> getDiffRent(List<String> list1, List<String> list2) {
         List<String> diff = new ArrayList<String>();
         List<String> maxList = list1;