Complete the datasource code

This commit is contained in:
JiaJu Zhuang
2023-08-05 21:22:28 +08:00
parent ab4801d97b
commit c09ee3156e
37 changed files with 176 additions and 127 deletions

View File

@ -13,25 +13,29 @@ public enum RoleCodeEnum implements BaseEnum<String> {
/**
* DESKTOP
*/
DESKTOP("DESKTOP", 1L),
DESKTOP("DESKTOP", 1L, "_desktop_default_user_name", "_desktop_default_user_name"),
/**
* ADMIN
*/
ADMIN("ADMIN", 2L),
ADMIN("ADMIN", 2L, "chat2db", "chat2db"),
/**
* USER
*/
USER("USER", null),
USER("USER", null, null, null),
;
final String description;
final Long defaultUserId;
final String userName;
final String password;
RoleCodeEnum(String description, Long defaultUserId) {
RoleCodeEnum(String description, Long defaultUserId, String userName, String password) {
this.description = description;
this.defaultUserId = defaultUserId;
this.userName = userName;
this.password = password;
}
@Override

View File

@ -33,7 +33,7 @@ public class MemoryCacheManage {
.createCache(CACHE,
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, byte[].class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.offheap(10, MemoryUnit.MB))
.offheap(5, MemoryUnit.MB))
.withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(10))));
}

View File

@ -14,7 +14,7 @@ import lombok.Setter;
* </p>
*
* @author chat2db
* @since 2023-07-30
* @since 2023-08-05
*/
@Getter
@Setter

View File

@ -1,6 +1,7 @@
package ai.chat2db.server.domain.repository.mapper;
import ai.chat2db.server.domain.repository.entity.DataSourceDO;
import com.baomidou.mybatisplus.core.mapper.Mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
@ -9,8 +10,9 @@ import org.apache.ibatis.annotations.Param;
*
* @author Jiaju Zhuang
*/
public interface DataSourceCustomMapper {
public interface DataSourceCustomMapper extends Mapper<DataSourceDO> {
IPage<DataSourceDO> selectPageWithPermission(IPage<DataSourceDO> page, @Param("admin") Boolean admin,
@Param("userId") Long userId,
@Param("searchKey") String searchKey);
IPage<DataSourceDO> selectPageWithPermission(IPage<DataSourceDO> page, @Param("admin") Boolean admin, @Param("userId") Long userId,
@Param("searchKey") String searchKey);
}

View File

@ -1,32 +0,0 @@
<?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>

View File

@ -0,0 +1,36 @@
<?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>
<choose>
<when test="admin == true">
and ds.USER_ID != 1
</when>
<otherwise>
<choose>
<when test="userId == 1">
and ds.USER_ID = #{userId}
</when>
<otherwise>
and (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>
</otherwise>
</choose>
<if test="searchKey != '' and searchKey != null ">
and (ds.alias like concat('%',#{searchKey},'%') or ds.url like concat('%',#{searchKey},'%'))
</if>
</where>
</select>
</mapper>