Compare commits
11 Commits
main
...
dev-active
Author | SHA1 | Date |
---|---|---|
lensfrex | cdba2e4a76 | 2 years ago |
lensfrex | 17f90ce524 | 2 years ago |
lensfrex | e53862b226 | 2 years ago |
lensfrex | 5bbf9113c8 | 2 years ago |
lensfrex | a3dedc2c98 | 2 years ago |
lensfrex | 685b582d04 | 2 years ago |
lensfrex | ff1ae38707 | 2 years ago |
lensfrex | d154aab9ed | 2 years ago |
lensfrex | 15baa50907 | 2 years ago |
lensfrex | fd91bd15ca | 2 years ago |
lensfrex | bb90b69df0 | 2 years ago |
@ -0,0 +1,77 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ Class created by lensfrex. |
||||
--> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dscape-server</artifactId> |
||||
<groupId>net.lensfrex</groupId> |
||||
<version>0.0.1-dev</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dscape-cache</artifactId> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>11</maven.compiler.source> |
||||
<maven.compiler.target>11</maven.compiler.target> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-entities</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-utils</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||
<version>2.7.3</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-pool2</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-core</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-databind</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-annotations</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-lang3</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<classifier>exec</classifier> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,80 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.cache; |
||||
|
||||
import net.lensfrex.dscape.configure.GlobalConstant; |
||||
import net.lensfrex.dscape.dao.entity.UserBasic; |
||||
import net.lensfrex.dscape.utils.ObjectJsonSerializer; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Slf4j |
||||
@Component |
||||
public class UserBasicCache { |
||||
|
||||
private static final String USER_INFO_CACHE_KEY = GlobalConstant.USER_INFO_CACHE_KEY; |
||||
|
||||
private static final String USERNAME_UID_CACHE_KEY = GlobalConstant.USERNAME_UID_CACHE_KEY; |
||||
|
||||
private final RedisTemplate<String, String> redis; |
||||
|
||||
public UserBasicCache(RedisTemplate<String, String> redis) { |
||||
this.redis = redis; |
||||
} |
||||
|
||||
public UserBasic getUserByUid(String uid) { |
||||
try { |
||||
String cacheData = (String) redis.opsForHash().get(USER_INFO_CACHE_KEY, uid); |
||||
if (cacheData != null) { |
||||
return ObjectJsonSerializer.deserialize(cacheData, UserBasic.class); |
||||
} else { |
||||
log.debug("缓存中没有用户信息"); |
||||
return null; |
||||
} |
||||
} catch (Exception e) { |
||||
log.warn("获取缓存时出现问题"); |
||||
log.debug("追踪:", e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public UserBasic getUserByUserName(String username) { |
||||
try { |
||||
String uid = (String) redis.opsForHash().get(USERNAME_UID_CACHE_KEY, username); |
||||
if (uid != null) { |
||||
return this.getUserByUid(uid); |
||||
} else { |
||||
log.debug("缓存中没有用户名和uid的对应信息"); |
||||
return null; |
||||
} |
||||
} catch (Exception e) { |
||||
log.warn("获取缓存时出现问题"); |
||||
log.debug("追踪:", e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public void save(UserBasic userBasic) { |
||||
redis.opsForHash().put(USER_INFO_CACHE_KEY, userBasic.getUid(), ObjectJsonSerializer.serialize(userBasic)); |
||||
redis.opsForHash().put(USERNAME_UID_CACHE_KEY, userBasic.getUserName(), userBasic.getUid()); |
||||
} |
||||
|
||||
public void clear(String uid) { |
||||
redis.opsForHash().delete(USER_INFO_CACHE_KEY, uid); |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.configure; |
||||
|
||||
public class GlobalConstant { |
||||
public static final String USER_INFO_CACHE_KEY = "dscape:user:basic"; |
||||
|
||||
public static final String USERNAME_UID_CACHE_KEY = "dscape:user:uid"; |
||||
|
||||
public static final String REGISTER_INVITE_CODE_KEY = "dscape:user:inviteCodes"; |
||||
|
||||
public static final String ADMIN_INVITE_CODE_COUNTER_KEY = "dscape:admin:inviteCodeCounter:%s"; |
||||
} |
@ -0,0 +1,37 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.configure; |
||||
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
||||
import org.springframework.cache.annotation.EnableCaching; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
||||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
||||
@Configuration |
||||
@EnableCaching |
||||
public class RedisConfigure extends CachingConfigurerSupport { |
||||
@Bean |
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory redisConnectionFactory) { |
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); |
||||
redisTemplate.setConnectionFactory(redisConnectionFactory); |
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class); |
||||
|
||||
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); |
||||
redisTemplate.setKeySerializer(new StringRedisSerializer()); |
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer()); |
||||
|
||||
redisTemplate.afterPropertiesSet(); |
||||
|
||||
return redisTemplate; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dscape-server</artifactId> |
||||
<groupId>net.lensfrex</groupId> |
||||
<version>0.0.1-dev</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dscape-compute</artifactId> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>11</maven.compiler.source> |
||||
<maven.compiler.target>11</maven.compiler.target> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-dao</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-io</groupId> |
||||
<artifactId>commons-io</artifactId> |
||||
<version>2.11.0</version> |
||||
</dependency> |
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.github.yannrichet/Rsession --> |
||||
<dependency> |
||||
<groupId>com.github.yannrichet</groupId> |
||||
<artifactId>Rsession</artifactId> |
||||
<version>3.1.6</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>commons-io</groupId> |
||||
<artifactId>commons-io</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
@ -0,0 +1,13 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape; |
||||
|
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
@SpringBootApplication |
||||
@MapperScan("net.lensfrex.dscape.dao.mapper") |
||||
public class ComputeMain { |
||||
} |
@ -0,0 +1,67 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ Class created by lensfrex. |
||||
--> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dscape-server</artifactId> |
||||
<groupId>net.lensfrex</groupId> |
||||
<version>0.0.1-dev</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dscape-dao</artifactId> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>11</maven.compiler.source> |
||||
<maven.compiler.target>11</maven.compiler.target> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-entities</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
<version>3.5.2</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.mariadb.jdbc</groupId> |
||||
<artifactId>mariadb-java-client</artifactId> |
||||
<version>3.0.6</version> |
||||
</dependency> |
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid --> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>druid</artifactId> |
||||
<version>1.2.11</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>druid-spring-boot-starter</artifactId> |
||||
<version>1.2.11</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<classifier>exec</classifier> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,63 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.configure; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType; |
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* 分页功能的配置类 |
||||
*/ |
||||
@Slf4j |
||||
@Configuration |
||||
@EnableTransactionManagement |
||||
public class MybatisPlusConfigure { |
||||
@Resource |
||||
DataSourceProperties dataSourceProperties; |
||||
|
||||
@Bean |
||||
public PaginationInnerInterceptor paginationInnerInterceptor() { |
||||
return new PaginationInnerInterceptor(); |
||||
} |
||||
|
||||
@Bean |
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() { |
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
||||
String databaseDriverName = dataSourceProperties.getDriverClassName(); |
||||
|
||||
PaginationInnerInterceptor paginationInnerInterceptor; |
||||
if (databaseDriverName.contains("mariadb")) { |
||||
log.info("使用Mariadb作为数据库"); |
||||
paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MARIADB); |
||||
} else if (databaseDriverName.contains("mysql")) { |
||||
log.info("使用Mysql作为数据库"); |
||||
paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL); |
||||
} else { |
||||
paginationInnerInterceptor = new PaginationInnerInterceptor(); |
||||
log.warn("使用了可能不受支持的数据库:" + databaseDriverName); |
||||
} |
||||
paginationInnerInterceptor.setOptimizeJoin(true); |
||||
|
||||
interceptor.addInnerInterceptor(paginationInnerInterceptor); |
||||
return interceptor; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.BlackList; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description black_listMapper |
||||
* @date 2022-08-19 |
||||
*/ |
||||
@Mapper |
||||
public interface BlackListMapper extends BaseMapper<BlackList> { |
||||
|
||||
} |
@ -0,0 +1,24 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.ComputeHistory; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description compute_historyMapper |
||||
* @date 2022-08-22 |
||||
*/ |
||||
@Mapper |
||||
public interface ComputeHistoryMapper extends BaseMapper<ComputeHistory> { |
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.PatientData; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description patient_dataMapper |
||||
* @date 2022-08-22 |
||||
*/ |
||||
@Mapper |
||||
public interface PatientDataMapper extends BaseMapper<PatientData> { |
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.RegisterApplies; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description register_appliesMapper |
||||
* @date 2022-08-18 |
||||
*/ |
||||
@Mapper |
||||
public interface RegisterAppliesMapper extends BaseMapper<RegisterApplies> { |
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.RolePermission; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description role_permissionMapper |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Mapper |
||||
public interface RolePermissionMapper extends BaseMapper<RolePermission> { |
||||
|
||||
} |
@ -0,0 +1,22 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.UserBasic; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description user_basicMapper |
||||
* @date 2022-08-18 |
||||
*/ |
||||
@Mapper |
||||
public interface UserBasicMapper extends BaseMapper<UserBasic> { |
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.dao.entity.UserRole; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description user_roleMapper |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Mapper |
||||
public interface UserRoleMapper extends BaseMapper<UserRole> { |
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.BlackList; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description black_list服务层 |
||||
* @date 2022-08-19 |
||||
*/ |
||||
@Service |
||||
public interface BlackListService extends IService<BlackList> { |
||||
|
||||
} |
@ -0,0 +1,34 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.ComputeHistory; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description compute_history服务层 |
||||
* @date 2022-08-22 |
||||
*/ |
||||
@Service |
||||
public interface ComputeHistoryService extends IService<ComputeHistory> { |
||||
long count(SFunction<ComputeHistory, ?> indexColum, Object index); |
||||
|
||||
List<ComputeHistory> getHistory(String uid, int page, int limit); |
||||
|
||||
List<Long> getHistoryDataIds(String uid, int page, int limit); |
||||
|
||||
boolean remove(Long id); |
||||
|
||||
String getHistoryUser(Long rid); |
||||
} |
@ -0,0 +1,30 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.PatientData; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description patient_data服务层 |
||||
* @date 2022-08-22 |
||||
*/ |
||||
@Service |
||||
public interface PatientDataService extends IService<PatientData> { |
||||
List<PatientData> getData(Collection<Long> ids); |
||||
|
||||
PatientData getData(Long id); |
||||
|
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.RegisterApplies; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description register_applies服务层 |
||||
* @date 2022-08-18 |
||||
*/ |
||||
@Service |
||||
public interface RegisterAppliesService extends IService<RegisterApplies> { |
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.RolePermission; |
||||
import org.apache.ibatis.annotations.Select; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description role_permission服务层 |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Service |
||||
public interface RolePermissionService extends IService<RolePermission> { |
||||
@Select("select permission from role_permission where role = #{role} and is_deleted = 0") |
||||
List<String> getPermissions(String role); |
||||
|
||||
@Select("select permission from role_permission where role = #{role} and is_deleted = 0") |
||||
List<String> getPermissions(List<String> roles); |
||||
} |
@ -0,0 +1,34 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.UserBasic; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description user_basic服务层 |
||||
* @date 2022-08-18 |
||||
*/ |
||||
@Service |
||||
public interface UserBasicService extends IService<UserBasic> { |
||||
UserBasic getUser(SFunction<UserBasic, ?> function, String index); |
||||
|
||||
UserBasic getUser(QueryWrapper<UserBasic> wrapper); |
||||
|
||||
boolean userNameExists(String username); |
||||
|
||||
void modify(SFunction<UserBasic, ?> colm, Object index, SFunction<UserBasic, ?> modifyColm, Object newValue); |
||||
|
||||
void modify(UpdateWrapper<UserBasic> wrapper); |
||||
} |
@ -0,0 +1,28 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import net.lensfrex.dscape.dao.entity.UserRole; |
||||
import org.apache.ibatis.annotations.Select; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description user_role服务层 |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Service |
||||
public interface UserRoleService extends IService<UserRole> { |
||||
|
||||
@Select("select role from user_role where uid = '#{uid}' and is_deleted != 1") |
||||
List<String> getRoles(String uid); |
||||
} |
@ -0,0 +1,24 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.entity.BlackList; |
||||
import net.lensfrex.dscape.dao.mapper.BlackListMapper; |
||||
import net.lensfrex.dscape.dao.service.BlackListService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class BlackListServiceImpl extends ServiceImpl<BlackListMapper, BlackList> implements BlackListService { |
||||
|
||||
} |
@ -0,0 +1,80 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.entity.ComputeHistory; |
||||
import net.lensfrex.dscape.dao.mapper.ComputeHistoryMapper; |
||||
import net.lensfrex.dscape.dao.service.ComputeHistoryService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
public class ComputeHistoryServiceImpl extends ServiceImpl<ComputeHistoryMapper, ComputeHistory> implements ComputeHistoryService { |
||||
@Override |
||||
public long count(SFunction<ComputeHistory, ?> indexColum, Object index) { |
||||
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.eq(indexColum, index); |
||||
|
||||
return this.count(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public List<ComputeHistory> getHistory(String uid, int page, int limit) { |
||||
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.eq(ComputeHistory::getUid, uid); |
||||
|
||||
return this.page(new Page<>(page, limit), wrapper).getRecords(); |
||||
} |
||||
|
||||
@Override |
||||
public List<Long> getHistoryDataIds(String uid, int page, int limit) { |
||||
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.select(ComputeHistory::getRid) |
||||
.eq(ComputeHistory::getUid, uid); |
||||
|
||||
List<ComputeHistory> results = this.page(new Page<>(page, limit), wrapper).getRecords(); |
||||
|
||||
List<Long> ids = new ArrayList<>(results.size()); |
||||
results.forEach(result -> ids.add(result.getRid())); |
||||
|
||||
return ids; |
||||
} |
||||
|
||||
@Override |
||||
public boolean remove(Long rid) { |
||||
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.eq(ComputeHistory::getRid, rid); |
||||
|
||||
return this.remove(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public String getHistoryUser(Long rid) { |
||||
QueryWrapper<ComputeHistory> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.select(ComputeHistory::getUid) |
||||
.eq(ComputeHistory::getRid, rid); |
||||
|
||||
return this.getOne(wrapper).getUid(); |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.entity.PatientData; |
||||
import net.lensfrex.dscape.dao.service.PatientDataService; |
||||
import net.lensfrex.dscape.dao.mapper.PatientDataMapper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
public class PatientDataServiceImpl extends ServiceImpl<PatientDataMapper, PatientData> implements PatientDataService { |
||||
@Override |
||||
public List<PatientData> getData(Collection<Long> ids) { |
||||
if (ids == null || ids.isEmpty()) { |
||||
return new ArrayList<>(); |
||||
} |
||||
|
||||
QueryWrapper<PatientData> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.in(PatientData::getId, ids) |
||||
.orderByDesc(PatientData::getId); |
||||
|
||||
return this.list(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public PatientData getData(Long rid) { |
||||
QueryWrapper<PatientData> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.eq(PatientData::getId, rid); |
||||
|
||||
return this.getOne(wrapper); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.mapper.RegisterAppliesMapper; |
||||
import net.lensfrex.dscape.dao.service.RegisterAppliesService; |
||||
import net.lensfrex.dscape.dao.entity.RegisterApplies; |
||||
|
||||
public class RegisterAppliesServiceImpl extends ServiceImpl<RegisterAppliesMapper, RegisterApplies> implements RegisterAppliesService { |
||||
|
||||
} |
@ -0,0 +1,59 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.entity.RolePermission; |
||||
import net.lensfrex.dscape.dao.mapper.RolePermissionMapper; |
||||
import net.lensfrex.dscape.dao.service.RolePermissionService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService { |
||||
|
||||
@Override |
||||
public List<String> getPermissions(String role) { |
||||
QueryWrapper<RolePermission> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.select(RolePermission::getPermission) |
||||
.eq(RolePermission::getRole, role) |
||||
.eq(RolePermission::getIsDeleted, 0); |
||||
|
||||
return this.getPermissions(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public List<String> getPermissions(List<String> roles) { |
||||
QueryWrapper<RolePermission> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.select(RolePermission::getPermission) |
||||
.in(RolePermission::getRole, roles) |
||||
.eq(RolePermission::getIsDeleted, 0); |
||||
|
||||
return this.getPermissions(wrapper); |
||||
} |
||||
|
||||
private List<String> getPermissions(QueryWrapper<RolePermission> wrapper) { |
||||
|
||||
List<RolePermission> rolePermissionList = this.list(wrapper); |
||||
|
||||
List<String> permissions = new ArrayList<>(); |
||||
rolePermissionList.forEach(rolePermission -> permissions.add(rolePermission.getPermission().toString())); |
||||
|
||||
return permissions; |
||||
} |
||||
} |
@ -0,0 +1,61 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.entity.UserBasic; |
||||
import net.lensfrex.dscape.dao.service.UserBasicService; |
||||
import net.lensfrex.dscape.dao.mapper.UserBasicMapper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class UserBasicServiceImpl extends ServiceImpl<UserBasicMapper, UserBasic> implements UserBasicService { |
||||
@Override |
||||
public UserBasic getUser(SFunction<UserBasic, ?> indexColm, String index) { |
||||
QueryWrapper<UserBasic> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda().eq(indexColm, index); |
||||
|
||||
return this.getOne(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public UserBasic getUser(QueryWrapper<UserBasic> wrapper) { |
||||
return this.getOne(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public boolean userNameExists(String username) { |
||||
QueryWrapper<UserBasic> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda().eq(UserBasic::getUserName, username); |
||||
|
||||
return this.count(wrapper) != 0; |
||||
} |
||||
|
||||
@Override |
||||
public void modify(SFunction<UserBasic, ?> indexColm, Object index, SFunction<UserBasic, ?> modifyColm, Object newValue) { |
||||
UpdateWrapper<UserBasic> wrapper = new UpdateWrapper<>(); |
||||
wrapper.lambda() |
||||
.eq(indexColm, index) |
||||
.set(modifyColm, newValue); |
||||
|
||||
this.update(wrapper); |
||||
} |
||||
|
||||
@Override |
||||
public void modify(UpdateWrapper<UserBasic> wrapper) { |
||||
this.update(wrapper); |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import net.lensfrex.dscape.dao.entity.UserRole; |
||||
import net.lensfrex.dscape.dao.mapper.UserRoleMapper; |
||||
import net.lensfrex.dscape.dao.service.UserRoleService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService { |
||||
|
||||
@Override |
||||
public List<String> getRoles(String uid) { |
||||
QueryWrapper<UserRole> wrapper = new QueryWrapper<>(); |
||||
wrapper.lambda() |
||||
.select(UserRole::getRole) |
||||
.eq(UserRole::getUid, uid) |
||||
.eq(UserRole::getIsDeleted, 0); |
||||
|
||||
List<UserRole> userRoleList = this.list(wrapper); |
||||
List<String> roles = new ArrayList<>(); |
||||
|
||||
userRoleList.forEach(userRole -> roles.add(userRole.getRole().toString())); |
||||
|
||||
return roles; |
||||
} |
||||
} |
@ -0,0 +1,54 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ Class created by lensfrex. |
||||
--> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dscape-server</artifactId> |
||||
<groupId>net.lensfrex</groupId> |
||||
<version>0.0.1-dev</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dscape-entities</artifactId> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>11</maven.compiler.source> |
||||
<maven.compiler.target>11</maven.compiler.target> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-annotation</artifactId> |
||||
<version>3.5.2</version> |
||||
<scope>compile</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-databind</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-annotations</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<classifier>exec</classifier> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,68 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description black_list |
||||
* @date 2022-08-19 |
||||
*/ |
||||
@Data |
||||
public class BlackList implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
/** |
||||
* id |
||||
*/ |
||||
private Integer id; |
||||
|
||||
/** |
||||
* 黑名单数据类型;0:ip;1:uid |
||||
*/ |
||||
private int type; |
||||
|
||||
/** |
||||
* 黑名单条目名称,可空 |
||||
*/ |
||||
private String name; |
||||
|
||||
/** |
||||
* 黑名单数据 |
||||
*/ |
||||
private String data; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private Date editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
@TableLogic |
||||
private int isDeleted; |
||||
|
||||
public BlackList() { |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description compute_history |
||||
* @date 2022-08-23 |
||||
*/ |
||||
@Data |
||||
public class ComputeHistory implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
/** |
||||
* id |
||||
*/ |
||||
private Long id; |
||||
|
||||
/** |
||||
* 计算数据记录对应的用户uid |
||||
*/ |
||||
private String uid; |
||||
|
||||
/** |
||||
* 计算数据记录对应的患者数据id |
||||
*/ |
||||
private Long rid; |
||||
|
||||
/** |
||||
* 状态,0:完成,1:计算中 |
||||
*/ |
||||
private int status; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private LocalDateTime editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
private int isDeleted; |
||||
|
||||
public ComputeHistory() { |
||||
} |
||||
} |
@ -0,0 +1,84 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description patient_data |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Data |
||||
public class PatientData implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 数据id |
||||
*/ |
||||
@TableId(type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 病人id |
||||
*/ |
||||
private Integer pid; |
||||
|
||||
/** |
||||
* ctdna长度 |
||||
*/ |
||||
|
||||
private Integer ctdnaLength; |
||||
|
||||
/** |
||||
* 甲基化位点数 |
||||
*/ |
||||
private Integer cpg; |
||||
|
||||
/** |
||||
* 是否为hcc,0: 否, 1: 是 |
||||
*/ |
||||
private int isHcc; |
||||
|
||||
/** |
||||
* 通过推断得出的hcc状态 |
||||
*/ |
||||
private int isInferHcc; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private LocalDateTime editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
@TableLogic |
||||
private int isDeleted; |
||||
|
||||
public PatientData() { |
||||
} |
||||
} |
@ -0,0 +1,68 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description register_applies |
||||
* @date 2022-08-18 |
||||
*/ |
||||
@Data |
||||
public class RegisterApplies implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
@TableId(type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 管理员uid |
||||
*/ |
||||
private String admin; |
||||
|
||||
/** |
||||
* 申请认证的用户 |
||||
*/ |
||||
private String applyUser; |
||||
|
||||
/** |
||||
* 申请状态 |
||||
*/ |
||||
private int status; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private LocalDateTime editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
@TableLogic |
||||
private int isDeleted; |
||||
|
||||
public RegisterApplies() { |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description role_permission |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Data |
||||
public class RolePermission implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
/** |
||||
* id |
||||
*/ |
||||
private Long id; |
||||
|
||||
/** |
||||
* 角色id |
||||
*/ |
||||
private Integer role; |
||||
|
||||
/** |
||||
* 权限id |
||||
*/ |
||||
private Integer permission; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private LocalDateTime editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
@TableLogic |
||||
private int isDeleted; |
||||
|
||||
public RolePermission() { |
||||
} |
||||
} |
@ -0,0 +1,83 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description user_basic |
||||
* @date 2022-08-18 |
||||
*/ |
||||
@Data |
||||
public class UserBasic implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
private Integer id; |
||||
|
||||
/** |
||||
* 用户唯一uuid |
||||
*/ |
||||
@TableId(type = IdType.AUTO) |
||||
private String uid; |
||||
|
||||
/** |
||||
* 用户用户名 |
||||
*/ |
||||
private String userName; |
||||
|
||||
/** |
||||
* 用户密码 |
||||
*/ |
||||
private String password; |
||||
|
||||
/** |
||||
* 账号对应的上级管理员,若无上级管理员,请设为“null”(字符串) |
||||
*/ |
||||
private String superior; |
||||
|
||||
/** |
||||
* 用户注册ip |
||||
*/ |
||||
private String createIp; |
||||
|
||||
/** |
||||
* 用户状态;0:正常;1:封禁;2:注销(销号);3:未激活 |
||||
*/ |
||||
private int status; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private LocalDateTime editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
@TableLogic |
||||
private int isDeleted; |
||||
|
||||
public UserBasic() { |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* @author lensfrex |
||||
* @description user_role |
||||
* @date 2022-08-17 |
||||
*/ |
||||
@Data |
||||
public class UserRole implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
@TableId(type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 角色id |
||||
*/ |
||||
private Integer role; |
||||
|
||||
/** |
||||
* 用户uid |
||||
*/ |
||||
private String uid; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private LocalDateTime editTime; |
||||
|
||||
/** |
||||
* is_deleted |
||||
*/ |
||||
@TableLogic |
||||
private int isDeleted; |
||||
|
||||
public UserRole() { |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.request; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class UserLoginRequestBody { |
||||
@JsonProperty("user_name") |
||||
private String userName; |
||||
|
||||
private String password; |
||||
} |
@ -0,0 +1,10 @@ |
||||
package net.lensfrex.dscape.dto.request.compute; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class ComputeRequestBody{ |
||||
private int pid; |
||||
private int cpg; |
||||
private int ctdna; |
||||
} |
@ -0,0 +1,21 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.request.user; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class PasswordModifyRequestBody { |
||||
@JsonProperty("old_password") |
||||
String oldPassword; |
||||
|
||||
@JsonProperty("new_password") |
||||
String newPassword; |
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.request.user; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class RegisterRequestBody { |
||||
@JsonProperty("user_name") |
||||
private String userName; |
||||
|
||||
private String password; |
||||
|
||||
@JsonProperty("invite_code") |
||||
private String inviteCode; |
||||
} |
@ -0,0 +1,22 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.request.user; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class UserAddRequest { |
||||
@JsonProperty("user_name") |
||||
private String userName; |
||||
|
||||
private String password; |
||||
|
||||
private int role; |
||||
} |
@ -0,0 +1,38 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.response.data.compute; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class ComputeHistoryResponseData { |
||||
private long id; |
||||
|
||||
private long cpg; |
||||
|
||||
private long ctdna; |
||||
|
||||
private Boolean hcc; |
||||
|
||||
@JsonProperty("hcc_infer") |
||||
private Boolean hccInfer; |
||||
|
||||
private long pid; |
||||
|
||||
private String time; |
||||
} |
@ -0,0 +1,10 @@ |
||||
package net.lensfrex.dscape.dto.response.data.compute; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@AllArgsConstructor |
||||
public class ComputeResponseData{ |
||||
private Long id; |
||||
} |
@ -0,0 +1,20 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.response.data.user; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class RegisterResponseBody { |
||||
private String uid; |
||||
} |
@ -0,0 +1,58 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.response.general; |
||||
|
||||
//@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Response<T> { |
||||
private final int code; |
||||
private final String message; |
||||
private final T data; |
||||
|
||||
public Response(int code, String message, T data) { |
||||
this.code = code; |
||||
this.message = message; |
||||
this.data = data; |
||||
} |
||||
|
||||
public static <T> Response<T> success(T data) { |
||||
return new Response<>(ResponseCode.SUCCESS.getCode(), "success", data); |
||||
} |
||||
|
||||
public static <T> Response<T> success() { |
||||
return success(null); |
||||
} |
||||
|
||||
public static <T> Response<T> error(int code, String message) { |
||||
return new Response<>(code, message, null); |
||||
} |
||||
|
||||
public static <T> Response<T> error(ResponseCode code, String message) { |
||||
return error(code.getCode(), message); |
||||
} |
||||
|
||||
public static <T> Response<T> error(ResponseCode code) { |
||||
return error(code, code.getMessage()); |
||||
} |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public String getMessage() { |
||||
return message; |
||||
} |
||||
|
||||
public T getData() { |
||||
return data; |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dto.response.general; |
||||
|
||||
public enum ResponseCode { |
||||
SUCCESS(20000, "成功"), |
||||
INVALID_REQUEST(30000, "非法请求"), |
||||
PARAM_WRONG(30001, "参数错误"), |
||||
PERMISSION_DENIED(40000, "权限不足"), |
||||
NEED_LOGIN(40001, "需要登录"), |
||||
TOKEN_EXPIRED(40001, "token过期"), |
||||
TOKEN_INVALID(40002, "token无效"), |
||||
SERVER_INTERNAL_ERROR(50000, "服务器内部错误"), |
||||
API_NOT_IMPLEMENT(0, "接口未实现"), |
||||
|
||||
USERNAME_OR_PASSWORD_WRONG(60101, "用户名或密码不正确"), |
||||
USER_WAS_BANNED(60102, "用户已被封禁"), |
||||
USER_WAS_NOT_IDENTIFIED(60103, "上级管理员未认证该用户"), |
||||
|
||||
USER_NAME_EXISTS(60204, "用户名已经被使用"), |
||||
INVITE_CODE_WRONG(60202, "注册码不正确"), |
||||
|
||||
INVITE_CODE_REACHED_LIMIT(60401, "注册码已达上限"); |
||||
|
||||
private final int code; |
||||
|
||||
private final String message; |
||||
|
||||
ResponseCode(int code, String message) { |
||||
this.code = code; |
||||
this.message = message; |
||||
} |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public String getMessage() { |
||||
return message; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.enums.blacklist; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
import lombok.Getter; |
||||
|
||||
@Getter |
||||
public enum BlackListTypeEnum { |
||||
|
||||
IP_ADDRESS(0, "IP地址"), |
||||
UID(1, "用户UID"), |
||||
; |
||||
|
||||
@EnumValue |
||||
private final int code; |
||||
private final String name; |
||||
|
||||
BlackListTypeEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.enums.compute; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
import lombok.Data; |
||||
import lombok.Getter; |
||||
|
||||
@Getter |
||||
public enum ComputeStatusEnum { |
||||
FINISHED(0, "完成"), |
||||
PROCESSING(1, "处理中"); |
||||
|
||||
@EnumValue |
||||
private final int code; |
||||
private final String name; |
||||
|
||||
ComputeStatusEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.enums.user; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
import lombok.Getter; |
||||
|
||||
@Getter |
||||
public enum UserRoleEnum { |
||||
NORMAL_USER(0, "normal"), |
||||
ADMIN(1, "admin"); |
||||
|
||||
private final static UserRoleEnum[] allEnums = values(); |
||||
@EnumValue |
||||
private final int code; |
||||
private final String name; |
||||
|
||||
UserRoleEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
public static UserRoleEnum getTypeEnumByCode(int code) { |
||||
for (UserRoleEnum result : allEnums) { |
||||
if (result.code == code) { |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
throw new IllegalArgumentException(String.format("角色id\"%s\"不存在", code)); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.enums.user; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
import lombok.Getter; |
||||
|
||||
@Getter |
||||
public enum UserStatusEnum { |
||||
|
||||
NORMAL(0, "正常"), |
||||
BANNED(1, "封禁中"), |
||||
NOT_IDENTIFIED(2, "管理员未认证"); |
||||
|
||||
@EnumValue |
||||
private final int code; |
||||
private final String name; |
||||
|
||||
UserStatusEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.exception; |
||||
|
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
|
||||
public class GlobalException extends RuntimeException { |
||||
private final ResponseCode responseCode; |
||||
|
||||
public GlobalException(ResponseCode responseCode) { |
||||
super(responseCode.toString()); |
||||
this.responseCode = responseCode; |
||||
} |
||||
|
||||
public GlobalException(ResponseCode responseCode, String message) { |
||||
super(message); |
||||
this.responseCode = responseCode; |
||||
} |
||||
|
||||
public ResponseCode getResponseCode() { |
||||
return responseCode; |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ Class created by lensfrex. |
||||
--> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dscape-server</artifactId> |
||||
<groupId>net.lensfrex</groupId> |
||||
<version>0.0.1-dev</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dscape-utils</artifactId> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>11</maven.compiler.source> |
||||
<maven.compiler.target>11</maven.compiler.target> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-core</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-databind</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-annotations</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.datatype</groupId> |
||||
<artifactId>jackson-datatype-jsr310</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<classifier>exec</classifier> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,46 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.utils; |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
||||
|
||||
public class ObjectJsonSerializer { |
||||
/** |
||||
* 序列化对象到json字符串 |
||||
* |
||||
* @param obj 待序列化的对象 |
||||
* @return 序列化后的数据 |
||||
*/ |
||||
public static String serialize(Object obj) { |
||||
try { |
||||
return new ObjectMapper().registerModule(new JavaTimeModule()).writeValueAsString(obj); |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 反序列化对象 |
||||
* |
||||
* @param data 源数据 |
||||
* @return 反序列化后的对象 |
||||
*/ |
||||
public static <T> T deserialize(String data, Class<T> valueType) { |
||||
try { |
||||
return new ObjectMapper().registerModule(new JavaTimeModule()).readValue(data, valueType); |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.utils; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.ObjectInputStream; |
||||
import java.io.ObjectOutputStream; |
||||
|
||||
@Slf4j |
||||
public class ObjectSerializer { |
||||
/** |
||||
* 序列化对象到二进制 |
||||
* |
||||
* @param obj 待序列化的对象 |
||||
* @return 序列化后的数据 |
||||
*/ |
||||
public static byte[] serialize(Object obj) { |
||||
try { |
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
||||
new ObjectOutputStream(byteArrayOutputStream).writeObject(obj); |
||||
|
||||
return byteArrayOutputStream.toByteArray(); |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 反序列化对象 |
||||
* |
||||
* @param data 源数据 |
||||
* @return 反序列化后的对象 |
||||
*/ |
||||
public static Object deserialize(byte[] data) { |
||||
try { |
||||
return new ObjectInputStream(new ByteArrayInputStream(data)).readObject(); |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,67 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.utils.validate; |
||||
|
||||
public class TextCheckUtil { |
||||
|
||||
private static final String ABC_AND_CHINESE_REGEX = "[^a-zA-Z0-9\\_\\u4e00-\\u9fa5]"; |
||||
|
||||
private static final String ABC_REGEX = "[^a-zA-Z0-9\\_]"; |
||||
|
||||
// [^a-zA-Z0-9\_\[\];',./{}:"<>?/*\-\\!@#$%^&()\+\u4e00-\u9fa5]
|
||||
private static final String ALL_CHARACTER_REGEX = "[^a-zA-Z0-9\\_\\[\\];',./{}:\"<>?/*\\-\\\\!@#$%^&()+=~`\\u4e00-\\u9fa5]"; |
||||
|
||||
/** |
||||
* 检测非字母和中文符号(下划线"_"除外) |
||||
* |
||||
* @param source 待检测字符串 |
||||
* @return 是否含有非字母字符 |
||||
*/ |
||||
public static boolean checkNoneAbcAndChinese(String source) { |
||||
return !source.matches(ABC_AND_CHINESE_REGEX); |
||||
} |
||||
|
||||
/** |
||||
* 批量检测非字母和中文符号(下划线"_"除外) |
||||
* |
||||
* @param source 待检测字符串 |
||||
* @return 是否含有非字母字符 |
||||
*/ |
||||
public static boolean checkNoneAbcAndChinese(String... source) { |
||||
for (String text : source) { |
||||
if (text.matches(ABC_AND_CHINESE_REGEX)) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static boolean checkNoneCharacter(String source) { |
||||
return !source.matches(ALL_CHARACTER_REGEX); |
||||
} |
||||
|
||||
public static boolean checkNoneCharacter(String... source) { |
||||
for (String text : source) { |
||||
if (text.matches(ALL_CHARACTER_REGEX)) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,132 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dscape-server</artifactId> |
||||
<groupId>net.lensfrex</groupId> |
||||
<version>0.0.1-dev</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<artifactId>dscape-web</artifactId> |
||||
<description>dscape后端主服务</description> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>11</maven.compiler.source> |
||||
<maven.compiler.target>11</maven.compiler.target> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-dao</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-cache</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-entities</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.lensfrex</groupId> |
||||
<artifactId>dscape-utils</artifactId> |
||||
<version>0.0.1-dev</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
<version>2.7.3</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-tomcat</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter</artifactId> |
||||
<version>2.7.3</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<version>2.7.3</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-core</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-databind</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-annotations</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.mindrot</groupId> |
||||
<artifactId>jbcrypt</artifactId> |
||||
<version>0.4</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-jetty</artifactId> |
||||
<version>2.7.3</version> |
||||
<scope>compile</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>cn.dev33</groupId> |
||||
<artifactId>sa-token-spring-boot-starter</artifactId> |
||||
<version>1.30.0</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-lang3</artifactId> |
||||
</dependency> |
||||
|
||||
<!-- 雪花id算法生成库(改进过的) --> |
||||
<dependency> |
||||
<groupId>com.github.yitter</groupId> |
||||
<artifactId>yitter-idgenerator</artifactId> |
||||
<version>1.0.6</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-amqp</artifactId> |
||||
<version>2.7.3</version> |
||||
</dependency> |
||||
|
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<classifier>exec</classifier> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,29 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape; |
||||
|
||||
import com.github.yitter.contract.IdGeneratorOptions; |
||||
import com.github.yitter.idgen.YitIdHelper; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
||||
|
||||
import java.util.TimeZone; |
||||
|
||||
@SpringBootApplication |
||||
@MapperScan("net.lensfrex.dscape.dao.mapper") |
||||
public class ServerMain extends SpringBootServletInitializer { |
||||
|
||||
public static void main(String[] args) { |
||||
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); |
||||
|
||||
IdGeneratorOptions options = new IdGeneratorOptions((short) 12); |
||||
options.WorkerIdBitLength = 4; |
||||
YitIdHelper.setIdGenerator(options); |
||||
|
||||
SpringApplication.run(ServerMain.class, args); |
||||
} |
||||
} |
@ -0,0 +1,45 @@ |
||||
///*
|
||||
// * Class created by lensfrex.
|
||||
// */
|
||||
//
|
||||
//package net.lensfrex.dscape.annotation;
|
||||
//
|
||||
//import net.lensfrex.dscape.utils.validate.TextCheckUtil;
|
||||
//
|
||||
//import java.lang.annotation.Documented;
|
||||
//import java.lang.annotation.Repeatable;
|
||||
//import java.lang.annotation.Retention;
|
||||
//import java.lang.annotation.Target;
|
||||
//
|
||||
//import static java.lang.annotation.ElementType.*;
|
||||
//import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
//
|
||||
//@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
|
||||
//@Retention(RUNTIME)
|
||||
//@Repeatable(NotInvalidChar.List.class)
|
||||
//@Documented
|
||||
//@Constraint(validatedBy = TextCheckUtil.class)//标明由哪个类执行校验逻辑
|
||||
//public @interface NotInvalidChar {
|
||||
// String message() default "value not in enum values.";
|
||||
//
|
||||
// Class<?>[] groups() default {};
|
||||
//
|
||||
//// Class<? extends Payload>[] payload() default {};
|
||||
//
|
||||
// /**
|
||||
// * @return date must in this value array
|
||||
// */
|
||||
// String[] value();
|
||||
//
|
||||
// /**
|
||||
// * Defines several {@link NotInvalidChar} annotations on the same element.
|
||||
// *
|
||||
// * @see NotInvalidChar
|
||||
// */
|
||||
// @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
|
||||
// @Retention(RUNTIME)
|
||||
// @Documented
|
||||
// @interface List {
|
||||
// NotInvalidChar[] value();
|
||||
// }
|
||||
//}
|
@ -0,0 +1,108 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.auth; |
||||
|
||||
import cn.dev33.satoken.stp.StpInterface; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import net.lensfrex.dscape.dao.service.RolePermissionService; |
||||
import net.lensfrex.dscape.dao.service.UserRoleService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
@Component |
||||
public class StpInterfaceImpl implements StpInterface { |
||||
|
||||
private final UserRoleService userRoleService; |
||||
private final RolePermissionService rolePermissionService; |
||||
|
||||
private final RedisTemplate<String, String> redis; |
||||
|
||||
@Autowired |
||||
public StpInterfaceImpl(RedisTemplate<String, String> redis, |
||||
UserRoleService userRoleService, |
||||
RolePermissionService rolePermissionService) { |
||||
|
||||
this.userRoleService = userRoleService; |
||||
this.rolePermissionService = rolePermissionService; |
||||
this.redis = redis; |
||||
} |
||||
|
||||
@Override |
||||
public List<String> getPermissionList(Object loginId, String loginType) { |
||||
String uid = (String) loginId; |
||||
|
||||
List<String> userRoles = this.getRoleList(loginId, loginType); |
||||
List<String> rolePermissions = new ArrayList<>(); |
||||
|
||||
for (String role : userRoles) { |
||||
String redisRolePermissionKey = "dscape:auth:role:permission:" + role; |
||||
|
||||
if (Boolean.FALSE.equals(redis.hasKey(redisRolePermissionKey))) { |
||||
log.debug("角色 " + uid + " 的权限信息缓存不存在,从数据库中查找并放入缓存"); |
||||
|
||||
rolePermissions.addAll(rolePermissionService.getPermissions(role)); |
||||
if (rolePermissions.isEmpty()) { |
||||
return rolePermissions; |
||||
} |
||||
|
||||
redis.opsForList().leftPushAll(redisRolePermissionKey, rolePermissions); |
||||
} else { |
||||
List<String> cachedUserRole = redis.opsForList().range(redisRolePermissionKey, 0, -1); |
||||
if (cachedUserRole == null) { |
||||
return rolePermissions; |
||||
} |
||||
|
||||
rolePermissions.addAll(cachedUserRole); |
||||
} |
||||
} |
||||
|
||||
return rolePermissions; |
||||
} |
||||
|
||||
@Override |
||||
public List<String> getRoleList(Object loginId, String loginType) { |
||||
String uid = (String) loginId; |
||||
String redisUserRoleKey = "dscape:auth:user:role:" + uid; |
||||
|
||||
List<String> userRoleList = new ArrayList<>(2); |
||||
if (Boolean.FALSE.equals(redis.hasKey(redisUserRoleKey))) { |
||||
log.debug("用户 " + uid + " 的角色信息缓存不存在,从数据库中查找并放入缓存"); |
||||
|
||||
userRoleList.addAll(userRoleService.getRoles(uid)); |
||||
|
||||
if (userRoleList.isEmpty()) { |
||||
return userRoleList; |
||||
} |
||||
|
||||
redis.opsForList().leftPushAll(redisUserRoleKey, userRoleList); |
||||
} else { |
||||
List<String> cachedUserRole = redis.opsForList().range(redisUserRoleKey, 0, -1); |
||||
if (cachedUserRole == null) { |
||||
return userRoleList; |
||||
} |
||||
|
||||
userRoleList.addAll(cachedUserRole); |
||||
} |
||||
|
||||
return userRoleList; |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.configure; |
||||
|
||||
import org.springframework.amqp.core.Binding; |
||||
import org.springframework.amqp.core.BindingBuilder; |
||||
import org.springframework.amqp.core.DirectExchange; |
||||
import org.springframework.amqp.core.Queue; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
public class RabbitConfigure { |
||||
|
||||
public static final String QUEUE_NAME = "net.lensfrex.dscape.mq.queue"; |
||||
|
||||
public static final String EXCHANGE_NAME = "net.lensfrex.dscape.mq.exchange"; |
||||
|
||||
public static final String ROUTING_KEY = "net.lensfrex.dscape.mq.routing"; |
||||
|
||||
@Bean |
||||
public Queue queue() { |
||||
return new Queue(QUEUE_NAME, true, false, false); |
||||
} |
||||
|
||||
@Bean |
||||
public DirectExchange directExchange() { |
||||
return new DirectExchange(EXCHANGE_NAME, true, false); |
||||
} |
||||
|
||||
@Bean |
||||
public Binding binding() { |
||||
return BindingBuilder |
||||
.bind(this.queue()) |
||||
.to(this.directExchange()) |
||||
.with(ROUTING_KEY); |
||||
} |
||||
} |
@ -0,0 +1,187 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.exception.handler; |
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException; |
||||
import cn.dev33.satoken.exception.NotRoleException; |
||||
import com.fasterxml.jackson.databind.JsonMappingException; |
||||
import net.lensfrex.dscape.dto.response.general.Response; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.http.converter.HttpMessageNotReadableException; |
||||
import org.springframework.web.HttpMediaTypeNotSupportedException; |
||||
import org.springframework.web.HttpRequestMethodNotSupportedException; |
||||
import org.springframework.web.bind.MissingServletRequestParameterException; |
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
import org.springframework.web.bind.annotation.RestControllerAdvice; |
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
||||
import org.springframework.web.multipart.MultipartException; |
||||
|
||||
/** |
||||
* 全局异常处理,负责后端抛出Exception时响应相应的信息 |
||||
*/ |
||||
@RestControllerAdvice |
||||
public class GlobalExceptionHandler { |
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); |
||||
|
||||
/** |
||||
* 负责处理各种自定义业务异常(权限不足,学号不存在等) |
||||
* |
||||
* @param e 抛出的异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(GlobalException.class) |
||||
public Response<Object> handler(GlobalException e) { |
||||
log.debug("请求错误: " + e.getResponseCode().getMessage()); |
||||
return Response.error(e.getResponseCode()); |
||||
} |
||||
|
||||
/** |
||||
* 负责处理和响应其他部分都没有接收的异常(说白了就是剩下的都返回50000) |
||||
* 这部分日志要特别关注,所以以error打出来 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(Exception.class) |
||||
public Response<Object> handler(Exception e) { |
||||
log.error("请求错误: " + e.getMessage()); |
||||
log.error("异常类: " + e.getClass()); |
||||
log.error("追踪:", e); |
||||
return Response.error(ResponseCode.SERVER_INTERNAL_ERROR); |
||||
} |
||||
|
||||
/** |
||||
* 处理参数不完整的请求异常 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(MissingServletRequestParameterException.class) |
||||
public Response<Object> handler(MissingServletRequestParameterException e) { |
||||
log.debug("请求的参数不完整: " + e.getMessage()); |
||||
return Response.error(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
/** |
||||
* 处理参数类型错误的请求异常(请求参数类型错误) |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class) |
||||
public Response<Object> handler(MethodArgumentTypeMismatchException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
/** |
||||
* 处理参数类型错误的请求异常(请求参数类型错误) |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(IllegalArgumentException.class) |
||||
public Response<Object> handler(IllegalArgumentException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
/** |
||||
* 处理参数类型错误的请求异常2(Json解析错误) |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(JsonMappingException.class) |
||||
public Response<Object> handler(JsonMappingException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
/** |
||||
* 处理参数类型错误的请求异常3(字段映射错误) |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(HttpMessageNotReadableException.class) |
||||
public Response<Object> handler(HttpMessageNotReadableException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
/** |
||||
* 处理请求头中“Content-Type”字段不正确的异常 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(HttpMediaTypeNotSupportedException.class) |
||||
public Response<Object> handler(HttpMediaTypeNotSupportedException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.PARAM_WRONG, "请求头\"Contene-Type\"字段有误"); |
||||
} |
||||
|
||||
/** |
||||
* 处理请求方法错误的情况 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) |
||||
public Response<Object> handler(HttpRequestMethodNotSupportedException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.INVALID_REQUEST); |
||||
} |
||||
|
||||
/** |
||||
* 处理上传文件时不是Multipart方式 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(MultipartException.class) |
||||
public Response<Object> handler(MultipartException e) { |
||||
log.debug(String.format("请求错误(%s): %s", e.getClass().getName(), e.getMessage())); |
||||
return Response.error(ResponseCode.INVALID_REQUEST); |
||||
} |
||||
|
||||
/** |
||||
* 权限不足 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(NotRoleException.class) |
||||
public Response<Object> handler(NotRoleException e) { |
||||
return Response.error(ResponseCode.PERMISSION_DENIED); |
||||
} |
||||
|
||||
/** |
||||
* 没登陆 |
||||
* |
||||
* @param e 异常 |
||||
* @return 统一响应 |
||||
*/ |
||||
@ExceptionHandler(NotLoginException.class) |
||||
public Response<Object> handler(NotLoginException e) { |
||||
return Response.error(ResponseCode.NEED_LOGIN); |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.mq; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import net.lensfrex.dscape.configure.RabbitConfigure; |
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Slf4j |
||||
@Component |
||||
public class MessageQueueProducer { |
||||
private final RabbitTemplate rabbit; |
||||
|
||||
public MessageQueueProducer(RabbitTemplate rabbit) { |
||||
this.rabbit = rabbit; |
||||
} |
||||
|
||||
public void sendObject(Object data) { |
||||
rabbit.convertAndSend(RabbitConfigure.EXCHANGE_NAME, RabbitConfigure.ROUTING_KEY, data); |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.utils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
public class NetworkUtil { |
||||
|
||||
public static String getRealIP(HttpServletRequest request) { |
||||
String forward = request.getHeader("X-Forwarded-For"); |
||||
if (forward != null) { |
||||
return forward.split(",")[0]; |
||||
} else { |
||||
return request.getRemoteAddr(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.compute; |
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin; |
||||
import net.lensfrex.dscape.dto.request.compute.ComputeRequestBody; |
||||
import net.lensfrex.dscape.dto.response.data.compute.ComputeResponseData; |
||||
import net.lensfrex.dscape.dto.response.general.Response; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.web.service.compute.ComputeService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@SaCheckLogin |
||||
@RestController |
||||
@RequestMapping("/compute") |
||||
public class ComputeController { |
||||
|
||||
private final ComputeService computeService; |
||||
|
||||
public ComputeController(ComputeService computeService) { |
||||
this.computeService = computeService; |
||||
} |
||||
|
||||
@GetMapping(value = "/status/{tid}", produces = "application/json") |
||||
public Response status(@PathVariable String tid, |
||||
@RequestHeader String token) { |
||||
return Response.error(ResponseCode.API_NOT_IMPLEMENT); |
||||
} |
||||
|
||||
@PostMapping(value = "/add", produces = "application/json") |
||||
public Response<ComputeResponseData> addComputeTask(@RequestBody ComputeRequestBody request) { |
||||
long rid = computeService.addTask(request); |
||||
|
||||
return Response.success(new ComputeResponseData(rid)); |
||||
} |
||||
} |
@ -0,0 +1,87 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.history; |
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin; |
||||
import cn.dev33.satoken.stp.StpUtil; |
||||
import net.lensfrex.dscape.dao.entity.PatientData; |
||||
import net.lensfrex.dscape.dto.response.data.compute.ComputeHistoryResponseData; |
||||
import net.lensfrex.dscape.dto.response.general.Response; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import net.lensfrex.dscape.web.service.data.HistoryService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@SaCheckLogin |
||||
@RestController |
||||
@RequestMapping("/history") |
||||
public class HistoryController { |
||||
private final HistoryService historyService; |
||||
|
||||
public HistoryController(HistoryService historyService) { |
||||
this.historyService = historyService; |
||||
} |
||||
|
||||
@GetMapping(value = "/list", produces = "application/json") |
||||
public Response<List<ComputeHistoryResponseData>> list(@RequestParam(required = false, defaultValue = "1") int page, |
||||
@RequestParam(required = false, defaultValue = "10") int limit) { |
||||
|
||||
String uid = StpUtil.getLoginIdAsString(); |
||||
|
||||
List<PatientData> results = historyService.getUserHistoryData(uid, page, limit); |
||||
|
||||
List<ComputeHistoryResponseData> responseDataList = new ArrayList<>(results.size()); |
||||
results.forEach(result -> { |
||||
ComputeHistoryResponseData response = new ComputeHistoryResponseData(); |
||||
response.setId(result.getId()); |
||||
response.setPid(result.getPid()); |
||||
response.setCpg(result.getCpg()); |
||||
response.setHcc(result.getIsHcc() == 1); |
||||
response.setHccInfer(result.getIsInferHcc() == 1); |
||||
response.setCtdna(result.getCtdnaLength()); |
||||
response.setTime(result.getCreateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); |
||||
|
||||
responseDataList.add(response); |
||||
}); |
||||
|
||||
return Response.success(responseDataList); |
||||
} |
||||
|
||||
@RequestMapping(value = "/delete/{rid}", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json") |
||||
public Response<Object> delete(@PathVariable long rid) { |
||||
String historyUser = historyService.getHistoryUser(rid); |
||||
|
||||
if (!StpUtil.getLoginIdAsString().equals(historyUser)) { |
||||
throw new GlobalException(ResponseCode.PERMISSION_DENIED); |
||||
} |
||||
|
||||
historyService.deleteHistoryData(rid); |
||||
|
||||
return Response.success(); |
||||
} |
||||
|
||||
@RequestMapping(value = "/count", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json") |
||||
public Response<Long> count() { |
||||
long result = historyService.getTotalCount(StpUtil.getLoginIdAsString()); |
||||
|
||||
return Response.success(result); |
||||
} |
||||
} |
@ -0,0 +1,87 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.user; |
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo; |
||||
import cn.dev33.satoken.stp.StpUtil; |
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
||||
import net.lensfrex.dscape.dto.request.UserLoginRequestBody; |
||||
import net.lensfrex.dscape.dto.response.general.Response; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import net.lensfrex.dscape.web.service.user.UserService; |
||||
import net.lensfrex.dscape.dto.request.user.PasswordModifyRequestBody; |
||||
import net.lensfrex.dscape.dto.request.user.RegisterRequestBody; |
||||
import net.lensfrex.dscape.dto.response.data.user.RegisterResponseBody; |
||||
import net.lensfrex.dscape.utils.NetworkUtil; |
||||
import net.lensfrex.dscape.utils.validate.TextCheckUtil; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class) |
||||
@RestController |
||||
@RequestMapping("/user") |
||||
public class UserController { |
||||
|
||||
private final UserService userService; |
||||
|
||||
public UserController(UserService userService) { |
||||
this.userService = userService; |
||||
} |
||||
|
||||
@PostMapping(value = "/login", produces = "application/json") |
||||
public Response<SaTokenInfo> login(@RequestBody UserLoginRequestBody requestBody) { |
||||
if (requestBody == null |
||||
|| requestBody.getUserName() == null |
||||
|| requestBody.getPassword() == null) { |
||||
|
||||
throw new GlobalException(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
return Response.success(userService.login(requestBody)); |
||||
} |
||||
|
||||
@GetMapping(value = "/checkLogin", produces = "application/json") |
||||
public Response<SaTokenInfo> testLogin() { |
||||
return Response.success(userService.checkLogin()); |
||||
} |
||||
|
||||
@PostMapping(value = "/register", produces = "application/json") |
||||
public Response<RegisterResponseBody> register(@RequestBody RegisterRequestBody request, HttpServletRequest httpServletRequest) { |
||||
if (request.getUserName() == null || request.getPassword() == null) { |
||||
throw new GlobalException(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
// 这里的密码也用checkNoneAbcAndChinese是因为正常从前端发来的话是sha256,实际上是可以任意符号的
|
||||
if (TextCheckUtil.checkNoneAbcAndChinese(request.getUserName(), request.getPassword())) { |
||||
throw new GlobalException(ResponseCode.INVALID_REQUEST); |
||||
} |
||||
|
||||
return Response.success(userService.register(request, NetworkUtil.getRealIP(httpServletRequest))); |
||||
} |
||||
|
||||
@PostMapping(value = "/modifyPassword/{uid}", produces = "application/json") |
||||
public Response<Object> modifyPassword(@RequestBody PasswordModifyRequestBody body, @PathVariable String uid) { |
||||
StpUtil.checkLogin(); |
||||
|
||||
userService.modifyPassword(uid, body.getOldPassword(), body.getNewPassword()); |
||||
|
||||
return Response.success(); |
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.user.admin; |
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin; |
||||
import cn.dev33.satoken.stp.StpUtil; |
||||
import net.lensfrex.dscape.dto.response.general.Response; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.enums.user.UserRoleEnum; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import net.lensfrex.dscape.dto.request.user.UserAddRequest; |
||||
import net.lensfrex.dscape.dto.response.data.user.RegisterResponseBody; |
||||
import net.lensfrex.dscape.utils.NetworkUtil; |
||||
import net.lensfrex.dscape.web.service.user.AdminService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
@SaCheckLogin |
||||
@RestController |
||||
@RequestMapping("/user/admin") |
||||
public class AdminController { |
||||
|
||||
private final AdminService adminService; |
||||
|
||||
public AdminController(AdminService adminService) { |
||||
this.adminService = adminService; |
||||
} |
||||
|
||||
@PostMapping(value = "/add", produces = "application/json") |
||||
public Response<RegisterResponseBody> addUser(@RequestBody UserAddRequest request, HttpServletRequest httpServletRequest) { |
||||
StpUtil.checkRole(String.valueOf(UserRoleEnum.ADMIN.getCode())); |
||||
|
||||
return Response.success(adminService.adminAddUser(request, NetworkUtil.getRealIP(httpServletRequest))); |
||||
} |
||||
|
||||
@PostMapping(value = "/modifyStatus", produces = "application/json") |
||||
public Response<Object> modifyStatus(@RequestParam String uid, @RequestParam int status) { |
||||
StpUtil.checkRole(String.valueOf(UserRoleEnum.ADMIN.getCode())); |
||||
|
||||
if (StpUtil.getLoginIdAsString().equals(uid)) { |
||||
throw new GlobalException(ResponseCode.PERMISSION_DENIED); |
||||
} |
||||
|
||||
switch (status) { |
||||
case 0: |
||||
case 1: |
||||
adminService.modifyUserStatus(uid, status); |
||||
break; |
||||
case 2: |
||||
adminService.deleteUser(uid); |
||||
break; |
||||
case 3: |
||||
adminService.addUserToBlackList(uid); |
||||
break; |
||||
default: |
||||
throw new GlobalException(ResponseCode.PARAM_WRONG); |
||||
} |
||||
|
||||
return Response.success(); |
||||
} |
||||
|
||||
@GetMapping(value = "/inviteCode", produces = "application/json") |
||||
public Response<List<String>> generateInviteCodes(@RequestParam(required = false, defaultValue = "-1") long expired, |
||||
@RequestParam(required = false, defaultValue = "1") int count) { |
||||
StpUtil.checkRole(String.valueOf(UserRoleEnum.ADMIN.getCode())); |
||||
|
||||
if (count > 1024) { |
||||
throw new GlobalException(ResponseCode.INVALID_REQUEST); |
||||
} |
||||
|
||||
List<String> result = adminService.generateInviteCode(expired, count); |
||||
|
||||
return Response.success(result); |
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.service.compute; |
||||
|
||||
import cn.dev33.satoken.stp.StpUtil; |
||||
import com.github.yitter.idgen.YitIdHelper; |
||||
import net.lensfrex.dscape.configure.RabbitConfigure; |
||||
import net.lensfrex.dscape.dao.entity.ComputeHistory; |
||||
import net.lensfrex.dscape.dao.entity.PatientData; |
||||
import net.lensfrex.dscape.dao.service.ComputeHistoryService; |
||||
import net.lensfrex.dscape.dao.service.PatientDataService; |
||||
import net.lensfrex.dscape.dto.request.compute.ComputeRequestBody; |
||||
import net.lensfrex.dscape.enums.compute.ComputeStatusEnum; |
||||
import net.lensfrex.dscape.mq.MessageQueueProducer; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
@Service |
||||
public class ComputeService { |
||||
private final PatientDataService patientDataService; |
||||
|
||||
private final ComputeHistoryService computeHistoryService; |
||||
|
||||
private final MessageQueueProducer messageQueueProducer; |
||||
|
||||
public ComputeService(PatientDataService patientDataService, |
||||
ComputeHistoryService computeHistoryService, |
||||
MessageQueueProducer messageQueueProducer) { |
||||
|
||||
this.patientDataService = patientDataService; |
||||
this.computeHistoryService = computeHistoryService; |
||||
this.messageQueueProducer = messageQueueProducer; |
||||
} |
||||
|
||||
@Transactional |
||||
public long addTask(ComputeRequestBody request) { |
||||
long rid = YitIdHelper.nextId(); |
||||
String uid = StpUtil.getLoginIdAsString(); |
||||
|
||||
ComputeHistory computeHistory = new ComputeHistory(); |
||||
computeHistory.setUid(uid); |
||||
computeHistory.setRid(rid); |
||||
computeHistory.setStatus(ComputeStatusEnum.PROCESSING.getCode()); |
||||
|
||||
PatientData patientData = new PatientData(); |
||||
patientData.setId(rid); |
||||
patientData.setCpg(request.getCpg()); |
||||
patientData.setPid(request.getPid()); |
||||
patientData.setCtdnaLength(request.getCtdna()); |
||||
|
||||
computeHistoryService.save(computeHistory); |
||||
patientDataService.save(patientData); |
||||
|
||||
this.addMessageQueue(patientData); |
||||
|
||||
return rid; |
||||
} |
||||
|
||||
private void addMessageQueue(PatientData patientData) { |
||||
messageQueueProducer.sendObject(patientData); |
||||
} |
||||
} |
@ -0,0 +1,62 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.service.data; |
||||
|
||||
import net.lensfrex.dscape.dao.entity.ComputeHistory; |
||||
import net.lensfrex.dscape.dao.entity.PatientData; |
||||
import net.lensfrex.dscape.dao.service.PatientDataService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import net.lensfrex.dscape.dao.service.ComputeHistoryService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
@Service |
||||
public class HistoryService { |
||||
|
||||
private final ComputeHistoryService computeHistoryService; |
||||
|
||||
private final PatientDataService patientDataService; |
||||
|
||||
public HistoryService(ComputeHistoryService computeHistoryService, |
||||
PatientDataService patientDataService) { |
||||
|
||||
this.computeHistoryService = computeHistoryService; |
||||
this.patientDataService = patientDataService; |
||||
} |
||||
|
||||
public long getTotalCount(String uid) { |
||||
return computeHistoryService.count(ComputeHistory::getUid, uid); |
||||
} |
||||
|
||||
public List<Long> getUserHistoryId(String uid, int page, int limit) { |
||||
return computeHistoryService.getHistoryDataIds(uid, page, limit); |
||||
} |
||||
|
||||
public List<PatientData> getUserHistoryData(String uid, int page, int limit) { |
||||
return patientDataService.getData(getUserHistoryId(uid, page, limit)); |
||||
} |
||||
|
||||
public String getHistoryUser(Long rid) { |
||||
return computeHistoryService.getHistoryUser(rid); |
||||
} |
||||
|
||||
public void deleteHistoryData(Long rid) { |
||||
computeHistoryService.remove(rid); |
||||
} |
||||
} |
@ -0,0 +1,118 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.service.user; |
||||
|
||||
import cn.dev33.satoken.stp.StpUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import net.lensfrex.dscape.web.service.user.admin.InviteCode; |
||||
import net.lensfrex.dscape.cache.UserBasicCache; |
||||
import net.lensfrex.dscape.dao.entity.BlackList; |
||||
import net.lensfrex.dscape.dao.entity.UserBasic; |
||||
import net.lensfrex.dscape.dao.service.BlackListService; |
||||
import net.lensfrex.dscape.dao.service.UserBasicService; |
||||
import net.lensfrex.dscape.dto.request.user.UserAddRequest; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.enums.blacklist.BlackListTypeEnum; |
||||
import net.lensfrex.dscape.enums.user.UserRoleEnum; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import net.lensfrex.dscape.dto.response.data.user.RegisterResponseBody; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Service |
||||
public class AdminService { |
||||
private final RedisTemplate<String, String> redis; |
||||
|
||||
private final UserBasicService userBasicService; |
||||
|
||||
private final UserService userService; |
||||
|
||||
private final BlackListService blackListService; |
||||
|
||||
private final InviteCode inviteCode; |
||||
|
||||
private final UserBasicCache userBasicCache; |
||||
|
||||
public AdminService(RedisTemplate<String, String> redis, |
||||
UserBasicService userBasicService, |
||||
UserService userService, |
||||
BlackListService blackListService, |
||||
InviteCode inviteCode, |
||||
UserBasicCache userBasicCache) { |
||||
|
||||
this.redis = redis; |
||||
this.userBasicService = userBasicService; |
||||
this.userService = userService; |
||||
this.blackListService = blackListService; |
||||
this.inviteCode = inviteCode; |
||||
this.userBasicCache = userBasicCache; |
||||
} |
||||
|
||||
public List<String> generateInviteCode(long expired, int count) { |
||||
return inviteCode.generateInviteCode(expired, count, StpUtil.getLoginIdAsString()); |
||||
} |
||||
|
||||
public void modifyUserStatus(String uid, int status) { |
||||
UpdateWrapper<UserBasic> wrapper = new UpdateWrapper<>(); |
||||
wrapper.lambda() |
||||
.eq(UserBasic::getUid, uid) |
||||
.eq(UserBasic::getSuperior, StpUtil.getLoginIdAsString()) |
||||
.set(UserBasic::getStatus, status); |
||||
|
||||
this.clearUserBasicCache(uid); |
||||
userBasicService.update(wrapper); |
||||
} |
||||
|
||||
public void addUserToBlackList(String uid) { |
||||
BlackList blackList = new BlackList(); |
||||
blackList.setData(uid); |
||||
blackList.setType(BlackListTypeEnum.UID.getCode()); |
||||
|
||||
blackListService.save(blackList); |
||||
} |
||||
|
||||
public void deleteUser(String uid) { |
||||
this.clearUserBasicCache(uid); |
||||
|
||||
userBasicService.removeById(uid); |
||||
} |
||||
|
||||
private void clearUserBasicCache(String uid) { |
||||
userBasicCache.clear(uid); |
||||
} |
||||
|
||||
public RegisterResponseBody adminAddUser(UserAddRequest requestBody, String registerIp) { |
||||
if (userService.userNameExists(requestBody.getUserName())) { |
||||
throw new GlobalException(ResponseCode.USER_NAME_EXISTS); |
||||
} |
||||
|
||||
String uid = userService.addUserToDatabase(requestBody.getUserName(), requestBody.getPassword(), |
||||
StpUtil.getLoginIdAsString(), UserRoleEnum.getTypeEnumByCode(requestBody.getRole()), registerIp); |
||||
|
||||
RegisterResponseBody registerResponseBody = new RegisterResponseBody(); |
||||
registerResponseBody.setUid(uid); |
||||
|
||||
return registerResponseBody; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,211 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.service.user; |
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo; |
||||
import cn.dev33.satoken.stp.StpUtil; |
||||
import net.lensfrex.dscape.dao.entity.UserBasic; |
||||
import net.lensfrex.dscape.dao.service.UserBasicService; |
||||
import net.lensfrex.dscape.dto.request.UserLoginRequestBody; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.enums.user.UserRoleEnum; |
||||
import net.lensfrex.dscape.enums.user.UserStatusEnum; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import net.lensfrex.dscape.web.service.user.admin.InviteCode; |
||||
import net.lensfrex.dscape.cache.UserBasicCache; |
||||
import net.lensfrex.dscape.dao.entity.UserRole; |
||||
import net.lensfrex.dscape.dao.service.UserRoleService; |
||||
import net.lensfrex.dscape.dto.request.user.RegisterRequestBody; |
||||
import net.lensfrex.dscape.dto.response.data.user.RegisterResponseBody; |
||||
import org.mindrot.jbcrypt.BCrypt; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.UUID; |
||||
|
||||
@Slf4j |
||||
@Service |
||||
public class UserService { |
||||
private final UserBasicCache userBasicCache; |
||||
|
||||
private final UserBasicService userBasicService; |
||||
|
||||
private final UserRoleService userRoleService; |
||||
|
||||
private final InviteCode inviteCode; |
||||
|
||||
@Autowired |
||||
public UserService(UserBasicCache userBasicCache, |
||||
UserBasicService userBasicService, |
||||
UserRoleService userRoleService, |
||||
InviteCode inviteCode) { |
||||
|
||||
this.userBasicCache = userBasicCache; |
||||
this.userBasicService = userBasicService; |
||||
this.userRoleService = userRoleService; |
||||
this.inviteCode = inviteCode; |
||||
} |
||||
|
||||
public SaTokenInfo checkLogin() { |
||||
return StpUtil.getTokenInfo(); |
||||
} |
||||
|
||||
public SaTokenInfo login(UserLoginRequestBody requestBody) { |
||||
String username = requestBody.getUserName(); |
||||
String password = requestBody.getPassword(); |
||||
|
||||
// 找缓存
|
||||
UserBasic userBasic = userBasicCache.getUserByUserName(username); |
||||
if (userBasic == null) { |
||||
userBasic = this.getUserAndCache(username); |
||||
} |
||||
|
||||
// 验证密码
|
||||
if (userBasic != null && BCrypt.checkpw(password, userBasic.getPassword())) { |
||||
// 检查用户状态
|
||||
if (userBasic.getStatus() == UserStatusEnum.BANNED.getCode()) { |
||||
throw new GlobalException(ResponseCode.USER_WAS_BANNED); |
||||
} else if (userBasic.getStatus() == UserStatusEnum.NOT_IDENTIFIED.getCode()) { |
||||
throw new GlobalException(ResponseCode.USER_WAS_NOT_IDENTIFIED); |
||||
} |
||||
|
||||
StpUtil.login(userBasic.getUid()); |
||||
} else { |
||||
throw new GlobalException(ResponseCode.USERNAME_OR_PASSWORD_WRONG); |
||||
} |
||||
|
||||
return StpUtil.getTokenInfo(); |
||||
} |
||||
|
||||
private UserBasic getUserAndCache(String username) { |
||||
UserBasic userBasic = userBasicService.getUser(UserBasic::getUserName, username); |
||||
this.cacheUser(userBasic); |
||||
|
||||
return userBasic; |
||||
} |
||||
|
||||
private UserBasic getUserAndCacheByUid(String uid) { |
||||
UserBasic userBasic = userBasicService.getUser(UserBasic::getUid, uid); |
||||
this.cacheUser(userBasic); |
||||
|
||||
return userBasic; |
||||
} |
||||
|
||||
private boolean cacheUser(UserBasic userBasic) { |
||||
try { |
||||
if (userBasic != null) { |
||||
userBasicCache.save(userBasic); |
||||
} |
||||
} catch (Exception e) { |
||||
log.info("将用户数据存入redis缓存时发生错误"); |
||||
log.debug("追踪:", e); |
||||
|
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
@Transactional |
||||
public RegisterResponseBody register(RegisterRequestBody requestBody, String registerIp) { |
||||
if (userNameExists(requestBody.getUserName())) { |
||||
throw new GlobalException(ResponseCode.USER_NAME_EXISTS); |
||||
} |
||||
|
||||
RegisterResponseBody registerResponseBody = new RegisterResponseBody(); |
||||
|
||||
// 注册码验证
|
||||
String inviteCode = requestBody.getInviteCode(); |
||||
if (inviteCode == null) { |
||||
// 验证是否注册为初始管理员
|
||||
if (userBasicService.count() != 0) { |
||||
throw new GlobalException(ResponseCode.PERMISSION_DENIED); |
||||
} |
||||
|
||||
String uid = addUserToDatabase(requestBody.getUserName(), requestBody.getPassword(), "null", UserRoleEnum.ADMIN, registerIp); |
||||
registerResponseBody.setUid(uid); |
||||
} else { |
||||
String superior = this.inviteCode.useInviteCode(inviteCode); |
||||
|
||||
String uid = addUserToDatabase(requestBody.getUserName(), requestBody.getPassword(), superior, UserRoleEnum.NORMAL_USER, registerIp); |
||||
registerResponseBody.setUid(uid); |
||||
} |
||||
|
||||
return registerResponseBody; |
||||
} |
||||
|
||||
/** |
||||
* 添加一个用户到数据库 |
||||
* |
||||
* @param userName 用户名 |
||||
* @param password 密码(未用bcrypt加密的) |
||||
* @param superior 上级管理员,本身是管理员时可为空 |
||||
* @param userRoleEnum 用户角色 |
||||
* @return 用户uid |
||||
*/ |
||||
protected String addUserToDatabase(String userName, String password, String superior, UserRoleEnum userRoleEnum, String userIp) { |
||||
UserBasic userBasic = new UserBasic(); |
||||
|
||||
String uid = UUID.randomUUID().toString(); |
||||
userBasic.setUid(uid); |
||||
userBasic.setPassword(BCrypt.hashpw(password, BCrypt.gensalt())); |
||||
userBasic.setUserName(userName); |
||||
userBasic.setStatus(UserStatusEnum.NORMAL.getCode()); |
||||
userBasic.setSuperior(superior); |
||||
userBasic.setCreateIp(userIp); |
||||
userBasicService.save(userBasic); |
||||
|
||||
UserRole userRole = new UserRole(); |
||||
userRole.setRole(userRoleEnum.getCode()); |
||||
userRole.setUid(uid); |
||||
userRoleService.save(userRole); |
||||
|
||||
return uid; |
||||
} |
||||
|
||||
protected boolean userNameExists(String username) { |
||||
return userBasicService.userNameExists(username); |
||||
} |
||||
|
||||
public void modifyPassword(String uid, String oldPassword, String newPassword) { |
||||
String loginUser = StpUtil.getLoginIdAsString(); |
||||
|
||||
UserBasic userBasic = this.getUserAndCacheByUid(uid); |
||||
if (userBasic == null) { |
||||
return; |
||||
} |
||||
|
||||
if (!loginUser.equals(uid)) { |
||||
if (!loginUser.equals(userBasic.getSuperior())) { |
||||
throw new GlobalException(ResponseCode.PERMISSION_DENIED); |
||||
} |
||||
} |
||||
|
||||
if (BCrypt.checkpw(userBasic.getPassword(), oldPassword)) { |
||||
throw new GlobalException(ResponseCode.PERMISSION_DENIED); |
||||
} |
||||
|
||||
String newHashedPassword = BCrypt.hashpw(newPassword, BCrypt.gensalt()); |
||||
|
||||
userBasicService.modify(UserBasic::getUid, uid, |
||||
UserBasic::getPassword, newHashedPassword); |
||||
|
||||
userBasicCache.clear(uid); |
||||
} |
||||
} |
@ -0,0 +1,92 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.service.user.admin; |
||||
|
||||
import net.lensfrex.dscape.configure.GlobalConstant; |
||||
import net.lensfrex.dscape.dto.response.general.ResponseCode; |
||||
import net.lensfrex.dscape.exception.GlobalException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang3.RandomStringUtils; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
@Service |
||||
public class InviteCode { |
||||
private static final int INVITE_CODE_LENGTH = 6; |
||||
|
||||
private static final String REGISTER_INVITE_CODE_KEY = GlobalConstant.REGISTER_INVITE_CODE_KEY; |
||||
|
||||
private static final String ADMIN_INVITE_CODE_COUNTER_KEY = GlobalConstant.ADMIN_INVITE_CODE_COUNTER_KEY; |
||||
|
||||
private final RedisTemplate<String, String> redis; |
||||
|
||||
public InviteCode(RedisTemplate<String, String> redis) { |
||||
this.redis = redis; |
||||
} |
||||
|
||||
public List<String> generateInviteCode(long expired, int count, String adminUid) { |
||||
String adminInviteCodeCounterKey = String.format(ADMIN_INVITE_CODE_COUNTER_KEY, adminUid); |
||||
|
||||
String countResult = redis.opsForValue().get(adminInviteCodeCounterKey); |
||||
|
||||
if (countResult != null && Integer.parseInt(countResult) > 1024) { |
||||
throw new GlobalException(ResponseCode.INVITE_CODE_REACHED_LIMIT); |
||||
} |
||||
|
||||
List<String> inviteCodes = new ArrayList<>(count); |
||||
|
||||
for (int i = 0; i < count; i++) { |
||||
inviteCodes.add(RandomStringUtils.randomAlphanumeric(INVITE_CODE_LENGTH)); |
||||
} |
||||
HashMap<String, String> codeAdmin = new HashMap<>(count); |
||||
inviteCodes.forEach(inviteCode -> codeAdmin.put(inviteCode, adminUid)); |
||||
|
||||
redis.opsForHash().putAll(REGISTER_INVITE_CODE_KEY, codeAdmin); |
||||
redis.opsForValue().increment(adminInviteCodeCounterKey, count); |
||||
|
||||
return inviteCodes; |
||||
} |
||||
|
||||
public boolean checkInviteCode(String code) { |
||||
try { |
||||
return redis.opsForHash().get(REGISTER_INVITE_CODE_KEY, code) == null; |
||||
} catch (Exception e) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public String useInviteCode(String code) { |
||||
try { |
||||
String superior = (String) redis.opsForHash().get(REGISTER_INVITE_CODE_KEY, code); |
||||
if (superior == null) { |
||||
throw new GlobalException(ResponseCode.INVITE_CODE_WRONG); |
||||
} |
||||
|
||||
redis.opsForHash().delete(REGISTER_INVITE_CODE_KEY, code); |
||||
redis.opsForValue().decrement(String.format(ADMIN_INVITE_CODE_COUNTER_KEY, superior)); |
||||
|
||||
return superior; |
||||
} catch (Exception e) { |
||||
throw new GlobalException(ResponseCode.INVITE_CODE_WRONG); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
spring: |
||||
profiles: |
||||
active: dev |
||||
|
||||
--- |
||||
|
||||
server: |
||||
address: 127.0.0.1 |
||||
port: 6480 |
||||
http2: |
||||
enabled: false |
||||
ssl: |
||||
enabled: false |
||||
trust-certificate: |
||||
trust-certificate-private-key: |
||||
logging: |
||||
level: |
||||
net.lensfrex.dscape: debug |
||||
spring: |
||||
datasource: |
||||
driver-class-name: org.mariadb.jdbc.Driver |
||||
url: jdbc:mariadb://localhost:3306/dscape?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai |
||||
username: "dscape_user" |
||||
password: asdfasdf |
||||
rabbitmq: |
||||
host: 127.0.0.1 |
||||
port: 5672 |
||||
username: dscape-test |
||||
password: asdfasdf |
||||
redis: |
||||
client-name: dscape |
||||
host: 127.0.0.1 |
||||
port: 49153 |
||||
username: default |
||||
password: bd2fbffa5 |
||||
timeout: 2000ms |
||||
lettuce: |
||||
pool: |
||||
max-active: 8 |
||||
max-wait: -1 |
||||
max-idle: 8 |
||||
min-idle: 0 |
||||
config: |
||||
activate: |
||||
on-profile: dev |
||||
|
||||
mybatis-plus: |
||||
configuration: |
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
||||
default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler |
||||
global-config: |
||||
db-config: |
||||
logic-delete-field: id_deleted |
||||
logic-not-delete-value: 0 |
||||
logic-delete-value: 1 |
||||
|
||||
sa-token: |
||||
token-name: dscape-token |
||||
timeout: 259200 |
||||
activity-timeout: -1 |
||||
is-concurrent: true |
||||
is-share: false |
||||
token-style: random-64 |
||||
is-log: true |
||||
|
||||
# 性能检测用的,记得在生产环境中不要enable |
||||
ko-time: |
||||
enable: true |
||||
pointcut: execution(public * net.lensfrex.dscape..*.*(..)) |
||||
threshold: 250.0 |
||||
exception-enable: true |
||||
auth-enable: false |
||||
log-enable: true |
@ -1,15 +0,0 @@ |
||||
package net.lensfrex.dscape; |
||||
|
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
||||
|
||||
@SpringBootApplication |
||||
@MapperScan("net.lensfrex.dscape.dao.mappers") |
||||
public class ServerMain extends SpringBootServletInitializer { |
||||
|
||||
public static void main(String[] args) { |
||||
SpringApplication.run(ServerMain.class, args); |
||||
} |
||||
} |
@ -1,12 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao; |
||||
|
||||
public class PatientDataDao { |
||||
} |
@ -1,5 +0,0 @@ |
||||
package net.lensfrex.dscape.dao; |
||||
|
||||
public class UserBasicDao { |
||||
|
||||
} |
@ -1,12 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.dao.mappers; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.domain.PatientData; |
||||
|
||||
public interface PatientDataMapper extends BaseMapper<PatientData> { |
||||
|
||||
} |
@ -1,10 +0,0 @@ |
||||
package net.lensfrex.dscape.dao.mappers; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.lensfrex.dscape.domain.user.UserBasic; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
@Repository |
||||
public interface UserBasicMapper extends BaseMapper<UserBasic> { |
||||
|
||||
} |
@ -1,142 +0,0 @@ |
||||
package net.lensfrex.dscape.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@TableName("patient_data") |
||||
public class PatientData { |
||||
|
||||
/** |
||||
* 患者数据id |
||||
*/ |
||||
private int id; |
||||
|
||||
/** |
||||
* 病人id |
||||
*/ |
||||
private int pid; |
||||
|
||||
/** |
||||
* ctDNA长度 |
||||
*/ |
||||
private int ctDNALength; |
||||
|
||||
/** |
||||
* 甲基化位点数 |
||||
*/ |
||||
private int cpg; |
||||
|
||||
/** |
||||
* 是否为hcc |
||||
*/ |
||||
private boolean hccStatus; |
||||
|
||||
/** |
||||
* 通过推断得出的hcc状态 |
||||
*/ |
||||
private boolean hccInferStatus; |
||||
|
||||
/** |
||||
* create_time |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* edit_time |
||||
*/ |
||||
private Date editTime; |
||||
|
||||
/** |
||||
* delete |
||||
*/ |
||||
private boolean delete; |
||||
|
||||
public PatientData() {} |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(int id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public int getPid() { |
||||
return pid; |
||||
} |
||||
|
||||
public void setPid(int pid) { |
||||
this.pid = pid; |
||||
} |
||||
|
||||
public int getCtDNALength() { |
||||
return ctDNALength; |
||||
} |
||||
|
||||
public void setCtDNALength(int ctDNALength) { |
||||
this.ctDNALength = ctDNALength; |
||||
} |
||||
|
||||
public boolean isHccStatus() { |
||||
return hccStatus; |
||||
} |
||||
|
||||
public void setHccStatus(boolean hccStatus) { |
||||
this.hccStatus = hccStatus; |
||||
} |
||||
|
||||
public boolean isHccInferStatus() { |
||||
return hccInferStatus; |
||||
} |
||||
|
||||
public void setHccInferStatus(boolean hccInferStatus) { |
||||
this.hccInferStatus = hccInferStatus; |
||||
} |
||||
|
||||
public boolean isDelete() { |
||||
return delete; |
||||
} |
||||
|
||||
public void setDelete(boolean delete) { |
||||
this.delete = delete; |
||||
} |
||||
|
||||
public int getCpg() { |
||||
return cpg; |
||||
} |
||||
|
||||
public void setCpg(int cpg) { |
||||
this.cpg = cpg; |
||||
} |
||||
|
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
|
||||
public Date getEditTime() { |
||||
return editTime; |
||||
} |
||||
|
||||
public void setEditTime(Date editTime) { |
||||
this.editTime = editTime; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "PatientData{" + "id=" + id + |
||||
", pid=" + pid + |
||||
", ctDNALength=" + ctDNALength + |
||||
", cpg=" + cpg + |
||||
", hccStatus=" + hccStatus + |
||||
", hccInferStatus=" + hccInferStatus + |
||||
", createTime=" + createTime + |
||||
", editTime=" + editTime + |
||||
", delete=" + delete + |
||||
'}'; |
||||
} |
||||
} |
@ -1,48 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response; |
||||
|
||||
//@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Response<T> { |
||||
private final int code; |
||||
private final String message; |
||||
private final T data; |
||||
|
||||
public Response(int code, String message, T data) { |
||||
this.code = code; |
||||
this.message = message; |
||||
this.data = data; |
||||
} |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public String getMessage() { |
||||
return message; |
||||
} |
||||
|
||||
public T getData() { |
||||
return data; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
final StringBuffer sb = new StringBuffer("Response{"); |
||||
sb.append("code=").append(code); |
||||
sb.append(", message='").append(message).append('\''); |
||||
sb.append(", data=").append(data); |
||||
sb.append('}'); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public static<T> Response<T> success(T data) { |
||||
return new Response<>(20000, "success", data); |
||||
} |
||||
|
||||
public static Response<Object> error(int code, String message) { |
||||
return new Response<>(code, message, null); |
||||
} |
||||
} |
@ -1,36 +0,0 @@ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.admin; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.Expose; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class CreateUserResponse { |
||||
|
||||
@Expose |
||||
private long role; |
||||
@Expose |
||||
private String uid; |
||||
|
||||
public long getRole() { |
||||
return role; |
||||
} |
||||
|
||||
public void setRole(long role) { |
||||
this.role = role; |
||||
} |
||||
|
||||
public String getUid() { |
||||
return uid; |
||||
} |
||||
|
||||
public void setUid(String uid) { |
||||
this.uid = uid; |
||||
} |
||||
|
||||
} |
@ -1,62 +0,0 @@ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.admin; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.Expose; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class UserRegisterApplicationResponseData { |
||||
|
||||
@Expose |
||||
private long id; |
||||
@Expose |
||||
private String ip; |
||||
@Expose |
||||
private String name; |
||||
@Expose |
||||
private String time; |
||||
@Expose |
||||
private String uid; |
||||
|
||||
public long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getIp() { |
||||
return ip; |
||||
} |
||||
|
||||
public void setIp(String ip) { |
||||
this.ip = ip; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getTime() { |
||||
return time; |
||||
} |
||||
|
||||
public void setTime(String time) { |
||||
this.time = time; |
||||
} |
||||
|
||||
public String getUid() { |
||||
return uid; |
||||
} |
||||
|
||||
public void setUid(String uid) { |
||||
this.uid = uid; |
||||
} |
||||
|
||||
} |
@ -1,87 +0,0 @@ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.compute; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.Expose; |
||||
import com.google.gson.annotations.SerializedName; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class ComputeHistoryReponseData { |
||||
|
||||
@Expose |
||||
private long cpg; |
||||
@Expose |
||||
private long ctdna; |
||||
@Expose |
||||
private Boolean hcc; |
||||
@SerializedName("hcc_infer") |
||||
private Boolean hccInfer; |
||||
@Expose |
||||
private long id; |
||||
@Expose |
||||
private long pid; |
||||
@Expose |
||||
private String time; |
||||
|
||||
public long getCpg() { |
||||
return cpg; |
||||
} |
||||
|
||||
public void setCpg(long cpg) { |
||||
this.cpg = cpg; |
||||
} |
||||
|
||||
public long getCtdna() { |
||||
return ctdna; |
||||
} |
||||
|
||||
public void setCtdna(long ctdna) { |
||||
this.ctdna = ctdna; |
||||
} |
||||
|
||||
public Boolean getHcc() { |
||||
return hcc; |
||||
} |
||||
|
||||
public void setHcc(Boolean hcc) { |
||||
this.hcc = hcc; |
||||
} |
||||
|
||||
public Boolean getHccInfer() { |
||||
return hccInfer; |
||||
} |
||||
|
||||
public void setHccInfer(Boolean hccInfer) { |
||||
this.hccInfer = hccInfer; |
||||
} |
||||
|
||||
public long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public long getPid() { |
||||
return pid; |
||||
} |
||||
|
||||
public void setPid(long pid) { |
||||
this.pid = pid; |
||||
} |
||||
|
||||
public String getTime() { |
||||
return time; |
||||
} |
||||
|
||||
public void setTime(String time) { |
||||
this.time = time; |
||||
} |
||||
|
||||
} |
@ -1,36 +0,0 @@ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.compute; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.Expose; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class ComputeStatusQueryResponse { |
||||
|
||||
@Expose |
||||
private String id; |
||||
@Expose |
||||
private int status; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public int getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(int status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
} |
@ -1,26 +0,0 @@ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.compute; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.Expose; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class ComputeTaskResponseData { |
||||
|
||||
@Expose |
||||
private String id; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
} |
@ -1,66 +0,0 @@ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.user; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.SerializedName; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class LoginResponseData { |
||||
|
||||
@SerializedName("access_token") |
||||
private String mAccessToken; |
||||
@SerializedName("expired") |
||||
private long mExpired; |
||||
@SerializedName("refresh_token") |
||||
private String mRefreshToken; |
||||
@SerializedName("role") |
||||
private long mRole; |
||||
@SerializedName("uid") |
||||
private String mUid; |
||||
|
||||
public String getAccessToken() { |
||||
return mAccessToken; |
||||
} |
||||
|
||||
public void setAccessToken(String accessToken) { |
||||
mAccessToken = accessToken; |
||||
} |
||||
|
||||
public long getExpired() { |
||||
return mExpired; |
||||
} |
||||
|
||||
public void setExpired(long expired) { |
||||
mExpired = expired; |
||||
} |
||||
|
||||
public String getRefreshToken() { |
||||
return mRefreshToken; |
||||
} |
||||
|
||||
public void setRefreshToken(String refreshToken) { |
||||
mRefreshToken = refreshToken; |
||||
} |
||||
|
||||
public long getRole() { |
||||
return mRole; |
||||
} |
||||
|
||||
public void setRole(long role) { |
||||
mRole = role; |
||||
} |
||||
|
||||
public String getUid() { |
||||
return mUid; |
||||
} |
||||
|
||||
public void setUid(String uid) { |
||||
mUid = uid; |
||||
} |
||||
|
||||
} |
@ -1,26 +0,0 @@ |
||||
|
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.domain.response.data.user; |
||||
|
||||
import javax.annotation.Generated; |
||||
import com.google.gson.annotations.Expose; |
||||
|
||||
@Generated("net.hexar.json2pojo") |
||||
@SuppressWarnings("unused") |
||||
public class RegisterResponseData { |
||||
|
||||
@Expose |
||||
private String uid; |
||||
|
||||
public String getUid() { |
||||
return uid; |
||||
} |
||||
|
||||
public void setUid(String uid) { |
||||
this.uid = uid; |
||||
} |
||||
|
||||
} |
@ -1,62 +0,0 @@ |
||||
package net.lensfrex.dscape.domain.user; |
||||
|
||||
public class UserBasic { |
||||
private String uid; |
||||
private String userName; |
||||
private String password; |
||||
private UserStatus status; |
||||
private UserRole role; |
||||
|
||||
public String getUid() { |
||||
return uid; |
||||
} |
||||
|
||||
public void setUid(String uid) { |
||||
this.uid = uid; |
||||
} |
||||
|
||||
public String getUserName() { |
||||
return userName; |
||||
} |
||||
|
||||
public void setUserName(String userName) { |
||||
this.userName = userName; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public UserRole getRole() { |
||||
return role; |
||||
} |
||||
|
||||
public void setRole(UserRole role) { |
||||
this.role = role; |
||||
} |
||||
|
||||
public UserStatus getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(UserStatus status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
final StringBuffer sb = new StringBuffer("UserBasic{"); |
||||
sb.append("uid='").append(uid).append('\''); |
||||
sb.append(", userName='").append(userName).append('\''); |
||||
sb.append(", password='").append(password).append('\''); |
||||
sb.append(", status=").append(status); |
||||
sb.append(", role=").append(role); |
||||
sb.append('}'); |
||||
return sb.toString(); |
||||
} |
||||
} |
||||
|
@ -1,17 +0,0 @@ |
||||
package net.lensfrex.dscape.domain.user; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
|
||||
public enum UserRole { |
||||
ADMIN(1, "admin"), NORMAL_USER(0, "normal"); |
||||
|
||||
@EnumValue |
||||
private final int role; |
||||
|
||||
private final String desc; |
||||
|
||||
UserRole(int role, String desc) { |
||||
this.role = role; |
||||
this.desc = desc; |
||||
} |
||||
} |
@ -1,15 +0,0 @@ |
||||
package net.lensfrex.dscape.domain.user; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
|
||||
public enum UserStatus { |
||||
|
||||
NORMAL(0), BANNED(1), DELETED(2); |
||||
|
||||
@EnumValue |
||||
private final int status; |
||||
|
||||
UserStatus(int status) { |
||||
this.status = status; |
||||
} |
||||
} |
@ -1,19 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers; |
||||
|
||||
import net.lensfrex.dscape.domain.response.Response; |
||||
import org.springframework.web.bind.annotation.ControllerAdvice; |
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
|
||||
@ControllerAdvice |
||||
public class Error extends AbstractMethodError { |
||||
|
||||
@ExceptionHandler({ RuntimeException.class }) |
||||
public Response error() { |
||||
return Response.error(50000, "服务器内部错误...."); |
||||
} |
||||
|
||||
} |
@ -1,18 +0,0 @@ |
||||
package net.lensfrex.dscape.web.controllers; |
||||
|
||||
import net.lensfrex.dscape.dao.mappers.UserBasicMapper; |
||||
import net.lensfrex.dscape.domain.user.UserBasic; |
||||
import net.lensfrex.dscape.domain.user.UserRole; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@RestController |
||||
public class Index { |
||||
@RequestMapping("/") |
||||
public String index() { |
||||
return "Wow~~~~~~~~~~~~~~~~~~~~~~"; |
||||
} |
||||
} |
@ -1,24 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.compute; |
||||
|
||||
import net.lensfrex.dscape.domain.response.Response; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@RestController |
||||
@RequestMapping("/compute") |
||||
public class Compute { |
||||
@GetMapping(value = "/status/{tid}", produces = "application/json") |
||||
public Response status(@PathVariable String tid, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@PostMapping(value = "/add", produces = "application/json") |
||||
public Response addComputeTask(@RequestBody String body, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
} |
@ -1,26 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.history; |
||||
|
||||
import net.lensfrex.dscape.domain.response.Response; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@RestController |
||||
@RequestMapping("/history") |
||||
public class History { |
||||
|
||||
@GetMapping(value = "/list/{uid}", produces = "application/json") |
||||
public Response list(@PathVariable String uid, |
||||
@RequestParam int offset, @RequestParam int limit, @RequestParam int page, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@RequestMapping(value = "/delete/{rid}", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json") |
||||
public Response delete(@PathVariable int rid, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
} |
@ -1,34 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.user; |
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
||||
import net.lensfrex.dscape.domain.response.Response; |
||||
import net.lensfrex.dscape.domain.response.data.user.LoginResponseData; |
||||
import net.lensfrex.dscape.domain.response.data.user.RegisterResponseData; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class) |
||||
@RestController |
||||
@RequestMapping("/user") |
||||
public class User { |
||||
|
||||
@PostMapping(value = "/login" , produces = "application/json") |
||||
public Response login(@RequestBody String body) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@PostMapping(value = "/register", produces = "application/json") |
||||
public Response register(@RequestBody String body) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@PostMapping(value = "/modifyPassword/{uid}", produces = "application/json") |
||||
public Response modifyPassword(@RequestBody String body, @PathVariable String uid, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
} |
@ -1,37 +0,0 @@ |
||||
/* |
||||
* Class created by lensfrex. |
||||
*/ |
||||
|
||||
package net.lensfrex.dscape.web.controllers.user.admin; |
||||
|
||||
import net.lensfrex.dscape.domain.response.Response; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@RestController |
||||
@RequestMapping("/user/admin") |
||||
public class Admin { |
||||
@PostMapping(value = "/add", produces = "application/json") |
||||
public Response addUser(@RequestBody String body, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@PostMapping(value = "/modifyStatus/{uid}", produces = "application/json") |
||||
public Response modifyStatus(@RequestBody String body, @PathVariable String uid, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@GetMapping(value = "/application/list", produces = "application/json") |
||||
public Response listApplication( |
||||
@RequestParam String offset, @RequestParam String limit, @RequestParam String page, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
|
||||
@PostMapping(value = "/application/deal/{uid}", produces = "application/json") |
||||
public Response dealApplication(@RequestBody String body, @PathVariable String uid, |
||||
@RequestHeader String token) { |
||||
return Response.error(0, "Not implement"); |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue