mirror of
https://github.com/dataease/dataease.git
synced 2026-06-16 11:21:44 +08:00
feat: 支持jpa
This commit is contained in:
@@ -78,6 +78,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fit2cloud</groupId>
|
||||
<artifactId>quartz-spring-boot-starter</artifactId>
|
||||
|
||||
@@ -19,7 +19,7 @@ import io.dataease.dataset.utils.FieldUtils;
|
||||
import io.dataease.dataset.utils.SqlUtils;
|
||||
import io.dataease.dataset.utils.TableUtils;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.manage.DataSourceManage;
|
||||
import io.dataease.datasource.manage.EngineManage;
|
||||
import io.dataease.datasource.utils.DatasourceUtils;
|
||||
@@ -68,8 +68,8 @@ import static io.dataease.chart.manage.ChartDataManage.START_END_SEPARATOR;
|
||||
public class DatasetDataManage {
|
||||
@Resource
|
||||
private DatasetSQLManage datasetSQLManage;
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
@Resource
|
||||
private DatasetTableFieldManage datasetTableFieldManage;
|
||||
@Resource
|
||||
|
||||
@@ -17,8 +17,7 @@ import io.dataease.dataset.dto.DataSetNodeBO;
|
||||
import io.dataease.dataset.utils.DatasetUtils;
|
||||
import io.dataease.dataset.utils.FieldUtils;
|
||||
import io.dataease.dataset.utils.TableUtils;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.engine.constant.ExtFieldConstant;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.extensions.datasource.dto.DatasetTableDTO;
|
||||
@@ -68,19 +67,14 @@ public class DatasetGroupManage {
|
||||
private CoreDataSetExtMapper coreDataSetExtMapper;
|
||||
@Resource
|
||||
private CoreDatasetTableMapper coreDatasetTableMapper;
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
|
||||
|
||||
@Resource
|
||||
private CoreUserManage coreUserManage;
|
||||
|
||||
@Resource
|
||||
private CoreOptRecentManage coreOptRecentManage;
|
||||
|
||||
@Autowired(required = false)
|
||||
private RelationApi relationManage;
|
||||
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
private static final String leafType = "dataset";
|
||||
|
||||
private Lock lock = new ReentrantLock();
|
||||
@@ -270,15 +264,12 @@ public class DatasetGroupManage {
|
||||
QueryWrapper<CoreDatasetTable> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("dataset_group_id", datasetId);
|
||||
List<CoreDatasetTable> coreDatasetTables = coreDatasetTableMapper.selectList(wrapper);
|
||||
Set<Long> ids = new LinkedHashSet();
|
||||
List<Long> ids = new ArrayList<>();
|
||||
coreDatasetTables.forEach(ele -> ids.add(ele.getDatasourceId()));
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
DEException.throwException(Translator.get("i18n_dataset_create_error"));
|
||||
}
|
||||
|
||||
QueryWrapper<CoreDatasource> datasourceQueryWrapper = new QueryWrapper<>();
|
||||
datasourceQueryWrapper.in("id", ids);
|
||||
List<DatasourceDTO> datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> {
|
||||
List<DatasourceDTO> datasourceDTOList = coreDatasourceRepository.findInIds(ids).stream().map(ele -> {
|
||||
DatasourceDTO dto = new DatasourceDTO();
|
||||
BeanUtils.copyBean(dto, ele);
|
||||
dto.setConfiguration(null);
|
||||
|
||||
@@ -13,7 +13,7 @@ import io.dataease.dataset.utils.DatasetTableTypeConstants;
|
||||
import io.dataease.dataset.utils.SqlUtils;
|
||||
import io.dataease.dataset.utils.TableUtils;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.manage.DataSourceManage;
|
||||
import io.dataease.datasource.manage.EngineManage;
|
||||
import io.dataease.engine.constant.ExtFieldConstant;
|
||||
@@ -56,15 +56,10 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Component
|
||||
public class DatasetSQLManage {
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Resource
|
||||
private EngineManage engineManage;
|
||||
|
||||
@Resource
|
||||
private CorePermissionManage corePermissionManage;
|
||||
|
||||
@Autowired(required = false)
|
||||
private PluginManageApi pluginManage;
|
||||
@Autowired(required = false)
|
||||
|
||||
@@ -1,237 +0,0 @@
|
||||
package io.dataease.datasource.dao.auto.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源表
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-07-09
|
||||
*/
|
||||
@TableName("core_datasource")
|
||||
public class CoreDatasource implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 父级ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 更新方式:0:替换;1:追加
|
||||
*/
|
||||
private String editType;
|
||||
|
||||
/**
|
||||
* 详细信息
|
||||
*/
|
||||
private String configuration;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Long createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Long updateTime;
|
||||
|
||||
/**
|
||||
* 变更人
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String qrtzInstance;
|
||||
|
||||
/**
|
||||
* 任务状态
|
||||
*/
|
||||
private String taskStatus;
|
||||
|
||||
/**
|
||||
* 开启数据填报
|
||||
*/
|
||||
private Boolean enableDataFill;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(Long pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getEditType() {
|
||||
return editType;
|
||||
}
|
||||
|
||||
public void setEditType(String editType) {
|
||||
this.editType = editType;
|
||||
}
|
||||
|
||||
public String getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public void setConfiguration(String configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public Long getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Long getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Long updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Long getUpdateBy() {
|
||||
return updateBy;
|
||||
}
|
||||
|
||||
public void setUpdateBy(Long updateBy) {
|
||||
this.updateBy = updateBy;
|
||||
}
|
||||
|
||||
public String getCreateBy() {
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(String createBy) {
|
||||
this.createBy = createBy;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getQrtzInstance() {
|
||||
return qrtzInstance;
|
||||
}
|
||||
|
||||
public void setQrtzInstance(String qrtzInstance) {
|
||||
this.qrtzInstance = qrtzInstance;
|
||||
}
|
||||
|
||||
public String getTaskStatus() {
|
||||
return taskStatus;
|
||||
}
|
||||
|
||||
public void setTaskStatus(String taskStatus) {
|
||||
this.taskStatus = taskStatus;
|
||||
}
|
||||
|
||||
public Boolean getEnableDataFill() {
|
||||
return enableDataFill;
|
||||
}
|
||||
|
||||
public void setEnableDataFill(Boolean enableDataFill) {
|
||||
this.enableDataFill = enableDataFill;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CoreDatasource{" +
|
||||
"id = " + id +
|
||||
", name = " + name +
|
||||
", description = " + description +
|
||||
", type = " + type +
|
||||
", pid = " + pid +
|
||||
", editType = " + editType +
|
||||
", configuration = " + configuration +
|
||||
", createTime = " + createTime +
|
||||
", updateTime = " + updateTime +
|
||||
", updateBy = " + updateBy +
|
||||
", createBy = " + createBy +
|
||||
", status = " + status +
|
||||
", qrtzInstance = " + qrtzInstance +
|
||||
", taskStatus = " + taskStatus +
|
||||
", enableDataFill = " + enableDataFill +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.dataease.datasource.dao.auto.mapper;
|
||||
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-07-09
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreDatasourceMapper extends BaseMapper<CoreDatasource> {
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.dataease.datasource.dao.auto.mapper;
|
||||
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDriverJar;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 驱动详情 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2023-04-17
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreDriverJarMapper extends BaseMapper<CoreDriverJar> {
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.dataease.datasource.dao.auto.mapper;
|
||||
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDriver;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 驱动 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2023-04-18
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreDriverMapper extends BaseMapper<CoreDriver> {
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import io.dataease.commons.constants.OptConstants;
|
||||
import io.dataease.commons.constants.TaskStatus;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.dao.ext.mapper.CoreDatasourceExtMapper;
|
||||
import io.dataease.datasource.dao.ext.mapper.DataSourceExtMapper;
|
||||
import io.dataease.datasource.dao.ext.po.DataSourceNodePO;
|
||||
@@ -22,19 +22,19 @@ import io.dataease.license.utils.LicenseUtil;
|
||||
import io.dataease.model.BusiNodeRequest;
|
||||
import io.dataease.model.BusiNodeVO;
|
||||
import io.dataease.operation.manage.CoreOptRecentManage;
|
||||
import io.dataease.utils.AuthUtils;
|
||||
import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.CommunityUtils;
|
||||
import io.dataease.utils.TreeUtils;
|
||||
import io.dataease.utils.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Stack;
|
||||
|
||||
@Component
|
||||
@@ -42,10 +42,8 @@ public class DataSourceManage {
|
||||
|
||||
@Resource
|
||||
private DataSourceExtMapper dataSourceExtMapper;
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
@Resource
|
||||
private CoreOptRecentManage coreOptRecentManage;
|
||||
|
||||
@@ -117,7 +115,7 @@ public class DataSourceManage {
|
||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
BeanUtils.copyBean(coreDatasource, dataSourceDTO);
|
||||
checkName(dataSourceDTO);
|
||||
coreDatasourceMapper.insert(coreDatasource);
|
||||
coreDatasourceRepository.saveAndFlush(coreDatasource);
|
||||
coreOptRecentManage.saveOpt(coreDatasource.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASOURCE, OptConstants.OPT_TYPE.NEW);
|
||||
}
|
||||
|
||||
@@ -125,29 +123,32 @@ public class DataSourceManage {
|
||||
if (StringUtils.isEmpty(dto.getName()) || StringUtils.isEmpty(dto.getName().trim())) {
|
||||
DEException.throwException(Translator.get("i18n_df_name_can_not_empty"));
|
||||
}
|
||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||
if (ObjectUtils.isNotEmpty(dto.getPid())) {
|
||||
if (LicenseUtil.licenseValid() && dto.getPid().equals(0L)) {
|
||||
wrapper.eq("pid", -100L);
|
||||
} else {
|
||||
wrapper.eq("pid", dto.getPid());
|
||||
Specification<CoreDatasource> spec = (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (ObjectUtils.isNotEmpty(dto.getPid())) {
|
||||
if (LicenseUtil.licenseValid() && dto.getPid().equals(0L)) {
|
||||
predicates.add(criteriaBuilder.equal(root.get("pid"), -100L));
|
||||
} else {
|
||||
predicates.add(criteriaBuilder.equal(root.get("pid"), dto.getPid()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dto.getName())) {
|
||||
wrapper.eq("name", dto.getName());
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(dto.getId())) {
|
||||
wrapper.ne("id", dto.getId());
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(dto.getNodeType())) {
|
||||
if (dto.getNodeType().equalsIgnoreCase("folder")) {
|
||||
wrapper.eq("type", dto.getType());
|
||||
} else {
|
||||
wrapper.ne("type", "folder");
|
||||
if (StringUtils.isNotEmpty(dto.getName())) {
|
||||
predicates.add(criteriaBuilder.equal(root.get("name"), dto.getName()));
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(dto.getId())) {
|
||||
predicates.add(criteriaBuilder.notEqual(root.get("id"), dto.getId()));
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(dto.getNodeType())) {
|
||||
if (dto.getNodeType().equalsIgnoreCase("folder")) {
|
||||
predicates.add(criteriaBuilder.equal(root.get("type"), dto.getType()));
|
||||
} else {
|
||||
predicates.add(criteriaBuilder.notEqual(root.get("type"), "folder"));
|
||||
}
|
||||
}
|
||||
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||
};
|
||||
|
||||
}
|
||||
List<CoreDatasource> list = coreDatasourceMapper.selectList(wrapper);
|
||||
List<CoreDatasource> list = coreDatasourceRepository.findAll(spec);
|
||||
if (list.size() > 0) {
|
||||
DEException.throwException(Translator.get("i18n_ds_name_exists"));
|
||||
}
|
||||
@@ -161,24 +162,20 @@ public class DataSourceManage {
|
||||
|
||||
@XpackInteract(value = "datasourceResourceTree", before = false)
|
||||
public void innerEdit(CoreDatasource coreDatasource) {
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", coreDatasource.getId());
|
||||
coreDatasource.setUpdateTime(System.currentTimeMillis());
|
||||
coreDatasource.setUpdateBy(AuthUtils.getUser().getUserId());
|
||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
coreDatasourceMapper.update(coreDatasource, updateWrapper);
|
||||
coreDatasourceRepository.save(coreDatasource);
|
||||
coreOptRecentManage.saveOpt(coreDatasource.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASOURCE, OptConstants.OPT_TYPE.UPDATE);
|
||||
}
|
||||
|
||||
|
||||
@XpackInteract(value = "datasourceResourceTree", before = false)
|
||||
public void innerEditName(CoreDatasource coreDatasource) {
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", coreDatasource.getId());
|
||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
coreDatasource.setUpdateTime(System.currentTimeMillis());
|
||||
coreDatasource.setUpdateBy(AuthUtils.getUser().getUserId());
|
||||
coreDatasourceMapper.update(coreDatasource, updateWrapper);
|
||||
Optional<CoreDatasource> optionalCoreDatasource = coreDatasourceRepository.findById(coreDatasource.getId());
|
||||
if (optionalCoreDatasource.isPresent()) {
|
||||
coreDatasourceRepository.move(coreDatasource.getId(), System.currentTimeMillis(), coreDatasource.getPid(), coreDatasource.getName(), AuthUtils.getUser().getUserId());
|
||||
}
|
||||
coreOptRecentManage.saveOpt(coreDatasource.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASOURCE, OptConstants.OPT_TYPE.UPDATE);
|
||||
}
|
||||
|
||||
@@ -187,7 +184,7 @@ public class DataSourceManage {
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", coreDatasource.getId());
|
||||
updateWrapper.set("status", coreDatasource.getStatus());
|
||||
coreDatasourceMapper.update(null, updateWrapper);
|
||||
coreDatasourceRepository.updateStatusById(coreDatasource.getStatus(), coreDatasource.getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -199,31 +196,21 @@ public class DataSourceManage {
|
||||
DEException.throwException("resource not exist");
|
||||
}
|
||||
checkName(dataSourceDTO);
|
||||
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", id);
|
||||
updateWrapper.set("update_time", System.currentTimeMillis());
|
||||
updateWrapper.set("pid", dataSourceDTO.getPid());
|
||||
updateWrapper.set("name", dataSourceDTO.getName());
|
||||
updateWrapper.set("update_by", AuthUtils.getUser().getUserId());
|
||||
coreDatasourceMapper.update(null, updateWrapper);
|
||||
|
||||
coreDatasourceRepository.move(id, System.currentTimeMillis(), dataSourceDTO.getPid(), dataSourceDTO.getName(), AuthUtils.getUser().getUserId());
|
||||
coreOptRecentManage.saveOpt(sourceData.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASOURCE, OptConstants.OPT_TYPE.UPDATE);
|
||||
}
|
||||
|
||||
|
||||
public void encryptDsConfig() {
|
||||
coreDatasourceMapper.selectList(null).forEach(dataSource -> {
|
||||
coreDatasourceMapper.updateById(dataSource);
|
||||
});
|
||||
coreDatasourceRepository.saveAll(coreDatasourceRepository.findAll());
|
||||
}
|
||||
|
||||
@XpackInteract(value = "datasourceResourceTree", before = false)
|
||||
public CoreDatasource getCoreDatasource(Long id) {
|
||||
if (id == -1L) {
|
||||
return engineManage.getDeEngine();
|
||||
}
|
||||
return coreDatasourceMapper.selectById(id);
|
||||
return coreDatasourceRepository.findById(id).get();
|
||||
|
||||
}
|
||||
|
||||
public List<Long> getPidList(Long pid) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasourceTask;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasourceTaskLog;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDeEngine;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.provider.*;
|
||||
import io.dataease.datasource.request.EngineRequest;
|
||||
import io.dataease.datasource.server.DatasourceServer;
|
||||
@@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
@@ -38,8 +39,8 @@ import static io.dataease.datasource.server.DatasourceTaskServer.ScheduleType.MA
|
||||
@Component
|
||||
public class DatasourceSyncManage {
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper datasourceMapper;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
@Resource
|
||||
private EngineManage engineManage;
|
||||
@Resource
|
||||
@@ -101,7 +102,7 @@ public class DatasourceSyncManage {
|
||||
|
||||
public void extractData(Long datasourceId, Long taskId, JobExecutionContext context) {
|
||||
LicenseUtil.validate();
|
||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
||||
CoreDatasource coreDatasource = coreDatasourceRepository.findById(datasourceId).orElse(null);
|
||||
if (coreDatasource == null) {
|
||||
LogUtil.error("Can not find datasource: " + datasourceId);
|
||||
return;
|
||||
@@ -123,11 +124,7 @@ public class DatasourceSyncManage {
|
||||
try {
|
||||
DatasourceServer.UpdateType updateType = DatasourceServer.UpdateType.valueOf(coreDatasourceTask.getUpdateType());
|
||||
if (context != null) {
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", datasourceId);
|
||||
CoreDatasource record = new CoreDatasource();
|
||||
record.setQrtzInstance(context.getFireInstanceId());
|
||||
datasourceMapper.update(record, updateWrapper);
|
||||
coreDatasourceRepository.updateQrtzInstanceById(context.getFireInstanceId(), datasourceId);
|
||||
}
|
||||
if (coreDatasource.getType().equalsIgnoreCase("ExcelRemote")) {
|
||||
extractedExcelData(taskId, coreDatasource, updateType, coreDatasourceTask.getSyncRate());
|
||||
@@ -138,7 +135,7 @@ public class DatasourceSyncManage {
|
||||
LogUtil.error(e);
|
||||
} finally {
|
||||
datasourceTaskServer.updateTaskStatus(coreDatasourceTask);
|
||||
updateDsTaskStatus(datasourceId);
|
||||
coreDatasourceRepository.updateTaskStatusByIds(Arrays.asList(datasourceId), TaskStatus.WaitingForExecution.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,17 +216,9 @@ public class DatasourceSyncManage {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDsTaskStatus(Long datasourceId) {
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", datasourceId);
|
||||
CoreDatasource record = new CoreDatasource();
|
||||
record.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
datasourceMapper.update(record, updateWrapper);
|
||||
}
|
||||
|
||||
public void extractDataForTable(Long datasourceId, String name, String tableName, String type) {
|
||||
DatasourceServer.UpdateType updateType = DatasourceServer.UpdateType.valueOf(type);
|
||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
||||
CoreDatasource coreDatasource = coreDatasourceRepository.findById(datasourceId).orElse(null);
|
||||
if (coreDatasource == null) {
|
||||
LogUtil.error("Can not find datasource: " + datasourceId);
|
||||
return;
|
||||
|
||||
@@ -3,8 +3,8 @@ package io.dataease.datasource.manage;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDeEngine;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDeEngineMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.type.H2;
|
||||
import io.dataease.datasource.type.Mysql;
|
||||
import io.dataease.exception.DEException;
|
||||
@@ -19,8 +19,10 @@ import io.dataease.utils.JsonUtil;
|
||||
import io.dataease.utils.ModelUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -40,9 +42,8 @@ public class EngineManage {
|
||||
private Environment env;
|
||||
@Resource
|
||||
private CoreDeEngineMapper deEngineMapper;
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper datasourceMapper;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
|
||||
@Value("${dataease.path.engine:jdbc:h2:/opt/dataease2.0/desktop_data;AUTO_SERVER=TRUE;AUTO_RECONNECT=TRUE;MODE=MySQL;CASE_INSENSITIVE_IDENTIFIERS=TRUE;DATABASE_TO_UPPER=FALSE}")
|
||||
private String engineUrl;
|
||||
@@ -167,13 +168,14 @@ public class EngineManage {
|
||||
}
|
||||
|
||||
public void initLocalDataSource() {
|
||||
QueryWrapper<CoreDatasource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", 985188400292302848L);
|
||||
queryWrapper.ne("create_time", 1715053684176L);
|
||||
CoreDatasource coreDatasource = new CoreDatasource();
|
||||
coreDatasource.setId(985188400292302848L);
|
||||
coreDatasource.setCreateTime(1715053684176L);
|
||||
Example<CoreDatasource> example = Example.of(coreDatasource);
|
||||
// 版本检查
|
||||
QueryWrapper<DeTemplateVersion> queryVersionWrapper = new QueryWrapper<>();
|
||||
queryVersionWrapper.eq("version", "985188400292302848");
|
||||
if (!datasourceMapper.exists(queryWrapper) && !deTemplateVersionMapper.exists(queryVersionWrapper) && !ModelUtils.isDesktop()) {
|
||||
if (!coreDatasourceRepository.exists(example) && !deTemplateVersionMapper.exists(queryVersionWrapper) && !ModelUtils.isDesktop()) {
|
||||
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)\\?(.*)");
|
||||
Matcher matcher = WITH_SQL_FRAGMENT.matcher(env.getProperty("spring.datasource.url"));
|
||||
if (!matcher.find()) {
|
||||
@@ -199,8 +201,8 @@ public class EngineManage {
|
||||
initDatasource.setUpdateBy(1L);
|
||||
initDatasource.setStatus("success");
|
||||
initDatasource.setTaskStatus("WaitingForExecution");
|
||||
datasourceMapper.deleteById(985188400292302848L);
|
||||
datasourceMapper.insert(initDatasource);
|
||||
coreDatasourceRepository.deleteById(985188400292302848L);
|
||||
coreDatasourceRepository.saveAndFlush(initDatasource);
|
||||
|
||||
DeTemplateVersion version = new DeTemplateVersion();
|
||||
version.setVersion("985188400292302848");
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package io.dataease.datasource.provider;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jcraft.jsch.Session;
|
||||
import io.dataease.constant.SQLConstants;
|
||||
import io.dataease.dataset.utils.FieldUtils;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDriver;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.manage.EngineManage;
|
||||
import io.dataease.datasource.request.EngineRequest;
|
||||
import io.dataease.datasource.type.*;
|
||||
@@ -33,6 +32,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -52,8 +52,8 @@ import java.util.stream.Collectors;
|
||||
@Component("calciteProvider")
|
||||
public class CalciteProvider extends Provider {
|
||||
|
||||
@Resource
|
||||
protected CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
@Resource
|
||||
private EngineManage engineManage;
|
||||
protected ExtendedJdbcClassLoader extendedJdbcClassLoader;
|
||||
@@ -1587,8 +1587,7 @@ public class CalciteProvider extends Provider {
|
||||
|
||||
public void initConnectionPool() {
|
||||
LogUtil.info("Begin to init datasource pool...");
|
||||
QueryWrapper<CoreDatasource> datasourceQueryWrapper = new QueryWrapper();
|
||||
List<CoreDatasource> coreDatasources = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().filter(coreDatasource -> !Arrays.asList("folder", "API", "Excel", "ExcelRemote").contains(coreDatasource.getType())).collect(Collectors.toList());
|
||||
List<CoreDatasource> coreDatasources = coreDatasourceRepository.findAll().stream().filter(coreDatasource -> !Arrays.asList("folder", "API", "Excel", "ExcelRemote").contains(coreDatasource.getType())).collect(Collectors.toList());
|
||||
CoreDatasource engine = engineManage.deEngine();
|
||||
if (engine != null) {
|
||||
coreDatasources.add(engine);
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
package io.dataease.datasource.server;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.dataease.api.ds.DatasourceDriverApi;
|
||||
import io.dataease.api.ds.vo.DriveDTO;
|
||||
import io.dataease.api.ds.vo.DriveJarDTO;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDriver;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDriverJar;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDriverJarMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDriverMapper;
|
||||
import io.dataease.extensions.datasource.dto.DatasourceDTO;
|
||||
import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.FileUtils;
|
||||
import io.dataease.utils.Md5Utils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RestController
|
||||
@RequestMapping("/datasourceDriver")
|
||||
public class DatasourceDriverServer implements DatasourceDriverApi {
|
||||
|
||||
@Value("${dataease.path.custom-drivers:/opt/dataease2.0/custom-drivers/}")
|
||||
private String DRIVER_PATH;
|
||||
|
||||
@Resource
|
||||
private CoreDriverMapper coreDriverMapper;
|
||||
|
||||
@Resource
|
||||
private CoreDriverJarMapper coreDriverJarMapper;
|
||||
|
||||
@Override
|
||||
public List<DatasourceDTO> query(String keyWord) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DriveDTO> list() {
|
||||
List<DriveDTO> driveDTOS = new ArrayList<>();
|
||||
List<CoreDriver> coreDrivers = coreDriverMapper.selectList(null);
|
||||
coreDrivers.forEach(coreDriver -> {
|
||||
DriveDTO datasourceDrive = new DriveDTO();
|
||||
BeanUtils.copyBean(datasourceDrive, coreDriver);
|
||||
datasourceDrive.setTypeDesc(""); //TODO 设置数据源类型desc
|
||||
});
|
||||
return driveDTOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DriveDTO> listByDsType(String dsType) {
|
||||
List<DriveDTO> driveDTOS = new ArrayList<>();
|
||||
QueryWrapper<CoreDriver> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type", dsType);
|
||||
List<CoreDriver> coreDrivers = coreDriverMapper.selectList(queryWrapper);
|
||||
coreDrivers.forEach(coreDriver -> {
|
||||
DriveDTO datasourceDrive = new DriveDTO();
|
||||
BeanUtils.copyBean(datasourceDrive, coreDriver);
|
||||
});
|
||||
return driveDTOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriveDTO save(DriveDTO datasourceDrive) {
|
||||
CoreDriver coreDriver = new CoreDriver();
|
||||
BeanUtils.copyBean(coreDriver, datasourceDrive);
|
||||
coreDriverMapper.insert(coreDriver);
|
||||
return datasourceDrive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriveDTO update(DriveDTO datasourceDrive) {
|
||||
CoreDriver coreDriver = new CoreDriver();
|
||||
BeanUtils.copyBean(coreDriver, datasourceDrive);
|
||||
coreDriverMapper.updateById(coreDriver);
|
||||
return datasourceDrive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String driverId) {
|
||||
coreDriverMapper.deleteById(driverId);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("deDriverId", driverId);
|
||||
coreDriverJarMapper.deleteByMap(map);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DriveJarDTO> listDriverJar(String driverId) {
|
||||
List<DriveJarDTO> driveJarDTOS = new ArrayList<>();
|
||||
QueryWrapper<CoreDriverJar> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("deDriverId", driverId);
|
||||
coreDriverJarMapper.selectList(queryWrapper).forEach(coreDriverJar -> {
|
||||
DriveJarDTO driveJarDTO = new DriveJarDTO();
|
||||
BeanUtils.copyBean(driveJarDTO, coreDriverJar);
|
||||
driveJarDTOS.add(driveJarDTO);
|
||||
});
|
||||
return driveJarDTOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDriverJar(String jarId) {
|
||||
CoreDriverJar driverJar = coreDriverJarMapper.selectById(jarId);
|
||||
coreDriverJarMapper.deleteById(jarId);
|
||||
CoreDriver driver = coreDriverMapper.selectById(driverJar.getDeDriverId());
|
||||
FileUtils.deleteFile(DRIVER_PATH + driverJar.getDeDriverId() + "/" + driverJar.getTransName());
|
||||
//TODO 更新classloader
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriveJarDTO uploadJar(@RequestParam("deDriverId") String deDriverId, @RequestParam("jarFile") MultipartFile jarFile) throws Exception {
|
||||
CoreDriver coreDriver = coreDriverMapper.selectById(deDriverId);
|
||||
if (coreDriver == null) {
|
||||
throw new RuntimeException("DRIVER_NOT_FOUND");
|
||||
}
|
||||
String filename = jarFile.getOriginalFilename();
|
||||
if (!filename.endsWith(".jar")) {
|
||||
throw new RuntimeException("NOT_JAR");
|
||||
}
|
||||
|
||||
QueryWrapper<CoreDriverJar> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("fileName", filename);
|
||||
if (!CollectionUtils.isEmpty(coreDriverJarMapper.selectList(queryWrapper))) {
|
||||
throw new Exception("A file with the same name already exists:" + filename);
|
||||
}
|
||||
|
||||
String dirPath = DRIVER_PATH + deDriverId + "/";
|
||||
String filePath = dirPath + Md5Utils.md5(filename) + ".jar";
|
||||
saveJarFile(jarFile, dirPath, filePath);
|
||||
|
||||
CoreDriverJar coreDriverJar = new CoreDriverJar();
|
||||
coreDriverJar.setDeDriverId(deDriverId);
|
||||
coreDriverJar.setVersion("");
|
||||
coreDriverJar.setFileName(filename);
|
||||
coreDriverJar.setDriverClass(String.join(",", new ArrayList<>()));
|
||||
coreDriverJar.setIsTransName(true);
|
||||
coreDriverJar.setTransName(Md5Utils.md5(filename) + ".jar");
|
||||
coreDriverJarMapper.insert(coreDriverJar);
|
||||
//TODO 并更新classloader
|
||||
|
||||
DriveJarDTO driveJarDTO = new DriveJarDTO();
|
||||
BeanUtils.copyBean(driveJarDTO, coreDriverJar);
|
||||
return driveJarDTO;
|
||||
}
|
||||
|
||||
private String saveJarFile(MultipartFile file, String dirPath, String filePath) throws Exception {
|
||||
File p = new File(dirPath);
|
||||
if (!p.exists()) {
|
||||
p.mkdirs();
|
||||
}
|
||||
File f = new File(filePath);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(f);
|
||||
fileOutputStream.write(file.getBytes());
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ import io.dataease.constant.SQLConstants;
|
||||
import io.dataease.dataset.manage.DatasetDataManage;
|
||||
import io.dataease.dataset.utils.TableUtils;
|
||||
import io.dataease.datasource.dao.auto.entity.*;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDsFinishPageMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.QrtzSchedulerStateMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.dao.ext.mapper.DataSourceExtMapper;
|
||||
import io.dataease.datasource.dao.ext.mapper.TaskLogExtMapper;
|
||||
import io.dataease.datasource.manage.DataSourceManage;
|
||||
@@ -54,6 +54,8 @@ import org.quartz.JobDataMap;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -61,6 +63,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.awt.print.Pageable;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -74,8 +77,6 @@ import static io.dataease.datasource.server.DatasourceTaskServer.ScheduleType.RI
|
||||
@RestController
|
||||
@RequestMapping("/datasource")
|
||||
public class DatasourceServer implements DatasourceApi {
|
||||
@Resource
|
||||
private CoreDatasourceMapper datasourceMapper;
|
||||
@Resource
|
||||
private EngineManage engineManage;
|
||||
@Resource
|
||||
@@ -105,6 +106,9 @@ public class DatasourceServer implements DatasourceApi {
|
||||
private PluginManageApi pluginManage;
|
||||
@Autowired(required = false)
|
||||
private RelationApi relationManage;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
|
||||
|
||||
public enum UpdateType {
|
||||
all_scope, add_scope
|
||||
@@ -138,10 +142,8 @@ public class DatasourceServer implements DatasourceApi {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return false;
|
||||
}
|
||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.in("id", ids);
|
||||
|
||||
List<CoreDatasource> datasources = datasourceMapper.selectList(wrapper);
|
||||
List<CoreDatasource> datasources = coreDatasourceRepository.findInIds(ids);
|
||||
if (CollectionUtils.isEmpty(datasources)) {
|
||||
return false;
|
||||
}
|
||||
@@ -566,11 +568,13 @@ public class DatasourceServer implements DatasourceApi {
|
||||
public List<DatasourceDTO> innerList(List<Long> ids, List<String> types) throws DEException {
|
||||
List<DatasourceDTO> list = new ArrayList<>();
|
||||
LambdaQueryWrapper<CoreDatasource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
List<CoreDatasource> dsList = new ArrayList<>();
|
||||
if (ids != null) {
|
||||
if (ids.isEmpty()) {
|
||||
return list;
|
||||
} else {
|
||||
queryWrapper.in(CoreDatasource::getId, ids);
|
||||
dsList = coreDatasourceRepository.findInIds(ids);
|
||||
}
|
||||
}
|
||||
if (types != null) {
|
||||
@@ -578,9 +582,9 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return list;
|
||||
} else {
|
||||
queryWrapper.in(CoreDatasource::getType, types);
|
||||
dsList = coreDatasourceRepository.findInTypes(types);
|
||||
}
|
||||
}
|
||||
List<CoreDatasource> dsList = datasourceMapper.selectList(queryWrapper);
|
||||
|
||||
for (CoreDatasource datasource : dsList) {
|
||||
DatasourceDTO datasourceDTO = new DatasourceDTO();
|
||||
@@ -684,15 +688,13 @@ public class DatasourceServer implements DatasourceApi {
|
||||
|
||||
datasourceTaskServer.deleteByDSId(datasourceId);
|
||||
}
|
||||
datasourceMapper.deleteById(datasourceId);
|
||||
coreDatasourceRepository.deleteById(datasourceId);
|
||||
if (notFullDs.stream().allMatch(e -> !coreDatasource.getType().contains(e))) {
|
||||
calciteProvider.delete(coreDatasource);
|
||||
}
|
||||
|
||||
if (coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.folder.name())) {
|
||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("pid", datasourceId);
|
||||
List<CoreDatasource> coreDatasources = datasourceMapper.selectList(wrapper);
|
||||
List<CoreDatasource> coreDatasources = coreDatasourceRepository.findByPid(datasourceId);
|
||||
if (ObjectUtils.isNotEmpty(coreDatasources)) {
|
||||
for (CoreDatasource record : coreDatasources) {
|
||||
delete(record.getId());
|
||||
@@ -1101,11 +1103,10 @@ public class DatasourceServer implements DatasourceApi {
|
||||
@Override
|
||||
public List<String> latestUse() {
|
||||
List<String> types = new ArrayList<>();
|
||||
QueryWrapper<CoreDatasource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("create_by", AuthUtils.getUser().getUserId());
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
queryWrapper.last(" limit 5");
|
||||
List<CoreDatasource> coreDatasources = datasourceMapper.selectList(queryWrapper);
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
|
||||
org.springframework.data.domain.Pageable pageableWithSort = PageRequest.of(0, 5, sort);
|
||||
|
||||
List<CoreDatasource> coreDatasources = coreDatasourceRepository.findCoreDatasourcesByCreateBy(AuthUtils.getUser().getUserId(), pageableWithSort);
|
||||
if (CollectionUtils.isEmpty(coreDatasources)) {
|
||||
return types;
|
||||
}
|
||||
@@ -1144,9 +1145,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
|
||||
|
||||
public void updateDatasourceStatus() {
|
||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.notIn("type", Arrays.asList("Excel", "folder"));
|
||||
List<CoreDatasource> datasources = datasourceMapper.selectList(wrapper);
|
||||
List<CoreDatasource> datasources = coreDatasourceRepository.findTypeNotIn(Arrays.asList("Excel", "folder"));
|
||||
datasources.forEach(datasource -> {
|
||||
if (!syncDsIds.contains(datasource.getId())) {
|
||||
syncDsIds.add(datasource.getId());
|
||||
@@ -1183,9 +1182,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
List<QrtzSchedulerState> qrtzSchedulerStates = qrtzSchedulerStateMapper.selectList(null);
|
||||
List<String> activeQrtzInstances = qrtzSchedulerStates.stream().filter(qrtzSchedulerState -> qrtzSchedulerState.getLastCheckinTime() + qrtzSchedulerState.getCheckinInterval() + 1000 > dataSourceExtMapper.selectTimestamp().getCurrentTimestamp() * 1000).map(QrtzSchedulerState::getInstanceName).collect(Collectors.toList());
|
||||
|
||||
QueryWrapper<CoreDatasource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("task_status", TaskStatus.UnderExecution.name());
|
||||
List<CoreDatasource> datasources = datasourceMapper.selectList(queryWrapper);
|
||||
List<CoreDatasource> datasources = coreDatasourceRepository.findByTaskStatus(TaskStatus.UnderExecution.name());
|
||||
|
||||
List<CoreDatasource> syncCoreDatasources = new ArrayList<>();
|
||||
List<CoreDatasource> jobStoppedCoreDatasources = new ArrayList<>();
|
||||
@@ -1200,12 +1197,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
if (CollectionUtils.isEmpty(jobStoppedCoreDatasources)) {
|
||||
return;
|
||||
}
|
||||
|
||||
queryWrapper.clear();
|
||||
queryWrapper.in("id", jobStoppedCoreDatasources.stream().map(CoreDatasource::getId).collect(Collectors.toList()));
|
||||
CoreDatasource record = new CoreDatasource();
|
||||
record.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
datasourceMapper.update(record, queryWrapper);
|
||||
coreDatasourceRepository.updateTaskStatusByIds(jobStoppedCoreDatasources.stream().map(CoreDatasource::getId).collect(Collectors.toList()), TaskStatus.WaitingForExecution.name());
|
||||
//Task
|
||||
datasourceTaskServer.updateByDsIds(jobStoppedCoreDatasources.stream().map(CoreDatasource::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@@ -6,15 +6,17 @@ import io.dataease.commons.constants.TaskStatus;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasourceTask;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasourceTaskLog;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceTaskLogMapper;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceTaskMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.dto.CoreDatasourceTaskDTO;
|
||||
import io.dataease.datasource.dao.ext.mapper.ExtDatasourceTaskMapper;
|
||||
import io.dataease.datasource.manage.DatasourceSyncManage;
|
||||
import io.dataease.utils.IDUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -26,8 +28,8 @@ public class DatasourceTaskServer {
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceTaskMapper datasourceTaskMapper;
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
@Resource
|
||||
private ExtDatasourceTaskMapper extDatasourceTaskMapper;
|
||||
@Resource
|
||||
@@ -131,15 +133,15 @@ public class DatasourceTaskServer {
|
||||
}
|
||||
|
||||
public synchronized boolean existUnderExecutionTask(Long datasourceId, Long taskId) {
|
||||
UpdateWrapper<CoreDatasource> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", datasourceId);
|
||||
updateWrapper.ne("task_status", TaskStatus.UnderExecution.name());
|
||||
CoreDatasource coreDatasource = new CoreDatasource();
|
||||
coreDatasource.setId(datasourceId);
|
||||
coreDatasource.setTaskStatus(TaskStatus.UnderExecution.name());
|
||||
Boolean existSyncTask = coreDatasourceMapper.update(coreDatasource, updateWrapper) == 0;
|
||||
Example<CoreDatasource> example = Example.of(coreDatasource);
|
||||
|
||||
boolean existSyncTask = coreDatasourceRepository.exists(example);
|
||||
if (!existSyncTask) {
|
||||
UpdateWrapper<CoreDatasourceTask> updateTaskWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", taskId);
|
||||
updateTaskWrapper.eq("id", taskId);
|
||||
CoreDatasourceTask record = new CoreDatasourceTask();
|
||||
record.setTaskStatus(TaskStatus.UnderExecution.name());
|
||||
record.setLastExecTime(System.currentTimeMillis());
|
||||
|
||||
@@ -34,7 +34,7 @@ import io.dataease.dataset.manage.DatasetGroupManage;
|
||||
import io.dataease.dataset.manage.DatasetSQLManage;
|
||||
import io.dataease.dataset.utils.DatasetUtils;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.auto.repository.CoreDatasourceRepository;
|
||||
import io.dataease.datasource.provider.ExcelUtils;
|
||||
import io.dataease.datasource.server.DatasourceServer;
|
||||
import io.dataease.exception.DEException;
|
||||
@@ -140,8 +140,8 @@ public class DataVisualizationServer implements DataVisualizationApi {
|
||||
@Resource
|
||||
private CoreDatasetTableFieldMapper coreDatasetTableFieldMapper;
|
||||
|
||||
@Resource
|
||||
private CoreDatasourceMapper coreDatasourceMapper;
|
||||
@Autowired
|
||||
private CoreDatasourceRepository coreDatasourceRepository;
|
||||
|
||||
@Resource
|
||||
private CoreBusiManage coreBusiManage;
|
||||
@@ -277,7 +277,7 @@ public class DataVisualizationServer implements DataVisualizationApi {
|
||||
}
|
||||
});
|
||||
|
||||
List<CoreDatasource> systemDatasource = coreDatasourceMapper.selectBatchIds(newDatasourceId);
|
||||
List<CoreDatasource> systemDatasource = coreDatasourceRepository.findInIds(newDatasourceId);
|
||||
systemDatasource.forEach(datasourceNew -> {
|
||||
// Excel 数据表明映射
|
||||
if (StringUtils.isNotEmpty(datasourceNew.getConfiguration())) {
|
||||
|
||||
@@ -5,14 +5,14 @@ spring:
|
||||
password: 123456
|
||||
messages:
|
||||
basename: i18n/lic,i18n/core,i18n/permissions,i18n/xpack,i18n/sync
|
||||
flyway:
|
||||
enabled: true
|
||||
table: de_standalone_version
|
||||
validate-on-migrate: false
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
out-of-order: true
|
||||
|
||||
jpa:
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQLDialect
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mybatis/*.xml
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.dataease.initSql;
|
||||
|
||||
public interface SqlBlock {
|
||||
Version getVersion();
|
||||
void execute();
|
||||
String getVersionGroup();
|
||||
}
|
||||
45
sdk/common/src/main/java/io/dataease/initSql/Version.java
Normal file
45
sdk/common/src/main/java/io/dataease/initSql/Version.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package io.dataease.initSql;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Version implements Comparable<Version> {
|
||||
private final String version;
|
||||
private final List<String> parts;
|
||||
|
||||
public Version(String version) {
|
||||
this.version = version;
|
||||
this.parts = parseVersionString(version);
|
||||
}
|
||||
|
||||
private List<String> parseVersionString(String version) {
|
||||
return Arrays.asList(version.split("\\."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version other) {
|
||||
int i = 0;
|
||||
while (i < parts.size() || i < other.parts.size()) {
|
||||
if (i < parts.size() && i < other.parts.size()) {
|
||||
int thisPart = Integer.parseInt(parts.get(i));
|
||||
int otherPart = Integer.parseInt(other.parts.get(i));
|
||||
if (thisPart != otherPart) {
|
||||
return thisPart - otherPart;
|
||||
}
|
||||
} else if (i < parts.size()) {
|
||||
if (Integer.parseInt(parts.get(i)) != 0) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (Integer.parseInt(other.parts.get(i)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user