Browse Source

青涩知夏:修改为id默认排序

huanghuijie 4 years ago
parent
commit
964af0eaac

+ 9 - 0
src/main/java/com/sumbytes/helloblog/menu/controller/MenuController.java

@@ -61,4 +61,13 @@ public class MenuController {
     public Result delete(@PathVariable Long id){
         return menuService.deleteMenu(id);
     }
+
+
+    /**
+     * 前端菜单列表
+     */
+    @GetMapping("/front/v1/list")
+    public Result getFrontMenuList(MenuVO menuVO){
+        return menuService.getFrontMenuList(menuVO);
+    }
 }

+ 1 - 0
src/main/java/com/sumbytes/helloblog/menu/dao/MenuDao.java

@@ -18,4 +18,5 @@ public interface MenuDao extends BaseDao<Menu> {
      * 分页查询菜单表
      */
     List<Menu> selectMenuList(@Param("page") Page<Menu> page, @Param("condition") MenuVO menu);
+    List<Menu> selectMenuList(@Param("condition") MenuVO menu);
 }

+ 6 - 1
src/main/java/com/sumbytes/helloblog/menu/domain/vo/MenuVO.java

@@ -1,9 +1,12 @@
 package com.sumbytes.helloblog.menu.domain.vo;
 
 import com.sumbytes.common.base.domain.vo.BaseVO;
+import com.sumbytes.helloblog.menu.domain.po.Menu;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import java.util.List;
+
 
 @Data
 @Accessors(chain = true)
@@ -37,6 +40,8 @@ public class MenuVO extends BaseVO<MenuVO> {
 	/**
 	 * 排序
 	 */
-	private Integer sort; 
+	private Integer sort;
+
+	private List<Menu> child;
 	// columns END
 }

+ 5 - 0
src/main/java/com/sumbytes/helloblog/menu/service/MenuService.java

@@ -36,4 +36,9 @@ public interface MenuService {
      * 删除菜单表
      */
     Result deleteMenu(Long id);
+
+    /**
+     * 前端查询菜单列表
+     */
+    Result getFrontMenuList(MenuVO menuVO);
 }

+ 21 - 0
src/main/java/com/sumbytes/helloblog/menu/service/impl/MenuServiceImpl.java

@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 
@@ -73,4 +74,24 @@ public class MenuServiceImpl implements MenuService {
         this.menuDao.deleteById(id);
         return Result.createWithSuccessMessage();
     }
+
+
+    @Override
+    public Result getFrontMenuList(MenuVO menuVO) {
+        List<Menu> menus = menuDao.selectMenuList(menuVO.setParentId(0L));
+        List<MenuVO> menuVOS=new ArrayList<>();
+        menus.forEach(menu -> {
+            menuVOS.add(new MenuVO()
+                    .setId(menu.getId())
+                    .setIcon(menu.getIcon())
+                    .setTitle(menu.getTitle())
+                    .setParentId(menu.getParentId())
+                    .setSort(menu.getSort())
+                    .setUrl(menu.getUrl())
+                    .setChild(menuDao.selectMenuList(menuVO.setParentId(menu.getId())))
+            );
+        });
+        return Result.createWithModels(menuVOS);
+    }
+
 }

+ 1 - 1
src/main/resources/mapper/auth/AuthUserSocialMapper.xml

@@ -31,7 +31,7 @@
 			<if test="condition.isHome != null "> AND is_home=#{condition.isHome}</if>
 			<if test="condition.keywords != null and condition.keywords != ''"> AND code LIKE #{condition.keywords}</if>
 		</where>
-		ORDER BY create_time DESC
+		ORDER BY id DESC
 	</select>
 
 </mapper>

+ 1 - 1
src/main/resources/mapper/category/CategoryMapper.xml

@@ -41,6 +41,6 @@
                 AND name = #{condition.name}
             </if>
         </where>
-        ORDER BY create_time DESC
+        ORDER BY id DESC
     </select>
 </mapper>

+ 4 - 4
src/main/resources/mapper/menu/MenuMapper.xml

@@ -16,9 +16,9 @@
     </resultMap>
 	
 	<select id="selectMenuList" resultType="com.sumbytes.helloblog.menu.domain.po.Menu">
-        SELECT <include refid="Base_Column_List" />
-        FROM hello_blog_menu
-        <where>
+		SELECT <include refid="Base_Column_List" />
+		FROM hello_blog_menu
+		<where>
 			<if test="condition.keywords != null and condition.keywords != ''">title LIKE #{condition.keywords}</if>
 			<if test="condition.title != null and condition.title != ''">AND title = #{condition.title}</if>
 			<if test="condition.parentId != null">AND parent_id = #{condition.parentId}</if>
@@ -26,7 +26,7 @@
 			<if test="condition.sort != null and condition.sort != ''">AND sort = #{condition.sort}</if>
 			<if test="condition.url != null and condition.url != ''">AND url LIKE '%${condition.url}%'</if>
 		</where>
-		ORDER BY sort DESC
+		ORDER BY id DESC
     </select>
 	
 </mapper>

+ 1 - 1
src/main/resources/mapper/posts/PostsCommentsMapper.xml

@@ -31,7 +31,7 @@
             postsComments.posts_id = #{postsId}
         </where>
 
-        ORDER BY postsComments.create_time DESC
+        ORDER BY postsComments.id DESC
     </select>
 
     <select id="selectPostsCommentsList" resultType="com.sumbytes.helloblog.posts.domain.vo.PostsCommentsVO">

+ 2 - 2
src/main/resources/mapper/posts/PostsMapper.xml

@@ -79,7 +79,7 @@
                 ORDER BY posts.weight DESC
             </when>
             <otherwise>
-                ORDER BY posts.create_time DESC
+                ORDER BY posts.id DESC
             </otherwise>
         </choose>
     </select>
@@ -111,7 +111,7 @@
       FROM
         hello_blog_posts
       GROUP BY DATE_FORMAT( create_time, "%Y-%m-01 00:00:00" )
-      ORDER BY create_time DESC
+      ORDER BY id DESC
     </select>
     <select id="selectOneById" resultType="com.sumbytes.helloblog.posts.domain.po.Posts">
         SELECT