diff --git a/pom.xml b/pom.xml
index acabb25..62f400a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,12 @@
test
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
com.alibaba
druid-spring-boot-starter
diff --git a/src/main/java/net/educoder/ecsonar/EcsonarApplication.java b/src/main/java/net/educoder/ecsonar/EcsonarApplication.java
index 4554952..c7ad01f 100644
--- a/src/main/java/net/educoder/ecsonar/EcsonarApplication.java
+++ b/src/main/java/net/educoder/ecsonar/EcsonarApplication.java
@@ -3,7 +3,9 @@ package net.educoder.ecsonar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+@EnableAspectJAutoProxy
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class EcsonarApplication {
diff --git a/src/main/java/net/educoder/ecsonar/config/RequestAop.java b/src/main/java/net/educoder/ecsonar/config/RequestAop.java
new file mode 100644
index 0000000..40c780c
--- /dev/null
+++ b/src/main/java/net/educoder/ecsonar/config/RequestAop.java
@@ -0,0 +1,76 @@
+package net.educoder.ecsonar.config;
+
+import com.alibaba.fastjson.JSONObject;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+
+/**
+ * @author youys
+ * @data 2019/8/13
+ * @description 请求日志打印
+ */
+@Aspect
+@Component
+public class RequestAop {
+
+ private Logger log = LoggerFactory.getLogger(RequestAop.class);
+ /**
+ * 声明一个切点,controller包下和子包下的所有类所有方法
+ */
+ @Pointcut("execution(* net.educoder.ecsonar.controller.*.*(..))")
+ public void pointCut() {
+ }
+
+ @Around("pointCut()")
+ public Object pintLog(ProceedingJoinPoint pjp) throws Throwable {
+ Long startTime = System.currentTimeMillis();
+
+ ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ HttpServletRequest request = requestAttributes.getRequest();
+ String requestUrl = request.getRequestURL().toString();
+
+ // 打印请求内容
+ log.info("|===============请求内容 start ==============================|");
+ log.info("|请求地址:" + requestUrl);
+ log.info("|请求方式:" + request.getMethod());
+ log.info("|请求类方法:" + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
+
+ //获取所有参数
+ Enumeration enu = request.getParameterNames();
+ StringBuilder params = new StringBuilder("【");
+ while (enu.hasMoreElements()) {
+ String paraName = enu.nextElement();
+ params.append(paraName).append("=").append(request.getParameter(paraName)).append(";");
+ }
+ params.append("】");
+ log.info("|请求方法参数:" + params.toString());
+
+ Enumeration headersEnu = request.getHeaderNames();
+ StringBuilder headersParams = new StringBuilder("【");
+ while (headersEnu.hasMoreElements()) {
+ String headerName = headersEnu.nextElement();
+ headersParams.append(headerName).append("=").append(request.getHeader(headerName)).append(";");
+ }
+ headersParams.append("】");
+
+ log.info("|请求Header信息:{}", headersParams.toString());
+ log.info("|===============请求内容 end ================================|");
+
+ Object result = pjp.proceed();
+ long endTime = System.currentTimeMillis();
+
+ log.info("调用方法: {},返回结果response==>>{}", requestUrl, JSONObject.toJSONString(result));
+ log.info("调用方法: {},请求耗时==>> {} ms", requestUrl, endTime - startTime);
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java b/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java
index 79afd87..1c91efe 100644
--- a/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java
+++ b/src/main/java/net/educoder/ecsonar/config/ThreadPoolConfig.java
@@ -14,7 +14,7 @@ public class ThreadPoolConfig {
@Primary
public ExecutorService sonarScannerPool() {
ThreadFactory sonarScannerPool = new CustomizableThreadFactory("sonarScanner-pool-");
- return new ThreadPoolExecutor(10, 10, 60,
+ return new ThreadPoolExecutor(20, 20, 0,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), sonarScannerPool,
new ThreadPoolExecutor.AbortPolicy());
}
@@ -23,7 +23,7 @@ public class ThreadPoolConfig {
@Bean("sonarQueryResultPool")
public ExecutorService queryResultPool() {
ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarQueryResult-pool-");
- return new ThreadPoolExecutor(5, 10, 60,
+ return new ThreadPoolExecutor(10, 10, 0,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000),
sonarQueryResultPool,
new ThreadPoolExecutor.AbortPolicy());
diff --git a/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java b/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java
index d649d87..500f0e3 100644
--- a/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java
+++ b/src/main/java/net/educoder/ecsonar/config/WebMvcConfiguration.java
@@ -1,12 +1,9 @@
package net.educoder.ecsonar.config;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.ArrayList;
@@ -45,6 +42,6 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
supportedMediaTypes.add(MediaType.TEXT_XML);
fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
- converters.add(0,fastJsonHttpMessageConverter);
+ converters.add(0, fastJsonHttpMessageConverter);
}
}
diff --git a/src/main/java/net/educoder/ecsonar/constant/Constant.java b/src/main/java/net/educoder/ecsonar/constant/Constant.java
index 1a6294e..51f9e2b 100644
--- a/src/main/java/net/educoder/ecsonar/constant/Constant.java
+++ b/src/main/java/net/educoder/ecsonar/constant/Constant.java
@@ -11,10 +11,10 @@ import java.util.List;
public class Constant {
- public static final String JAVA = "JAVA";
- public static final String C = "C";
- public static final String CXX = "C++";
- public static final String PYTHON = "PYTHON";
+ public static final String JAVA = "java";
+ public static final String C = "c";
+ public static final String CXX = "cpp";
+ public static final String PYTHON = "python";
public static final List language = Arrays.asList(JAVA, C, CXX, PYTHON);
}
diff --git a/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java b/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java
index f6a3725..675d6e8 100644
--- a/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java
+++ b/src/main/java/net/educoder/ecsonar/controller/QualityInspectController.java
@@ -1,10 +1,12 @@
package net.educoder.ecsonar.controller;
+import com.alibaba.fastjson.JSONArray;
import net.educoder.ecsonar.constant.Constant;
import net.educoder.ecsonar.model.RollPage;
import net.educoder.ecsonar.model.api.QualityInspect;
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
import net.educoder.ecsonar.model.api.QualityInspectResultData;
+import net.educoder.ecsonar.model.vo.QualityInspectUserDataVO;
import net.educoder.ecsonar.model.vo.QualityInspectVO;
import net.educoder.ecsonar.services.QualityInspectService;
import net.educoder.ecsonar.utils.ResponseResult;
@@ -12,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
+import java.util.List;
+
/**
* @Author: youys
* @Date: 2022/1/17
@@ -32,7 +36,13 @@ public class QualityInspectController {
*/
@RequestMapping(value = "qualityInspect", method = RequestMethod.POST)
@ResponseBody
- public ResponseResult qualityInspect(@RequestBody QualityInspectVO qualityInspectVO){
+ public ResponseResult qualityInspect(@RequestParam String language,
+ @RequestParam String homeworkId,
+ @RequestParam String userDatas){
+
+ List userDataVOList = JSONArray.parseArray(userDatas,QualityInspectUserDataVO.class);
+
+ QualityInspectVO qualityInspectVO = new QualityInspectVO(language, homeworkId, userDataVOList);
if (!Constant.language.contains(qualityInspectVO.getLanguage())) {
return ResponseResult.error("不支持的语言");
}
diff --git a/src/main/java/net/educoder/ecsonar/dao/TaskInfoDetailDao.java b/src/main/java/net/educoder/ecsonar/dao/TaskInfoDetailDao.java
index 23c82aa..fc69287 100644
--- a/src/main/java/net/educoder/ecsonar/dao/TaskInfoDetailDao.java
+++ b/src/main/java/net/educoder/ecsonar/dao/TaskInfoDetailDao.java
@@ -20,7 +20,7 @@ public interface TaskInfoDetailDao {
*
* @param taskInfoDetail
*/
- @Insert("insert into task_info_detail(id,task_id,project_name,student_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{name},#{codeIds})")
+ @Insert("insert into task_info_detail(id,task_id,project_name,student_id,user_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{userId} ,#{name},#{codeIds})")
void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);
/**
@@ -47,7 +47,7 @@ public interface TaskInfoDetailDao {
* @param id
* @return
*/
- @Select("select id,task_id taskId,project_name projectName,student_id studentId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
+ @Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
TaskInfoDetail selectById(String id);
/**
@@ -69,6 +69,6 @@ public interface TaskInfoDetailDao {
* @param position
* @return
*/
- @Select("select id,task_id taskId,project_name projectName,student_id studentId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
+ @Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
List selectTaskInfoDetailPageList(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("position") Integer position);
}
diff --git a/src/main/java/net/educoder/ecsonar/model/TaskInfoDetail.java b/src/main/java/net/educoder/ecsonar/model/TaskInfoDetail.java
index 9da4ed2..1f34deb 100644
--- a/src/main/java/net/educoder/ecsonar/model/TaskInfoDetail.java
+++ b/src/main/java/net/educoder/ecsonar/model/TaskInfoDetail.java
@@ -13,6 +13,7 @@ public class TaskInfoDetail {
private String taskId;
private String projectName;
private String studentId;
+ private Long userId;
private String name;
private String codeIds;
/**
@@ -55,6 +56,14 @@ public class TaskInfoDetail {
this.studentId = studentId;
}
+ public Long getUserId() {
+ return userId;
+ }
+
+ public void setUserId(Long userId) {
+ this.userId = userId;
+ }
+
public String getName() {
return name;
}
diff --git a/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java b/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java
index 78d1d58..22da559 100644
--- a/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java
+++ b/src/main/java/net/educoder/ecsonar/model/api/QualityInspectResultData.java
@@ -18,6 +18,11 @@ public class QualityInspectResultData {
*/
private String studentId;
+ /**
+ * 用户id
+ */
+ private Long userId;
+
/**
* 姓名
*/
@@ -67,6 +72,14 @@ public class QualityInspectResultData {
this.studentId = studentId;
}
+ public Long getUserId() {
+ return userId;
+ }
+
+ public void setUserId(Long userId) {
+ this.userId = userId;
+ }
+
public String getName() {
return name;
}
diff --git a/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectUserDataVO.java b/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectUserDataVO.java
index 069ed63..978560b 100644
--- a/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectUserDataVO.java
+++ b/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectUserDataVO.java
@@ -1,5 +1,6 @@
package net.educoder.ecsonar.model.vo;
+import java.io.Serializable;
import java.util.List;
/**
@@ -7,12 +8,18 @@ import java.util.List;
* @Date: 2022/1/17
* @Description:
*/
-public class QualityInspectUserDataVO {
+public class QualityInspectUserDataVO implements Serializable {
/**
* 学号
*/
private String studentId;
+
+ /**
+ * 用户id
+ */
+ private Long userId;
+
/**
* 姓名
*/
@@ -46,4 +53,12 @@ public class QualityInspectUserDataVO {
public void setCodeIds(List codeIds) {
this.codeIds = codeIds;
}
+
+ public Long getUserId() {
+ return userId;
+ }
+
+ public void setUserId(Long userId) {
+ this.userId = userId;
+ }
}
diff --git a/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectVO.java b/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectVO.java
index c8f9866..1005759 100644
--- a/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectVO.java
+++ b/src/main/java/net/educoder/ecsonar/model/vo/QualityInspectVO.java
@@ -1,5 +1,6 @@
package net.educoder.ecsonar.model.vo;
+import java.io.Serializable;
import java.util.List;
/**
@@ -7,12 +8,17 @@ import java.util.List;
* @Date: 2022/1/17
* @Description:
*/
-public class QualityInspectVO {
+public class QualityInspectVO implements Serializable {
private String language;
private String homeworkId;
private List userDatas;
+ public QualityInspectVO(String language, String homeworkId, List userDatas) {
+ this.language = language;
+ this.homeworkId = homeworkId;
+ this.userDatas = userDatas;
+ }
public String getLanguage() {
return language;
diff --git a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java
index 1879b4c..0058eaa 100644
--- a/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java
+++ b/src/main/java/net/educoder/ecsonar/services/QualityInspectService.java
@@ -89,6 +89,7 @@ public class QualityInspectService {
taskInfoDetail.setProjectName(String.format("%s-%s", qualityInspectVO.getHomeworkId(), userData.getStudentId()));
taskInfoDetail.setName(userData.getName());
taskInfoDetail.setStudentId(userData.getStudentId());
+ taskInfoDetail.setUserId(userData.getUserId());
taskInfoDetail.setCodeIds(userData.getCodeIds().toString());
taskInfoDetailDao.insertTaskInfoDetail(taskInfoDetail);
@@ -130,6 +131,7 @@ public class QualityInspectService {
QualityInspectResultData resultData = new QualityInspectResultData();
resultData.setName(taskInfoDetail.getName());
resultData.setStudentId(taskInfoDetail.getStudentId());
+ resultData.setUserId(taskInfoDetail.getUserId());
Metrics metrics = reportService.getMetrics(taskInfoDetail.getProjectName());
diff --git a/src/main/java/net/educoder/ecsonar/services/SonarService.java b/src/main/java/net/educoder/ecsonar/services/SonarService.java
index 01564c5..4fadce7 100644
--- a/src/main/java/net/educoder/ecsonar/services/SonarService.java
+++ b/src/main/java/net/educoder/ecsonar/services/SonarService.java
@@ -42,8 +42,8 @@ public class SonarService {
@Value("${sonar.url}")
String sonarUrl;
- @Value("${sonar.token}")
- String sonarToken;
+// @Value("${sonar.token}")
+// String sonarToken;
@Value("${extract.path}")
String extractProgramPath;
@@ -60,7 +60,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
- "-Dsonar.login=" + sonarToken + " " +
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
@@ -71,7 +70,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
- "-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.executeAndGetExitStatus(command);
@@ -82,7 +80,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
- "-Dsonar.login=" + sonarToken + " " +
"-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.executeAndGetExitStatus(command);
@@ -93,10 +90,10 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
- "-Dsonar.login=" + sonarToken + " " +
"-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
- SystemUtil.executeAndGetExitStatus(command);
+ SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
+ log.info("command:{}, result:{}", command, executeResp.getOutput());
});
}
@@ -188,7 +185,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + key + " " +
- "-Dsonar.login=" + sonarToken + " " +
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);
diff --git a/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java b/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java
index da46db8..339f1b1 100644
--- a/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java
+++ b/src/main/java/net/educoder/ecsonar/task/QualityInspectRunnable.java
@@ -67,6 +67,10 @@ public class QualityInspectRunnable implements Runnable {
}
GameCodes gameCodes = dbOperateService.queryGameCodesById(codeId);
+ if(gameCodes == null){
+ LOGGER.error("projectName:{}, game_codes_id:{}找不到对应的学员代码",projectName, codeId);
+ continue;
+ }
FileUtil.writeString(gameCodes.getCode(), path + gameCodes.getPath(), Charset.forName("UTF-8"));
}
diff --git a/src/main/java/net/educoder/ecsonar/utils/ResponseResult.java b/src/main/java/net/educoder/ecsonar/utils/ResponseResult.java
index b94fa1f..9b29f64 100644
--- a/src/main/java/net/educoder/ecsonar/utils/ResponseResult.java
+++ b/src/main/java/net/educoder/ecsonar/utils/ResponseResult.java
@@ -29,7 +29,7 @@ public class ResponseResult implements Serializable {
}
public static ResponseResult success(){
- return new ResponseResult(1,"success");
+ return new ResponseResult(0,"success");
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index d6f7f95..8f9fc25 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -12,10 +12,17 @@ spring.datasource.master.password=root
spring.datasource.master.driverClassName=org.postgresql.Driver
+#### test ######
spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver
-spring.datasource.readonly.url=jdbc:mysql://rm-bp1ht3504joktie83.mysql.rds.aliyuncs.com:3306/educoderweb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
-spring.datasource.readonly.username=readonly
-spring.datasource.readonly.password=readonly_20210901
+spring.datasource.readonly.url=jdbc:mysql://rm-bp13v5020p7828r5rso.mysql.rds.aliyuncs.com:3306/preeducoderweb?userSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
+spring.datasource.readonly.username=testeducoder
+spring.datasource.readonly.password=TEST@123
+
+#### prod ######
+#spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver
+#spring.datasource.readonly.url=jdbc:mysql://rm-bp1ht3504joktie83.mysql.rds.aliyuncs.com:3306/educoderweb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
+#spring.datasource.readonly.username=readonly
+#spring.datasource.readonly.password=readonly_20210901
# Hikari will use the above plus the following to setup connection pooling
#spring.datasource.type=com.zaxxer.hikari.HikariDataSource