inleft
2024-05-18 2ddbd99aa5b2e396f96c6daba60fe1ac2573d9fb
commit | author | age
2ddbd9 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.modular.xmlFeed;
26
27 import cn.hutool.core.date.DateUtil;
28 import cn.hutool.core.util.StrUtil;
29 import com.rometools.rome.feed.rss.*;
30 import lombok.extern.slf4j.Slf4j;
31 import org.springframework.web.bind.annotation.GetMapping;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.RestController;
34 import vip.xiaonuo.core.annotion.BusinessLog;
35 import vip.xiaonuo.core.consts.MyConstant;
36 import vip.xiaonuo.core.context.constant.ConstantContextHolder;
37 import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
38 import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
39 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
40 import vip.xiaonuo.sys.modular.file.service.SysFileInfoService;
41
42 import javax.annotation.Resource;
43 import java.util.*;
44 import java.util.stream.Collectors;
45
46 /**
47  * blog文章控制器 (提供给外部blog系统查询)
48  *
49  * @author inleft
50  * @date 2024-05-18 09:23:00
51  */
52 @RestController
53 @RequestMapping
54 @Slf4j
55 public class BlogFeedController {
56
57     @Resource
58     private BlogArticleService blogArticleService;
59
60
61     @Resource
62     private SysFileInfoService fileInfoService;
63
64
65     /**
66      * 获取订阅列表,返回最新的10条
67      *
68      * @author inleft
69      * @date 2024-05-18 09:23:00
70      */
71     @GetMapping("/feed")
72     @BusinessLog(title = "获取订阅列表", opType = LogAnnotionOpTypeEnum.QUERY)
73     public Channel queryBlogArticleList() {
74
75
76         Map<String, Object> param = new HashMap<>(16);
77         param.put("pageNo", 0);
78         param.put("pageSize", 10);
79
80         param.put("faceExcludeFile", MyConstant.faceExcludeFile);
81         String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix();
82
83
84         Channel channel = new Channel();
85         channel.setFeedType("rss_2.0");
86         channel.setTitle("inleft");
87         channel.setDescription("在你左边,听风及雨");
88         channel.setLink("http://blog.inleft.com");
89         channel.setUri("http://blog.inleft.com");
90         channel.setGenerator("inleft");
91
92         Image image = new Image();
93         image.setUrl("http://t.inleft.com/share/media_photo/xigong.png");
94         image.setTitle("inleft");
95         image.setHeight(32);
96         image.setWidth(32);
97         channel.setImage(image);
98
99         //更新明细
100
101         Date now = DateUtil.date();
102         //空类型查询条件,排除笔记系列,按更新时间倒序
103         //含有类型查询,按发布时间倒序
104         List<Item> resList = blogArticleService.searchList(param).stream().map(e -> {
105
106             Source source = new Source();
107             if (StrUtil.isNotEmpty(e.getCoverFileURL())) {
108                 if (!e.getCoverFileURL().startsWith("http")) {
109                     //补上访问参数
110                     source.setUrl(blogSourcePrefix + e.getCoverFileURL());
111                     source.setValue(blogSourcePrefix + e.getCoverFileURL());
112                 }
113             }else {
114                 source.setUrl("http://t.inleft.com/share/media_photo/1.jpg");
115                 source.setValue("http://t.inleft.com/share/media_photo/1.jpg");
116             }
117
118             Category category = new com.rometools.rome.feed.rss.Category();
119             category.setValue(e.getArticleTypeName());
120
121
122             Description descr = new Description();
123             descr.setValue(e.getIntroduce());
124
125             Item item = new Item();
126             item.setAuthor("inleft");
127
128             item.setUri("http://blog.inleft.com");
129
130             item.setComments("http://blog.inleft.com/mdDetail?id=" + e.getId());
131
132             item.setTitle(e.getTitle());
133             item.setLink("http://blog.inleft.com/mdDetail?id=" + e.getId());
134             item.setDescription(descr);
135             item.setCategories(Collections.singletonList(category));
136             item.setSource(source);
137             item.setPubDate(e.getUpdateDate());
138
139             //前端根据条件标注小红点(发布时间小于更新时间,且在7天内)
140             /*if (e.getPublishDate().before(e.getUpdateDate())
141                     && DateUtil.between(e.getUpdateDate(), now, DateUnit.DAY) <= 7) {
142                 e.setIsAnyUpdate(MyConstant.Yes);
143                 item.setTitle(e.getTitle()+"(最近翻新)");
144             }*/
145
146             return item;
147         }).collect(Collectors.toList());
148
149
150         //最后更新时间
151         BlogArticle lastUpdateBlog = blogArticleService.lambdaQuery().orderByDesc(BlogArticle::getUpdateDate).last(MyConstant.limit).one();
152         if (lastUpdateBlog != null && lastUpdateBlog.getUpdateDate() != null) {
153             channel.setLastBuildDate(lastUpdateBlog.getUpdateDate());
154         }
155         channel.setPubDate(now);
156
157         channel.setItems(resList);
158
159         return channel;
160     }
161
162 }