diff --git a/pom.xml b/pom.xml
index cd74848..ac0ca32 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,6 +41,12 @@
com.baomidou
mybatis-plus-boot-starter
3.5.2
+
+
+ org.slf4j
+ *
+
+
@@ -51,11 +57,6 @@
org.springframework.session
spring-session-data-redis
-
-
- org.springframework.boot
- spring-boot-starter-data-elasticsearch
-
com.github.binarywang
@@ -68,12 +69,6 @@
knife4j-openapi2-spring-boot-starter
4.4.0
-
-
- com.qcloud
- cos_api
- 5.6.89
-
org.apache.commons
diff --git a/src/main/java/com/yupi/springbootinit/MainApplication.java b/src/main/java/com/yupi/springbootinit/MainApplication.java
index 2090350..af1d74d 100644
--- a/src/main/java/com/yupi/springbootinit/MainApplication.java
+++ b/src/main/java/com/yupi/springbootinit/MainApplication.java
@@ -21,8 +21,14 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
public class MainApplication {
-
+ static {
+ // 在静态块中最早设置
+ org.apache.ibatis.logging.LogFactory.useNoLogging();
+ }
public static void main(String[] args) {
+ org.apache.ibatis.logging.Log log =
+ org.apache.ibatis.logging.LogFactory.getLog(MainApplication.class);
+ System.out.println("当前MyBatis日志实现: " + log.getClass().getName());
SpringApplication.run(MainApplication.class, args);
}
diff --git a/src/main/java/com/yupi/springbootinit/aop/AuthInterceptor.java b/src/main/java/com/yupi/springbootinit/aop/AuthInterceptor.java
deleted file mode 100644
index adc3673..0000000
--- a/src/main/java/com/yupi/springbootinit/aop/AuthInterceptor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.yupi.springbootinit.aop;
-
-import com.yupi.springbootinit.annotation.AuthCheck;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.enums.UserRoleEnum;
-import com.yupi.springbootinit.service.UserService;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.springframework.stereotype.Component;
-import org.springframework.web.context.request.RequestAttributes;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * 权限校验 AOP
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Aspect
-@Component
-public class AuthInterceptor {
-
- @Resource
- private UserService userService;
-
- /**
- * 执行拦截
- *
- * @param joinPoint
- * @param authCheck
- * @return
- */
- @Around("@annotation(authCheck)")
- public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable {
- String mustRole = authCheck.mustRole();
- RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
- HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
- // 当前登录用户
- User loginUser = userService.getLoginUser(request);
- UserRoleEnum mustRoleEnum = UserRoleEnum.getEnumByValue(mustRole);
- // 不需要权限,放行
- if (mustRoleEnum == null) {
- return joinPoint.proceed();
- }
- // 必须有该权限才通过
- UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(loginUser.getUserRole());
- if (userRoleEnum == null) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- // 如果被封号,直接拒绝
- if (UserRoleEnum.BAN.equals(userRoleEnum)) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- // 必须有管理员权限
- if (UserRoleEnum.ADMIN.equals(mustRoleEnum)) {
- // 用户没有管理员权限,拒绝
- if (!UserRoleEnum.ADMIN.equals(userRoleEnum)) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- }
- // 通过权限校验,放行
- return joinPoint.proceed();
- }
-}
-
diff --git a/src/main/java/com/yupi/springbootinit/config/AsyncConfig.java b/src/main/java/com/yupi/springbootinit/config/AsyncConfig.java
deleted file mode 100644
index 3314fca..0000000
--- a/src/main/java/com/yupi/springbootinit/config/AsyncConfig.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.yupi.springbootinit.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableAsync;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
-
-import java.util.concurrent.Executor;
-
-@Configuration
-@EnableAsync
-public class AsyncConfig {
-@Bean(name = "taskExecutor")
-public Executor taskExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- executor.setCorePoolSize(4); // 核心线程数
- executor.setMaxPoolSize(8); // 最大线程数
- executor.setQueueCapacity(100); // 队列容量
- executor.setThreadNamePrefix("AsyncExecutor-");
- executor.initialize();
- return executor;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/config/CosClientConfig.java b/src/main/java/com/yupi/springbootinit/config/CosClientConfig.java
deleted file mode 100644
index f01b26a..0000000
--- a/src/main/java/com/yupi/springbootinit/config/CosClientConfig.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.yupi.springbootinit.config;
-
-import com.qcloud.cos.COSClient;
-import com.qcloud.cos.ClientConfig;
-import com.qcloud.cos.auth.BasicCOSCredentials;
-import com.qcloud.cos.auth.COSCredentials;
-import com.qcloud.cos.region.Region;
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * 腾讯云对象存储客户端
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Configuration
-@ConfigurationProperties(prefix = "cos.client")
-@Data
-public class CosClientConfig {
-
- /**
- * accessKey
- */
- private String accessKey;
-
- /**
- * secretKey
- */
- private String secretKey;
-
- /**
- * 区域
- */
- private String region;
-
- /**
- * 桶名
- */
- private String bucket;
-
- @Bean
- public COSClient cosClient() {
- // 初始化用户身份信息(secretId, secretKey)
- COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey);
- // 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
- ClientConfig clientConfig = new ClientConfig(new Region(region));
- // 生成cos客户端
- return new COSClient(cred, clientConfig);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/config/MyBatisPlusConfig.java b/src/main/java/com/yupi/springbootinit/config/MyBatisPlusConfig.java
index a5f3b9b..9c46153 100644
--- a/src/main/java/com/yupi/springbootinit/config/MyBatisPlusConfig.java
+++ b/src/main/java/com/yupi/springbootinit/config/MyBatisPlusConfig.java
@@ -21,11 +21,11 @@ public class MyBatisPlusConfig {
*
* @return
*/
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor() {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- // 分页插件
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
- return interceptor;
- }
+// @Bean
+// public MybatisPlusInterceptor mybatisPlusInterceptor() {
+// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+// // 分页插件
+// interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+// return interceptor;
+// }
}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/config/WxOpenConfig.java b/src/main/java/com/yupi/springbootinit/config/WxOpenConfig.java
deleted file mode 100644
index b0d0dc1..0000000
--- a/src/main/java/com/yupi/springbootinit/config/WxOpenConfig.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.yupi.springbootinit.config;
-
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
-import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * 微信开放平台配置
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Slf4j
-@Configuration
-@ConfigurationProperties(prefix = "wx.open")
-@Data
-public class WxOpenConfig {
-
- private String appId;
-
- private String appSecret;
-
- private WxMpService wxMpService;
-
- /**
- * 单例模式(不用 @Bean 是为了防止和公众号的 service 冲突)
- *
- * @return
- */
- public WxMpService getWxMpService() {
- if (wxMpService != null) {
- return wxMpService;
- }
- synchronized (this) {
- if (wxMpService != null) {
- return wxMpService;
- }
- WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
- config.setAppId(appId);
- config.setSecret(appSecret);
- WxMpService service = new WxMpServiceImpl();
- service.setWxMpConfigStorage(config);
- wxMpService = service;
- return wxMpService;
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/controller/FileController.java b/src/main/java/com/yupi/springbootinit/controller/FileController.java
deleted file mode 100644
index cd3b060..0000000
--- a/src/main/java/com/yupi/springbootinit/controller/FileController.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.yupi.springbootinit.controller;
-
-import cn.hutool.core.io.FileUtil;
-import com.yupi.springbootinit.common.BaseResponse;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.common.ResultUtils;
-import com.yupi.springbootinit.constant.FileConstant;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.manager.CosManager;
-import com.yupi.springbootinit.model.dto.file.UploadFileRequest;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.enums.FileUploadBizEnum;
-import com.yupi.springbootinit.service.UserService;
-import java.io.File;
-import java.util.Arrays;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestPart;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-/**
- * 文件接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@RestController
-@RequestMapping("/file")
-@Slf4j
-public class FileController {
-
- @Resource
- private UserService userService;
-
- @Resource
- private CosManager cosManager;
-
- /**
- * 文件上传
- *
- * @param multipartFile
- * @param uploadFileRequest
- * @param request
- * @return
- */
- @PostMapping("/upload")
- public BaseResponse uploadFile(@RequestPart("file") MultipartFile multipartFile,
- UploadFileRequest uploadFileRequest, HttpServletRequest request) {
- String biz = uploadFileRequest.getBiz();
- FileUploadBizEnum fileUploadBizEnum = FileUploadBizEnum.getEnumByValue(biz);
- if (fileUploadBizEnum == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- validFile(multipartFile, fileUploadBizEnum);
- User loginUser = userService.getLoginUser(request);
- // 文件目录:根据业务、用户来划分
- String uuid = RandomStringUtils.randomAlphanumeric(8);
- String filename = uuid + "-" + multipartFile.getOriginalFilename();
- String filepath = String.format("/%s/%s/%s", fileUploadBizEnum.getValue(), loginUser.getId(), filename);
- File file = null;
- try {
- // 上传文件
- file = File.createTempFile(filepath, null);
- multipartFile.transferTo(file);
- cosManager.putObject(filepath, file);
- // 返回可访问地址
- return ResultUtils.success(FileConstant.COS_HOST + filepath);
- } catch (Exception e) {
- log.error("file upload error, filepath = " + filepath, e);
- throw new BusinessException(ErrorCode.SYSTEM_ERROR, "上传失败");
- } finally {
- if (file != null) {
- // 删除临时文件
- boolean delete = file.delete();
- if (!delete) {
- log.error("file delete error, filepath = {}", filepath);
- }
- }
- }
- }
-
- /**
- * 校验文件
- *
- * @param multipartFile
- * @param fileUploadBizEnum 业务类型
- */
- private void validFile(MultipartFile multipartFile, FileUploadBizEnum fileUploadBizEnum) {
- // 文件大小
- long fileSize = multipartFile.getSize();
- // 文件后缀
- String fileSuffix = FileUtil.getSuffix(multipartFile.getOriginalFilename());
- final long ONE_M = 1024 * 1024L;
- if (FileUploadBizEnum.USER_AVATAR.equals(fileUploadBizEnum)) {
- if (fileSize > ONE_M) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件大小不能超过 1M");
- }
- if (!Arrays.asList("jpeg", "jpg", "svg", "png", "webp").contains(fileSuffix)) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件类型错误");
- }
- }
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/controller/PostController.java b/src/main/java/com/yupi/springbootinit/controller/PostController.java
deleted file mode 100644
index 676f173..0000000
--- a/src/main/java/com/yupi/springbootinit/controller/PostController.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package com.yupi.springbootinit.controller;
-
-import cn.hutool.json.JSONUtil;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yupi.springbootinit.annotation.AuthCheck;
-import com.yupi.springbootinit.common.BaseResponse;
-import com.yupi.springbootinit.common.DeleteRequest;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.common.ResultUtils;
-import com.yupi.springbootinit.constant.UserConstant;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.exception.ThrowUtils;
-import com.yupi.springbootinit.model.dto.post.PostAddRequest;
-import com.yupi.springbootinit.model.dto.post.PostEditRequest;
-import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
-import com.yupi.springbootinit.model.dto.post.PostUpdateRequest;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.vo.PostVO;
-import com.yupi.springbootinit.service.PostService;
-import com.yupi.springbootinit.service.UserService;
-import java.util.List;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.BeanUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 帖子接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@RestController
-@RequestMapping("/post")
-@Slf4j
-public class PostController {
-
- @Resource
- private PostService postService;
-
- @Resource
- private UserService userService;
-
- // region 增删改查
-
- /**
- * 创建
- *
- * @param postAddRequest
- * @param request
- * @return
- */
- @PostMapping("/add")
- public BaseResponse addPost(@RequestBody PostAddRequest postAddRequest, HttpServletRequest request) {
- if (postAddRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = new Post();
- BeanUtils.copyProperties(postAddRequest, post);
- List tags = postAddRequest.getTags();
- if (tags != null) {
- post.setTags(JSONUtil.toJsonStr(tags));
- }
- postService.validPost(post, true);
- User loginUser = userService.getLoginUser(request);
- post.setUserId(loginUser.getId());
- post.setFavourNum(0);
- post.setThumbNum(0);
- boolean result = postService.save(post);
- ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
- long newPostId = post.getId();
- return ResultUtils.success(newPostId);
- }
-
- /**
- * 删除
- *
- * @param deleteRequest
- * @param request
- * @return
- */
- @PostMapping("/delete")
- public BaseResponse deletePost(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
- if (deleteRequest == null || deleteRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User user = userService.getLoginUser(request);
- long id = deleteRequest.getId();
- // 判断是否存在
- Post oldPost = postService.getById(id);
- ThrowUtils.throwIf(oldPost == null, ErrorCode.NOT_FOUND_ERROR);
- // 仅本人或管理员可删除
- if (!oldPost.getUserId().equals(user.getId()) && !userService.isAdmin(request)) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- boolean b = postService.removeById(id);
- return ResultUtils.success(b);
- }
-
- /**
- * 更新(仅管理员)
- *
- * @param postUpdateRequest
- * @return
- */
- @PostMapping("/update")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse updatePost(@RequestBody PostUpdateRequest postUpdateRequest) {
- if (postUpdateRequest == null || postUpdateRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = new Post();
- BeanUtils.copyProperties(postUpdateRequest, post);
- List tags = postUpdateRequest.getTags();
- if (tags != null) {
- post.setTags(JSONUtil.toJsonStr(tags));
- }
- // 参数校验
- postService.validPost(post, false);
- long id = postUpdateRequest.getId();
- // 判断是否存在
- Post oldPost = postService.getById(id);
- ThrowUtils.throwIf(oldPost == null, ErrorCode.NOT_FOUND_ERROR);
- boolean result = postService.updateById(post);
- return ResultUtils.success(result);
- }
-
- /**
- * 根据 id 获取
- *
- * @param id
- * @return
- */
- @GetMapping("/get/vo")
- public BaseResponse getPostVOById(long id, HttpServletRequest request) {
- if (id <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = postService.getById(id);
- if (post == null) {
- throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
- }
- return ResultUtils.success(postService.getPostVO(post, request));
- }
-
- /**
- * 分页获取列表(仅管理员)
- *
- * @param postQueryRequest
- * @return
- */
- @PostMapping("/list/page")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse> listPostByPage(@RequestBody PostQueryRequest postQueryRequest) {
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- Page postPage = postService.page(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest));
- return ResultUtils.success(postPage);
- }
-
- /**
- * 分页获取列表(封装类)
- *
- * @param postQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/list/page/vo")
- public BaseResponse> listPostVOByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postService.page(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest));
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- /**
- * 分页获取当前用户创建的资源列表
- *
- * @param postQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/my/list/page/vo")
- public BaseResponse> listMyPostVOByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- if (postQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User loginUser = userService.getLoginUser(request);
- postQueryRequest.setUserId(loginUser.getId());
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postService.page(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest));
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- // endregion
-
- /**
- * 分页搜索(从 ES 查询,封装类)
- *
- * @param postQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/search/page/vo")
- public BaseResponse> searchPostVOByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postService.searchFromEs(postQueryRequest);
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- /**
- * 编辑(用户)
- *
- * @param postEditRequest
- * @param request
- * @return
- */
- @PostMapping("/edit")
- public BaseResponse editPost(@RequestBody PostEditRequest postEditRequest, HttpServletRequest request) {
- if (postEditRequest == null || postEditRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- Post post = new Post();
- BeanUtils.copyProperties(postEditRequest, post);
- List tags = postEditRequest.getTags();
- if (tags != null) {
- post.setTags(JSONUtil.toJsonStr(tags));
- }
- // 参数校验
- postService.validPost(post, false);
- User loginUser = userService.getLoginUser(request);
- long id = postEditRequest.getId();
- // 判断是否存在
- Post oldPost = postService.getById(id);
- ThrowUtils.throwIf(oldPost == null, ErrorCode.NOT_FOUND_ERROR);
- // 仅本人或管理员可编辑
- if (!oldPost.getUserId().equals(loginUser.getId()) && !userService.isAdmin(loginUser)) {
- throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
- }
- boolean result = postService.updateById(post);
- return ResultUtils.success(result);
- }
-
-}
diff --git a/src/main/java/com/yupi/springbootinit/controller/PostFavourController.java b/src/main/java/com/yupi/springbootinit/controller/PostFavourController.java
deleted file mode 100644
index 767d4ef..0000000
--- a/src/main/java/com/yupi/springbootinit/controller/PostFavourController.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.yupi.springbootinit.controller;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yupi.springbootinit.common.BaseResponse;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.common.ResultUtils;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.exception.ThrowUtils;
-import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
-import com.yupi.springbootinit.model.dto.postfavour.PostFavourAddRequest;
-import com.yupi.springbootinit.model.dto.postfavour.PostFavourQueryRequest;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.vo.PostVO;
-import com.yupi.springbootinit.service.PostFavourService;
-import com.yupi.springbootinit.service.PostService;
-import com.yupi.springbootinit.service.UserService;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 帖子收藏接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@RestController
-@RequestMapping("/post_favour")
-@Slf4j
-public class PostFavourController {
-
- @Resource
- private PostFavourService postFavourService;
-
- @Resource
- private PostService postService;
-
- @Resource
- private UserService userService;
-
- /**
- * 收藏 / 取消收藏
- *
- * @param postFavourAddRequest
- * @param request
- * @return resultNum 收藏变化数
- */
- @PostMapping("/")
- public BaseResponse doPostFavour(@RequestBody PostFavourAddRequest postFavourAddRequest,
- HttpServletRequest request) {
- if (postFavourAddRequest == null || postFavourAddRequest.getPostId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- // 登录才能操作
- final User loginUser = userService.getLoginUser(request);
- long postId = postFavourAddRequest.getPostId();
- int result = postFavourService.doPostFavour(postId, loginUser);
- return ResultUtils.success(result);
- }
-
- /**
- * 获取我收藏的帖子列表
- *
- * @param postQueryRequest
- * @param request
- */
- @PostMapping("/my/list/page")
- public BaseResponse> listMyFavourPostByPage(@RequestBody PostQueryRequest postQueryRequest,
- HttpServletRequest request) {
- if (postQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User loginUser = userService.getLoginUser(request);
- long current = postQueryRequest.getCurrent();
- long size = postQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page postPage = postFavourService.listFavourPostByPage(new Page<>(current, size),
- postService.getQueryWrapper(postQueryRequest), loginUser.getId());
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-
- /**
- * 获取用户收藏的帖子列表
- *
- * @param postFavourQueryRequest
- * @param request
- */
- @PostMapping("/list/page")
- public BaseResponse> listFavourPostByPage(@RequestBody PostFavourQueryRequest postFavourQueryRequest,
- HttpServletRequest request) {
- if (postFavourQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- long current = postFavourQueryRequest.getCurrent();
- long size = postFavourQueryRequest.getPageSize();
- Long userId = postFavourQueryRequest.getUserId();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20 || userId == null, ErrorCode.PARAMS_ERROR);
- Page postPage = postFavourService.listFavourPostByPage(new Page<>(current, size),
- postService.getQueryWrapper(postFavourQueryRequest.getPostQueryRequest()), userId);
- return ResultUtils.success(postService.getPostVOPage(postPage, request));
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/controller/PostThumbController.java b/src/main/java/com/yupi/springbootinit/controller/PostThumbController.java
deleted file mode 100644
index faaaa3c..0000000
--- a/src/main/java/com/yupi/springbootinit/controller/PostThumbController.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.yupi.springbootinit.controller;
-
-import com.yupi.springbootinit.common.BaseResponse;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.common.ResultUtils;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.model.dto.postthumb.PostThumbAddRequest;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.service.PostThumbService;
-import com.yupi.springbootinit.service.UserService;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 帖子点赞接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@RestController
-@RequestMapping("/post_thumb")
-@Slf4j
-public class PostThumbController {
-
- @Resource
- private PostThumbService postThumbService;
-
- @Resource
- private UserService userService;
-
- /**
- * 点赞 / 取消点赞
- *
- * @param postThumbAddRequest
- * @param request
- * @return resultNum 本次点赞变化数
- */
- @PostMapping("/")
- public BaseResponse doThumb(@RequestBody PostThumbAddRequest postThumbAddRequest,
- HttpServletRequest request) {
- if (postThumbAddRequest == null || postThumbAddRequest.getPostId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- // 登录才能点赞
- final User loginUser = userService.getLoginUser(request);
- long postId = postThumbAddRequest.getPostId();
- int result = postThumbService.doPostThumb(postId, loginUser);
- return ResultUtils.success(result);
- }
-
-}
diff --git a/src/main/java/com/yupi/springbootinit/controller/UserController.java b/src/main/java/com/yupi/springbootinit/controller/UserController.java
deleted file mode 100644
index 725d60a..0000000
--- a/src/main/java/com/yupi/springbootinit/controller/UserController.java
+++ /dev/null
@@ -1,320 +0,0 @@
-package com.yupi.springbootinit.controller;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yupi.springbootinit.annotation.AuthCheck;
-import com.yupi.springbootinit.common.BaseResponse;
-import com.yupi.springbootinit.common.DeleteRequest;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.common.ResultUtils;
-import com.yupi.springbootinit.config.WxOpenConfig;
-import com.yupi.springbootinit.constant.UserConstant;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.exception.ThrowUtils;
-import com.yupi.springbootinit.model.dto.user.UserAddRequest;
-import com.yupi.springbootinit.model.dto.user.UserLoginRequest;
-import com.yupi.springbootinit.model.dto.user.UserQueryRequest;
-import com.yupi.springbootinit.model.dto.user.UserRegisterRequest;
-import com.yupi.springbootinit.model.dto.user.UserUpdateMyRequest;
-import com.yupi.springbootinit.model.dto.user.UserUpdateRequest;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.vo.LoginUserVO;
-import com.yupi.springbootinit.model.vo.UserVO;
-import com.yupi.springbootinit.service.UserService;
-
-import java.util.List;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
-import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
-import me.chanjar.weixin.mp.api.WxMpService;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.util.DigestUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import static com.yupi.springbootinit.service.impl.UserServiceImpl.SALT;
-
-/**
- * 用户接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@RestController
-@RequestMapping("/user")
-@Slf4j
-public class UserController {
-
- @Resource
- private UserService userService;
-
- @Resource
- private WxOpenConfig wxOpenConfig;
-
- // region 登录相关
-
- /**
- * 用户注册
- *
- * @param userRegisterRequest
- * @return
- */
- @PostMapping("/register")
- public BaseResponse userRegister(@RequestBody UserRegisterRequest userRegisterRequest) {
- if (userRegisterRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- String userAccount = userRegisterRequest.getUserAccount();
- String userPassword = userRegisterRequest.getUserPassword();
- String checkPassword = userRegisterRequest.getCheckPassword();
- if (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword)) {
- return null;
- }
- long result = userService.userRegister(userAccount, userPassword, checkPassword);
- return ResultUtils.success(result);
- }
-
- /**
- * 用户登录
- *
- * @param userLoginRequest
- * @param request
- * @return
- */
- @PostMapping("/login")
- public BaseResponse userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
- if (userLoginRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- String userAccount = userLoginRequest.getUserAccount();
- String userPassword = userLoginRequest.getUserPassword();
- if (StringUtils.isAnyBlank(userAccount, userPassword)) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- LoginUserVO loginUserVO = userService.userLogin(userAccount, userPassword, request);
- return ResultUtils.success(loginUserVO);
- }
-
- /**
- * 用户登录(微信开放平台)
- */
- @GetMapping("/login/wx_open")
- public BaseResponse userLoginByWxOpen(HttpServletRequest request, HttpServletResponse response,
- @RequestParam("code") String code) {
- WxOAuth2AccessToken accessToken;
- try {
- WxMpService wxService = wxOpenConfig.getWxMpService();
- accessToken = wxService.getOAuth2Service().getAccessToken(code);
- WxOAuth2UserInfo userInfo = wxService.getOAuth2Service().getUserInfo(accessToken, code);
- String unionId = userInfo.getUnionId();
- String mpOpenId = userInfo.getOpenid();
- if (StringUtils.isAnyBlank(unionId, mpOpenId)) {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败,系统错误");
- }
- return ResultUtils.success(userService.userLoginByMpOpen(userInfo, request));
- } catch (Exception e) {
- log.error("userLoginByWxOpen error", e);
- throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败,系统错误");
- }
- }
-
- /**
- * 用户注销
- *
- * @param request
- * @return
- */
- @PostMapping("/logout")
- public BaseResponse userLogout(HttpServletRequest request) {
- if (request == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- boolean result = userService.userLogout(request);
- return ResultUtils.success(result);
- }
-
- /**
- * 获取当前登录用户
- *
- * @param request
- * @return
- */
- @GetMapping("/get/login")
- public BaseResponse getLoginUser(HttpServletRequest request) {
- User user = userService.getLoginUser(request);
- return ResultUtils.success(userService.getLoginUserVO(user));
- }
-
- // endregion
-
- // region 增删改查
-
- /**
- * 创建用户
- *
- * @param userAddRequest
- * @param request
- * @return
- */
- @PostMapping("/add")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse addUser(@RequestBody UserAddRequest userAddRequest, HttpServletRequest request) {
- if (userAddRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User user = new User();
- BeanUtils.copyProperties(userAddRequest, user);
- // 默认密码 12345678
- String defaultPassword = "12345678";
- String encryptPassword = DigestUtils.md5DigestAsHex((SALT + defaultPassword).getBytes());
- user.setUserPassword(encryptPassword);
- boolean result = userService.save(user);
- ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
- return ResultUtils.success(user.getId());
- }
-
- /**
- * 删除用户
- *
- * @param deleteRequest
- * @param request
- * @return
- */
- @PostMapping("/delete")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse deleteUser(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
- if (deleteRequest == null || deleteRequest.getId() <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- boolean b = userService.removeById(deleteRequest.getId());
- return ResultUtils.success(b);
- }
-
- /**
- * 更新用户
- *
- * @param userUpdateRequest
- * @param request
- * @return
- */
- @PostMapping("/update")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse updateUser(@RequestBody UserUpdateRequest userUpdateRequest,
- HttpServletRequest request) {
- if (userUpdateRequest == null || userUpdateRequest.getId() == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User user = new User();
- BeanUtils.copyProperties(userUpdateRequest, user);
- boolean result = userService.updateById(user);
- ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
- return ResultUtils.success(true);
- }
-
- /**
- * 根据 id 获取用户(仅管理员)
- *
- * @param id
- * @param request
- * @return
- */
- @GetMapping("/get")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse getUserById(long id, HttpServletRequest request) {
- if (id <= 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User user = userService.getById(id);
- ThrowUtils.throwIf(user == null, ErrorCode.NOT_FOUND_ERROR);
- return ResultUtils.success(user);
- }
-
- /**
- * 根据 id 获取包装类
- *
- * @param id
- * @param request
- * @return
- */
- @GetMapping("/get/vo")
- public BaseResponse getUserVOById(long id, HttpServletRequest request) {
- BaseResponse response = getUserById(id, request);
- User user = response.getData();
- return ResultUtils.success(userService.getUserVO(user));
- }
-
- /**
- * 分页获取用户列表(仅管理员)
- *
- * @param userQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/list/page")
- @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
- public BaseResponse> listUserByPage(@RequestBody UserQueryRequest userQueryRequest,
- HttpServletRequest request) {
- long current = userQueryRequest.getCurrent();
- long size = userQueryRequest.getPageSize();
- Page userPage = userService.page(new Page<>(current, size),
- userService.getQueryWrapper(userQueryRequest));
- return ResultUtils.success(userPage);
- }
-
- /**
- * 分页获取用户封装列表
- *
- * @param userQueryRequest
- * @param request
- * @return
- */
- @PostMapping("/list/page/vo")
- public BaseResponse> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest,
- HttpServletRequest request) {
- if (userQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- long current = userQueryRequest.getCurrent();
- long size = userQueryRequest.getPageSize();
- // 限制爬虫
- ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
- Page userPage = userService.page(new Page<>(current, size),
- userService.getQueryWrapper(userQueryRequest));
- Page userVOPage = new Page<>(current, size, userPage.getTotal());
- List userVO = userService.getUserVO(userPage.getRecords());
- userVOPage.setRecords(userVO);
- return ResultUtils.success(userVOPage);
- }
-
- // endregion
-
- /**
- * 更新个人信息
- *
- * @param userUpdateMyRequest
- * @param request
- * @return
- */
- @PostMapping("/update/my")
- public BaseResponse updateMyUser(@RequestBody UserUpdateMyRequest userUpdateMyRequest,
- HttpServletRequest request) {
- if (userUpdateMyRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- User loginUser = userService.getLoginUser(request);
- User user = new User();
- BeanUtils.copyProperties(userUpdateMyRequest, user);
- user.setId(loginUser.getId());
- boolean result = userService.updateById(user);
- ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
- return ResultUtils.success(true);
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/controller/WxMpController.java b/src/main/java/com/yupi/springbootinit/controller/WxMpController.java
deleted file mode 100644
index 7843df0..0000000
--- a/src/main/java/com/yupi/springbootinit/controller/WxMpController.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package com.yupi.springbootinit.controller;
-
-import com.yupi.springbootinit.wxmp.WxMpConstant;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.api.WxConsts.MenuButtonType;
-import me.chanjar.weixin.common.bean.menu.WxMenu;
-import me.chanjar.weixin.common.bean.menu.WxMenuButton;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.mp.api.WxMpMessageRouter;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 微信公众号相关接口
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-@RestController
-@RequestMapping("/")
-@Slf4j
-public class WxMpController {
-
- @Resource
- private WxMpService wxMpService;
-
- @Resource
- private WxMpMessageRouter router;
-
- @PostMapping("/")
- public void receiveMessage(HttpServletRequest request, HttpServletResponse response)
- throws IOException {
- response.setContentType("text/html;charset=utf-8");
- response.setStatus(HttpServletResponse.SC_OK);
- // 校验消息签名,判断是否为公众平台发的消息
- String signature = request.getParameter("signature");
- String nonce = request.getParameter("nonce");
- String timestamp = request.getParameter("timestamp");
- if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
- response.getWriter().println("非法请求");
- }
- // 加密类型
- String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ? "raw"
- : request.getParameter("encrypt_type");
- // 明文消息
- if ("raw".equals(encryptType)) {
- return;
- }
- // aes 加密消息
- if ("aes".equals(encryptType)) {
- // 解密消息
- String msgSignature = request.getParameter("msg_signature");
- WxMpXmlMessage inMessage = WxMpXmlMessage
- .fromEncryptedXml(request.getInputStream(), wxMpService.getWxMpConfigStorage(), timestamp,
- nonce,
- msgSignature);
- log.info("message content = {}", inMessage.getContent());
- // 路由消息并处理
- WxMpXmlOutMessage outMessage = router.route(inMessage);
- if (outMessage == null) {
- response.getWriter().write("");
- } else {
- response.getWriter().write(outMessage.toEncryptedXml(wxMpService.getWxMpConfigStorage()));
- }
- return;
- }
- response.getWriter().println("不可识别的加密类型");
- }
-
- @GetMapping("/")
- public String check(String timestamp, String nonce, String signature, String echostr) {
- log.info("check");
- if (wxMpService.checkSignature(timestamp, nonce, signature)) {
- return echostr;
- } else {
- return "";
- }
- }
-
- /**
- * 设置公众号菜单
- *
- * @return
- * @throws WxErrorException
- */
- @GetMapping("/setMenu")
- public String setMenu() throws WxErrorException {
- log.info("setMenu");
- WxMenu wxMenu = new WxMenu();
- // 菜单一
- WxMenuButton wxMenuButton1 = new WxMenuButton();
- wxMenuButton1.setType(MenuButtonType.VIEW);
- wxMenuButton1.setName("主菜单一");
- // 子菜单
- WxMenuButton wxMenuButton1SubButton1 = new WxMenuButton();
- wxMenuButton1SubButton1.setType(MenuButtonType.VIEW);
- wxMenuButton1SubButton1.setName("跳转页面");
- wxMenuButton1SubButton1.setUrl(
- "https://yupi.icu");
- wxMenuButton1.setSubButtons(Collections.singletonList(wxMenuButton1SubButton1));
-
- // 菜单二
- WxMenuButton wxMenuButton2 = new WxMenuButton();
- wxMenuButton2.setType(MenuButtonType.CLICK);
- wxMenuButton2.setName("点击事件");
- wxMenuButton2.setKey(WxMpConstant.CLICK_MENU_KEY);
-
- // 菜单三
- WxMenuButton wxMenuButton3 = new WxMenuButton();
- wxMenuButton3.setType(MenuButtonType.VIEW);
- wxMenuButton3.setName("主菜单三");
- WxMenuButton wxMenuButton3SubButton1 = new WxMenuButton();
- wxMenuButton3SubButton1.setType(MenuButtonType.VIEW);
- wxMenuButton3SubButton1.setName("编程学习");
- wxMenuButton3SubButton1.setUrl("https://yupi.icu");
- wxMenuButton3.setSubButtons(Collections.singletonList(wxMenuButton3SubButton1));
-
- // 设置主菜单
- wxMenu.setButtons(Arrays.asList(wxMenuButton1, wxMenuButton2, wxMenuButton3));
- wxMpService.getMenuService().menuCreate(wxMenu);
- return "ok";
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/esdao/PostEsDao.java b/src/main/java/com/yupi/springbootinit/esdao/PostEsDao.java
deleted file mode 100644
index 8565f53..0000000
--- a/src/main/java/com/yupi/springbootinit/esdao/PostEsDao.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.yupi.springbootinit.esdao;
-
-import com.yupi.springbootinit.model.dto.post.PostEsDTO;
-import java.util.List;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-/**
- * 帖子 ES 操作
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostEsDao extends ElasticsearchRepository {
-
- List findByUserId(Long userId);
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/job/cycle/IncSyncPostToEs.java b/src/main/java/com/yupi/springbootinit/job/cycle/IncSyncPostToEs.java
deleted file mode 100644
index 9a24326..0000000
--- a/src/main/java/com/yupi/springbootinit/job/cycle/IncSyncPostToEs.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.yupi.springbootinit.job.cycle;
-
-import com.yupi.springbootinit.esdao.PostEsDao;
-import com.yupi.springbootinit.mapper.PostMapper;
-import com.yupi.springbootinit.model.dto.post.PostEsDTO;
-import com.yupi.springbootinit.model.entity.Post;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Resource;
-import lombok.extern.slf4j.Slf4j;
-import cn.hutool.core.collection.CollUtil;
-import org.springframework.scheduling.annotation.Scheduled;
-
-/**
- * 增量同步帖子到 es
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-// todo 取消注释开启任务
-//@Component
-@Slf4j
-public class IncSyncPostToEs {
-
- @Resource
- private PostMapper postMapper;
-
- @Resource
- private PostEsDao postEsDao;
-
- /**
- * 每分钟执行一次
- */
- @Scheduled(fixedRate = 60 * 1000)
- public void run() {
- // 查询近 5 分钟内的数据
- Date fiveMinutesAgoDate = new Date(new Date().getTime() - 5 * 60 * 1000L);
- List postList = postMapper.listPostWithDelete(fiveMinutesAgoDate);
- if (CollUtil.isEmpty(postList)) {
- log.info("no inc post");
- return;
- }
- List postEsDTOList = postList.stream()
- .map(PostEsDTO::objToDto)
- .collect(Collectors.toList());
- final int pageSize = 500;
- int total = postEsDTOList.size();
- log.info("IncSyncPostToEs start, total {}", total);
- for (int i = 0; i < total; i += pageSize) {
- int end = Math.min(i + pageSize, total);
- log.info("sync from {} to {}", i, end);
- postEsDao.saveAll(postEsDTOList.subList(i, end));
- }
- log.info("IncSyncPostToEs end, total {}", total);
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/job/once/FullSyncPostToEs.java b/src/main/java/com/yupi/springbootinit/job/once/FullSyncPostToEs.java
deleted file mode 100644
index e7b8793..0000000
--- a/src/main/java/com/yupi/springbootinit/job/once/FullSyncPostToEs.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.yupi.springbootinit.job.once;
-
-import com.yupi.springbootinit.esdao.PostEsDao;
-import com.yupi.springbootinit.model.dto.post.PostEsDTO;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.service.PostService;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.annotation.Resource;
-import lombok.extern.slf4j.Slf4j;
-import cn.hutool.core.collection.CollUtil;
-import org.springframework.boot.CommandLineRunner;
-
-/**
- * 全量同步帖子到 es
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-// todo 取消注释开启任务
-//@Component
-@Slf4j
-public class FullSyncPostToEs implements CommandLineRunner {
-
- @Resource
- private PostService postService;
-
- @Resource
- private PostEsDao postEsDao;
-
- @Override
- public void run(String... args) {
- List postList = postService.list();
- if (CollUtil.isEmpty(postList)) {
- return;
- }
- List postEsDTOList = postList.stream().map(PostEsDTO::objToDto).collect(Collectors.toList());
- final int pageSize = 500;
- int total = postEsDTOList.size();
- log.info("FullSyncPostToEs start, total {}", total);
- for (int i = 0; i < total; i += pageSize) {
- int end = Math.min(i + pageSize, total);
- log.info("sync from {} to {}", i, end);
- postEsDao.saveAll(postEsDTOList.subList(i, end));
- }
- log.info("FullSyncPostToEs end, total {}", total);
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/manager/CosManager.java b/src/main/java/com/yupi/springbootinit/manager/CosManager.java
deleted file mode 100644
index a556cc2..0000000
--- a/src/main/java/com/yupi/springbootinit/manager/CosManager.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.yupi.springbootinit.manager;
-
-import com.qcloud.cos.COSClient;
-import com.qcloud.cos.model.PutObjectRequest;
-import com.qcloud.cos.model.PutObjectResult;
-import com.yupi.springbootinit.config.CosClientConfig;
-import java.io.File;
-import javax.annotation.Resource;
-import org.springframework.stereotype.Component;
-
-/**
- * Cos 对象存储操作
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Component
-public class CosManager {
-
- @Resource
- private CosClientConfig cosClientConfig;
-
- @Resource
- private COSClient cosClient;
-
- /**
- * 上传对象
- *
- * @param key 唯一键
- * @param localFilePath 本地文件路径
- * @return
- */
- public PutObjectResult putObject(String key, String localFilePath) {
- PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key,
- new File(localFilePath));
- return cosClient.putObject(putObjectRequest);
- }
-
- /**
- * 上传对象
- *
- * @param key 唯一键
- * @param file 文件
- * @return
- */
- public PutObjectResult putObject(String key, File file) {
- PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key,
- file);
- return cosClient.putObject(putObjectRequest);
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/mapper/PostFavourMapper.java b/src/main/java/com/yupi/springbootinit/mapper/PostFavourMapper.java
deleted file mode 100644
index c57cf5e..0000000
--- a/src/main/java/com/yupi/springbootinit/mapper/PostFavourMapper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.yupi.springbootinit.mapper;
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.PostFavour;
-import org.apache.ibatis.annotations.Param;
-
-/**
- * 帖子收藏数据库操作
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostFavourMapper extends BaseMapper {
-
- /**
- * 分页查询收藏帖子列表
- *
- * @param page
- * @param queryWrapper
- * @param favourUserId
- * @return
- */
- Page listFavourPostByPage(IPage page, @Param(Constants.WRAPPER) Wrapper queryWrapper,
- long favourUserId);
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/mapper/PostMapper.java b/src/main/java/com/yupi/springbootinit/mapper/PostMapper.java
deleted file mode 100644
index 2975b84..0000000
--- a/src/main/java/com/yupi/springbootinit/mapper/PostMapper.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.yupi.springbootinit.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.yupi.springbootinit.model.entity.Post;
-import java.util.Date;
-import java.util.List;
-
-/**
- * 帖子数据库操作
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostMapper extends BaseMapper {
-
- /**
- * 查询帖子列表(包括已被删除的数据)
- */
- List listPostWithDelete(Date minUpdateTime);
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/mapper/PostThumbMapper.java b/src/main/java/com/yupi/springbootinit/mapper/PostThumbMapper.java
deleted file mode 100644
index fe39c82..0000000
--- a/src/main/java/com/yupi/springbootinit/mapper/PostThumbMapper.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.yupi.springbootinit.mapper;
-
-import com.yupi.springbootinit.model.entity.PostThumb;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-
-/**
- * 帖子点赞数据库操作
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostThumbMapper extends BaseMapper {
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/mapper/UserMapper.java b/src/main/java/com/yupi/springbootinit/mapper/UserMapper.java
deleted file mode 100644
index 001b7e2..0000000
--- a/src/main/java/com/yupi/springbootinit/mapper/UserMapper.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.yupi.springbootinit.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.yupi.springbootinit.model.entity.User;
-
-/**
- * 用户数据库操作
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface UserMapper extends BaseMapper {
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/file/UploadFileRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/file/UploadFileRequest.java
deleted file mode 100644
index 09654ec..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/file/UploadFileRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.yupi.springbootinit.model.dto.file;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 文件上传请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UploadFileRequest implements Serializable {
-
- /**
- * 业务
- */
- private String biz;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/post/PostAddRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/post/PostAddRequest.java
deleted file mode 100644
index 45ac49c..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/post/PostAddRequest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.yupi.springbootinit.model.dto.post;
-
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-
-/**
- * 创建请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class PostAddRequest implements Serializable {
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/post/PostEditRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/post/PostEditRequest.java
deleted file mode 100644
index 40c3888..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/post/PostEditRequest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.yupi.springbootinit.model.dto.post;
-
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-
-/**
- * 编辑请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class PostEditRequest implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/post/PostEsDTO.java b/src/main/java/com/yupi/springbootinit/model/dto/post/PostEsDTO.java
deleted file mode 100644
index aa7ae46..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/post/PostEsDTO.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package com.yupi.springbootinit.model.dto.post;
-
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.json.JSONUtil;
-import com.yupi.springbootinit.model.entity.Post;
-import lombok.Data;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.data.annotation.Id;
-import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.annotations.FieldType;
-
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-/**
- * 帖子 ES 包装类
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-// todo 取消注释开启 ES(须先配置 ES)
-//@Document(indexName = "post")
-@Data
-public class PostEsDTO implements Serializable {
-
- private static final String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
-
- /**
- * id
- */
- @Id
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- /**
- * 点赞数
- */
- private Integer thumbNum;
-
- /**
- * 收藏数
- */
- private Integer favourNum;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN)
- private Date createTime;
-
- /**
- * 更新时间
- */
- @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN)
- private Date updateTime;
-
- /**
- * 是否删除
- */
- private Integer isDelete;
-
- private static final long serialVersionUID = 1L;
-
- /**
- * 对象转包装类
- *
- * @param post
- * @return
- */
- public static PostEsDTO objToDto(Post post) {
- if (post == null) {
- return null;
- }
- PostEsDTO postEsDTO = new PostEsDTO();
- BeanUtils.copyProperties(post, postEsDTO);
- String tagsStr = post.getTags();
- if (StringUtils.isNotBlank(tagsStr)) {
- postEsDTO.setTags(JSONUtil.toList(tagsStr, String.class));
- }
- return postEsDTO;
- }
-
- /**
- * 包装类转对象
- *
- * @param postEsDTO
- * @return
- */
- public static Post dtoToObj(PostEsDTO postEsDTO) {
- if (postEsDTO == null) {
- return null;
- }
- Post post = new Post();
- BeanUtils.copyProperties(postEsDTO, post);
- List tagList = postEsDTO.getTags();
- if (CollUtil.isNotEmpty(tagList)) {
- post.setTags(JSONUtil.toJsonStr(tagList));
- }
- return post;
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/post/PostQueryRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/post/PostQueryRequest.java
deleted file mode 100644
index c9f160a..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/post/PostQueryRequest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.yupi.springbootinit.model.dto.post;
-
-import com.yupi.springbootinit.common.PageRequest;
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 查询请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@EqualsAndHashCode(callSuper = true)
-@Data
-public class PostQueryRequest extends PageRequest implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * id
- */
- private Long notId;
-
- /**
- * 搜索词
- */
- private String searchText;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- /**
- * 至少有一个标签
- */
- private List orTags;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 收藏用户 id
- */
- private Long favourUserId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/post/PostUpdateRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/post/PostUpdateRequest.java
deleted file mode 100644
index c90bc70..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/post/PostUpdateRequest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.yupi.springbootinit.model.dto.post;
-
-import java.io.Serializable;
-import java.util.List;
-import lombok.Data;
-
-/**
- * 更新请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class PostUpdateRequest implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表
- */
- private List tags;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/postfavour/PostFavourAddRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/postfavour/PostFavourAddRequest.java
deleted file mode 100644
index 1b8cc27..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/postfavour/PostFavourAddRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.yupi.springbootinit.model.dto.postfavour;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 帖子收藏 / 取消收藏请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class PostFavourAddRequest implements Serializable {
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/postfavour/PostFavourQueryRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/postfavour/PostFavourQueryRequest.java
deleted file mode 100644
index e8bf989..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/postfavour/PostFavourQueryRequest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.yupi.springbootinit.model.dto.postfavour;
-
-import com.yupi.springbootinit.common.PageRequest;
-import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
-import java.io.Serializable;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 帖子收藏查询请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class PostFavourQueryRequest extends PageRequest implements Serializable {
-
- /**
- * 帖子查询请求
- */
- private PostQueryRequest postQueryRequest;
-
- /**
- * 用户 id
- */
- private Long userId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/postthumb/PostThumbAddRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/postthumb/PostThumbAddRequest.java
deleted file mode 100644
index e6209e7..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/postthumb/PostThumbAddRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.yupi.springbootinit.model.dto.postthumb;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 帖子点赞请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class PostThumbAddRequest implements Serializable {
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/user/UserAddRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/user/UserAddRequest.java
deleted file mode 100644
index 7c56337..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/user/UserAddRequest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.yupi.springbootinit.model.dto.user;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 用户创建请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UserAddRequest implements Serializable {
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 账号
- */
- private String userAccount;
-
- /**
- * 用户头像
- */
- private String userAvatar;
-
- /**
- * 用户角色: user, admin
- */
- private String userRole;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/user/UserLoginRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/user/UserLoginRequest.java
deleted file mode 100644
index 85c241e..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/user/UserLoginRequest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.yupi.springbootinit.model.dto.user;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 用户登录请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UserLoginRequest implements Serializable {
-
- private static final long serialVersionUID = 3191241716373120793L;
-
- private String userAccount;
-
- private String userPassword;
-}
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/user/UserQueryRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/user/UserQueryRequest.java
deleted file mode 100644
index 7b0e3d4..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/user/UserQueryRequest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.yupi.springbootinit.model.dto.user;
-
-import com.yupi.springbootinit.common.PageRequest;
-import java.io.Serializable;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 用户查询请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@EqualsAndHashCode(callSuper = true)
-@Data
-public class UserQueryRequest extends PageRequest implements Serializable {
- /**
- * id
- */
- private Long id;
-
- /**
- * 开放平台id
- */
- private String unionId;
-
- /**
- * 公众号openId
- */
- private String mpOpenId;
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 简介
- */
- private String userProfile;
-
- /**
- * 用户角色:user/admin/ban
- */
- private String userRole;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/user/UserRegisterRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/user/UserRegisterRequest.java
deleted file mode 100644
index ded70ed..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/user/UserRegisterRequest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.yupi.springbootinit.model.dto.user;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 用户注册请求体
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UserRegisterRequest implements Serializable {
-
- private static final long serialVersionUID = 3191241716373120793L;
-
- private String userAccount;
-
- private String userPassword;
-
- private String checkPassword;
-}
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateMyRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateMyRequest.java
deleted file mode 100644
index f07f55a..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateMyRequest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.yupi.springbootinit.model.dto.user;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 用户更新个人信息请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UserUpdateMyRequest implements Serializable {
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 用户头像
- */
- private String userAvatar;
-
- /**
- * 简介
- */
- private String userProfile;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateRequest.java b/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateRequest.java
deleted file mode 100644
index 6536de5..0000000
--- a/src/main/java/com/yupi/springbootinit/model/dto/user/UserUpdateRequest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.yupi.springbootinit.model.dto.user;
-
-import java.io.Serializable;
-import lombok.Data;
-
-/**
- * 用户更新请求
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UserUpdateRequest implements Serializable {
- /**
- * id
- */
- private Long id;
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 用户头像
- */
- private String userAvatar;
-
- /**
- * 简介
- */
- private String userProfile;
-
- /**
- * 用户角色:user/admin/ban
- */
- private String userRole;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/entity/Post.java b/src/main/java/com/yupi/springbootinit/model/entity/Post.java
deleted file mode 100644
index 3c0e301..0000000
--- a/src/main/java/com/yupi/springbootinit/model/entity/Post.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.yupi.springbootinit.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 帖子
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@TableName(value = "post")
-@Data
-public class Post implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.ASSIGN_ID)
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 标签列表 json
- */
- private String tags;
-
- /**
- * 点赞数
- */
- private Integer thumbNum;
-
- /**
- * 收藏数
- */
- private Integer favourNum;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- /**
- * 是否删除
- */
- @TableLogic
- private Integer isDelete;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/entity/PostFavour.java b/src/main/java/com/yupi/springbootinit/model/entity/PostFavour.java
deleted file mode 100644
index 7626ec5..0000000
--- a/src/main/java/com/yupi/springbootinit/model/entity/PostFavour.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.yupi.springbootinit.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 帖子收藏
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-@TableName(value = "post_favour")
-@Data
-public class PostFavour implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.AUTO)
- private Long id;
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/entity/PostThumb.java b/src/main/java/com/yupi/springbootinit/model/entity/PostThumb.java
deleted file mode 100644
index c22f119..0000000
--- a/src/main/java/com/yupi/springbootinit/model/entity/PostThumb.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.yupi.springbootinit.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 帖子点赞
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@TableName(value = "post_thumb")
-@Data
-public class PostThumb implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.AUTO)
- private Long id;
-
- /**
- * 帖子 id
- */
- private Long postId;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/entity/User.java b/src/main/java/com/yupi/springbootinit/model/entity/User.java
deleted file mode 100644
index b128c5b..0000000
--- a/src/main/java/com/yupi/springbootinit/model/entity/User.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.yupi.springbootinit.model.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 用户
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@TableName(value = "user")
-@Data
-public class User implements Serializable {
-
- /**
- * id
- */
- @TableId(type = IdType.ASSIGN_ID)
- private Long id;
-
- /**
- * 用户账号
- */
- private String userAccount;
-
- /**
- * 用户密码
- */
- private String userPassword;
-
- /**
- * 开放平台id
- */
- private String unionId;
-
- /**
- * 公众号openId
- */
- private String mpOpenId;
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 用户头像
- */
- private String userAvatar;
-
- /**
- * 用户简介
- */
- private String userProfile;
-
- /**
- * 用户角色:user/admin/ban
- */
- private String userRole;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- /**
- * 是否删除
- */
- @TableLogic
- private Integer isDelete;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/vo/LoginUserVO.java b/src/main/java/com/yupi/springbootinit/model/vo/LoginUserVO.java
deleted file mode 100644
index 47ebf8f..0000000
--- a/src/main/java/com/yupi/springbootinit/model/vo/LoginUserVO.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.yupi.springbootinit.model.vo;
-
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 已登录用户视图(脱敏)
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-@Data
-public class LoginUserVO implements Serializable {
-
- /**
- * 用户 id
- */
- private Long id;
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 用户头像
- */
- private String userAvatar;
-
- /**
- * 用户简介
- */
- private String userProfile;
-
- /**
- * 用户角色:user/admin/ban
- */
- private String userRole;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/model/vo/PostVO.java b/src/main/java/com/yupi/springbootinit/model/vo/PostVO.java
deleted file mode 100644
index 92aa7fd..0000000
--- a/src/main/java/com/yupi/springbootinit/model/vo/PostVO.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package com.yupi.springbootinit.model.vo;
-
-import cn.hutool.json.JSONUtil;
-import com.yupi.springbootinit.model.entity.Post;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-import lombok.Data;
-import org.springframework.beans.BeanUtils;
-
-/**
- * 帖子视图
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class PostVO implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 标题
- */
- private String title;
-
- /**
- * 内容
- */
- private String content;
-
- /**
- * 点赞数
- */
- private Integer thumbNum;
-
- /**
- * 收藏数
- */
- private Integer favourNum;
-
- /**
- * 创建用户 id
- */
- private Long userId;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- /**
- * 更新时间
- */
- private Date updateTime;
-
- /**
- * 标签列表
- */
- private List tagList;
-
- /**
- * 创建人信息
- */
- private UserVO user;
-
- /**
- * 是否已点赞
- */
- private Boolean hasThumb;
-
- /**
- * 是否已收藏
- */
- private Boolean hasFavour;
-
- /**
- * 包装类转对象
- *
- * @param postVO
- * @return
- */
- public static Post voToObj(PostVO postVO) {
- if (postVO == null) {
- return null;
- }
- Post post = new Post();
- BeanUtils.copyProperties(postVO, post);
- List tagList = postVO.getTagList();
- post.setTags(JSONUtil.toJsonStr(tagList));
- return post;
- }
-
- /**
- * 对象转包装类
- *
- * @param post
- * @return
- */
- public static PostVO objToVo(Post post) {
- if (post == null) {
- return null;
- }
- PostVO postVO = new PostVO();
- BeanUtils.copyProperties(post, postVO);
- postVO.setTagList(JSONUtil.toList(post.getTags(), String.class));
- return postVO;
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/model/vo/UserVO.java b/src/main/java/com/yupi/springbootinit/model/vo/UserVO.java
deleted file mode 100644
index 536b1f4..0000000
--- a/src/main/java/com/yupi/springbootinit/model/vo/UserVO.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.yupi.springbootinit.model.vo;
-
-import java.io.Serializable;
-import java.util.Date;
-import lombok.Data;
-
-/**
- * 用户视图(脱敏)
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Data
-public class UserVO implements Serializable {
-
- /**
- * id
- */
- private Long id;
-
- /**
- * 用户昵称
- */
- private String userName;
-
- /**
- * 用户头像
- */
- private String userAvatar;
-
- /**
- * 用户简介
- */
- private String userProfile;
-
- /**
- * 用户角色:user/admin/ban
- */
- private String userRole;
-
- /**
- * 创建时间
- */
- private Date createTime;
-
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
diff --git a/src/main/java/com/yupi/springbootinit/service/PostFavourService.java b/src/main/java/com/yupi/springbootinit/service/PostFavourService.java
deleted file mode 100644
index 1e29151..0000000
--- a/src/main/java/com/yupi/springbootinit/service/PostFavourService.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.PostFavour;
-import com.yupi.springbootinit.model.entity.User;
-
-/**
- * 帖子收藏服务
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostFavourService extends IService {
-
- /**
- * 帖子收藏
- *
- * @param postId
- * @param loginUser
- * @return
- */
- int doPostFavour(long postId, User loginUser);
-
- /**
- * 分页获取用户收藏的帖子列表
- *
- * @param page
- * @param queryWrapper
- * @param favourUserId
- * @return
- */
- Page listFavourPostByPage(IPage page, Wrapper queryWrapper,
- long favourUserId);
-
- /**
- * 帖子收藏(内部服务)
- *
- * @param userId
- * @param postId
- * @return
- */
- int doPostFavourInner(long userId, long postId);
-}
diff --git a/src/main/java/com/yupi/springbootinit/service/PostService.java b/src/main/java/com/yupi/springbootinit/service/PostService.java
deleted file mode 100644
index d938f0b..0000000
--- a/src/main/java/com/yupi/springbootinit/service/PostService.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.vo.PostVO;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * 帖子服务
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostService extends IService {
-
- /**
- * 校验
- *
- * @param post
- * @param add
- */
- void validPost(Post post, boolean add);
-
- /**
- * 获取查询条件
- *
- * @param postQueryRequest
- * @return
- */
- QueryWrapper getQueryWrapper(PostQueryRequest postQueryRequest);
-
- /**
- * 从 ES 查询
- *
- * @param postQueryRequest
- * @return
- */
- Page searchFromEs(PostQueryRequest postQueryRequest);
-
- /**
- * 获取帖子封装
- *
- * @param post
- * @param request
- * @return
- */
- PostVO getPostVO(Post post, HttpServletRequest request);
-
- /**
- * 分页获取帖子封装
- *
- * @param postPage
- * @param request
- * @return
- */
- Page getPostVOPage(Page postPage, HttpServletRequest request);
-}
diff --git a/src/main/java/com/yupi/springbootinit/service/PostThumbService.java b/src/main/java/com/yupi/springbootinit/service/PostThumbService.java
deleted file mode 100644
index db731f9..0000000
--- a/src/main/java/com/yupi/springbootinit/service/PostThumbService.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import com.yupi.springbootinit.model.entity.PostThumb;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.yupi.springbootinit.model.entity.User;
-
-/**
- * 帖子点赞服务
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface PostThumbService extends IService {
-
- /**
- * 点赞
- *
- * @param postId
- * @param loginUser
- * @return
- */
- int doPostThumb(long postId, User loginUser);
-
- /**
- * 帖子点赞(内部服务)
- *
- * @param userId
- * @param postId
- * @return
- */
- int doPostThumbInner(long userId, long postId);
-}
diff --git a/src/main/java/com/yupi/springbootinit/service/UserService.java b/src/main/java/com/yupi/springbootinit/service/UserService.java
deleted file mode 100644
index 0f83cf7..0000000
--- a/src/main/java/com/yupi/springbootinit/service/UserService.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.yupi.springbootinit.model.dto.user.UserQueryRequest;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.vo.LoginUserVO;
-import com.yupi.springbootinit.model.vo.UserVO;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
-
-/**
- * 用户服务
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-public interface UserService extends IService {
-
- /**
- * 用户注册
- *
- * @param userAccount 用户账户
- * @param userPassword 用户密码
- * @param checkPassword 校验密码
- * @return 新用户 id
- */
- long userRegister(String userAccount, String userPassword, String checkPassword);
-
- /**
- * 用户登录
- *
- * @param userAccount 用户账户
- * @param userPassword 用户密码
- * @param request
- * @return 脱敏后的用户信息
- */
- LoginUserVO userLogin(String userAccount, String userPassword, HttpServletRequest request);
-
- /**
- * 用户登录(微信开放平台)
- *
- * @param wxOAuth2UserInfo 从微信获取的用户信息
- * @param request
- * @return 脱敏后的用户信息
- */
- LoginUserVO userLoginByMpOpen(WxOAuth2UserInfo wxOAuth2UserInfo, HttpServletRequest request);
-
- /**
- * 获取当前登录用户
- *
- * @param request
- * @return
- */
- User getLoginUser(HttpServletRequest request);
-
- /**
- * 获取当前登录用户(允许未登录)
- *
- * @param request
- * @return
- */
- User getLoginUserPermitNull(HttpServletRequest request);
-
- /**
- * 是否为管理员
- *
- * @param request
- * @return
- */
- boolean isAdmin(HttpServletRequest request);
-
- /**
- * 是否为管理员
- *
- * @param user
- * @return
- */
- boolean isAdmin(User user);
-
- /**
- * 用户注销
- *
- * @param request
- * @return
- */
- boolean userLogout(HttpServletRequest request);
-
- /**
- * 获取脱敏的已登录用户信息
- *
- * @return
- */
- LoginUserVO getLoginUserVO(User user);
-
- /**
- * 获取脱敏的用户信息
- *
- * @param user
- * @return
- */
- UserVO getUserVO(User user);
-
- /**
- * 获取脱敏的用户信息
- *
- * @param userList
- * @return
- */
- List getUserVO(List userList);
-
- /**
- * 获取查询条件
- *
- * @param userQueryRequest
- * @return
- */
- QueryWrapper getQueryWrapper(UserQueryRequest userQueryRequest);
-
-}
diff --git a/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java
index 3dfeae4..a9f4c38 100644
--- a/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java
+++ b/src/main/java/com/yupi/springbootinit/service/impl/HostInfoServiceImpl.java
@@ -13,6 +13,7 @@ import org.springframework.util.StopWatch;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/*
@@ -27,7 +28,6 @@ public class HostInfoServiceImpl extends ServiceImpl i
@Override
@Async("taskExecutor")
-
public CompletableFuture saveHostInfo(List newHosts) {
try {
StopWatch stopWatch = new StopWatch();
@@ -35,11 +35,11 @@ public class HostInfoServiceImpl extends ServiceImpl i
saveBatch(newHosts);
stopWatch.stop();
long totalTimeMillis = stopWatch.getTotalTimeMillis();
- log.info(" 存储花费: {}ms", totalTimeMillis);
+ log.info("存储花费: {}ms", totalTimeMillis);
return CompletableFuture.completedFuture(null);
} catch (Exception e) {
// 将异常包装到Future,使调用方能处理
- return CompletableFuture.failedFuture(e); // Java9+
+ return CompletableFuture.failedFuture(e);
}
}
@@ -64,6 +64,7 @@ public class HostInfoServiceImpl extends ServiceImpl i
List> futures = new ArrayList<>();
// 分片提交(避免单批次过大)
Lists.partition(hosts, 1500).forEach(batch -> {
+ log.info("当前存储数据量大小 {}", batch.size());
CompletableFuture future = this.saveHostInfo(batch);
futures.add(future);
});
diff --git a/src/main/java/com/yupi/springbootinit/service/impl/PostFavourServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/PostFavourServiceImpl.java
deleted file mode 100644
index 08abe11..0000000
--- a/src/main/java/com/yupi/springbootinit/service/impl/PostFavourServiceImpl.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package com.yupi.springbootinit.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.mapper.PostFavourMapper;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.PostFavour;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.service.PostFavourService;
-import com.yupi.springbootinit.service.PostService;
-import javax.annotation.Resource;
-import org.springframework.aop.framework.AopContext;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * 帖子收藏服务实现
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Service
-public class PostFavourServiceImpl extends ServiceImpl
- implements PostFavourService {
-
- @Resource
- private PostService postService;
-
- /**
- * 帖子收藏
- *
- * @param postId
- * @param loginUser
- * @return
- */
- @Override
- public int doPostFavour(long postId, User loginUser) {
- // 判断是否存在
- Post post = postService.getById(postId);
- if (post == null) {
- throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
- }
- // 是否已帖子收藏
- long userId = loginUser.getId();
- // 每个用户串行帖子收藏
- // 锁必须要包裹住事务方法
- PostFavourService postFavourService = (PostFavourService) AopContext.currentProxy();
- synchronized (String.valueOf(userId).intern()) {
- return postFavourService.doPostFavourInner(userId, postId);
- }
- }
-
- @Override
- public Page listFavourPostByPage(IPage page, Wrapper queryWrapper, long favourUserId) {
- if (favourUserId <= 0) {
- return new Page<>();
- }
- return baseMapper.listFavourPostByPage(page, queryWrapper, favourUserId);
- }
-
- /**
- * 封装了事务的方法
- *
- * @param userId
- * @param postId
- * @return
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public int doPostFavourInner(long userId, long postId) {
- PostFavour postFavour = new PostFavour();
- postFavour.setUserId(userId);
- postFavour.setPostId(postId);
- QueryWrapper postFavourQueryWrapper = new QueryWrapper<>(postFavour);
- PostFavour oldPostFavour = this.getOne(postFavourQueryWrapper);
- boolean result;
- // 已收藏
- if (oldPostFavour != null) {
- result = this.remove(postFavourQueryWrapper);
- if (result) {
- // 帖子收藏数 - 1
- result = postService.update()
- .eq("id", postId)
- .gt("favourNum", 0)
- .setSql("favourNum = favourNum - 1")
- .update();
- return result ? -1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- } else {
- // 未帖子收藏
- result = this.save(postFavour);
- if (result) {
- // 帖子收藏数 + 1
- result = postService.update()
- .eq("id", postId)
- .setSql("favourNum = favourNum + 1")
- .update();
- return result ? 1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- }
- }
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/service/impl/PostServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/PostServiceImpl.java
deleted file mode 100644
index 791c8c4..0000000
--- a/src/main/java/com/yupi/springbootinit/service/impl/PostServiceImpl.java
+++ /dev/null
@@ -1,312 +0,0 @@
-package com.yupi.springbootinit.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.constant.CommonConstant;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.exception.ThrowUtils;
-import com.yupi.springbootinit.mapper.PostFavourMapper;
-import com.yupi.springbootinit.mapper.PostMapper;
-import com.yupi.springbootinit.mapper.PostThumbMapper;
-import com.yupi.springbootinit.model.dto.post.PostEsDTO;
-import com.yupi.springbootinit.model.dto.post.PostQueryRequest;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.PostFavour;
-import com.yupi.springbootinit.model.entity.PostThumb;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.vo.PostVO;
-import com.yupi.springbootinit.model.vo.UserVO;
-import com.yupi.springbootinit.service.PostService;
-import com.yupi.springbootinit.service.UserService;
-import com.yupi.springbootinit.utils.SqlUtils;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import cn.hutool.core.collection.CollUtil;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.sort.SortBuilder;
-import org.elasticsearch.search.sort.SortBuilders;
-import org.elasticsearch.search.sort.SortOrder;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
-import org.springframework.data.elasticsearch.core.SearchHit;
-import org.springframework.data.elasticsearch.core.SearchHits;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.stereotype.Service;
-
-/**
- * 帖子服务实现
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Service
-@Slf4j
-public class PostServiceImpl extends ServiceImpl implements PostService {
-
- @Resource
- private UserService userService;
-
- @Resource
- private PostThumbMapper postThumbMapper;
-
- @Resource
- private PostFavourMapper postFavourMapper;
-
- @Resource
- private ElasticsearchRestTemplate elasticsearchRestTemplate;
-
- @Override
- public void validPost(Post post, boolean add) {
- if (post == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR);
- }
- String title = post.getTitle();
- String content = post.getContent();
- String tags = post.getTags();
- // 创建时,参数不能为空
- if (add) {
- ThrowUtils.throwIf(StringUtils.isAnyBlank(title, content, tags), ErrorCode.PARAMS_ERROR);
- }
- // 有参数则校验
- if (StringUtils.isNotBlank(title) && title.length() > 80) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
- }
- if (StringUtils.isNotBlank(content) && content.length() > 8192) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
- }
- }
-
- /**
- * 获取查询包装类
- *
- * @param postQueryRequest
- * @return
- */
- @Override
- public QueryWrapper getQueryWrapper(PostQueryRequest postQueryRequest) {
- QueryWrapper queryWrapper = new QueryWrapper<>();
- if (postQueryRequest == null) {
- return queryWrapper;
- }
- String searchText = postQueryRequest.getSearchText();
- String sortField = postQueryRequest.getSortField();
- String sortOrder = postQueryRequest.getSortOrder();
- Long id = postQueryRequest.getId();
- String title = postQueryRequest.getTitle();
- String content = postQueryRequest.getContent();
- List tagList = postQueryRequest.getTags();
- Long userId = postQueryRequest.getUserId();
- Long notId = postQueryRequest.getNotId();
- // 拼接查询条件
- if (StringUtils.isNotBlank(searchText)) {
- queryWrapper.and(qw -> qw.like("title", searchText).or().like("content", searchText));
- }
- queryWrapper.like(StringUtils.isNotBlank(title), "title", title);
- queryWrapper.like(StringUtils.isNotBlank(content), "content", content);
- if (CollUtil.isNotEmpty(tagList)) {
- for (String tag : tagList) {
- queryWrapper.like("tags", "\"" + tag + "\"");
- }
- }
- queryWrapper.ne(ObjectUtils.isNotEmpty(notId), "id", notId);
- queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
- queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
- queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
- sortField);
- return queryWrapper;
- }
-
- @Override
- public Page searchFromEs(PostQueryRequest postQueryRequest) {
- Long id = postQueryRequest.getId();
- Long notId = postQueryRequest.getNotId();
- String searchText = postQueryRequest.getSearchText();
- String title = postQueryRequest.getTitle();
- String content = postQueryRequest.getContent();
- List tagList = postQueryRequest.getTags();
- List orTagList = postQueryRequest.getOrTags();
- Long userId = postQueryRequest.getUserId();
- // es 起始页为 0
- long current = postQueryRequest.getCurrent() - 1;
- long pageSize = postQueryRequest.getPageSize();
- String sortField = postQueryRequest.getSortField();
- String sortOrder = postQueryRequest.getSortOrder();
- BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
- // 过滤
- boolQueryBuilder.filter(QueryBuilders.termQuery("isDelete", 0));
- if (id != null) {
- boolQueryBuilder.filter(QueryBuilders.termQuery("id", id));
- }
- if (notId != null) {
- boolQueryBuilder.mustNot(QueryBuilders.termQuery("id", notId));
- }
- if (userId != null) {
- boolQueryBuilder.filter(QueryBuilders.termQuery("userId", userId));
- }
- // 必须包含所有标签
- if (CollUtil.isNotEmpty(tagList)) {
- for (String tag : tagList) {
- boolQueryBuilder.filter(QueryBuilders.termQuery("tags", tag));
- }
- }
- // 包含任何一个标签即可
- if (CollUtil.isNotEmpty(orTagList)) {
- BoolQueryBuilder orTagBoolQueryBuilder = QueryBuilders.boolQuery();
- for (String tag : orTagList) {
- orTagBoolQueryBuilder.should(QueryBuilders.termQuery("tags", tag));
- }
- orTagBoolQueryBuilder.minimumShouldMatch(1);
- boolQueryBuilder.filter(orTagBoolQueryBuilder);
- }
- // 按关键词检索
- if (StringUtils.isNotBlank(searchText)) {
- boolQueryBuilder.should(QueryBuilders.matchQuery("title", searchText));
- boolQueryBuilder.should(QueryBuilders.matchQuery("description", searchText));
- boolQueryBuilder.should(QueryBuilders.matchQuery("content", searchText));
- boolQueryBuilder.minimumShouldMatch(1);
- }
- // 按标题检索
- if (StringUtils.isNotBlank(title)) {
- boolQueryBuilder.should(QueryBuilders.matchQuery("title", title));
- boolQueryBuilder.minimumShouldMatch(1);
- }
- // 按内容检索
- if (StringUtils.isNotBlank(content)) {
- boolQueryBuilder.should(QueryBuilders.matchQuery("content", content));
- boolQueryBuilder.minimumShouldMatch(1);
- }
- // 排序
- SortBuilder> sortBuilder = SortBuilders.scoreSort();
- if (StringUtils.isNotBlank(sortField)) {
- sortBuilder = SortBuilders.fieldSort(sortField);
- sortBuilder.order(CommonConstant.SORT_ORDER_ASC.equals(sortOrder) ? SortOrder.ASC : SortOrder.DESC);
- }
- // 分页
- PageRequest pageRequest = PageRequest.of((int) current, (int) pageSize);
- // 构造查询
- NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder)
- .withPageable(pageRequest).withSorts(sortBuilder).build();
- SearchHits searchHits = elasticsearchRestTemplate.search(searchQuery, PostEsDTO.class);
- Page page = new Page<>();
- page.setTotal(searchHits.getTotalHits());
- List resourceList = new ArrayList<>();
- // 查出结果后,从 db 获取最新动态数据(比如点赞数)
- if (searchHits.hasSearchHits()) {
- List> searchHitList = searchHits.getSearchHits();
- List postIdList = searchHitList.stream().map(searchHit -> searchHit.getContent().getId())
- .collect(Collectors.toList());
- List postList = baseMapper.selectBatchIds(postIdList);
- if (postList != null) {
- Map> idPostMap = postList.stream().collect(Collectors.groupingBy(Post::getId));
- postIdList.forEach(postId -> {
- if (idPostMap.containsKey(postId)) {
- resourceList.add(idPostMap.get(postId).get(0));
- } else {
- // 从 es 清空 db 已物理删除的数据
- String delete = elasticsearchRestTemplate.delete(String.valueOf(postId), PostEsDTO.class);
- log.info("delete post {}", delete);
- }
- });
- }
- }
- page.setRecords(resourceList);
- return page;
- }
-
- @Override
- public PostVO getPostVO(Post post, HttpServletRequest request) {
- PostVO postVO = PostVO.objToVo(post);
- long postId = post.getId();
- // 1. 关联查询用户信息
- Long userId = post.getUserId();
- User user = null;
- if (userId != null && userId > 0) {
- user = userService.getById(userId);
- }
- UserVO userVO = userService.getUserVO(user);
- postVO.setUser(userVO);
- // 2. 已登录,获取用户点赞、收藏状态
- User loginUser = userService.getLoginUserPermitNull(request);
- if (loginUser != null) {
- // 获取点赞
- QueryWrapper postThumbQueryWrapper = new QueryWrapper<>();
- postThumbQueryWrapper.in("postId", postId);
- postThumbQueryWrapper.eq("userId", loginUser.getId());
- PostThumb postThumb = postThumbMapper.selectOne(postThumbQueryWrapper);
- postVO.setHasThumb(postThumb != null);
- // 获取收藏
- QueryWrapper postFavourQueryWrapper = new QueryWrapper<>();
- postFavourQueryWrapper.in("postId", postId);
- postFavourQueryWrapper.eq("userId", loginUser.getId());
- PostFavour postFavour = postFavourMapper.selectOne(postFavourQueryWrapper);
- postVO.setHasFavour(postFavour != null);
- }
- return postVO;
- }
-
- @Override
- public Page getPostVOPage(Page postPage, HttpServletRequest request) {
- List postList = postPage.getRecords();
- Page postVOPage = new Page<>(postPage.getCurrent(), postPage.getSize(), postPage.getTotal());
- if (CollUtil.isEmpty(postList)) {
- return postVOPage;
- }
- // 1. 关联查询用户信息
- Set userIdSet = postList.stream().map(Post::getUserId).collect(Collectors.toSet());
- Map> userIdUserListMap = userService.listByIds(userIdSet).stream()
- .collect(Collectors.groupingBy(User::getId));
- // 2. 已登录,获取用户点赞、收藏状态
- Map postIdHasThumbMap = new HashMap<>();
- Map postIdHasFavourMap = new HashMap<>();
- User loginUser = userService.getLoginUserPermitNull(request);
- if (loginUser != null) {
- Set postIdSet = postList.stream().map(Post::getId).collect(Collectors.toSet());
- loginUser = userService.getLoginUser(request);
- // 获取点赞
- QueryWrapper postThumbQueryWrapper = new QueryWrapper<>();
- postThumbQueryWrapper.in("postId", postIdSet);
- postThumbQueryWrapper.eq("userId", loginUser.getId());
- List postPostThumbList = postThumbMapper.selectList(postThumbQueryWrapper);
- postPostThumbList.forEach(postPostThumb -> postIdHasThumbMap.put(postPostThumb.getPostId(), true));
- // 获取收藏
- QueryWrapper postFavourQueryWrapper = new QueryWrapper<>();
- postFavourQueryWrapper.in("postId", postIdSet);
- postFavourQueryWrapper.eq("userId", loginUser.getId());
- List postFavourList = postFavourMapper.selectList(postFavourQueryWrapper);
- postFavourList.forEach(postFavour -> postIdHasFavourMap.put(postFavour.getPostId(), true));
- }
- // 填充信息
- List postVOList = postList.stream().map(post -> {
- PostVO postVO = PostVO.objToVo(post);
- Long userId = post.getUserId();
- User user = null;
- if (userIdUserListMap.containsKey(userId)) {
- user = userIdUserListMap.get(userId).get(0);
- }
- postVO.setUser(userService.getUserVO(user));
- postVO.setHasThumb(postIdHasThumbMap.getOrDefault(post.getId(), false));
- postVO.setHasFavour(postIdHasFavourMap.getOrDefault(post.getId(), false));
- return postVO;
- }).collect(Collectors.toList());
- postVOPage.setRecords(postVOList);
- return postVOPage;
- }
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/service/impl/PostThumbServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/PostThumbServiceImpl.java
deleted file mode 100644
index a0b3c06..0000000
--- a/src/main/java/com/yupi/springbootinit/service/impl/PostThumbServiceImpl.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package com.yupi.springbootinit.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.mapper.PostThumbMapper;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.PostThumb;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.service.PostService;
-import com.yupi.springbootinit.service.PostThumbService;
-import javax.annotation.Resource;
-import org.springframework.aop.framework.AopContext;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * 帖子点赞服务实现
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Service
-public class PostThumbServiceImpl extends ServiceImpl
- implements PostThumbService {
-
- @Resource
- private PostService postService;
-
- /**
- * 点赞
- *
- * @param postId
- * @param loginUser
- * @return
- */
- @Override
- public int doPostThumb(long postId, User loginUser) {
- // 判断实体是否存在,根据类别获取实体
- Post post = postService.getById(postId);
- if (post == null) {
- throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
- }
- // 是否已点赞
- long userId = loginUser.getId();
- // 每个用户串行点赞
- // 锁必须要包裹住事务方法
- PostThumbService postThumbService = (PostThumbService) AopContext.currentProxy();
- synchronized (String.valueOf(userId).intern()) {
- return postThumbService.doPostThumbInner(userId, postId);
- }
- }
-
- /**
- * 封装了事务的方法
- *
- * @param userId
- * @param postId
- * @return
- */
- @Override
- @Transactional(rollbackFor = Exception.class)
- public int doPostThumbInner(long userId, long postId) {
- PostThumb postThumb = new PostThumb();
- postThumb.setUserId(userId);
- postThumb.setPostId(postId);
- QueryWrapper thumbQueryWrapper = new QueryWrapper<>(postThumb);
- PostThumb oldPostThumb = this.getOne(thumbQueryWrapper);
- boolean result;
- // 已点赞
- if (oldPostThumb != null) {
- result = this.remove(thumbQueryWrapper);
- if (result) {
- // 点赞数 - 1
- result = postService.update()
- .eq("id", postId)
- .gt("thumbNum", 0)
- .setSql("thumbNum = thumbNum - 1")
- .update();
- return result ? -1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- } else {
- // 未点赞
- result = this.save(postThumb);
- if (result) {
- // 点赞数 + 1
- result = postService.update()
- .eq("id", postId)
- .setSql("thumbNum = thumbNum + 1")
- .update();
- return result ? 1 : 0;
- } else {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR);
- }
- }
- }
-
-}
-
-
-
-
diff --git a/src/main/java/com/yupi/springbootinit/service/impl/UserServiceImpl.java b/src/main/java/com/yupi/springbootinit/service/impl/UserServiceImpl.java
deleted file mode 100644
index bde1928..0000000
--- a/src/main/java/com/yupi/springbootinit/service/impl/UserServiceImpl.java
+++ /dev/null
@@ -1,272 +0,0 @@
-package com.yupi.springbootinit.service.impl;
-
-import static com.yupi.springbootinit.constant.UserConstant.USER_LOGIN_STATE;
-
-import cn.hutool.core.collection.CollUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yupi.springbootinit.common.ErrorCode;
-import com.yupi.springbootinit.constant.CommonConstant;
-import com.yupi.springbootinit.exception.BusinessException;
-import com.yupi.springbootinit.mapper.UserMapper;
-import com.yupi.springbootinit.model.dto.user.UserQueryRequest;
-import com.yupi.springbootinit.model.entity.User;
-import com.yupi.springbootinit.model.enums.UserRoleEnum;
-import com.yupi.springbootinit.model.vo.LoginUserVO;
-import com.yupi.springbootinit.model.vo.UserVO;
-import com.yupi.springbootinit.service.UserService;
-import com.yupi.springbootinit.utils.SqlUtils;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.stereotype.Service;
-import org.springframework.util.DigestUtils;
-
-/**
- * 用户服务实现
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Service
-@Slf4j
-public class UserServiceImpl extends ServiceImpl implements UserService {
-
- /**
- * 盐值,混淆密码
- */
- public static final String SALT = "yupi";
-
- @Override
- public long userRegister(String userAccount, String userPassword, String checkPassword) {
- // 1. 校验
- if (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword)) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数为空");
- }
- if (userAccount.length() < 4) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户账号过短");
- }
- if (userPassword.length() < 8 || checkPassword.length() < 8) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户密码过短");
- }
- // 密码和校验密码相同
- if (!userPassword.equals(checkPassword)) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "两次输入的密码不一致");
- }
- synchronized (userAccount.intern()) {
- // 账户不能重复
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("userAccount", userAccount);
- long count = this.baseMapper.selectCount(queryWrapper);
- if (count > 0) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "账号重复");
- }
- // 2. 加密
- String encryptPassword = DigestUtils.md5DigestAsHex((SALT + userPassword).getBytes());
- // 3. 插入数据
- User user = new User();
- user.setUserAccount(userAccount);
- user.setUserPassword(encryptPassword);
- boolean saveResult = this.save(user);
- if (!saveResult) {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR, "注册失败,数据库错误");
- }
- return user.getId();
- }
- }
-
- @Override
- public LoginUserVO userLogin(String userAccount, String userPassword, HttpServletRequest request) {
- // 1. 校验
- if (StringUtils.isAnyBlank(userAccount, userPassword)) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数为空");
- }
- if (userAccount.length() < 4) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "账号错误");
- }
- if (userPassword.length() < 8) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "密码错误");
- }
- // 2. 加密
- String encryptPassword = DigestUtils.md5DigestAsHex((SALT + userPassword).getBytes());
- // 查询用户是否存在
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("userAccount", userAccount);
- queryWrapper.eq("userPassword", encryptPassword);
- User user = this.baseMapper.selectOne(queryWrapper);
- // 用户不存在
- if (user == null) {
- log.info("user login failed, userAccount cannot match userPassword");
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户不存在或密码错误");
- }
- // 3. 记录用户的登录态
- request.getSession().setAttribute(USER_LOGIN_STATE, user);
- return this.getLoginUserVO(user);
- }
-
- @Override
- public LoginUserVO userLoginByMpOpen(WxOAuth2UserInfo wxOAuth2UserInfo, HttpServletRequest request) {
- String unionId = wxOAuth2UserInfo.getUnionId();
- String mpOpenId = wxOAuth2UserInfo.getOpenid();
- // 单机锁
- synchronized (unionId.intern()) {
- // 查询用户是否已存在
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("unionId", unionId);
- User user = this.getOne(queryWrapper);
- // 被封号,禁止登录
- if (user != null && UserRoleEnum.BAN.getValue().equals(user.getUserRole())) {
- throw new BusinessException(ErrorCode.FORBIDDEN_ERROR, "该用户已被封,禁止登录");
- }
- // 用户不存在则创建
- if (user == null) {
- user = new User();
- user.setUnionId(unionId);
- user.setMpOpenId(mpOpenId);
- user.setUserAvatar(wxOAuth2UserInfo.getHeadImgUrl());
- user.setUserName(wxOAuth2UserInfo.getNickname());
- boolean result = this.save(user);
- if (!result) {
- throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败");
- }
- }
- // 记录用户的登录态
- request.getSession().setAttribute(USER_LOGIN_STATE, user);
- return getLoginUserVO(user);
- }
- }
-
- /**
- * 获取当前登录用户
- *
- * @param request
- * @return
- */
- @Override
- public User getLoginUser(HttpServletRequest request) {
- // 先判断是否已登录
- Object userObj = request.getSession().getAttribute(USER_LOGIN_STATE);
- User currentUser = (User) userObj;
- if (currentUser == null || currentUser.getId() == null) {
- throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
- }
- // 从数据库查询(追求性能的话可以注释,直接走缓存)
- long userId = currentUser.getId();
- currentUser = this.getById(userId);
- if (currentUser == null) {
- throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
- }
- return currentUser;
- }
-
- /**
- * 获取当前登录用户(允许未登录)
- *
- * @param request
- * @return
- */
- @Override
- public User getLoginUserPermitNull(HttpServletRequest request) {
- // 先判断是否已登录
- Object userObj = request.getSession().getAttribute(USER_LOGIN_STATE);
- User currentUser = (User) userObj;
- if (currentUser == null || currentUser.getId() == null) {
- return null;
- }
- // 从数据库查询(追求性能的话可以注释,直接走缓存)
- long userId = currentUser.getId();
- return this.getById(userId);
- }
-
- /**
- * 是否为管理员
- *
- * @param request
- * @return
- */
- @Override
- public boolean isAdmin(HttpServletRequest request) {
- // 仅管理员可查询
- Object userObj = request.getSession().getAttribute(USER_LOGIN_STATE);
- User user = (User) userObj;
- return isAdmin(user);
- }
-
- @Override
- public boolean isAdmin(User user) {
- return user != null && UserRoleEnum.ADMIN.getValue().equals(user.getUserRole());
- }
-
- /**
- * 用户注销
- *
- * @param request
- */
- @Override
- public boolean userLogout(HttpServletRequest request) {
- if (request.getSession().getAttribute(USER_LOGIN_STATE) == null) {
- throw new BusinessException(ErrorCode.OPERATION_ERROR, "未登录");
- }
- // 移除登录态
- request.getSession().removeAttribute(USER_LOGIN_STATE);
- return true;
- }
-
- @Override
- public LoginUserVO getLoginUserVO(User user) {
- if (user == null) {
- return null;
- }
- LoginUserVO loginUserVO = new LoginUserVO();
- BeanUtils.copyProperties(user, loginUserVO);
- return loginUserVO;
- }
-
- @Override
- public UserVO getUserVO(User user) {
- if (user == null) {
- return null;
- }
- UserVO userVO = new UserVO();
- BeanUtils.copyProperties(user, userVO);
- return userVO;
- }
-
- @Override
- public List getUserVO(List userList) {
- if (CollUtil.isEmpty(userList)) {
- return new ArrayList<>();
- }
- return userList.stream().map(this::getUserVO).collect(Collectors.toList());
- }
-
- @Override
- public QueryWrapper getQueryWrapper(UserQueryRequest userQueryRequest) {
- if (userQueryRequest == null) {
- throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
- }
- Long id = userQueryRequest.getId();
- String unionId = userQueryRequest.getUnionId();
- String mpOpenId = userQueryRequest.getMpOpenId();
- String userName = userQueryRequest.getUserName();
- String userProfile = userQueryRequest.getUserProfile();
- String userRole = userQueryRequest.getUserRole();
- String sortField = userQueryRequest.getSortField();
- String sortOrder = userQueryRequest.getSortOrder();
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq(id != null, "id", id);
- queryWrapper.eq(StringUtils.isNotBlank(unionId), "unionId", unionId);
- queryWrapper.eq(StringUtils.isNotBlank(mpOpenId), "mpOpenId", mpOpenId);
- queryWrapper.eq(StringUtils.isNotBlank(userRole), "userRole", userRole);
- queryWrapper.like(StringUtils.isNotBlank(userProfile), "userProfile", userProfile);
- queryWrapper.like(StringUtils.isNotBlank(userName), "userName", userName);
- queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
- sortField);
- return queryWrapper;
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/wxmp/WxMpConstant.java b/src/main/java/com/yupi/springbootinit/wxmp/WxMpConstant.java
deleted file mode 100644
index 04256b6..0000000
--- a/src/main/java/com/yupi/springbootinit/wxmp/WxMpConstant.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.yupi.springbootinit.wxmp;
-
-/**
- * 微信公众号相关常量
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-public class WxMpConstant {
-
- /**
- * 点击菜单 key
- */
- public static final String CLICK_MENU_KEY = "CLICK_MENU_KEY";
-
-}
diff --git a/src/main/java/com/yupi/springbootinit/wxmp/WxMpMsgRouter.java b/src/main/java/com/yupi/springbootinit/wxmp/WxMpMsgRouter.java
deleted file mode 100644
index a449923..0000000
--- a/src/main/java/com/yupi/springbootinit/wxmp/WxMpMsgRouter.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.yupi.springbootinit.wxmp;
-
-import com.yupi.springbootinit.wxmp.handler.EventHandler;
-import com.yupi.springbootinit.wxmp.handler.MessageHandler;
-import com.yupi.springbootinit.wxmp.handler.SubscribeHandler;
-import javax.annotation.Resource;
-import me.chanjar.weixin.common.api.WxConsts.EventType;
-import me.chanjar.weixin.common.api.WxConsts.XmlMsgType;
-import me.chanjar.weixin.mp.api.WxMpMessageRouter;
-import me.chanjar.weixin.mp.api.WxMpService;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * 微信公众号路由
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@Configuration
-public class WxMpMsgRouter {
-
- @Resource
- private WxMpService wxMpService;
-
- @Resource
- private EventHandler eventHandler;
-
- @Resource
- private MessageHandler messageHandler;
-
- @Resource
- private SubscribeHandler subscribeHandler;
-
- @Bean
- public WxMpMessageRouter getWxMsgRouter() {
- WxMpMessageRouter router = new WxMpMessageRouter(wxMpService);
- // 消息
- router.rule()
- .async(false)
- .msgType(XmlMsgType.TEXT)
- .handler(messageHandler)
- .end();
- // 关注
- router.rule()
- .async(false)
- .msgType(XmlMsgType.EVENT)
- .event(EventType.SUBSCRIBE)
- .handler(subscribeHandler)
- .end();
- // 点击按钮
- router.rule()
- .async(false)
- .msgType(XmlMsgType.EVENT)
- .event(EventType.CLICK)
- .eventKey(WxMpConstant.CLICK_MENU_KEY)
- .handler(eventHandler)
- .end();
- return router;
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/wxmp/handler/EventHandler.java b/src/main/java/com/yupi/springbootinit/wxmp/handler/EventHandler.java
deleted file mode 100644
index 61c348d..0000000
--- a/src/main/java/com/yupi/springbootinit/wxmp/handler/EventHandler.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.yupi.springbootinit.wxmp.handler;
-
-import java.util.Map;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.mp.api.WxMpMessageHandler;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
-import org.springframework.stereotype.Component;
-
-/**
- * 事件处理器
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-@Component
-public class EventHandler implements WxMpMessageHandler {
-
- @Override
- public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map, WxMpService wxMpService,
- WxSessionManager wxSessionManager) throws WxErrorException {
- final String content = "您点击了菜单";
- // 调用接口,返回验证码
- return WxMpXmlOutMessage.TEXT().content(content)
- .fromUser(wxMpXmlMessage.getToUser())
- .toUser(wxMpXmlMessage.getFromUser())
- .build();
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/wxmp/handler/MessageHandler.java b/src/main/java/com/yupi/springbootinit/wxmp/handler/MessageHandler.java
deleted file mode 100644
index 4c71641..0000000
--- a/src/main/java/com/yupi/springbootinit/wxmp/handler/MessageHandler.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.yupi.springbootinit.wxmp.handler;
-
-import java.util.Map;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.mp.api.WxMpMessageHandler;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
-import org.springframework.stereotype.Component;
-
-/**
- * 消息处理器
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-@Component
-public class MessageHandler implements WxMpMessageHandler {
-
- @Override
- public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map,
- WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
- String content = "我是复读机:" + wxMpXmlMessage.getContent();
- return WxMpXmlOutMessage.TEXT().content(content)
- .fromUser(wxMpXmlMessage.getToUser())
- .toUser(wxMpXmlMessage.getFromUser())
- .build();
- }
-}
diff --git a/src/main/java/com/yupi/springbootinit/wxmp/handler/SubscribeHandler.java b/src/main/java/com/yupi/springbootinit/wxmp/handler/SubscribeHandler.java
deleted file mode 100644
index 44fc233..0000000
--- a/src/main/java/com/yupi/springbootinit/wxmp/handler/SubscribeHandler.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.yupi.springbootinit.wxmp.handler;
-
-import java.util.Map;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.mp.api.WxMpMessageHandler;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
-import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
-import org.springframework.stereotype.Component;
-
-/**
- * 关注处理器
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- **/
-@Component
-public class SubscribeHandler implements WxMpMessageHandler {
-
- @Override
- public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map,
- WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
- final String content = "感谢关注";
- // 调用接口,返回验证码
- return WxMpXmlOutMessage.TEXT().content(content)
- .fromUser(wxMpXmlMessage.getToUser())
- .toUser(wxMpXmlMessage.getFromUser())
- .build();
- }
-}
diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-dev.yml
similarity index 100%
rename from src/main/resources/application-test.yml
rename to src/main/resources/application-dev.yml
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 0bc2700..1bba187 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -6,7 +6,7 @@ spring:
name: springboot-init
# 默认 dev 环境
profiles:
- active: test
+ active: dev
# 支持 swagger3
mvc:
pathmatch:
@@ -26,21 +26,6 @@ spring:
password: 123asd
jackson:
date-format: yyyy-MM-dd HH:mm:ss
- # Redis 配置
- # todo 需替换配置,然后取消注释
-# redis:
-# database: 1
-# host: localhost
-# port: 6379
-# timeout: 5000
-# password: 123456
- # Elasticsearch 配置
- # todo 需替换配置,然后取消注释
-# elasticsearch:
-# uris: http://localhost:9200
-# username: root
-# password: 123456
- # 文件上传
servlet:
multipart:
# 大小限制
@@ -58,8 +43,8 @@ mybatis-plus:
configuration:
map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+ log-sql:
default-executor-type: batch
-
global-config:
db-config:
logic-delete-field: isDelete # 全局逻辑删除的实体字段名
diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt
deleted file mode 100644
index c24dbad..0000000
--- a/src/main/resources/banner.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-by 程序员鱼皮:https://github.com/liyupi
-可能是最好的编程学习圈子:https://yupi.icu
diff --git a/src/main/resources/mapper/NewHostsMapper.xml b/src/main/resources/mapper/NewHostsMapper.xml
index 0f73a32..b133b57 100644
--- a/src/main/resources/mapper/NewHostsMapper.xml
+++ b/src/main/resources/mapper/NewHostsMapper.xml
@@ -42,13 +42,12 @@
insert into new_hosts (hosts_id, hosts_level, hosts_coins,
Invitation_type, fans, fllowernum,
yesterday_coins, country, hosts_kind,
- tenant_id, creator, create_time,
- updater, update_time)
+ tenant_id, creator
+ )
values (#{hostsId,jdbcType=VARCHAR}, #{hostsLevel,jdbcType=VARCHAR}, #{hostsCoins,jdbcType=INTEGER},
#{invitationType,jdbcType=INTEGER}, #{fans,jdbcType=INTEGER}, #{fllowernum,jdbcType=INTEGER},
#{yesterdayCoins,jdbcType=INTEGER}, #{country,jdbcType=VARCHAR}, #{hostsKind,jdbcType=VARCHAR},
- #{tenantId,jdbcType=BIGINT}, #{creator,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
- #{updater,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP})
+ #{tenantId,jdbcType=BIGINT}, #{creator,jdbcType=INTEGER})
diff --git a/src/main/resources/mapper/PostFavourMapper.xml b/src/main/resources/mapper/PostFavourMapper.xml
deleted file mode 100644
index b7985c9..0000000
--- a/src/main/resources/mapper/PostFavourMapper.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,postId,userId,
- createTime,updateTime
-
-
-
-
diff --git a/src/main/resources/mapper/PostMapper.xml b/src/main/resources/mapper/PostMapper.xml
deleted file mode 100644
index d57b866..0000000
--- a/src/main/resources/mapper/PostMapper.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,title,content,tags,
- thumbNum,favourNum,userId,
- createTime,updateTime,isDelete
-
-
-
-
diff --git a/src/main/resources/mapper/PostThumbMapper.xml b/src/main/resources/mapper/PostThumbMapper.xml
deleted file mode 100644
index 07909ab..0000000
--- a/src/main/resources/mapper/PostThumbMapper.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,postId,
- userId,createTime,updateTime
-
-
diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml
deleted file mode 100644
index e61aa90..0000000
--- a/src/main/resources/mapper/UserMapper.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- id,unionId,mpOpenId,
- userName,userAvatar,userProfile,
- userRole,createTime,updateTime,isDelete
-
-
diff --git a/src/test/java/com/yupi/springbootinit/manager/CosManagerTest.java b/src/test/java/com/yupi/springbootinit/manager/CosManagerTest.java
deleted file mode 100644
index e803a4b..0000000
--- a/src/test/java/com/yupi/springbootinit/manager/CosManagerTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.yupi.springbootinit.manager;
-
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * Cos 操作测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-class CosManagerTest {
-
- @Resource
- private CosManager cosManager;
-
- @Test
- void putObject() {
- cosManager.putObject("test", "test.json");
- }
-}
\ No newline at end of file
diff --git a/src/test/java/com/yupi/springbootinit/mapper/PostFavourMapperTest.java b/src/test/java/com/yupi/springbootinit/mapper/PostFavourMapperTest.java
deleted file mode 100644
index 96bd2f3..0000000
--- a/src/test/java/com/yupi/springbootinit/mapper/PostFavourMapperTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.yupi.springbootinit.mapper;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yupi.springbootinit.model.entity.Post;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子收藏数据库操作测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-class PostFavourMapperTest {
-
- @Resource
- private PostFavourMapper postFavourMapper;
-
- @Test
- void listUserFavourPostByPage() {
- IPage page = new Page<>(2, 1);
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("id", 1);
- queryWrapper.like("content", "a");
- IPage result = postFavourMapper.listFavourPostByPage(page, queryWrapper, 1);
- Assertions.assertNotNull(result);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/com/yupi/springbootinit/mapper/PostMapperTest.java b/src/test/java/com/yupi/springbootinit/mapper/PostMapperTest.java
deleted file mode 100644
index b0186ba..0000000
--- a/src/test/java/com/yupi/springbootinit/mapper/PostMapperTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.yupi.springbootinit.mapper;
-
-import com.yupi.springbootinit.model.entity.Post;
-import java.util.Date;
-import java.util.List;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子数据库操作测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-class PostMapperTest {
-
- @Resource
- private PostMapper postMapper;
-
- @Test
- void listPostWithDelete() {
- List postList = postMapper.listPostWithDelete(new Date());
- Assertions.assertNotNull(postList);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/com/yupi/springbootinit/service/PostFavourServiceTest.java b/src/test/java/com/yupi/springbootinit/service/PostFavourServiceTest.java
deleted file mode 100644
index 16aa319..0000000
--- a/src/test/java/com/yupi/springbootinit/service/PostFavourServiceTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yupi.springbootinit.model.entity.Post;
-import com.yupi.springbootinit.model.entity.User;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子收藏服务测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-class PostFavourServiceTest {
-
- @Resource
- private PostFavourService postFavourService;
-
- private static final User loginUser = new User();
-
- @BeforeAll
- static void setUp() {
- loginUser.setId(1L);
- }
-
- @Test
- void doPostFavour() {
- int i = postFavourService.doPostFavour(1L, loginUser);
- Assertions.assertTrue(i >= 0);
- }
-
- @Test
- void listFavourPostByPage() {
- QueryWrapper postQueryWrapper = new QueryWrapper<>();
- postQueryWrapper.eq("id", 1L);
- postFavourService.listFavourPostByPage(Page.of(0, 1), postQueryWrapper, loginUser.getId());
- }
-}
diff --git a/src/test/java/com/yupi/springbootinit/service/PostThumbServiceTest.java b/src/test/java/com/yupi/springbootinit/service/PostThumbServiceTest.java
deleted file mode 100644
index 46fe0e9..0000000
--- a/src/test/java/com/yupi/springbootinit/service/PostThumbServiceTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import com.yupi.springbootinit.model.entity.User;
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 帖子点赞服务测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-class PostThumbServiceTest {
-
- @Resource
- private PostThumbService postThumbService;
-
- private static final User loginUser = new User();
-
- @BeforeAll
- static void setUp() {
- loginUser.setId(1L);
- }
-
- @Test
- void doPostThumb() {
- int i = postThumbService.doPostThumb(1L, loginUser);
- Assertions.assertTrue(i >= 0);
- }
-}
diff --git a/src/test/java/com/yupi/springbootinit/service/UserServiceTest.java b/src/test/java/com/yupi/springbootinit/service/UserServiceTest.java
deleted file mode 100644
index 0b152c5..0000000
--- a/src/test/java/com/yupi/springbootinit/service/UserServiceTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.yupi.springbootinit.service;
-
-import javax.annotation.Resource;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * 用户服务测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-public class UserServiceTest {
-
- @Resource
- private UserService userService;
-
- @Test
- void userRegister() {
- String userAccount = "yupi";
- String userPassword = "";
- String checkPassword = "123456";
- try {
- long result = userService.userRegister(userAccount, userPassword, checkPassword);
- Assertions.assertEquals(-1, result);
- userAccount = "yu";
- result = userService.userRegister(userAccount, userPassword, checkPassword);
- Assertions.assertEquals(-1, result);
- } catch (Exception e) {
-
- }
- }
-}
diff --git a/src/test/java/com/yupi/springbootinit/utils/EasyExcelTest.java b/src/test/java/com/yupi/springbootinit/utils/EasyExcelTest.java
deleted file mode 100644
index b74eb9f..0000000
--- a/src/test/java/com/yupi/springbootinit/utils/EasyExcelTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.yupi.springbootinit.utils;
-
-import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.support.ExcelTypeEnum;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.util.ResourceUtils;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.List;
-import java.util.Map;
-
-/**
- * EasyExcel 测试
- *
- * @author 程序员鱼皮
- * @from 编程导航知识星球
- */
-@SpringBootTest
-public class EasyExcelTest {
-
- @Test
- public void doImport() throws FileNotFoundException {
- File file = ResourceUtils.getFile("classpath:test_excel.xlsx");
- List