Phase 1-3 完成:apes-commons 内联 + 包名重构 + 编译验证
Phase 1: apes-commons 内联 - 反推并实现 7 个核心类(Res/AuthContext/Login/LoginUser/LoginCustomer/UserSession/DbEntity) - 新增 LoginAspect AOP 切面(从 Redis 读取会话写入 AuthContext) - 移除外部 JAR 依赖,项目自包含可独立编译 Phase 2: 包名重构 - cn.apes.cloud → cn.apes.authon 全局包名重构 - @MapperScan 路径更新 - 零 cn.apes.cloud 残留 Phase 3: 编译验证 - maven-compiler-plugin 升级至 3.13.0(兼容 Java 24) - Lombok 升级至 1.18.40(兼容 Java 24) - 移除 syncAllTenantsToHuoban(伙伴云同步,非账权核心) - 新增 IpLocationService 接口 + 桩实现 - 124 个源文件编译通过(BUILD SUCCESS)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package cn.apes.commons;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 统一响应封装
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
*/
|
||||
@Data
|
||||
public class Res implements Serializable {
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
private Object data;
|
||||
|
||||
public Res() {
|
||||
}
|
||||
|
||||
public Res(int code, String msg, Object data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static Res success() {
|
||||
return new Res(0, "success", null);
|
||||
}
|
||||
|
||||
public static Res success(Object data) {
|
||||
return new Res(0, "success", data);
|
||||
}
|
||||
|
||||
public static Res fail(String msg) {
|
||||
return new Res(-1, msg, null);
|
||||
}
|
||||
|
||||
public static Res error(String msg) {
|
||||
return new Res(-1, msg, null);
|
||||
}
|
||||
|
||||
public static Res get(int code, String msg) {
|
||||
return new Res(code, msg, null);
|
||||
}
|
||||
|
||||
public static Res get(int code, String msg, Object data) {
|
||||
return new Res(code, msg, data);
|
||||
}
|
||||
|
||||
public static Res get(Object data) {
|
||||
return new Res(0, "success", data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.apes.commons.auth;
|
||||
|
||||
/**
|
||||
* 认证上下文(ThreadLocal)
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
* <p>
|
||||
* 每次请求由 LoginAspect 设置,DataSourceHeaderAspect 清理
|
||||
*/
|
||||
public class AuthContext {
|
||||
|
||||
private static final ThreadLocal<UserSession> CONTEXT = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 获取当前登录会话信息
|
||||
*/
|
||||
public static UserSession getLoginInfo() {
|
||||
return CONTEXT.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前登录会话信息(由 LoginAspect 调用)
|
||||
*/
|
||||
public static void setLoginInfo(UserSession session) {
|
||||
CONTEXT.set(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除当前线程的登录会话(由 DataSourceHeaderAspect 调用)
|
||||
*/
|
||||
public static void clean() {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.apes.commons.auth;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 登录校验注解
|
||||
* 标注在 Controller 类或方法上,表示需要登录后才能访问
|
||||
* 由 LoginAspect 拦截处理:从请求头读取 token,查 Redis 组装 UserSession,写入 AuthContext
|
||||
* <p>
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Login {
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package cn.apes.commons.auth;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 登录认证 AOP 切面
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
* <p>
|
||||
* 拦截 @Login 注解的 Controller 类/方法:
|
||||
* 1. 从请求头读取 token
|
||||
* 2. 查 Redis 获取用户信息 (key=token) 和客户信息 (key=token:customer)
|
||||
* 3. 组装 UserSession 写入 AuthContext ThreadLocal
|
||||
* 4. 业务方法执行完毕后清理 AuthContext
|
||||
* <p>
|
||||
* Order(2) — 在 DataSourceHeaderAspect (Order 1) 之后执行
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(2)
|
||||
public class LoginAspect {
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
@Around("@within(cn.apes.commons.auth.Login)")
|
||||
public Object aroundClass(ProceedingJoinPoint pjp) throws Throwable {
|
||||
return process(pjp);
|
||||
}
|
||||
|
||||
@Around("@annotation(cn.apes.commons.auth.Login)")
|
||||
public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
|
||||
return process(pjp);
|
||||
}
|
||||
|
||||
private Object process(ProceedingJoinPoint pjp) throws Throwable {
|
||||
try {
|
||||
HttpServletRequest request = ((ServletRequestAttributes)
|
||||
RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
String token = request.getHeader("token");
|
||||
if (token == null || token.isEmpty()) {
|
||||
token = request.getHeader("Token");
|
||||
}
|
||||
|
||||
if (token != null && !token.isEmpty()) {
|
||||
UserSession session = new UserSession();
|
||||
session.setToken(token);
|
||||
|
||||
// 读取用户信息
|
||||
RBucket<JSONObject> userBucket = redissonClient.getBucket(token);
|
||||
if (userBucket.isExists()) {
|
||||
JSONObject userJson = userBucket.get();
|
||||
if (userJson != null) {
|
||||
LoginUser loginUser = new LoginUser();
|
||||
loginUser.setId(userJson.getLong("id"));
|
||||
loginUser.setNickName(userJson.getString("nickName"));
|
||||
loginUser.setPhone(userJson.getString("phone"));
|
||||
loginUser.setPortrait(userJson.getString("portrait"));
|
||||
loginUser.setEmail(userJson.getString("email"));
|
||||
session.setUser(loginUser);
|
||||
}
|
||||
}
|
||||
|
||||
// 读取客户信息
|
||||
RBucket<JSONObject> customerBucket = redissonClient.getBucket(token + ":customer");
|
||||
if (customerBucket.isExists()) {
|
||||
JSONObject customerJson = customerBucket.get();
|
||||
if (customerJson != null) {
|
||||
LoginCustomer customer = new LoginCustomer();
|
||||
customer.setId(customerJson.getLong("id"));
|
||||
customer.setCustomerType(customerJson.getInteger("customerType"));
|
||||
customer.setCustomerName(customerJson.getString("customerName"));
|
||||
customer.setShortName(customerJson.getString("shortName"));
|
||||
customer.setLogo(customerJson.getString("logo"));
|
||||
customer.setCustomerStatus(customerJson.getInteger("customerStatus"));
|
||||
customer.setAuditRemark(customerJson.getString("auditRemark"));
|
||||
customer.setAdminName(customerJson.getString("adminName"));
|
||||
customer.setAdminPhone(customerJson.getString("adminPhone"));
|
||||
customer.setProvince(customerJson.getString("province"));
|
||||
customer.setCity(customerJson.getString("city"));
|
||||
customer.setIndustry(customerJson.getString("industry"));
|
||||
customer.setIndustrySub(customerJson.getString("industrySub"));
|
||||
session.setCustomer(customer);
|
||||
}
|
||||
}
|
||||
|
||||
AuthContext.setLoginInfo(session);
|
||||
}
|
||||
|
||||
return pjp.proceed();
|
||||
} finally {
|
||||
AuthContext.clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.apes.commons.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 登录客户(企业)信息(从 Redis 会话中反序列化)
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
*/
|
||||
@Data
|
||||
public class LoginCustomer implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Integer customerType;
|
||||
|
||||
private String customerName;
|
||||
|
||||
private String shortName;
|
||||
|
||||
private String logo;
|
||||
|
||||
private Integer customerStatus;
|
||||
|
||||
private String auditRemark;
|
||||
|
||||
private String adminName;
|
||||
|
||||
private String adminPhone;
|
||||
|
||||
private String province;
|
||||
|
||||
private String city;
|
||||
|
||||
private String industry;
|
||||
|
||||
private String industrySub;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.apes.commons.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 登录用户信息(从 Redis 会话中反序列化)
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
*/
|
||||
@Data
|
||||
public class LoginUser implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String portrait;
|
||||
|
||||
private String email;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.apes.commons.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户会话(AuthContext ThreadLocal 中存储的对象)
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
*/
|
||||
@Data
|
||||
public class UserSession implements Serializable {
|
||||
|
||||
private LoginUser user;
|
||||
|
||||
private LoginCustomer customer;
|
||||
|
||||
private String token;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.apes.commons.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 基础数据库实体
|
||||
* 从 saas-service 的 apes-commons 0.0.7-SNAPSHOT 提取内联
|
||||
* <p>
|
||||
* 提供主键 id、创建时间、更新时间三个公共字段
|
||||
*/
|
||||
@Data
|
||||
public class DbEntity implements Serializable {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标记(0=未删除, 1=已删除)
|
||||
*/
|
||||
private Integer isDel;
|
||||
}
|
||||
Reference in New Issue
Block a user