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; |
a9c4c9
|
37 |
import vip.xiaonuo.modular.blogStatistics.vo.BlogArchiveVo; |
0613f2
|
38 |
import vip.xiaonuo.modular.blogStatistics.vo.BlogStatisticsVo; |
I |
39 |
import vip.xiaonuo.modular.blogarticle.entity.BlogArticle; |
|
40 |
import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; |
|
41 |
|
|
42 |
import javax.annotation.Resource; |
a9c4c9
|
43 |
import java.util.*; |
0613f2
|
44 |
|
I |
45 |
/** |
|
46 |
* blog文章控制器 (提供给外部blog系统查询) |
|
47 |
* |
|
48 |
* @author inleft |
|
49 |
* @date 2022-02-09 18:20:22 |
|
50 |
*/ |
|
51 |
@RestController |
|
52 |
@RequestMapping("/outside") |
|
53 |
public class BlogStatisticsController { |
|
54 |
|
|
55 |
@Resource |
|
56 |
private BlogArticleService blogArticleService; |
|
57 |
|
|
58 |
/** |
|
59 |
* @author inleft |
|
60 |
* @date 2022-02-09 18:20:22 |
|
61 |
*/ |
|
62 |
@GetMapping("/blog/statistics") |
|
63 |
@BusinessLog(title = "外部blog系统_统计_查询", opType = LogAnnotionOpTypeEnum.QUERY) |
|
64 |
public ResponseData statistics() { |
|
65 |
|
4d51af
|
66 |
String updateDate = "--"; |
I |
67 |
BlogArticle lastUpdateBlog = blogArticleService.lambdaQuery().orderByDesc(BlogArticle::getUpdateDate).last(" limit 1 ").one(); |
0613f2
|
68 |
if (lastUpdateBlog != null && lastUpdateBlog.getUpdateDate() != null) { |
I |
69 |
updateDate = DateUtil.formatDate(lastUpdateBlog.getUpdateDate()); |
|
70 |
} |
4d51af
|
71 |
|
0613f2
|
72 |
String startFrom = "从这开始: 2020-05-27 "; |
4d51af
|
73 |
String aliveDayCount = "已稳定运行:" + DateUtil.between(DateUtil.parseDate("2022-02-14"), new Date(), DateUnit.DAY) + "天"; |
0613f2
|
74 |
String lastUpdateDate = "上次更新:" + updateDate; |
4d51af
|
75 |
String visitCount = "累计访问:1010次"; //24小时ip 访问次数 |
I |
76 |
String visitorCount = "累计访客:1001名";//所有时间ip个数 |
0613f2
|
77 |
|
I |
78 |
List<BlogStatisticsVo.simpleVo> res = new ArrayList<>(); |
|
79 |
res.add(new BlogStatisticsVo.simpleVo().setName(startFrom)); |
|
80 |
res.add(new BlogStatisticsVo.simpleVo().setName(aliveDayCount)); |
|
81 |
res.add(new BlogStatisticsVo.simpleVo().setName(lastUpdateDate)); |
a9c4c9
|
82 |
// res.add(new BlogStatisticsVo.simpleVo().setName(visitCount)); |
I |
83 |
// res.add(new BlogStatisticsVo.simpleVo().setName(visitorCount)); |
0613f2
|
84 |
|
I |
85 |
BlogStatisticsVo statisticsVo = new BlogStatisticsVo(); |
|
86 |
statisticsVo.setList(res); |
|
87 |
statisticsVo.setTitle("统计信息"); |
|
88 |
return new SuccessResponseData(statisticsVo); |
|
89 |
|
|
90 |
} |
|
91 |
|
a9c4c9
|
92 |
/** |
I |
93 |
* 查询blog归档 |
|
94 |
* |
|
95 |
* @author inleft |
|
96 |
* @date 2022-02-09 18:20:22 |
|
97 |
*/ |
|
98 |
@GetMapping("/blog/archive") |
|
99 |
@BusinessLog(title = "外部blog系统_blog归档_查询", opType = LogAnnotionOpTypeEnum.QUERY) |
|
100 |
public ResponseData archive(Integer year, Integer month) { |
|
101 |
//不考虑数据太多的情况,这里应该可以把数据全部捞出来 |
|
102 |
|
|
103 |
List<BlogArticle> articleList = blogArticleService.lambdaQuery() |
|
104 |
.eq(BlogArticle::getIsEnable, MyConstant.Yes) |
|
105 |
.eq(BlogArticle::getEditorStatus, MyConstant.Yes) |
|
106 |
// .eq(year != null,BlogArticle::getSeparateYear, year) |
|
107 |
// .eq(month != null, BlogArticle::getSeparateMonth, month) |
|
108 |
.orderByDesc(BlogArticle::getSeparateYear) |
|
109 |
.groupBy(BlogArticle::getSeparateYear) |
|
110 |
.select(BlogArticle::getSeparateYear) |
|
111 |
.list(); |
|
112 |
|
|
113 |
List<BlogArchiveVo> res = new ArrayList<>(articleList.size()); |
|
114 |
BlogArchiveVo blogArchiveVo; |
|
115 |
for (BlogArticle blogArticle : articleList) { |
|
116 |
|
|
117 |
blogArchiveVo = new BlogArchiveVo(); |
|
118 |
blogArchiveVo.setYear(blogArticle.getSeparateYear().toString()); |
|
119 |
blogArchiveVo.setList(blogArticleService.searchMonthCount(blogArticle.getSeparateYear())); |
|
120 |
res.add(blogArchiveVo); |
|
121 |
} |
|
122 |
|
|
123 |
return new SuccessResponseData(res); |
|
124 |
} |
|
125 |
|
0613f2
|
126 |
|
I |
127 |
} |