Browse Source

feature 校验手机号的问题

xiahan 4 months ago
parent
commit
4629438dbd

+ 32 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/config/AsyncConfig.java

@@ -0,0 +1,32 @@
+package com.rongwei.zhsw.system.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+
+import java.lang.reflect.Method;
+
+/**
+ * AsyncConfig class
+ *
+ * @author XH
+ * @date 2025/04/03
+ */
+public class AsyncConfig implements AsyncConfigurer {
+    private static final Logger log = LoggerFactory.getLogger(AsyncConfig.class);
+
+    @Override
+    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
+        return new CustomAsyncExceptionHandler();
+    }
+
+    private static class CustomAsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
+        @Override
+        public void handleUncaughtException(Throwable ex, Method method, Object... params) {
+            // 记录异常日志或发送告警
+            log.error("Async method error: {}", ex.getMessage());
+            ex.printStackTrace();
+        }
+    }
+}

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/zhsw/system/config/ThreadPoolConfig.java

@@ -50,7 +50,7 @@ public class ThreadPoolConfig implements AsyncConfigurer {
                     runnable.run();
                 } finally {
                     // 清理子线程的上下文,避免内存泄漏
-                    RequestContextHolder.resetRequestAttributes();
+                    RequestContextHolder.resetRequestAttributes(); // 始终清理上下文
                 }
             };
         }

+ 2 - 2
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/BillGenerationServiceImpl.java

@@ -66,8 +66,6 @@ public class BillGenerationServiceImpl {
     @Async(value = "zhswThreadPool")
     public void asyncGenerateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList, ServletRequestAttributes attributes){
         RequestContextHolder.setRequestAttributes(attributes);
-        SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
-        log.info("当前生成账单的用户:{},所属的租户库为:{}", currentUser.getAccount(), currentUser.getTenantDo().getDskey());
         if (swWaterUsageEntryDoList == null || swWaterUsageEntryDoList.isEmpty()) {
             log.error("暂无需要生成账单的信息");
             return;
@@ -78,6 +76,8 @@ public class BillGenerationServiceImpl {
 
     public void generateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList) {
         log.debug("需要生成账单的抄表记录为:{}", swWaterUsageEntryDoList);
+        SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
+        log.error("判断上下文对象是否正常传递:{}",currentUser);
         // 对数据按照抄表日期排序
         List<SwWaterUsageEntryDo> collect = swWaterUsageEntryDoList.stream()
                 .sorted(Comparator.comparing(SwWaterUsageEntryDo::getCurrentreadingdate))