4
0
Эх сурвалжийг харах

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

ZizgZh 2 жил өмнө
parent
commit
0a05ca58e1

+ 1 - 1
src/main/java/com/redxun/knowledge/album/controller/AlbumYelpController.java

@@ -60,7 +60,7 @@ public class AlbumYelpController extends BaseController<AlbumYelp> {
     @GetMapping("list")
     public JsonResult list(@RequestParam("albumId") String albumId){
         JsonResult jsonResult = JsonResult.getSuccessResult("");
-        List<AlbumYelpListPcVo> albumYelpListPcVo = albumYelpService.listAll(albumId);
+        List<AlbumYelpListPcVo> albumYelpListPcVo = albumYelpService.listAll(albumId,"1");
         return jsonResult.setData(albumYelpListPcVo);
     }
 

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

@@ -22,14 +22,6 @@ public interface AlbumYelpMapper extends BaseDao<AlbumYelp> {
      */
     void deleteByAlbumId(String ids);
 
-    /**
-     * PC端分页查询一级点评信息(最多返回两条回复)
-     * @param page
-     * @param params
-     * @param order
-     * @return
-     */
-    IPage findAllYelpInfo(IPage page, @Param("params") Map<String, Object> params,@Param("w") Map<String, Object> order);
 
     /**
      * 管理端分页查询一级点评信息(最多返回两条回复)
@@ -47,4 +39,19 @@ public interface AlbumYelpMapper extends BaseDao<AlbumYelp> {
      */
     List<AlbumYelp> findListAllReplies(@Param("albumId")String albumId,@Param("userId") String userId,@Param("pkId") String pkId);
 
+    /**
+     * PC端与我相关的一级点评
+     * @param albumId
+     * @param userId
+     * @return
+     */
+    List<AlbumYelp> findListAllYelpInfoById(@Param("albumId")String albumId,@Param("userId") String userId);
+
+    /**
+     * PC端与我相关的回复
+     * @param albumId
+     * @param userId
+     * @return
+     */
+    List<AlbumYelp> findListAllRepliesById(@Param("albumId")String albumId,@Param("userId") String userId);
 }

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

@@ -418,7 +418,6 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
             albumApproveVoList.add(albumApproveVo);
         }
         albumVersionDetailVo.setApprovalFlows(albumApproveVoList);
-        // TODO: 2023/2/3  点评信息
         return albumVersionDetailVo;
     }
 

+ 67 - 32
src/main/java/com/redxun/knowledge/album/service/AlbumYelpServiceImpl.java

@@ -3,12 +3,15 @@ package com.redxun.knowledge.album.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.redxun.common.base.db.BaseDao;
 import com.redxun.common.base.db.BaseService;
 import com.redxun.common.base.db.PageHelper;
 import com.redxun.common.base.search.QueryFilter;
 import com.redxun.common.service.impl.SuperServiceImpl;
 import com.redxun.common.tool.IdGenerator;
+import com.redxun.common.tool.StringUtils;
 import com.redxun.knowledge.album.entity.consts.AlbumConst;
 import com.redxun.knowledge.album.entity.dao.*;
 import com.redxun.knowledge.album.entity.dto.YelpDto;
@@ -24,6 +27,7 @@ import com.redxun.knowledge.album.mapper.AlbumInfoMapper;
 import com.redxun.knowledge.album.mapper.AlbumVersionMapper;
 import com.redxun.knowledge.album.mapper.AlbumYelpMapper;
 import com.redxun.knowledge.common.UserService;
