|
@@ -14,10 +14,7 @@ import com.ruoyi.common.utils.ServletUtils;
|
|
|
import com.ruoyi.generator.domain.Community.*;
|
|
|
import com.ruoyi.generator.mapper.community.*;
|
|
|
import com.ruoyi.generator.service.*;
|
|
|
-import com.ruoyi.generator.vo.CommunityArticleVo;
|
|
|
-import com.ruoyi.generator.vo.CommunityCircleVo;
|
|
|
-import com.ruoyi.generator.vo.CommunityCollectionArticleVo;
|
|
|
-import com.ruoyi.generator.vo.CommunityCollectionVo;
|
|
|
+import com.ruoyi.generator.vo.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
@@ -120,7 +117,11 @@ public class CommunityArticleController extends BaseController {
|
|
|
return AjaxResult.error("板块不能为空");
|
|
|
}
|
|
|
|
|
|
- communityArticleService.insertCommunityArticle(communityArticle);
|
|
|
+ try {
|
|
|
+ communityArticleService.insertCommunityArticle(communityArticle);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success("文章发布成功!");
|
|
|
}
|
|
|
|
|
@@ -135,12 +136,15 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Strings.isEmpty(id)) {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
-
|
|
|
- CommunityArticle communityArticle = new CommunityArticle();
|
|
|
- communityArticle.setIsDelete(true);
|
|
|
- boolean result = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
|
|
|
- if (result) {
|
|
|
- return success("删除成功!");
|
|
|
+ try {
|
|
|
+ CommunityArticle communityArticle = new CommunityArticle();
|
|
|
+ communityArticle.setIsDelete(true);
|
|
|
+ boolean result = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
|
|
|
+ if (result) {
|
|
|
+ return success("删除成功!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
return error("删除失败!");
|
|
|
}
|
|
@@ -150,7 +154,12 @@ public class CommunityArticleController extends BaseController {
|
|
|
@ApiOperation("获取文章分类列表")
|
|
|
//@Anonymous
|
|
|
public AjaxResult getClassList() {
|
|
|
- List<CommunityClass> communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>());
|
|
|
+ List<CommunityClass> communityClasses = null;
|
|
|
+ try {
|
|
|
+ communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success(communityClasses);
|
|
|
}
|
|
|
|
|
@@ -158,10 +167,15 @@ public class CommunityArticleController extends BaseController {
|
|
|
@ApiOperation("获取文章圈子列表")
|
|
|
//@Anonymous
|
|
|
public AjaxResult getCircleList() {
|
|
|
- List<CommunityCircle> communityClasses = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>());
|
|
|
- for (CommunityCircle communityCircle : communityClasses) {
|
|
|
- String className = communityClassCircleMapper.getClassNameByCircleId(communityCircle.getId());
|
|
|
- communityCircle.setCircleName(className + "·" + communityCircle.getCircleName());
|
|
|
+ List<CommunityCircle> communityClasses = null;
|
|
|
+ try {
|
|
|
+ communityClasses = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>());
|
|
|
+ for (CommunityCircle communityCircle : communityClasses) {
|
|
|
+ String className = communityClassCircleMapper.getClassNameByCircleId(communityCircle.getId());
|
|
|
+ communityCircle.setCircleName(className + "·" + communityCircle.getCircleName());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
return AjaxResult.success(communityClasses);
|
|
|
}
|
|
@@ -174,16 +188,19 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (null == communityArticleComment.getArticleId()) {
|
|
|
return AjaxResult.error("文章不存在或异常!");
|
|
|
}
|
|
|
- System.out.println("communityArticleComment: " + communityArticleComment);
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
- //调用方法去判断当前评论的用户 是不是文章作者的关注列表
|
|
|
- Boolean aBoolean = communityArticleService.checkCommentPermission(userId, null, communityArticleComment.getArticleId());
|
|
|
- communityArticleComment.setUserId(SecurityUtils.getUserId());
|
|
|
- if (!aBoolean) { // 当 aBoolean 为 false 时,进入这个条件
|
|
|
- return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
|
|
|
- }
|
|
|
- //新增评论
|
|
|
- communityArticleService.sendComment(communityArticleComment);
|
|
|
+ try {
|
|
|
+ //调用方法去判断当前评论的用户 是不是文章作者的关注列表
|
|
|
+ Boolean aBoolean = communityArticleService.checkCommentPermission(userId, null, communityArticleComment.getArticleId());
|
|
|
+ communityArticleComment.setUserId(SecurityUtils.getUserId());
|
|
|
+ if (!aBoolean) { // 当 aBoolean 为 false 时,进入这个条件
|
|
|
+ return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
|
|
|
+ }
|
|
|
+ //新增评论
|
|
|
+ communityArticleService.sendComment(communityArticleComment);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
@@ -191,14 +208,17 @@ public class CommunityArticleController extends BaseController {
|
|
|
@DeleteMapping("/comment")
|
|
|
@Transactional
|
|
|
public AjaxResult deleteComment(@RequestBody CommunityArticleComment communityArticleComment) {
|
|
|
- //获取评论信息
|
|
|
- CommunityArticleComment articleComment = communityArticleCommentMapper.selectById(communityArticleComment.getId());
|
|
|
-
|
|
|
- if (!articleComment.getCreateBy().equals(SecurityUtils.getUserId())) {
|
|
|
- return AjaxResult.error("不允许删除别人的评论!");
|
|
|
+ try {
|
|
|
+ //获取评论信息
|
|
|
+ CommunityArticleComment articleComment = communityArticleCommentMapper.selectById(communityArticleComment.getId());
|
|
|
+ if (!articleComment.getCreateBy().equals(SecurityUtils.getUserId())) {
|
|
|
+ return AjaxResult.error("不允许删除别人的评论!");
|
|
|
+ }
|
|
|
+ //删除评论
|
|
|
+ communityArticleService.deleteComment(articleComment);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
- //删除评论
|
|
|
- communityArticleService.deleteComment(articleComment);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
@@ -215,25 +235,30 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
boolean isSuccess = true;
|
|
|
String message = "";
|
|
|
- CommunityLike like = communityArticleService.selectCommunityLikeById(communityLike);
|
|
|
- if (Objects.isNull(like)) {
|
|
|
- //新增点赞
|
|
|
- communityLike.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
|
|
|
- communityLike.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
|
|
|
- communityLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityLike.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- isSuccess = communityArticleService.insertCommunityLikeById(communityLike);
|
|
|
- message = "感谢点赞";
|
|
|
- } else {
|
|
|
- //删除点赞
|
|
|
- isSuccess = communityArticleService.deleteCommunityLikeById(like);
|
|
|
- message = "取消点赞";
|
|
|
- }
|
|
|
-
|
|
|
- if (!isSuccess) {
|
|
|
- message = "操作失败!";
|
|
|
- return AjaxResult.error(message);
|
|
|
+ try {
|
|
|
+ CommunityLike like = communityArticleService.selectCommunityLikeById(communityLike);
|
|
|
+ if (Objects.isNull(like)) {
|
|
|
+ //新增点赞
|
|
|
+ communityLike.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
|
|
|
+ communityLike.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
|
|
|
+ communityLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityLike.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ isSuccess = communityArticleService.insertCommunityLikeById(communityLike);
|
|
|
+ message = "感谢点赞";
|
|
|
+ } else {
|
|
|
+ //删除点赞
|
|
|
+ isSuccess = communityArticleService.deleteCommunityLikeById(like);
|
|
|
+ message = "取消点赞";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isSuccess) {
|
|
|
+ message = "操作失败!";
|
|
|
+ return AjaxResult.error(message);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success(message);
|
|
|
}
|
|
|
|
|
@@ -251,34 +276,39 @@ public class CommunityArticleController extends BaseController {
|
|
|
boolean isSuccess = true;
|
|
|
String message = "";
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
- CommunityArticleRecommend recommend = communityArticleRecommendService.getOne(new QueryWrapper<CommunityArticleRecommend>()
|
|
|
- .eq("article_id", articleRecommend.getArticleId())
|
|
|
- .eq("user_id", userId).and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
- if (Objects.isNull(recommend)) {
|
|
|
- //新增推荐值
|
|
|
- recommend = new CommunityArticleRecommend();
|
|
|
- recommend.setArticleId(articleRecommend.getArticleId());
|
|
|
- recommend.setCreateBy(userId);
|
|
|
- recommend.setUserId(userId);
|
|
|
- recommend.setDelete(false);
|
|
|
- recommend.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- isSuccess = communityArticleRecommendService.save(recommend);
|
|
|
- message = "感谢推荐";
|
|
|
- } else {
|
|
|
- //删除点赞
|
|
|
- recommend.setDelete(true);
|
|
|
- recommend.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- recommend.setUpdateBy(userId);
|
|
|
- isSuccess = communityArticleRecommendService.updateById(recommend);
|
|
|
- message = "取消推荐";
|
|
|
- }
|
|
|
-
|
|
|
- if (!isSuccess) {
|
|
|
- message = "操作失败!";
|
|
|
- return AjaxResult.error(message);
|
|
|
+ try {
|
|
|
+ CommunityArticleRecommend recommend = communityArticleRecommendService.getOne(new QueryWrapper<CommunityArticleRecommend>()
|
|
|
+ .eq("article_id", articleRecommend.getArticleId())
|
|
|
+ .eq("user_id", userId).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+ if (Objects.isNull(recommend)) {
|
|
|
+ //新增推荐值
|
|
|
+ recommend = new CommunityArticleRecommend();
|
|
|
+ recommend.setArticleId(articleRecommend.getArticleId());
|
|
|
+ recommend.setCreateBy(userId);
|
|
|
+ recommend.setUserId(userId);
|
|
|
+ recommend.setDelete(false);
|
|
|
+ recommend.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ isSuccess = communityArticleRecommendService.save(recommend);
|
|
|
+ message = "感谢推荐";
|
|
|
+ } else {
|
|
|
+ //删除点赞
|
|
|
+ recommend.setDelete(true);
|
|
|
+ recommend.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ recommend.setUpdateBy(userId);
|
|
|
+ isSuccess = communityArticleRecommendService.updateById(recommend);
|
|
|
+ message = "取消推荐";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isSuccess) {
|
|
|
+ message = "操作失败!";
|
|
|
+ return AjaxResult.error(message);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success(message);
|
|
|
}
|
|
|
|
|
@@ -296,21 +326,27 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
boolean isSuccess = true;
|
|
|
String message = "";
|
|
|
- CommunityArticleCollect collect = communityArticleService.selectCommunityCollectById(communityArticleCollect);
|
|
|
- if (Objects.isNull(collect) || Objects.isNull(collect.getId())) {
|
|
|
- //新增收藏
|
|
|
- isSuccess = communityArticleService.insertCommunityCollectById(communityArticleCollect);
|
|
|
- message = "收藏成功";
|
|
|
- } else {
|
|
|
- //删除收藏
|
|
|
- isSuccess = communityArticleService.deleteCommunityCollectById(collect);
|
|
|
- message = "取消收藏";
|
|
|
- }
|
|
|
|
|
|
- if (!isSuccess) {
|
|
|
- message = "操作失败!";
|
|
|
- return AjaxResult.error(message);
|
|
|
+ try {
|
|
|
+ CommunityArticleCollect collect = communityArticleService.selectCommunityCollectById(communityArticleCollect);
|
|
|
+ if (Objects.isNull(collect) || Objects.isNull(collect.getId())) {
|
|
|
+ //新增收藏
|
|
|
+ isSuccess = communityArticleService.insertCommunityCollectById(communityArticleCollect);
|
|
|
+ message = "收藏成功";
|
|
|
+ } else {
|
|
|
+ //删除收藏
|
|
|
+ isSuccess = communityArticleService.deleteCommunityCollectById(collect);
|
|
|
+ message = "取消收藏";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isSuccess) {
|
|
|
+ message = "操作失败!";
|
|
|
+ return AjaxResult.error(message);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success(message);
|
|
|
}
|
|
|
|
|
@@ -326,39 +362,44 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(commentLike.getCommentId())) {
|
|
|
return AjaxResult.error("评论或用户信息异常!");
|
|
|
}
|
|
|
-
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
String message = "";
|
|
|
- //评论点赞
|
|
|
- //查询该评论是否已点赞
|
|
|
- QueryWrapper<CommunityCommentLike> queryWrapper = null;
|
|
|
- if (commentLike.isReply()) {
|
|
|
- //回复的点赞
|
|
|
- queryWrapper = new QueryWrapper<CommunityCommentLike>()
|
|
|
- .eq("reply_id", commentLike.getCommentId())
|
|
|
- .eq("user_id", userId);
|
|
|
- commentLike.setReplyId(commentLike.getCommentId());
|
|
|
- commentLike.setCommentId(null);
|
|
|
- } else {
|
|
|
- //评论的点赞
|
|
|
- queryWrapper = new QueryWrapper<CommunityCommentLike>()
|
|
|
- .eq("comment_id", commentLike.getCommentId())
|
|
|
- .eq("user_id", userId);
|
|
|
- }
|
|
|
-
|
|
|
- CommunityCommentLike communityCommentLike = communityCommentLikeMapper.selectOne(queryWrapper);
|
|
|
- if (Objects.isNull(communityCommentLike) || Objects.isNull(communityCommentLike.getId())) {
|
|
|
- //新增点赞
|
|
|
- commentLike.setCreateBy(userId);
|
|
|
- commentLike.setUserId(userId);
|
|
|
- commentLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityCommentLikeMapper.insert(commentLike);
|
|
|
- message = "感谢点赞";
|
|
|
- } else {
|
|
|
- //删除点赞
|
|
|
- communityCommentLikeMapper.deleteById(communityCommentLike);
|
|
|
- message = "取消点赞";
|
|
|
+
|
|
|
+ try {
|
|
|
+ //评论点赞
|
|
|
+ //查询该评论是否已点赞
|
|
|
+ QueryWrapper<CommunityCommentLike> queryWrapper = null;
|
|
|
+ if (commentLike.isReply()) {
|
|
|
+ //回复的点赞
|
|
|
+ queryWrapper = new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("reply_id", commentLike.getCommentId())
|
|
|
+ .eq("user_id", userId);
|
|
|
+ commentLike.setReplyId(commentLike.getCommentId());
|
|
|
+ commentLike.setCommentId(null);
|
|
|
+ } else {
|
|
|
+ //评论的点赞
|
|
|
+ queryWrapper = new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("comment_id", commentLike.getCommentId())
|
|
|
+ .eq("user_id", userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ CommunityCommentLike communityCommentLike = communityCommentLikeMapper.selectOne(queryWrapper);
|
|
|
+ if (Objects.isNull(communityCommentLike) || Objects.isNull(communityCommentLike.getId())) {
|
|
|
+ //新增点赞
|
|
|
+ commentLike.setCreateBy(userId);
|
|
|
+ commentLike.setUserId(userId);
|
|
|
+ commentLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityCommentLikeMapper.insert(commentLike);
|
|
|
+ message = "感谢点赞";
|
|
|
+ } else {
|
|
|
+ //删除点赞
|
|
|
+ communityCommentLikeMapper.deleteById(communityCommentLike);
|
|
|
+ message = "取消点赞";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success(message);
|
|
|
}
|
|
|
|
|
@@ -370,7 +411,12 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Strings.isBlank(classId)) {
|
|
|
return AjaxResult.error("板块信息有误!");
|
|
|
}
|
|
|
- List<CommunityCircleVo> communityCircles = communityArticleService.selectCommunityCircleList(classId);
|
|
|
+ List<CommunityCircleVo> communityCircles = null;
|
|
|
+ try {
|
|
|
+ communityCircles = communityArticleService.selectCommunityCircleList(classId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success(communityCircles);
|
|
|
}
|
|
|
|
|
@@ -379,22 +425,29 @@ public class CommunityArticleController extends BaseController {
|
|
|
//@Anonymous
|
|
|
public AjaxResult myCircle(@RequestParam(required = false) String circleName) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- List<CommunityUserCircle> communityUserCircles = communityUserCircleMapper.selectList(new QueryWrapper<CommunityUserCircle>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
- }));
|
|
|
|
|
|
- List<Long> circleIds = new ArrayList<>();
|
|
|
- for (CommunityUserCircle communityUserCircle : communityUserCircles) {
|
|
|
- circleIds.add(communityUserCircle.getCircleId());
|
|
|
- }
|
|
|
List<CommunityCircle> communityCircles = null;
|
|
|
- if (!circleIds.isEmpty()) {
|
|
|
- communityCircles = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>()
|
|
|
- .in("id", circleIds)
|
|
|
- .like("circle_name", circleName));
|
|
|
+ try {
|
|
|
+ List<CommunityUserCircle> communityUserCircles = communityUserCircleMapper.selectList(new QueryWrapper<CommunityUserCircle>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ List<Long> circleIds = new ArrayList<>();
|
|
|
+ for (CommunityUserCircle communityUserCircle : communityUserCircles) {
|
|
|
+ circleIds.add(communityUserCircle.getCircleId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!circleIds.isEmpty()) {
|
|
|
+ communityCircles = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>()
|
|
|
+ .in("id", circleIds)
|
|
|
+ .like("circle_name", circleName));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success("获取成功!", communityCircles);
|
|
|
}
|
|
|
|
|
@@ -408,33 +461,39 @@ public class CommunityArticleController extends BaseController {
|
|
|
return AjaxResult.error("关注圈子异常,请刷新页面重试!");
|
|
|
}
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- CommunityUserCircle userCircle = communityUserCircleMapper
|
|
|
- .selectOne(new QueryWrapper<CommunityUserCircle>()
|
|
|
- .eq("circle_id", communityUserCircle.getCircleId())
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("is_delete", 0));
|
|
|
String msg = "";
|
|
|
- if (Objects.isNull(userCircle) || Objects.isNull(userCircle.getId())) {
|
|
|
- //如果未找到数据,则进行关注
|
|
|
- userCircle = new CommunityUserCircle();
|
|
|
- userCircle.setCircleId(communityUserCircle.getCircleId());
|
|
|
- userCircle.setUserId(userId);
|
|
|
- userCircle.setCreateBy(userId);
|
|
|
- userCircle.setUpdateBy(userId);
|
|
|
- userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityUserCircleMapper.insert(userCircle);
|
|
|
- msg = "已关注";
|
|
|
- } else {
|
|
|
- //更新删除标识
|
|
|
- userCircle.setDelete(true);
|
|
|
- userCircle.setCreateBy(userId);
|
|
|
- userCircle.setUpdateBy(userId);
|
|
|
- userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityUserCircleMapper.updateById(userCircle);
|
|
|
- msg = "已取关";
|
|
|
+ try {
|
|
|
+ CommunityUserCircle userCircle = communityUserCircleMapper
|
|
|
+ .selectOne(new QueryWrapper<CommunityUserCircle>()
|
|
|
+ .eq("circle_id", communityUserCircle.getCircleId())
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("is_delete", 0));
|
|
|
+
|
|
|
+ if (Objects.isNull(userCircle) || Objects.isNull(userCircle.getId())) {
|
|
|
+ //如果未找到数据,则进行关注
|
|
|
+ userCircle = new CommunityUserCircle();
|
|
|
+ userCircle.setCircleId(communityUserCircle.getCircleId());
|
|
|
+ userCircle.setUserId(userId);
|
|
|
+ userCircle.setCreateBy(userId);
|
|
|
+ userCircle.setUpdateBy(userId);
|
|
|
+ userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityUserCircleMapper.insert(userCircle);
|
|
|
+ msg = "已关注";
|
|
|
+ } else {
|
|
|
+ //更新删除标识
|
|
|
+ userCircle.setDelete(true);
|
|
|
+ userCircle.setCreateBy(userId);
|
|
|
+ userCircle.setUpdateBy(userId);
|
|
|
+ userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityUserCircleMapper.updateById(userCircle);
|
|
|
+ msg = "已取关";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success(msg);
|
|
|
}
|
|
|
|
|
@@ -454,11 +513,16 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
String msg = "";
|
|
|
CommunityUserLike communityUserLike = communityArticleService.addOrDeleteUserLike(likeUserId);
|
|
|
- if (Objects.isNull(communityUserLike) || Objects.isNull(communityUserLike.getId())) {
|
|
|
- msg = "取消关注";
|
|
|
- } else {
|
|
|
- msg = "已关注";
|
|
|
+ try {
|
|
|
+ if (Objects.isNull(communityUserLike) || Objects.isNull(communityUserLike.getId())) {
|
|
|
+ msg = "取消关注";
|
|
|
+ } else {
|
|
|
+ msg = "已关注";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
+
|
|
|
return AjaxResult.success(msg);
|
|
|
}
|
|
|
|
|
@@ -468,7 +532,13 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(userId)) {
|
|
|
userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
}
|
|
|
- return AjaxResult.success(communityArticleService.selectCommunityUserInfoById(userId));
|
|
|
+ CommunityUserInfoVo communityUserInfoVo = null;
|
|
|
+ try {
|
|
|
+ communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+ return AjaxResult.success(communityUserInfoVo);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -478,7 +548,15 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(SearchValue)) {
|
|
|
return AjaxResult.error();
|
|
|
}
|
|
|
- return AjaxResult.success(communityArticleService.selectUserBySearchValue(SearchValue));
|
|
|
+ List<CommunityUserInfoVo> communityUserInfoVos = null;
|
|
|
+ try {
|
|
|
+ communityUserInfoVos = communityArticleService.selectUserBySearchValue(SearchValue);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return AjaxResult.success(communityUserInfoVos);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("根据条件查询账户")
|
|
@@ -487,26 +565,54 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(SearchValue)) {
|
|
|
return AjaxResult.error();
|
|
|
}
|
|
|
- return AjaxResult.success(communityArticleService.selectUsersByAccountOrName(SearchValue));
|
|
|
+ List<CommunityUserInfoVo> communityUserInfoVos = null;
|
|
|
+ try {
|
|
|
+ communityUserInfoVos = communityArticleService.selectUsersByAccountOrName(SearchValue);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(communityUserInfoVos);
|
|
|
}
|
|
|
|
|
|
|
|
|
@ApiOperation("获取关注列表")
|
|
|
@GetMapping("/likeUserList")
|
|
|
public AjaxResult likeUserList() {
|
|
|
- return AjaxResult.success(communityArticleService.selectCommunityUserLikeList(SecurityUtils.getLoginUser().getUserId()));
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = null;
|
|
|
+ try {
|
|
|
+ communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(SecurityUtils.getLoginUser().getUserId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(communityUserLikeVos);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("获取粉丝列表")
|
|
|
@GetMapping("/userFans")
|
|
|
public AjaxResult userFans() {
|
|
|
- return AjaxResult.success(communityArticleService.selectUserFansList(SecurityUtils.getLoginUser().getUserId()));
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = null;
|
|
|
+ try {
|
|
|
+ communityUserLikeVos = communityArticleService.selectUserFansList(SecurityUtils.getLoginUser().getUserId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(communityUserLikeVos);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("互相关注列表")
|
|
|
@GetMapping("/mutualAttention")
|
|
|
public AjaxResult mutualAttention() {
|
|
|
- return AjaxResult.success(communityArticleService.selectMutualAttention(SecurityUtils.getLoginUser().getUserId()));
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = null;
|
|
|
+ try {
|
|
|
+ communityUserLikeVos = communityArticleService.selectMutualAttention(SecurityUtils.getLoginUser().getUserId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(communityUserLikeVos);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("发送用户验证码")
|
|
@@ -529,14 +635,17 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (backImage == null) {
|
|
|
return AjaxResult.error("背景图不能为空");
|
|
|
}
|
|
|
-
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- CommunityUserInfo communityUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
|
|
|
- if (Objects.isNull(communityUserInfo) || Objects.isNull(communityUserInfo.getId())) {
|
|
|
- return AjaxResult.error("系统出错");
|
|
|
+ try {
|
|
|
+ CommunityUserInfo communityUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
|
|
|
+ if (Objects.isNull(communityUserInfo) || Objects.isNull(communityUserInfo.getId())) {
|
|
|
+ return AjaxResult.error("系统出错");
|
|
|
+ }
|
|
|
+ communityUserInfo.setBackImage(backImage);
|
|
|
+ communityUserInfoMapper.updateById(communityUserInfo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
- communityUserInfo.setBackImage(backImage);
|
|
|
- communityUserInfoMapper.updateById(communityUserInfo);
|
|
|
return AjaxResult.success("背景图片上传成功!");
|
|
|
}
|
|
|
|
|
@@ -558,7 +667,14 @@ public class CommunityArticleController extends BaseController {
|
|
|
// .or()
|
|
|
// .isNull("is_delete"));
|
|
|
|
|
|
- List<CommunityCollectionVo> communityCollectionVos = communityCollectionService.selectUserCollection(userId, articleId);
|
|
|
+ List<CommunityCollectionVo> communityCollectionVos = null;
|
|
|
+ try {
|
|
|
+ communityCollectionVos = communityCollectionService.selectUserCollection(userId, articleId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
return AjaxResult.success(communityCollectionVos);
|
|
|
}
|
|
@@ -583,26 +699,29 @@ public class CommunityArticleController extends BaseController {
|
|
|
return AjaxResult.error("合集图片不能为空");
|
|
|
}
|
|
|
|
|
|
- CommunityCollection collection = communityCollectionService
|
|
|
- .getOne(new QueryWrapper<CommunityCollection>()
|
|
|
- .eq("collection_name", communityCollection.getCollectionName())
|
|
|
- .eq("user_id", SecurityUtils.getLoginUser().getUserId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true)
|
|
|
- .or()
|
|
|
- .isNull("is_delete");
|
|
|
- }));
|
|
|
-
|
|
|
- if (!Objects.isNull(collection)) {
|
|
|
- return AjaxResult.error("合集名称不能重复!");
|
|
|
+ try {
|
|
|
+ CommunityCollection collection = communityCollectionService
|
|
|
+ .getOne(new QueryWrapper<CommunityCollection>()
|
|
|
+ .eq("collection_name", communityCollection.getCollectionName())
|
|
|
+ .eq("user_id", SecurityUtils.getLoginUser().getUserId())
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true)
|
|
|
+ .or()
|
|
|
+ .isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (!Objects.isNull(collection)) {
|
|
|
+ return AjaxResult.error("合集名称不能重复!");
|
|
|
+ }
|
|
|
+ communityCollection.setUserId(SecurityUtils.getLoginUser().getUserId());
|
|
|
+ communityCollection.setCreateBy(SecurityUtils.getLoginUser().getUserId());
|
|
|
+ communityCollection.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityCollection.setDelete(false);
|
|
|
+ communityCollectionService.save(communityCollection);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
|
|
|
- communityCollection.setUserId(SecurityUtils.getLoginUser().getUserId());
|
|
|
- communityCollection.setCreateBy(SecurityUtils.getLoginUser().getUserId());
|
|
|
- communityCollection.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityCollection.setDelete(false);
|
|
|
- communityCollectionService.save(communityCollection);
|
|
|
-
|
|
|
return AjaxResult.success(communityCollection);
|
|
|
}
|
|
|
|
|
@@ -619,8 +738,11 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(collectionId)) {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
-
|
|
|
- communityCollectionService.deleteCollectionById(collectionId);
|
|
|
+ try {
|
|
|
+ communityCollectionService.deleteCollectionById(collectionId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success("删除成功!");
|
|
|
}
|
|
|
|
|
@@ -653,55 +775,60 @@ public class CommunityArticleController extends BaseController {
|
|
|
Long articleId = collectionArticle.getArticleId();
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
|
|
- //查询当前文章是不是属于该用户的
|
|
|
- List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("id", articleId)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
- }));
|
|
|
-
|
|
|
- if (communityArticles.isEmpty()) {
|
|
|
- return AjaxResult.success("文章ID不属于当前用户!");
|
|
|
- }
|
|
|
-
|
|
|
- //查询当前用户有没有这个合集
|
|
|
- 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()) {
|
|
|
- for (CommunityCollectionArticle communityCollectionArticle : communityCollectionArticles) {
|
|
|
- Long collectionId1 = communityCollectionArticle.getCollectionId();
|
|
|
- // 如果 id 与 collectionId 相等,直接返回
|
|
|
- if (collectionId1.equals(collectionId)) {
|
|
|
- return AjaxResult.success("该文章在合集已经存在!");
|
|
|
- } else {
|
|
|
- // 如果不相等,执行删除操作
|
|
|
- communityCollectionService.deleteArticleToCollection(collectionId1, articleId);
|
|
|
+
|
|
|
+ try {
|
|
|
+ //查询当前文章是不是属于该用户的
|
|
|
+ List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("id", articleId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (communityArticles.isEmpty()) {
|
|
|
+ return AjaxResult.success("文章ID不属于当前用户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询当前用户有没有这个合集
|
|
|
+ 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()) {
|
|
|
+ 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);
|
|
|
+ collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityCollectionService.addArticleToCollection(collectionArticle);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
}
|
|
|
- collectionArticle.setCreateBy(userId);
|
|
|
- collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityCollectionService.addArticleToCollection(collectionArticle);
|
|
|
|
|
|
return AjaxResult.success("加入合集成功!");
|
|
|
}
|
|
@@ -720,8 +847,11 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(collectionId) || Objects.isNull(articleId)) {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
-
|
|
|
- communityCollectionService.deleteArticleToCollection(collectionId, articleId);
|
|
|
+ try {
|
|
|
+ communityCollectionService.deleteArticleToCollection(collectionId, articleId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success("文章删除成功!");
|
|
|
}
|
|
|
|
|
@@ -737,7 +867,12 @@ public class CommunityArticleController extends BaseController {
|
|
|
if (Objects.isNull(collectionId)) {
|
|
|
return AjaxResult.error("合集不存在!");
|
|
|
}
|
|
|
- List<CommunityCollectionArticleVo> collectionArticleVos = communityCollectionService.selectArticleInfoInCollection(collectionId);
|
|
|
+ List<CommunityCollectionArticleVo> collectionArticleVos = null;
|
|
|
+ try {
|
|
|
+ collectionArticleVos = communityCollectionService.selectArticleInfoInCollection(collectionId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
return AjaxResult.success(collectionArticleVos);
|
|
|
}
|
|
|
|