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