From d3b15391e1743d54264c2f2d800c4c96335cd8dd Mon Sep 17 00:00:00 2001 From: taojinlong Date: Sat, 20 Feb 2021 18:35:09 +0800 Subject: [PATCH] datasource --- .../io/dataease/base/domain/Datasource.java | 23 + .../base/domain/DatasourceExample.java | 600 ++++++++++++++++++ .../base/mapper/DatasourceMapper.java | 36 ++ .../dataease/base/mapper/DatasourceMapper.xml | 287 +++++++++ .../io/dataease/config/WebSocketConfig.java | 15 - .../datasource/constants/DatasourceTypes.java | 5 + .../controller/DatasourceController.java | 51 ++ .../datasource/dto/MysqlConfigrationDTO.java | 25 + .../provider/DatasourceProvider.java | 47 ++ .../datasource/provider/JdbcProvider.java | 105 +++ .../datasource/provider/ProviderFactory.java | 33 + .../datasource/service/DatasourceService.java | 67 ++ .../resources/db/migration/V6__datasource.sql | 10 + .../src/main/resources/generatorConfig.xml | 7 +- .../business/components/settings/router.js | 5 + .../components/settings/system/Datasource.vue | 535 ++++++++++++++++ frontend/src/i18n/zh-CN.js | 54 +- 17 files changed, 1883 insertions(+), 22 deletions(-) create mode 100644 backend/src/main/java/io/dataease/base/domain/Datasource.java create mode 100644 backend/src/main/java/io/dataease/base/domain/DatasourceExample.java create mode 100644 backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.java create mode 100644 backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.xml delete mode 100644 backend/src/main/java/io/dataease/config/WebSocketConfig.java create mode 100644 backend/src/main/java/io/dataease/datasource/constants/DatasourceTypes.java create mode 100644 backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java create mode 100644 backend/src/main/java/io/dataease/datasource/dto/MysqlConfigrationDTO.java create mode 100644 backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java create mode 100644 backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java create mode 100644 backend/src/main/java/io/dataease/datasource/provider/ProviderFactory.java create mode 100644 backend/src/main/java/io/dataease/datasource/service/DatasourceService.java create mode 100644 backend/src/main/resources/db/migration/V6__datasource.sql create mode 100644 frontend/src/business/components/settings/system/Datasource.vue diff --git a/backend/src/main/java/io/dataease/base/domain/Datasource.java b/backend/src/main/java/io/dataease/base/domain/Datasource.java new file mode 100644 index 0000000000..5becfe9cb8 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/domain/Datasource.java @@ -0,0 +1,23 @@ +package io.dataease.base.domain; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class Datasource implements Serializable { + private String id; + + private String name; + + private String desc; + + private String type; + + private Long createTime; + + private Long updateTime; + + private String configuration; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/domain/DatasourceExample.java b/backend/src/main/java/io/dataease/base/domain/DatasourceExample.java new file mode 100644 index 0000000000..10d246da35 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/domain/DatasourceExample.java @@ -0,0 +1,600 @@ +package io.dataease.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class DatasourceExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public DatasourceExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(String value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(String value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(String value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(String value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(String value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(String value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLike(String value) { + addCriterion("id like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotLike(String value) { + addCriterion("id not like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(String value1, String value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(String value1, String value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andNameIsNull() { + addCriterion("`name` is null"); + return (Criteria) this; + } + + public Criteria andNameIsNotNull() { + addCriterion("`name` is not null"); + return (Criteria) this; + } + + public Criteria andNameEqualTo(String value) { + addCriterion("`name` =", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotEqualTo(String value) { + addCriterion("`name` <>", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThan(String value) { + addCriterion("`name` >", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThanOrEqualTo(String value) { + addCriterion("`name` >=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThan(String value) { + addCriterion("`name` <", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThanOrEqualTo(String value) { + addCriterion("`name` <=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLike(String value) { + addCriterion("`name` like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotLike(String value) { + addCriterion("`name` not like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameIn(List values) { + addCriterion("`name` in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameNotIn(List values) { + addCriterion("`name` not in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameBetween(String value1, String value2) { + addCriterion("`name` between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andNameNotBetween(String value1, String value2) { + addCriterion("`name` not between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andDescIsNull() { + addCriterion("`desc` is null"); + return (Criteria) this; + } + + public Criteria andDescIsNotNull() { + addCriterion("`desc` is not null"); + return (Criteria) this; + } + + public Criteria andDescEqualTo(String value) { + addCriterion("`desc` =", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescNotEqualTo(String value) { + addCriterion("`desc` <>", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescGreaterThan(String value) { + addCriterion("`desc` >", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescGreaterThanOrEqualTo(String value) { + addCriterion("`desc` >=", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescLessThan(String value) { + addCriterion("`desc` <", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescLessThanOrEqualTo(String value) { + addCriterion("`desc` <=", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescLike(String value) { + addCriterion("`desc` like", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescNotLike(String value) { + addCriterion("`desc` not like", value, "desc"); + return (Criteria) this; + } + + public Criteria andDescIn(List values) { + addCriterion("`desc` in", values, "desc"); + return (Criteria) this; + } + + public Criteria andDescNotIn(List values) { + addCriterion("`desc` not in", values, "desc"); + return (Criteria) this; + } + + public Criteria andDescBetween(String value1, String value2) { + addCriterion("`desc` between", value1, value2, "desc"); + return (Criteria) this; + } + + public Criteria andDescNotBetween(String value1, String value2) { + addCriterion("`desc` not between", value1, value2, "desc"); + return (Criteria) this; + } + + public Criteria andTypeIsNull() { + addCriterion("`type` is null"); + return (Criteria) this; + } + + public Criteria andTypeIsNotNull() { + addCriterion("`type` is not null"); + return (Criteria) this; + } + + public Criteria andTypeEqualTo(String value) { + addCriterion("`type` =", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotEqualTo(String value) { + addCriterion("`type` <>", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThan(String value) { + addCriterion("`type` >", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThanOrEqualTo(String value) { + addCriterion("`type` >=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThan(String value) { + addCriterion("`type` <", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThanOrEqualTo(String value) { + addCriterion("`type` <=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLike(String value) { + addCriterion("`type` like", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotLike(String value) { + addCriterion("`type` not like", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeIn(List values) { + addCriterion("`type` in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotIn(List values) { + addCriterion("`type` not in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeBetween(String value1, String value2) { + addCriterion("`type` between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotBetween(String value1, String value2) { + addCriterion("`type` not between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Long value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Long value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Long value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Long value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Long value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Long value1, Long value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Long value1, Long value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Long value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Long value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Long value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Long value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Long value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Long value1, Long value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Long value1, Long value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.java b/backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.java new file mode 100644 index 0000000000..131bfd5714 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.java @@ -0,0 +1,36 @@ +package io.dataease.base.mapper; + +import io.dataease.base.domain.Datasource; +import io.dataease.base.domain.DatasourceExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface DatasourceMapper { + long countByExample(DatasourceExample example); + + int deleteByExample(DatasourceExample example); + + int deleteByPrimaryKey(String id); + + int insert(Datasource record); + + int insertSelective(Datasource record); + + List selectByExampleWithBLOBs(DatasourceExample example); + + List selectByExample(DatasourceExample example); + + Datasource selectByPrimaryKey(String id); + + int updateByExampleSelective(@Param("record") Datasource record, @Param("example") DatasourceExample example); + + int updateByExampleWithBLOBs(@Param("record") Datasource record, @Param("example") DatasourceExample example); + + int updateByExample(@Param("record") Datasource record, @Param("example") DatasourceExample example); + + int updateByPrimaryKeySelective(Datasource record); + + int updateByPrimaryKeyWithBLOBs(Datasource record); + + int updateByPrimaryKey(Datasource record); +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.xml b/backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.xml new file mode 100644 index 0000000000..f5670c69f5 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/DatasourceMapper.xml @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, `name`, `desc`, `type`, create_time, update_time + + + configuration + + + + + + delete from datasource + where id = #{id,jdbcType=VARCHAR} + + + delete from datasource + + + + + + insert into datasource (id, `name`, `desc`, + `type`, create_time, update_time, + configuration) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, + #{type,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, + #{configuration,jdbcType=LONGVARCHAR}) + + + insert into datasource + + + id, + + + `name`, + + + `desc`, + + + `type`, + + + create_time, + + + update_time, + + + configuration, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{desc,jdbcType=VARCHAR}, + + + #{type,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=BIGINT}, + + + #{updateTime,jdbcType=BIGINT}, + + + #{configuration,jdbcType=LONGVARCHAR}, + + + + + + update datasource + + + id = #{record.id,jdbcType=VARCHAR}, + + + `name` = #{record.name,jdbcType=VARCHAR}, + + + `desc` = #{record.desc,jdbcType=VARCHAR}, + + + `type` = #{record.type,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=BIGINT}, + + + update_time = #{record.updateTime,jdbcType=BIGINT}, + + + configuration = #{record.configuration,jdbcType=LONGVARCHAR}, + + + + + + + + update datasource + set id = #{record.id,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, + `desc` = #{record.desc,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + configuration = #{record.configuration,jdbcType=LONGVARCHAR} + + + + + + update datasource + set id = #{record.id,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, + `desc` = #{record.desc,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + update_time = #{record.updateTime,jdbcType=BIGINT} + + + + + + update datasource + + + `name` = #{name,jdbcType=VARCHAR}, + + + `desc` = #{desc,jdbcType=VARCHAR}, + + + `type` = #{type,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=BIGINT}, + + + update_time = #{updateTime,jdbcType=BIGINT}, + + + configuration = #{configuration,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update datasource + set `name` = #{name,jdbcType=VARCHAR}, + `desc` = #{desc,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=BIGINT}, + configuration = #{configuration,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=VARCHAR} + + + update datasource + set `name` = #{name,jdbcType=VARCHAR}, + `desc` = #{desc,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=BIGINT} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/config/WebSocketConfig.java b/backend/src/main/java/io/dataease/config/WebSocketConfig.java deleted file mode 100644 index 2082102c9a..0000000000 --- a/backend/src/main/java/io/dataease/config/WebSocketConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.dataease.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration -public class WebSocketConfig { - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - -} diff --git a/backend/src/main/java/io/dataease/datasource/constants/DatasourceTypes.java b/backend/src/main/java/io/dataease/datasource/constants/DatasourceTypes.java new file mode 100644 index 0000000000..1c3860db49 --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/constants/DatasourceTypes.java @@ -0,0 +1,5 @@ +package io.dataease.datasource.constants; + +public enum DatasourceTypes { + mysql +} diff --git a/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java b/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java new file mode 100644 index 0000000000..48e195fcd3 --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java @@ -0,0 +1,51 @@ +package io.dataease.datasource.controller; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.dataease.base.domain.Datasource; +import io.dataease.commons.utils.PageUtils; +import io.dataease.commons.utils.Pager; +import io.dataease.datasource.service.DatasourceService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@RequestMapping("datasource") +@RestController +public class DatasourceController { + + @Resource + private DatasourceService datasourceService; + + @PostMapping("/add") + public Datasource addDatasource(@RequestBody Datasource Datasource) { + return datasourceService.addDatasource(Datasource); + } + + @PostMapping("/validate") + public void validate(@RequestBody Datasource Datasource) throws Exception{ + datasourceService.validate(Datasource); + } + + @GetMapping("/list") + public List getDatasourceList() throws Exception { + return datasourceService.getDatasourceList(new Datasource()); + } + + @PostMapping("/list/{goPage}/{pageSize}") + public Pager> getDatasourceList(@RequestBody Datasource request, @PathVariable int goPage, @PathVariable int pageSize) throws Exception{ + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, datasourceService.getDatasourceList(request)); + } + + @GetMapping("/delete/{datasourceID}") + public void deleteDatasource(@PathVariable(value = "datasourceID") String datasourceID) { + datasourceService.deleteDatasource(datasourceID); + } + + @PostMapping("/update") + public void updateDatasource(@RequestBody Datasource Datasource) { + datasourceService.updateDatasource(Datasource); + } +} diff --git a/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigrationDTO.java b/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigrationDTO.java new file mode 100644 index 0000000000..a7197eb75c --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigrationDTO.java @@ -0,0 +1,25 @@ +package io.dataease.datasource.dto; + +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.StringUtils; + +@Getter +@Setter +public class MysqlConfigrationDTO { + private String host; + private Integer port; + private String username; + private String password; + private String jdbc; + private String dataBase; + private String driver = "com.mysql.cj.jdbc.Driver"; + + public String getJdbc(){ + if(StringUtils.isNotEmpty(jdbc)){ + return jdbc; + }else { + return "jdbc:mysql://HOSTNAME:PORT/DATABASE".replace("HOSTNAME", host).replace("PORT", port.toString()).replace("DATABASE", dataBase); + } + } +} diff --git a/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java b/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java new file mode 100644 index 0000000000..2258400264 --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java @@ -0,0 +1,47 @@ +package io.dataease.datasource.provider; + +import java.util.List; + +public abstract class DatasourceProvider { + + protected String dataSourceConfigration; + protected String type; + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + protected String query; + private int resultLimit = 30000; + + public String getDataSourceConfigration() { + return dataSourceConfigration; + } + + public void setDataSourceConfigration(String dataSourceConfigration) { + this.dataSourceConfigration = dataSourceConfigration; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + + + abstract public List getData() throws Exception; + + abstract public List getTables() throws Exception; + + public void test() throws Exception { + getData(); + } + +} diff --git a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java new file mode 100644 index 0000000000..68d4c4e596 --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java @@ -0,0 +1,105 @@ +package io.dataease.datasource.provider; + +import com.google.gson.Gson; +import io.dataease.datasource.constants.DatasourceTypes; +import io.dataease.datasource.dto.MysqlConfigrationDTO; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.sql.*; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import io.dataease.datasource.constants.DatasourceTypes.*; +import java.util.Properties; + + +@Service("jdbc") +public class JdbcProvider extends DatasourceProvider{ + + @Override + public List getData() throws Exception { + List list = new LinkedList<>(); + try ( + Connection connection = getConnection(); + Statement stat = connection.createStatement(); + ResultSet rs = stat.executeQuery(getQuery()) + ) { + ResultSetMetaData metaData = rs.getMetaData(); + int columnCount = metaData.getColumnCount(); + while (rs.next()) { + String[] row = new String[columnCount]; + for (int j = 0; j < columnCount; j++) { + int columType = metaData.getColumnType(j + 1); + switch (columType) { + case java.sql.Types.DATE: + row[j] = rs.getDate(j + 1).toString(); + break; + default: + row[j] = rs.getString(j + 1); + break; + } + } + list.add(row); + } + } catch (Exception e) { + throw new Exception("ERROR:" + e.getMessage(), e); + } + return list; + } + + @Override + public List getTables() throws Exception { + List tables = new ArrayList<>(); + + String queryStr = "show tables"; + try (Connection con = getConnection(); Statement ps = con.createStatement()) { + ResultSet resultSet = ps.executeQuery(queryStr); + while (resultSet.next()){ + tables.add(resultSet.getString(1)); + } + } catch (Exception e) { + throw new Exception("ERROR: " + e.getMessage(), e); + } + return tables; + } + + @Override + public void test() throws Exception { + String queryStr = "show tables"; + try (Connection con = getConnection(); Statement ps = con.createStatement()) { + ResultSet resultSet = ps.executeQuery(queryStr); + } catch (Exception e) { + throw new Exception("ERROR: " + e.getMessage(), e); + } + } + + + private Connection getConnection() throws Exception { + String username = null; + String password = null; + String driver = null; + String jdbcurl = null; + DatasourceTypes datasourceType = DatasourceTypes.valueOf(getType()); + switch (datasourceType){ + case mysql: + MysqlConfigrationDTO mysqlConfigrationDTO = new Gson().fromJson(getDataSourceConfigration(), MysqlConfigrationDTO.class); + username = mysqlConfigrationDTO.getUsername(); + password = mysqlConfigrationDTO.getPassword(); + driver = mysqlConfigrationDTO.getDriver(); + jdbcurl = mysqlConfigrationDTO.getJdbc(); + break; + default: + break; + } + + Class.forName(driver); + Properties props = new Properties(); + props.setProperty("user", username); + if (StringUtils.isNotBlank(password)) { + props.setProperty("password", password); + } + return DriverManager.getConnection(jdbcurl, props); + } + +} diff --git a/backend/src/main/java/io/dataease/datasource/provider/ProviderFactory.java b/backend/src/main/java/io/dataease/datasource/provider/ProviderFactory.java new file mode 100644 index 0000000000..8c9f7269da --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/provider/ProviderFactory.java @@ -0,0 +1,33 @@ +package io.dataease.datasource.provider; + +import io.dataease.datasource.constants.DatasourceTypes; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + + + +@Component +public class ProviderFactory implements ApplicationContextAware { + + private static ApplicationContext context; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.context = applicationContext; + } + + public static DatasourceProvider getProvider(String type){ + DatasourceTypes datasourceType = DatasourceTypes.valueOf(type); + switch (datasourceType){ + case mysql: + return context.getBean("jdbc", DatasourceProvider.class); + default: + return context.getBean("jdbc", DatasourceProvider.class); + } + + } + + +} diff --git a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java new file mode 100644 index 0000000000..de19c05a31 --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java @@ -0,0 +1,67 @@ +package io.dataease.datasource.service; + +import com.google.gson.Gson; +import io.dataease.base.domain.*; +import io.dataease.base.mapper.*; +import io.dataease.datasource.dto.MysqlConfigrationDTO; +import io.dataease.datasource.provider.DatasourceProvider; +import io.dataease.datasource.provider.JdbcProvider; +import io.dataease.datasource.provider.ProviderFactory; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Service +@Transactional(rollbackFor = Exception.class) +public class DatasourceService { + + @Resource + private DatasourceMapper datasourceMapper; + + public Datasource addDatasource(Datasource datasource) { + long currentTimeMillis = System.currentTimeMillis(); + datasource.setId(UUID.randomUUID().toString()); + datasource.setUpdateTime(currentTimeMillis); + datasource.setCreateTime(currentTimeMillis); + datasourceMapper.insertSelective(datasource); + return datasource; + } + + public List getDatasourceList(Datasource request)throws Exception{ + DatasourceExample example = new DatasourceExample(); + DatasourceExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(request.getName())) { + criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%")); + } + if (StringUtils.isNotBlank(request.getType())) { + criteria.andTypeEqualTo(request.getType()); + } + example.setOrderByClause("update_time desc"); + return datasourceMapper.selectByExample(example); + } + + public void deleteDatasource(String datasourceId) { + datasourceMapper.deleteByPrimaryKey(datasourceId); + } + + public void updateDatasource(Datasource datasource) { + datasource.setCreateTime(null); + datasource.setUpdateTime(System.currentTimeMillis()); + datasourceMapper.updateByPrimaryKeySelective(datasource); + } + + public void validate(Datasource datasource)throws Exception { + DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType()); + datasourceProvider.setDataSourceConfigration(datasource.getConfiguration()); + datasourceProvider.test(); + } + + + +} diff --git a/backend/src/main/resources/db/migration/V6__datasource.sql b/backend/src/main/resources/db/migration/V6__datasource.sql new file mode 100644 index 0000000000..4fdd6de256 --- /dev/null +++ b/backend/src/main/resources/db/migration/V6__datasource.sql @@ -0,0 +1,10 @@ +CREATE TABLE `datasource` ( + `id` varchar(50) NOT NULL DEFAULT '' COMMENT 'ID', + `name` varchar(50) NOT NULL COMMENT '名称', + `desc` varchar(50) NOT NULL COMMENT '描述', + `type` varchar(50) NOT NULL COMMENT '类型', + `configuration` longtext NOT NULL COMMENT '详细信息', + `create_time` bigint(13) NOT NULL COMMENT 'Create timestamp', + `update_time` bigint(13) NOT NULL COMMENT 'Update timestamp', + PRIMARY KEY (`id`) +) diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index e3cd14f962..7335b04159 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -64,11 +64,8 @@ - -
- - - +
+ diff --git a/frontend/src/business/components/settings/router.js b/frontend/src/business/components/settings/router.js index 253335ab7c..efd342f18a 100644 --- a/frontend/src/business/components/settings/router.js +++ b/frontend/src/business/components/settings/router.js @@ -7,6 +7,11 @@ export default { content: () => import('@/business/components/settings/Setting') }, children: [ + { + path: 'datasource', + component: () => import('@/business/components/settings/system/Datasource'), + meta: {system: true, title: 'commons.datasource'} + }, { path: 'user', component: () => import('@/business/components/settings/system/User'), diff --git a/frontend/src/business/components/settings/system/Datasource.vue b/frontend/src/business/components/settings/system/Datasource.vue new file mode 100644 index 0000000000..13320dd4fc --- /dev/null +++ b/frontend/src/business/components/settings/system/Datasource.vue @@ -0,0 +1,535 @@ + + + + + diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 59ab7d855b..3169f71d36 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -192,7 +192,8 @@ export default { module: { select_module: "选择模块", default_module: "默认模块", - } + }, + datasource: '数据连接' }, license: { title: '授权管理', @@ -1521,5 +1522,54 @@ export default { delete_prompt: '此操作会删除认证源,是否继续?', title: '认证设置', auth_name_valid: '名称不支持特殊字符', - } + }, + datasource: { + create: '新建数据连接', + type: '类型', + please_choose_type: '请选择数据源类型', + data_base: '数据库名称', + user_name: '用户名', + password: '密码', + host: '主机', + port: '端口', + please_input_data_base: '请输入数据库名称', + please_input_user_name: '请输入用户名', + please_input_password: '请输入密码', + please_input_host: '请输入主机', + please_input_port: '请输入端口', + modify: '修改组织', + delete: '删除组织', + delete_confirm: '删除该组织会关联删除该组织下的所有资源(如:相关工作空间,项目,测试用例等),确定要删除吗?', + input_name: '请输入名称', + input_desc: '请输入描述', + select_organization: '请选择组织', + search_by_name: '根据名称搜索', + special_characters_are_not_supported: '格式错误(不支持特殊字符,且不能以\'-\'开头结尾)', + none: '无组织', + select: '选择组织', + delete_warning: '删除该组织将同步删除该组织下所有相关工作空间和相关工作空间下的所有项目,以及项目中的所有用例、接口测试、性能测试等,确定要删除吗?', + service_integration: '服务集成', + defect_manage: '缺陷管理平台', + message_settings: '消息设置', + message: { + jenkins_task_notification: 'Jenkins接口调用任务通知', + test_plan_task_notification: '测试计划任务通知', + test_review_task_notice: '测试评审任务通知', + create_new_notification: '创建新通知', + mail_template_example: '邮件模版', + robot_template: '机器人模版', + select_events: '选择事件', + defect_task_notification: '缺陷任务通知', + select_receiving_method: '选择接收方式', + mail: '邮件', + nail_robot: '钉钉机器人', + enterprise_wechat_robot: '企业微信机器人', + notes: '1.钉钉和企业群里新建一个自定义机器人,然后复制 webhook 地址在我们平台上;\n' + + ' 2.机器人选择为群机器人,安全验证选择“自定义关键词” :"任务通知";\n' + + ' 3.选择接收人时必须是你所建的群里包含的人,接收人手机号为必填项且为钉钉企业所使用的手机号,', + message: '事件,接收人,接收方式为必填项', + message_webhook: '接收方式为钉钉和企业机器人时,webhook为必填项', + template: "模版" + }, + }, };