diff --git a/src/main/java/net/educoder/ecsonar/config/CustomExceptionHandler.java b/src/main/java/net/educoder/ecsonar/config/CustomExceptionHandler.java index ee50b5b..c44a5e1 100644 --- a/src/main/java/net/educoder/ecsonar/config/CustomExceptionHandler.java +++ b/src/main/java/net/educoder/ecsonar/config/CustomExceptionHandler.java @@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletRequest; public class CustomExceptionHandler { private static final Logger LOGGER = LoggerFactory.getLogger(CustomExceptionHandler.class); + /** * 处理Exception异常 * @@ -61,7 +62,7 @@ public class CustomExceptionHandler { @ExceptionHandler(BusinessException.class) @ResponseBody public ResponseResult handleException(HttpServletRequest request, BusinessException e) { - LOGGER.error("接口:"+request.getRequestURI()+",BusinessException异常:",e); + LOGGER.error("接口:" + request.getRequestURI() + ",BusinessException异常:", e); return ResponseResult.error(e.getMessage()); } diff --git a/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceConfig.java b/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceConfig.java index 99e90a4..92ac9e3 100644 --- a/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceConfig.java +++ b/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceConfig.java @@ -26,7 +26,7 @@ public class DynamicDataSourceConfig { public static final String MASTER = "master"; public static final String READONLY = "readonly"; - private static final List INIT_SQLS= Arrays.asList("SET NAMES utf8mb4"); + private static final List INIT_SQLS = Arrays.asList("SET NAMES utf8mb4"); @Value("${spring.datasource.master.driverClassName}") private String masterDriverClass; diff --git a/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceContextHolder.java b/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceContextHolder.java index 221b7a3..a431fea 100644 --- a/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceContextHolder.java +++ b/src/main/java/net/educoder/ecsonar/config/DynamicDataSourceContextHolder.java @@ -11,24 +11,26 @@ public class DynamicDataSourceContextHolder { * 动态数据源名称上下文 */ private static final ThreadLocal DATASOURCE_CONTEXT_KEY_HOLDER = new ThreadLocal<>(); + /** * 设置/切换数据源 */ - public static void setContextKey(String key){ + public static void setContextKey(String key) { DATASOURCE_CONTEXT_KEY_HOLDER.set(key); } + /** * 获取数据源名称 */ - public static String getContextKey(){ + public static String getContextKey() { String key = DATASOURCE_CONTEXT_KEY_HOLDER.get(); - return key == null? DynamicDataSourceConfig.MASTER: key; + return key == null ? DynamicDataSourceConfig.MASTER : key; } /** * 删除当前数据源名称 */ - public static void removeContextKey(){ + public static void removeContextKey() { DATASOURCE_CONTEXT_KEY_HOLDER.remove(); } diff --git a/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java b/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java index dd993a8..79afd87 100644 --- a/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java +++ b/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java @@ -22,7 +22,7 @@ public class ThreadPoolConfig { @Bean("sonarQueryResultPool") public ExecutorService queryResultPool() { - ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarScanner-pool-"); + ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarQueryResult-pool-"); return new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), sonarQueryResultPool, diff --git a/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java b/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java index 571e52f..d649d87 100644 --- a/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java +++ b/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java @@ -45,10 +45,6 @@ public class WebMvcConfiguration implements WebMvcConfigurer { supportedMediaTypes.add(MediaType.TEXT_XML); fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes); -// FastJsonConfig fastJsonConfig = new FastJsonConfig(); -// fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteMapNullValue); -// -// fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); converters.add(0,fastJsonHttpMessageConverter); } } diff --git a/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java b/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java index be97833..da46db8 100644 --- a/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java +++ b/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java @@ -82,12 +82,12 @@ public class QualityInspectRunnable implements Runnable { } // 调用sonar服务 - LOGGER.info("projectName:{}, detailId:{} 开始调用sonar分析,语言:{}", projectName,taskInfoDetail.getId(),language); + LOGGER.info("projectName:{}, detailId:{} 开始调用sonar分析,语言:{}", projectName, taskInfoDetail.getId(), language); sonarService.sonar(language, param); // 提交一个查结果的任务 SonarQueryResultRunnable queryResultRunnable = new SonarQueryResultRunnable(projectName, taskInfoDetail.getId(), dbOperateService); - LOGGER.info("projectName:{}, detailId:{} 提交了查询结果的任务", projectName,taskInfoDetail.getId()); + LOGGER.info("projectName:{}, detailId:{} 提交了查询结果的任务", projectName, taskInfoDetail.getId()); queryResultPool.execute(queryResultRunnable); } diff --git a/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java b/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java index 860d3a8..6df53d1 100644 --- a/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java +++ b/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java @@ -1,9 +1,7 @@ package net.educoder.ecsonar.task; -import net.educoder.ecsonar.model.api.Person; import net.educoder.ecsonar.model.api.SonarRequest; import net.educoder.ecsonar.services.SonarService; -import net.educoder.ecsonar.utils.UrlUtil; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,7 +12,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.net.URLConnection; -import java.net.URLDecoder; /** * @Author: youys diff --git a/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java b/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java index 715fc26..4143ecf 100644 --- a/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java +++ b/src/main/java/net/educoder/ecsonar/task/SonarQueryResultRunnable.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; /** * @Author: youys * @Date: 2022/1/18 - * @Description: + * @Description: 查询分析结果 */ public class SonarQueryResultRunnable implements Runnable { @@ -29,13 +29,13 @@ public class SonarQueryResultRunnable implements Runnable { @Override public void run() { - + int count = 0; String status; - while((status = dbOperateService.queryCeActivityStatus(projectName)) == null){ + while((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <=120){ + LOGGER.info("detailId:[{}],sonar还未执行完,次数:{}", detailId, count); try { Thread.sleep(1000); } catch (InterruptedException e) {} - LOGGER.info("detailId:[{}],sonar还未执行完", detailId); } // 查询 LOGGER.info("detailId:[{}], 查询sonar执行状态[{}]", detailId, status);