接口定义

test
youys 3 years ago
parent 53fe884463
commit 3bb714f796

@ -16,6 +16,7 @@
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<mysql-connector.version>5.1.47</mysql-connector.version>
</properties> </properties>
<dependencies> <dependencies>
@ -45,6 +46,18 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>

@ -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);
}
}

@ -0,0 +1,147 @@
package net.educoder.ecsonar.utils;
/**
* Twitter_Snowflake<br>
* SnowFlake(-):<br>
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 -
* 000000000000 <br>
* 1longJava01id0<br>
* 41()41 - )
* id使IdWorkerstartTime41使69T
* = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
* 1010245datacenterId5workerId<br>
* 1212()4096ID<br>
* 64Long<br>
* SnowFlakeID(IDID)SnowFlake26ID
*/
public class SnowflakeIdWorker {
// ==============================Fields===========================================
/** 开始时间截 (2015-01-01) */
private final long twepoch = 1420041600000L;
/** 机器id所占的位数 */
private final long workerIdBits = 5L;
/** 数据标识id所占的位数 */
private final long datacenterIdBits = 5L;
/** 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/** 支持的最大数据标识id结果是31 */
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/** 序列在id中占的位数 */
private final long sequenceBits = 12L;
/** 机器ID向左移12位 */
private final long workerIdShift = sequenceBits;
/** 数据标识id向左移17位(12+5) */
private final long datacenterIdShift = sequenceBits + workerIdBits;
/** 时间截向左移22位(5+5+12) */
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/** 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095) */
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
/** 工作机器ID(0~31) */
private long workerId;
/** 数据中心ID(0~31) */
private long datacenterId;
/** 毫秒内序列(0~4095) */
private long sequence = 0L;
/** 上次生成ID的时间截 */
private long lastTimestamp = -1L;
// ==============================Constructors=====================================
/**
*
*
* @param workerId
* ID (0~31)
* @param datacenterId
* ID (0~31)
*/
public SnowflakeIdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(
String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(
String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
// ==============================Methods==========================================
/**
* ID (线)
*
* @return SnowflakeId
*/
public synchronized long nextId() {
long timestamp = timeGen();
// 如果当前时间小于上一次ID生成的时间戳说明系统时钟回退过这个时候应当抛出异常
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format(
"Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
// 如果是同一时间生成的,则进行毫秒内序列
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
// 毫秒内序列溢出
if (sequence == 0) {
// 阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
}
// 时间戳改变,毫秒内序列重置
else {
sequence = 0L;
}
// 上次生成ID的时间截
lastTimestamp = timestamp;
// 移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (datacenterId << datacenterIdShift) //
| (workerId << workerIdShift) //
| sequence;
}
/**
*
*
* @param lastTimestamp
* ID
* @return
*/
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
/**
*
*
* @return ()
*/
protected long timeGen() {
return System.currentTimeMillis();
}
}

@ -1,20 +1,32 @@
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7 #spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
##spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar
#spring.datasource.username=root
#spring.datasource.password=root
#spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
#spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar #spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar
spring.datasource.username=root spring.datasource.master.username=root
spring.datasource.password=root spring.datasource.master.password=root
spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.master.driverClass=org.postgresql.Driver
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 # Hikari will use the above plus the following to setup connection pooling
spring.datasource.type=com.zaxxer.hikari.HikariDataSource #spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5 #spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=15 #spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.auto-commit=true #spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000 #spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=DatebookHikariCP #spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000 #spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000 #spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1 #spring.datasource.hikari.connection-test-query=SELECT 1
logging.config=classpath:logback-spring.xml logging.config=classpath:logback-spring.xml

Loading…
Cancel
Save