Jelajahi Sumber

优化代码

fangzhen 5 bulan lalu
induk
melakukan
91b297fe2b

+ 7 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -155,10 +155,15 @@ public class CommunityArticleController extends BaseController {
             return AjaxResult.error("参数异常!");
         }
         try {
+            //文章删除
             CommunityArticle communityArticle = new CommunityArticle();
             communityArticle.setIsDelete(true);
-            boolean result = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
-            if (result) {
+            boolean result1 = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
+            //文章合集删除
+            int result2 = communityCollectionArticleMapper.update(null, new UpdateWrapper<CommunityCollectionArticle>()
+                    .eq("article_id", id)
+                    .set("is_delete", true));
+            if (result1 && result2 > 0) {
                 return success("删除成功!");
             }
         } catch (Exception e) {

+ 17 - 21
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityCollectionServiceImpl.java

@@ -85,8 +85,8 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
      * @return 文章信息
      */
     @Override
-    public JSONArray selectArticleInfoInCollection(Long collectionId,Long  searchType) {
-        if (searchType == null){
+    public JSONArray selectArticleInfoInCollection(Long collectionId, Long searchType) {
+        if (searchType == null) {
             searchType = 1L;
         }
         JSONArray jsonArray = new JSONArray();
@@ -99,7 +99,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
                             .isNull("is_delete");
                 }));
 
-        if (communityCollection == null){
+        if (communityCollection == null) {
             return null;
         }
         //没调用这一个接口 热度 + 1
@@ -111,21 +111,21 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
 
         //一级层级
         JSONObject collectionObject = new JSONObject();
-        collectionObject.put("CollectionName",communityCollection.getCollectionName());
+        collectionObject.put("CollectionName", communityCollection.getCollectionName());
         Date updateTime = communityCollection.getUpdateTime();
-        if (updateTime == null){
+        if (updateTime == null) {
             updateTime = communityCollection.getCreateTime();
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String formattedUpdateTime = sdf.format(updateTime);
-        collectionObject.put("collectioncreateby",communityCollection.getCreateBy());
-        collectionObject.put("updateTime",formattedUpdateTime);
-        collectionObject.put("followNumber", communityCollectionUserMapper.selectList(new QueryWrapper<CommunityCollectionUser>().eq("collection_id",collectionId).and((wrapper) -> {
+        collectionObject.put("collectioncreateby", communityCollection.getCreateBy());
+        collectionObject.put("updateTime", formattedUpdateTime);
+        collectionObject.put("followNumber", communityCollectionUserMapper.selectList(new QueryWrapper<CommunityCollectionUser>().eq("collection_id", collectionId).and((wrapper) -> {
             wrapper.ne("is_delete", true)
                     .or()
                     .isNull("is_delete");
         })).size());
-        collectionObject.put("heat",communityCollection.getHeat());
+        collectionObject.put("heat", communityCollection.getHeat());
 
         //查询当前用户是否订阅
         CommunityCollectionUser communityCollectionUser = communityCollectionUserMapper.selectOne(new QueryWrapper<CommunityCollectionUser>()
@@ -137,10 +137,10 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
                             .isNull("is_delete");
                 }));
         boolean follow = false;
-        if (communityCollectionUser != null){
+        if (communityCollectionUser != null) {
             follow = true;
         }
-        collectionObject.put("follow",follow);
+        collectionObject.put("follow", follow);
 
         //查询合集关联文章表
         List<Object> articleIdsObj = collectionArticleMapper
@@ -156,8 +156,6 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         if (articleIdsObj.isEmpty()) {
             return null;
         }
-        collectionObject.put("articleNumber", articleIdsObj.size());
-
 
         //转换object为long
         List<Long> articleIds = articleIdsObj.stream()
@@ -176,7 +174,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
                                 .or()
                                 .isNull("is_delete");
                     }).orderByDesc("create_time"));
-        } else{
+        } else {
             // 查询最早的文章
             communityArticles = communityArticleMapper.selectList(
                     new QueryWrapper<CommunityArticle>().in("id", articleIds).and((wrapper) -> {
@@ -185,9 +183,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
                                 .isNull("is_delete");
                     }).orderByAsc("create_time"));
         }
-
-
-
+        collectionObject.put("articleNumber", communityArticles.size());
 
         List<CommunityCollectionArticleVo> collectionArticleVos = new ArrayList<>();
         CommunityCollectionArticleVo collectionArticleVo = null;
@@ -219,7 +215,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
 
             collectionArticleVos.add(collectionArticleVo);
         }
-        collectionObject.put("Article",collectionArticleVos);
+        collectionObject.put("Article", collectionArticleVos);
         jsonArray.add(collectionObject);
 
         return jsonArray;
@@ -248,7 +244,7 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         List<Long> ids = communityCollectionArticleMapper.selectObjs(new QueryWrapper<CommunityCollectionArticle>()
                 .eq("collection_id", collectionId)
                 .and((wrapper) -> {
-                    wrapper .ne("is_delete", true)
+                    wrapper.ne("is_delete", true)
                             .or()
                             .isNull("is_delete");
                 })).stream().map(item -> (Long) item).collect(Collectors.toList());
@@ -260,8 +256,8 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
     }
 
     @Override
-    public List<CommunityCollectionVo> selectUserCollection(Long userId,Long articleId) {
-        return communityCollectionMapper.selectUserCollection(userId,articleId);
+    public List<CommunityCollectionVo> selectUserCollection(Long userId, Long articleId) {
+        return communityCollectionMapper.selectUserCollection(userId, articleId);
     }