Skip to content

Commit 338bf6f

Browse files
committed
Add: 添加【新内容】和【内容有更新】特殊文章标签检索
1 parent 9b9fab2 commit 338bf6f

File tree

20 files changed

+327
-71
lines changed

20 files changed

+327
-71
lines changed

upupor-framework/src/main/java/com/upupor/framework/CcConstant.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public final class CcConstant {
145145
*/
146146
public static final String CV_OFF = "0";
147147
public static final String CV_ON = "1";
148-
public static final String CONTENT_LIST = "content/list";
149-
public static final String CONTENT_ALL = "content/all";
150148

151149
public static final class UserView {
152150
public static final String BASE_PATH = "user";
@@ -163,13 +161,12 @@ public static final class UserView {
163161
public static final String TAG_INDEX = "tag/index";
164162
public static final String EDITOR = "editor/editor";
165163
public static final String BEFORE_EDITOR = "components/before-editor";
166-
public static final String CONTENT_INDEX = "content/index";
164+
167165
public static final String EDIT_USER_MANAGE_ADMIN = "user/admin/admin";
168166
public static final String EDIT_USER_MANAGE_CONTENT = "user/admin/content";
169167
public static final String FEEDBACK_INDEX = "feedback/index";
170168
public static final String INTEGRAL_INDEX = "integral/index";
171169
public static final String PINNED_INDEX = "foot/pinned";
172-
public static final String CONTENT_HISTORY = "content/history";
173170
public static final String RADIO_STATION_LIST = "radio-station/list";
174171
public static final String RADIO_STATION_CREATE = "radio-station/create";
175172
public static final String RADIO_STATION_RECORD = "radio-station/record";
@@ -179,6 +176,16 @@ public static final class UserView {
179176
public static final String OPEN = "foot/opensource";
180177
public static final String MARKDOWN = "components/markdown";
181178
public static final String OUR_HOME = "components/our-home";
179+
public static final class ContentView {
180+
// 文章列表
181+
public static final String CONTENT_LIST = "content/list";
182+
// 全部文章 、 最近编辑过的
183+
public static final String CONTENT_TYPE = "content/type";
184+
// 文章详情
185+
public static final String CONTENT_INDEX = "content/index";
186+
// 临时文章
187+
public static final String CONTENT_HISTORY = "content/history";
188+
}
182189
/**
183190
* 运营活动
184191
*/
@@ -259,6 +266,7 @@ public static final class SeoKey {
259266
public static final String TITLE = "seo_title";
260267
public static final String DESCRIPTION = "seo_description";
261268
public static final String KEYWORDS = "seo_keywords";
269+
public static final String BUSINESS_TITLE = "businessTitle";
262270
}
263271

264272
/**
@@ -281,6 +289,7 @@ public static final class Page {
281289
* 每页条数
282290
*/
283291
public static final Integer SIZE = 15;
292+
public static final Integer SIZE_HALF = 7;
284293
public static final Integer SIZE_COMMENT = 30;
285294
public static final Integer SIZE_TEN = 10;
286295
/**

upupor-service/src/main/java/com/upupor/service/business/aggregation/CommonAggregateService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public CommonPageIndexDto index(GetCommonReq getCommonReq) {
127127
// 最近一周新增的文章
128128
List<Content> latestContentList = contentService.latestContentList();
129129

130-
131130
// 获取Banner栏
132131
ListBannerDto listBannerDto = bannerService.listBannerByStatus(BannerStatus.NORMAL, CcConstant.Page.NUM, CcConstant.Page.SIZE);
133132

upupor-service/src/main/java/com/upupor/service/business/aggregation/dao/entity/ContentData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ public void minusLikeNum(){
5151
this.likeNum = this.likeNum - 1;
5252
}
5353

54+
public void incrementViewNum(){
55+
this.viewNum = this.viewNum + 1;
56+
}
57+
58+
5459
}

upupor-service/src/main/java/com/upupor/service/business/aggregation/service/ContentService.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.upupor.service.outer.req.UpdateContentReq;
4040
import com.upupor.service.types.ContentType;
4141
import com.upupor.service.types.PinnedStatus;
42+
import com.upupor.service.types.SearchContentType;
4243

4344
import java.util.List;
4445

@@ -76,25 +77,25 @@ public interface ContentService {
7677
*/
7778
ListContentDto listContent(ListContentReq listContentReq);
7879

79-
8080
/**
81-
* 根据标题搜索
81+
* 根据文章类型来获取文章列表
8282
*
83-
* @param listContentReq
83+
* @param contentType
84+
* @param pageNum
85+
* @param pageSize
8486
* @return
8587
*/
86-
ListContentDto listContentByTitleAndShortContent(ListContentReq listContentReq);
87-
88+
ListContentDto listContentByContentType(ContentType contentType, Integer pageNum, Integer pageSize, String tag);
8889

8990
/**
90-
* 根据文章类型来获取文章列表
91-
*
92-
* @param contentType
91+
* 不同类型的文章列表
92+
* @note: 全部文章、最近更新的、新内容
93+
* @param searchType
9394
* @param pageNum
9495
* @param pageSize
9596
* @return
9697
*/
97-
ListContentDto listContentByContentType(ContentType contentType, Integer pageNum, Integer pageSize, String tag);
98+
ListContentDto typeContentList(SearchContentType searchType, Integer pageNum, Integer pageSize);
9899

99100
/**
100101
* 添加内容
@@ -157,13 +158,6 @@ public interface ContentService {
157158
void bindRadioContentData(List<Radio> radioList);
158159

159160

160-
/**
161-
* 绑定个人详情页内容数据
162-
*
163-
* @param listContentDto
164-
*/
165-
void bindContentData(ListContentDto listContentDto);
166-
167161
/**
168162
* 绑定文章扩展信息
169163
*
@@ -296,6 +290,7 @@ public interface ContentService {
296290

297291
/**
298292
* 最近一周新增的文章
293+
* @note: 只显示15条
299294
* @return
300295
*/
301296
List<Content> latestContentList();

upupor-service/src/main/java/com/upupor/service/business/aggregation/service/impl/ContentServiceImpl.java

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.github.pagehelper.PageHelper;
3232
import com.github.pagehelper.PageInfo;
3333
import com.google.common.collect.Lists;
34+
import com.upupor.framework.CcConstant;
3435
import com.upupor.framework.utils.CcDateUtil;
3536
import com.upupor.service.business.aggregation.dao.entity.*;
3637
import com.upupor.service.business.aggregation.dao.mapper.*;
@@ -49,10 +50,7 @@
4950
import com.upupor.service.outer.req.GetMemberIntegralReq;
5051
import com.upupor.service.outer.req.ListContentReq;
5152
import com.upupor.service.outer.req.UpdateContentReq;
52-
import com.upupor.service.types.ContentStatus;
53-
import com.upupor.service.types.ContentType;
54-
import com.upupor.service.types.MemberIntegralStatus;
55-
import com.upupor.service.types.PinnedStatus;
53+
import com.upupor.service.types.*;
5654
import com.upupor.service.utils.Asserts;
5755
import com.upupor.service.utils.ServletUtils;
5856
import lombok.RequiredArgsConstructor;
@@ -66,6 +64,7 @@
6664
import java.util.*;
6765
import java.util.stream.Collectors;
6866

67+
import static com.upupor.framework.CcConstant.Time.CONTENT_UPDATE_TIME;
6968
import static com.upupor.framework.CcConstant.Time.NEW_CONTENT_TIME;
7069
import static com.upupor.service.common.ErrorCode.*;
7170

@@ -154,20 +153,9 @@ public ListContentDto listContent(ListContentReq listContentReq) {
154153
.in(!CollectionUtils.isEmpty(listContentReq.getTagIdList()), Content::getTagIds, listContentReq.getTagIdList())
155154
.orderByDesc(Content::getCreateTime);
156155

157-
PageHelper.startPage(listContentReq.getPageNum(), listContentReq.getPageSize());
158-
List<Content> contents = contentMapper.selectList(query);
159-
PageInfo<Content> pageInfo = new PageInfo<>(contents);
160-
161-
ListContentDto listContentDto = new ListContentDto(pageInfo);
162-
listContentDto.setContentList(pageInfo.getList());
163-
164-
// 绑定文章数据
165-
this.bindContentData(listContentDto.getContentList());
166-
// 绑定用户信息
167-
this.bindContentMember(listContentDto.getContentList());
156+
ListContentDto listContentDto = commonListContentDtoQuery(listContentReq.getPageNum(), listContentReq.getPageSize(), query);
168157
// 处理文章置顶
169158
handlePinnedContent(listContentDto, listContentReq.getUserId());
170-
171159
return listContentDto;
172160
}
173161

@@ -195,15 +183,25 @@ public void handlePinnedContent(ListContentDto listContentDto, String userId) {
195183
}
196184

197185

198-
199186
@Override
200187
public ListContentDto listContentByContentType(ContentType contentType, Integer pageNum, Integer pageSize, String tag) {
201188
LambdaQueryWrapper<Content> query = new LambdaQueryWrapper<Content>()
202189
.eq(Content::getStatus, ContentStatus.NORMAL)
203-
.eq(Objects.nonNull(contentType),Content::getContentType, contentType)
204-
.eq(Objects.nonNull(tag),Content::getTagIds, tag)
190+
.eq(Objects.nonNull(contentType), Content::getContentType, contentType)
191+
.eq(Objects.nonNull(tag), Content::getTagIds, tag)
205192
.orderByDesc(Content::getLatestCommentTime);
193+
return commonListContentDtoQuery(pageNum, pageSize, query);
194+
}
206195

196+
/**
197+
* 通用Query & 封装
198+
*
199+
* @param pageNum
200+
* @param pageSize
201+
* @param query
202+
* @return
203+
*/
204+
private ListContentDto commonListContentDtoQuery(Integer pageNum, Integer pageSize, LambdaQueryWrapper<Content> query) {
207205
// 分页查询
208206
PageHelper.startPage(pageNum, pageSize);
209207
List<Content> contents = contentMapper.selectList(query);
@@ -212,7 +210,7 @@ public ListContentDto listContentByContentType(ContentType contentType, Integer
212210
// 封装文章数据
213211
this.bindContentData(pageInfo.getList());
214212
this.bindContentMember(contents);
215-
// 不能添加广告,会引起首页文章列表布局紊乱问题
213+
// 不能添加广告,会引起首页文章列表布局紊乱问题,如果需要添加广告,请在各业务外面添加
216214
// AbstractAd.ad(pageInfo.getList());
217215

218216
// 数据组装
@@ -221,6 +219,30 @@ public ListContentDto listContentByContentType(ContentType contentType, Integer
221219
return listContentDto;
222220
}
223221

222+
@Override
223+
public ListContentDto typeContentList(SearchContentType searchType, Integer pageNum, Integer pageSize) {
224+
// 默认的全部文章: SearchContentType.ALL.equals(searchType)
225+
LambdaQueryWrapper<Content> query = new LambdaQueryWrapper<Content>()
226+
.eq(Content::getStatus, ContentStatus.NORMAL)
227+
.orderByDesc(Content::getLatestCommentTime);
228+
229+
if (SearchContentType.RECENTLY_EDITED.equals(searchType)) {
230+
// 最近是否更新过
231+
// CcDateUtil.getCurrentTime() - editTime <= CONTENT_UPDATE_TIME;
232+
// ==> CcDateUtil.getCurrentTime() - CONTENT_UPDATE_TIME<= editTime;
233+
query.ge(Content::getEditTime, CcDateUtil.getCurrentTime() - CONTENT_UPDATE_TIME);
234+
}
235+
236+
if (SearchContentType.NEW.equals(searchType)) {
237+
// 是否是最近的新文章
238+
// CcDateUtil.getCurrentTime() - createTime <= NEW_CONTENT_TIME;
239+
// ==> CcDateUtil.getCurrentTime() - NEW_CONTENT_TIME <= createTime
240+
query.ge(Content::getCreateTime, CcDateUtil.getCurrentTime() - NEW_CONTENT_TIME);
241+
}
242+
243+
return commonListContentDtoQuery(pageNum, pageSize, query);
244+
}
245+
224246
/**
225247
* 绑定详细文章
226248
*
@@ -357,20 +379,6 @@ public void bindRadioContentData(List<Radio> radioList) {
357379

358380
}
359381

360-
@Override
361-
public void bindContentData(ListContentDto listContentDto) {
362-
if (Objects.isNull(listContentDto)) {
363-
return;
364-
}
365-
this.bindContentData(listContentDto.getContentList());
366-
this.bindContentMember(listContentDto);
367-
}
368-
369-
@Override
370-
public ListContentDto listContentByTitleAndShortContent(ListContentReq listContentReq) {
371-
listContentReq.setStatus(ContentStatus.NORMAL);
372-
return listContent(listContentReq);
373-
}
374382

375383
@Override
376384
public List<Content> listAllByUserId(String userId) {
@@ -486,7 +494,7 @@ public void viewNumPlusOne(String targetId) {
486494
}
487495

488496
ContentData contentData = contentDataList.get(0);
489-
contentData.setViewNum(contentData.getViewNum() + 1);
497+
contentData.incrementViewNum();
490498
contentDataMapper.updateById(contentData);
491499
} catch (Exception e) {
492500
e.printStackTrace();
@@ -645,7 +653,9 @@ public List<Content> latestContentList() {
645653
.ge(Content::getCreateTime, CcDateUtil.getCurrentTime() - NEW_CONTENT_TIME)
646654
.orderByDesc(Content::getCreateTime);
647655

656+
PageHelper.startPage(CcConstant.Page.NUM, CcConstant.Page.SIZE_HALF);
648657
List<Content> contentList = contentMapper.selectList(query);
658+
649659
this.bindContentMember(contentList);
650660
return contentList;
651661
}

upupor-service/src/main/java/com/upupor/service/business/pages/content/AllContentView.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
import com.upupor.service.business.aggregation.service.ContentService;
3333
import com.upupor.service.business.pages.AbstractView;
3434
import com.upupor.service.dto.page.common.ListContentDto;
35+
import com.upupor.service.types.SearchContentType;
3536
import lombok.RequiredArgsConstructor;
3637
import org.springframework.stereotype.Component;
3738

38-
import static com.upupor.framework.CcConstant.CONTENT_ALL;
39+
import static com.upupor.framework.CcConstant.ContentView.CONTENT_TYPE;
3940

4041
/**
4142
* @author Yang Runkang (cruise)
@@ -50,7 +51,7 @@ public class AllContentView extends AbstractView {
5051

5152
@Override
5253
public String viewName() {
53-
return CONTENT_ALL;
54+
return CONTENT_TYPE;
5455
}
5556

5657
@Override
@@ -62,13 +63,14 @@ protected String pageUrl() {
6263
protected void seoInfo() {
6364
modelAndView.addObject(CcConstant.SeoKey.TITLE, "全部文章");
6465
modelAndView.addObject(CcConstant.SeoKey.DESCRIPTION, "全部文章");
66+
modelAndView.addObject(CcConstant.SeoKey.BUSINESS_TITLE, "全部文章");
6567
}
6668

6769
@Override
6870
protected void fetchData() {
6971
Integer pageNum = query.getPageNum();
7072
Integer pageSize = query.getPageSize();
71-
ListContentDto listContentDto = contentService.listContentByContentType(null, pageNum, pageSize, null);
73+
ListContentDto listContentDto = contentService.typeContentList(SearchContentType.getByUrl(URL), pageNum, pageSize);
7274
AbstractAd.ad(listContentDto.getContentList());
7375
modelAndView.addObject(listContentDto);
7476
}

upupor-service/src/main/java/com/upupor/service/business/pages/content/ContentDetailView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import java.util.Objects;
4242

43-
import static com.upupor.framework.CcConstant.CONTENT_INDEX;
43+
import static com.upupor.framework.CcConstant.ContentView.CONTENT_INDEX;
4444
import static com.upupor.framework.CcConstant.Page.SIZE_COMMENT;
4545

4646
/**

upupor-service/src/main/java/com/upupor/service/business/pages/content/DraftContentDetailView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import lombok.RequiredArgsConstructor;
3636
import org.springframework.stereotype.Component;
3737

38-
import static com.upupor.framework.CcConstant.CONTENT_INDEX;
38+
import static com.upupor.framework.CcConstant.ContentView.CONTENT_INDEX;
3939

4040
/**
4141
* @author Yang Runkang (cruise)

0 commit comments

Comments
 (0)