zouxuan 5 年之前
父節點
當前提交
ea218d82f3

+ 17 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysMenuDao.java

@@ -2,9 +2,11 @@ package com.ym.mec.auth.dal.dao;
 
 import com.ym.mec.auth.api.entity.SysMenu;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.page.PageInfo;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 public interface SysMenuDao extends BaseDAO<Integer, SysMenu> {
 
@@ -37,4 +39,19 @@ public interface SysMenuDao extends BaseDAO<Integer, SysMenu> {
      * @return
      */
     List<SysMenu> findByParentId(@Param("parentId") Integer menuId,@Param("delFlag") String delFlag,@Param("userId") Integer userId);
+
+    /**
+     * count所有菜单列表
+     * @param params
+     * @return
+     */
+    int findCountBySys(Map<String, Object> params);
+
+    /**
+     * 获取所有菜单列表
+     * @param menuId
+     * @param delFlag
+     * @return
+     */
+    List<SysMenu> findList(@Param("parentId") Integer menuId,@Param("delFlag") String delFlag);
 }

+ 2 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysUserDao.java

@@ -1,7 +1,9 @@
 package com.ym.mec.auth.dal.dao;
 
+import com.ym.mec.auth.api.entity.SysMenu;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.page.PageInfo;
 import org.apache.ibatis.annotations.Param;
 
 public interface SysUserDao extends BaseDAO<Integer, SysUser> {

+ 44 - 7
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/impl/SysMenuServiceImpl.java

@@ -1,24 +1,31 @@
 package com.ym.mec.auth.service.impl;
 
 import com.ym.mec.auth.api.dto.MenuQueryInfo;
-import com.ym.mec.auth.api.enums.YesOrNoEnum;
-import com.ym.mec.common.page.PageInfo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
 import com.ym.mec.auth.api.entity.SysMenu;
+import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.auth.api.enums.SysUserType;
 import com.ym.mec.auth.dal.dao.SysMenuDao;
+import com.ym.mec.auth.dal.dao.SysUserDao;
 import com.ym.mec.auth.service.SysMenuService;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.util.collection.MapUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu>  implements SysMenuService {
 	
 	@Autowired
 	private SysMenuDao sysMenuDao;
+	@Autowired
+	private SysUserDao sysUserDao;
 
 	@Override
 	public BaseDAO<Integer, SysMenu> getDAO() {
@@ -32,17 +39,47 @@ public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu>  imple
 
 	@Override
 	public PageInfo<SysMenu> findByUser(MenuQueryInfo menuQueryInfo) {
-		PageInfo<SysMenu> pageInfo = queryPage(menuQueryInfo);
+		SysUser sysUser = sysUserDao.get(menuQueryInfo.getUserId());
+		PageInfo<SysMenu> pageInfo = null;
+		if(sysUser.getUserType() == SysUserType.SYSTEM){
+			pageInfo = findBySys(menuQueryInfo);
+		}else {
+			pageInfo = queryPage(menuQueryInfo);
+		}
 		for (SysMenu menu:pageInfo.getRows()) {
 			menu = getTree(menu,menuQueryInfo.getDelFlag(),menuQueryInfo.getUserId());
 		}
 		return pageInfo;
 	}
 
+	private PageInfo<SysMenu> findBySys(MenuQueryInfo menuQueryInfo){
+		PageInfo<SysMenu> pageInfo = new PageInfo<>(menuQueryInfo.getPage(), menuQueryInfo.getRows());
+		Map<String, Object> params = new HashMap<>();
+		MapUtil.populateMap(params, menuQueryInfo);
+
+		List<SysMenu> dataList = null;
+		int count = sysMenuDao.findCountBySys(params);
+		if (count > 0) {
+			pageInfo.setTotal(count);
+			params.put("offset", pageInfo.getOffset());
+			dataList = sysMenuDao.findList(menuQueryInfo.getParentId(),menuQueryInfo.getDelFlag());
+		}
+		if (count == 0) {
+			dataList = new ArrayList<>();
+		}
+		pageInfo.setRows(dataList);
+		return pageInfo;
+	}
+
 	private SysMenu getTree(SysMenu menu, String delFlag,Integer userId){
 		//得到根节点对象
 		//获取子节点list
-		List<SysMenu> sysMenus = sysMenuDao.findByParentId(menu.getId(),delFlag,userId);
+		List<SysMenu> sysMenus = null;
+		if(userId == null){
+			sysMenus = sysMenuDao.findList(menu.getId(),delFlag);
+		}else {
+			sysMenus = sysMenuDao.findByParentId(menu.getId(),delFlag,userId);
+		}
 		//如果存在子节点
 		if(sysMenus != null && sysMenus.size() > 0) {
 			//将子节点list放入父节点对象

+ 1 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/web/controller/MenuController.java

@@ -64,6 +64,7 @@ public class MenuController extends BaseController {
             if(menuQueryInfo == null){
                 menuQueryInfo = new MenuQueryInfo();
             }
+
             menuQueryInfo.setUserId(user.getUserId());
             return succeed(sysMenuService.findByUser(menuQueryInfo));
         }

+ 15 - 4
mec-auth/mec-auth-server/src/main/resources/config/mybatis/SysMenuMapper.xml

@@ -41,8 +41,8 @@
         </selectKey>
         -->
         INSERT INTO sys_menu
-        (id_,name_,permission_,path,parent_id_,icon_,component_,sort,keep_alive_,type_,create_time_,update_time_)
-        VALUES(#{id},#{name},#{permission},#{path},#{parentId},#{icon},#{component},#{sort},#{keepAlive},#{type},now(),now())
+        (id_,name_,permission_,path_,parent_id_,icon_,component_,sort_,type_,create_time_,update_time_)
+        VALUES(#{id},#{name},#{permission},#{path},#{parentId},#{icon},#{component},#{sort},#{type},now(),now())
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -97,12 +97,14 @@
         LEFT JOIN sys_role_menu srm ON sur.role_id_ = srm.role_id_
         LEFT JOIN sys_menu sm ON srm.menu_id_ = sm.id_
         <include refid="queryTree"/>
+--         GROUP BY sm.id_
+        ORDER BY sm.sort_ DESC
         <include refid="global.limit"/>
     </select>
 
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
-        SELECT COUNT(sm.id_) FROM sys_user_role sur
+        SELECT COUNT(DISTINCT sm.id_) FROM sys_user_role sur
         LEFT JOIN sys_role_menu srm ON sur.role_id_ = srm.role_id_
         LEFT JOIN sys_menu sm ON srm.menu_id_ = sm.id_
         <include refid="queryTree"/>
@@ -124,7 +126,7 @@
 
     <!-- 根据权限标识查菜单 -->
     <select id="findMenuByPermission" resultMap="SysMenu">
-        SELECT * FROM `sys_menu` WHERE `permission_` = #{permission} AND del_flag_ = 0
+        SELECT * FROM `sys_menu` WHERE `permission_` = #{permission}
     </select>
     <sql id="queryTree">
         <where>
@@ -145,6 +147,15 @@
         LEFT JOIN sys_role_menu srm ON sur.role_id_ = srm.role_id_
         LEFT JOIN sys_menu sm ON srm.menu_id_ = sm.id_
         <include refid="queryTree"/>
+--         GROUP BY sm.id_
         ORDER BY sm.sort_
     </select>
+
+    <select id="findCountBySys" resultType="java.lang.Integer">
+        SELECT COUNT(id_) FROM sys_menu WHERE del_flag_ = #{delFlag} AND parent_id_ = #{parentId}
+    </select>
+
+    <select id="findList" resultMap="SysMenu">
+        SELECT * FROM sys_menu WHERE del_flag_ = #{delFlag} AND parent_id_ = #{parentId} ORDER BY sort_ DESC
+    </select>
 </mapper>

+ 6 - 6
mec-web/src/main/java/com/ym/mec/web/controller/education/CourseHomeworkController.java

@@ -7,10 +7,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @Author Joburgess
@@ -25,8 +22,11 @@ public class CourseHomeworkController extends BaseController {
     private CourseHomeworkService courseHomeworkService;
 
     @ApiOperation(value = "分页查询作业列表")
-    @PostMapping(value = "/queryPage",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
-    public Object queryPage(@RequestBody CourseHomeworkQueryInfo queryInfo){
+    @GetMapping(value = "/queryPage",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    public Object queryPage(@RequestBody(required = false) CourseHomeworkQueryInfo queryInfo){
+        if(queryInfo == null){
+            queryInfo = new CourseHomeworkQueryInfo();
+        }
         return succeed(courseHomeworkService.queryPage(queryInfo));
     }
 

+ 5 - 2
mec-web/src/main/java/com/ym/mec/web/controller/student/StudentCourseHomeworkController.java

@@ -48,8 +48,11 @@ public class StudentCourseHomeworkController extends BaseController {
     }
 
     @ApiOperation(value = "分页查询作业列表")
-    @PostMapping(value = "/queryPage",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
-    public Object queryPage(@RequestBody CourseHomeworkQueryInfo queryInfo){
+    @GetMapping(value = "/queryPage",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+    public Object queryPage(@RequestBody(required = false) CourseHomeworkQueryInfo queryInfo){
+        if(queryInfo == null){
+            queryInfo = new CourseHomeworkQueryInfo();
+        }
         return succeed(studentCourseHomeworkService.queryPage(queryInfo));
     }