Browse Source

作者:张哲
时间:2023/02/20
类型:优化
描述:里程碑(2)点评优化

ZizgZh 2 years ago
parent
commit
cd859a2efc

+ 1 - 1
src/main/java/com/redxun/knowledge/album/entity/enums/AlbumVersionEnum.java

@@ -13,7 +13,7 @@ public enum AlbumVersionEnum {
 
     APPROVE_PROGRESS(1,"审核中"),
     FORCE_PROGRESS(2,"已发布"),
-    NO_FORCE(3,""),
+    NO_FORCE(3,"未生效"),
     REJECT(4,"驳回");
 
 

+ 3 - 0
src/main/java/com/redxun/knowledge/album/entity/vo/AlbumYelpListPcVo.java

@@ -59,6 +59,9 @@ public class AlbumYelpListPcVo implements Serializable {
     @ApiModelProperty("回复内容")
     private List<AlbumYelpListPcVo> replies;
 
+    @ApiModelProperty("上级Id")
+    private String yelpId;
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;

+ 4 - 4
src/main/java/com/redxun/knowledge/album/mapper/AlbumYelpMapper.java

@@ -3,6 +3,7 @@ package com.redxun.knowledge.album.mapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.redxun.common.base.db.BaseDao;
 import com.redxun.knowledge.album.entity.dao.AlbumYelp;
+import com.redxun.knowledge.album.entity.vo.AlbumYelpListPcVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -24,14 +25,14 @@ public interface AlbumYelpMapper extends BaseDao<AlbumYelp> {
 
 
     /**
-     * 管理端分页查询一级点评信息(最多返回两条回复)
+     * 管理端分页查询一级点评信息(最多返回两条回复)(审核通过的)
      * @param userId
      * @return
      */
     List<AlbumYelp> findListAllYelpInfo(@Param("albumId")String albumId,@Param("userId") String userId);
 
     /**
-     * 查询回复信息(根为一级评论)
+     * 查询回复信息(根为一级评论)(审核通过的)
      * @param albumId
      * @param userId
      * @param pkId
@@ -53,7 +54,7 @@ public interface AlbumYelpMapper extends BaseDao<AlbumYelp> {
      * @param userId
      * @return
      */
-    List<AlbumYelp> findListAllRepliesById(@Param("albumId")String albumId,@Param("userId") String userId);
+    List<AlbumYelpListPcVo> findListAllRepliesById(@Param("albumId")String albumId, @Param("userId") String userId, @Param("yelpId") String yelpId);
 
     /**
      * 清除下级回复
@@ -69,5 +70,4 @@ public interface AlbumYelpMapper extends BaseDao<AlbumYelp> {
 
 
     List<AlbumYelp> findListAllRepliesByYelpId(@Param("albumId")String albumId,@Param("userId") String userId,@Param("yelp") String yelp);
-
 }

+ 1 - 1
src/main/java/com/redxun/knowledge/album/service/AlbumInfoServiceImpl.java

@@ -191,7 +191,7 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
                         AlbumInfo albumInfo = albumInfoMapper.selectById(albumYelp.getAlbumId());
                         return albumInfo;
                     }).collect(Collectors.toList());
-                    List<AlbumInfoVo> albumInfoVoListYelp = pageInfo(albumInfos.stream().
+                    List<AlbumInfoVo> albumInfoVoListYelp = pageInfo(albumInfos.stream().filter(e -> e.getState() == 1).
                             sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList()));
                     Page page3 = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), albumInfoVoListYelp);
                     return page3;

+ 6 - 2
src/main/java/com/redxun/knowledge/album/service/AlbumYelpApproveServiceImpl.java

@@ -164,7 +164,9 @@ public class AlbumYelpApproveServiceImpl extends SuperServiceImpl<AlbumYelpAppro
             }
         }
         if ("1".equals(type)) {
-            Page pageResult = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), albumApproveListVos);
+            List<AlbumYelpApproveListVo> result = albumApproveListVos.stream().
+                    sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList());
+            Page pageResult = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), result);
             return pageResult;
         } else {
             //获取当前登录人的userId和deptId
@@ -181,7 +183,9 @@ public class AlbumYelpApproveServiceImpl extends SuperServiceImpl<AlbumYelpAppro
                     albumApproveListVoUser.add(albumApproveListVo);
                 }
             });
-            Page pageResult = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), albumApproveListVoUser);
+            List<AlbumYelpApproveListVo> result = albumApproveListVoUser.stream().
+                    sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList());
+            Page pageResult = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), result);
             return pageResult;
         }
     }

+ 64 - 51
src/main/java/com/redxun/knowledge/album/service/AlbumYelpServiceImpl.java

@@ -75,7 +75,7 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
 
 
     /**
-     * PC端分页查询一级点评信息(最多返回两条回复)
+     * PC端分页查询一级点评信息(与二级回复一同返回)
      * @param queryFilter
      * @return
      */
@@ -88,18 +88,40 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
         String type = (String) params.get("type");
         List<AlbumYelpListPcVo> albumYelpListPcVoList = new ArrayList<>();
         if ("1".equals(type)){
-            albumYelpListPcVoList = listAll(albumId,type);
+            //审核通过的点评和我提交的点评
+            albumYelpListPcVoList = listAll(albumId, "2");
             Page page = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), albumYelpListPcVoList);
             return page;
         } else {
             //与我相关
             //1.1 与我相关的一级点评+回复
-            List<AlbumYelpListPcVo> finalAlbumYelpListPcVoList = listAll(albumId,type);
+            List<AlbumYelp> albumYelpList = albumYelpMapper.findListAllYelpInfoById(albumId, userId);
+            List<AlbumYelpListPcVo> result = albumYelpList.parallelStream().map(albumYelp -> {
+                AlbumYelpListPcVo albumYelpListPcVo = new AlbumYelpListPcVo();
+                BeanUtils.copyProperties(albumYelp, albumYelpListPcVo);
+                albumYelpListPcVo.setCreateName(userService.queryOsUserDto(albumYelp.getCreateBy()).getFullName());
+                albumYelpListPcVo.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp.getCreateBy()).get("photo"));
+                //与我相关的下级
+                List<AlbumYelpListPcVo> listAllRepliesById = albumYelpMapper.findListAllRepliesById(albumId, userId, albumYelp.getPkId());
+                List<AlbumYelpListPcVo> albumYelpListPcVoList1 = listAllRepliesById.stream().map(albumYelp1 -> {
+                    AlbumYelpListPcVo albumYelpListPcVo1 = new AlbumYelpListPcVo();
+                    BeanUtils.copyProperties(albumYelp1, albumYelpListPcVo1);
+                    albumYelpListPcVo1.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp1.getCreateName()).get("photo"));
+                    albumYelpListPcVo1.setCreateName(userService.queryOsUserDto(albumYelp1.getCreateName()).getFullName());
+                    return albumYelpListPcVo1;
+                }).collect(Collectors.toList());
+                albumYelpListPcVo.setReplyCount(listAllRepliesById.size());
+                albumYelpListPcVo.setReplies(albumYelpListPcVoList1);
+                return albumYelpListPcVo;
+            }).collect(Collectors.toList());
             //收集一级点评Id
