mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 13:34:07 +08:00
Complete the datasource code
This commit is contained in:
@ -13,23 +13,25 @@ public enum RoleCodeEnum implements BaseEnum<String> {
|
||||
/**
|
||||
* DESKTOP
|
||||
*/
|
||||
DESKTOP("DESKTOP"),
|
||||
|
||||
/**
|
||||
* USER
|
||||
*/
|
||||
USER("USER"),
|
||||
DESKTOP("DESKTOP", 1L),
|
||||
|
||||
/**
|
||||
* ADMIN
|
||||
*/
|
||||
ADMIN("ADMIN"),
|
||||
ADMIN("ADMIN", 2L),
|
||||
|
||||
/**
|
||||
* USER
|
||||
*/
|
||||
USER("USER", null),
|
||||
|
||||
;
|
||||
final String description;
|
||||
final Long defaultUserId;
|
||||
|
||||
RoleCodeEnum(String description) {
|
||||
RoleCodeEnum(String description, Long defaultUserId) {
|
||||
this.description = description;
|
||||
this.defaultUserId = defaultUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,21 +2,19 @@ package ai.chat2db.server.domain.api.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import ai.chat2db.server.domain.api.model.DataSource;
|
||||
import ai.chat2db.server.domain.api.param.DataSourceCreateParam;
|
||||
import ai.chat2db.server.domain.api.param.DataSourcePageQueryParam;
|
||||
import ai.chat2db.server.domain.api.param.DataSourcePreConnectParam;
|
||||
import ai.chat2db.server.domain.api.param.DataSourceSelector;
|
||||
import ai.chat2db.server.domain.api.param.DataSourceUpdateParam;
|
||||
import ai.chat2db.spi.model.Database;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.PageResult;
|
||||
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import ai.chat2db.server.tools.common.exception.PermissionDeniedBusinessException;
|
||||
import ai.chat2db.spi.model.Database;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 数据源管理服务
|
||||
@ -76,13 +74,24 @@ public interface DataSourceService {
|
||||
*/
|
||||
PageResult<DataSource> queryPage(DataSourcePageQueryParam param, DataSourceSelector selector);
|
||||
|
||||
/**
|
||||
* 分页查询数据源列表
|
||||
* Need to determine permissions
|
||||
*
|
||||
* @param param
|
||||
* @param selector
|
||||
* @return
|
||||
* @throws PermissionDeniedBusinessException
|
||||
*/
|
||||
PageResult<DataSource> queryPageWithPermission(DataSourcePageQueryParam param, DataSourceSelector selector);
|
||||
|
||||
/**
|
||||
* 通过ID列表查询数据源
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
ListResult<DataSource> queryByIds(List<Long>ids);
|
||||
ListResult<DataSource> queryByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 数据源连接测试
|
||||
|
@ -4,6 +4,10 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
public class CacheKey {
|
||||
|
||||
public static String getLoginUserKey(Long userId) {
|
||||
return "login_user_" + userId;
|
||||
}
|
||||
|
||||
public static String getDataSourceKey(Long dataSourceId) {
|
||||
return "schemas_datasourceId_" + dataSourceId;
|
||||
}
|
||||
|
@ -0,0 +1,110 @@
|
||||
package ai.chat2db.server.domain.core.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.ehcache.Cache;
|
||||
import org.ehcache.config.builders.CacheConfigurationBuilder;
|
||||
import org.ehcache.config.builders.CacheManagerBuilder;
|
||||
import org.ehcache.config.builders.ExpiryPolicyBuilder;
|
||||
import org.ehcache.config.builders.ResourcePoolsBuilder;
|
||||
import org.ehcache.config.units.MemoryUnit;
|
||||
import org.springframework.cache.support.NullValue;
|
||||
|
||||
/**
|
||||
* It will only be stored in memory
|
||||
*
|
||||
* @author Jiaju Zhuang
|
||||
*/
|
||||
public class MemoryCacheManage {
|
||||
|
||||
private static final byte[] NULL_BYTES = SerializationUtils.serialize((NullValue)NullValue.INSTANCE);
|
||||
private static final String CACHE = "memory_cache";
|
||||
private static final String SYNCHRONIZED_PREFIX = "MemoryCache:";
|
||||
|
||||
private static Cache<String, byte[]> cache;
|
||||
|
||||
static {
|
||||
cache = CacheManagerBuilder.newCacheManagerBuilder()
|
||||
.build(true)
|
||||
.createCache(CACHE,
|
||||
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, byte[].class,
|
||||
ResourcePoolsBuilder.newResourcePoolsBuilder()
|
||||
.offheap(10, MemoryUnit.MB))
|
||||
.withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(10))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a value from the cache, and if not, query it
|
||||
* The timeout is fixed at 10 minutes
|
||||
*
|
||||
* @param key
|
||||
* @param queryData
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T extends Serializable> T computeIfAbsent(String key, Supplier<T> queryData) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
T data = get(key);
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
String lockKey = SYNCHRONIZED_PREFIX + key;
|
||||
synchronized (lockKey.intern()) {
|
||||
data = get(key);
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
|
||||
T value = queryData.get();
|
||||
put(key, value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a data from cache
|
||||
*
|
||||
* @param key
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T get(String key) {
|
||||
if (StringUtils.isBlank(key)) {
|
||||
return null;
|
||||
}
|
||||
byte[] bytes = cache.get(key);
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
T data = SerializationUtils.deserialize(bytes);
|
||||
if (NullValue.INSTANCE.equals(data)) {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a data from cache
|
||||
* The timeout is fixed at 10 minutes
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public static void put(String key, Serializable value) {
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
cache.put(key, NULL_BYTES);
|
||||
} else {
|
||||
cache.put(key, SerializationUtils.serialize(value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -18,11 +18,14 @@ import ai.chat2db.server.domain.api.service.DataSourceService;
|
||||
import ai.chat2db.server.domain.api.service.DatabaseService;
|
||||
import ai.chat2db.server.domain.core.converter.DataSourceConverter;
|
||||
import ai.chat2db.server.domain.repository.entity.DataSourceDO;
|
||||
import ai.chat2db.server.domain.repository.mapper.DataSourceCustomMapper;
|
||||
import ai.chat2db.server.domain.repository.mapper.DataSourceMapper;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.PageResult;
|
||||
import ai.chat2db.server.tools.common.model.LoginUser;
|
||||
import ai.chat2db.server.tools.common.util.ContextUtils;
|
||||
import ai.chat2db.spi.config.DriverConfig;
|
||||
import ai.chat2db.spi.model.DataSourceConnect;
|
||||
import ai.chat2db.spi.model.Database;
|
||||
@ -31,9 +34,10 @@ import ai.chat2db.spi.sql.Chat2DBContext;
|
||||
import ai.chat2db.spi.sql.IDriverManager;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import ai.chat2db.spi.util.JdbcUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -57,12 +61,15 @@ public class DataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
@Autowired
|
||||
private DatabaseService databaseService;
|
||||
@Resource
|
||||
private DataSourceCustomMapper dataSourceCustomMapper;
|
||||
|
||||
@Override
|
||||
public DataResult<Long> create(DataSourceCreateParam param) {
|
||||
DataSourceDO dataSourceDO = dataSourceConverter.param2do(param);
|
||||
dataSourceDO.setGmtCreate(LocalDateTime.now());
|
||||
dataSourceDO.setGmtModified(LocalDateTime.now());
|
||||
dataSourceDO.setUserId(ContextUtils.getUserId());
|
||||
dataSourceMapper.insert(dataSourceDO);
|
||||
preWarmingData(dataSourceDO.getId());
|
||||
return DataResult.of(dataSourceDO.getId());
|
||||
@ -120,9 +127,11 @@ public class DataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
@Override
|
||||
public PageResult<DataSource> queryPage(DataSourcePageQueryParam param, DataSourceSelector selector) {
|
||||
QueryWrapper<DataSourceDO> queryWrapper = new QueryWrapper<>();
|
||||
LambdaQueryWrapper<DataSourceDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(param.getSearchKey())) {
|
||||
queryWrapper.like("alias", param.getSearchKey());
|
||||
queryWrapper.and(wrapper -> wrapper.like(DataSourceDO::getAlias, "%" + param.getSearchKey() + "%")
|
||||
.or()
|
||||
.like(DataSourceDO::getUrl, "%" + param.getSearchKey() + "%"));
|
||||
}
|
||||
Integer start = param.getPageNo();
|
||||
Integer offset = param.getPageSize();
|
||||
@ -132,6 +141,17 @@ public class DataSourceServiceImpl implements DataSourceService {
|
||||
return PageResult.of(dataSources, iPage.getTotal(), param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DataSource> queryPageWithPermission(DataSourcePageQueryParam param, DataSourceSelector selector) {
|
||||
LoginUser loginUser = ContextUtils.getLoginUser();
|
||||
IPage<DataSourceDO> iPage = dataSourceCustomMapper.selectPageWithPermission(
|
||||
new Page<>(param.getPageNo(), param.getPageSize()),
|
||||
BooleanUtils.isTrue(loginUser.getAdmin()), loginUser.getId(), param.getSearchKey());
|
||||
List<DataSource> dataSources = dataSourceConverter.do2dto(iPage.getRecords());
|
||||
return PageResult.of(dataSources, iPage.getTotal(), param);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListResult<DataSource> queryByIds(List<Long> ids) {
|
||||
List<DataSourceDO> dataSourceDOS = dataSourceMapper.selectBatchIds(ids);
|
||||
|
@ -0,0 +1,16 @@
|
||||
package ai.chat2db.server.domain.repository.mapper;
|
||||
|
||||
import ai.chat2db.server.domain.repository.entity.DataSourceDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* Data Source Custom Mapper
|
||||
*
|
||||
* @author Jiaju Zhuang
|
||||
*/
|
||||
public interface DataSourceCustomMapper {
|
||||
|
||||
IPage<DataSourceDO> selectPageWithPermission(IPage<DataSourceDO> page, @Param("admin") Boolean admin, @Param("userId") Long userId,
|
||||
@Param("searchKey") String searchKey);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="ai.chat2db.server.domain.repository.mapper.DataSourceCustomMapper">
|
||||
|
||||
<select id="selectPageWithPermission" resultType="ai.chat2db.server.domain.repository.entity.DataSourceDO">
|
||||
select ds.*
|
||||
from DATA_SOURCE ds
|
||||
<where>
|
||||
<if test="admin != true">
|
||||
<choose>
|
||||
<when test="userId == 1">
|
||||
ds.USER_ID = #{userId}
|
||||
</when>
|
||||
<otherwise>
|
||||
(ds.USER_ID = #{userId}
|
||||
or exists(select 1 from DATA_SOURCE_ACCESS dsa where dsa.ACCESS_OBJECT_TYPE = 'USER' and
|
||||
dsa.ACCESS_OBJECT_ID = #{userId})
|
||||
or exists(select 1
|
||||
from DATA_SOURCE_ACCESS dsa
|
||||
LEFT JOIN TEAM_USER tu on tu.ID = dsa.ACCESS_OBJECT_ID and dsa.ACCESS_OBJECT_TYPE = 'TEAM'
|
||||
where tu.USER_ID = #{userId})
|
||||
)
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="searchKey != '' and searchKey != null ">
|
||||
and (ds.alias like concat('%',#{searchKey},'%') or ds.url like concat('%',#{searchKey},'%'))
|
||||
</if>
|
||||
</where>
|
||||
|
||||
</select>
|
||||
</mapper>
|
@ -1,9 +1,12 @@
|
||||
package ai.chat2db.server.start;
|
||||
|
||||
import ai.chat2db.server.tools.common.enums.ModeEnum;
|
||||
import ai.chat2db.server.tools.common.model.ConfigJson;
|
||||
import ai.chat2db.server.tools.common.util.ConfigUtils;
|
||||
import ai.chat2db.server.tools.common.util.EasyEnumUtils;
|
||||
import com.dtflys.forest.springboot.annotation.ForestScan;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@ -34,12 +37,18 @@ public class Application {
|
||||
String currentVersion = ConfigUtils.getLocalVersion();
|
||||
ConfigJson configJson = ConfigUtils.getConfig();
|
||||
// Represents that the current version has been successfully launched
|
||||
if (StringUtils.isNotBlank(currentVersion) && StringUtils.equals(currentVersion, configJson.getLatestStartupSuccessVersion())) {
|
||||
if (StringUtils.isNotBlank(currentVersion) && StringUtils.equals(currentVersion,
|
||||
configJson.getLatestStartupSuccessVersion())) {
|
||||
// Flyway doesn't need to start every time to increase startup speed
|
||||
//args = ArrayUtils.add(args, "--spring.flyway.enabled=false");
|
||||
log.info("The current version {} has been successfully launched once and will no longer load Flyway.",
|
||||
currentVersion);
|
||||
}
|
||||
ModeEnum mode = EasyEnumUtils.getEnum(ModeEnum.class, System.getProperty("chat2db.mode"));
|
||||
if (mode == ModeEnum.DESKTOP) {
|
||||
// In this mode, no user login is required, so only local access is available
|
||||
args = ArrayUtils.add(args, "--server.address = 0.0.0.0");
|
||||
}
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,16 @@ import java.util.Enumeration;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
|
||||
import ai.chat2db.server.domain.api.enums.RoleCodeEnum;
|
||||
import ai.chat2db.server.domain.api.model.User;
|
||||
import ai.chat2db.server.domain.api.service.UserService;
|
||||
import ai.chat2db.server.domain.core.cache.CacheKey;
|
||||
import ai.chat2db.server.domain.core.cache.MemoryCacheManage;
|
||||
import ai.chat2db.server.tools.base.constant.SymbolConstant;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
|
||||
import ai.chat2db.server.tools.common.config.Chat2dbProperties;
|
||||
import ai.chat2db.server.tools.common.enums.ModeEnum;
|
||||
import ai.chat2db.server.tools.common.exception.PermissionDeniedBusinessException;
|
||||
import ai.chat2db.server.tools.common.exception.RedirectBusinessException;
|
||||
import ai.chat2db.server.tools.common.model.Context;
|
||||
import ai.chat2db.server.tools.common.model.LoginUser;
|
||||
@ -21,6 +27,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -50,6 +57,8 @@ public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private Chat2dbProperties chat2dbProperties;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
@ -60,24 +69,36 @@ public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer {
|
||||
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response,
|
||||
@NotNull Object handler) {
|
||||
String userIdString = (String)StpUtil.getLoginIdDefaultNull();
|
||||
Long userId;
|
||||
// 未登录
|
||||
if (!StringUtils.isNumeric(userIdString)) {
|
||||
// TODO 这个版本默认放开登录 不管用户是否登录 都算登录,下个版本做权限
|
||||
userIdString = "1";
|
||||
//return true;
|
||||
if (chat2dbProperties.getMode() == ModeEnum.DESKTOP) {
|
||||
userId = RoleCodeEnum.DESKTOP.getDefaultUserId();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
// 已经登录 查询用户信息
|
||||
Long userId = Long.parseLong(userIdString);
|
||||
User user = userService.query(userId).getData();
|
||||
}
|
||||
userId = Long.parseLong(userIdString);
|
||||
Long finalUserId = userId;
|
||||
LoginUser loginUser = MemoryCacheManage.computeIfAbsent(CacheKey.getLoginUserKey(userId), () -> {
|
||||
User user = userService.query(finalUserId).getData();
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
return LoginUser.builder()
|
||||
.id(user.getId())
|
||||
.nickName(user.getNickName())
|
||||
.admin(RoleCodeEnum.ADMIN.getCode().equals(user.getRoleCode()))
|
||||
.build();
|
||||
});
|
||||
|
||||
if (loginUser == null) {
|
||||
// 代表用户可能被删除了
|
||||
return true;
|
||||
}
|
||||
|
||||
ContextUtils.setContext(Context.builder()
|
||||
.loginUser(LoginUser.builder()
|
||||
.id(user.getId()).nickName(user.getNickName())
|
||||
.build())
|
||||
.loginUser(loginUser)
|
||||
.build());
|
||||
return true;
|
||||
}
|
||||
@ -106,7 +127,8 @@ public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer {
|
||||
String path = SaHolder.getRequest().getRequestPath();
|
||||
if (path.startsWith(API_PREFIX)) {
|
||||
response.getWriter().println(JSON.toJSONString(
|
||||
ActionResult.fail("common.needLoggedIn", I18nUtils.getMessage("common.needLoggedIn"), "")));
|
||||
ActionResult.fail("common.needLoggedIn", I18nUtils.getMessage("common.needLoggedIn"),
|
||||
"")));
|
||||
return false;
|
||||
} else {
|
||||
throw new RedirectBusinessException(
|
||||
@ -126,6 +148,23 @@ public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer {
|
||||
// _a结尾的统一放行
|
||||
.excludePathPatterns("/**/*_a");
|
||||
|
||||
// 校验权限
|
||||
registry.addInterceptor(new AsyncHandlerInterceptor() {
|
||||
@Override
|
||||
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response,
|
||||
@NotNull Object handler) throws IOException {
|
||||
LoginUser loginUser = ContextUtils.getLoginUser();
|
||||
if (BooleanUtils.isNotTrue(loginUser.getAdmin())) {
|
||||
throw new PermissionDeniedBusinessException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.order(3)
|
||||
.addPathPatterns("/api/admin/**")
|
||||
.addPathPatterns("/admin/**")
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
private String buildHeaderString(HttpServletRequest request) {
|
||||
|
@ -23,16 +23,25 @@ VALUES (2, 1, 1, '测试环境', '测试', 'TEST');
|
||||
ALTER TABLE `data_source`
|
||||
ADD COLUMN `environment_id` bigint(20) unsigned NOT NULL DEFAULT 2 COMMENT '环境id';
|
||||
|
||||
ALTER TABLE `data_source`
|
||||
modify COLUMN `user_id` bigint(20) unsigned NOT NULL DEFAULT 1 COMMENT '用户id';
|
||||
|
||||
update data_source
|
||||
set user_id= 1;
|
||||
|
||||
ALTER TABLE `dbhub_user`
|
||||
ADD COLUMN `role_code` varchar(32) DEFAULT NULL COMMENT '角色编码';
|
||||
|
||||
ALTER TABLE `dbhub_user`
|
||||
ADD `status` varchar(32) NOT NULL DEFAULT 'VALID' COMMENT '用户状态';
|
||||
|
||||
|
||||
|
||||
update dbhub_user
|
||||
set role_code= 'DESKTOP'
|
||||
where id = 1;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `team`
|
||||
(
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
|
@ -7,6 +7,7 @@ common.paramError=The parameter is incorrect
|
||||
common.paramDetailError=The parameter: {0} is incorrect
|
||||
common.paramCheckError=The following parameters are not valid:
|
||||
common.maxUploadSize=The file exceeds the maximum limit
|
||||
common.permissionDenied=Permission denied
|
||||
# dataSource
|
||||
dataSource.sqlAnalysisError=Invalid statements
|
||||
# connection
|
||||
|
@ -6,6 +6,8 @@ common.paramError=The parameter is incorrect
|
||||
common.paramDetailError=The parameter: {0} is incorrect
|
||||
common.paramCheckError=The following parameters are not valid
|
||||
common.maxUploadSize=The file exceeds the maximum limit
|
||||
common.permissionDenied=Permission denied
|
||||
|
||||
dataSource.sqlAnalysisError=Invalid statements
|
||||
connection.error=Connection failed, please check the connection information
|
||||
connection.ssh.error=SSH connection failed, please check the connection information
|
||||
|
@ -6,7 +6,7 @@ common.paramError=您输入的参数异常
|
||||
common.paramDetailError=您输入的参数:{0},存在异常
|
||||
common.paramCheckError=请检查以下参数:
|
||||
common.maxUploadSize=您输入的文件超过最大限制
|
||||
|
||||
common.permissionDenied=您没有权限访问该页面
|
||||
|
||||
dataSource.sqlAnalysisError=不合法的执行语句
|
||||
connection.error=数据库链接异常,请检查数据库配置
|
||||
|
@ -0,0 +1,36 @@
|
||||
package ai.chat2db.server.start.test.druid;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
|
||||
import ai.chat2db.server.domain.core.cache.MemoryCacheManage;
|
||||
import ai.chat2db.server.start.test.dto.TestDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Slf4j
|
||||
public class SerializationUtilsTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
TestDTO test = TestDTO.builder().name("test").build();
|
||||
|
||||
byte[] bytes = SerializationUtils.serialize(test);
|
||||
|
||||
TestDTO t2 = SerializationUtils.deserialize(bytes);
|
||||
|
||||
log.info("tt{}", t2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cache() throws InterruptedException {
|
||||
TestDTO test = TestDTO.builder().name("test").build();
|
||||
MemoryCacheManage.put("t1", test);
|
||||
TestDTO t1 = MemoryCacheManage.get("t1");
|
||||
log.info("t1:{}", JSON.toJSONString(t1));
|
||||
Thread.sleep(12000);
|
||||
t1 = MemoryCacheManage.get("t1");
|
||||
log.info("t1:{}", JSON.toJSONString(t1));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package ai.chat2db.server.start.test.dto;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import ai.chat2db.server.tools.base.constant.EasyToolsConstant;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TestDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID;
|
||||
|
||||
private String name;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package ai.chat2db.server.tools.common.config;
|
||||
|
||||
import ai.chat2db.server.tools.common.enums.ModeEnum;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -24,6 +25,11 @@ public class Chat2dbProperties {
|
||||
*/
|
||||
private GatewayProperties gateway;
|
||||
|
||||
/**
|
||||
* mode
|
||||
*/
|
||||
private ModeEnum mode;
|
||||
|
||||
@Data
|
||||
public static class GatewayProperties {
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
package ai.chat2db.server.tools.common.enums;
|
||||
|
||||
import ai.chat2db.server.tools.base.enums.BaseEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* model
|
||||
*
|
||||
* @author Jiaju Zhuang
|
||||
*/
|
||||
@Getter
|
||||
public enum ModeEnum implements BaseEnum<String> {
|
||||
/**
|
||||
* DESKTOP
|
||||
*/
|
||||
DESKTOP("DESKTOP"),
|
||||
|
||||
/**
|
||||
* WEB
|
||||
*/
|
||||
WEB("WEB"),
|
||||
|
||||
;
|
||||
final String description;
|
||||
|
||||
ModeEnum(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return this.name();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package ai.chat2db.server.tools.common.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import ai.chat2db.server.tools.base.constant.EasyToolsConstant;
|
||||
import ai.chat2db.server.tools.base.excption.BusinessException;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Permission Denied
|
||||
*
|
||||
* @author Jiaju Zhuang
|
||||
*/
|
||||
@Getter
|
||||
public class PermissionDeniedBusinessException extends BusinessException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID;
|
||||
|
||||
public PermissionDeniedBusinessException() {
|
||||
super("common.permissionDenied");
|
||||
}
|
||||
}
|
@ -32,4 +32,9 @@ public class LoginUser implements Serializable {
|
||||
* 昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* Is it an administrator
|
||||
*/
|
||||
private Boolean admin;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
package ai.chat2db.server.admin.api.controller.common;
|
||||
|
||||
import ai.chat2db.server.admin.api.controller.common.request.TeamUserPageQueryRequest;
|
||||
import ai.chat2db.server.admin.api.controller.common.request.CommonPageQueryRequest;
|
||||
import ai.chat2db.server.admin.api.controller.common.vo.TeamUserListVO;
|
||||
import ai.chat2db.server.admin.api.controller.datasource.converter.DataSourceAdminConverter;
|
||||
import ai.chat2db.server.domain.api.service.DataSourceService;
|
||||
@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/common")
|
||||
@RestController
|
||||
public class CommonController {
|
||||
public class CommonAdminController {
|
||||
|
||||
@Resource
|
||||
private DataSourceService dataSourceService;
|
||||
@ -33,8 +33,32 @@ public class CommonController {
|
||||
* @return
|
||||
* @version 2.1.0
|
||||
*/
|
||||
@GetMapping("/team-user/list")
|
||||
public WebPageResult<TeamUserListVO> teamUserList(@Valid TeamUserPageQueryRequest request) {
|
||||
@GetMapping("/team_user/list")
|
||||
public WebPageResult<TeamUserListVO> teamUserList(@Valid CommonPageQueryRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuzzy query of users
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @version 2.1.0
|
||||
*/
|
||||
@GetMapping("/user/list")
|
||||
public WebPageResult<TeamUserListVO> userList(@Valid CommonPageQueryRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuzzy query of teams
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @version 2.1.0
|
||||
*/
|
||||
@GetMapping("/team/list")
|
||||
public WebPageResult<TeamUserListVO> teamList(@Valid CommonPageQueryRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/data_source/access")
|
||||
@RestController
|
||||
public class DataSourceAccessController {
|
||||
public class DataSourceAccessAdminController {
|
||||
|
||||
@Resource
|
||||
private DataSourceService dataSourceService;
|
@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/data_source")
|
||||
@RestController
|
||||
public class DataSourceController {
|
||||
public class DataSourceAdminController {
|
||||
|
||||
@Resource
|
||||
private DataSourceService dataSourceService;
|
@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/team")
|
||||
@RestController
|
||||
public class TeamController {
|
||||
public class TeamAdminController {
|
||||
|
||||
/**
|
||||
* Pagination query
|
@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/team/data_source")
|
||||
@RestController
|
||||
public class TeamDataSourceController {
|
||||
public class TeamDataSourceAdminController {
|
||||
|
||||
/**
|
||||
* Pagination query
|
@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/team/user")
|
||||
@RestController
|
||||
public class TeamUserController {
|
||||
public class TeamUserAdminController {
|
||||
|
||||
/**
|
||||
* Pagination query
|
@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/user")
|
||||
@RestController
|
||||
public class UserController {
|
||||
public class UserAdminController {
|
||||
|
||||
@Resource
|
||||
private DataSourceService dataSourceService;
|
@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/user/data_source")
|
||||
@RestController
|
||||
public class UserDataSourceController {
|
||||
public class UserDataSourceAdminController {
|
||||
|
||||
/**
|
||||
* Pagination query
|
@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RequestMapping("/api/admin/user/team")
|
||||
@RestController
|
||||
public class UserTeamController {
|
||||
public class UserTeamAdminController {
|
||||
|
||||
/**
|
||||
* Pagination query
|
@ -8,5 +8,4 @@ ADD chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-
|
||||
ADD chat2db-server/chat2db-server-start/target/lib lib
|
||||
# 让当前容器暴露10824
|
||||
EXPOSE 10824
|
||||
# 运行jar包
|
||||
ENTRYPOINT ["java","-Dloader.path=lib","-Dspring.profiles.active=release","-jar","chat2db-server-start.jar"]
|
||||
# 运行jar包ENTRYPOINT ["java","-Dloader.path=lib","-Dspring.profiles.active=release","-jar","chat2db-server-start.jar"]
|
||||
|
Reference in New Issue
Block a user