Commit a99c1ec0 by Lizh

删除无用的文件,修复自测中发现的问题

parent 34f0bdcc
package com.jomalls.custom.app.constant;
/**
* 返回状态码
*/
public class HttpStatus {
/**
* 操作成功
*/
public static final int SUCCESS = 200;
/**
* 对象创建成功
*/
public static final int CREATED = 201;
/**
* 请求已经被接受
*/
public static final int ACCEPTED = 202;
/**
* 操作已经执行成功,但是没有返回数据
*/
public static final int NO_CONTENT = 204;
/**
* 资源已被移除
*/
public static final int MOVED_PERM = 301;
/**
* 重定向
*/
public static final int SEE_OTHER = 303;
/**
* 资源没有被修改
*/
public static final int NOT_MODIFIED = 304;
/**
* 参数列表错误(缺少,格式不匹配)
*/
public static final int BAD_REQUEST = 400;
/**
* 未授权
*/
public static final int UNAUTHORIZED = 401;
/**
* 访问受限,授权过期
*/
public static final int FORBIDDEN = 403;
/**
* 资源,服务未找到
*/
public static final int NOT_FOUND = 404;
/**
* 不允许的http方法
*/
public static final int BAD_METHOD = 405;
/**
* 资源冲突,或者资源被锁
*/
public static final int CONFLICT = 409;
/**
* 不支持的数据,媒体类型
*/
public static final int UNSUPPORTED_TYPE = 415;
/**
* 系统内部错误
*/
public static final int ERROR = 500;
/**
* 接口未实现
*/
public static final int NOT_IMPLEMENTED = 501;
/**
* 系统警告消息
*/
public static final int WARN = 601;
}
package com.jomalls.custom.app.constant;
/**
* 用户常量信息
*/
public class UserConstants {
/**
* 平台内系统用户的唯一标志
*/
public static final String SYS_USER = "SYS_USER";
/**
* 正常状态
*/
public static final String NORMAL = "0";
/**
* 异常状态
*/
public static final String EXCEPTION = "1";
/**
* 用户封禁状态
*/
public static final String USER_DISABLE = "1";
/**
* 角色正常状态
*/
public static final String ROLE_NORMAL = "0";
/**
* 角色封禁状态
*/
public static final String ROLE_DISABLE = "1";
/**
* 部门正常状态
*/
public static final String DEPT_NORMAL = "0";
/**
* 部门停用状态
*/
public static final String DEPT_DISABLE = "1";
/**
* 字典正常状态
*/
public static final String DICT_NORMAL = "0";
/**
* 是否为系统默认(是)
*/
public static final String YES = "Y";
/**
* 是否菜单外链(是)
*/
public static final String YES_FRAME = "0";
/**
* 是否菜单外链(否)
*/
public static final String NO_FRAME = "1";
/**
* 菜单类型(目录)
*/
public static final String TYPE_DIR = "M";
/**
* 菜单类型(菜单)
*/
public static final String TYPE_MENU = "C";
/**
* 菜单类型(按钮)
*/
public static final String TYPE_BUTTON = "F";
/**
* Layout组件标识
*/
public final static String LAYOUT = "Layout";
/**
* ParentView组件标识
*/
public final static String PARENT_VIEW = "ParentView";
/**
* InnerLink组件标识
*/
public final static String INNER_LINK = "InnerLink";
/**
* 校验是否唯一的返回标识
*/
public final static boolean UNIQUE = true;
public final static boolean NOT_UNIQUE = false;
/**
* 用户名长度限制
*/
public static final int USERNAME_MIN_LENGTH = 2;
public static final int USERNAME_MAX_LENGTH = 20;
/**
* 密码长度限制
*/
public static final int PASSWORD_MIN_LENGTH = 5;
public static final int PASSWORD_MAX_LENGTH = 20;
}
package com.jomalls.custom.app.enums; package com.jomalls.custom.app.enums;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.Arrays; import java.util.Arrays;
......
...@@ -119,7 +119,7 @@ public class CustomProductItemServiceImpl implements CustomProductItemService { ...@@ -119,7 +119,7 @@ public class CustomProductItemServiceImpl implements CustomProductItemService {
} }
// 价格未变则跳过 // 价格未变则跳过
if (newPrice.compareTo(item.getSalesPrice()) == 0) { if (item.getSalesPrice() != null && newPrice.compareTo(item.getSalesPrice()) == 0) {
continue; continue;
} }
......
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
/** /**
* Bean映射工具类 * Bean映射工具类
* 使用Jackson实现,支持复杂嵌套对象转换 * 使用Jackson实现,支持复杂嵌套对象转换
* * <p>
* 支持的复杂场景: * 支持的复杂场景:
* 1. 嵌套对象(对象内包含另一个对象) * 1. 嵌套对象(对象内包含另一个对象)
* 2. 集合类型(List, Set, Map) * 2. 集合类型(List, Set, Map)
......
package com.jomalls.custom.app.utils; package com.jomalls.custom.app.utils;
import com.alibaba.ttl.TransmittableThreadLocal;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
/** /**
* @Author: Lizh * @Author: Lizh
* @Date: 2026/6/2 10:26 * @Date: 2026/6/2 10:26
* @Description: * @Description: 请求上下文持有者,使用 TransmittableThreadLocal 支持线程池场景下的上下文透传
* @Version: 1.0 * @Version: 1.0
*/ */
public class RequestHolder { public class RequestHolder {
private static final ThreadLocal<HttpServletRequest> REQUEST_CONTEXT_HOLDER = new InheritableThreadLocal<>(); private static final TransmittableThreadLocal<HttpServletRequest> REQUEST_CONTEXT_HOLDER = new TransmittableThreadLocal<>();
public RequestHolder() { public RequestHolder() {
} }
......
...@@ -57,5 +57,10 @@ ...@@ -57,5 +57,10 @@
<artifactId>commons-collections</artifactId> <artifactId>commons-collections</artifactId>
<version>3.2.2</version> <version>3.2.2</version>
</dependency> </dependency>
<!-- 线程上下文透传:解决线程池场景下 InheritableThreadLocal 值传递问题 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
package com.jomalls.custom.security; package com.jomalls.custom.security;
import com.alibaba.ttl.TransmittableThreadLocal;
/** /**
* 安全服务工具类 * @Author: Lizh
* 支持子线程继承登录信息 * @Date: 2026/6/2 10:26
* @Description: 安全服务工具类,使用 TransmittableThreadLocal 支持线程池场景下的上下文透传
* @Version: 1.0
*/ */
public class SecurityUtils { public class SecurityUtils {
/** /**
* 线程本地变量 - 支持子线程继承 * 线程本地变量 - 支持线程池场景下的上下文透传
* InheritableThreadLocal 允许子线程继承父线程的值
*/ */
private static final InheritableThreadLocal<LoginUser> THREAD_LOCAL = new InheritableThreadLocal<>(); private static final TransmittableThreadLocal<LoginUser> THREAD_LOCAL = new TransmittableThreadLocal<>();
/** /**
* 设置登录用户 * 设置登录用户
......
...@@ -8,7 +8,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -8,7 +8,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
* 启动类 * 启动类
* *
* @author lizh * @author Lizh
* @date 2026-05-26 18:25:27 * @date 2026-05-26 18:25:27
*/ */
@SpringBootApplication @SpringBootApplication
......
package com.jomalls.custom.config; package com.jomalls.custom.config;
import com.jomalls.custom.security.LoginUser; import com.alibaba.ttl.TtlRunnable;
import com.jomalls.custom.security.SecurityUtils;
import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NonNull;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
...@@ -13,7 +12,7 @@ import java.util.concurrent.TimeUnit; ...@@ -13,7 +12,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* @Author: Lizh * @Author: Lizh
* @Date: 2026/6/2 16:27 * @Date: 2026/6/2 16:27
* @Description: 上下文传递线程池,将主线程的LoginUser传递到工作线程,确保异步任务中可以获取当前用户信息 * @Description: 上下文传递线程池,通过重写 execute() 使用 TtlRunnable 自动透传线程上下文,
* @Version: 1.0 * @Version: 1.0
*/ */
public class CustomServerThreadPoolExecutor extends ThreadPoolExecutor { public class CustomServerThreadPoolExecutor extends ThreadPoolExecutor {
...@@ -28,20 +27,6 @@ public class CustomServerThreadPoolExecutor extends ThreadPoolExecutor { ...@@ -28,20 +27,6 @@ public class CustomServerThreadPoolExecutor extends ThreadPoolExecutor {
@Override @Override
public void execute(@NonNull Runnable command) { public void execute(@NonNull Runnable command) {
// 在提交线程中捕获用户信息 super.execute(TtlRunnable.get(command));
LoginUser loginUser = SecurityUtils.getLoginUser();
super.execute(() -> {
// 在工作线程中传递用户信息
if (loginUser != null) {
SecurityUtils.setLoginUser(loginUser);
}
try {
command.run();
} finally {
// 清理ThreadLocal,防止内存泄漏
SecurityUtils.clearLoginUser();
}
});
} }
} }
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.jomalls.custom.enums.CodeEnum; import com.jomalls.custom.enums.CodeEnum;
import com.jomalls.custom.page.PageAdapter; import com.jomalls.custom.page.PageAdapter;
import com.jomalls.custom.utils.R;
import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NonNull;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotatedElementUtils;
...@@ -25,7 +26,7 @@ import java.util.List; ...@@ -25,7 +26,7 @@ import java.util.List;
/** /**
* 统一返回处理 * 统一返回处理
* @author lizh * @author Lizh
* @date 2026-05-28 10:25:27 * @date 2026-05-28 10:25:27
*/ */
@ControllerAdvice @ControllerAdvice
...@@ -47,7 +48,7 @@ public class RestResponseBodyConfig implements ResponseBodyAdvice<Object> { ...@@ -47,7 +48,7 @@ public class RestResponseBodyConfig implements ResponseBodyAdvice<Object> {
public Object beforeBodyWrite(Object body, @NonNull MethodParameter returnType, public Object beforeBodyWrite(Object body, @NonNull MethodParameter returnType,
MediaType selectedContentType, MediaType selectedContentType,
@NonNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NonNull Class<? extends HttpMessageConverter<?>> selectedConverterType,
@NonNull ServerHttpRequest request, ServerHttpResponse response) { @NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response) {
String json = "application/json"; String json = "application/json";
String text = "text/plain"; String text = "text/plain";
if (!selectedContentType.toString().toLowerCase().contains(json) if (!selectedContentType.toString().toLowerCase().contains(json)
...@@ -57,7 +58,7 @@ public class RestResponseBodyConfig implements ResponseBodyAdvice<Object> { ...@@ -57,7 +58,7 @@ public class RestResponseBodyConfig implements ResponseBodyAdvice<Object> {
String requestPath = request.getURI().getPath(); String requestPath = request.getURI().getPath();
ServletServerHttpResponse httpResponse = (ServletServerHttpResponse) response; ServletServerHttpResponse httpResponse = (ServletServerHttpResponse) response;
if (httpResponse.getServletResponse().getStatus() == HttpStatus.NOT_FOUND.value()) { if (httpResponse.getServletResponse().getStatus() == HttpStatus.NOT_FOUND.value()) {
return com.jomalls.custom.utils.R.fail(CodeEnum.NOT_FOUND); return R.fail(CodeEnum.NOT_FOUND);
} else if (this.isNoWrapResponseUrl(requestPath)) { } else if (this.isNoWrapResponseUrl(requestPath)) {
return body; return body;
} else { } else {
...@@ -67,12 +68,12 @@ public class RestResponseBodyConfig implements ResponseBodyAdvice<Object> { ...@@ -67,12 +68,12 @@ public class RestResponseBodyConfig implements ResponseBodyAdvice<Object> {
} }
if (body instanceof String) { if (body instanceof String) {
try { try {
return objectMapper.writeValueAsString(com.jomalls.custom.utils.R.ok(body)); return objectMapper.writeValueAsString(R.ok(body));
} catch (Exception e) { } catch (Exception e) {
return body; return body;
} }
} }
return body instanceof com.jomalls.custom.utils.R ? body : com.jomalls.custom.utils.R.ok(body); return body instanceof R ? body : R.ok(body);
} }
} }
} }
......
...@@ -14,8 +14,10 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -14,8 +14,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
/** /**
* 安全拦截器 * @Author: Lizh
* 负责用户登录权限检查,保存登录信息到线程本地变量 * @Date: 2026/6/2 16:27
* @Description: 安全拦截器,负责用户登录权限检查,保存登录信息到线程本地变量
* @Version: 1.0
*/ */
@Slf4j @Slf4j
public class SecurityInterceptor implements HandlerInterceptor { public class SecurityInterceptor implements HandlerInterceptor {
......
package com.jomalls.custom.config;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WebConfig {
}
\ No newline at end of file
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<log4j.version>2.23.1</log4j.version> <log4j.version>2.23.1</log4j.version>
<fastjson2.version>2.0.54</fastjson2.version> <fastjson2.version>2.0.54</fastjson2.version>
<mybatis-plus.version>3.5.8</mybatis-plus.version> <mybatis-plus.version>3.5.8</mybatis-plus.version>
<transmittable-thread-local.version>2.14.5</transmittable-thread-local.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>
...@@ -120,6 +121,12 @@ ...@@ -120,6 +121,12 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>${commons-io.version}</version> <version>${commons-io.version}</version>
</dependency> </dependency>
<!-- 线程上下文透传:解决线程池场景下 ThreadLocal 值传递问题 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
<version>${transmittable-thread-local.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<modules> <modules>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment