parent
53fe884463
commit
3bb714f796
@ -0,0 +1,15 @@
|
||||
package net.educoder.ecsonar.config;
|
||||
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2021/12/31
|
||||
* @Description:
|
||||
*/
|
||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DynamicDataSourceContextHolder.getContextKey();
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package net.educoder.ecsonar.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2021/12/31
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@MapperScan(basePackages = "net.educoder.ecsonar.dao")
|
||||
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");
|
||||
|
||||
@Value("${spring.datasource.master.driverClassName}")
|
||||
private String masterDriverClass;
|
||||
|
||||
@Value("${spring.datasource.master.url}")
|
||||
private String masterUrl;
|
||||
|
||||
@Value("${spring.datasource.master.username}")
|
||||
private String masterUsername;
|
||||
|
||||
@Value("${spring.datasource.master.password}")
|
||||
private String masterPassword;
|
||||
|
||||
@Value("${spring.datasource.readonly.driverClassName}")
|
||||
private String readonlyDriverClass;
|
||||
|
||||
@Value("${spring.datasource.readonly.url}")
|
||||
private String readonlyUrl;
|
||||
|
||||
@Value("${spring.datasource.readonly.username}")
|
||||
private String readonlyUsername;
|
||||
|
||||
@Value("${spring.datasource.readonly.password}")
|
||||
private String readonlyPassword;
|
||||
|
||||
@Value("${spring.datasource.initSize}")
|
||||
private Integer initSize;
|
||||
|
||||
@Bean("master")
|
||||
public DataSource masterDataSource() {
|
||||
DruidDataSource masterDataSource = new DruidDataSource();
|
||||
masterDataSource.setDriverClassName(masterDriverClass);
|
||||
masterDataSource.setUrl(masterUrl);
|
||||
masterDataSource.setUsername(masterUsername);
|
||||
masterDataSource.setPassword(masterPassword);
|
||||
masterDataSource.setInitialSize(initSize);
|
||||
masterDataSource.setConnectionInitSqls(INIT_SQLS);
|
||||
return masterDataSource;
|
||||
}
|
||||
|
||||
@Bean("readonly")
|
||||
public DataSource slaveDataSource() {
|
||||
DruidDataSource readonlyDataSource = new DruidDataSource();
|
||||
readonlyDataSource.setDriverClassName(readonlyDriverClass);
|
||||
readonlyDataSource.setUrl(readonlyUrl);
|
||||
readonlyDataSource.setUsername(readonlyUsername);
|
||||
readonlyDataSource.setPassword(readonlyPassword);
|
||||
readonlyDataSource.setInitialSize(initSize);
|
||||
readonlyDataSource.setConnectionInitSqls(INIT_SQLS);
|
||||
return readonlyDataSource;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource dynamicDataSource() {
|
||||
Map<Object, Object> dataSourceMap = new HashMap<>(2);
|
||||
dataSourceMap.put(MASTER, masterDataSource());
|
||||
dataSourceMap.put(READONLY, slaveDataSource());
|
||||
//设置动态数据源
|
||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||
dynamicDataSource.setTargetDataSources(dataSourceMap);
|
||||
dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
||||
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package net.educoder.ecsonar.config;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2021/12/31
|
||||
* @Description:
|
||||
*/
|
||||
public class DynamicDataSourceContextHolder {
|
||||
|
||||
/**
|
||||
* 动态数据源名称上下文
|
||||
*/
|
||||
private static final ThreadLocal<String> DATASOURCE_CONTEXT_KEY_HOLDER = new ThreadLocal<>();
|
||||
/**
|
||||
* 设置/切换数据源
|
||||
*/
|
||||
public static void setContextKey(String key){
|
||||
DATASOURCE_CONTEXT_KEY_HOLDER.set(key);
|
||||
}
|
||||
/**
|
||||
* 获取数据源名称
|
||||
*/
|
||||
public static String getContextKey(){
|
||||
String key = DATASOURCE_CONTEXT_KEY_HOLDER.get();
|
||||
return key == null? net.educode.detection.config.DynamicDataSourceConfig.MASTER: key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前数据源名称
|
||||
*/
|
||||
public static void removeContextKey(){
|
||||
DATASOURCE_CONTEXT_KEY_HOLDER.remove();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package net.educoder.ecsonar.controller;
|
||||
|
||||
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
|
||||
import net.educoder.ecsonar.model.api.QualityInspectResult;
|
||||
import net.educoder.ecsonar.model.vo.QualityInspectVO;
|
||||
import net.educoder.ecsonar.services.QualityInspectService;
|
||||
import net.educoder.ecsonar.utils.ResponseResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class QualityInspectController {
|
||||
|
||||
@Autowired
|
||||
QualityInspectService qualityInspectService;
|
||||
|
||||
|
||||
/**
|
||||
* 质量检测
|
||||
* @param qualityInspectVO
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "qualityInspect", method = RequestMethod.POST)
|
||||
public ResponseResult<String> qualityInspect(@RequestBody QualityInspectVO qualityInspectVO){
|
||||
String taskId = qualityInspectService.qualityInspect(qualityInspectVO);
|
||||
return ResponseResult.success(taskId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 质量检测任务是否完成
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "qualityInspectIsCompleted", method = RequestMethod.GET)
|
||||
public ResponseResult<QualityInspectIsCompleted> qualityInspectIsCompleted(@RequestParam String taskId){
|
||||
QualityInspectIsCompleted result = qualityInspectService.qualityInspectIsCompleted(taskId);
|
||||
return ResponseResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 质量检测结果查询
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "qualityInspectResultQuery", method = RequestMethod.GET)
|
||||
public ResponseResult<QualityInspectResult> qualityInspectResultQuery(@RequestParam String taskId){
|
||||
QualityInspectResult result = qualityInspectService.qualityInspectResultQuery(taskId);
|
||||
return ResponseResult.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,70 @@
|
||||
package net.educoder.ecsonar.model.api;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description: 质量
|
||||
*/
|
||||
public class Quality {
|
||||
|
||||
/**
|
||||
* 阻断
|
||||
*/
|
||||
private Integer blocker;
|
||||
/**
|
||||
* 主要
|
||||
*/
|
||||
private Integer major;
|
||||
/**
|
||||
* 次要
|
||||
*/
|
||||
private Integer minor;
|
||||
/**
|
||||
* 严重
|
||||
*/
|
||||
private Integer critical;
|
||||
/**
|
||||
* 等级 A-E
|
||||
*/
|
||||
private String grade;
|
||||
|
||||
public Integer getBlocker() {
|
||||
return blocker;
|
||||
}
|
||||
|
||||
public void setBlocker(Integer blocker) {
|
||||
this.blocker = blocker;
|
||||
}
|
||||
|
||||
public Integer getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public void setMajor(Integer major) {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public Integer getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public void setMinor(Integer minor) {
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public Integer getCritical() {
|
||||
return critical;
|
||||
}
|
||||
|
||||
public void setCritical(Integer critical) {
|
||||
this.critical = critical;
|
||||
}
|
||||
|
||||
public String getGrade() {
|
||||
return grade;
|
||||
}
|
||||
|
||||
public void setGrade(String grade) {
|
||||
this.grade = grade;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package net.educoder.ecsonar.model.api;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
public class QualityInspectIsCompleted {
|
||||
|
||||
/**
|
||||
* 任务id
|
||||
*/
|
||||
private String taskId;
|
||||
|
||||
|
||||
/**
|
||||
* 是否完成 0 未完成 1 已完成
|
||||
*/
|
||||
private Integer completed;
|
||||
|
||||
public QualityInspectIsCompleted(String taskId, Integer completed) {
|
||||
this.taskId = taskId;
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public Integer getCompleted() {
|
||||
return completed;
|
||||
}
|
||||
|
||||
public void setCompleted(Integer completed) {
|
||||
this.completed = completed;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package net.educoder.ecsonar.model.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description: 检测结果
|
||||
*/
|
||||
public class QualityInspectResult {
|
||||
|
||||
/**
|
||||
* 任务id
|
||||
*/
|
||||
private String taskId;
|
||||
|
||||
|
||||
/**
|
||||
* 质量检测数据
|
||||
*/
|
||||
private List<QualityInspectResultData> dataList;
|
||||
|
||||
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<QualityInspectResultData> getDataList() {
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public void setDataList(List<QualityInspectResultData> dataList) {
|
||||
this.dataList = dataList;
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
package net.educoder.ecsonar.model.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
public class QualityInspectResultData {
|
||||
|
||||
/**
|
||||
* 导师
|
||||
*/
|
||||
private String mentor;
|
||||
/**
|
||||
* 学号
|
||||
*/
|
||||
private String studentId;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 缺陷
|
||||
*/
|
||||
private Quality bug;
|
||||
/**
|
||||
* 漏洞
|
||||
*/
|
||||
private Quality vulnerability;
|
||||
/**
|
||||
* 代码规范
|
||||
*/
|
||||
private Quality codeSmall;
|
||||
|
||||
/**
|
||||
* 复杂度
|
||||
*/
|
||||
private BigDecimal complexity;
|
||||
|
||||
/**
|
||||
* 总行数
|
||||
*/
|
||||
private Integer totalRowNumber;
|
||||
|
||||
/**
|
||||
* 质量得分
|
||||
*/
|
||||
private BigDecimal qualityScore;
|
||||
|
||||
public String getMentor() {
|
||||
return mentor;
|
||||
}
|
||||
|
||||
public void setMentor(String mentor) {
|
||||
this.mentor = mentor;
|
||||
}
|
||||
|
||||
public String getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Quality getBug() {
|
||||
return bug;
|
||||
}
|
||||
|
||||
public void setBug(Quality bug) {
|
||||
this.bug = bug;
|
||||
}
|
||||
|
||||
public Quality getVulnerability() {
|
||||
return vulnerability;
|
||||
}
|
||||
|
||||
public void setVulnerability(Quality vulnerability) {
|
||||
this.vulnerability = vulnerability;
|
||||
}
|
||||
|
||||
public Quality getCodeSmall() {
|
||||
return codeSmall;
|
||||
}
|
||||
|
||||
public void setCodeSmall(Quality codeSmall) {
|
||||
this.codeSmall = codeSmall;
|
||||
}
|
||||
|
||||
public BigDecimal getComplexity() {
|
||||
return complexity;
|
||||
}
|
||||
|
||||
public void setComplexity(BigDecimal complexity) {
|
||||
this.complexity = complexity;
|
||||
}
|
||||
|
||||
public Integer getTotalRowNumber() {
|
||||
return totalRowNumber;
|
||||
}
|
||||
|
||||
public void setTotalRowNumber(Integer totalRowNumber) {
|
||||
this.totalRowNumber = totalRowNumber;
|
||||
}
|
||||
|
||||
public BigDecimal getQualityScore() {
|
||||
return qualityScore;
|
||||
}
|
||||
|
||||
public void setQualityScore(BigDecimal qualityScore) {
|
||||
this.qualityScore = qualityScore;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package net.educoder.ecsonar.model.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
public class QualityInspectUserDataVO {
|
||||
|
||||
/**
|
||||
* 学号
|
||||
*/
|
||||
private String studentId;
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 学员代码id
|
||||
*/
|
||||
private List<Integer> codeIds;
|
||||
|
||||
public String getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Integer> getCodeIds() {
|
||||
return codeIds;
|
||||
}
|
||||
|
||||
public void setCodeIds(List<Integer> codeIds) {
|
||||
this.codeIds = codeIds;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package net.educoder.ecsonar.model.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
public class QualityInspectVO {
|
||||
|
||||
private String language;
|
||||
private String homeworkId;
|
||||
private List<QualityInspectUserDataVO> userDatas;
|
||||
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public String getHomeworkId() {
|
||||
return homeworkId;
|
||||
}
|
||||
|
||||
public void setHomeworkId(String homeworkId) {
|
||||
this.homeworkId = homeworkId;
|
||||
}
|
||||
|
||||
public List<QualityInspectUserDataVO> getUserDatas() {
|
||||
return userDatas;
|
||||
}
|
||||
|
||||
public void setUserDatas(List<QualityInspectUserDataVO> userDatas) {
|
||||
this.userDatas = userDatas;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.educoder.ecsonar.services;
|
||||
|
||||
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
|
||||
import net.educoder.ecsonar.model.api.QualityInspectResult;
|
||||
import net.educoder.ecsonar.model.vo.QualityInspectVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
@Service
|
||||
public class QualityInspectService {
|
||||
|
||||
|
||||
public String qualityInspect(QualityInspectVO qualityInspectVO) {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public QualityInspectResult qualityInspectResultQuery(String taskId) {
|
||||
|
||||
QualityInspectResult result = new QualityInspectResult();
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public QualityInspectIsCompleted qualityInspectIsCompleted(String taskId) {
|
||||
QualityInspectIsCompleted completed = new QualityInspectIsCompleted(taskId, 1);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.educoder.ecsonar.utils;
|
||||
|
||||
public final class IdUtils {
|
||||
|
||||
private static SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
|
||||
|
||||
private IdUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static long nextId() {
|
||||
return idWorker.nextId();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package net.educoder.ecsonar.utils;
|
||||
|
||||
/**
|
||||
* @Author: youys
|
||||
* @Date: 2022/1/17
|
||||
* @Description:
|
||||
*/
|
||||
public class ResponseResult<T> {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private T data;
|
||||
|
||||
|
||||
public ResponseResult(){
|
||||
|
||||
}
|
||||
public ResponseResult(Integer code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public ResponseResult(T data){
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static ResponseResult success(){
|
||||
return new ResponseResult(1,"success");
|
||||
}
|
||||
|
||||
|
||||
public static ResponseResult success(Object data){
|
||||
return new ResponseResult(data);
|
||||
}
|
||||
|
||||
public static ResponseResult error(String msg){
|
||||
return new ResponseResult(2,msg);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue