|
@@ -80,6 +80,8 @@ public class CommunityArticleController extends BaseController {
|
|
|
@Autowired
|
|
|
private CommunityCollectionArticleMapper communityCollectionArticleMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommunityCollectionMapper communityCollectionMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -638,8 +640,8 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 1.查询当前用户合集下有没有收录这边文章
|
|
|
- * 2.情况1 如果在合集下,更新这个合集的删除状态,在插入到新的合集
|
|
|
+ * 1.查询当前用户有没有这个合集
|
|
|
+ * 2.情况1 如果文章在合集下,更新这个合集的删除状态,在插入到新的合集
|
|
|
* 4.情况2 如果文章就在需要添加的合集下,则返回 该文章在合集已经存在
|
|
|
* 3.如果没有在合集下,直接插入
|
|
|
*/
|
|
@@ -647,18 +649,38 @@ public class CommunityArticleController extends BaseController {
|
|
|
Long articleId = collectionArticle.getArticleId();
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
|
|
- List<CommunityCollectionArticle> communityCollectionArticles = communityCollectionArticleMapper.selectUserCollectionArticle(userId,articleId);
|
|
|
+ //查询该用户有没有这个合集
|
|
|
+ List<CommunityCollection> communityCollections = communityCollectionMapper.selectList(new QueryWrapper<CommunityCollection>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("id",collectionId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (communityCollections.isEmpty()) {
|
|
|
+ return AjaxResult.success("合集ID不属于当前登录用户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("communityCollections: " + communityCollections);
|
|
|
+ //根据创建人ID,合集ID,文章ID保持唯一性 查询表如果没有则插入,有了则更新ID
|
|
|
+ List<CommunityCollectionArticle> communityCollectionArticles = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
|
|
|
+ .eq("create_by", userId)
|
|
|
+ .eq("article_id",articleId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
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);
|
|
|
+ for (CommunityCollectionArticle communityCollectionArticle : communityCollectionArticles) {
|
|
|
+ Long collectionId1 = communityCollectionArticle.getCollectionId();
|
|
|
+ // 如果 id 与 collectionId 相等,直接返回
|
|
|
+ if (collectionId1.equals(collectionId)) {
|
|
|
+ return AjaxResult.success("该文章在合集已经存在!");
|
|
|
+ } else {
|
|
|
+ // 如果不相等,执行删除操作
|
|
|
+ communityCollectionService.deleteArticleToCollection(collectionId1, articleId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
collectionArticle.setCreateBy(userId);
|