Преглед изворни кода

完成员工和科室树开发

hurugang пре 4 година
родитељ
комит
cfc0915585

+ 2 - 2
src/main/java/cn/hnthyy/thmz/controller/LoginController.java

@@ -27,8 +27,8 @@ import java.util.Map;
 @RestController
 @Slf4j
 public class LoginController {
-    @Autowired
-    private XtUserServiceImpl xtUserService;
+//    @Autowired
+//    private XtUserServiceImpl xtUserService;
     @Autowired
     private UserService userService;
     @Autowired

+ 112 - 25
src/main/java/cn/hnthyy/thmz/controller/MenuController.java

@@ -2,11 +2,16 @@ package cn.hnthyy.thmz.controller;
 
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
+import cn.hnthyy.thmz.entity.his.Employee;
+import cn.hnthyy.thmz.entity.his.ZdUnitCode;
 import cn.hnthyy.thmz.entity.thmz.Menu;
 import cn.hnthyy.thmz.entity.thmz.User;
 import cn.hnthyy.thmz.entity.thmz.UserMenuRelation;
+import cn.hnthyy.thmz.service.his.EmployeeService;
+import cn.hnthyy.thmz.service.his.ZdUnitCodeService;
 import cn.hnthyy.thmz.service.thmz.MenuService;
 import cn.hnthyy.thmz.service.thmz.UserMenuRelationService;
+import cn.hnthyy.thmz.service.thmz.UserService;
 import cn.hnthyy.thmz.vo.MenuVo;
 import cn.hnthyy.thmz.vo.UserMenuRelationVo;
 import lombok.extern.slf4j.Slf4j;
@@ -25,6 +30,12 @@ public class MenuController {
     private MenuService menuService;
     @Autowired
     private UserMenuRelationService userMenuRelationService;
+    @Autowired
+    private ZdUnitCodeService zdUnitCodeService;
+    @Autowired
+    private EmployeeService employeeService;
+    @Autowired
+    private UserService userService;
 
     /**
      * 获取所有的父菜单
@@ -99,7 +110,7 @@ public class MenuController {
                 resultMap.put("message", "保存菜单数据失败,菜单名称为空");
                 return resultMap;
             }
-            if (menu.getSortValue()==null) {
+            if (menu.getSortValue() == null) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "保存菜单数据失败,排序字段为空");
                 return resultMap;
@@ -267,23 +278,23 @@ public class MenuController {
                 resultMap.put("message", "获取用户已有的菜单关系失败,用户集参数为空");
                 return resultMap;
             }
-            if(userMenuRelationVo.getUserMenuRelationVos()==null || userMenuRelationVo.getUserMenuRelationVos().size()==0){
+            if (userMenuRelationVo.getUserMenuRelationVos() == null || userMenuRelationVo.getUserMenuRelationVos().size() == 0) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "获取用户已有的菜单关系失败,当前构造菜单树为空");
                 return resultMap;
             }
             List<String> userIds = Arrays.asList(userMenuRelationVo.getUserIds().split(","));
             List<Long> userIdLs = userIds.stream().map(u -> Long.valueOf(u)).collect(Collectors.toList());
-            List<UserMenuRelation> userMenuRelationList=userMenuRelationService.queryByUserIds(userIdLs);
+            List<UserMenuRelation> userMenuRelationList = userMenuRelationService.queryByUserIds(userIdLs);
             List<Menu> parentMenus = menuService.queryAllParentMenu();
             //父菜单集合
             Set<Long> patrntSets = parentMenus.stream().map(Menu::getId).collect(Collectors.toSet());
             Set<Long> returnSet = new HashSet<>();
-            if(userMenuRelationList!=null && userMenuRelationList.size()>0){
-                Map<Long,Long> map = userMenuRelationVo.getUserMenuRelationVos().stream().collect(Collectors.toMap(UserMenuRelationVo::getDataId, UserMenuRelationVo::getNodeId));
-                for (UserMenuRelation userMenuRelation:userMenuRelationList){
+            if (userMenuRelationList != null && userMenuRelationList.size() > 0) {
+                Map<Long, Long> map = userMenuRelationVo.getUserMenuRelationVos().stream().collect(Collectors.toMap(UserMenuRelationVo::getDataId, UserMenuRelationVo::getNodeId));
+                for (UserMenuRelation userMenuRelation : userMenuRelationList) {
                     //父菜单不需要放到页面勾选的集合,因为只要勾选了子菜单,父菜单就会被勾选,然后如果勾选了父菜单,所有的子菜单都会被选上
-                    if(patrntSets.contains(userMenuRelation.getMenuId())){
+                    if (patrntSets.contains(userMenuRelation.getMenuId())) {
                         continue;
                     }
                     returnSet.add(map.get(userMenuRelation.getMenuId()));
@@ -303,7 +314,6 @@ public class MenuController {
     }
 
 
-
     /**
      * 获取当前用户的菜单权限
      *
@@ -315,30 +325,30 @@ public class MenuController {
         Map<String, Object> resultMap = new HashMap<>();
         try {
             User tokenUser = TokenUtil.getUser(httpServletRequest);
-            List<UserMenuRelation> userMenuRelationList=userMenuRelationService.queryByUserId(tokenUser.getId());
-            List<Long> menuIds=userMenuRelationList.stream().map(UserMenuRelation::getMenuId).collect(Collectors.toList());
+            List<UserMenuRelation> userMenuRelationList = userMenuRelationService.queryByUserId(tokenUser.getId());
+            List<Long> menuIds = userMenuRelationList.stream().map(UserMenuRelation::getMenuId).collect(Collectors.toList());
             List<MenuVo> resultList = new ArrayList<>();
-            if(menuIds!=null && menuIds.size()>0){
-                List<Menu> menuList= menuService.queryByIds(menuIds);
-                Map<Long,MenuVo> tempMap = new HashMap<>();
-                for (Menu menu:menuList){
-                    if(menu.getParentId()==null){
+            if (menuIds != null && menuIds.size() > 0) {
+                List<Menu> menuList = menuService.queryByIds(menuIds);
+                Map<Long, MenuVo> tempMap = new HashMap<>();
+                for (Menu menu : menuList) {
+                    if (menu.getParentId() == null) {
                         //是父菜单
-                        MenuVo menuVo=tempMap.get(menu.getId());
-                        if(menuVo==null){
-                            menuVo=new MenuVo();
+                        MenuVo menuVo = tempMap.get(menu.getId());
+                        if (menuVo == null) {
+                            menuVo = new MenuVo();
                             menuVo.setMenuList(new ArrayList<>());
                             resultList.add(menuVo);
-                            tempMap.put(menu.getId(),menuVo);
+                            tempMap.put(menu.getId(), menuVo);
                         }
                         menuVo.setMenu(menu);
-                    }else {
-                        MenuVo menuVo=tempMap.get(menu.getParentId());
-                        if(menuVo==null){
-                            menuVo=new MenuVo();
+                    } else {
+                        MenuVo menuVo = tempMap.get(menu.getParentId());
+                        if (menuVo == null) {
+                            menuVo = new MenuVo();
                             menuVo.setMenuList(new ArrayList<>());
                             resultList.add(menuVo);
-                            tempMap.put(menu.getId(),menuVo);
+                            tempMap.put(menu.getId(), menuVo);
                         }
                         menuVo.getMenuList().add(menu);
                     }
@@ -346,7 +356,7 @@ public class MenuController {
             }
             resultMap.put("code", 0);
             resultMap.put("message", "获取当前用户的菜单权限成功");
-            resultMap.put("data",resultList);
+            resultMap.put("data", resultList);
             return resultMap;
         } catch (Exception e) {
             e.printStackTrace();
@@ -356,4 +366,81 @@ public class MenuController {
             return resultMap;
         }
     }
+
+
+    /**
+     * 查询用户树
+     *
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/getNewUserTree", method = {RequestMethod.GET})
+    public Map<String, Object> getNewUserTree() {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            List<User> userList = userService.queryAllUser();
+            if (userList == null || userList.size()==0) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "查询用户树失败,没有任何用户信息!");
+                return resultMap;
+            }
+            List<ZdUnitCode> zdUnitCodes = zdUnitCodeService.queryAllDeptInCache();
+            List<String> userIdCodes = userList.stream().map(u -> u.getUserIdCode()).collect(Collectors.toList());
+            Map<String,Long> userMap =userList.stream().collect(Collectors.toMap(User::getUserIdCode,User::getId));
+            List<Employee> employees= employeeService.queryByCodes(userIdCodes);
+            List<String> deptNos = null;
+            if (employees != null && employees.size() > 0) {
+                deptNos = employees.stream().map(e -> e.getDeptCode()).collect(Collectors.toList());
+            }
+            List<Map<String, Object>> trees = new ArrayList<>();
+            Map<String, Map<String, Object>> nodesMap = new HashMap<>();
+            //尽量展示最少的数据,新用户表中的最小部门集合
+            if (deptNos != null && deptNos.size() > 0) {
+                for (ZdUnitCode zd : zdUnitCodes) {
+                    if (deptNos.contains(zd.getCode())) {
+                        formatUnit(trees, nodesMap, zd);
+                    }
+                }
+            } else {
+                for (ZdUnitCode zd : zdUnitCodes) {
+                    formatUnit(trees, nodesMap, zd);
+                }
+            }
+            for (Employee e : employees) {
+                Map<String, Object> tempParent = nodesMap.get(e.getDeptCode());
+                List<Map<String, Object>> childList = (List<Map<String, Object>>) tempParent.get("nodes");
+                Map<String, Object> temp = new HashMap<>();
+                temp.put("text", e.getEmployeeName());
+                temp.put("dataId", userMap.get(e.getEmployeeCode()));
+                childList.add(temp);
+            }
+            resultMap.put("code", 0);
+            resultMap.put("message", "查询用户树成功");
+            resultMap.put("data", trees);
+            return resultMap;
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("查询用户树失败,错误信息{}", e.getMessage());
+            resultMap.put("code", -1);
+            resultMap.put("message", "查询用户树失败");
+            return resultMap;
+        }
+    }
+
+    /**
+     * 构造部门集合
+     * @param trees
+     * @param nodesMap
+     * @param zd
+     */
+    private void formatUnit(List<Map<String, Object>> trees, Map<String, Map<String, Object>> nodesMap, ZdUnitCode zd) {
+        Map<String, Object> tempParent = new HashMap<>();
+        tempParent.put("text", zd.getName());
+        tempParent.put("dataId", zd.getCode());
+        tempParent.put("nodes", new ArrayList<>());
+        trees.add(tempParent);
+        nodesMap.put(zd.getCode().trim(), tempParent);
+    }
+
+
 }

+ 2 - 2
src/main/resources/static/js/user_menu_relation.js

@@ -110,7 +110,7 @@ $(function () {
     //用户树
     $.ajax({
         type: "GET",
-        url: '/thmz/getUserTree',
+        url: '/thmz/getNewUserTree',
         dataType: "json",
         headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
         success: function (res) {
@@ -124,7 +124,7 @@ $(function () {
                 onNodeChecked: userNodeChecked,//当选中节点check时响应函数
                 onNodeUnchecked: userNodeUnchecked//当不选中时响应函数,就是用于级联效果
             });
-
+            $("#userTree").treeview('collapseAll');//关闭展开
         }
     });