-            List<String> yelpId = finalAlbumYelpListPcVoList.parallelStream().map(AlbumYelpListPcVo::getPkId).collect(Collectors.toList());
+            List<String> yelpId = result.parallelStream().map(AlbumYelpListPcVo::getPkId).collect(Collectors.toList());
             //1.2 查询与我相关的回复
-            List<AlbumYelp> listAllRepliesById = albumYelpMapper.findListAllRepliesById(albumId, userId);
+            List<AlbumYelpListPcVo> listAllRepliesById = albumYelpMapper.findListAllRepliesById(albumId, userId, null);
             listAllRepliesById.forEach(e -> {
+                e.setCreatePhoto((String) userService.querySexAndPhoto(e.getCreateName()).get("photo"));
+                e.setCreateName(userService.queryOsUserDto(e.getCreateName()).getFullName());
+                //查询到父节点
                 QueryWrapper<AlbumYelp> queryWrapper = new QueryWrapper<>();
                 queryWrapper.eq("PK_ID",e.getYelpId());
                 AlbumYelp albumYelpParent = albumYelpMapper.selectOne(queryWrapper);
@@ -109,14 +131,24 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
                         BeanUtils.copyProperties(albumYelpParent, albumYelpListPcVoParent);
                         albumYelpListPcVoParent.setCreateName(userService.queryOsUserDto(albumYelpParent.getCreateBy()).getFullName());
                         albumYelpListPcVoParent.setCreatePhoto((String) userService.querySexAndPhoto(albumYelpParent.getCreateBy()).get("photo"));
-                        List<AlbumYelpListPcVo> replies = replies(albumYelpParent);
-                        replyCount(albumYelpListPcVoParent,replies);
-                        finalAlbumYelpListPcVoList.add(albumYelpListPcVoParent);
+                        //把子节点加到父节点中
+                        List<AlbumYelpListPcVo> child = new ArrayList<>();
+                        child.add(e);
+                        albumYelpListPcVoParent.setReplies(child);
+                        //把父节点加入到结果集
+                        result.add(albumYelpListPcVoParent);
                     }
                 }
             });
