Skip to content

Commit

Permalink
Merge pull request #918 from chat2db/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
shanhexi committed Dec 5, 2023
2 parents e09d1d1 + a1aec22 commit e93e54b
Show file tree
Hide file tree
Showing 112 changed files with 3,278 additions and 635 deletions.
4 changes: 2 additions & 2 deletions chat2db-client/src/blocks/Tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const TreeNode = memo((props: TreeNodeIProps) => {
setTimeout(() => {
console.log(res);
if (res.data) {
// res.data每次只插入200条数据,间隔30ms
const count = res.data.length / 200;
// res.data每次只插入50条数据,间隔50ms
const count = res.data.length / 50;
for (let i = 0; i < count; i++) {
setTimeout(() => {
setTreeNodeData({
Expand Down
2 changes: 2 additions & 0 deletions chat2db-client/src/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ contextBridge.exposeInMainWorld('electronApi', {
console.log('productName:', productName, isTest);

const child = spawn(path.join(__dirname, '../..', `./static/${JAVA_PATH}`), [
'-noverify',
'-jar',
'-Xmx1024M',
`-Dspring.profiles.active=${isTest ? 'test' : 'release'}`,
'-Dserver.address=127.0.0.1',
'-Dchat2db.mode=DESKTOP',
`-Dproject.path=${javaPath}`,
`-Dloader.path=${libPath}`,
`-Dclient.version=${readVersion()}`,
javaPath,
]);

Expand Down
5 changes: 4 additions & 1 deletion chat2db-client/src/pages/main/dashboard/chart-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ function ChartItem(props: IChartItemProps) {
setIsLoading(true);

const res = await getChartById({ id: props.id });
if (!res.dataSourceId) {
res.connectable = undefined;
}
setChartData(res);

// 设置级联value
Expand All @@ -165,7 +168,7 @@ function ChartItem(props: IChartItemProps) {
const formValue = JSON.parse(res.schema || '{}');
form.setFieldsValue(formValue);

if (res.ddl) {
if (res.ddl && res.connectable) {
setInitDDL(res.ddl);
handleExecuteSQL(res.ddl, res);
// let p: IExecuteSqlParams = {
Expand Down
11 changes: 6 additions & 5 deletions chat2db-client/src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import Connection from './connection';
import Team from './team';
import Setting from '@/blocks/Setting';

// ----- utils -----
import { generateUrl } from '@/utils/url';

import styles from './index.less';
import { useUpdateEffect } from '@/hooks';

Expand Down Expand Up @@ -124,8 +121,12 @@ function MainPage() {
};

const switchingNav = (key: string) => {
setActiveNavKey(key);
setMainPageActiveTab(key);
if (key === 'github') {
window.open('https://github.com/chat2db/Chat2DB/', '_blank');
} else {
setActiveNavKey(key);
setMainPageActiveTab(key);
}
};

const handleLogout = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dbType": "MONGODB",
"supportDatabase": false,
"supportSchema": false,
"supportDatabase": true,
"supportSchema": true,
"driverConfigList": [
{
"url": "jdbc:mongodb://localhost:27017",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<artifactId>mybatis-plus</artifactId>
</dependency>
<dependency>
<groupId>ai.chat2db</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ai.chat2db.server.domain.api.service.DataSourceService;
import ai.chat2db.server.domain.core.converter.ChartConverter;
import ai.chat2db.server.domain.core.util.PermissionUtils;
import ai.chat2db.server.domain.repository.Dbutils;
import ai.chat2db.server.domain.repository.entity.ChartDO;
import ai.chat2db.server.domain.repository.entity.DashboardChartRelationDO;
import ai.chat2db.server.domain.repository.mapper.ChartMapper;
Expand Down Expand Up @@ -43,9 +44,6 @@
@Service
public class ChartServiceImpl implements ChartService {

@Autowired
private ChartMapper chartMapper;

@Autowired
private DataSourceService dataSourceService;

Expand All @@ -62,7 +60,7 @@ public DataResult<Long> createWithPermission(ChartCreateParam param) {
param.setDeleted(YesOrNoEnum.NO.getLetter());
param.setUserId(ContextUtils.getUserId());
ChartDO chartDO = chartConverter.param2do(param);
chartMapper.insert(chartDO);
getMapper().insert(chartDO);
return DataResult.of(chartDO.getId());
}

Expand All @@ -73,13 +71,13 @@ public ActionResult updateWithPermission(ChartUpdateParam param) {

param.setGmtModified(LocalDateTime.now());
ChartDO chartDO = chartConverter.updateParam2do(param);
chartMapper.updateById(chartDO);
getMapper().updateById(chartDO);
return ActionResult.isSuccess();
}

@Override
public DataResult<Chart> find(Long id) {
ChartDO chartDO = chartMapper.selectById(id);
ChartDO chartDO = getMapper().selectById(id);
if (YesOrNoEnum.YES.getLetter().equals(chartDO.getDeleted())) {
return DataResult.empty();
}
Expand All @@ -95,7 +93,7 @@ public DataResult<Chart> queryExistent(ChartQueryParam param) {
.eq(ChartDO::getDeleted, YesOrNoEnum.NO.getLetter())
.eqWhenPresent(ChartDO::getId, param.getId())
.eqWhenPresent(ChartDO::getUserId, param.getUserId());
IPage<ChartDO> page = chartMapper.selectPage(new Page<>(1, 1), queryWrapper);
IPage<ChartDO> page = getMapper().selectPage(new Page<>(1, 1), queryWrapper);
if (CollectionUtils.isEmpty(page.getRecords())) {
throw new DataNotFoundException();
}
Expand All @@ -120,7 +118,7 @@ public ListResult<Chart> listQuery(ChartListQueryParam param) {
.eq(ChartDO::getDeleted, YesOrNoEnum.NO.getLetter())
.inWhenPresent(ChartDO::getId, param.getIdList())
.eqWhenPresent(ChartDO::getUserId, param.getUserId());
List<ChartDO> queryList = chartMapper.selectList(queryWrapper);
List<ChartDO> queryList = getMapper().selectList(queryWrapper);
List<Chart> list = chartConverter.do2model(queryList);
setDataSourceInfo(list);
return ListResult.of(list);
Expand All @@ -134,7 +132,7 @@ public ActionResult deleteWithPermission(Long id) {
ChartDO chartDO = new ChartDO();
chartDO.setId(id);
chartDO.setDeleted(YesOrNoEnum.YES.getLetter());
chartMapper.updateById(chartDO);
getMapper().updateById(chartDO);
LambdaQueryWrapper<DashboardChartRelationDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DashboardChartRelationDO::getChartId, id);
List<DashboardChartRelationDO> relationDO = dashboardChartRelationMapper.selectList(queryWrapper);
Expand All @@ -150,7 +148,7 @@ public ListResult<Chart> queryByIds(List<Long> ids) {
if (CollectionUtils.isEmpty(ids)) {
return ListResult.empty();
}
List<ChartDO> chartDOS = chartMapper.selectBatchIds(ids);
List<ChartDO> chartDOS = getMapper().selectBatchIds(ids);
List<Chart> charts = chartConverter.do2model(chartDOS);
List<Chart> result = charts.stream().filter(o -> YesOrNoEnum.NO.getLetter().equals(o.getDeleted())).toList();
setDataSourceInfo(result);
Expand All @@ -173,4 +171,8 @@ private void setDataSourceInfo(List<Chart> result) {
}
});
}

private ChartMapper getMapper() {
return Dbutils.getMapper(ChartMapper.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import ai.chat2db.server.domain.api.param.SystemConfigParam;
import ai.chat2db.server.domain.api.service.ConfigService;
import ai.chat2db.server.domain.core.converter.ConfigConverter;
import ai.chat2db.server.domain.repository.Dbutils;
import ai.chat2db.server.domain.repository.entity.SystemConfigDO;
import ai.chat2db.server.domain.repository.mapper.ChartMapper;
import ai.chat2db.server.domain.repository.mapper.SystemConfigMapper;
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
Expand All @@ -23,8 +25,9 @@
@Service
public class ConfigServiceImpl implements ConfigService {

@Autowired
private SystemConfigMapper systemConfigMapper;
private SystemConfigMapper getMapper() {
return Dbutils.getMapper(SystemConfigMapper.class);
}

@Autowired
private ConfigConverter configConverter;
Expand All @@ -34,7 +37,7 @@ public ActionResult create(SystemConfigParam param) {
SystemConfigDO systemConfigDO = configConverter.param2do(param);
systemConfigDO.setGmtCreate(LocalDateTime.now());
systemConfigDO.setGmtModified(LocalDateTime.now());
systemConfigMapper.insert(systemConfigDO);
getMapper().insert(systemConfigDO);
return ActionResult.isSuccess();
}

Expand All @@ -43,13 +46,13 @@ public ActionResult update(SystemConfigParam param) {
SystemConfigDO systemConfigDO = configConverter.param2do(param);
UpdateWrapper<SystemConfigDO> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("code", param.getCode());
systemConfigMapper.update(systemConfigDO, updateWrapper);
getMapper().update(systemConfigDO, updateWrapper);
return ActionResult.isSuccess();
}

@Override
public ActionResult createOrUpdate(SystemConfigParam param) {
SystemConfigDO systemConfigDO = systemConfigMapper.selectOne(
SystemConfigDO systemConfigDO = getMapper().selectOne(
new UpdateWrapper<SystemConfigDO>().eq("code", param.getCode()));
if (systemConfigDO == null) {
return create(param);
Expand All @@ -60,14 +63,14 @@ public ActionResult createOrUpdate(SystemConfigParam param) {

@Override
public DataResult<Config> find(String code) {
SystemConfigDO systemConfigDO = systemConfigMapper.selectOne(
SystemConfigDO systemConfigDO = getMapper().selectOne(
new UpdateWrapper<SystemConfigDO>().eq("code", code));
return DataResult.of(configConverter.do2model(systemConfigDO));
}

@Override
public ActionResult delete(String code) {
systemConfigMapper.delete(new UpdateWrapper<SystemConfigDO>().eq("code", code));
getMapper().delete(new UpdateWrapper<SystemConfigDO>().eq("code", code));
return ActionResult.isSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ai.chat2db.server.domain.api.service.DashboardService;
import ai.chat2db.server.domain.core.converter.DashboardConverter;
import ai.chat2db.server.domain.core.util.PermissionUtils;
import ai.chat2db.server.domain.repository.Dbutils;
import ai.chat2db.server.domain.repository.entity.DashboardChartRelationDO;
import ai.chat2db.server.domain.repository.entity.DashboardDO;
import ai.chat2db.server.domain.repository.mapper.DashboardChartRelationMapper;
Expand Down Expand Up @@ -39,11 +40,14 @@
@Service
public class DashboardServiceImpl implements DashboardService {

@Autowired
private DashboardMapper dashboardMapper;

@Autowired
private DashboardChartRelationMapper dashboardChartRelationMapper;
private DashboardMapper getMapper() {
return Dbutils.getMapper(DashboardMapper.class);
}
private DashboardChartRelationMapper getMapper1() {
return Dbutils.getMapper(DashboardChartRelationMapper.class);
}


@Autowired
private DashboardConverter dashboardConverter;
Expand All @@ -55,7 +59,7 @@ public DataResult<Long> createWithPermission(DashboardCreateParam param) {
param.setDeleted(YesOrNoEnum.NO.getLetter());
param.setUserId(ContextUtils.getUserId());
DashboardDO dashboardDO = dashboardConverter.param2do(param);
dashboardMapper.insert(dashboardDO);
getMapper().insert(dashboardDO);
insertDashboardRelation(dashboardDO.getId(), param.getChartIds());
return DataResult.of(dashboardDO.getId());
}
Expand All @@ -67,7 +71,7 @@ public ActionResult updateWithPermission(DashboardUpdateParam param) {

param.setGmtModified(LocalDateTime.now());
DashboardDO dashboardDO = dashboardConverter.updateParam2do(param);
dashboardMapper.updateById(dashboardDO);
getMapper().updateById(dashboardDO);
if (CollectionUtils.isEmpty(param.getChartIds())) {
return ActionResult.isSuccess();
}
Expand All @@ -78,14 +82,14 @@ public ActionResult updateWithPermission(DashboardUpdateParam param) {

@Override
public DataResult<Dashboard> find(Long id) {
DashboardDO dashboardDO = dashboardMapper.selectById(id);
DashboardDO dashboardDO = getMapper().selectById(id);
if (YesOrNoEnum.YES.getLetter().equals(dashboardDO.getDeleted())) {
return DataResult.empty();
}
Dashboard dashboard = dashboardConverter.do2model(dashboardDO);
LambdaQueryWrapper<DashboardChartRelationDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DashboardChartRelationDO::getDashboardId, id);
List<DashboardChartRelationDO> relationDO = dashboardChartRelationMapper.selectList(queryWrapper);
List<DashboardChartRelationDO> relationDO = getMapper1().selectList(queryWrapper);
List<Long> chartIds = relationDO.stream().map(DashboardChartRelationDO::getChartId).toList();
dashboard.setChartIds(chartIds);
return DataResult.of(dashboard);
Expand All @@ -98,14 +102,14 @@ public DataResult<Dashboard> queryExistent(DashboardQueryParam param) {
.eq(DashboardDO::getDeleted, YesOrNoEnum.NO.getLetter())
.eqWhenPresent(DashboardDO::getId, param.getId())
.eqWhenPresent(DashboardDO::getUserId, param.getUserId());
IPage<DashboardDO> page = dashboardMapper.selectPage(new Page<>(1, 1), queryWrapper);
IPage<DashboardDO> page = getMapper().selectPage(new Page<>(1, 1), queryWrapper);
if (CollectionUtils.isEmpty(page.getRecords())) {
throw new DataNotFoundException();
}
Dashboard data = dashboardConverter.do2model(page.getRecords().get(0));
LambdaQueryWrapper<DashboardChartRelationDO> dashboardChartRelationQueryWrapper = new LambdaQueryWrapper<>();
dashboardChartRelationQueryWrapper.eq(DashboardChartRelationDO::getDashboardId, param.getId());
List<DashboardChartRelationDO> relationDO = dashboardChartRelationMapper.selectList(
List<DashboardChartRelationDO> relationDO = getMapper1().selectList(
dashboardChartRelationQueryWrapper);
List<Long> chartIds = relationDO.stream().map(DashboardChartRelationDO::getChartId).toList();
data.setChartIds(chartIds);
Expand All @@ -129,7 +133,7 @@ public ActionResult deleteWithPermission(Long id) {
DashboardDO dashboardDO = new DashboardDO();
dashboardDO.setId(id);
dashboardDO.setDeleted(YesOrNoEnum.YES.getLetter());
dashboardMapper.updateById(dashboardDO);
getMapper().updateById(dashboardDO);
deleteDashboardRelation(id);
return ActionResult.isSuccess();
}
Expand All @@ -142,10 +146,10 @@ public ActionResult deleteWithPermission(Long id) {
private void deleteDashboardRelation(Long id) {
LambdaQueryWrapper<DashboardChartRelationDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DashboardChartRelationDO::getDashboardId, id);
List<DashboardChartRelationDO> relationDO = dashboardChartRelationMapper.selectList(queryWrapper);
List<DashboardChartRelationDO> relationDO = getMapper1().selectList(queryWrapper);
List<Long> relationIds = relationDO.stream().map(DashboardChartRelationDO::getId).toList();
if (CollectionUtils.isNotEmpty(relationIds)) {
dashboardChartRelationMapper.deleteBatchIds(relationIds);
getMapper1().deleteBatchIds(relationIds);
}
}

Expand All @@ -165,7 +169,7 @@ private void insertDashboardRelation(Long dashboardId, List<Long> chartIds) {
relationDO.setGmtModified(LocalDateTime.now());
relationDO.setDashboardId(dashboardId);
relationDO.setChartId(chartId);
dashboardChartRelationMapper.insert(relationDO);
getMapper1().insert(relationDO);
});
}

Expand All @@ -179,7 +183,7 @@ public PageResult<Dashboard> queryPage(DashboardPageQueryParam param) {
Integer start = param.getPageNo();
Integer offset = param.getPageSize();
Page<DashboardDO> page = new Page<>(start, offset);
IPage<DashboardDO> iPage = dashboardMapper.selectPage(page, queryWrapper);
IPage<DashboardDO> iPage = getMapper().selectPage(page, queryWrapper);
List<Dashboard> dashboards = dashboardConverter.do2model(iPage.getRecords());
return PageResult.of(dashboards, iPage.getTotal(), param);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ai.chat2db.server.domain.api.param.datasource.access.DataSourceAccessPageQueryParam;
import ai.chat2db.server.domain.api.service.DataSourceAccessBusinessService;
import ai.chat2db.server.domain.api.service.DataSourceAccessService;
import ai.chat2db.server.domain.repository.Dbutils;
import ai.chat2db.server.domain.repository.mapper.DataSourceAccessCustomMapper;
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
import ai.chat2db.server.tools.common.exception.PermissionDeniedBusinessException;
Expand All @@ -27,9 +28,9 @@ public class DataSourceAccessBusinessServiceImpl implements DataSourceAccessBusi

@Resource
private DataSourceAccessService dataSourceAccessService;
@Resource
private DataSourceAccessCustomMapper dataSourceAccessCustomMapper;

private DataSourceAccessCustomMapper getMapper() {
return Dbutils.getMapper(DataSourceAccessCustomMapper.class);
}
@Override
public ActionResult checkPermission(@NotNull DataSource dataSource) {
LoginUser loginUser = ContextUtils.getLoginUser();
Expand Down Expand Up @@ -58,7 +59,7 @@ public ActionResult checkPermission(@NotNull DataSource dataSource) {
}

// Verify if the team has permission
if (dataSourceAccessCustomMapper.checkTeamPermission(dataSource.getId(), loginUser.getId()) != null) {
if (getMapper().checkTeamPermission(dataSource.getId(), loginUser.getId()) != null) {
return ActionResult.isSuccess();

}
Expand Down
Loading

0 comments on commit e93e54b

Please sign in to comment.