+import com.redxun.knowledge.utils.PageListUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -77,23 +81,57 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
      */
     @Override
     public IPage query(QueryFilter queryFilter) {
-        Map<String, Object> params = PageHelper.constructParams(queryFilter);
-        queryFilter.getParams().put("createBy",userService.queryLoginUser());
-        IPage page = albumYelpMapper.findAllYelpInfo(queryFilter.getPage(), queryFilter.getParams(), params);
-        List<AlbumYelp> albumYelpList = page.getRecords();
-        List<AlbumYelpListPcVo> albumYelpListPcVoList = albumYelpList.parallelStream().map(albumYelp -> {
-            AlbumYelpListPcVo albumYelpListPcVo = new AlbumYelpListPcVo();
-            albumYelpListPcVo.setPkId(albumYelp.getPkId());
-            albumYelpListPcVo.setState(albumYelp.getState());
-            albumYelpListPcVo.setCreateName(userService.queryOsUserDto(albumYelp.getCreateBy()).getFullName());
-            albumYelpListPcVo.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp.getCreateBy()).get("photo"));
-            albumYelpListPcVo.setContent(albumYelp.getContent());
-            albumYelpListPcVo.setCreateTime(albumYelp.getCreateTime());
-            // TODO: 2023/2/16  下级回复
-            return albumYelpListPcVo;
-        }).collect(Collectors.toList());
-        page.setRecords(albumYelpListPcVoList);
-        return page;
+        //获取请求参数
+        String userId = userService.queryLoginUser();
+        Map<String, Object> params = queryFilter.getParams();
+        String albumId = (String) params.get("albumId");
+        String type = (String) params.get("type");
+        List<AlbumYelpListPcVo> albumYelpListPcVoList = new ArrayList<>();
+        if ("1".equals(type)){
+            albumYelpListPcVoList = listAll(albumId,type);
+            Page page = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), albumYelpListPcVoList);
+            return page;
+        } else {
+            //与我相关
+            //1.1 与我相关的一级点评+回复
+            List<AlbumYelpListPcVo> finalAlbumYelpListPcVoList = listAll(albumId,type);
+            //收集一级点评Id
+            List<String> yelpId = finalAlbumYelpListPcVoList.parallelStream().map(AlbumYelpListPcVo::getPkId).collect(Collectors.toList());
+            //1.2 查询与我相关的回复
+            List<AlbumYelp> listAllRepliesById = albumYelpMapper.findListAllRepliesById(albumId, userId);
+            listAllRepliesById.forEach(e -> {
+                QueryWrapper<AlbumYelp> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("PK_ID",e.getYelpId());
+                AlbumYelp albumYelpParent = albumYelpMapper.selectOne(queryWrapper);
+                if (CollectionUtils.isNotEmpty(yelpId)){
+                    if (!yelpId.contains(albumYelpParent.getPkId())){
+                        AlbumYelpListPcVo albumYelpListPcVoParent = new AlbumYelpListPcVo();
+                        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);
+                    }
+                }
+            });
+            Page page = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(),
+                    finalAlbumYelpListPcVoList.stream().distinct().sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList()));
+            return page;
+        }
+    }
+
+    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);
+        }
     }
 
     /**
@@ -274,9 +312,14 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
      * @param albumId
      * @return
      */
-    public List<AlbumYelpListPcVo> listAll(String albumId) {
+    public List<AlbumYelpListPcVo> listAll(String albumId,String type) {
+        List<AlbumYelp> albumYelpList = new ArrayList<>();
         String userId = userService.queryLoginUser();
-        List<AlbumYelp> albumYelpList = albumYelpMapper.findListAllYelpInfo(albumId,userId);
+        if ("1".equals(type)){
+            albumYelpList = albumYelpMapper.findListAllYelpInfo(albumId,userId);
+        } else {
+            albumYelpList = albumYelpMapper.findListAllYelpInfoById(albumId, userId);
+        }
         List<AlbumYelpListPcVo> albumYelpListPcVoList = albumYelpList.parallelStream().map(albumYelp -> {
             AlbumYelpListPcVo albumYelpListPcVo = new AlbumYelpListPcVo();
             BeanUtils.copyProperties(albumYelp, albumYelpListPcVo);
@@ -284,16 +327,8 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
             albumYelpListPcVo.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp.getCreateBy()).get("photo"));
             //查询下级
             List<AlbumYelpListPcVo> replies = replies(albumYelp);
-            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);
-            }
+            //组装下级
+            replyCount(albumYelpListPcVo,replies);
             return albumYelpListPcVo;
         }).collect(Collectors.toList());
         return albumYelpListPcVoList;
