forked from weiwosuoai/WeBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
740 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...boot/weblog-web/src/main/java/com/quanxiaoha/weblog/web/controller/ArchiveController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.quanxiaoha.weblog.web.controller; | ||
|
||
import com.quanxiaoha.weblog.common.PageResponse; | ||
import com.quanxiaoha.weblog.common.Response; | ||
import com.quanxiaoha.weblog.common.aspect.ApiOperationLog; | ||
import com.quanxiaoha.weblog.web.model.vo.archive.QueryArchivePageListReqVO; | ||
import com.quanxiaoha.weblog.web.model.vo.article.QueryIndexArticlePageListReqVO; | ||
import com.quanxiaoha.weblog.web.model.vo.article.QueryTagArticlePageListReqVO; | ||
import com.quanxiaoha.weblog.web.service.ArchiveService; | ||
import com.quanxiaoha.weblog.web.service.ArticleService; | ||
import com.quanxiaoha.weblog.web.service.TagService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author: 犬小哈 | ||
* @url: www.quanxiaoha.com | ||
* @date: 2023-04-18 8:14 | ||
* @description: 归档 | ||
**/ | ||
@RestController | ||
@RequestMapping("/archive") | ||
public class ArchiveController { | ||
|
||
@Autowired | ||
private ArchiveService archiveService; | ||
|
||
@PostMapping("/list") | ||
@ApiOperationLog(description = "获取文章归档列表") | ||
public Response queryArchive(@RequestBody QueryArchivePageListReqVO queryArchivePageListReqVO) { | ||
return archiveService.queryArchive(queryArchivePageListReqVO); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...g-web/src/main/java/com/quanxiaoha/weblog/web/model/vo/archive/QueryArchiveItemRspVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.quanxiaoha.weblog.web.model.vo.archive; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class QueryArchiveItemRspVO { | ||
private Long id; | ||
private String titleImage; | ||
private String title; | ||
private String createMonth; | ||
private String createTime; | ||
} |
16 changes: 16 additions & 0 deletions
16
...b/src/main/java/com/quanxiaoha/weblog/web/model/vo/archive/QueryArchivePageListReqVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.quanxiaoha.weblog.web.model.vo.archive; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class QueryArchivePageListReqVO { | ||
private Long current = 1L; | ||
private Long size = 10L; | ||
} |
20 changes: 20 additions & 0 deletions
20
...b/src/main/java/com/quanxiaoha/weblog/web/model/vo/archive/QueryArchivePageListRspVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.quanxiaoha.weblog.web.model.vo.archive; | ||
|
||
|
||
import com.quanxiaoha.weblog.web.model.vo.category.QueryCategoryListRspVO; | ||
import com.quanxiaoha.weblog.web.model.vo.tag.QueryTagListRspVO; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class QueryArchivePageListRspVO { | ||
private String month; | ||
private List<QueryArchiveItemRspVO> articles; | ||
} |
13 changes: 13 additions & 0 deletions
13
...springboot/weblog-web/src/main/java/com/quanxiaoha/weblog/web/service/ArchiveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.quanxiaoha.weblog.web.service; | ||
|
||
import com.baomidou.mybatisplus.extension.service.IService; | ||
import com.quanxiaoha.weblog.common.Response; | ||
import com.quanxiaoha.weblog.common.domain.dos.ArticleDO; | ||
import com.quanxiaoha.weblog.common.domain.dos.TagDO; | ||
import com.quanxiaoha.weblog.web.model.vo.archive.QueryArchivePageListReqVO; | ||
|
||
|
||
public interface ArchiveService extends IService<ArticleDO> { | ||
|
||
Response queryArchive(QueryArchivePageListReqVO queryArchivePageListReqVO); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...t/weblog-web/src/main/java/com/quanxiaoha/weblog/web/service/impl/ArchiveServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.quanxiaoha.weblog.web.service.impl; | ||
|
||
import com.baomidou.mybatisplus.core.metadata.IPage; | ||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
import com.google.common.collect.Lists; | ||
import com.quanxiaoha.weblog.common.PageResponse; | ||
import com.quanxiaoha.weblog.common.Response; | ||
import com.quanxiaoha.weblog.common.constant.Constants; | ||
import com.quanxiaoha.weblog.common.domain.dos.*; | ||
import com.quanxiaoha.weblog.common.domain.mapper.ArticleMapper; | ||
import com.quanxiaoha.weblog.common.domain.mapper.TagMapper; | ||
import com.quanxiaoha.weblog.web.dao.ArticleDao; | ||
import com.quanxiaoha.weblog.web.dao.TagDao; | ||
import com.quanxiaoha.weblog.web.model.vo.archive.QueryArchiveItemRspVO; | ||
import com.quanxiaoha.weblog.web.model.vo.archive.QueryArchivePageListReqVO; | ||
import com.quanxiaoha.weblog.web.model.vo.archive.QueryArchivePageListRspVO; | ||
import com.quanxiaoha.weblog.web.model.vo.article.QueryIndexArticlePageListRspVO; | ||
import com.quanxiaoha.weblog.web.model.vo.category.QueryCategoryListRspVO; | ||
import com.quanxiaoha.weblog.web.model.vo.tag.QueryTagListRspVO; | ||
import com.quanxiaoha.weblog.web.service.ArchiveService; | ||
import com.quanxiaoha.weblog.web.service.TagService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.time.YearMonth; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author: 犬小哈 | ||
* @url: www.quanxiaoha.com | ||
* @date: 2023-04-17 12:08 | ||
* @description: TODO | ||
**/ | ||
@Service | ||
@Slf4j | ||
public class ArchiveServiceImpl extends ServiceImpl<ArticleMapper, ArticleDO> implements ArchiveService { | ||
|
||
@Autowired | ||
private ArticleDao articleDao; | ||
|
||
@Override | ||
public Response queryArchive(QueryArchivePageListReqVO queryArchivePageListReqVO) { | ||
Long current = queryArchivePageListReqVO.getCurrent(); | ||
Long size = queryArchivePageListReqVO.getSize(); | ||
|
||
IPage<ArticleDO> articleDOIPage = articleDao.queryArticlePageList(current, size); | ||
List<ArticleDO> records = articleDOIPage.getRecords(); | ||
|
||
List<QueryArchivePageListRspVO> list = Lists.newArrayList(); | ||
List<QueryArchiveItemRspVO> itemRspVOList = null; | ||
if (!CollectionUtils.isEmpty(records)) { | ||
itemRspVOList = records.stream() | ||
.map(p -> QueryArchiveItemRspVO.builder() | ||
.id(p.getId()) | ||
.title(p.getTitle()) | ||
.titleImage(p.getTitleImage()) | ||
.createMonth(Constants.MONTH_FORMAT.format(p.getCreateTime())) | ||
.createTime(Constants.DATE_FORMAT.format(p.getCreateTime())) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
Map<String, List<QueryArchiveItemRspVO>> map = itemRspVOList.stream().collect(Collectors.groupingBy(QueryArchiveItemRspVO::getCreateMonth)); | ||
Map<String, List<QueryArchiveItemRspVO>> sortedMap = new TreeMap<>(new MonthKeyComparator()); | ||
sortedMap.putAll(map); | ||
|
||
sortedMap.forEach((k, v) -> list.add(QueryArchivePageListRspVO.builder().month(k).articles(v).build())); | ||
} | ||
return PageResponse.success(articleDOIPage, list); | ||
} | ||
|
||
class MonthKeyComparator implements Comparator<String> { | ||
@Override | ||
public int compare(String o1, String o2) { | ||
// 使用YearMonth类将字符串解析成日期,并根据日期进行倒序排序 | ||
YearMonth ym1 = YearMonth.parse(o1); | ||
YearMonth ym2 = YearMonth.parse(o2); | ||
return ym2.compareTo(ym1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.