|
@@ -14,6 +14,7 @@ import com.ruoyi.common.utils.ip.AddressUtils;
|
|
|
import com.ruoyi.generator.domain.Community.*;
|
|
|
import com.ruoyi.generator.mapper.community.*;
|
|
|
import com.ruoyi.generator.vo.*;
|
|
|
+import com.ruoyi.system.domain.CommunityChatMsg;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -225,12 +226,14 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
List<CommunityArticleClass> articleId = communityArticleCircleMapper.selectList(
|
|
|
new QueryWrapper<CommunityArticleClass>()
|
|
|
.eq("article_id", articleVo.getId())
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ })
|
|
|
);
|
|
|
// 使用 Java Streams API 提取 classId,并转换成 List<Long>
|
|
|
List<Long> classIdss = articleId.stream()
|
|
|
.map(CommunityArticleClass::getClassId)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
articleVo.setClassIds(classIdss);
|
|
|
|
|
|
|
|
@@ -317,7 +320,11 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
articleVo.setRecommend(!Objects.isNull(recommend));
|
|
|
|
|
|
//获取文章标签
|
|
|
- List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>().eq("article_id", articleVo.getId()));
|
|
|
+ List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>()
|
|
|
+ .eq("article_id", articleVo.getId())
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
|
|
|
List<Long> tagIds = new ArrayList<>();
|
|
|
|
|
@@ -374,7 +381,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
communityArticle.setId(null);
|
|
|
}
|
|
|
|
|
|
- System.out.println(communityArticle);
|
|
|
+
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
//插入文章信息
|
|
|
communityArticle.setUserId(userId);
|
|
@@ -470,6 +477,166 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 编辑文章
|
|
|
+ *
|
|
|
+ * @param communityArticle 文章信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void editCommunityArticle(CommunityArticle communityArticle) {
|
|
|
+
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ //编辑文章信息
|
|
|
+ communityArticle.setUpdateBy(userId);
|
|
|
+ communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+
|
|
|
+
|
|
|
+ String address = null;
|
|
|
+ try {
|
|
|
+ address = AddressUtils.getAddress(null);
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ communityArticle.setAddress(address);
|
|
|
+
|
|
|
+ communityArticleMapper.updateById(communityArticle);
|
|
|
+
|
|
|
+
|
|
|
+ //插入标签日志
|
|
|
+ List<String> tags = communityArticle.getTags();
|
|
|
+
|
|
|
+ //不在本次更新的标签都传失效
|
|
|
+ communityArticleTagMapper.update(
|
|
|
+ null,
|
|
|
+ new UpdateWrapper<CommunityArticleTag>()
|
|
|
+ .eq("article_id", communityArticle.getId())
|
|
|
+ .notIn("tag_id", tags)
|
|
|
+ .set("is_delete", true)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ if (tags != null && !tags.isEmpty()) {
|
|
|
+ CommunityArticleTag tagLog = null;
|
|
|
+ for (String tag : tags) {
|
|
|
+
|
|
|
+ //查询该标签是否在数据库中存在
|
|
|
+ CommunityArticleTag communityArticleTag = communityArticleTagMapper.selectOne((new QueryWrapper<CommunityArticleTag>()
|
|
|
+ .eq("article_id", communityArticle.getId())
|
|
|
+ .eq("tag_id", tag)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ })));
|
|
|
+ //不为空就不操作
|
|
|
+ if (communityArticleTag == null ){
|
|
|
+ tagLog = new CommunityArticleTag();
|
|
|
+ tagLog.setArticleId(communityArticle.getId());
|
|
|
+ tagLog.setTagId(Long.parseLong(tag));
|
|
|
+ tagLog.setUpdateBy(userId);
|
|
|
+ tagLog.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ tagLog.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ tagLog.setCreateBy(userId);
|
|
|
+ articleTagMapper.insert(tagLog);
|
|
|
+
|
|
|
+ //标签热度自增
|
|
|
+ CommunityTag communityTag = communityTagMapper.selectById(Long.parseLong(tag));
|
|
|
+ communityTag.setTagHot(Objects.isNull(communityTag.getTagHot()) ? 1 : communityTag.getTagHot() + 1);
|
|
|
+ communityTag.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityTag.setUpdateBy(userId);
|
|
|
+ communityTagMapper.updateById(communityTag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入图片日志
|
|
|
+ List<String> images = communityArticle.getImages();
|
|
|
+
|
|
|
+ //插入图片日志 都失效
|
|
|
+ communityArticleImagesMapper.update(
|
|
|
+ null,
|
|
|
+ new UpdateWrapper<CommunityArticleImages>()
|
|
|
+ .eq("article_id", communityArticle.getId())
|
|
|
+ .set("is_delete", true)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ if (images != null && !images.isEmpty()) {
|
|
|
+ CommunityArticleImages articleImages = null;
|
|
|
+ for (String image : images) {
|
|
|
+ articleImages = new CommunityArticleImages();
|
|
|
+ articleImages.setArticleId(communityArticle.getId());
|
|
|
+ articleImages.setImageUrl(image);
|
|
|
+ articleImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ articleImages.setCreateBy(userId);
|
|
|
+ communityArticleImagesMapper.insert(articleImages);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入板块
|
|
|
+ List<Long> classIds = communityArticle.getClassIds();
|
|
|
+
|
|
|
+ //插入板块 都失效
|
|
|
+ communityArticleClassService.update(
|
|
|
+ null,
|
|
|
+ new UpdateWrapper<CommunityArticleClass>()
|
|
|
+ .eq("article_id", communityArticle.getId())
|
|
|
+ .set("is_delete", true)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ if (classIds != null && !classIds.isEmpty()) {
|
|
|
+ List<CommunityArticleClass> articleClasses = new ArrayList<>();
|
|
|
+ CommunityArticleClass articleClass = null;
|
|
|
+ for (Long classId : classIds) {
|
|
|
+ articleClass = new CommunityArticleClass();
|
|
|
+ articleClass.setClassId(classId);
|
|
|
+ articleClass.setArticleId(communityArticle.getId());
|
|
|
+ articleClass.setCreateBy(userId);
|
|
|
+ articleClass.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ articleClasses.add(articleClass);
|
|
|
+ }
|
|
|
+ communityArticleClassService.saveBatch(articleClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入合集
|
|
|
+ List<String> collectionIds = communityArticle.getCollectionIds();
|
|
|
+
|
|
|
+
|
|
|
+ if (collectionIds != null && !collectionIds.isEmpty()) {
|
|
|
+ //插入合集 都失效
|
|
|
+ collectionArticleService.update(
|
|
|
+ null,
|
|
|
+ new UpdateWrapper<CommunityCollectionArticle>()
|
|
|
+ .eq("article_id", communityArticle.getId())
|
|
|
+ .in("collection_id",collectionIds)
|
|
|
+ .set("is_delete", true)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ List<CommunityCollectionArticle> collectionArticles = new ArrayList<>();
|
|
|
+ CommunityCollectionArticle collectionArticle = null;
|
|
|
+ for (String collectionId : collectionIds) {
|
|
|
+ collectionArticle = new CommunityCollectionArticle();
|
|
|
+ collectionArticle.setCollectionId(Long.parseLong(collectionId));
|
|
|
+ collectionArticle.setArticleId(communityArticle.getId());
|
|
|
+ collectionArticle.setCreateBy(userId);
|
|
|
+ collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ collectionArticles.add(collectionArticle);
|
|
|
+ }
|
|
|
+ collectionArticleService.saveBatch(collectionArticles);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送评论
|
|
|
*
|