|
@@ -1,5 +1,7 @@
|
|
|
package com.ruoyi.generator.service;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -12,7 +14,9 @@ import com.ruoyi.generator.vo.CommunityCollectionVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -39,6 +43,8 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
|
|
|
|
|
|
@Autowired
|
|
|
private CommunityCollectionArticleMapper communityCollectionArticleMapper;
|
|
|
+ @Autowired
|
|
|
+ private CommunityCollectionUserMapper communityCollectionUserMapper;
|
|
|
|
|
|
/**
|
|
|
* 添加文章到用户合集中
|
|
@@ -79,7 +85,62 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
|
|
|
* @return 文章信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<CommunityCollectionArticleVo> selectArticleInfoInCollection(Long collectionId) {
|
|
|
+ public JSONArray selectArticleInfoInCollection(Long collectionId,Long searchType) {
|
|
|
+
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ //查询合集表
|
|
|
+ CommunityCollection communityCollection = communityCollectionMapper.selectOne(new QueryWrapper<CommunityCollection>()
|
|
|
+ .eq("id", collectionId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true)
|
|
|
+ .or()
|
|
|
+ .isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (communityCollection == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //没调用这一个接口 热度 + 1
|
|
|
+ UpdateWrapper<CommunityCollection> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", collectionId)
|
|
|
+ .and(w -> w.ne("is_delete", true).or().isNull("is_delete"));
|
|
|
+ updateWrapper.setSql("heat = IFNULL(heat, 0) + 1");
|
|
|
+ communityCollectionMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ //一级层级
|
|
|
+ JSONObject collectionObject = new JSONObject();
|
|
|
+ collectionObject.put("CollectionName",communityCollection.getCollectionName());
|
|
|
+ Date updateTime = communityCollection.getUpdateTime();
|
|
|
+ if (updateTime == null){
|
|
|
+ updateTime = communityCollection.getCreateTime();
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedUpdateTime = sdf.format(updateTime);
|
|
|
+ collectionObject.put("CreateBy",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());
|
|
|
+
|
|
|
+ //查询当前用户是否订阅
|
|
|
+ CommunityCollectionUser communityCollectionUser = communityCollectionUserMapper.selectOne(new QueryWrapper<CommunityCollectionUser>()
|
|
|
+ .eq("collection_id", collectionId)
|
|
|
+ .eq("user_id", SecurityUtils.getUserId())
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true)
|
|
|
+ .or()
|
|
|
+ .isNull("is_delete");
|
|
|
+ }));
|
|
|
+ boolean follow = false;
|
|
|
+ if (communityCollectionUser != null){
|
|
|
+ follow = true;
|
|
|
+ }
|
|
|
+ collectionObject.put("follow",follow);
|
|
|
+
|
|
|
+ //查询合集关联文章表
|
|
|
List<Object> articleIdsObj = collectionArticleMapper
|
|
|
.selectObjs(new QueryWrapper<CommunityCollectionArticle>()
|
|
|
.select("article_id")
|
|
@@ -93,13 +154,30 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
|
|
|
if (articleIdsObj.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
+ collectionObject.put("articleNumber", articleIdsObj.size());
|
|
|
+
|
|
|
|
|
|
//转换object为long
|
|
|
List<Long> articleIds = articleIdsObj.stream()
|
|
|
.filter(item -> item instanceof Long)
|
|
|
.map(item -> (Long) item)
|
|
|
.collect(Collectors.toList());
|
|
|
- List<CommunityArticle> communityArticles = communityArticleMapper.selectBatchIds(articleIds);
|
|
|
+
|
|
|
+
|
|
|
+ List<CommunityArticle> communityArticles;
|
|
|
+
|
|
|
+ if (searchType == 1) {
|
|
|
+ // 查询最新的文章
|
|
|
+ communityArticles = communityArticleMapper.selectList(
|
|
|
+ new QueryWrapper<CommunityArticle>().in("id", articleIds).orderByDesc("create_time"));
|
|
|
+ } else{
|
|
|
+ // 查询最早的文章
|
|
|
+ communityArticles = communityArticleMapper.selectList(
|
|
|
+ new QueryWrapper<CommunityArticle>().in("id", articleIds).orderByAsc("create_time"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
List<CommunityCollectionArticleVo> collectionArticleVos = new ArrayList<>();
|
|
|
CommunityCollectionArticleVo collectionArticleVo = null;
|
|
@@ -126,7 +204,10 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
|
|
|
|
|
|
collectionArticleVos.add(collectionArticleVo);
|
|
|
}
|
|
|
- return collectionArticleVos;
|
|
|
+ collectionObject.put("Article",collectionArticleVos);
|
|
|
+ jsonArray.add(collectionObject);
|
|
|
+
|
|
|
+ return jsonArray;
|
|
|
}
|
|
|
|
|
|
/**
|