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