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

master
youys 2 months ago
parent 6fb9fb7db1
commit 268808fb1b

@ -12,4 +12,8 @@ public interface GameCodesDao {
@Select("select new_code code,path from game_codes where id=#{id}") @Select("select new_code code,path from game_codes where id=#{id}")
GameCodes queryOriginalCodeById(Long 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 * @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); void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);
/** /**
@ -47,7 +48,9 @@ public interface TaskInfoDetailDao {
* @param id * @param id
* @return * @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); TaskInfoDetail selectById(String id);
/** /**
@ -69,6 +72,9 @@ public interface TaskInfoDetailDao {
* @param position * @param position
* @return * @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}") @Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name," +
List<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("position") Integer position); "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 Long userId;
private String name; private String name;
private String codeIds; private String codeIds;
private String shiXunCodeIds;
/** /**
* 0 1 -1 * 0 1 -1
*/ */
@ -103,4 +104,12 @@ public class TaskInfoDetail {
public void setUpdateTime(Date updateTime) { public void setUpdateTime(Date updateTime) {
this.updateTime = 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> codeIds;
private List<Long> studentWorkShixunCodeIds;
public String getStudentId() { public String getStudentId() {
return studentId; return studentId;
} }
@ -61,4 +63,12 @@ public class QualityInspectUserDataVO implements Serializable {
public void setUserId(Long userId) { public void setUserId(Long userId) {
this.userId = 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; 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.setStudentId(userData.getStudentId());
taskInfoDetail.setUserId(userData.getUserId()); taskInfoDetail.setUserId(userData.getUserId());
taskInfoDetail.setCodeIds(userData.getCodeIds().toString()); taskInfoDetail.setCodeIds(userData.getCodeIds().toString());
taskInfoDetail.setShiXunCodeIds(userData.getStudentWorkShixunCodeIds().toString());
taskInfoDetailDao.insertTaskInfoDetail(taskInfoDetail); taskInfoDetailDao.insertTaskInfoDetail(taskInfoDetail);

@ -15,8 +15,11 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.function.Function;
/** /**
@ -59,42 +62,16 @@ public class QualityInspectRunnable implements Runnable {
String path = String.format("/tmp/%s/%s/", homeworkId, projectName); String path = String.format("/tmp/%s/%s/", homeworkId, projectName);
List<Long> codeIds = userData.getCodeIds(); List<Long> codeIds = userData.getCodeIds();
boolean constantCFlag = true,constantCPPFlag = true,constantJavaFlag = true, constantPyFlag = true; List<Long> shiXunCodeIds = userData.getStudentWorkShixunCodeIds();
for (Long codeId : codeIds) {
File file = new File(path);
try {
FileUtils.forceMkdir(file);
} catch (IOException e) {
}
GameCodes gameCodes = dbOperateService.queryGameCodesById(codeId); for (Long codeId : codeIds) {
if(gameCodes == null){ processCodeId(codeId, path, projectName, dbOperateService::queryGameCodesById);
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")) { for (Long codeId : shiXunCodeIds) {
constantCFlag = false; processCodeId(codeId, path, projectName, dbOperateService::queryShiXunCodesById);
} 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;
}
} }
// 需要自己判别语言,Java优先
if(!constantJavaFlag){
language = Constant.JAVA;
}else if(!constantPyFlag){
language = Constant.PYTHON;
} else if(!constantCFlag){
language = Constant.C;
}else if(!constantCPPFlag){
language = Constant.CXX;
}
// 写完所有文件开始用sonar进行质量分析 // 写完所有文件开始用sonar进行质量分析
SonarScannerParam param = new SonarScannerParam(projectName, path); SonarScannerParam param = new SonarScannerParam(projectName, path);
@ -133,4 +110,45 @@ public class QualityInspectRunnable implements Runnable {
public void setSonarService(SonarService sonarService) { public void setSonarService(SonarService sonarService) {
this.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.initSize=20
#spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7 #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.username=sonar
spring.datasource.master.password=sonar spring.datasource.master.password=sonar
spring.datasource.master.driverClassName=org.postgresql.Driver spring.datasource.master.driverClassName=org.postgresql.Driver
@ -14,7 +14,7 @@ spring.datasource.master.driverClassName=org.postgresql.Driver
#### test ###### #### test ######
spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver 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.username=testeducoder
spring.datasource.readonly.password=TEST@123 spring.datasource.readonly.password=TEST@123

Loading…
Cancel
Save