-            Page page = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(),
-                    finalAlbumYelpListPcVoList.stream().distinct().sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList()));
+            //计算结果集中回复数量统计以及排序
+            List<AlbumYelpListPcVo> collect = result.stream().distinct().sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList());
+            collect.forEach(e -> {
+                List<AlbumYelpListPcVo> replies = e.getReplies().stream().sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList());
+                if (CollectionUtils.isNotEmpty(replies)){
+                    e.setReplyCount(replies.size());
+                }
+            });
+            Page page = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(),collect);
             return page;
         }
     }
@@ -260,7 +292,7 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
         albumInfoDetailVo.setVersionStateName(AlbumVersionEnum.getMessage(albumVersions.get(0).getState()));
         //专辑点评量(当前专辑中通过审核的点评量总和)
         Integer countYelp = albumYelpMapper.selectCount(new LambdaQueryWrapper<AlbumYelp>().
-                eq(AlbumYelp::getAlbumId, pkId).
+                eq(AlbumYelp::getAlbumId, albumInfo.getPkId()).
                 eq(AlbumYelp::getState, 1));
         albumInfoDetailVo.setYelpTotal(countYelp);
         albumYelpInfoVo.setAblum(albumInfoDetailVo);
@@ -295,34 +327,44 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
     }
 
     /**
-     * 根据知识专辑ID获取点评信息列表
+     * 根据知识专辑ID获取点评信息列表(管理端)
      * @param albumId
      * @return
      */
     public List<AlbumYelpListPcVo> listAll(String albumId,String type) {
         List<AlbumYelp> albumYelpList = new ArrayList<>();
         String userId = userService.queryLoginUser();
-        if ("1".equals(type)){
-            albumYelpList = albumYelpMapper.findListAllYelpInfo(albumId,userId);
-        } else {
-            albumYelpList = albumYelpMapper.findListAllYelpInfoById(albumId, userId);
-        }
+        albumYelpList = albumYelpMapper.findListAllYelpInfo(albumId,userId);
         List<AlbumYelpListPcVo> albumYelpListPcVoList = albumYelpList.parallelStream().map(albumYelp -> {
             AlbumYelpListPcVo albumYelpListPcVo = new AlbumYelpListPcVo();
             BeanUtils.copyProperties(albumYelp, albumYelpListPcVo);
             albumYelpListPcVo.setCreateName(userService.queryOsUserDto(albumYelp.getCreateBy()).getFullName());
             albumYelpListPcVo.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp.getCreateBy()).get("photo"));
-            //查询下级
             List<AlbumYelpListPcVo> replies = replies(albumYelp);
-            //组装下级
-            replyCount(albumYelpListPcVo,replies);
+            if("1".equals(type)){
+                //查询下级
+                //组装下级
+                if (replies.size() == 0) {
+                    albumYelpListPcVo.setReplyCount(0);
+                    albumYelpListPcVo.setReplies(null);
+                } else if (replies.size() >= 2){
+                    albumYelpListPcVo.setReplyCount(replies.size());
+                    albumYelpListPcVo.setReplies(replies.stream().limit(2).collect(Collectors.toList()));
+                } else {
+                    albumYelpListPcVo.setReplyCount(replies.size());
+                    albumYelpListPcVo.setReplies(replies);
+                }
+            } else {
+                //查询下级
+                albumYelpListPcVo.setReplies(replies);
+            }
             return albumYelpListPcVo;
         }).collect(Collectors.toList());
         return albumYelpListPcVoList;
     }
 
     /**
-     * 查询回复信息(根为一级评论)
+     * 查询回复信息(根为一级评论 管理端)
      * @param albumYelp
      * @return
      */
@@ -334,42 +376,13 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
             BeanUtils.copyProperties(albumYelp1, albumYelpListPcVo);
             albumYelpListPcVo.setCreateName(userService.queryOsUserDto(albumYelp1.getCreateBy()).getFullName());
             albumYelpListPcVo.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp1.getCreateBy()).get("photo"));
