Browse Source

分配菜单递归父

lyhzzz 2 years ago
parent
commit
43599c33a0

+ 19 - 7
src/main/java/com/fdkankan/manage/service/impl/SysRoleMenuServiceImpl.java

@@ -9,6 +9,7 @@ import com.fdkankan.manage.mapper.ISysRoleMenuMapper;
 import com.fdkankan.manage.service.ISysMenuService;
 import com.fdkankan.manage.service.ISysRoleMenuService;
 import com.fdkankan.manage.service.ISysRoleService;
+import org.opencv.ml.EM;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -43,14 +44,12 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<ISysRoleMenuMapper, SysR
     @Override
     public void saveBatchByRoleId(Long roleId, List<Long> menuIds) {
         List<SysRoleMenu> sysMenus = new ArrayList<>();
-        HashMap<Long, SysMenu> menuMap = sysMenuService.getByIds(menuIds);
+        HashMap<Long, SysMenu> menuMap = new HashMap<>();
+        List<SysMenu> list = sysMenuService.list();
+        list.forEach(entity -> menuMap.put(entity.getId(),entity));
+
         HashSet<Long> menuIdsSet = new HashSet<>();
-        for (Long menuId : menuIds) {
-            Long parentId = menuMap.get(menuId).getParentId();
-            if(parentId != null && !menuIds.contains(parentId) ){
-                menuIdsSet.add(parentId);
-            }
-        }
+        this.getAllMenuIds(menuMap,menuIdsSet,menuIds);
         menuIdsSet.addAll(menuIds);
         for (Long menuId : menuIdsSet) {
             SysRoleMenu roleMenu = new SysRoleMenu();
@@ -61,6 +60,19 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<ISysRoleMenuMapper, SysR
         this.saveBatch(sysMenus);
     }
 
+    private void getAllMenuIds(HashMap<Long, SysMenu> menuMap, HashSet<Long> menuIdsSet,List<Long> menuIds ) {
+        List<Long> parentIds = new ArrayList<>();
+        for (Long menuId : menuIds) {
+            Long parentId = menuMap.get(menuId).getParentId();
+            if(parentId != null && ! menuIds.contains(parentId) ){
+                menuIdsSet.add(parentId);
+                parentIds.add(parentId);
+            }
+        }
+        if(parentIds.size() >0){
+            getAllMenuIds(menuMap,menuIdsSet,parentIds);
+        }
+    }
 
 
     @Override

+ 1 - 1
src/main/resources/mapper/manage/AgentNewLogMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fdkankan.manage.mapper.IAgentNewLogMapper">
 
-    <select id="listGroup" resultType="com.fdkankan.manage.vo.response.AgentLogGVo" parameterType="com.fdkankan.manage.vo.request.AgentNewLogParam">
+    <select id="listGroup" resultType="com.fdkankan.manage.vo.response.AgentLogGVo" >
         select agent_id,type,sum(count)as num from t_agent_new_log GROUP BY agent_id,type
         <if test="param.startTime != null and param.startTime !='' ">
             and create_time between #{param.startTime} and #{param.endTime}