inleft
2022-08-02 70097d968795fcc872095c42f7b7bba618baaaf9
commit | author | age
0613f2 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.blogStatistics;
26
27 import cn.hutool.core.date.DateUnit;
28 import cn.hutool.core.date.DateUtil;
29 import org.springframework.web.bind.annotation.GetMapping;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RestController;
32 import vip.xiaonuo.core.annotion.BusinessLog;
a9c4c9 33 import vip.xiaonuo.core.consts.MyConstant;
0613f2 34 import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
ba780f 35 import vip.xiaonuo.core.exception.BlogException;
0613f2 36 import vip.xiaonuo.core.pojo.response.ResponseData;
I 37 import vip.xiaonuo.core.pojo.response.SuccessResponseData;
504927 38 import vip.xiaonuo.modular.blogStatistics.vo.BlogArchiveDetailVo;
a9c4c9 39 import vip.xiaonuo.modular.blogStatistics.vo.BlogArchiveVo;
0613f2 40 import vip.xiaonuo.modular.blogStatistics.vo.BlogStatisticsVo;
I 41 import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
42 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
ba780f 43 import vip.xiaonuo.modular.blogarticlecomment.entity.BlogArticleComment;
I 44 import vip.xiaonuo.modular.blogarticlecomment.service.BlogArticleCommentService;
0613f2 45
I 46 import javax.annotation.Resource;
a9c4c9 47 import java.util.*;
504927 48 import java.util.function.Function;
I 49 import java.util.stream.Collectors;
0613f2 50
I 51 /**
52  * blog文章控制器 (提供给外部blog系统查询)
53  *
54  * @author inleft
55  * @date 2022-02-09 18:20:22
56  */
57 @RestController
58 @RequestMapping("/outside")
59 public class BlogStatisticsController {
60
61     @Resource
62     private BlogArticleService blogArticleService;
63
ba780f 64     @Resource
I 65     private BlogArticleCommentService commentService;
66
0613f2 67     /**
I 68      * @author inleft
69      * @date 2022-02-09 18:20:22
70      */
71     @GetMapping("/blog/statistics")
72     @BusinessLog(title = "外部blog系统_统计_查询", opType = LogAnnotionOpTypeEnum.QUERY)
73     public ResponseData statistics() {
74
4d51af 75         String updateDate = "--";
ba780f 76         BlogArticle lastUpdateBlog = blogArticleService.lambdaQuery().orderByDesc(BlogArticle::getUpdateDate).last(MyConstant.limit).one();
0613f2 77         if (lastUpdateBlog != null && lastUpdateBlog.getUpdateDate() != null) {
I 78             updateDate = DateUtil.formatDate(lastUpdateBlog.getUpdateDate());
ba780f 79         }
I 80
81         //新增最近的评论时间
82         BlogArticleComment comment = commentService.lambdaQuery()
83                 .eq(BlogArticleComment::getVisitorNickName, MyConstant.inleft)
84                 .orderByDesc(BlogArticleComment::getCreateDate)
85                 .last(MyConstant.limit)
86                 .select(BlogArticleComment::getId,BlogArticleComment::getCreateDate)
87                 .one();
88
89         if (comment != null && comment.getUpdateDate() != null
90                 && lastUpdateBlog != null
91                 && lastUpdateBlog.getCreateDate().before(comment.getCreateDate())) {
92             updateDate = DateUtil.formatDate(comment.getCreateDate());
0613f2 93         }
4d51af 94
0613f2 95         String startFrom = "从这开始: 2020-05-27 ";
4d51af 96         String aliveDayCount = "已稳定运行:" + DateUtil.between(DateUtil.parseDate("2022-02-14"), new Date(), DateUnit.DAY) + "天";
e343e5 97         String lastUpdateDate = "上次活跃于:" + updateDate;
4d51af 98         String visitCount = "累计访问:1010次"; //24小时ip 访问次数
I 99         String visitorCount = "累计访客:1001名";//所有时间ip个数
0613f2 100
I 101         List<BlogStatisticsVo.simpleVo> res = new ArrayList<>();
102         res.add(new BlogStatisticsVo.simpleVo().setName(startFrom));
103         res.add(new BlogStatisticsVo.simpleVo().setName(aliveDayCount));
104         res.add(new BlogStatisticsVo.simpleVo().setName(lastUpdateDate));
a9c4c9 105 //        res.add(new BlogStatisticsVo.simpleVo().setName(visitCount));
I 106 //        res.add(new BlogStatisticsVo.simpleVo().setName(visitorCount));
0613f2 107
I 108         BlogStatisticsVo statisticsVo = new BlogStatisticsVo();
109         statisticsVo.setList(res);
110         statisticsVo.setTitle("统计信息");
111         return new SuccessResponseData(statisticsVo);
112
113     }
114
a9c4c9 115     /**
I 116      * 查询blog归档
117      *
118      * @author inleft
119      * @date 2022-02-09 18:20:22
120      */
121     @GetMapping("/blog/archive")
122     @BusinessLog(title = "外部blog系统_blog归档_查询", opType = LogAnnotionOpTypeEnum.QUERY)
504927 123     public ResponseData archive() {
a9c4c9 124         //不考虑数据太多的情况,这里应该可以把数据全部捞出来
I 125
126         List<BlogArticle> articleList = blogArticleService.lambdaQuery()
127                 .eq(BlogArticle::getIsEnable, MyConstant.Yes)
128                 .eq(BlogArticle::getEditorStatus, MyConstant.Yes)
129                 .orderByDesc(BlogArticle::getSeparateYear)
130                 .groupBy(BlogArticle::getSeparateYear)
131                 .select(BlogArticle::getSeparateYear)
132                 .list();
133
134         List<BlogArchiveVo> res = new ArrayList<>(articleList.size());
135         BlogArchiveVo blogArchiveVo;
136         for (BlogArticle blogArticle : articleList) {
137
138             blogArchiveVo = new BlogArchiveVo();
139             blogArchiveVo.setYear(blogArticle.getSeparateYear().toString());
140             blogArchiveVo.setList(blogArticleService.searchMonthCount(blogArticle.getSeparateYear()));
141             res.add(blogArchiveVo);
142         }
143
144         return new SuccessResponseData(res);
145     }
146
504927 147     @GetMapping("/blog/archiveGroup")
I 148     @BusinessLog(title = "外部blog系统_blog归档组列表_查询", opType = LogAnnotionOpTypeEnum.QUERY)
149     public ResponseData archiveGroup(Integer year, Integer month) {
150
151         List<BlogArticle> articleList = blogArticleService.lambdaQuery()
152                 .eq(BlogArticle::getIsEnable, MyConstant.Yes)
153                 .eq(BlogArticle::getEditorStatus, MyConstant.Yes)
154                 .eq(year != null, BlogArticle::getSeparateYear, year)
155                 .eq(month != null, BlogArticle::getSeparateMonth, month)
156                 .orderByDesc(BlogArticle::getSeparateYear)
157                 .orderByDesc(BlogArticle::getSeparateMonth)
158                 .select(BlogArticle::getId, BlogArticle::getTitle,
159                         BlogArticle::getAuthStatus,
160                         BlogArticle::getSeparateYear,
161                         BlogArticle::getSeparateMonth,
162                         BlogArticle::getSeparateDay)
163                 .list();
164
165         Map<Integer, List<BlogArticle>> groupMap = articleList.stream()
166                 .collect(Collectors.groupingBy(e -> e.getSeparateYear(), LinkedHashMap::new,
167                         Collectors.mapping(Function.identity(), Collectors.toList())));
168
169         List<BlogArchiveVo> res = new ArrayList<>(groupMap.size());
170         BlogArchiveVo archiveVo;
171
172         Map<String, List<BlogArchiveDetailVo.simpleVo>> detailGroup;
173         List<BlogArchiveDetailVo> tempDetailList;
174
175         for (Integer key : groupMap.keySet()) {
176             archiveVo = new BlogArchiveVo();
177             archiveVo.setYear(key.toString());
178
2782f3 179             detailGroup = groupMap.get(key).stream().sorted(
I 180                     Comparator.comparing(BlogArticle::getSeparateMonth)
181                             .thenComparing(BlogArticle::getSeparateDay).reversed())
504927 182                     .collect(Collectors.groupingBy(e -> e.getSeparateMonth().toString() + "月" + e.getSeparateDay() + "日", LinkedHashMap::new,
I 183                             Collectors.mapping(e -> {
184                                 BlogArchiveDetailVo.simpleVo simpleVo = new BlogArchiveDetailVo.simpleVo();
185                                 simpleVo.setName(e.getTitle());
186                                 simpleVo.setId(e.getId());
187                                 simpleVo.setAuthStatus(e.getAuthStatus());
188                                 return simpleVo;
189                             }, Collectors.toList())));
190
191             tempDetailList = new ArrayList<>(detailGroup.size());
192             archiveVo.setList(tempDetailList);
193             for (String monthAndDay : detailGroup.keySet()) {
194                 BlogArchiveDetailVo detailVo = new BlogArchiveDetailVo();
195                 detailVo.setMonth(monthAndDay);
196                 detailVo.setList(detailGroup.get(monthAndDay));
197                 tempDetailList.add(detailVo);
198             }
199
200             res.add(archiveVo);
201         }
202
203         return new SuccessResponseData(res);
204     }
0613f2 205
ba780f 206
I 207     @GetMapping("/blog/option")
208     @BusinessLog(title = "外部blog系统_blog统计数据_添加", opType = LogAnnotionOpTypeEnum.EDIT)
209     public ResponseData option(Long articleId, Integer option) {
210         BlogArticle find = blogArticleService.lambdaQuery()
211                 .eq(BlogArticle::getIsEnable, MyConstant.Yes)
212                 .eq(BlogArticle::getEditorStatus, MyConstant.Yes)
213                 .eq(BlogArticle::getId, articleId)
214                 .one();
215         if (find == null) {
216             throw new BlogException("查询不到相关日志");
217         }
218         /**
219          * 同一个ip,24小时之内只统计一次 访问次数,访问人数(ip)
220          */
221         return null;
222     }
0613f2 223 }