fix(质量分析): 增加查询代码字段shixunCodeIds

master
youys 2 months ago
parent 6fb9fb7db1
commit 268808fb1b

@ -9,7 +9,11 @@ import org.apache.ibatis.annotations.Select;
* @Description:
*/
public interface GameCodesDao {
@Select("select new_code code,path from game_codes where id=#{id}")
GameCodes queryOriginalCodeById(Long id);
@Select("select code,path from student_work_shixun_codes where id=#{id}")
GameCodes queryShiXunOriginalCodeById(Long id);
}

@ -20,7 +20,8 @@ public interface TaskInfoDetailDao {
*
* @param taskInfoDetail
*/
@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})")
@Insert("insert into task_info_detail(id,task_id,project_name,student_id,user_id,name,code_ids, shixun_code_ids) " +
"values(#{id},#{taskId},#{projectName},#{studentId},#{userId} ,#{name},#{codeIds}, #{shiXunCodeIds})")
void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);
/**
@ -47,7 +48,9 @@ public interface TaskInfoDetailDao {
* @param id
* @return
*/
@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}")
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name," +
"code_ids codeIds,shixun_code_ids shiXunCodeIds, status,create_time createTime,update_time updateTime " +
"from task_info_detail where id=#{id}")
TaskInfoDetail selectById(String id);
/**
@ -69,6 +72,9 @@ public interface TaskInfoDetailDao {
* @param position
* @return
*/
@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<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("position") Integer position);
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name," +
"code_ids codeIds,shixun_code_ids shiXunCodeIds, status,create_time createTime,update_time updateTime " +
"from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
List<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId,
@Param("pageSize") Integer pageSize, @Param("position") Integer position);
}

