|
@@ -76,6 +76,12 @@ public class CommunityArticleController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private CommunityArticleMapper communityArticleMapper;
|
|
private CommunityArticleMapper communityArticleMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CommunityCollectionArticleMapper communityCollectionArticleMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取文章列表信息
|
|
* 获取文章列表信息
|
|
*/
|
|
*/
|
|
@@ -631,7 +637,31 @@ public class CommunityArticleController extends BaseController {
|
|
return AjaxResult.error("合集参数异常!");
|
|
return AjaxResult.error("合集参数异常!");
|
|
}
|
|
}
|
|
|
|
|
|
- collectionArticle.setCreateBy(SecurityUtils.getLoginUser().getUserId());
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 1.查询当前用户合集下有没有收录这边文章
|
|
|
|
+ * 2.情况1 如果在合集下,更新这个合集的删除状态,在插入到新的合集
|
|
|
|
+ * 4.情况2 如果文章就在需要添加的合集下,则返回 该文章在合集已经存在
|
|
|
|
+ * 3.如果没有在合集下,直接插入
|
|
|
|
+ */
|
|
|
|
+ Long collectionId = collectionArticle.getCollectionId();
|
|
|
|
+ Long articleId = collectionArticle.getArticleId();
|
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
+
|
|
|
|
+ List<CommunityCollectionArticle> communityCollectionArticles = communityCollectionArticleMapper.selectUserCollectionArticle(userId,articleId);
|
|
|
|
+ System.out.println("communityCollectionArticles: " + communityCollectionArticles);
|
|
|
|
+ // 如果已存在,则更新删除状态并插入新的合集
|
|
|
|
+ if (!communityCollectionArticles.isEmpty()) {
|
|
|
|
+ Long collectionId1 = communityCollectionArticles.get(0).getCollectionId();
|
|
|
|
+ System.out.println("collectionId1: " + collectionId1);
|
|
|
|
+ // 如果 id 与 collectionId 相等,直接返回
|
|
|
|
+ if (collectionId1.equals(collectionId)) {
|
|
|
|
+ return AjaxResult.success("该文章在合集已经存在!");
|
|
|
|
+ } else {
|
|
|
|
+ // 如果不相等,执行删除操作
|
|
|
|
+ communityCollectionService.deleteArticleToCollection(collectionId1, articleId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ collectionArticle.setCreateBy(userId);
|
|
collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
communityCollectionService.addArticleToCollection(collectionArticle);
|
|
communityCollectionService.addArticleToCollection(collectionArticle);
|
|
|
|
|