zhangc il y a 8 mois
Parent
commit
b2c2b9aa15

+ 11 - 0
src/main/java/com/sunxung/factoring/entity/sys/Permission.java

@@ -33,6 +33,9 @@ public class Permission extends BaseEntity {
     private Integer count;
     /** 判断节点是否选中 */
     private boolean check;
+    /** 类型 **/
+    private String type;
+
     private List<Permission> childPermission;
 
     public boolean isCheck() {
@@ -114,4 +117,12 @@ public class Permission extends BaseEntity {
     public void setChildPermission(List<Permission> childPermission) {
         this.childPermission = childPermission;
     }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
 }

+ 2 - 1
src/main/java/com/sunxung/factoring/service/sys/PermissionService.java

@@ -4,6 +4,7 @@ import java.util.List;
 
 import com.sunxung.factoring.entity.sys.Permission;
 import com.sunxung.factoring.entity.sys.vo.PermissionTreeNode;
+import com.sunxung.factoring.service.sys.dto.PermissionDTO;
 
 public interface PermissionService {
 
@@ -117,5 +118,5 @@ public interface PermissionService {
      * @param userId
      * @return
      */
-    List<String> getAllPermissionEname(Long userId);
+    PermissionDTO getAllPermissionEname(Long userId);
 }

+ 14 - 0
src/main/java/com/sunxung/factoring/service/sys/dto/PermissionDTO.java

@@ -0,0 +1,14 @@
+package com.sunxung.factoring.service.sys.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class PermissionDTO {
+
+  private List<String> menus;
+
+  private List<String> buttons;
+
+}

+ 21 - 10
src/main/java/com/sunxung/factoring/service/sys/impl/PermissionServiceImpl.java

@@ -4,6 +4,8 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import com.sunxung.factoring.component.util.ConstantConversionUtil;
+import com.sunxung.factoring.service.sys.dto.PermissionDTO;
+import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -423,23 +425,32 @@ public class PermissionServiceImpl implements PermissionService {
     }
 
     @Override
-    public List<String> getAllPermissionEname(Long userId) {
+    public PermissionDTO getAllPermissionEname(Long userId) {
 
         List<Role> roleList = roleService.getRoleListByUseId();
-        List<String> result = new ArrayList<>();
+        List<String> menuList = new ArrayList<>();
+        List<String> buttonList = new ArrayList<>();
+        List<Permission>   permissionList = Lists.newArrayList();
+        boolean isAdmin = false;
         for (Role role : roleList) {
             if (ConstantConversionUtil.ADMINISTORIES_DISPLAYNAME.equals(role.getName())
                     || ConstantConversionUtil.CHILD_ADMINISTORIES_DISPLAYNAME.equals(role.getName())) {
                 //如果是超级管理员或子管理员角色,默认返回所有
-                List<Permission> permissionAllList = permissionMapper.findAll();
-                result = permissionAllList.stream().map(Permission::getEname).collect(Collectors.toList());
-                return result;
+                permissionList = permissionMapper.findAll();
+                isAdmin = true;
+               // result = permissionAllList.stream().map(Permission::getEname).collect(Collectors.toList());
+
             }
         }
-
-        List<Permission> permissionList = permissionMapper.findAllByUserId(userId);
-        permissionList.removeAll(Collections.singleton(null));
-        result = permissionList.stream().map(Permission::getEname).collect(Collectors.toList());
-        return result;
+        if(!isAdmin){
+            permissionList = permissionMapper.findAllByUserId(userId);
+           // permissionList.removeAll(Collections.singleton(null));
+        }
+        menuList = permissionList.stream().filter(x->"menu".equals(x.getType())).map(Permission::getEname).collect(Collectors.toList());
+        buttonList =  permissionList.stream().filter(x->"button".equals(x.getType())).map(Permission::getEname).collect(Collectors.toList());
+        PermissionDTO permissionDTO = new PermissionDTO();
+        permissionDTO.setButtons(buttonList);
+        permissionDTO.setMenus(menuList);
+        return permissionDTO;
     }
 }

+ 2 - 0
src/main/resources/mapper/sys/PermissionMapper.xml

@@ -5,6 +5,7 @@
 	<resultMap type="Permission" id="permissionResult">
 		<result property="id" column="id"/>
 		<result property="parentId" column="parentId"/>
+		<result property="type" column="type"/>
 		<result property="cname" column="cname"/>
 		<result property="ename" column="ename"/>
 		<result property="gradation" column="gradation"/>
@@ -18,6 +19,7 @@
 	<sql id="fields">
 		id,
 		parentId,
+    type,
 		cname,
 		ename,
 		gradation,