@ -16,6 +16,7 @@ public class TaskInfoDetail {
private Long userId;
private String name;
private String codeIds;
private String shiXunCodeIds;
/**
* 0 1 -1
*/
@ -103,4 +104,12 @@ public class TaskInfoDetail {
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getShiXunCodeIds() {
return shiXunCodeIds;
}
public void setShiXunCodeIds(String shiXunCodeIds) {
this.shiXunCodeIds = shiXunCodeIds;
}
}

@ -30,6 +30,8 @@ public class QualityInspectUserDataVO implements Serializable {
*/
private List<Long> codeIds;
private List<Long> studentWorkShixunCodeIds;
public String getStudentId() {
return studentId;
}
@ -61,4 +63,12 @@ public class QualityInspectUserDataVO implements Serializable {
public void setUserId(Long userId) {
this.userId = userId;
}
public List<Long> getStudentWorkShixunCodeIds() {
return studentWorkShixunCodeIds;
}
public void setStudentWorkShixunCodeIds(List<Long> studentWorkShixunCodeIds) {
this.studentWorkShixunCodeIds = studentWorkShixunCodeIds;
}
}

@ -45,6 +45,13 @@ public class DbOperateService {
return gameCode;
}
public GameCodes queryShiXunCodesById(Long id) {
DynamicDataSourceContextHolder.setContextKey(DynamicDataSourceConfig.READONLY);
GameCodes gameCode = gameCodesDao.queryShiXunOriginalCodeById(id);
DynamicDataSourceContextHolder.removeContextKey();
return gameCode;
}
/**
*
*

@ -108,6 +108,7 @@ public class QualityInspectService {
taskInfoDetail.setStudentId(userData.getStudentId());
taskInfoDetail.setUserId(userData.getUserId());
taskInfoDetail.setCodeIds(userData.getCodeIds().toString());
taskInfoDetail.setShiXunCodeIds(userData.getStudentWorkShixunCodeIds().toString());
taskInfoDetailDao.insertTaskInfoDetail(taskInfoDetail);

@ -15,8 +15,11 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
/**
@ -41,9 +44,9 @@ public class QualityInspectRunnable implements Runnable {
private SonarService sonarService;
public QualityInspectRunnable(String taskId, String language, String homeworkId,
TaskInfoDetail taskInfoDetail,
QualityInspectUserDataVO userData,
ExecutorService queryResultPool) {
TaskInfoDetail taskInfoDetail,
QualityInspectUserDataVO userData,
ExecutorService queryResultPool) {
this.taskId = taskId;
this.language = language;
this.homeworkId = homeworkId;
@ -59,43 +62,17 @@ public class QualityInspectRunnable implements Runnable {
String path = String.format("/tmp/%s/%s/", homeworkId, projectName);
List<Long> codeIds = userData.getCodeIds();
boolean constantCFlag = true,constantCPPFlag = true,constantJavaFlag = true, constantPyFlag = true;
for (Long codeId : codeIds) {
File file = new File(path);
try {
FileUtils.forceMkdir(file);
} catch (IOException e) {
}
List<Long> shiXunCodeIds = userData.getStudentWorkShixunCodeIds();
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"));
if (constantCFlag && gameCodes.getPath().toLowerCase().contains(".c")) {
constantCFlag = false;
} else if (constantCPPFlag && gameCodes.getPath().toLowerCase().contains(".cpp")) {
constantCPPFlag = false;
} else if (constantJavaFlag && gameCodes.getPath().toLowerCase().contains(".java")) {
constantJavaFlag = false;
} else if (constantPyFlag && gameCodes.getPath().toLowerCase().contains(".py")) {
constantPyFlag = false;
}
for (Long codeId : codeIds) {
processCodeId(codeId, path, projectName, dbOperateService::queryGameCodesById);
}
// 需要自己判别语言,Java优先
if(!constantJavaFlag){
language = Constant.JAVA;
}else if(!constantPyFlag){
language = Constant.PYTHON;
} else if(!constantCFlag){
language = Constant.C;
}else if(!constantCPPFlag){
language = Constant.CXX;
for (Long codeId : shiXunCodeIds) {
processCodeId(codeId, path, projectName, dbOperateService::queryShiXunCodesById);
}
// 写完所有文件开始用sonar进行质量分析
SonarScannerParam param = new SonarScannerParam(projectName, path);
if (Constant.C.equalsIgnoreCase(language) || Constant.CXX.equalsIgnoreCase(language)) {
@ -133,4 +110,45 @@ public class QualityInspectRunnable implements Runnable {
public void setSonarService(SonarService sonarService) {
this.sonarService = sonarService;
}
private void processCodeId(Long codeId, String path, String projectName, Function<Long, GameCodes> queryMethod) {
boolean constantCFlag = true, constantCPPFlag = true, constantJavaFlag = true, constantPyFlag = true;
File file = new File(path);
try {
FileUtils.forceMkdir(file);
} catch (IOException e) {
LOGGER.error("创建目录失败: {}", path, e);
}
GameCodes gameCodes = queryMethod.apply(codeId);
if (gameCodes == null) {
LOGGER.error("projectName:{}, game_codes_id:{} 找不到对应的学员代码", projectName, codeId);
return;
}
Path filePath = Paths.get(path, gameCodes.getPath());
FileUtil.writeString(gameCodes.getCode(), filePath.toString(), Charset.forName("UTF-8"));
String filePathLower = gameCodes.getPath().toLowerCase();
if (constantCFlag && filePathLower.matches(".*\\.c$")) {
constantCFlag = false;
} else if (constantCPPFlag && filePathLower.matches(".*\\.cpp$")) {
constantCPPFlag = false;
} else if (constantJavaFlag && filePathLower.matches(".*\\.java$")) {
constantJavaFlag = false;
} else if (constantPyFlag && filePathLower.matches(".*\\.py$")) {
constantPyFlag = false;
}
// 需要自己判别语言,Java优先
if (!constantJavaFlag) {
language = Constant.JAVA;
} else if (!constantPyFlag) {
language = Constant.PYTHON;
} else if (!constantCFlag) {
language = Constant.C;
} else if (!constantCPPFlag) {
language = Constant.CXX;
}
}
}

@ -6,7 +6,7 @@
spring.datasource.initSize=20
#spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
spring.datasource.master.url=jdbc:postgresql://117.50.14.123:5432/sonar
spring.datasource.master.url=jdbc:postgresql://106.75.25.158:5432/sonar
spring.datasource.master.username=sonar
spring.datasource.master.password=sonar
spring.datasource.master.driverClassName=org.postgresql.Driver
@ -14,7 +14,7 @@ spring.datasource.master.driverClassName=org.postgresql.Driver
#### test ######
spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver
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.url=jdbc:mysql://testeducoder-public.mysql.polardb.rds.aliyuncs.com:3306/newtesteducoderweb?userSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring.datasource.readonly.username=testeducoder
spring.datasource.readonly.password=TEST@123

Loading…
Cancel
Save