-            List<AlbumYelpListPcVo> replies = replies(albumYelp1);
-            if (replies.size() == 0) {
-                albumYelpListPcVo.setReplyCount(0);
-                albumYelpListPcVo.setReplies(null);
-            } else if (replies.size() >= 2){
-                albumYelpListPcVo.setReplyCount(replies.size());
-                albumYelpListPcVo.setReplies(replies.stream().limit(2).collect(Collectors.toList()));
-            } else {
-                albumYelpListPcVo.setReplyCount(replies.size());
-                albumYelpListPcVo.setReplies(replies);
-            }
             return albumYelpListPcVo;
         }).collect(Collectors.toList());
         return albumYelpListPcVoList;
     }
 
     /**
-     * 下级点评数据封装
-     * @param albumYelpListPcVoParent
-     * @param replies
-     */
-    private void replyCount(AlbumYelpListPcVo albumYelpListPcVoParent,List<AlbumYelpListPcVo> replies){
-        if (replies.size() == 0) {
-            albumYelpListPcVoParent.setReplyCount(0);
-            albumYelpListPcVoParent.setReplies(null);
-        } else if (replies.size() >= 2){
-            albumYelpListPcVoParent.setReplyCount(replies.size());
-            albumYelpListPcVoParent.setReplies(replies.stream().limit(2).collect(Collectors.toList()));
-        } else {
-            albumYelpListPcVoParent.setReplyCount(replies.size());
-            albumYelpListPcVoParent.setReplies(replies);
-        }
-    }
-
-    /**
-     * PC端获取点评回复列表
+     * PC端获取点评回复列表(管理端同样适用)(PC端已废弃)
      * @param queryFilter
      * @return
      */

+ 9 - 6
src/main/resources/mapper/knowledge/album/AlbumYelpMapper.xml

@@ -55,7 +55,7 @@
         UPDATE_BY_,UPDATE_TIME_,APPROVAL_STATE
         from KM_ALBUM_YELP
         <where>
-            (STATE = 1 or CREATE_BY_ = #{userId}) and ALBUM_ID = #{albumId} and TYPE = 1 and IS_DEL = 0
+            STATE = 1 and ALBUM_ID = #{albumId} and TYPE = 1 and IS_DEL = 0
         </where>
         order by CREATE_TIME_ desc
     </select>
@@ -66,7 +66,7 @@
         UPDATE_BY_,UPDATE_TIME_,APPROVAL_STATE
         from KM_ALBUM_YELP
         <where>
-            (STATE = 1 or CREATE_BY_ = #{userId}) and ALBUM_ID = #{albumId} and TYPE = 2 and YELP_ID = #{pkId} and IS_DEL = 0
+            STATE = 1  and ALBUM_ID = #{albumId} and TYPE = 2 and YELP_ID = #{pkId} and IS_DEL = 0
         </where>
         order by CREATE_TIME_ desc
     </select>
@@ -82,13 +82,17 @@
         order by CREATE_TIME_ desc
     </select>
 
-    <select id="findListAllRepliesById" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
+    <select id="findListAllRepliesById" resultType="com.redxun.knowledge.album.entity.vo.AlbumYelpListPcVo">
         select
-        distinct PK_ID,ALBUM_ID,TYPE,CONTENT,YELP_ID,STATE,IS_DEL,COMPANY_ID_,CREATE_DEP_ID_,TENANT_ID_,CREATE_BY_,CREATE_TIME_,
+        distinct PK_ID,ALBUM_ID,TYPE,CONTENT,YELP_ID,STATE,IS_DEL,COMPANY_ID_,CREATE_DEP_ID_,TENANT_ID_,CREATE_BY_ as createName,CREATE_TIME_,
         UPDATE_BY_,UPDATE_TIME_,APPROVAL_STATE
         from KM_ALBUM_YELP
         <where>
-            CREATE_BY_ = #{userId} and ALBUM_ID = #{albumId} and TYPE = 2 and IS_DEL = 0
+            CREATE_BY_ = #{userId} and ALBUM_ID = #{albumId}
+            <if test="yelpId != null and yelpId != ''">
+                and YELP_ID = #{yelpId}
+            </if>
+            and TYPE = 2 and IS_DEL = 0
         </where>
         order by CREATE_TIME_ desc
     </select>
@@ -116,7 +120,6 @@
         order by CREATE_TIME_ desc
     </select>
 
-
 </mapper>