@@ -309,9 +344,9 @@ public class AlbumYelpServiceImpl extends SuperServiceImpl<AlbumYelpMapper, Albu
         List<AlbumYelp> albumYelpList = albumYelpMapper.findListAllReplies(albumYelp.getAlbumId(),userId,albumYelp.getPkId());
         List<AlbumYelpListPcVo> albumYelpListPcVoList = albumYelpList.parallelStream().map(albumYelp1 -> {
             AlbumYelpListPcVo albumYelpListPcVo = new AlbumYelpListPcVo();
-            BeanUtils.copyProperties(albumYelp, albumYelpListPcVo);
-            albumYelpListPcVo.setCreateName(userService.queryOsUserDto(albumYelp.getCreateBy()).getFullName());
-            albumYelpListPcVo.setCreatePhoto((String) userService.querySexAndPhoto(albumYelp.getCreateBy()).get("photo"));
+            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);

+ 20 - 7
src/main/resources/mapper/knowledge/album/AlbumYelpMapper.xml

@@ -48,34 +48,47 @@
         where ALBUM_ID = #{albumId}
     </delete>
 
-    <select id="findAllYelpInfo" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
+
+    <select id="findListAllYelpInfo" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
         select
-        <include refid="COLUMNS"/>
+        distinct PK_ID,ALBUM_ID,TYPE,CONTENT,YELP_ID,STATE,IS_DEL,COMPANY_ID_,CREATE_DEP_ID_,TENANT_ID_,CREATE_BY_,CREATE_TIME_,
+        UPDATE_BY_,UPDATE_TIME_,APPROVAL_STATE
         from KM_ALBUM_YELP
         <where>
-            (STATE = 1 or CREATE_BY_ = #{params.createBy}) and TYPE = 1 and IS_DEL = 0
+            (STATE = 1 or CREATE_BY_ = #{userId}) and ALBUM_ID = #{albumId} and TYPE = 1 and IS_DEL = 0
         </where>
         order by CREATE_TIME_
     </select>
 
-    <select id="findListAllYelpInfo" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
+    <select id="findListAllReplies" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
         select
         distinct PK_ID,ALBUM_ID,TYPE,CONTENT,YELP_ID,STATE,IS_DEL,COMPANY_ID_,CREATE_DEP_ID_,TENANT_ID_,CREATE_BY_,CREATE_TIME_,
         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 or CREATE_BY_ = #{userId}) and ALBUM_ID = #{albumId} and TYPE = 2 and YELP_ID = #{pkId} and IS_DEL = 0
         </where>
         order by CREATE_TIME_
     </select>
 
-    <select id="findListAllReplies" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
+    <select id="findListAllYelpInfoById" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
         select
         distinct PK_ID,ALBUM_ID,TYPE,CONTENT,YELP_ID,STATE,IS_DEL,COMPANY_ID_,CREATE_DEP_ID_,TENANT_ID_,CREATE_BY_,CREATE_TIME_,
         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
+            CREATE_BY_ = #{userId} and ALBUM_ID = #{albumId} and TYPE = 1 and IS_DEL = 0
+        </where>
+        order by CREATE_TIME_
+    </select>
+
+    <select id="findListAllRepliesById" resultType="com.redxun.knowledge.album.entity.dao.AlbumYelp">
+        select
+        distinct PK_ID,ALBUM_ID,TYPE,CONTENT,YELP_ID,STATE,IS_DEL,COMPANY_ID_,CREATE_DEP_ID_,TENANT_ID_,CREATE_BY_,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
         </where>
         order by CREATE_TIME_
     </select>