Compare commits
5 Commits
707a616bda
...
1e86af810f
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e86af810f | |||
| 6e7dde5235 | |||
| dda272b9ab | |||
| b3936a0347 | |||
| fc69911580 |
10
pom.xml
10
pom.xml
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -218,7 +218,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<version>3.18.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -226,6 +226,10 @@
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@ -39,6 +39,48 @@ import java.util.Objects;
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AopLog {
|
||||
/**
|
||||
* 获取ip地址
|
||||
*
|
||||
* @param request 请求体
|
||||
* @return 返回ip地址
|
||||
*/
|
||||
public static String getIp(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
// 处理多级代理
|
||||
if (ip != null && ip.contains(",")) {
|
||||
ip = ip.split(",")[0].trim();
|
||||
}
|
||||
|
||||
// 本地地址处理
|
||||
if ("127.0.0.1".equals(ip) || "0:0:0:0:0:0:0:1".equals(ip)) {
|
||||
try {
|
||||
ip = InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
log.error("获取本地 IP 失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
private static boolean isInvalidIp(String ip) {
|
||||
return ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切入点
|
||||
*/
|
||||
@ -111,48 +153,6 @@ public class AopLog {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ip地址
|
||||
*
|
||||
* @param request 请求体
|
||||
* @return 返回ip地址
|
||||
*/
|
||||
public static String getIp(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (isInvalidIp(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
// 处理多级代理
|
||||
if (ip != null && ip.contains(",")) {
|
||||
ip = ip.split(",")[0].trim();
|
||||
}
|
||||
|
||||
// 本地地址处理
|
||||
if ("127.0.0.1".equals(ip) || "0:0:0:0:0:0:0:1".equals(ip)) {
|
||||
try {
|
||||
ip = InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
log.error("获取本地 IP 失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
private static boolean isInvalidIp(String ip) {
|
||||
return ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip);
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
|
||||
@ -58,17 +58,17 @@ public class SecurityConfig {
|
||||
)
|
||||
// 认证请求
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/auth/**").permitAll()
|
||||
.requestMatchers("/auth/register").permitAll()
|
||||
.requestMatchers("/api/**").permitAll()
|
||||
.requestMatchers("/auth/**").permitAll()
|
||||
.requestMatchers("/auth/register").permitAll()
|
||||
.requestMatchers("/api/**").permitAll()
|
||||
// .requestMatchers("/user/**").permitAll()
|
||||
.anyRequest().access((authenticationSupplier, requestAuthorizationContext) -> {
|
||||
HttpServletRequest request = requestAuthorizationContext.getRequest();
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
return new AuthorizationDecision(
|
||||
jwtRbacAuthenticationService.hasPermission(request, authentication)
|
||||
);
|
||||
})
|
||||
.anyRequest().access((authenticationSupplier, requestAuthorizationContext) -> {
|
||||
HttpServletRequest request = requestAuthorizationContext.getRequest();
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
return new AuthorizationDecision(
|
||||
jwtRbacAuthenticationService.hasPermission(request, authentication)
|
||||
);
|
||||
})
|
||||
)
|
||||
// JWT过滤器
|
||||
.addFilterBefore(
|
||||
|
||||
@ -12,70 +12,114 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
public enum Status {
|
||||
/** 操作成功! */
|
||||
/**
|
||||
* 操作成功!
|
||||
*/
|
||||
SUCCESS(200, "操作成功!"),
|
||||
|
||||
/** 未知异常 */
|
||||
/**
|
||||
* 未知异常
|
||||
*/
|
||||
UNKNOWN_ERROR(500, "未知异常"),
|
||||
|
||||
/** 退出成功! */
|
||||
/**
|
||||
* 退出成功!
|
||||
*/
|
||||
LOGOUT(200, "退出成功!"),
|
||||
|
||||
/** 登录成功! */
|
||||
/**
|
||||
* 登录成功!
|
||||
*/
|
||||
LOGIN_SUCCESS(200, "登录成功!"),
|
||||
|
||||
/** 请先登录! */
|
||||
/**
|
||||
* 请先登录!
|
||||
*/
|
||||
UNAUTHORIZED(401, "请先登录!"),
|
||||
|
||||
/** 暂无权限访问! */
|
||||
/**
|
||||
* 暂无权限访问!
|
||||
*/
|
||||
ACCESS_DENIED(403, "权限不足!"),
|
||||
|
||||
/** 请求不存在! */
|
||||
/**
|
||||
* 请求不存在!
|
||||
*/
|
||||
REQUEST_NOT_FOUND(404, "请求不存在!"),
|
||||
|
||||
/** 请求方式不支持! */
|
||||
/**
|
||||
* 请求方式不支持!
|
||||
*/
|
||||
HTTP_BAD_METHOD(405, "请求方式不支持!"),
|
||||
|
||||
/** 请求异常! */
|
||||
/**
|
||||
* 请求异常!
|
||||
*/
|
||||
BAD_REQUEST(400, "请求异常!"),
|
||||
|
||||
/** 参数不匹配! */
|
||||
/**
|
||||
* 参数不匹配!
|
||||
*/
|
||||
PARAM_NOT_MATCH(400, "参数不匹配!"),
|
||||
|
||||
/** 参数不能为空! */
|
||||
/**
|
||||
* 参数不能为空!
|
||||
*/
|
||||
PARAM_NOT_NULL(400, "参数不能为空!"),
|
||||
|
||||
/** 当前用户已被锁定,请联系管理员解锁! */
|
||||
/**
|
||||
* 当前用户已被锁定,请联系管理员解锁!
|
||||
*/
|
||||
USER_DISABLED(403, "当前用户已被锁定,请联系管理员解锁!"),
|
||||
|
||||
/** 用户名或密码错误! */
|
||||
/**
|
||||
* 用户名或密码错误!
|
||||
*/
|
||||
USERNAME_PASSWORD_ERROR(5001, "用户名或密码错误!"),
|
||||
|
||||
/** token 已过期,请重新登录! */
|
||||
/**
|
||||
* token 已过期,请重新登录!
|
||||
*/
|
||||
TOKEN_EXPIRED(5002, "token 已过期,请重新登录!"),
|
||||
|
||||
/** token 解析失败,请尝试重新登录! */
|
||||
/**
|
||||
* token 解析失败,请尝试重新登录!
|
||||
*/
|
||||
TOKEN_PARSE_ERROR(5002, "token 解析失败,请尝试重新登录!"),
|
||||
|
||||
/** 当前用户已在别处登录,请尝试更改密码或重新登录! */
|
||||
/**
|
||||
* 当前用户已在别处登录,请尝试更改密码或重新登录!
|
||||
*/
|
||||
TOKEN_OUT_OF_CTRL(5003, "当前用户已在别处登录,请尝试更改密码或重新登录!"),
|
||||
|
||||
/** 无法手动踢出自己,请尝试退出登录操作! */
|
||||
/**
|
||||
* 无法手动踢出自己,请尝试退出登录操作!
|
||||
*/
|
||||
KICKOUT_SELF(5004, "无法手动踢出自己,请尝试退出登录操作!"),
|
||||
|
||||
/** 账号密码错误 */
|
||||
/**
|
||||
* 账号密码错误
|
||||
*/
|
||||
USERNAME_OR_PASSWORD_ERROR(200, "账号密码错误"),
|
||||
|
||||
/** 账户已被锁定 */
|
||||
/**
|
||||
* 账户已被锁定
|
||||
*/
|
||||
ACCOUNT_LOCKED(200, "账户已被锁定"),
|
||||
|
||||
/** 注册成功! */
|
||||
/**
|
||||
* 注册成功!
|
||||
*/
|
||||
REGISTER_SUCCESS(200, "注册成功");
|
||||
|
||||
/** 状态码 */
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private final Integer code;
|
||||
|
||||
/** 内容 */
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private final String message;
|
||||
|
||||
Status(Integer code, String message) {
|
||||
|
||||
@ -9,6 +9,7 @@ import asia.yulinling.workflow.model.entity.Notebook;
|
||||
import asia.yulinling.workflow.model.vo.NotebookVO;
|
||||
import asia.yulinling.workflow.service.NotebookService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -36,14 +37,24 @@ public class NotebookController {
|
||||
}
|
||||
|
||||
@GetMapping("/notebooks/{id}")
|
||||
public void notebooksGet(@PathVariable Long id) {
|
||||
public ApiResponse<NotebookVO> notebooksGet(@PathVariable Long id) {
|
||||
NotebookVO notebookVO = notebookService.getNotebook(id);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS, notebookVO);
|
||||
}
|
||||
|
||||
@PutMapping("/notebooks/{id}")
|
||||
public void notebooksPut(@PathVariable Long id) {
|
||||
@PutMapping("/notebooks/{userId}/?id={id}")
|
||||
public ApiResponse<Object> notebooksPut(@PathVariable Long userId, @PathVariable @NonNull Long id, @Valid @RequestBody NotebookRequest notebookRequest) {
|
||||
Notebook notebook = new Notebook();
|
||||
notebook.setId(id);
|
||||
notebook.setUserId(userId);
|
||||
BeanUtils.copyProperties(notebookRequest, notebook);
|
||||
notebookService.updateNotebook(notebook);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS);
|
||||
}
|
||||
|
||||
@DeleteMapping("/notebooks/{id}")
|
||||
public void notebooksDelete(@PathVariable Long id) {
|
||||
public ApiResponse<Object> notebooksDelete(@PathVariable Long id) {
|
||||
notebookService.deleteNotebookById(id);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package asia.yulinling.workflow.dto.request;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录请求类
|
||||
|
||||
@ -5,25 +5,25 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NotebookRequest {
|
||||
/**
|
||||
* 用户id,外键
|
||||
*/
|
||||
@NotBlank(message = "创建用户为空")
|
||||
Long userId;
|
||||
/**
|
||||
* 用户id,外键
|
||||
*/
|
||||
@NotBlank(message = "创建用户为空")
|
||||
Long userId;
|
||||
|
||||
/**
|
||||
* 笔记本名称
|
||||
*/
|
||||
@NotBlank(message = "笔记本名称为空")
|
||||
String name;
|
||||
/**
|
||||
* 笔记本名称
|
||||
*/
|
||||
@NotBlank(message = "笔记本名称为空")
|
||||
String name;
|
||||
|
||||
/**
|
||||
* 笔记本颜色标识
|
||||
*/
|
||||
String color;
|
||||
/**
|
||||
* 笔记本颜色标识
|
||||
*/
|
||||
String color;
|
||||
|
||||
/**
|
||||
* 笔记本图标标识
|
||||
*/
|
||||
String icon;
|
||||
/**
|
||||
* 笔记本图标标识
|
||||
*/
|
||||
String icon;
|
||||
}
|
||||
|
||||
@ -29,7 +29,8 @@ public class PageResult<T> implements Serializable {
|
||||
private int to; // 当前页最后一条数据在总数据中的位置
|
||||
|
||||
// 无参构造器
|
||||
public PageResult() {}
|
||||
public PageResult() {
|
||||
}
|
||||
|
||||
// 构造方法(可选传参)
|
||||
public PageResult(long total, int currentPage, int pageSize, List<T> list) {
|
||||
|
||||
@ -4,23 +4,15 @@ import asia.yulinling.workflow.exception.PageException;
|
||||
import asia.yulinling.workflow.exception.ServiceException;
|
||||
import asia.yulinling.workflow.model.ApiResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 全局异常处理
|
||||
|
||||
@ -130,11 +130,6 @@ public class UserPrincipal implements UserDetails {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public UserPrincipal(Long id,
|
||||
String username,
|
||||
String password,
|
||||
@ -173,6 +168,10 @@ public class UserPrincipal implements UserDetails {
|
||||
return userPrincipal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
|
||||
@ -33,7 +33,7 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response,
|
||||
AuthenticationException authException) throws IOException {
|
||||
|
||||
log.error("AuthenticationException: {}",authException.getMessage());
|
||||
log.error("AuthenticationException: {}", authException.getMessage());
|
||||
|
||||
// 1. 设置res 401
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
@ -57,10 +57,10 @@ public class JwtRbacAuthenticationService {
|
||||
|
||||
log.info(permissions.toString());
|
||||
List<Permission> pagePerms = permissions.stream()
|
||||
.filter(permission -> Objects.equals(permission.getType(), 1))
|
||||
.filter(permission -> StrUtil.isNotBlank(permission.getMethod()))
|
||||
.filter(permission -> StrUtil.isNotBlank(permission.getMethod()))
|
||||
.toList();
|
||||
.filter(permission -> Objects.equals(permission.getType(), 1))
|
||||
.filter(permission -> StrUtil.isNotBlank(permission.getMethod()))
|
||||
.filter(permission -> StrUtil.isNotBlank(permission.getMethod()))
|
||||
.toList();
|
||||
|
||||
for (Permission permission : pagePerms) {
|
||||
AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
@ -116,8 +116,8 @@ public class JwtRbacAuthenticationService {
|
||||
Set<PathPattern> urlTemplates = pathPatternsCondition.getPatterns();
|
||||
RequestMethodsRequestCondition methodsCondition = mapping.getMethodsCondition();
|
||||
List<String> httpMethods = methodsCondition.getMethods().stream()
|
||||
.map(Enum::toString)
|
||||
.collect(Collectors.toList());
|
||||
.map(Enum::toString)
|
||||
.collect(Collectors.toList());
|
||||
urlTemplates.forEach(url ->
|
||||
urlMapping.put(url.toString(), httpMethods)
|
||||
);
|
||||
|
||||
@ -39,11 +39,11 @@ public class JwtUserDetailsService implements UserDetailsService {
|
||||
public UserPrincipal loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// 1. 构建查找sql
|
||||
LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery(User.class)
|
||||
.eq(User::getUsername, username)
|
||||
.or()
|
||||
.eq(User::getEmail, username)
|
||||
.or()
|
||||
.eq(User::getPhone, username);
|
||||
.eq(User::getUsername, username)
|
||||
.or()
|
||||
.eq(User::getEmail, username)
|
||||
.or()
|
||||
.eq(User::getPhone, username);
|
||||
|
||||
// 2. 查找用户
|
||||
User user = userMapper.selectOne(queryWrapper);
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
package asia.yulinling.workflow.service;
|
||||
|
||||
import asia.yulinling.workflow.dto.request.LoginRequest;
|
||||
import asia.yulinling.workflow.dto.request.RegisterRequest;
|
||||
import asia.yulinling.workflow.model.ApiResponse;
|
||||
import asia.yulinling.workflow.model.vo.LoginVO;
|
||||
import asia.yulinling.workflow.model.vo.RegisterVO;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
/**
|
||||
@ -19,21 +16,21 @@ import org.springframework.security.core.Authentication;
|
||||
public interface AuthService {
|
||||
/**
|
||||
* 登录系统
|
||||
*
|
||||
*
|
||||
* @param authentication 登录信息
|
||||
*/
|
||||
LoginVO login(Authentication authentication, boolean rememberMe);
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*
|
||||
*
|
||||
* @param token 登录信息
|
||||
*/
|
||||
void logout(String token) throws SecurityException;
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*
|
||||
*
|
||||
* @param request 注册请求
|
||||
* @return 请求结果
|
||||
*/
|
||||
|
||||
@ -15,23 +15,21 @@ public interface NotebookService {
|
||||
*
|
||||
* @param notebook 笔记本
|
||||
*/
|
||||
int addNotebook(Notebook notebook);
|
||||
void addNotebook(Notebook notebook);
|
||||
|
||||
/**
|
||||
* 删除笔记本
|
||||
*
|
||||
* @param notebookId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNotebookById(Long notebookId);
|
||||
void deleteNotebookById(Long notebookId);
|
||||
|
||||
/**
|
||||
* 更新笔记本
|
||||
*
|
||||
* @param notebook 笔记本
|
||||
* @return 结果
|
||||
*/
|
||||
int updateNotebook(Notebook notebook);
|
||||
void updateNotebook(Notebook notebook);
|
||||
|
||||
/**
|
||||
* 获取笔记本内容
|
||||
@ -39,7 +37,7 @@ public interface NotebookService {
|
||||
* @param notebookId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
Notebook getNotebook(Long notebookId);
|
||||
NotebookVO getNotebook(Long notebookId);
|
||||
|
||||
/**
|
||||
* 获取笔记本列表
|
||||
@ -63,5 +61,5 @@ public interface NotebookService {
|
||||
* @param notebookId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkNotebookIdExist(Long notebookId);
|
||||
boolean isNotebookNotExist(Long notebookId);
|
||||
}
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
package asia.yulinling.workflow.service.impl;
|
||||
|
||||
import asia.yulinling.workflow.constant.Status;
|
||||
import asia.yulinling.workflow.dto.request.RegisterRequest;
|
||||
import asia.yulinling.workflow.mapper.UserMapper;
|
||||
import asia.yulinling.workflow.model.ApiResponse;
|
||||
import asia.yulinling.workflow.model.entity.User;
|
||||
import asia.yulinling.workflow.model.vo.LoginVO;
|
||||
import asia.yulinling.workflow.model.vo.RegisterVO;
|
||||
import asia.yulinling.workflow.model.vo.user.UserPrincipal;
|
||||
import asia.yulinling.workflow.service.AuthService;
|
||||
import asia.yulinling.workflow.utils.JwtUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
@ -54,11 +50,11 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
log.info("用户登录成功: {}", userPrincipal.getUsername());
|
||||
return LoginVO.builder()
|
||||
.userId(userPrincipal.getId())
|
||||
.username(userPrincipal.getUsername())
|
||||
.accessToken(accessToken)
|
||||
.expiresIn(expiresIn)
|
||||
.build();
|
||||
.userId(userPrincipal.getId())
|
||||
.username(userPrincipal.getUsername())
|
||||
.accessToken(accessToken)
|
||||
.expiresIn(expiresIn)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -2,6 +2,8 @@ package asia.yulinling.workflow.service.impl;
|
||||
|
||||
import asia.yulinling.workflow.service.MailService;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
@ -10,9 +12,6 @@ import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.MessagingException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
|
||||
@ -27,40 +27,58 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
public int addNotebook(Notebook notebook) {
|
||||
public void addNotebook(Notebook notebook) {
|
||||
|
||||
if (!userService.checkUserIdExist(notebook.getUserId())) {
|
||||
if (userService.checkUserIdExist(notebook.getUserId())) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.insert(notebook);
|
||||
int result = notebookMapper.insert(notebook);
|
||||
|
||||
if (result == 0) {
|
||||
throw new ServiceException("添加笔记本失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteNotebookById(Long notebookId) {
|
||||
if (!userService.checkUserIdExist(notebookId)) {
|
||||
public void deleteNotebookById(Long notebookId) {
|
||||
if (userService.checkUserIdExist(notebookId)) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.deleteById(notebookId);
|
||||
int result = notebookMapper.deleteById(notebookId);
|
||||
if (result == 0) {
|
||||
throw new ServiceException("删除笔记本失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateNotebook(Notebook notebook) {
|
||||
if (!userService.checkUserIdExist(notebook.getUserId())) {
|
||||
public void updateNotebook(Notebook notebook) {
|
||||
if (userService.checkUserIdExist(notebook.getUserId())) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
if (isNotebookNotExist(notebook.getId())) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.updateById(notebook);
|
||||
int result = notebookMapper.updateById(notebook);
|
||||
if (result == 0) {
|
||||
throw new ServiceException("更新笔记本失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Notebook getNotebook(Long notebookId) {
|
||||
if (!userService.checkUserIdExist(notebookId)) {
|
||||
public NotebookVO getNotebook(Long notebookId) {
|
||||
if (isNotebookNotExist(notebookId)) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.selectById(notebookId);
|
||||
Notebook notebook = notebookMapper.selectById(notebookId);
|
||||
NotebookVO notebookVO = new NotebookVO();
|
||||
BeanUtils.copyProperties(notebook, notebookVO);
|
||||
|
||||
return notebookVO;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +112,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
*/
|
||||
@Override
|
||||
public List<Notebook> getNotebookListByUserId(Long userId) {
|
||||
if (!userService.checkUserIdExist(userId)) {
|
||||
if (userService.checkUserIdExist(userId)) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
@ -108,7 +126,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkNotebookIdExist(Long notebookId) {
|
||||
public boolean isNotebookNotExist(Long notebookId) {
|
||||
return notebookMapper.exists(new LambdaQueryWrapper<Notebook>().eq(Notebook::getId, notebookId));
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,9 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
/** 注入用户Mapper */
|
||||
/**
|
||||
* 注入用户Mapper
|
||||
*/
|
||||
private final UserMapper userMapper;
|
||||
private final RequestScopeData scopeData;
|
||||
private final RoleUserMapper roleUserMapper;
|
||||
@ -55,7 +57,7 @@ public class UserServiceImpl implements UserService {
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUserIdExist(Long userId) {
|
||||
return userMapper.exists(new LambdaQueryWrapper<User>().eq(User::getId, userId));
|
||||
return !userMapper.exists(new LambdaQueryWrapper<User>().eq(User::getId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package asia.yulinling.workflow.task;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 定时任务
|
||||
|
||||
@ -22,8 +22,8 @@ import java.util.Date;
|
||||
public class WebSocketTask {
|
||||
private final SimpMessagingTemplate simpMessagingTemplate;
|
||||
|
||||
// @Scheduled(fixedRate = 1000)
|
||||
public void sendMessage() throws Exception{
|
||||
// @Scheduled(fixedRate = 1000)
|
||||
public void sendMessage() throws Exception {
|
||||
log.info("【推送消息】开始执行:{}", DateUtil.formatDateTime(new Date()));
|
||||
simpMessagingTemplate.convertAndSend("test", "1");
|
||||
log.info("【推送消息】执行结束:{}", DateUtil.formatDateTime(new Date()));
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
SELECT * FROM wk_notes;
|
||||
SELECT * FROM wk_attachments;
|
||||
SELECT * FROM wk_note_tags;
|
||||
SELECT * FROM wk_tags;
|
||||
SELECT * FROM wk_notebooks;
|
||||
SELECT *
|
||||
FROM wk_notes;
|
||||
SELECT *
|
||||
FROM wk_attachments;
|
||||
SELECT *
|
||||
FROM wk_note_tags;
|
||||
SELECT *
|
||||
FROM wk_tags;
|
||||
SELECT *
|
||||
FROM wk_notebooks;
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
</h3>
|
||||
|
||||
<span style="text-align: center; padding: 10px">
|
||||
<a style="text-decoration: none" href="#" th:href="@{${url}}" target="_blank">
|
||||
<a href="#" style="text-decoration: none" target="_blank" th:href="@{${url}}">
|
||||
<strong>Spring Boot入门首选</strong>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
<configuration>
|
||||
|
||||
<!-- 设置通用变量 -->
|
||||
<property name="LOG_PATH" value="logs/demo-logback" />
|
||||
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n" />
|
||||
<property name="LOG_CHARSET" value="UTF-8" />
|
||||
<property name="LOG_PATH" value="logs/demo-logback"/>
|
||||
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n"/>
|
||||
<property name="LOG_CHARSET" value="UTF-8"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org" lang="en">
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8"/>
|
||||
<title>统一页面异常处理</title>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
</h3>
|
||||
|
||||
<span style="text-align: center; padding: 10px">
|
||||
<a style="text-decoration: none" href="#" th:href="@{${url}}" target="_blank">
|
||||
<a href="#" style="text-decoration: none" target="_blank" th:href="@{${url}}">
|
||||
<strong>Spring Boot入门首选</strong>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
@ -14,7 +14,7 @@ import java.net.URL;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 邮件测试
|
||||
* 邮件测试
|
||||
* </p>
|
||||
*
|
||||
* @author yulinling
|
||||
|
||||
@ -67,9 +67,9 @@ public class RedisTest extends WorkFlowMainTests {
|
||||
@Test
|
||||
public void testRedis() {
|
||||
UserDetails user = User.withUsername("test")
|
||||
.password("test")
|
||||
.roles("USER")
|
||||
.build();
|
||||
.password("test")
|
||||
.roles("USER")
|
||||
.build();
|
||||
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
|
||||
String token = jwtUtil.generateToken(authentication, false);
|
||||
assertNotNull(token);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user