Просмотр исходного кода

作者:张哲
时间:2023/04/10
类型:优化
描述:里程碑(3) 专辑列表优化、知识删除优化

zizg 1 год назад
Родитель
Сommit
5ca85216fe

+ 6 - 0
src/main/java/com/redxun/knowledge/album/entity/dao/AlbumInfo.java

@@ -72,6 +72,12 @@ public class AlbumInfo  extends BaseExtEntity<String> {
     @TableField(exist = false)
     private Integer versionState;
 
+    @TableField(exist = false)
+    private Integer knowledgeTotal;
+
+    @TableField(exist = false)
+    private Integer yelpTotal;
+
 
 
     @Override

+ 1 - 1
src/main/java/com/redxun/knowledge/album/mapper/AlbumInfoMapper.java

@@ -15,7 +15,7 @@ import java.util.Map;
 @Mapper
 public interface AlbumInfoMapper extends BaseDao<AlbumInfo> {
 
-    List<AlbumInfo> findAllAlbumInfo(@Param("params") Map<String, Object> params, @Param("w") Map<String, Object> order);
+    IPage findAllAlbumInfo(IPage<AlbumInfo> page, @Param("params") Map<String, Object> params, @Param("order") String order);
 
     /**
      * 版本收入知识量

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

@@ -158,7 +158,7 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
                     //查询我的专辑
                     IPage page1 = albumInfoMapper.findAllAlbumInfoByOwnerIds(queryFilter.getPage(), queryFilter.getParams(), params);
                     List<AlbumInfo> records = page1.getRecords();
-                    List<AlbumInfoVo> albumInfoVoList = pageInfo(records);
+                    List<AlbumInfoVo> albumInfoVoList = pageInfo(records,null);
                     page1.setRecords(albumInfoVoList);
                     return page1;
                 case "2":
@@ -174,7 +174,7 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
                     List<AlbumInfo> collect = ownerIdsList.stream().distinct().collect(Collectors.toList());
                     Page page2 = PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(), collect);
                     List<AlbumInfo> recordslist = page2.getRecords();
-                    List<AlbumInfoVo> albumInfoVoListResult = pageInfo(recordslist);
+                    List<AlbumInfoVo> albumInfoVoListResult = pageInfo(recordslist,null);
                     albumInfoVoListResult.stream().filter(e -> !e.getOwnerId().equals(userId)).forEach(h -> h.setVersionState(2));
                     page2.setRecords(albumInfoVoListResult);
                     return page2;
@@ -183,7 +183,7 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
                     queryFilter.getParams().put("userId", userService.queryLoginUser());
                     IPage page3 = albumInfoMapper.findAllAlbumInfoYelpByUserId(queryFilter.getPage(), queryFilter.getParams(), params);
                     List<AlbumInfo> result = page3.getRecords();
-                    List<AlbumInfoVo> albumInfoVoList3 = pageInfo(result);
+                    List<AlbumInfoVo> albumInfoVoList3 = pageInfo(result,null);
                     //不是我创建的专辑(状态设置为2 已发布)
                     albumInfoVoList3.stream().filter(e -> !e.getOwnerId().equals(userId)).forEach(h -> {
                         h.setVersionState(2);
@@ -193,31 +193,11 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
                     return page3;
             }
         }
-        List<AlbumInfo> collect = albumInfoMapper.findAllAlbumInfo(queryFilter.getParams(), params);
-        //List<AlbumInfo> collect = page.getRecords();
-        List<AlbumInfoVo> albumInfoVoList = pageInfo(collect);
-        if (queryFilter.getParams().containsKey("state")){
-            switch ((String) queryFilter.getParams().get("state")){
-                case "0":
-                    albumInfoVoList = albumInfoVoList.stream().filter(e -> e.getState() == 0).collect(Collectors.toList());
-                    break;
-                case "1":
-                    albumInfoVoList = albumInfoVoList.stream().filter(e -> e.getVersionState() == 1).collect(Collectors.toList());
-                    break;
-                case "2":
-                    albumInfoVoList = albumInfoVoList.stream().filter(e -> e.getVersionState() == 2).collect(Collectors.toList());
-                    break;
-                case "4":
-                    albumInfoVoList = albumInfoVoList.stream().filter(e -> e.getVersionState() == 4).collect(Collectors.toList());
-                    break;
-            }
-        }
-        //排序
-        if (StringUtils.isNotEmpty((String) queryFilter.getParams().get("orderBySql"))){
-            albumInfoVoList = albumInfoSort((String) queryFilter.getParams().get("orderBySql"),albumInfoVoList);
-        }
-        //page.setRecords(albumInfoVoList);
-        return PageListUtils.getPages(queryFilter.getPage().getCurrent(), queryFilter.getPage().getSize(),albumInfoVoList);
+        IPage page = albumInfoMapper.findAllAlbumInfo(queryFilter.getPage(),queryFilter.getParams(), queryFilter.getSortSql());
+        List<AlbumInfo> collect = page.getRecords();
+        List<AlbumInfoVo> albumInfoVoList = pageInfo(collect,"manager");
+        page.setRecords(albumInfoVoList);
+        return page;
     }
 
     /**
@@ -226,7 +206,7 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
      * @param collect
      * @return
      */
-    private List<AlbumInfoVo> pageInfo(List<AlbumInfo> collect) {
+    private List<AlbumInfoVo> pageInfo(List<AlbumInfo> collect,String manager) {
         String userId = userService.queryLoginUser();
         List<AlbumInfoVo> albumInfoVoList = collect.parallelStream().map(e -> {
             AlbumInfoVo albumInfoVo = new AlbumInfoVo();
@@ -245,38 +225,42 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
             }, threadPoolExecutor);
             //专辑收录知识量(当前生效版本各个目录中知识数量总和)
             CompletableFuture<Void> countKnowledgeCompletableFuture = CompletableFuture.runAsync(() -> {
-                AlbumVersion albumVersion = albumVersionMapper.
-                        selectOne(new LambdaQueryWrapper<AlbumVersion>().
-                                eq(AlbumVersion::getAlbumId, e.getPkId()).
-                                eq(AlbumVersion::getState, 2));
-                //没有生效的专辑(第一次创建专辑时的情况)
-                if (albumVersion == null) {
-                    AlbumVersion albumVersionFirst = albumVersionMapper.
+                if (manager == null) {
+                    AlbumVersion albumVersion = albumVersionMapper.
                             selectOne(new LambdaQueryWrapper<AlbumVersion>().
                                     eq(AlbumVersion::getAlbumId, e.getPkId()).
-                                    eq(AlbumVersion::getState, 1));
-                    if (albumVersionFirst == null) {
-                        AlbumVersion albumVersionFour = albumVersionMapper.
+                                    eq(AlbumVersion::getState, 2));
+                    //没有生效的专辑(第一次创建专辑时的情况)
+                    if (albumVersion == null) {
+                        AlbumVersion albumVersionFirst = albumVersionMapper.
                                 selectOne(new LambdaQueryWrapper<AlbumVersion>().
                                         eq(AlbumVersion::getAlbumId, e.getPkId()).
-                                        eq(AlbumVersion::getState, 4));
-                        Integer countKnowledge = albumInfoMapper.selectCountKnowledge(e.getPkId(), albumVersionFour.getPkId());
-                        albumInfoVo.setKnowledgeTotal(countKnowledge);
+                                        eq(AlbumVersion::getState, 1));
+                        if (albumVersionFirst == null) {
+                            AlbumVersion albumVersionFour = albumVersionMapper.
+                                    selectOne(new LambdaQueryWrapper<AlbumVersion>().
+                                            eq(AlbumVersion::getAlbumId, e.getPkId()).
+                                            eq(AlbumVersion::getState, 4));
+                            Integer countKnowledge = albumInfoMapper.selectCountKnowledge(e.getPkId(), albumVersionFour.getPkId());
+                            albumInfoVo.setKnowledgeTotal(countKnowledge);
+                        } else {
+                            Integer countKnowledge = albumInfoMapper.selectCountKnowledge(e.getPkId(), albumVersionFirst.getPkId());
+                            albumInfoVo.setKnowledgeTotal(countKnowledge);
+                        }
                     } else {
-                        Integer countKnowledge = albumInfoMapper.selectCountKnowledge(e.getPkId(), albumVersionFirst.getPkId());
+                        Integer countKnowledge = albumInfoMapper.selectCountKnowledge(e.getPkId(), albumVersion.getPkId());
                         albumInfoVo.setKnowledgeTotal(countKnowledge);
                     }
-                } else {
-                    Integer countKnowledge = albumInfoMapper.selectCountKnowledge(e.getPkId(), albumVersion.getPkId());
-                    albumInfoVo.setKnowledgeTotal(countKnowledge);
                 }
             }, threadPoolExecutor);
             //专辑点评量(当前专辑中通过审核的点评量总和)
             CompletableFuture<Void> countYelpCompletableFuture = CompletableFuture.runAsync(() -> {
-                Integer countYelp = albumYelpMapper.selectCount(new LambdaQueryWrapper<AlbumYelp>().
-                        eq(AlbumYelp::getAlbumId, e.getPkId()).
-                        eq(AlbumYelp::getState, 1));
-                albumInfoVo.setYelpTotal(countYelp);
+                if (manager == null) {
+                    Integer countYelp = albumYelpMapper.selectCount(new LambdaQueryWrapper<AlbumYelp>().
+                            eq(AlbumYelp::getAlbumId, e.getPkId()).
+                            eq(AlbumYelp::getState, 1));
+                    albumInfoVo.setYelpTotal(countYelp);
+                }
             }, threadPoolExecutor);
             //其他参数
             CompletableFuture<Void> anotherCompletableFuture = CompletableFuture.runAsync(() -> {
@@ -329,42 +313,6 @@ public class AlbumInfoServiceImpl extends SuperServiceImpl<AlbumInfoMapper, Albu
         return albumInfoVoList;
     }
 
-    private List<AlbumInfoVo> albumInfoSort(String sort,List<AlbumInfoVo> albumInfoVoList){
-        switch (sort) {
-            case "knowledgeTotal desc":
-                albumInfoVoList = albumInfoVoList.stream().sorted((t1, t2) -> t2.getKnowledgeTotal().compareTo(t1.getKnowledgeTotal())).collect(Collectors.toList());
-                break;
-            case "knowledgeTotal asc":
-                albumInfoVoList = albumInfoVoList.stream().sorted(Comparator.comparing(AlbumInfoVo::getKnowledgeTotal)).collect(Collectors.toList());
-                break;
-            case "yelpTotal desc":
-                albumInfoVoList = albumInfoVoList.stream().sorted((t1, t2) -> t2.getYelpTotal().compareTo(t1.getYelpTotal())).collect(Collectors.toList());
-                break;
-            case "yelpTotal asc":
-                albumInfoVoList = albumInfoVoList.stream().sorted(Comparator.comparing(AlbumInfoVo::getYelpTotal)).collect(Collectors.toList());
-                break;
-            case "views desc":
-                albumInfoVoList = albumInfoVoList.stream().sorted((t1, t2) -> t2.getViews().compareTo(t1.getViews())).collect(Collectors.toList());
-                break;
-            case "views asc":
-                albumInfoVoList = albumInfoVoList.stream().sorted(Comparator.comparing(AlbumInfoVo::getViews)).collect(Collectors.toList());
-                break;
-            case "createTime desc":
-                albumInfoVoList = albumInfoVoList.stream().sorted((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())).collect(Collectors.toList());
-                break;
-            case "createTime asc":
-                albumInfoVoList = albumInfoVoList.stream().sorted(Comparator.comparing(AlbumInfoVo::getCreateTime)).collect(Collectors.toList());
-                break;
-            case "updateTime desc":
-                albumInfoVoList = albumInfoVoList.stream().sorted((t1, t2) -> t2.getUpdateTime().compareTo(t1.getUpdateTime())).collect(Collectors.toList());
-                break;
-            case "updateTime asc":
-                albumInfoVoList = albumInfoVoList.stream().sorted(Comparator.comparing(AlbumInfoVo::getUpdateTime)).collect(Collectors.toList());
-                break;
-        }
-        return albumInfoVoList;
-    }
-
     /**
      * 专辑详情
      *

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

@@ -117,7 +117,7 @@ public class KnowledgeController extends BaseController<Knowledge> {
     public JsonResult deleteKnowledge(@RequestParam("knowledgeId") String knowledgeId){
         Boolean result = knowledgeService.deleteKnowledge(knowledgeId);
         if (!result){
-            return JsonResult.Fail("该知识下还有关联banner,删除失败");
+            return JsonResult.Fail("删除失败,知识已关联其他模块");
         }
         return JsonResult.Success("删除成功!");
     }

+ 16 - 1
src/main/java/com/redxun/knowledge/service/KnowledgeServiceImpl.java

@@ -19,6 +19,8 @@ import com.redxun.common.tool.IdGenerator;
 import com.redxun.common.tool.StringUtils;
 import com.redxun.common.utils.ContextUtil;
 import com.redxun.dto.user.OsUserDto;
+import com.redxun.knowledge.album.entity.dao.AlbumCatalogueKnowledge;
+import com.redxun.knowledge.album.mapper.AlbumCatalogueKnowledgeMapper;
 import com.redxun.knowledge.common.MessageService;
 import com.redxun.knowledge.common.UserService;
 import com.redxun.knowledge.entity.dao.*;
@@ -27,6 +29,8 @@ import com.redxun.knowledge.entity.vo.KnowledgeApprovalListVo;
 import com.redxun.knowledge.entity.vo.KnowledgeApprovalVo;
 import com.redxun.knowledge.entity.vo.KnowledgeCategoryAdminVo;
 import com.redxun.knowledge.entity.vo.KnowledgeVo;
+import com.redxun.knowledge.map.entity.dao.MapContent;
+import com.redxun.knowledge.map.mapper.MapContentMapper;
 import com.redxun.knowledge.mapper.*;
 import com.redxun.knowledge.utils.DeduplicationUtil;
 import com.redxun.knowledge.utils.PageListUtils;
@@ -86,6 +90,12 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
     @Autowired
     private KnowledgeApproveServiceImpl knowledgeApproveService;
 
+    @Autowired
+    private MapContentMapper mapContentMapper;
+
+    @Autowired
+    private AlbumCatalogueKnowledgeMapper albumCatalogueKnowledgeMapper;
+
 
 
     @Override
@@ -539,8 +549,13 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
      */
     @Transactional(rollbackFor = Exception.class)
     public Boolean deleteKnowledge(String knowledgeId) {
+        Integer count = 0;
         // 查看是否关联着banner
-        Integer count = bannerMapper.selectCount(new QueryWrapper<Banner>().eq("KNOWLEDGE_ID", knowledgeId));
+        count = bannerMapper.selectCount(new QueryWrapper<Banner>().eq("KNOWLEDGE_ID", knowledgeId));
+        //查看是否关联着地图
+        count = mapContentMapper.selectCount(new QueryWrapper<MapContent>().eq("KNOWLEDGE_ID",knowledgeId));
+        //查看是否关联着专辑
+        count = albumCatalogueKnowledgeMapper.selectCount(new QueryWrapper<AlbumCatalogueKnowledge>().eq("KNOWLEDGE_ID",knowledgeId));
         if (count > 0){
             return false;
         }

+ 26 - 6
src/main/resources/mapper/knowledge/album/AlbumInfoMapper.xml

@@ -51,10 +51,22 @@
     </select>
 
     <select id="findAllAlbumInfo" resultType="com.redxun.knowledge.album.entity.dao.AlbumInfo" parameterType="java.util.Map">
-        select
-        <include refid="COLUMNS"/>,FULLNAME_
-        from KM_ALBUM_INFO ai
-        JOIN LEARNING_USER_DEV.OS_USER
+        select ai.*,s2.FULLNAME_ from (
+        select * from (
+        select t1.*,nvl(t2.yelpCount,0) yelpTotal from (
+        select av.ALBUM_ID,nvl(sum(count(*)) over (partition by VERSION_ID),0) knowledgeTotal,av.STATE versionState
+        from (
+        select *
+        from (select b.*, (ROW_NUMBER() OVER (PARTITION BY b.ALBUM_ID ORDER BY b.CREATE_TIME_ desc)) rn
+        from KM_ALBUM_VERSION b where IS_DEL = 0)
+        where rn = 1) av
+        left join KM_ALBUM_CATALOGUE catalogue on av.PK_ID = catalogue.VERSION_ID and catalogue.IS_DEL = 0
+        join KM_ALBUM_CATALOGUE_KNOWLEDGE knowledge ON catalogue.PK_ID = knowledge.CATALOGUE_ID and knowledge.IS_DEL = 0
+        group by VERSION_ID,av.ALBUM_ID,av.STATE) t1 left join (select ALBUM_ID, count(*) yelpCount
+        from KM_ALBUM_YELP
+        where IS_DEL = 0 and STATE = 1
+        group by ALBUM_ID) t2 on t1.ALBUM_ID = t2.ALBUM_ID) result1 join KM_ALBUM_INFO ai on result1.ALBUM_ID = ai.PK_ID where ai.IS_DEL = 0)
+        ai JOIN LEARNING_USER_DEV.OS_USER s2
         ON OWNER_ID = USER_ID_
         <where>
             <if test="@rx.Ognl@isNotEmpty(params.name)">
@@ -69,17 +81,25 @@
             <if test="@rx.Ognl@isNotEmpty(params.ownerName)">
                 and instr(FULLNAME_,#{params.ownerName}) > 0
             </if>
+            <if test="@rx.Ognl@isNotEmpty(params.state) and params.state == 0">
+                and ai.state = #{params.state}
+            </if>
+            <if test="@rx.Ognl@isNotEmpty(params.state) and params.state != 0">
+                and ai.versionState = #{params.state}
+            </if>
             <if test="@rx.Ognl@isNotEmpty(params.createTimeStart)">
                 and TO_CHAR(ai.CREATE_TIME_,'yyyy-mm-dd') &gt;= #{params.createTimeStart}
             </if>
             <if test="@rx.Ognl@isNotEmpty(params.createTimeEnd)">
                 and TO_CHAR(ai.CREATE_TIME_,'yyyy-mm-dd') &lt;= #{params.createTimeEnd}
             </if>
-            and ai.IS_DEL = 0
         </where>
-        <if test="@rx.Ognl@isEmpty(w.orderBySql)">
+        <if test="@rx.Ognl@isEmpty(order)">
             ORDER BY ai.STATE DESC, ai.CREATE_TIME_ DESC
         </if>
+        <if test="@rx.Ognl@isNotEmpty(order)">
+            ORDER BY ${order}
+        </if>
     </select>
 
     <select id="selectCountKnowledge" resultType="integer">