liked(@ApiParam("文章id") @PathVariable("articleId") Integer articleId) {
39 | return createResponse(articleLikeService.liked(articleId));
40 | }
41 |
42 | @PostMapping("/add")
43 | @ApiOperation(value = "文章点赞")
44 | public ApiResponse like(@ApiParam("文章id") @RequestParam("articleId") Integer articleId) {
45 | articleLikeService.like(articleId);
46 | articleRecommendService.asyncRefresh(articleId);
47 | return createResponse();
48 | }
49 |
50 | @DeleteMapping("/cancel")
51 | @ApiOperation(value = "取消文章点赞")
52 | public ApiResponse cancel(@ApiParam("文章id") @NotNull(message = "文章id不能为空") @RequestParam("articleId") Integer articleId) {
53 | articleLikeService.cancel(articleId);
54 | articleRecommendService.asyncRefresh(articleId);
55 | return createResponse();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/ArticleReplyController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 |
4 | import cn.poile.blog.common.response.ApiResponse;
5 | import cn.poile.blog.service.IArticleReplyService;
6 | import io.swagger.annotations.Api;
7 | import io.swagger.annotations.ApiOperation;
8 | import io.swagger.annotations.ApiParam;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.web.bind.annotation.*;
11 |
12 | import cn.poile.blog.controller.BaseController;
13 |
14 | import javax.validation.constraints.NotBlank;
15 | import javax.validation.constraints.NotNull;
16 |
17 | /**
18 | *
19 | * 文章回复表 前端控制器
20 | *
21 | *
22 | * @author yaohw
23 | * @since 2019-12-03
24 | */
25 | @RestController
26 | @RequestMapping("/article/reply")
27 | @Api(tags = "文章评论回复服务",value = "/article/reply")
28 | public class ArticleReplyController extends BaseController {
29 |
30 | @Autowired
31 | private IArticleReplyService articleReplyService;
32 |
33 | @PostMapping("/add")
34 | @ApiOperation(value = "新增文章评论回复",notes = "需要accessToken")
35 | public ApiResponse add(@ApiParam(value = "文章id") @NotNull(message = "文章id不能为空") @RequestParam(value = "articleId") Integer articleId,
36 | @ApiParam(value = "评论id") @NotNull(message = "评论id不能为空") @RequestParam(value = "commentId") Integer commentId,
37 | @ApiParam(value = "被回复者id") @NotNull(message = "被回复者id不能为空") @RequestParam(value = "toUserId") Integer toUserId,
38 | @ApiParam(value = "回复内容") @NotBlank(message = "回复内容不能为空") @RequestParam(value = "content") String content) {
39 | articleReplyService.add(articleId, commentId, toUserId, content);
40 | articleReplyService.asyncSendMail(articleId,toUserId,content);
41 | return createResponse();
42 | }
43 |
44 | @DeleteMapping("/delete")
45 | @ApiOperation(value = "删除回复",notes = "逻辑删除,需要accessToken,管理员或回复者可删除")
46 | public ApiResponse delete(@ApiParam(value = "回复id") @NotNull(message = "回复id不能为空") @RequestParam(value = "replyId") Integer replyId) {
47 | articleReplyService.delete(replyId);
48 | return createResponse();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/ArticleTagController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 |
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import org.springframework.web.bind.annotation.RestController;
7 | import cn.poile.blog.controller.BaseController;
8 |
9 | /**
10 | *
11 | * 文章-标签 关联表 前端控制器
12 | *
13 | *
14 | * @author yaohw
15 | * @since 2019-11-15
16 | */
17 | @RestController
18 | @RequestMapping("/articleTag")
19 | public class ArticleTagController extends BaseController {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/BaseController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 | import cn.poile.blog.common.constant.ErrorEnum;
4 | import cn.poile.blog.common.response.ApiResponse;
5 | import org.springframework.validation.annotation.Validated;
6 |
7 | /**
8 | * @author: yaohw
9 | * @create: 2019-10-23 12:36
10 | **/
11 | @Validated
12 | public class BaseController {
13 |
14 | private ApiResponse init() {
15 | return new ApiResponse<>();
16 | }
17 |
18 | protected ApiResponse createResponse() {
19 | ApiResponse response = init();
20 | response.setCode(ErrorEnum.SUCCESS.getErrorCode());
21 | response.setMessage(ErrorEnum.SUCCESS.getErrorMsg());
22 | return response;
23 | }
24 |
25 | protected ApiResponse createResponse(T body) {
26 | ApiResponse response = createResponse();
27 | response.setData(body);
28 | return response;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/CategoryController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 |
4 | import cn.poile.blog.common.response.ApiResponse;
5 | import cn.poile.blog.controller.model.dto.CategoryNodeDTO;
6 | import cn.poile.blog.controller.model.request.AddCategoryRequest;
7 | import cn.poile.blog.entity.Category;
8 | import cn.poile.blog.service.ICategoryService;
9 | import com.baomidou.mybatisplus.core.metadata.IPage;
10 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
11 | import io.swagger.annotations.Api;
12 | import io.swagger.annotations.ApiOperation;
13 | import io.swagger.annotations.ApiParam;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.security.access.prepost.PreAuthorize;
16 | import org.springframework.validation.annotation.Validated;
17 | import org.springframework.web.bind.annotation.*;
18 |
19 | import java.util.List;
20 |
21 | /**
22 | *
23 | * 目录分类表 前端控制器
24 | *
25 | *
26 | * @author yaohw
27 | * @since 2019-11-14
28 | */
29 | @RestController
30 | @RequestMapping("/category")
31 | @Api(tags = "分类服务",value = "/category")
32 | public class CategoryController extends BaseController {
33 |
34 | @Autowired
35 | private ICategoryService categoryService;
36 |
37 |
38 | @PostMapping("/add")
39 | @PreAuthorize("hasAuthority('admin')")
40 | @ApiOperation(value = "新增分类",notes = "需要accessToken,需要管理员权限")
41 | public ApiResponse add(@Validated @RequestBody AddCategoryRequest request) {
42 | categoryService.add(request);
43 | return createResponse();
44 | }
45 |
46 |
47 | @GetMapping("/tree")
48 | @ApiOperation(value = "获取分类树",notes = "数据结构为树型结构,需要accessToken,需要管理员权限")
49 | public ApiResponse> tree() {
50 | return createResponse(categoryService.getCategoryNodeTree());
51 | }
52 |
53 | @GetMapping("/list")
54 | @ApiOperation(value = "获取分类列表",notes = "不分上下级,返回所有分类(已删除除外)")
55 | public ApiResponse> list() {
56 | return createResponse(categoryService.list());
57 | }
58 |
59 | @GetMapping("/page")
60 | @ApiOperation(value = "分页获取分类",notes = "需要accessToken,需要管理员权限")
61 | public ApiResponse> page( @ApiParam("页码") @RequestParam(value = "current", required = false, defaultValue = "1") long current,
62 | @ApiParam("每页数量") @RequestParam(value = "size", required = false, defaultValue = "5") long size) {
63 | Page page = new Page<>(current, size);
64 | return createResponse(categoryService.page(page));
65 | }
66 |
67 |
68 | @PostMapping("/update")
69 | @PreAuthorize("hasAuthority('admin')")
70 | @ApiOperation(value = "修改分类名",notes = "需要accessToken,需要管理员权限")
71 | public ApiResponse update(@ApiParam("分类id") @RequestParam("id") int id,
72 | @ApiParam("标签名") @RequestParam(value = "name") String name) {
73 | categoryService.updateCategoryById(id,name);
74 | return createResponse();
75 | }
76 |
77 |
78 | @DeleteMapping("/delete/{id}")
79 | @PreAuthorize("hasAuthority('admin')")
80 | @ApiOperation(value = "删除分类",notes = "需要accessToken,逻辑删除,需要管理员权限,若存在子类,则不允许删除")
81 | public ApiResponse delete(@ApiParam("分类id") @PathVariable("id") int id) {
82 | categoryService.delete(id);
83 | return createResponse();
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/ClientController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 |
4 | import cn.poile.blog.common.constant.ErrorEnum;
5 | import cn.poile.blog.common.exception.ApiException;
6 | import cn.poile.blog.common.response.ApiResponse;
7 | import cn.poile.blog.entity.Client;
8 | import cn.poile.blog.service.IClientService;
9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
10 | import com.baomidou.mybatisplus.core.metadata.IPage;
11 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
12 | import io.swagger.annotations.Api;
13 | import io.swagger.annotations.ApiOperation;
14 | import io.swagger.annotations.ApiParam;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.security.access.prepost.PreAuthorize;
17 | import org.springframework.validation.annotation.Validated;
18 | import org.springframework.web.bind.annotation.*;
19 |
20 | /**
21 | *
22 | * 客户端表 前端控制器
23 | *
24 | *
25 | * @author yaohw
26 | * @since 2019-12-06
27 | */
28 | @RestController
29 | @RequestMapping("/client")
30 | @Api(tags = "客户端服务",value = "/client")
31 | public class ClientController extends BaseController {
32 |
33 | @Autowired
34 | private IClientService clientService;
35 |
36 | @GetMapping("/page")
37 | @PreAuthorize("hasAuthority('admin')")
38 | @ApiOperation(value = "分页获取客户端列表",notes = "需要accessToken,需要管理员权限")
39 | public ApiResponse> page(@ApiParam("页码") @RequestParam(value = "current", required = false, defaultValue = "1") long current,
40 | @ApiParam("每页数量") @RequestParam(value = "size", required = false, defaultValue = "5") long size) {
41 | return createResponse(clientService.page(new Page<>(current,size)));
42 | }
43 |
44 | @DeleteMapping("/delete/{id}")
45 | @ApiOperation(value = "删除客户端",notes = "需要accessToken,需要管理员权限")
46 | public ApiResponse delete(@ApiParam("id") @PathVariable(value = "id") int id) {
47 | clientService.removeById(id);
48 | clientService.clearCache();
49 | return createResponse();
50 | }
51 |
52 | @PostMapping("/save")
53 | @ApiOperation(value = "新增或更新客户端,id为null时新增",notes = "需要accessToken,需要管理员权限")
54 | public ApiResponse save(@Validated @RequestBody Client client) {
55 | validateExist(client);
56 | clientService.saveOrUpdate(client);
57 | clientService.clearCache();
58 | return createResponse();
59 | }
60 |
61 | /**
62 | * 校验是否已存在
63 | * @param client
64 | */
65 | private void validateExist(Client client) {
66 | if (client.getId() == null) {
67 | QueryWrapper queryWrapper = new QueryWrapper<>();
68 | queryWrapper.lambda().eq(Client::getClientId,client.getClientId());
69 | int count = clientService.count(queryWrapper);
70 | if (count != 0) {
71 | throw new ApiException(ErrorEnum.INVALID_REQUEST.getErrorCode(),"客户端已存在");
72 | }
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/FileController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 | import cn.poile.blog.common.oss.PageStorageObject;
4 | import cn.poile.blog.common.oss.Storage;
5 | import cn.poile.blog.common.response.ApiResponse;
6 | import io.swagger.annotations.Api;
7 | import io.swagger.annotations.ApiOperation;
8 | import io.swagger.annotations.ApiParam;
9 | import lombok.extern.log4j.Log4j2;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.security.access.prepost.PreAuthorize;
12 | import org.springframework.web.bind.annotation.*;
13 | import org.springframework.web.multipart.MultipartFile;
14 |
15 | import javax.validation.constraints.NotNull;
16 | import java.io.IOException;
17 |
18 | /**
19 | * @author: yaohw
20 | * @create: 2019-10-31 14:13
21 | **/
22 | @RestController
23 | @RequestMapping("/file")
24 | @Log4j2
25 | @Api(tags = "文件存储服务",value = "file")
26 | public class FileController extends BaseController {
27 |
28 | @Autowired
29 | private Storage storage;
30 |
31 | @PostMapping("/upload")
32 | @PreAuthorize("hasAuthority('admin')")
33 | @ApiOperation(value = "上传文件",notes = "需要accessToken,需要管理员权限")
34 | public ApiResponse upload(@NotNull @RequestParam("file") MultipartFile file) throws IOException {
35 | String filename = file.getOriginalFilename();
36 | String contentType = file.getContentType();
37 | String extension = filename.substring(filename.lastIndexOf(".") + 1);
38 | String name = System.currentTimeMillis() + "." +extension;
39 | String fullPath = storage.upload(file.getInputStream(),name,contentType);
40 | return createResponse(fullPath);
41 | }
42 |
43 | @DeleteMapping("/delete")
44 | @PreAuthorize("hasAuthority('admin')")
45 | @ApiOperation(value = "删除文件",notes = "需要accessToken,需要管理员权限")
46 | public ApiResponse delete(@ApiParam("文件全路径") @NotNull @RequestParam("fullPath")String fullPath){
47 | storage.delete(fullPath);
48 | return createResponse();
49 | }
50 |
51 | @GetMapping("/page")
52 | @PreAuthorize("hasAuthority('admin')")
53 | @ApiOperation(value = "分页分类列表", notes = "需要accessToken,需要管理员权限")
54 | public ApiResponse page(@ApiParam("marker标记") @RequestParam(value = "marker", required = false) String marker,
55 | @ApiParam("每页数量") @RequestParam(value = "size", required = false, defaultValue = "5") int size) {
56 | return createResponse(storage.page(marker,size));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/FriendLinkController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 |
4 | import cn.poile.blog.common.oss.Storage;
5 | import cn.poile.blog.common.response.ApiResponse;
6 | import cn.poile.blog.entity.FriendLink;
7 | import cn.poile.blog.service.IFriendLinkService;
8 | import com.baomidou.mybatisplus.core.metadata.IPage;
9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
10 | import io.swagger.annotations.Api;
11 | import io.swagger.annotations.ApiOperation;
12 | import io.swagger.annotations.ApiParam;
13 | import org.apache.commons.lang3.StringUtils;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.web.bind.annotation.*;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | *
21 | * 友链表 前端控制器
22 | *
23 | *
24 | * @author yaohw
25 | * @since 2019-12-02
26 | */
27 | @RestController
28 | @RequestMapping("/friend/link")
29 | @Api(tags = "友链服务", value = "/friend/link")
30 | public class FriendLinkController extends BaseController {
31 |
32 | @Autowired
33 | private IFriendLinkService friendLinkService;
34 |
35 | @Autowired
36 | private Storage storage;
37 |
38 | @PostMapping("/save")
39 | @ApiOperation(value = "新增或更新友链", notes = "id不为空时更新,需要accessToken,需要管理员权限")
40 | public ApiResponse add(@RequestBody FriendLink friendLink) {
41 | friendLinkService.saveOrUpdate(friendLink);
42 | return createResponse();
43 | }
44 |
45 | @GetMapping("/list")
46 | @ApiOperation(value = "获取友链列表")
47 | public ApiResponse> list() {
48 | return createResponse(friendLinkService.list());
49 | }
50 |
51 | @GetMapping("/page")
52 | @ApiOperation(value = "分页获取友链列表")
53 | public ApiResponse> page(
54 | @ApiParam("页码") @RequestParam(value = "current", required = false, defaultValue = "1") long current,
55 | @ApiParam("每页数量") @RequestParam(value = "size", required = false, defaultValue = "5") long size) {
56 | Page page = new Page<>(current, size);
57 | return createResponse(friendLinkService.page(page));
58 | }
59 |
60 | @DeleteMapping("/delete/{id}")
61 | @ApiOperation(value = "删除友链")
62 | public ApiResponse delete(@ApiParam("友链id") @PathVariable(value = "id") int id) {
63 | FriendLink friendLink = friendLinkService.getById(id);
64 | if (friendLink != null && StringUtils.isNotBlank(friendLink.getIcon())) {
65 | deleteIcon(friendLink.getIcon());
66 | }
67 | friendLinkService.removeById(id);
68 | return createResponse();
69 | }
70 |
71 | /**
72 | * 删除icon
73 | * @param path
74 | */
75 | private void deleteIcon(String path) {
76 | storage.delete(path);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/LeaveMessageController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 | import cn.poile.blog.common.response.ApiResponse;
4 | import cn.poile.blog.entity.LeaveMessage;
5 | import cn.poile.blog.service.ILeaveMessageService;
6 | import cn.poile.blog.vo.ArticleCommentVo;
7 | import cn.poile.blog.vo.LeaveMessageVo;
8 | import com.baomidou.mybatisplus.core.metadata.IPage;
9 | import io.swagger.annotations.Api;
10 | import io.swagger.annotations.ApiOperation;
11 | import io.swagger.annotations.ApiParam;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.web.bind.annotation.*;
14 |
15 | import javax.validation.constraints.NotBlank;
16 | import javax.validation.constraints.NotNull;
17 | import java.util.List;
18 |
19 | /**
20 | *
21 | * 留言表 前端控制器
22 | *
23 | *
24 | * @author yaohw
25 | * @since 2019-12-05
26 | */
27 | @RestController
28 | @RequestMapping("/leave/message")
29 | @Api(tags = "留言服务",value = "/leave/message")
30 | public class LeaveMessageController extends BaseController {
31 |
32 |
33 | @Autowired
34 | private ILeaveMessageService messageService;
35 |
36 | @PostMapping("/add")
37 | @ApiOperation(value = "新增留言",notes = "需要accessToken")
38 | public ApiResponse add(@ApiParam("留言内容") @NotBlank(message = "内容不能为空") @RequestParam("content") String content) {
39 | messageService.add(content);
40 | return createResponse();
41 | }
42 |
43 | @PostMapping("/reply")
44 | @ApiOperation(value = "留言回复",notes = "需要accessToken")
45 | public ApiResponse reply(
46 | @ApiParam("父id") @NotNull(message = "pid不能为空") @RequestParam(value = "pid") Integer pid,
47 | @ApiParam("被回复者id") @NotNull(message = "被回复者id不能为空") @RequestParam(value = "toUserId") Integer toUserId,
48 | @ApiParam("回复内容") @NotBlank(message = "内容不能为空") @RequestParam("content") String content) {
49 | messageService.reply(pid,toUserId,content);
50 | return createResponse();
51 | }
52 |
53 | @GetMapping("/page")
54 | @ApiOperation(value = "分页获取留言及回复列表",notes = "包括留言者和回复者信息")
55 | public ApiResponse> page(
56 | @ApiParam("页码") @RequestParam(value = "current", required = false, defaultValue = "1") long current,
57 | @ApiParam("每页数量") @RequestParam(value = "size", required = false, defaultValue = "5") long size) {
58 | return createResponse(messageService.page(current,size));
59 | }
60 |
61 | @DeleteMapping("/delete/{id}")
62 | @ApiOperation(value = "删除留言或留言回复",notes = "需要accessToken,本人和管理员可删除")
63 | public ApiResponse delete(@ApiParam("id") @PathVariable("id") Integer id) {
64 | messageService.delete(id);
65 | return createResponse();
66 | }
67 |
68 | @GetMapping("/latest")
69 | @ApiOperation(value = "最新留言列表",notes = "包括留言者")
70 | public ApiResponse> latest(
71 | @ApiParam("数量限制,默认值:5") @RequestParam(value = "limit", required = false, defaultValue = "5") long limit) {
72 | return createResponse(messageService.selectLatest(limit));
73 | }
74 |
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/SmsController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 | import cn.poile.blog.biz.EmailService;
4 | import cn.poile.blog.common.constant.RedisConstant;
5 | import cn.poile.blog.common.limiter.annotation.RateLimiter;
6 | import cn.poile.blog.common.response.ApiResponse;
7 | import cn.poile.blog.common.sms.SmsCodeService;
8 | import cn.poile.blog.common.validator.annotation.IsPhone;
9 | import io.swagger.annotations.Api;
10 | import io.swagger.annotations.ApiOperation;
11 | import io.swagger.annotations.ApiParam;
12 | import lombok.extern.log4j.Log4j2;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.web.bind.annotation.PostMapping;
15 | import org.springframework.web.bind.annotation.RequestMapping;
16 | import org.springframework.web.bind.annotation.RequestParam;
17 | import org.springframework.web.bind.annotation.RestController;
18 |
19 | import javax.validation.constraints.NotNull;
20 |
21 | /**
22 | * @author: yaohw
23 | * @create: 2019-11-05 09:34
24 | **/
25 | @Log4j2
26 | @RestController
27 | @RequestMapping("/sms")
28 | @Api(tags = "短信验证码服务",value = "/sms")
29 | public class SmsController extends BaseController{
30 |
31 | @Autowired
32 | private SmsCodeService smsCodeService;
33 |
34 | @Autowired
35 | private EmailService emailService;
36 |
37 | @PostMapping("/send")
38 | @RateLimiter(name = RedisConstant.SMS_LIMIT_NAME,max = 1,key = "#mobile", timeout = 120L, extra = "smsLimiter")
39 | @ApiOperation(value = "发送短信验证码",notes = "验证码有效时5分钟;同一手机号每天只能发10次;同一ip每天只能发10次;同一手机号限流120s一次")
40 | public ApiResponse sendSmsCode(@ApiParam("手机号") @NotNull @IsPhone @RequestParam long mobile) {
41 | smsCodeService.sendSmsCode(mobile);
42 | return createResponse();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/TagController.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller;
2 |
3 |
4 | import cn.poile.blog.common.response.ApiResponse;
5 | import cn.poile.blog.entity.Tag;
6 | import cn.poile.blog.service.ITagService;
7 | import com.baomidou.mybatisplus.core.metadata.IPage;
8 | import io.swagger.annotations.Api;
9 | import io.swagger.annotations.ApiOperation;
10 | import io.swagger.annotations.ApiParam;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.security.access.prepost.PreAuthorize;
13 | import org.springframework.validation.annotation.Validated;
14 | import org.springframework.web.bind.annotation.*;
15 |
16 | import javax.validation.constraints.NotBlank;
17 | import java.util.List;
18 |
19 | /**
20 | *
21 | * 标签表 前端控制器
22 | *
23 | *
24 | * @author yaohw
25 | * @since 2019-11-14
26 | */
27 | @RestController
28 | @RequestMapping("/tag")
29 | @Api(tags = "标签服务", value = "/tag")
30 | public class TagController extends BaseController {
31 |
32 | @Autowired
33 | private ITagService tagService;
34 |
35 | @PostMapping("/add")
36 | @PreAuthorize("hasAuthority('admin')")
37 | @ApiOperation(value = "添加标签", notes = "需要accessToken,需要管理员权限")
38 | public ApiResponse addTag(@NotBlank(message = "标签名不能为空") @RequestParam("tagName") String tagName) {
39 | tagService.addTag(tagName);
40 | return createResponse();
41 | }
42 |
43 |
44 | @GetMapping("/page")
45 | @PreAuthorize("hasAuthority('admin')")
46 | @ApiOperation(value = "分页查询标签", notes = "需要accessToken,需要管理员权限")
47 | public ApiResponse> page(@ApiParam("当前页") @RequestParam(value = "current", required = false, defaultValue = "1") long current,
48 | @ApiParam("每页数量") @RequestParam(value = "size", required = false, defaultValue = "5") long size,
49 | @ApiParam("标签名关键字,可空") @RequestParam(value = "tagName", required = false) String tagName) {
50 | return createResponse(tagService.selectTagPage(current, size, tagName));
51 | }
52 |
53 |
54 | @GetMapping("/list")
55 | @ApiOperation(value = "获取标签列表", notes = "不需要accessToken")
56 | public ApiResponse> list(@ApiParam("标签名关键字,可空") @RequestParam(value = "tagName", required = false) String tagName) {
57 | return createResponse(tagService.selectTagList(tagName));
58 | }
59 |
60 |
61 | @PostMapping("/update")
62 | @PreAuthorize("hasAuthority('admin')")
63 | @ApiOperation(value = "修改标签名",notes = "需要accessToken,需要管理员权限")
64 | public ApiResponse update(@ApiParam("标签id") @RequestParam("id") int id,
65 | @ApiParam("标签名") @RequestParam(value = "name") String name) {
66 | tagService.update(id,name);
67 | return createResponse();
68 | }
69 |
70 |
71 | @DeleteMapping("/delete/{id}")
72 | @PreAuthorize("hasAuthority('admin')")
73 | @ApiOperation(value = "删除标签",notes = "需要accessToken,需要管理员权限,逻辑删除")
74 | public ApiResponse delete(@ApiParam("标签id") @PathVariable("id") int id) {
75 | tagService.delete(id);
76 | return createResponse();
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/dto/AccessTokenDTO.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 | import lombok.experimental.Accessors;
9 |
10 | /**
11 | * @author: yaohw
12 | * @create: 2019-11-04 17:03
13 | **/
14 | @Data
15 | @Accessors(chain = true)
16 | @JsonInclude(JsonInclude.Include.NON_NULL)
17 | @ApiModel(value="AccessTokenDTO", description="AccessTokenDTO")
18 | public class AccessTokenDTO {
19 |
20 | @JsonProperty("access_token")
21 | @ApiModelProperty("access_token")
22 | private String accessToken;
23 |
24 | @JsonProperty("token_type")
25 | @ApiModelProperty("token类型:Bearer")
26 | private String tokenType;
27 |
28 | @JsonProperty("refresh_token")
29 | @ApiModelProperty("refresh_token")
30 | private String refreshToken;
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/dto/ArticlePageQueryDTO.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.dto;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | /**
8 | * @author: yaohw
9 | * @create: 2019-11-28 19:17
10 | **/
11 | @Data
12 | @NoArgsConstructor
13 | @AllArgsConstructor
14 | public class ArticlePageQueryDTO {
15 |
16 | private Long current;
17 |
18 | private Long size;
19 |
20 | private Integer categoryId;
21 |
22 | private Integer tagId;
23 |
24 | private String yearMonth;
25 |
26 | private String title;
27 |
28 | private String sort;
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/dto/CategoryNodeDTO.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import io.swagger.annotations.ApiModelProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * 分类节点
13 | * @author: yaohw
14 | * @create: 2019-11-14 17:38
15 | **/
16 | @Data
17 | @NoArgsConstructor
18 | @AllArgsConstructor
19 | @JsonInclude(JsonInclude.Include.NON_NULL)
20 | public class CategoryNodeDTO {
21 |
22 | @ApiModelProperty(value = "id")
23 | private Integer id;
24 |
25 | @ApiModelProperty(value = "名称")
26 | private String name;
27 |
28 | @ApiModelProperty(value = "父类id")
29 | private Integer parentId;
30 |
31 | @ApiModelProperty(value = "子目录")
32 | private List children;
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/dto/PreArtAndNextArtDTO.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.dto;
2 |
3 | import cn.poile.blog.entity.Article;
4 | import lombok.Data;
5 |
6 | /**
7 | * 上一篇和下一篇文章DTO
8 | * @author: yaohw
9 | * @create: 2019-11-26 19:21
10 | **/
11 | @Data
12 | public class PreArtAndNextArtDTO {
13 |
14 | /**
15 | * 上一篇
16 | */
17 | private Article pre;
18 |
19 | /**
20 | * 下一篇
21 | */
22 | private Article next;
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/request/AddCategoryRequest.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.request;
2 |
3 | import io.swagger.annotations.ApiModel;
4 | import io.swagger.annotations.ApiModelProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 | import javax.validation.constraints.NotBlank;
10 | import javax.validation.constraints.NotNull;
11 |
12 | /**
13 | * @author: yaohw
14 | * @create: 2019-11-14 17:15
15 | **/
16 |
17 | @Data
18 | @NoArgsConstructor
19 | @AllArgsConstructor
20 | @ApiModel(value = "添加分类json",description = "添加分类")
21 | public class AddCategoryRequest {
22 |
23 | @NotBlank(message = "分类名称不能为空")
24 | @ApiModelProperty(value = "名称")
25 | private String name;
26 |
27 | @NotNull(message = "parentId不能为空")
28 | @ApiModelProperty(value = "父类id,添加根目录分类时值为0")
29 | private Integer parentId;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/request/ArticleRequest.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.request;
2 |
3 | import cn.poile.blog.common.validator.annotation.ListSize;
4 | import com.baomidou.mybatisplus.annotation.IdType;
5 | import com.baomidou.mybatisplus.annotation.TableId;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | import javax.validation.constraints.NotBlank;
13 | import javax.validation.constraints.NotNull;
14 | import java.util.List;
15 |
16 | /**
17 | * @author: yaohw
18 | * @create: 2019-11-15 15:08
19 | **/
20 | @Data
21 | @NoArgsConstructor
22 | @AllArgsConstructor
23 | @ApiModel(value = "文章请求json",description = "文章请求体")
24 | public class ArticleRequest {
25 |
26 | @ApiModelProperty(value = "文章id,编辑时不可空")
27 | @TableId(value = "id", type = IdType.AUTO)
28 | private Integer id;
29 |
30 | @NotNull(message = "是否原创标识不能为空")
31 | @ApiModelProperty(value = "是否原创,1:是,0:否")
32 | private Integer original;
33 |
34 | @NotNull(message = "状态不能为空")
35 | @ApiModelProperty(value = "状态,0:发布,1:保存")
36 | private Integer status;
37 |
38 | @NotNull(message = "文章分类id不能为空")
39 | @ApiModelProperty(value = "文章分类id")
40 | private Integer categoryId;
41 |
42 | @NotBlank(message = "文章标题不能为空")
43 | @ApiModelProperty(value = "文章标题")
44 | private String title;
45 |
46 | @NotBlank(message = "文章摘要不能为空")
47 | @ApiModelProperty(value = "文章摘要")
48 | private String summary;
49 |
50 | @NotBlank(message = "文章内容不能为空")
51 | @ApiModelProperty(value = "文章内容")
52 | private String content;
53 |
54 | @ApiModelProperty(value = "文章内容")
55 | private String htmlContent;
56 |
57 | @NotBlank(message = "文章封面不能为空")
58 | @ApiModelProperty(value = "文章封面")
59 | private String cover;
60 |
61 | @ListSize(max = 4,message = "一篇文章最多只允许添加4个标签")
62 | @ApiModelProperty(value = "文章标签id列表")
63 | private List tagIds;
64 |
65 | @ApiModelProperty(value = "转载地址,转载非空")
66 | private String reproduce;
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/request/UpdateUserRequest.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.request;
2 |
3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
6 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
7 | import io.swagger.annotations.ApiModel;
8 | import io.swagger.annotations.ApiModelProperty;
9 | import lombok.AllArgsConstructor;
10 | import lombok.Data;
11 | import lombok.NoArgsConstructor;
12 |
13 | import javax.validation.constraints.NotNull;
14 | import java.time.LocalDate;
15 |
16 | /**
17 | * @author: yaohw
18 | * @create: 2019-11-08 16:04
19 | **/
20 | @Data
21 | @NoArgsConstructor
22 | @AllArgsConstructor
23 | @ApiModel(value = "用户更新json",description = "用户更新")
24 | public class UpdateUserRequest {
25 |
26 | @ApiModelProperty(value = "用户id")
27 | @NotNull(message = "用户id不能为空")
28 | private Integer userId;
29 |
30 | @ApiModelProperty(value = "昵称")
31 | private String nickname;
32 |
33 | @ApiModelProperty(value = "性别,1:男,0:女,默认为1")
34 | private Integer gender;
35 |
36 | @JsonDeserialize(using = LocalDateDeserializer.class)
37 | @JsonSerialize(using = LocalDateSerializer.class)
38 | @ApiModelProperty(value = "生日")
39 | private LocalDate birthday;
40 |
41 | @ApiModelProperty(value = "简介|个性签名")
42 | private String brief;
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/controller/model/request/UserRegisterRequest.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.controller.model.request;
2 |
3 | import cn.poile.blog.common.validator.annotation.IsPhone;
4 | import io.swagger.annotations.ApiModel;
5 | import io.swagger.annotations.ApiModelProperty;
6 | import lombok.AllArgsConstructor;
7 | import lombok.Data;
8 | import lombok.NoArgsConstructor;
9 | import org.hibernate.validator.constraints.Length;
10 |
11 | import javax.validation.constraints.NotBlank;
12 | import javax.validation.constraints.NotNull;
13 | import javax.validation.constraints.Pattern;
14 | /**
15 | * @author: yaohw
16 | * @create: 2019-10-04 22:13
17 | */
18 | @Data
19 | @NoArgsConstructor
20 | @AllArgsConstructor
21 | @ApiModel(value = "用户注册请json",description = "用户注册")
22 | public class UserRegisterRequest {
23 |
24 | @NotBlank(message = "用户名不能为空")
25 | @ApiModelProperty("用户名只能字母开头,允许2-16字节,允许字母数字下划线")
26 | @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{1,15}$", message = "用户名只能字母开头,允许2-16字节,允许字母数字下划线")
27 | private String username;
28 |
29 | @NotBlank(message = "密码不能为空")
30 | @Length(min = 6,message = "密码至少6位数")
31 | @ApiModelProperty("密码")
32 | private String password;
33 |
34 | @NotNull(message = "手机号不能为空")
35 | @IsPhone
36 | @ApiModelProperty("手机号")
37 | private long mobile;
38 |
39 | @NotBlank(message = "验证码不能为空")
40 | @ApiModelProperty("验证码")
41 | private String code;
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/Article.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableLogic;
6 | import com.fasterxml.jackson.annotation.JsonFormat;
7 | import com.fasterxml.jackson.annotation.JsonIgnore;
8 | import com.fasterxml.jackson.annotation.JsonInclude;
9 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
10 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
11 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
12 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
13 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
14 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
15 | import io.swagger.annotations.ApiModel;
16 | import io.swagger.annotations.ApiModelProperty;
17 | import lombok.Data;
18 | import lombok.EqualsAndHashCode;
19 | import lombok.experimental.Accessors;
20 |
21 | import java.io.Serializable;
22 | import java.time.LocalDateTime;
23 |
24 | /**
25 | *
26 | * 文章表
27 | *
28 | *
29 | * @author yaohw
30 | * @since 2019-11-15
31 | */
32 | @Data
33 | @Accessors(chain = true)
34 | @EqualsAndHashCode(of = "id")
35 | @JsonInclude(JsonInclude.Include.NON_NULL)
36 | @ApiModel(value="Article对象", description="文章表")
37 | public class Article implements Serializable {
38 |
39 | private static final long serialVersionUID = 1L;
40 |
41 | @ApiModelProperty(value = "文章id")
42 | @TableId(value = "id", type = IdType.AUTO)
43 | private Integer id;
44 |
45 | @ApiModelProperty(value = "是否原创,1:是,0:否")
46 | private Integer original;
47 |
48 | @JsonIgnore
49 | @ApiModelProperty(value = "用户id")
50 | private Integer userId;
51 |
52 | @ApiModelProperty(value = "分类名称-冗余字段")
53 | private String categoryName;
54 |
55 | @ApiModelProperty(value = "文章分类id")
56 | private Integer categoryId;
57 |
58 | @ApiModelProperty(value = "文章标题")
59 | private String title;
60 |
61 | @ApiModelProperty(value = "文章摘要")
62 | private String summary;
63 |
64 | @ApiModelProperty(value = "文章内容")
65 | private String content;
66 |
67 | @ApiModelProperty(value = "文章富文本内容")
68 | private String htmlContent;
69 |
70 | @ApiModelProperty(value = "文章封面")
71 | private String cover;
72 |
73 | @ApiModelProperty(value = "文章状态:0为正常,1为待发布,2为回收站")
74 | private Integer status;
75 |
76 | @ApiModelProperty(value = "文章浏览次数")
77 | private Integer viewCount;
78 |
79 | @ApiModelProperty(value = "评论数-冗余字段")
80 | private Integer commentCount;
81 |
82 | @ApiModelProperty(value = "点赞数-冗余字段")
83 | private Integer likeCount;
84 |
85 | @ApiModelProperty(value = "收藏数-冗余字段")
86 | private Integer collectCount;
87 |
88 | @ApiModelProperty(value = "发布时间")
89 | @JsonSerialize(using = LocalDateTimeSerializer.class)
90 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
91 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
92 | private LocalDateTime publishTime;
93 |
94 | @ApiModelProperty(value = "更新时间")
95 | @JsonSerialize(using = LocalDateTimeSerializer.class)
96 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
97 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
98 | private LocalDateTime updateTime;
99 |
100 | @TableLogic
101 | @JsonIgnore
102 | @ApiModelProperty(value = "是否已删除,1:是,0:否")
103 | private Integer deleted;
104 |
105 | @ApiModelProperty(value = "转载地址")
106 | private String reproduce;
107 |
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/ArticleCollect.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 | import lombok.Data;
9 | import lombok.EqualsAndHashCode;
10 | import lombok.experimental.Accessors;
11 |
12 | /**
13 | *
14 | * 文章收藏表
15 | *
16 | *
17 | * @author yaohw
18 | * @since 2019-12-04
19 | */
20 | @Data
21 | @EqualsAndHashCode(callSuper = false)
22 | @Accessors(chain = true)
23 | @ApiModel(value="ArticleCollect对象", description="文章收藏表")
24 | public class ArticleCollect implements Serializable {
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | @ApiModelProperty(value = "id")
29 | @TableId(value = "id", type = IdType.AUTO)
30 | private Integer id;
31 |
32 | @ApiModelProperty(value = "用户id")
33 | private Integer userId;
34 |
35 | @ApiModelProperty(value = "文章id")
36 | private Integer articleId;
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/ArticleComment.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.time.LocalDateTime;
6 | import java.io.Serializable;
7 |
8 | import com.baomidou.mybatisplus.annotation.TableLogic;
9 | import com.fasterxml.jackson.annotation.JsonFormat;
10 | import com.fasterxml.jackson.annotation.JsonIgnore;
11 | import com.fasterxml.jackson.annotation.JsonInclude;
12 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
13 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
14 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
15 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
16 | import io.swagger.annotations.ApiModel;
17 | import io.swagger.annotations.ApiModelProperty;
18 | import lombok.Data;
19 | import lombok.EqualsAndHashCode;
20 | import lombok.experimental.Accessors;
21 |
22 | /**
23 | *
24 | * 文章评论表
25 | *
26 | *
27 | * @author yaohw
28 | * @since 2019-12-03
29 | */
30 | @Data
31 | @Accessors(chain = true)
32 | @EqualsAndHashCode(callSuper = false)
33 | @JsonInclude(JsonInclude.Include.NON_NULL)
34 | @ApiModel(value="ArticleComment对象", description="文章评论表")
35 | public class ArticleComment implements Serializable {
36 |
37 | private static final long serialVersionUID = 1L;
38 |
39 | @ApiModelProperty(value = "id")
40 | @TableId(value = "id", type = IdType.AUTO)
41 | private Integer id;
42 |
43 | @ApiModelProperty(value = "文章id")
44 | private Integer articleId;
45 |
46 | @ApiModelProperty(value = "评论者id")
47 | private Integer fromUserId;
48 |
49 | @ApiModelProperty(value = "评论内容")
50 | private String content;
51 |
52 | @ApiModelProperty(value = "评论时间")
53 | @JsonSerialize(using = LocalDateTimeSerializer.class)
54 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
55 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
56 | private LocalDateTime commentTime;
57 |
58 | @TableLogic
59 | @JsonIgnore
60 | @ApiModelProperty(value = "是否已删除,1:是,0:否")
61 | private Integer deleted;
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/ArticleLike.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 |
7 | import com.fasterxml.jackson.annotation.JsonIgnore;
8 | import io.swagger.annotations.ApiModel;
9 | import io.swagger.annotations.ApiModelProperty;
10 | import lombok.Data;
11 | import lombok.EqualsAndHashCode;
12 | import lombok.experimental.Accessors;
13 |
14 | /**
15 | *
16 | * 文章点赞表
17 | *
18 | *
19 | * @author yaohw
20 | * @since 2019-12-02
21 | */
22 | @Data
23 | @EqualsAndHashCode(callSuper = false)
24 | @Accessors(chain = true)
25 | @ApiModel(value="ArticleLike对象", description="文章点赞表")
26 | public class ArticleLike implements Serializable {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 |
31 | @JsonIgnore
32 | @ApiModelProperty(value = "id")
33 | @TableId(value = "id", type = IdType.AUTO)
34 | private Integer id;
35 |
36 | @JsonIgnore
37 | @ApiModelProperty(value = "文章id")
38 | private Integer articleId;
39 |
40 | @ApiModelProperty(value = "用户id")
41 | private Integer userId;
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/ArticleReply.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.time.LocalDateTime;
6 | import java.io.Serializable;
7 |
8 | import com.baomidou.mybatisplus.annotation.TableLogic;
9 | import com.fasterxml.jackson.annotation.JsonFormat;
10 | import com.fasterxml.jackson.annotation.JsonIgnore;
11 | import com.fasterxml.jackson.annotation.JsonInclude;
12 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
13 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
14 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
15 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
16 | import io.swagger.annotations.ApiModel;
17 | import io.swagger.annotations.ApiModelProperty;
18 | import lombok.Data;
19 | import lombok.EqualsAndHashCode;
20 | import lombok.experimental.Accessors;
21 |
22 | /**
23 | *
24 | * 文章回复表
25 | *
26 | *
27 | * @author yaohw
28 | * @since 2019-12-03
29 | */
30 | @Data
31 | @Accessors(chain = true)
32 | @EqualsAndHashCode(callSuper = false)
33 | @JsonInclude(JsonInclude.Include.NON_NULL)
34 | @ApiModel(value="ArticleReply对象", description="文章回复表")
35 | public class ArticleReply implements Serializable {
36 |
37 | private static final long serialVersionUID = 1L;
38 |
39 | @ApiModelProperty(value = "id")
40 | @TableId(value = "id", type = IdType.AUTO)
41 | private Integer id;
42 |
43 | @ApiModelProperty(value = "文章id")
44 | private Integer articleId;
45 |
46 | @ApiModelProperty(value = "评论id")
47 | private Integer commentId;
48 |
49 | @ApiModelProperty(value = "评论者id")
50 | private Integer fromUserId;
51 |
52 | @ApiModelProperty(value = "被评论者id")
53 | private Integer toUserId;
54 |
55 | @ApiModelProperty(value = "回复内容")
56 | private String content;
57 |
58 | @ApiModelProperty(value = "回复时间")
59 | @JsonSerialize(using = LocalDateTimeSerializer.class)
60 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
61 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
62 | private LocalDateTime replyTime;
63 |
64 | @TableLogic
65 | @JsonIgnore
66 | @ApiModelProperty(value = "是否已删除,1:是,0:否")
67 | private Integer deleted;
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/ArticleTag.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 |
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import io.swagger.annotations.ApiModel;
9 | import io.swagger.annotations.ApiModelProperty;
10 | import lombok.*;
11 | import lombok.experimental.Accessors;
12 |
13 | /**
14 | *
15 | * 文章-标签 关联表
16 | *
17 | *
18 | * @author yaohw
19 | * @since 2019-11-15
20 | */
21 | @Data
22 | @NoArgsConstructor
23 | @AllArgsConstructor
24 | @Accessors(chain = true)
25 | @RequiredArgsConstructor
26 | @EqualsAndHashCode
27 | @JsonInclude(JsonInclude.Include.NON_NULL)
28 | @ApiModel(value="ArticleTag对象", description="文章-标签 关联表")
29 | public class ArticleTag implements Serializable {
30 |
31 |
32 | private static final long serialVersionUID = 1L;
33 |
34 | @EqualsAndHashCode.Exclude
35 | @ApiModelProperty(value = "id")
36 | @TableId(value = "id", type = IdType.AUTO)
37 | private Integer id;
38 |
39 | @NonNull
40 | @ApiModelProperty(value = "文章id")
41 | private Integer articleId;
42 |
43 | @NonNull
44 | @ApiModelProperty(value = "标签id")
45 | private Integer tagId;
46 |
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/Category.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 |
7 | import com.baomidou.mybatisplus.annotation.TableLogic;
8 | import com.fasterxml.jackson.annotation.JsonIgnore;
9 | import com.fasterxml.jackson.annotation.JsonInclude;
10 | import io.swagger.annotations.ApiModel;
11 | import io.swagger.annotations.ApiModelProperty;
12 | import lombok.Data;
13 | import lombok.EqualsAndHashCode;
14 | import lombok.experimental.Accessors;
15 |
16 | /**
17 | *
18 | * 分类表
19 | *
20 | *
21 | * @author yaohw
22 | * @since 2019-11-14
23 | */
24 | @Data
25 | @Accessors(chain = true)
26 | @EqualsAndHashCode(callSuper = false)
27 | @JsonInclude(JsonInclude.Include.NON_NULL)
28 | @ApiModel(value="Category对象", description="分类表")
29 | public class Category implements Serializable {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | @ApiModelProperty(value = "id")
34 | @TableId(value = "id", type = IdType.AUTO)
35 | private Integer id;
36 |
37 | @ApiModelProperty(value = "名称")
38 | private String name;
39 |
40 | @ApiModelProperty(value = "父类id")
41 | private Integer parentId;
42 |
43 | @JsonIgnore
44 | @TableLogic
45 | @ApiModelProperty(value = "是否已删除,1:是,0:否")
46 | private Integer deleted;
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/Client.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 |
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import com.fasterxml.jackson.annotation.JsonProperty;
9 | import io.swagger.annotations.ApiModel;
10 | import io.swagger.annotations.ApiModelProperty;
11 | import lombok.Data;
12 | import lombok.EqualsAndHashCode;
13 | import lombok.experimental.Accessors;
14 |
15 | import javax.validation.constraints.NotBlank;
16 |
17 | /**
18 | *
19 | * 客户端表
20 | *
21 | *
22 | * @author yaohw
23 | * @since 2019-12-06
24 | */
25 | @Data
26 | @Accessors(chain = true)
27 | @EqualsAndHashCode(callSuper = false)
28 | @JsonInclude(JsonInclude.Include.NON_NULL)
29 | @ApiModel(value="Client对象", description="客户端表")
30 | public class Client implements Serializable {
31 |
32 | private static final long serialVersionUID = 1L;
33 |
34 | @ApiModelProperty(value = "id")
35 | @TableId(value = "id", type = IdType.AUTO)
36 | private Integer id;
37 |
38 | @NotBlank(message = "客户端ID不能为空")
39 | @ApiModelProperty(value = "客户端id,客户端唯一标识")
40 | private String clientId;
41 |
42 | @NotBlank(message = "客户端秘钥不能为空")
43 | @ApiModelProperty(value = "客户端秘钥")
44 | private String clientSecret;
45 |
46 | @ApiModelProperty(value = "access_token有效时长")
47 | private Long accessTokenExpire;
48 |
49 | @ApiModelProperty(value = "refresh_token有效时长")
50 | private Long refreshTokenExpire;
51 |
52 | @ApiModelProperty(value = "是否启用refresh_token,1:是,0:否")
53 | private Integer enableRefreshToken;
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/FriendLink.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.io.Serializable;
6 |
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import io.swagger.annotations.ApiModel;
9 | import io.swagger.annotations.ApiModelProperty;
10 | import lombok.Data;
11 | import lombok.EqualsAndHashCode;
12 | import lombok.experimental.Accessors;
13 |
14 | import javax.validation.constraints.NotBlank;
15 |
16 | /**
17 | *
18 | * 友链表
19 | *
20 | *
21 | * @author yaohw
22 | * @since 2019-12-02
23 | */
24 | @Data
25 | @Accessors(chain = true)
26 | @EqualsAndHashCode(callSuper = false)
27 | @JsonInclude(JsonInclude.Include.NON_NULL)
28 | @ApiModel(value="FriendChain对象", description="友链表")
29 | public class FriendLink implements Serializable {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | @ApiModelProperty(value = "id")
34 | @TableId(value = "id", type = IdType.AUTO)
35 | private Integer id;
36 |
37 | @ApiModelProperty(value = "名称")
38 | @NotBlank(message = "名称不能为空")
39 | private String name;
40 |
41 | @ApiModelProperty(value = "链接")
42 | @NotBlank(message = "链接不能为空")
43 | private String url;
44 |
45 | @ApiModelProperty(value = "图标")
46 | private String icon;
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/LeaveMessage.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.time.LocalDateTime;
6 | import java.io.Serializable;
7 |
8 | import com.baomidou.mybatisplus.annotation.TableLogic;
9 | import com.fasterxml.jackson.annotation.JsonInclude;
10 | import io.swagger.annotations.ApiModel;
11 | import io.swagger.annotations.ApiModelProperty;
12 | import lombok.Data;
13 | import lombok.EqualsAndHashCode;
14 | import lombok.experimental.Accessors;
15 |
16 | /**
17 | *
18 | * 留言表
19 | *
20 | *
21 | * @author yaohw
22 | * @since 2019-12-05
23 | */
24 | @Data
25 | @Accessors(chain = true)
26 | @EqualsAndHashCode(callSuper = false)
27 | @JsonInclude(JsonInclude.Include.NON_NULL)
28 | @ApiModel(value="LeaveMessage对象", description="留言表")
29 | public class LeaveMessage implements Serializable {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | @ApiModelProperty(value = "id")
34 | @TableId(value = "id", type = IdType.AUTO)
35 | private Integer id;
36 |
37 | @ApiModelProperty(value = "父id")
38 | private Integer pid;
39 |
40 | @ApiModelProperty(value = "留言者id")
41 | private Integer fromUserId;
42 |
43 | @ApiModelProperty(value = "被回复者id")
44 | private Integer toUserId;
45 |
46 | @ApiModelProperty(value = "内容")
47 | private String content;
48 |
49 | @ApiModelProperty(value = "时间")
50 | private LocalDateTime createTime;
51 |
52 | @TableLogic
53 | @ApiModelProperty(value = "是否删除,1:是,0:否")
54 | private Integer deleted;
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/OauthUser.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import java.time.LocalDateTime;
6 | import java.io.Serializable;
7 | import io.swagger.annotations.ApiModel;
8 | import io.swagger.annotations.ApiModelProperty;
9 | import lombok.Data;
10 | import lombok.EqualsAndHashCode;
11 | import lombok.experimental.Accessors;
12 |
13 | /**
14 | *
15 | * 第三方登录关联表
16 | *
17 | *
18 | * @author yaohw
19 | * @since 2020-05-20
20 | */
21 | @Data
22 | @EqualsAndHashCode(callSuper = false)
23 | @Accessors(chain = true)
24 | @ApiModel(value="OauthUser对象", description="第三方登录关联表")
25 | public class OauthUser implements Serializable {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | @TableId(value = "id", type = IdType.AUTO)
30 | private Integer id;
31 |
32 | @ApiModelProperty(value = "第三方平台的用户唯一id")
33 | private String uuid;
34 |
35 | @ApiModelProperty(value = "用户id")
36 | private Integer userId;
37 |
38 | @ApiModelProperty(value = "认证类型,1:qq,2:github,3:微信,4:gitee")
39 | private Integer type;
40 |
41 | @ApiModelProperty(value = "创建时间")
42 | private LocalDateTime createTime;
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/Tag.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableLogic;
6 | import com.fasterxml.jackson.annotation.JsonIgnore;
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import io.swagger.annotations.ApiModel;
9 | import io.swagger.annotations.ApiModelProperty;
10 | import lombok.Data;
11 | import lombok.EqualsAndHashCode;
12 | import lombok.experimental.Accessors;
13 |
14 | import javax.validation.constraints.NotBlank;
15 | import javax.validation.constraints.Null;
16 | import java.io.Serializable;
17 | import java.time.LocalDateTime;
18 |
19 | /**
20 | *
21 | * 标签表
22 | *
23 | *
24 | * @author yaohw
25 | * @since 2019-11-14
26 | */
27 | @Data
28 | @Accessors(chain = true)
29 | @EqualsAndHashCode(callSuper = false)
30 | @JsonInclude(JsonInclude.Include.NON_NULL)
31 | @ApiModel(value="Tag对象", description="标签表")
32 | public class Tag implements Serializable {
33 |
34 | private static final long serialVersionUID = 1L;
35 |
36 | @Null(message = "不需要传id")
37 | @ApiModelProperty(value = "id")
38 | @TableId(value = "id", type = IdType.AUTO)
39 | private Integer id;
40 |
41 | @NotBlank(message = "标签名不能为空")
42 | @ApiModelProperty(value = "标签名")
43 | private String name;
44 |
45 | @TableLogic
46 | @ApiModelProperty(value = "是否已删除,1:是,0:否")
47 | private Integer deleted;
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/entity/User.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.fasterxml.jackson.annotation.JsonFormat;
6 | import com.fasterxml.jackson.annotation.JsonIgnore;
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
9 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
10 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
11 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
12 | import io.swagger.annotations.ApiModel;
13 | import io.swagger.annotations.ApiModelProperty;
14 | import lombok.Data;
15 | import lombok.EqualsAndHashCode;
16 | import lombok.experimental.Accessors;
17 |
18 | import java.io.Serializable;
19 | import java.time.LocalDate;
20 | import java.time.LocalDateTime;
21 |
22 | /**
23 | *
24 | * 用户表
25 | *
26 | *
27 | * @author yaohw
28 | * @since 2019-10-23
29 | */
30 | @Data
31 | @Accessors(chain = true)
32 | @EqualsAndHashCode(callSuper = false)
33 | @JsonInclude(JsonInclude.Include.NON_NULL)
34 | @ApiModel(value="User对象", description="用户表")
35 | public class User implements Serializable {
36 |
37 | private static final long serialVersionUID = 1L;
38 |
39 | @ApiModelProperty(value = "用户id")
40 | @TableId(value = "id", type = IdType.AUTO)
41 | private Integer id;
42 |
43 | @ApiModelProperty(value = "用户名")
44 | private String username;
45 |
46 | @JsonIgnore
47 | @ApiModelProperty(value = "密码")
48 | private String password;
49 |
50 | @ApiModelProperty(value = "手机号")
51 | private Long mobile;
52 |
53 | @ApiModelProperty(value = "昵称")
54 | private String nickname;
55 |
56 | @ApiModelProperty(value = "性别,1:男,0:女,默认为1")
57 | private Integer gender;
58 |
59 | @ApiModelProperty(value = "生日")
60 | @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
61 | private LocalDate birthday;
62 |
63 | @ApiModelProperty(value = "电子邮箱")
64 | private String email;
65 |
66 | @ApiModelProperty(value = "简介|个性签名")
67 | private String brief;
68 |
69 | @ApiModelProperty(value = "用户头像")
70 | private String avatar;
71 |
72 | @ApiModelProperty(value = "状态,0:正常,1:锁定,2:禁用,3:过期")
73 | private Integer status;
74 |
75 | @ApiModelProperty(value = "是否管理员,1:是,0:否")
76 | private Integer admin;
77 |
78 | @ApiModelProperty(value = "创建时间")
79 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
80 | @JsonSerialize(using = LocalDateTimeSerializer.class)
81 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
82 | private LocalDateTime createTime;
83 |
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ArticleCollectMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.ArticleCollect;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 文章收藏表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-04
13 | */
14 | public interface ArticleCollectMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ArticleCommentMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.ArticleComment;
4 | import cn.poile.blog.vo.ArticleCommentVo;
5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 文章评论表 Mapper 接口
13 | *
14 | *
15 | * @author yaohw
16 | * @since 2019-12-03
17 | */
18 | public interface ArticleCommentMapper extends BaseMapper {
19 |
20 | /**
21 | * 查询文章评论及回复列表,包括评论者和回复者信息
22 | * @param articleId
23 | * @param offset
24 | * @param limit
25 | * @return
26 | */
27 | List selectCommentAndReplyList(@Param("offset") long offset,@Param("limit") long limit,@Param("articleId") Integer articleId);
28 |
29 | /**
30 | * 查询最新评论,包括评论者和文章信息
31 | * @param limit
32 | * @return
33 | */
34 | List selectLatestComment(@Param("limit") long limit);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ArticleLikeMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.ArticleLike;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 文章点赞表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-02
13 | */
14 | public interface ArticleLikeMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ArticleMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.Article;
4 | import cn.poile.blog.vo.ArticleArchivesVo;
5 | import cn.poile.blog.vo.ArticleCategoryStatisticsVo;
6 | import cn.poile.blog.vo.ArticleTagStatisticsVo;
7 | import cn.poile.blog.vo.ArticleVo;
8 | import cn.poile.blog.wrapper.ArticlePageQueryWrapper;
9 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
10 | import org.apache.ibatis.annotations.Param;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | *
16 | * 文章表 Mapper 接口
17 | *
18 | *
19 | * @author yaohw
20 | * @since 2019-11-15
21 | */
22 | public interface ArticleMapper extends BaseMapper {
23 |
24 | /**
25 | * 分页查询
26 | * @param queryWrapper
27 | * @return
28 | */
29 | List selectArticleVoPage(ArticlePageQueryWrapper queryWrapper);
30 |
31 |
32 | /**
33 | * 分页查询计数
34 | * @param status 状态
35 | * @param categoryId 分类id
36 | * @param tagId 标签id
37 | * @param start 开始日期
38 | * @param end 结束日期
39 | * @param title 标题关键字
40 | * @return
41 | */
42 | Integer selectPageCount(@Param("status") Integer status,
43 | @Param("categoryId") Integer categoryId,
44 | @Param("tagId") Integer tagId,
45 | @Param("start") String start,
46 | @Param("end")String end,
47 | @Param("title") String title);
48 |
49 | /**
50 | * 根据文章id查询
51 | * @param id 文章id
52 | * @param status
53 | * @return
54 | */
55 | ArticleVo selectArticleVoById(@Param("id") int id,@Param("status") Integer status);
56 |
57 | /**
58 | * 查询上一篇和下一篇
59 | * @param id
60 | * @return
61 | */
62 | List selectPreAndNext(@Param("id") int id);
63 |
64 |
65 | /**
66 | * 文章归档计数
67 | * @return
68 | */
69 | Integer selectArticleArchivesCount();
70 |
71 | /**
72 | * 文章归档
73 | * @param offset
74 | * @param limit
75 | * @return
76 | */
77 | List selectArticleArchives(@Param("offset") long offset,@Param("limit") long limit);
78 |
79 | /**
80 | * 按分类计数文章数
81 | * @return
82 | */
83 | List selectCategoryStatistic();
84 |
85 | /**
86 | * 按标签计数文章数
87 | * @return
88 | */
89 | List selectTagStatistic();
90 |
91 | /**
92 | * 标签列表查询文章列表
93 | * @param tagList
94 | * @param limit
95 | * @return
96 | */
97 | List selectByTagList(@Param("tagList") List tagList,@Param("limit") long limit );
98 |
99 | /**
100 | * 点赞数自增
101 | * @param id
102 | */
103 | void likeCountIncrement(@Param("id") int id);
104 |
105 | /**
106 | * 点赞数自减
107 | * @param id
108 | */
109 | void likeCountDecrement(@Param("id") int id);
110 |
111 | /**
112 | * 评论数自增
113 | * @param id
114 | */
115 | void commentCountIncrement(@Param("id") int id);
116 |
117 | /**
118 | * 评论数自减
119 | * @param id
120 | */
121 | void commentCountDecrement(@Param("id") int id);
122 |
123 | /**
124 | * 收藏数自增
125 | * @param id
126 | */
127 | void collectCountIncrement(@Param("id") int id);
128 |
129 | /**
130 | * 收藏数自减
131 | * @param id
132 | */
133 | void collectCountDecrement(@Param("id") int id);
134 |
135 | /**
136 | * 分页查询用户收藏文章
137 | * @param offset
138 | * @param limit
139 | * @param userId
140 | * @return
141 | */
142 | List selectCollectByUserId(@Param("offset") long offset,@Param("limit") long limit,@Param("userId") Integer userId);
143 | }
144 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ArticleReplyMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.ArticleReply;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 文章回复表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-03
13 | */
14 | public interface ArticleReplyMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ArticleTagMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.ArticleTag;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 文章-标签 关联表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-11-15
13 | */
14 | public interface ArticleTagMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/CategoryMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.Category;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 目录分类表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-11-14
13 | */
14 | public interface CategoryMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/ClientMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.Client;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 客户端表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-06
13 | */
14 | public interface ClientMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/FriendLinkMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.FriendLink;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 友链表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-02
13 | */
14 | public interface FriendLinkMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/LeaveMessageMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.LeaveMessage;
4 | import cn.poile.blog.vo.LeaveMessageVo;
5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 留言表 Mapper 接口
13 | *
14 | *
15 | * @author yaohw
16 | * @since 2019-12-05
17 | */
18 | public interface LeaveMessageMapper extends BaseMapper {
19 |
20 | /**
21 | * 查询留言及留言回复列表,包括留言者和回复者信息
22 | * @param offset
23 | * @param limit
24 | * @return
25 | */
26 | List selectLeaveMessageAndReplyList(@Param("offset") long offset, @Param("limit") long limit);
27 |
28 | /**
29 | * 最新留言
30 | * @param limit
31 | * @return
32 | */
33 | List selectLatest(@Param("limit") long limit);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/OauthUserMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.OauthUser;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 第三方登录关联表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2020-05-20
13 | */
14 | public interface OauthUserMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/TagMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.Tag;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 标签表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-11-14
13 | */
14 | public interface TagMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mapper;
2 |
3 | import cn.poile.blog.entity.User;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 |
6 | /**
7 | *
8 | * 用户表 Mapper 接口
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-10-23
13 | */
14 | public interface UserMapper extends BaseMapper {
15 |
16 |
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/mybatis/MybatisPlusGenerator.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.mybatis;
2 |
3 | import com.baomidou.mybatisplus.core.toolkit.StringPool;
4 | import com.baomidou.mybatisplus.generator.AutoGenerator;
5 | import com.baomidou.mybatisplus.generator.InjectionConfig;
6 | import com.baomidou.mybatisplus.generator.config.*;
7 | import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
8 | import com.baomidou.mybatisplus.generator.config.po.TableInfo;
9 | import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
10 | import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
11 | import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * mybatis-plus代码生成器
18 | * @author: yaohw
19 | * @create: 2019-10-23 11:42
20 | **/
21 | public class MybatisPlusGenerator {
22 |
23 | public static void main(String[] args) {
24 | AutoGenerator autoGenerator = new AutoGenerator();
25 | // 全局配置
26 | GlobalConfig gc = new GlobalConfig();
27 | gc.setOutputDir("F:/github-repos/ucs-blog/src/main/java");
28 | gc.setAuthor("yaohw");
29 | gc.setOpen(false);
30 | gc.setSwagger2(true);
31 | gc.isSwagger2();
32 | autoGenerator.setGlobalConfig(gc);
33 | // 数据源配置
34 | DataSourceConfig dataSource = new DataSourceConfig();
35 | dataSource.setUrl("jdbc:mysql://localhost:3306/blog_db?useSSL=false");
36 | dataSource.setDriverName("com.mysql.jdbc.Driver");
37 | dataSource.setUsername("root");
38 | dataSource.setPassword("root");
39 | dataSource.setTypeConvert(new MySqlTypeConvert() {
40 | @Override
41 | public DbColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
42 | String tinyint = "tinyint";
43 | if (fieldType.toLowerCase().contains(tinyint)) {
44 | return DbColumnType.INTEGER;
45 | }
46 | return (DbColumnType) super.processTypeConvert(globalConfig, fieldType);
47 | }
48 | });
49 | autoGenerator.setDataSource(dataSource);
50 | // 包名配置
51 | PackageConfig pc = new PackageConfig();
52 | pc.setParent("cn.poile.blog");
53 | autoGenerator.setPackageInfo(pc);
54 | InjectionConfig cfg = new InjectionConfig() {
55 | @Override
56 | public void initMap() {
57 | // to do nothing
58 | }
59 | };
60 | String templatePath = "/templates/mapper.xml.ftl";
61 | List focList = new ArrayList<>();
62 | // 自定义配置会被优先输出
63 | focList.add(new FileOutConfig(templatePath) {
64 | @Override
65 | public String outputFile(TableInfo tableInfo) {
66 | return "F:/github-repos/ucs-blog" + "/src/main/resources/mapper/"
67 | + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
68 | }
69 | });
70 | cfg.setFileOutConfigList(focList);
71 | autoGenerator.setCfg(cfg);
72 | // 配置模板
73 | TemplateConfig templateConfig = new TemplateConfig();
74 | templateConfig.setXml(null);
75 | autoGenerator.setTemplate(templateConfig);
76 | // 策略配置
77 | StrategyConfig strategy = new StrategyConfig();
78 | strategy.setNaming(NamingStrategy.underline_to_camel);
79 | strategy.setColumnNaming(NamingStrategy.underline_to_camel);
80 | strategy.setEntityLombokModel(true);
81 | strategy.setRestControllerStyle(true);
82 | strategy.setInclude("article_collect");
83 | // 设置
84 | // strategy.setInclude("")
85 | // 公共父类
86 | strategy.setSuperControllerClass("cn.poile.blog.controller.BaseController");
87 | autoGenerator.setStrategy(strategy);
88 | autoGenerator.setTemplateEngine(new FreemarkerTemplateEngine());
89 | autoGenerator.execute();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/ArticleRecommendService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.vo.ArticleVo;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 文章推荐服务接口
9 | * @author: yaohw
10 | * @create: 2019-11-29 11:57
11 | **/
12 | public interface ArticleRecommendService {
13 |
14 | /**
15 | * 新增推荐
16 | * @param articleId
17 | * @param score 分数
18 | */
19 | void add(Integer articleId,Double score);
20 |
21 | /**
22 | * 获取推荐列表
23 | * @return
24 | */
25 | List list();
26 |
27 | /**
28 | * 从推荐中移除
29 | * @param articleId
30 | */
31 | void remove(Integer articleId);
32 |
33 | /**
34 | * 异步刷新
35 | * @param articleId
36 | */
37 | void asyncRefresh(Integer articleId);
38 |
39 | /**
40 | * 刷新
41 | * @param articleId
42 | */
43 | void refresh(Integer articleId);
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/AuthenticationService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.common.security.AuthenticationToken;
4 | import cn.poile.blog.entity.Client;
5 |
6 | /**
7 | * @author: yaohw
8 | * @create: 2019-10-28 17:51
9 | **/
10 | public interface AuthenticationService {
11 | /**
12 | * 用户名或手机号密码认证
13 | * @param s 手机号或用户名
14 | * @param password 密码
15 | * @param client 客户端
16 | * @return cn.poile.blog.vo.TokenVo
17 | */
18 | AuthenticationToken usernameOrMobilePasswordAuthenticate(String s, String password,Client client);
19 |
20 | /**
21 | * 手机号验证码认证
22 | * @param mobile 手机号
23 | * @param code 验证码
24 | * @param client 客户端
25 | * @return
26 | */
27 | AuthenticationToken mobileCodeAuthenticate(long mobile,String code,Client client);
28 |
29 | /**
30 | * 移除 accessToken 相关
31 | * @param accessToken accessToken
32 | * @param client 客户端
33 | */
34 | void remove(String accessToken,Client client);
35 |
36 | /**
37 | * 刷新 accessToken
38 | * @param refreshToken refreshToken
39 | * @param client 客户端
40 | * @return
41 | */
42 | AuthenticationToken refreshAccessToken(String refreshToken, Client client);
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IArticleCollectService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.ArticleCollect;
4 | import cn.poile.blog.vo.ArticleVo;
5 | import com.baomidou.mybatisplus.core.metadata.IPage;
6 | import com.baomidou.mybatisplus.extension.service.IService;
7 |
8 | /**
9 | *
10 | * 文章收藏表 服务类
11 | *
12 | *
13 | * @author yaohw
14 | * @since 2019-12-04
15 | */
16 | public interface IArticleCollectService extends IService {
17 |
18 | /**
19 | * 新增收藏
20 | * @param articleId
21 | */
22 | void add(Integer articleId);
23 |
24 | /**
25 | * 删除收藏
26 | * @param articleId
27 | */
28 | void delete(Integer articleId);
29 |
30 | /**
31 | * 分页查询用户收藏文章
32 | * @param current
33 | * @param size
34 | * @return
35 | */
36 | IPage page(long current, long size);
37 |
38 | /**
39 | * 文章是否收藏
40 | * @param articleId
41 | * @return
42 | */
43 | Integer collected(Integer articleId);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IArticleCommentService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.ArticleComment;
4 | import cn.poile.blog.vo.ArticleCommentVo;
5 | import com.baomidou.mybatisplus.core.metadata.IPage;
6 | import com.baomidou.mybatisplus.extension.service.IService;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 文章评论表 服务类
13 | *
14 | *
15 | * @author yaohw
16 | * @since 2019-12-03
17 | */
18 | public interface IArticleCommentService extends IService {
19 |
20 | /**
21 | * 新增文章评论
22 | * @param articleId
23 | * @param content
24 | */
25 | void add(Integer articleId,String content);
26 |
27 | /**
28 | * 删除评论
29 | * @param commentId
30 | */
31 | void delete(Integer commentId);
32 |
33 | /**
34 | * 分页查询文章评论及回复列表,包括评论者和回复者信息
35 | * @param current
36 | * @param size
37 | * @param articleId
38 | * @return
39 | */
40 | IPage selectCommentAndReplyList(long current, long size, Integer articleId);
41 |
42 | /**
43 | * 查询最新评论,包括评论者和文章信息
44 | * @param limit
45 | * @return
46 | */
47 | List selectLatestComment(long limit);
48 |
49 | /**
50 | * 异步刷新推荐列表中的评论数、发送评论提醒邮箱
51 | * @param articleId
52 | * @param content
53 | * @return
54 | */
55 | void asyncRefreshRecommendAndSendCommentMail(Integer articleId,String content);
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IArticleLikeService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.ArticleLike;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | *
10 | * 文章点赞表 服务类
11 | *
12 | *
13 | * @author yaohw
14 | * @since 2019-12-02
15 | */
16 | public interface IArticleLikeService extends IService {
17 |
18 | /**
19 | * 查询文章是否已点赞
20 | *
21 | * @param articleId
22 | * @return 1:是,0:否
23 | */
24 | Integer liked(Integer articleId);
25 |
26 | /**
27 | * 文章点赞
28 | * @param articleId
29 | */
30 | void like(Integer articleId);
31 |
32 | /**
33 | * 取消文章点赞
34 | * @param articleId
35 | */
36 | void cancel(Integer articleId);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IArticleReplyService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.ArticleReply;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | /**
7 | *
8 | * 文章回复表 服务类
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-03
13 | */
14 | public interface IArticleReplyService extends IService {
15 |
16 | /**
17 | * 新增文章评论回复
18 | * @param articleId
19 | * @param commentId
20 | * @param toUserId
21 | * @param content
22 | */
23 | void add(Integer articleId,Integer commentId,Integer toUserId,String content);
24 |
25 | /**
26 | * 删除回复
27 | * @param replyId
28 | */
29 | void delete(Integer replyId);
30 |
31 | /**
32 | * 异步发送回复提醒邮箱
33 | * @param articleId
34 | * @param toUserId
35 | * @param content
36 | * @return
37 | */
38 | void asyncSendMail(Integer articleId,Integer toUserId,String content);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IArticleTagService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.ArticleTag;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | /**
7 | *
8 | * 文章-标签 关联表 服务类
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-11-15
13 | */
14 | public interface IArticleTagService extends IService {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/ICategoryService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.controller.model.dto.CategoryNodeDTO;
4 | import cn.poile.blog.controller.model.request.AddCategoryRequest;
5 | import cn.poile.blog.entity.Category;
6 | import com.baomidou.mybatisplus.extension.service.IService;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 目录分类表 服务类
13 | *
14 | *
15 | * @author yaohw
16 | * @since 2019-11-14
17 | */
18 | public interface ICategoryService extends IService {
19 |
20 | /**
21 | * 新增分类
22 | * @param request
23 | */
24 | void add(AddCategoryRequest request);
25 |
26 | /**
27 | * 分类目录树
28 | * @return
29 | */
30 | List getCategoryNodeTree();
31 |
32 | /**
33 | * 修改
34 | * @param id
35 | * @param name
36 | */
37 | void updateCategoryById(int id, String name);
38 |
39 | /**
40 | * 删除分类
41 | * @param id
42 | */
43 | void delete(int id);
44 |
45 | /**
46 | * 获取子元素对应父元素列表,顺序为 node3 node2 root
47 | * @param categoryId
48 | * @return
49 | */
50 | List parentList(Integer categoryId);
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IClientService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.Client;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | /**
7 | *
8 | * 客户端表 服务类
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-06
13 | */
14 | public interface IClientService extends IService {
15 |
16 | /**
17 | * 根据客户端id获取客户端
18 | * @param clientId
19 | * @return
20 | */
21 | Client getClientByClientId(String clientId);
22 |
23 | /**
24 | * 清空缓存
25 | */
26 | void clearCache();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IFriendLinkService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.FriendLink;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | /**
7 | *
8 | * 友链表 服务类
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2019-12-02
13 | */
14 | public interface IFriendLinkService extends IService {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/ILeaveMessageService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.LeaveMessage;
4 | import cn.poile.blog.vo.LeaveMessageVo;
5 | import com.baomidou.mybatisplus.core.metadata.IPage;
6 | import com.baomidou.mybatisplus.extension.service.IService;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 留言表 服务类
13 | *
14 | *
15 | * @author yaohw
16 | * @since 2019-12-05
17 | */
18 | public interface ILeaveMessageService extends IService {
19 |
20 | /**
21 | * 新增留言
22 | *
23 | * @param content
24 | */
25 | void add(String content);
26 |
27 | /**
28 | * 留言回复
29 | *
30 | * @param pid
31 | * @param toUserId
32 | * @param content
33 | */
34 | void reply(Integer pid, Integer toUserId, String content);
35 |
36 | /**
37 | * 分页获取留言及回复列表
38 | * @param current
39 | * @param size
40 | * @return
41 | */
42 | IPage page(long current,long size);
43 |
44 | /**
45 | * 删除(本人和管理可删除)
46 | * @param id
47 | */
48 | void delete(Integer id);
49 |
50 | /**
51 | * 最新留言
52 | * @param limit
53 | * @return
54 | */
55 | List selectLatest(long limit);
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IOauthUserService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.OauthUser;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | /**
7 | *
8 | * 第三方登录关联表 服务类
9 | *
10 | *
11 | * @author yaohw
12 | * @since 2020-05-20
13 | */
14 | public interface IOauthUserService extends IService {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/ITagService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.entity.Tag;
4 | import com.baomidou.mybatisplus.core.metadata.IPage;
5 | import com.baomidou.mybatisplus.extension.service.IService;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | *
11 | * 标签表 服务类
12 | *
13 | *
14 | * @author yaohw
15 | * @since 2019-11-14
16 | */
17 | public interface ITagService extends IService {
18 | /**
19 | * 新增标签
20 | * @param tagName
21 | * @return void
22 | */
23 | void addTag(String tagName);
24 |
25 | /**
26 | * 分页查询标签
27 | * @param current 当前页
28 | * @param size 每页数量
29 | * @param tagName 标签名模糊查询
30 | * @return com.baomidou.mybatisplus.core.metadata.IPage
31 | */
32 | IPage selectTagPage(long current,long size,String tagName);
33 |
34 | /**
35 | * 标签列表
36 | * @param tagName
37 | * @return java.util.List
38 | */
39 | List selectTagList(String tagName);
40 |
41 |
42 | /**
43 | * 修改标签
44 | * @param id
45 | * @param tagName
46 | */
47 | void update(int id,String tagName);
48 |
49 | /**
50 | * 删除标签
51 | * @param id
52 | */
53 | void delete(int id);
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/IUserService.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service;
2 |
3 | import cn.poile.blog.controller.model.request.UpdateUserRequest;
4 | import cn.poile.blog.controller.model.request.UserRegisterRequest;
5 | import cn.poile.blog.entity.User;
6 | import cn.poile.blog.vo.UserVo;
7 | import com.baomidou.mybatisplus.core.metadata.IPage;
8 | import com.baomidou.mybatisplus.extension.service.IService;
9 | import org.springframework.web.multipart.MultipartFile;
10 |
11 | /**
12 | *
13 | * 用户表 服务类
14 | *
15 | *
16 | * @author yaohw
17 | * @since 2019-10-23
18 | */
19 | public interface IUserService extends IService {
20 |
21 | /**
22 | * 根据用户名或手机号查询用户信息
23 | *
24 | * @param username
25 | * @param mobile
26 | * @return cn.poile.blog.entity.User
27 | */
28 | UserVo selectUserVoByUsernameOtherwiseMobile(String username, Long mobile);
29 |
30 | /**
31 | * 根据用户id获取用户
32 | *
33 | * @param id
34 | * @return
35 | */
36 | UserVo selectUserVoById(Integer id);
37 |
38 | /**
39 | * 用户注册
40 | *
41 | * @param request
42 | */
43 | void register(UserRegisterRequest request);
44 |
45 | /**
46 | * 更新用户信息
47 | *
48 | * @param request
49 | */
50 | void update(UpdateUserRequest request);
51 |
52 | /**
53 | * 发送邮箱验证链接
54 | *
55 | * @param email
56 | * @return void
57 | */
58 | void validateEmail(String email);
59 |
60 | /**
61 | * 绑定邮箱
62 | *
63 | * @param code
64 | * @return void
65 | */
66 | void bindEmail(String code);
67 |
68 | /**
69 | * 更新头像
70 | *
71 | * @param file
72 | * @return void
73 | */
74 | void updateAvatar(MultipartFile file);
75 |
76 | /**
77 | * 修改密码
78 | *
79 | * @param oldPassword
80 | * @param newPassword
81 | * @return void
82 | */
83 | void updatePassword(String oldPassword, String newPassword);
84 |
85 | /**
86 | * 重置密码
87 | *
88 | * @param mobile
89 | * @param code
90 | * @param password
91 | * @return void
92 | */
93 | void resetPassword(long mobile, String code, String password);
94 |
95 | /**
96 | * 更换手机号 验证手机号
97 | *
98 | * @param mobile
99 | * @param code
100 | * @return void
101 | */
102 | void validateMobile(long mobile, String code);
103 |
104 | /**
105 | * 更换手机号 重新绑定
106 | *
107 | * @param mobile
108 | * @param code
109 | * @return void
110 | */
111 | void rebindMobile(long mobile, String code);
112 |
113 | /**
114 | * 分页查询用户
115 | *
116 | * @param current
117 | * @param size
118 | * @param username
119 | * @param nickname
120 | * @return
121 | */
122 | IPage page(long current, long size, String username, String nickname);
123 |
124 | /**
125 | * 修改用户状态
126 | *
127 | * @param userId
128 | * @param status
129 | */
130 | void status(Integer userId, Integer status);
131 |
132 | /**
133 | * 绑定手机号 - 用于原手机号为空的情况
134 | * @param mobile
135 | * @param code
136 | */
137 | void bindMobile(long mobile, String code);
138 |
139 | /**
140 | * 绑定用户名 - 用于用户名为空的情况
141 | * @param username
142 | */
143 | void bindUsername(String username);
144 | }
145 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/ArticleLikeServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.common.constant.ErrorEnum;
4 | import cn.poile.blog.common.exception.ApiException;
5 | import cn.poile.blog.common.security.ServerSecurityContext;
6 | import cn.poile.blog.entity.ArticleLike;
7 | import cn.poile.blog.mapper.ArticleLikeMapper;
8 | import cn.poile.blog.service.IArticleLikeService;
9 | import cn.poile.blog.service.IArticleService;
10 | import cn.poile.blog.vo.CustomUserDetails;
11 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13 | import lombok.extern.log4j.Log4j2;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.stereotype.Service;
16 | import org.springframework.transaction.annotation.Transactional;
17 |
18 | /**
19 | *
20 | * 文章点赞表 服务实现类
21 | *
22 | *
23 | * @author yaohw
24 | * @since 2019-12-02
25 | */
26 | @Log4j2
27 | @Service
28 | public class ArticleLikeServiceImpl extends ServiceImpl implements IArticleLikeService {
29 |
30 | @Autowired
31 | private IArticleService articleService;
32 |
33 | /**
34 | * 查询文章是否已点赞
35 | *
36 | * @param articleId
37 | * @return 1:是,0:否
38 | */
39 | @Override
40 | public Integer liked(Integer articleId) {
41 | QueryWrapper queryWrapper = new QueryWrapper<>();
42 | CustomUserDetails userDetail = ServerSecurityContext.getUserDetail(true);
43 | queryWrapper.lambda().eq(ArticleLike::getArticleId, articleId).eq(ArticleLike::getUserId,userDetail.getId());
44 | return count(queryWrapper);
45 | }
46 |
47 | /**
48 | * 文章点赞
49 | *
50 | * @param articleId
51 | */
52 | @Override
53 | @Transactional(rollbackFor = Exception.class)
54 | public void like(Integer articleId) {
55 | QueryWrapper queryWrapper = new QueryWrapper<>();
56 | CustomUserDetails userDetail = ServerSecurityContext.getUserDetail(true);
57 | Integer userId = userDetail.getId();
58 | queryWrapper.lambda().eq(ArticleLike::getArticleId, articleId).eq(ArticleLike::getUserId,userId);
59 | int count = count(queryWrapper);
60 | if (count != 0) {
61 | throw new ApiException(ErrorEnum.INVALID_REQUEST.getErrorCode(),"文章已点赞,不可重复点赞");
62 | }
63 | ArticleLike like = new ArticleLike();
64 | like.setArticleId(articleId);
65 | like.setUserId(userId);
66 | save(like);
67 | articleService.likeCountIncrement(articleId);
68 |
69 | }
70 |
71 | /**
72 | * 取消文章点赞
73 | *
74 | * @param articleId
75 | */
76 | @Override
77 | @Transactional(rollbackFor = Exception.class)
78 | public void cancel(Integer articleId) {
79 | QueryWrapper queryWrapper = new QueryWrapper<>();
80 | CustomUserDetails userDetail = ServerSecurityContext.getUserDetail(true);
81 | queryWrapper.lambda().eq(ArticleLike::getArticleId, articleId).eq(ArticleLike::getUserId,userDetail.getId());
82 | int count = count(queryWrapper);
83 | if (count == 0) {
84 | throw new ApiException(ErrorEnum.INVALID_REQUEST.getErrorCode(),"文章未点赞");
85 | }
86 | remove(queryWrapper);
87 | articleService.likeCountDecrement(articleId);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/ArticleTagServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.entity.ArticleTag;
4 | import cn.poile.blog.mapper.ArticleTagMapper;
5 | import cn.poile.blog.service.IArticleTagService;
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 文章-标签 关联表 服务实现类
12 | *
13 | *
14 | * @author yaohw
15 | * @since 2019-11-15
16 | */
17 | @Service
18 | public class ArticleTagServiceImpl extends ServiceImpl implements IArticleTagService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/AuthenticationServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.common.security.AuthenticationToken;
4 | import cn.poile.blog.common.security.MobileCodeAuthenticationToken;
5 | import cn.poile.blog.common.security.RedisTokenStore;
6 | import cn.poile.blog.common.sms.SmsCodeService;
7 | import cn.poile.blog.entity.Client;
8 | import cn.poile.blog.service.AuthenticationService;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.security.authentication.AuthenticationManager;
11 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
12 | import org.springframework.security.core.Authentication;
13 | import org.springframework.stereotype.Service;
14 |
15 | /**
16 | * @author: yaohw
17 | * @create: 2019-10-28 18:27
18 | **/
19 | @Service
20 | public class AuthenticationServiceImpl implements AuthenticationService {
21 |
22 | @Autowired
23 | private AuthenticationManager authenticationManager;
24 |
25 | @Autowired
26 | private RedisTokenStore tokenStore;
27 |
28 | @Autowired
29 | private SmsCodeService smsCodeService;
30 |
31 | /**
32 | * 用户名或手机号密码认证
33 | * @param s 手机号或用户名
34 | * @param password 密码
35 | * @param client
36 | * @return
37 | */
38 | @Override
39 | public AuthenticationToken usernameOrMobilePasswordAuthenticate(String s, String password, Client client) {
40 | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(s, password);
41 | Authentication authenticate = authenticationManager.authenticate(authenticationToken);
42 | return tokenStore.storeToken(authenticate,client);
43 | }
44 |
45 | /**
46 | * 手机号验证码认证
47 | * @param mobile
48 | * @param code
49 | * @param client 客户端
50 | * @return
51 | */
52 | @Override
53 | public AuthenticationToken mobileCodeAuthenticate(long mobile, String code,Client client) {
54 | MobileCodeAuthenticationToken authenticationToken = new MobileCodeAuthenticationToken(mobile, code);
55 | Authentication authenticate = authenticationManager.authenticate(authenticationToken);
56 | AuthenticationToken storeAccessToken = tokenStore.storeToken(authenticate,client);
57 | smsCodeService.deleteSmsCode(mobile);
58 | return storeAccessToken;
59 | }
60 |
61 | /**
62 | * 移除 accessToken 相关
63 | * @param accessToken
64 | * @param client 客户端
65 | */
66 | @Override
67 | public void remove(String accessToken,Client client) {
68 | tokenStore.remove(accessToken,client);
69 | }
70 |
71 | /**
72 | * 刷新accessToken
73 | * @param refreshToken
74 | * @param client 客户端
75 | * @return
76 | */
77 | @Override
78 | public AuthenticationToken refreshAccessToken(String refreshToken,Client client) {
79 | return tokenStore.refreshAuthToken(refreshToken,client);
80 | }
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/ClientServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.entity.Client;
4 | import cn.poile.blog.mapper.ClientMapper;
5 | import cn.poile.blog.service.IClientService;
6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8 | import lombok.extern.log4j.Log4j2;
9 | import org.springframework.cache.annotation.CacheEvict;
10 | import org.springframework.cache.annotation.Cacheable;
11 | import org.springframework.stereotype.Service;
12 |
13 | /**
14 | *
15 | * 客户端表 服务实现类
16 | *
17 | *
18 | * @author yaohw
19 | * @since 2019-12-06
20 | */
21 | @Service
22 | @Log4j2
23 | public class ClientServiceImpl extends ServiceImpl implements IClientService {
24 |
25 | /**
26 | * 根据客户端id获取客户端
27 | *
28 | * @param clientId
29 | * @return
30 | */
31 | @Override
32 | @Cacheable(value = "client", key = "#clientId")
33 | public Client getClientByClientId(String clientId) {
34 | QueryWrapper queryWrapper = new QueryWrapper<>();
35 | queryWrapper.lambda().eq(Client::getClientId,clientId);
36 | return getOne(queryWrapper,false);
37 | }
38 |
39 | /**
40 | * 清空缓存
41 | */
42 | @Override
43 | @CacheEvict(value = "client",allEntries = true)
44 | public void clearCache() {
45 | log.info("清空client缓存");
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/FriendLinkServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.entity.FriendLink;
4 | import cn.poile.blog.mapper.FriendLinkMapper;
5 | import cn.poile.blog.service.IFriendLinkService;
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 友链表 服务实现类
12 | *
13 | *
14 | * @author yaohw
15 | * @since 2019-12-02
16 | */
17 | @Service
18 | public class FriendLinkServiceImpl extends ServiceImpl implements IFriendLinkService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/OauthUserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.entity.OauthUser;
4 | import cn.poile.blog.mapper.OauthUserMapper;
5 | import cn.poile.blog.service.IOauthUserService;
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 第三方登录关联表 服务实现类
12 | *
13 | *
14 | * @author yaohw
15 | * @since 2020-05-20
16 | */
17 | @Service
18 | public class OauthUserServiceImpl extends ServiceImpl implements IOauthUserService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/TagServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.common.constant.CommonConstant;
4 | import cn.poile.blog.common.constant.ErrorEnum;
5 | import cn.poile.blog.common.exception.ApiException;
6 | import cn.poile.blog.entity.Tag;
7 | import cn.poile.blog.mapper.TagMapper;
8 | import cn.poile.blog.service.ITagService;
9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
10 | import com.baomidou.mybatisplus.core.metadata.IPage;
11 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13 | import org.apache.commons.lang3.StringUtils;
14 | import org.springframework.stereotype.Service;
15 | import org.springframework.transaction.annotation.Transactional;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | *
21 | * 标签表 服务实现类
22 | *
23 | *
24 | * @author yaohw
25 | * @since 2019-11-14
26 | */
27 | @Service
28 | public class TagServiceImpl extends ServiceImpl implements ITagService {
29 |
30 | /**
31 | * 新增标签
32 | *
33 | * @param tagName
34 | * @return void
35 | */
36 | @Override
37 | @Transactional(rollbackFor = Exception.class)
38 | public void addTag(String tagName) {
39 | Tag daoTag = selectByTagName(tagName);
40 | if (daoTag != null) {
41 | throw new ApiException(ErrorEnum.INVALID_REQUEST.getErrorCode(),"标签已存在");
42 | }
43 | Tag tag = new Tag();
44 | tag.setName(tagName);
45 | tag.setDeleted(CommonConstant.NOT_DELETED);
46 | save(tag);
47 | }
48 |
49 | /**
50 | * 分页查询标签
51 | * @param current 当前页
52 | * @param size 每页数量
53 | * @param tagName 标签名
54 | * @return com.baomidou.mybatisplus.core.metadata.IPage
55 | */
56 | @Override
57 | public IPage selectTagPage(long current,long size,String tagName) {
58 | Page page = new Page<>(current,size);
59 | if (StringUtils.isBlank(tagName)) {
60 | return page(page);
61 | }
62 | QueryWrapper queryWrapper = new QueryWrapper<>();
63 | queryWrapper.lambda().like(Tag::getName,tagName);
64 | return page(page,queryWrapper);
65 | }
66 |
67 | /**
68 | * 标签列表
69 | * @param tagName
70 | * @return java.util.List
71 | */
72 | @Override
73 | public List selectTagList(String tagName) {
74 | QueryWrapper queryWrapper = new QueryWrapper<>();
75 | if (StringUtils.isNotBlank(tagName)) {
76 | queryWrapper.lambda().like(Tag::getName,tagName);
77 | }
78 | return list(queryWrapper);
79 | }
80 |
81 |
82 | /**
83 | * 修改标签
84 | * @param id
85 | * @param tagName
86 | */
87 | @Override
88 | public void update(int id, String tagName) {
89 | Tag daoTag = selectByTagName(tagName);
90 | if (daoTag != null && daoTag.getName().equals(tagName)) {
91 | throw new ApiException(ErrorEnum.INVALID_REQUEST.getErrorCode(),"标签已存在");
92 | }
93 | Tag tag = new Tag();
94 | tag.setName(tagName);
95 | tag.setId(id);
96 | updateById(tag);
97 | }
98 |
99 | /**
100 | * 删除标签
101 | *
102 | * @param id
103 | */
104 | @Override
105 | public void delete(int id) {
106 | removeById(id);
107 | }
108 |
109 | /**
110 | * 根据标签名查询
111 | * @param tagName
112 | * @return cn.poile.blog.entity.Tag
113 | */
114 | private Tag selectByTagName(String tagName){
115 | QueryWrapper queryWrapper = new QueryWrapper<>();
116 | queryWrapper.lambda().eq(Tag::getName,tagName);
117 | return getOne(queryWrapper,false);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/service/impl/UserDetailsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.service.impl;
2 |
3 | import cn.poile.blog.common.util.ValidateUtil;
4 | import cn.poile.blog.service.IUserService;
5 | import cn.poile.blog.vo.CustomUserDetails;
6 | import cn.poile.blog.vo.UserVo;
7 | import org.springframework.beans.BeanUtils;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.security.core.userdetails.UserDetails;
10 | import org.springframework.security.core.userdetails.UserDetailsService;
11 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
12 | import org.springframework.stereotype.Service;
13 |
14 | /**
15 | * @author: yaohw
16 | * @create: 2019-10-24 16:40
17 | **/
18 | @Service
19 | public class UserDetailsServiceImpl implements UserDetailsService {
20 |
21 | @Autowired
22 | private IUserService userService;
23 |
24 | @Override
25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
26 | boolean isMobile = ValidateUtil.validateMobile(username);
27 | UserVo userVo;
28 | if (isMobile) {
29 | userVo = userService.selectUserVoByUsernameOtherwiseMobile(null,Long.parseLong(username));
30 | } else {
31 | userVo = userService.selectUserVoByUsernameOtherwiseMobile(username,null);
32 | }
33 | if (userVo == null) {
34 | throw new UsernameNotFoundException("user not found:" + username);
35 | }
36 | UserDetails userDetails = new CustomUserDetails();
37 | BeanUtils.copyProperties(userVo,userDetails);
38 | return userDetails;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/ArticleArchivesVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableField;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 |
9 | /**
10 | * 归档
11 | * @author: yaohw
12 | * @create: 2019-11-27 11:11
13 | **/
14 | @Data
15 | @JsonInclude(JsonInclude.Include.NON_NULL)
16 | @ApiModel(value = "ArticleArchivesVo对象",description = "文章归档")
17 | public class ArticleArchivesVo {
18 |
19 | @ApiModelProperty(value = "年月,格式yyyy-mm")
20 | private String yearMonth;
21 |
22 | @TableField(value = "article_count")
23 | @ApiModelProperty(value = "数量")
24 | private long articleCount;
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/ArticleCategoryStatisticsVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.Category;
4 | import com.baomidou.mybatisplus.annotation.TableField;
5 | import com.fasterxml.jackson.annotation.JsonInclude;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 | import lombok.Data;
9 | import lombok.EqualsAndHashCode;
10 | import lombok.experimental.Accessors;
11 |
12 | /**
13 | * 文章分类统计
14 | * @author: yaohw
15 | * @create: 2019-11-28 10:45
16 | **/
17 | @Data
18 | @Accessors(chain = true)
19 | @EqualsAndHashCode(callSuper = false)
20 | @JsonInclude(JsonInclude.Include.NON_NULL)
21 | @ApiModel(value="ArticleCategoriesVo对象", description="文章分类计数")
22 | public class ArticleCategoryStatisticsVo extends Category {
23 |
24 | @TableField(value = "article_count")
25 | @ApiModelProperty("分类文章数量")
26 | private int articleCount;
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/ArticleCommentVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.Article;
4 | import cn.poile.blog.entity.User;
5 | import com.baomidou.mybatisplus.annotation.IdType;
6 | import com.baomidou.mybatisplus.annotation.TableId;
7 | import com.fasterxml.jackson.annotation.JsonFormat;
8 | import com.fasterxml.jackson.annotation.JsonInclude;
9 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
10 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
11 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
12 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
13 | import io.swagger.annotations.ApiModel;
14 | import io.swagger.annotations.ApiModelProperty;
15 | import lombok.Data;
16 | import lombok.EqualsAndHashCode;
17 | import lombok.experimental.Accessors;
18 | import java.time.LocalDateTime;
19 | import java.util.List;
20 |
21 | /**
22 | * @author: yaohw
23 | * @create: 2019-12-03 20:06
24 | **/
25 | @Data
26 | @Accessors(chain = true)
27 | @EqualsAndHashCode(callSuper = false)
28 | @JsonInclude(JsonInclude.Include.NON_NULL)
29 | @ApiModel(value="ArticleCommentVo", description="文章评论Vo")
30 | public class ArticleCommentVo {
31 |
32 | @ApiModelProperty(value = "id")
33 | @TableId(value = "id", type = IdType.AUTO)
34 | private Integer id;
35 |
36 | @ApiModelProperty(value = "评论内容")
37 | private String content;
38 |
39 | @ApiModelProperty(value = "评论时间")
40 | @JsonSerialize(using = LocalDateTimeSerializer.class)
41 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
42 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
43 | private LocalDateTime commentTime;
44 |
45 | @ApiModelProperty(value = "文章")
46 | private Article article;
47 |
48 | @ApiModelProperty(value = "评论者id")
49 | private User fromUser;
50 |
51 | @ApiModelProperty(value = "评论回复列表")
52 | private List replyList;
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/ArticleReplyVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.User;
4 | import com.baomidou.mybatisplus.annotation.IdType;
5 | import com.baomidou.mybatisplus.annotation.TableId;
6 | import com.fasterxml.jackson.annotation.JsonFormat;
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
9 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
10 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
11 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
12 | import io.swagger.annotations.ApiModel;
13 | import io.swagger.annotations.ApiModelProperty;
14 | import lombok.Data;
15 | import lombok.EqualsAndHashCode;
16 | import lombok.experimental.Accessors;
17 |
18 | import java.time.LocalDateTime;
19 |
20 | /**
21 | * @author: yaohw
22 | * @create: 2019-12-03 20:11
23 | **/
24 | @Data
25 | @Accessors(chain = true)
26 | @EqualsAndHashCode(callSuper = false)
27 | @JsonInclude(JsonInclude.Include.NON_NULL)
28 | @ApiModel(value="ArticleReplyVo", description="文章评论回复Vo")
29 | public class ArticleReplyVo {
30 |
31 | @ApiModelProperty(value = "id")
32 | @TableId(value = "id", type = IdType.AUTO)
33 | private Integer id;
34 |
35 | @ApiModelProperty(value = "回复内容")
36 | private String content;
37 |
38 | @ApiModelProperty(value = "回复时间")
39 | @JsonSerialize(using = LocalDateTimeSerializer.class)
40 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
41 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
42 | private LocalDateTime replyTime;
43 |
44 | @ApiModelProperty(value = "评论者")
45 | private User fromUser;
46 |
47 | @ApiModelProperty(value = "被评论者")
48 | private User toUser;
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/ArticleTagStatisticsVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.Tag;
4 | import com.baomidou.mybatisplus.annotation.TableField;
5 | import com.fasterxml.jackson.annotation.JsonInclude;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 | import lombok.Data;
9 | import lombok.EqualsAndHashCode;
10 | import lombok.experimental.Accessors;
11 |
12 | /**
13 | * @author: yaohw
14 | * @create: 2019-11-28 15:07
15 | **/
16 | @Data
17 | @Accessors(chain = true)
18 | @EqualsAndHashCode(callSuper = false)
19 | @JsonInclude(JsonInclude.Include.NON_NULL)
20 | @ApiModel(value="ArticleTagStatisticsVo对象", description="文章标签计数")
21 | public class ArticleTagStatisticsVo extends Tag {
22 |
23 | @TableField(value = "article_count")
24 | @ApiModelProperty("分类文章数量")
25 | private int articleCount;
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/ArticleVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.Article;
4 | import cn.poile.blog.entity.Category;
5 | import cn.poile.blog.entity.Tag;
6 | import cn.poile.blog.entity.User;
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import io.swagger.annotations.ApiModel;
9 | import io.swagger.annotations.ApiModelProperty;
10 | import lombok.Data;
11 | import lombok.EqualsAndHashCode;
12 | import lombok.experimental.Accessors;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * 文章详细对象
18 | * @author: yaohw
19 | * @create: 2019-11-25 11:10
20 | **/
21 | @Data
22 | @Accessors(chain = true)
23 | @EqualsAndHashCode(callSuper = true)
24 | @JsonInclude(JsonInclude.Include.NON_NULL)
25 | @ApiModel(value="ArticleVo对象", description="文章详细对象")
26 | public class ArticleVo extends Article {
27 |
28 | @ApiModelProperty("作者")
29 | private User user;
30 |
31 | @ApiModelProperty("标签列表")
32 | private List tagList;
33 |
34 | @ApiModelProperty("分类列表,顺序:root node2 node3")
35 | private List categoryList;
36 |
37 | @ApiModelProperty("上一篇")
38 | private Article previous;
39 |
40 | @ApiModelProperty("下一篇")
41 | private Article next;
42 |
43 | @ApiModelProperty("推荐分数")
44 | private Double recommendScore;
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/CustomUserDetails.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 | import lombok.experimental.Accessors;
8 | import org.springframework.security.core.GrantedAuthority;
9 | import org.springframework.security.core.userdetails.UserDetails;
10 | import org.springframework.util.CollectionUtils;
11 |
12 | import java.util.Collection;
13 | import java.util.Collections;
14 | import java.util.stream.Collectors;
15 |
16 | /**
17 | * @author: yaohw
18 | * @create: 2019-10-24 16:45
19 | **/
20 | @Data
21 | @Accessors(chain = true)
22 | @EqualsAndHashCode(callSuper = false)
23 | @JsonInclude(JsonInclude.Include.NON_NULL)
24 | public class CustomUserDetails extends UserVo implements UserDetails {
25 |
26 | @Override
27 | @JsonIgnore
28 | public Collection extends GrantedAuthority> getAuthorities() {
29 | if (!CollectionUtils.isEmpty(roles)) {
30 | return roles.stream().map(this::createAuthority).collect(Collectors.toSet());
31 | }
32 | return Collections.emptyList();
33 | }
34 |
35 | private GrantedAuthority createAuthority(String authority) {
36 | return (()->authority);
37 | }
38 |
39 | @Override
40 | @JsonIgnore
41 | public boolean isAccountNonExpired() {
42 | return !getStatus().equals(3);
43 | }
44 |
45 | @Override
46 | @JsonIgnore
47 | public boolean isAccountNonLocked() {
48 | return !getStatus().equals(1);
49 | }
50 |
51 | @Override
52 | @JsonIgnore
53 | public boolean isCredentialsNonExpired() {
54 | return true;
55 | }
56 |
57 | @Override
58 | @JsonIgnore
59 | public boolean isEnabled() {
60 | return !getStatus().equals(2);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/LeaveMessageReplyVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.User;
4 | import com.baomidou.mybatisplus.annotation.IdType;
5 | import com.baomidou.mybatisplus.annotation.TableId;
6 | import com.fasterxml.jackson.annotation.JsonFormat;
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
9 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
10 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
11 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
12 | import io.swagger.annotations.ApiModel;
13 | import io.swagger.annotations.ApiModelProperty;
14 | import lombok.Data;
15 | import lombok.EqualsAndHashCode;
16 | import lombok.experimental.Accessors;
17 |
18 | import java.time.LocalDateTime;
19 |
20 | /**
21 | * @author: yaohw
22 | * @create: 2019-12-06 10:05
23 | **/
24 | @Data
25 | @Accessors(chain = true)
26 | @EqualsAndHashCode(callSuper = false)
27 | @JsonInclude(JsonInclude.Include.NON_NULL)
28 | @ApiModel(value="LeaveMessageReplyVo对象", description="留言回复")
29 | public class LeaveMessageReplyVo {
30 |
31 | @ApiModelProperty(value = "id")
32 | private Integer id;
33 |
34 | @ApiModelProperty(value = "内容")
35 | private String content;
36 |
37 | @ApiModelProperty(value = "时间")
38 | @JsonSerialize(using = LocalDateTimeSerializer.class)
39 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
40 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
41 | private LocalDateTime createTime;
42 |
43 | @ApiModelProperty(value = "回复者")
44 | private User fromUser;
45 |
46 | @ApiModelProperty(value = "被回复者")
47 | private User toUser;
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/LeaveMessageVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.User;
4 | import com.baomidou.mybatisplus.annotation.IdType;
5 | import com.baomidou.mybatisplus.annotation.TableId;
6 | import com.fasterxml.jackson.annotation.JsonFormat;
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
9 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
10 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
11 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
12 | import io.swagger.annotations.ApiModel;
13 | import io.swagger.annotations.ApiModelProperty;
14 | import lombok.Data;
15 | import lombok.EqualsAndHashCode;
16 | import lombok.experimental.Accessors;
17 |
18 | import java.time.LocalDateTime;
19 | import java.util.List;
20 |
21 | /**
22 | * @author: yaohw
23 | * @create: 2019-12-06 10:01
24 | **/
25 | @Data
26 | @Accessors(chain = true)
27 | @EqualsAndHashCode(callSuper = false)
28 | @JsonInclude(JsonInclude.Include.NON_NULL)
29 | @ApiModel(value="LeaveMessageVo对象", description="留言")
30 | public class LeaveMessageVo {
31 |
32 | @ApiModelProperty(value = "id")
33 | private Integer id;
34 |
35 | @ApiModelProperty(value = "内容")
36 | private String content;
37 |
38 | @ApiModelProperty(value = "时间")
39 | @JsonSerialize(using = LocalDateTimeSerializer.class)
40 | @JsonDeserialize(using = LocalDateTimeDeserializer.class)
41 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
42 | private LocalDateTime createTime;
43 |
44 | @ApiModelProperty(value = "留言者")
45 | private User fromUser;
46 |
47 | @ApiModelProperty(value = "回复列表")
48 | private List replyList;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/vo/UserVo.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.vo;
2 |
3 | import cn.poile.blog.entity.User;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import lombok.experimental.Accessors;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * @author: yaohw
15 | * @create: 2019-10-24 16:50
16 | **/
17 | @Data
18 | @Accessors(chain = true)
19 | @EqualsAndHashCode(callSuper = false)
20 | @JsonInclude(JsonInclude.Include.NON_NULL)
21 | @ApiModel(value="UserVo对象", description="用户详细信息")
22 | public class UserVo extends User {
23 |
24 | /**
25 | * 角色列表
26 | */
27 | @ApiModelProperty(value = "角色列表")
28 | protected List roles;
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/cn/poile/blog/wrapper/ArticlePageQueryWrapper.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog.wrapper;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | /**
8 | * @author: yaohw
9 | * @create: 2019-11-28 19:41
10 | **/
11 | @Data
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | public class ArticlePageQueryWrapper {
15 |
16 | private Integer status;
17 |
18 | private Long offset;
19 |
20 | private Long limit;
21 |
22 | private Integer categoryId;
23 |
24 | private Integer tagId;
25 |
26 | private String title;
27 |
28 | private String orderBy;
29 |
30 | private String start;
31 |
32 | private String end;
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/resources/application-prod.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9090
3 | spring:
4 | task:
5 | execution:
6 | pool:
7 | max-size: 16
8 | core-size: 8
9 | keep-alive: 60s
10 | queue-capacity: 100
11 | allow-core-thread-timeout: true
12 | redis:
13 | host: 127.0.0.1
14 | port: 6379
15 | password:
16 | timeout: 3000
17 | lettuce:
18 | pool:
19 | max-active: 8
20 | max-idle: 8
21 | min-idle: 0
22 | max-wait: -1ms
23 | datasource:
24 | type: com.alibaba.druid.pool.DruidDataSource
25 | driver-class-name: com.mysql.jdbc.Driver
26 | url: jdbc:mysql://193.112.43.235:3306/blog_db?useSSL=false&u-seUnicode=true&characterEncoding=utf-8
27 | username: root
28 | password: Ab452637!
29 | druid:
30 | initial-size: 5
31 | min-idle: 5
32 | maxActive: 20
33 | maxWait: 60000
34 | timeBetweenEvictionRunsMillis: 60000
35 | minEvictableIdleTimeMillis: 300000
36 | validationQuery: SELECT 1 FROM DUAL
37 | testWhileIdle: true
38 | testOnBorrow: false
39 | testOnReturn: false
40 | poolPreparedStatements: true
41 | maxPoolPreparedStatementPerConnectionSize: 20
42 | filter:
43 | slf4j:
44 | enabled: true
45 | wall:
46 | enabled: true
47 | stat:
48 | enabled: true
49 | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
50 | web-stat-filter:
51 | enabled: true
52 | url-pattern: "/*"
53 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
54 | stat-view-servlet:
55 | url-pattern: "/druid/*"
56 | reset-enable: false
57 | login-username: admin
58 | login-password: yaohw321!
59 | mail:
60 | host: smtp.163.com
61 | port: 465
62 | username: 15625295093@163.com
63 | password:
64 | protocol: smtp
65 | default-encoding: UTF-8
66 | jndi-name: 个人悦读分享
67 | properties:
68 | mail:
69 | smtp:
70 | ssl:
71 | enable: true
72 |
73 |
74 | ## oss存储配置 ##
75 | oss:
76 | type: 3
77 | netease:
78 | accessKey: 2bec4d8797e64f99b967c88fa0d08d39
79 | secretKey: ca8bb777179949a4b0767108bdf032e8
80 | endpoint: nos-eastchina1.126.net
81 | bucket: poile-img
82 |
83 | sms:
84 | type: 1
85 | expire: 300
86 | day_max: 10
87 | ali:
88 | regionId: cn-hangzhou
89 | accessKeyId: LTAI4FvoP9o1tH
90 | accessKeySecret: YjUrQ9sTEWwGY6Ys1o
91 | signName: 个人悦读分享
92 | templateCode: SMS_176942058
93 |
94 | mail:
95 | check: http://www.poile.cn/email/verify
96 | article: http://www.poile.cn/article/#/
97 | message: http://www.poile.cn/message
98 |
99 | # 生产环境禁用swagger
100 | swagger:
101 | enabled: true
102 |
103 |
104 |
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active:
4 | - prod
5 | application:
6 | name: blog-api
7 | servlet:
8 | multipart:
9 | enabled: true
10 | file-size-threshold: 0
11 | location: /var/tmp
12 | max-request-size: 5MB
13 | max-file-size: 5MB
14 | thymeleaf:
15 | suffix: .html
16 | cache: true
17 | encoding: UTF-8
18 |
19 | # 忽略安全校验url列表,不可修改
20 | ignore:
21 | list:
22 | - /actuator/**
23 | - /v2/api-docs
24 | - /swagger/api-docs
25 | - /swagger-resources/**
26 | - /swagger-ui.html
27 | - /webjars/**
28 | - /druid/**
29 | - /sms/**
30 | - /account/login
31 | - /mobile/login
32 | - /logout
33 | - /refresh_access_token
34 | - /user/register
35 | - /user/password/reset
36 | - /user/email/bind
37 | - /user/password/reset
38 | - /category/tree
39 | - /category/list
40 | - /tag/list
41 | - /article/published/page
42 | - /article/view/**
43 | - /article/increment_view/**
44 | - /article/archives/page
45 | - /article/category/statistic
46 | - /article/tag/statistic
47 | - /article/recommend/list
48 | - /article/interrelated/list
49 | - /article/count
50 | - /article/like/list
51 | - /friend/link/page
52 | - /friend/link/list
53 | - /article/comment/page
54 | - /article/comment/latest
55 | - /leave/message/page
56 | - /leave/message/latest
57 | - /oauth
58 |
59 | # mybatis-plus配置,不可修改
60 | mybatis-plus:
61 | mapper-locations:
62 | - classpath:/mapper/*.xml
63 | type-aliases-package: cn.poile.bolg.entity
64 | global-config:
65 | db-config:
66 | # 配置逻辑删除,1:是,0:否
67 | logic-not-delete-value: 0
68 | logic-delete-value: 1
69 |
--------------------------------------------------------------------------------
/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | %d{yyyy-MM-dd HH:mm:ss.SSS} ----> [%thread] ---> %-5level %logger{50} - %msg%n
12 |
13 |
14 | %d{yyyy-MM-dd HH:mm:ss.SSS} ==== [%thread] ==== %-5level %logger{50} - %msg%n
15 |
16 |
17 |
18 |
19 |
20 | ${LOG_HOME}/${name}.log
21 |
22 | ${LOG_HOME}/${name}-%d{yyyy-MM-dd}-%i.log
23 | 365
24 |
25 | 100MB
26 |
27 |
28 |
29 |
30 | %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/ArticleCollectMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/ArticleLikeMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/ArticleReplyMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/ArticleTagMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/CategoryMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/ClientMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/FriendLinkMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/OauthUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/TagMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/scripts/redis/limit.lua:
--------------------------------------------------------------------------------
1 | -- 下标从 1 开始
2 | local key = KEYS[1]
3 | local now = tonumber(ARGV[1])
4 | local ttl = tonumber(ARGV[2])
5 | local expired = tonumber(ARGV[3])
6 | -- 最大访问量
7 | local max = tonumber(ARGV[4])
8 |
9 | -- 清除过期的数据
10 | -- 移除指定分数区间内的所有元素,expired 即已经过期的 score
11 | -- 根据当前时间毫秒数 - 超时毫秒数,得到过期时间 expired
12 | redis.call('zremrangebyscore', key, 0, expired)
13 |
14 | -- 获取 zset 中的当前元素个数
15 | local current = tonumber(redis.call('zcard', key))
16 | local next = current + 1
17 |
18 | if next > max then
19 | -- 达到限流大小 返回 0
20 | return 0;
21 | else
22 | -- 往 zset 中添加一个值、得分均为当前时间戳的元素,[value,score]
23 | redis.call("zadd", key, now, now)
24 | -- 每次访问均重新设置 zset 的过期时间,单位毫秒
25 | redis.call("pexpire", key, ttl)
26 | return next
27 | end
28 |
--------------------------------------------------------------------------------
/src/test/java/cn/poile/blog/BlogApplicationTest.java:
--------------------------------------------------------------------------------
1 | package cn.poile.blog;
2 |
3 | import lombok.extern.log4j.Log4j2;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | /**
10 | * @author: yaohw
11 | * @create: 2019-10-23 18:47
12 | **/
13 | //@RunWith(SpringRunner.class)
14 | //@SpringBootTest
15 | @Log4j2
16 | public class BlogApplicationTest {
17 |
18 | @Test
19 | public void test() {
20 |
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------