diff --git a/backend/src/main/java/io/dataease/base/domain/DatasetTableFunction.java b/backend/src/main/java/io/dataease/base/domain/DatasetTableFunction.java new file mode 100644 index 0000000000..b6232a6fa0 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/domain/DatasetTableFunction.java @@ -0,0 +1,21 @@ +package io.dataease.base.domain; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class DatasetTableFunction implements Serializable { + private Long id; + + private String name; + + private String func; + + private String dbType; + + private Integer funcType; + + private String desc; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/domain/DatasetTableFunctionExample.java b/backend/src/main/java/io/dataease/base/domain/DatasetTableFunctionExample.java new file mode 100644 index 0000000000..f098e791f9 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/domain/DatasetTableFunctionExample.java @@ -0,0 +1,530 @@ +package io.dataease.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class DatasetTableFunctionExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public DatasetTableFunctionExample() { + 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(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", 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(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long 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 andFuncIsNull() { + addCriterion("func is null"); + return (Criteria) this; + } + + public Criteria andFuncIsNotNull() { + addCriterion("func is not null"); + return (Criteria) this; + } + + public Criteria andFuncEqualTo(String value) { + addCriterion("func =", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncNotEqualTo(String value) { + addCriterion("func <>", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncGreaterThan(String value) { + addCriterion("func >", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncGreaterThanOrEqualTo(String value) { + addCriterion("func >=", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncLessThan(String value) { + addCriterion("func <", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncLessThanOrEqualTo(String value) { + addCriterion("func <=", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncLike(String value) { + addCriterion("func like", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncNotLike(String value) { + addCriterion("func not like", value, "func"); + return (Criteria) this; + } + + public Criteria andFuncIn(List values) { + addCriterion("func in", values, "func"); + return (Criteria) this; + } + + public Criteria andFuncNotIn(List values) { + addCriterion("func not in", values, "func"); + return (Criteria) this; + } + + public Criteria andFuncBetween(String value1, String value2) { + addCriterion("func between", value1, value2, "func"); + return (Criteria) this; + } + + public Criteria andFuncNotBetween(String value1, String value2) { + addCriterion("func not between", value1, value2, "func"); + return (Criteria) this; + } + + public Criteria andDbTypeIsNull() { + addCriterion("db_type is null"); + return (Criteria) this; + } + + public Criteria andDbTypeIsNotNull() { + addCriterion("db_type is not null"); + return (Criteria) this; + } + + public Criteria andDbTypeEqualTo(String value) { + addCriterion("db_type =", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeNotEqualTo(String value) { + addCriterion("db_type <>", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeGreaterThan(String value) { + addCriterion("db_type >", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeGreaterThanOrEqualTo(String value) { + addCriterion("db_type >=", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeLessThan(String value) { + addCriterion("db_type <", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeLessThanOrEqualTo(String value) { + addCriterion("db_type <=", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeLike(String value) { + addCriterion("db_type like", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeNotLike(String value) { + addCriterion("db_type not like", value, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeIn(List values) { + addCriterion("db_type in", values, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeNotIn(List values) { + addCriterion("db_type not in", values, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeBetween(String value1, String value2) { + addCriterion("db_type between", value1, value2, "dbType"); + return (Criteria) this; + } + + public Criteria andDbTypeNotBetween(String value1, String value2) { + addCriterion("db_type not between", value1, value2, "dbType"); + return (Criteria) this; + } + + public Criteria andFuncTypeIsNull() { + addCriterion("func_type is null"); + return (Criteria) this; + } + + public Criteria andFuncTypeIsNotNull() { + addCriterion("func_type is not null"); + return (Criteria) this; + } + + public Criteria andFuncTypeEqualTo(Integer value) { + addCriterion("func_type =", value, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeNotEqualTo(Integer value) { + addCriterion("func_type <>", value, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeGreaterThan(Integer value) { + addCriterion("func_type >", value, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeGreaterThanOrEqualTo(Integer value) { + addCriterion("func_type >=", value, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeLessThan(Integer value) { + addCriterion("func_type <", value, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeLessThanOrEqualTo(Integer value) { + addCriterion("func_type <=", value, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeIn(List values) { + addCriterion("func_type in", values, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeNotIn(List values) { + addCriterion("func_type not in", values, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeBetween(Integer value1, Integer value2) { + addCriterion("func_type between", value1, value2, "funcType"); + return (Criteria) this; + } + + public Criteria andFuncTypeNotBetween(Integer value1, Integer value2) { + addCriterion("func_type not between", value1, value2, "funcType"); + 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/DatasetTableFunctionMapper.java b/backend/src/main/java/io/dataease/base/mapper/DatasetTableFunctionMapper.java new file mode 100644 index 0000000000..ddd5f3787a --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/DatasetTableFunctionMapper.java @@ -0,0 +1,36 @@ +package io.dataease.base.mapper; + +import io.dataease.base.domain.DatasetTableFunction; +import io.dataease.base.domain.DatasetTableFunctionExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface DatasetTableFunctionMapper { + long countByExample(DatasetTableFunctionExample example); + + int deleteByExample(DatasetTableFunctionExample example); + + int deleteByPrimaryKey(Long id); + + int insert(DatasetTableFunction record); + + int insertSelective(DatasetTableFunction record); + + List selectByExampleWithBLOBs(DatasetTableFunctionExample example); + + List selectByExample(DatasetTableFunctionExample example); + + DatasetTableFunction selectByPrimaryKey(Long id); + + int updateByExampleSelective(@Param("record") DatasetTableFunction record, @Param("example") DatasetTableFunctionExample example); + + int updateByExampleWithBLOBs(@Param("record") DatasetTableFunction record, @Param("example") DatasetTableFunctionExample example); + + int updateByExample(@Param("record") DatasetTableFunction record, @Param("example") DatasetTableFunctionExample example); + + int updateByPrimaryKeySelective(DatasetTableFunction record); + + int updateByPrimaryKeyWithBLOBs(DatasetTableFunction record); + + int updateByPrimaryKey(DatasetTableFunction record); +} \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/base/mapper/DatasetTableFunctionMapper.xml b/backend/src/main/java/io/dataease/base/mapper/DatasetTableFunctionMapper.xml new file mode 100644 index 0000000000..3f82540c50 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/DatasetTableFunctionMapper.xml @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + 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`, func, db_type, func_type + + + `desc` + + + + + + delete from dataset_table_function + where id = #{id,jdbcType=BIGINT} + + + delete from dataset_table_function + + + + + + insert into dataset_table_function (id, `name`, func, + db_type, func_type, `desc` + ) + values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{func,jdbcType=VARCHAR}, + #{dbType,jdbcType=VARCHAR}, #{funcType,jdbcType=INTEGER}, #{desc,jdbcType=LONGVARCHAR} + ) + + + insert into dataset_table_function + + + id, + + + `name`, + + + func, + + + db_type, + + + func_type, + + + `desc`, + + + + + #{id,jdbcType=BIGINT}, + + + #{name,jdbcType=VARCHAR}, + + + #{func,jdbcType=VARCHAR}, + + + #{dbType,jdbcType=VARCHAR}, + + + #{funcType,jdbcType=INTEGER}, + + + #{desc,jdbcType=LONGVARCHAR}, + + + + + + update dataset_table_function + + + id = #{record.id,jdbcType=BIGINT}, + + + `name` = #{record.name,jdbcType=VARCHAR}, + + + func = #{record.func,jdbcType=VARCHAR}, + + + db_type = #{record.dbType,jdbcType=VARCHAR}, + + + func_type = #{record.funcType,jdbcType=INTEGER}, + + + `desc` = #{record.desc,jdbcType=LONGVARCHAR}, + + + + + + + + update dataset_table_function + set id = #{record.id,jdbcType=BIGINT}, + `name` = #{record.name,jdbcType=VARCHAR}, + func = #{record.func,jdbcType=VARCHAR}, + db_type = #{record.dbType,jdbcType=VARCHAR}, + func_type = #{record.funcType,jdbcType=INTEGER}, + `desc` = #{record.desc,jdbcType=LONGVARCHAR} + + + + + + update dataset_table_function + set id = #{record.id,jdbcType=BIGINT}, + `name` = #{record.name,jdbcType=VARCHAR}, + func = #{record.func,jdbcType=VARCHAR}, + db_type = #{record.dbType,jdbcType=VARCHAR}, + func_type = #{record.funcType,jdbcType=INTEGER} + + + + + + update dataset_table_function + + + `name` = #{name,jdbcType=VARCHAR}, + + + func = #{func,jdbcType=VARCHAR}, + + + db_type = #{dbType,jdbcType=VARCHAR}, + + + func_type = #{funcType,jdbcType=INTEGER}, + + + `desc` = #{desc,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update dataset_table_function + set `name` = #{name,jdbcType=VARCHAR}, + func = #{func,jdbcType=VARCHAR}, + db_type = #{dbType,jdbcType=VARCHAR}, + func_type = #{funcType,jdbcType=INTEGER}, + `desc` = #{desc,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=BIGINT} + + + update dataset_table_function + set `name` = #{name,jdbcType=VARCHAR}, + func = #{func,jdbcType=VARCHAR}, + db_type = #{dbType,jdbcType=VARCHAR}, + func_type = #{funcType,jdbcType=INTEGER} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableFieldController.java b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableFieldController.java index 8a216eeb5a..ec815cf692 100644 --- a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableFieldController.java +++ b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableFieldController.java @@ -51,6 +51,16 @@ public class DataSetTableFieldController { dataSetTableFieldsService.batchEdit(list); } + @PostMapping("save") + public DatasetTableField save(@RequestBody DatasetTableField datasetTableField) { + return dataSetTableFieldsService.save(datasetTableField); + } + + @PostMapping("delete/{id}") + public void delete(@PathVariable String id) { + dataSetTableFieldsService.delete(id); + } + @PostMapping("fieldValues/{fieldId}") public List fieldValues(@PathVariable String fieldId) { return dataSetFieldService.fieldValues(fieldId); diff --git a/backend/src/main/java/io/dataease/controller/dataset/DatasetFunctionController.java b/backend/src/main/java/io/dataease/controller/dataset/DatasetFunctionController.java new file mode 100644 index 0000000000..915e7d556d --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/dataset/DatasetFunctionController.java @@ -0,0 +1,27 @@ +package io.dataease.controller.dataset; + +import io.dataease.base.domain.DatasetTableFunction; +import io.dataease.service.dataset.DatasetFunctionService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @Author gin + * @Date 2021/7/29 11:58 上午 + */ +@RestController +@RequestMapping("dataset/function") +public class DatasetFunctionController { + @Resource + private DatasetFunctionService datasetFunctionService; + + @PostMapping("listByTableId/{tableId}") + public List listByTableId(@PathVariable String tableId) { + return datasetFunctionService.listByTableId(tableId); + } +} diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableFieldsService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableFieldsService.java index 189155738a..f4a68cdec9 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableFieldsService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableFieldsService.java @@ -3,6 +3,7 @@ package io.dataease.service.dataset; import io.dataease.base.domain.DatasetTableField; import io.dataease.base.domain.DatasetTableFieldExample; import io.dataease.base.mapper.DatasetTableFieldMapper; +import io.dataease.commons.utils.DorisTableUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -32,6 +33,10 @@ public class DataSetTableFieldsService { public DatasetTableField save(DatasetTableField datasetTableField) { if (StringUtils.isEmpty(datasetTableField.getId())) { datasetTableField.setId(UUID.randomUUID().toString()); + // 若dataeasename为空,则用MD5(id)作为dataeasename + if (StringUtils.isEmpty(datasetTableField.getDataeaseName())) { + datasetTableField.setDataeaseName(DorisTableUtils.dorisFieldName(datasetTableField.getId())); + } datasetTableFieldMapper.insert(datasetTableField); } else { datasetTableFieldMapper.updateByPrimaryKeySelective(datasetTableField); @@ -86,4 +91,8 @@ public class DataSetTableFieldsService { public DatasetTableField get(String id) { return datasetTableFieldMapper.selectByPrimaryKey(id); } + + public void delete(String id) { + datasetTableFieldMapper.deleteByPrimaryKey(id); + } } diff --git a/backend/src/main/java/io/dataease/service/dataset/DatasetFunctionService.java b/backend/src/main/java/io/dataease/service/dataset/DatasetFunctionService.java new file mode 100644 index 0000000000..92f2d61b4c --- /dev/null +++ b/backend/src/main/java/io/dataease/service/dataset/DatasetFunctionService.java @@ -0,0 +1,54 @@ +package io.dataease.service.dataset; + +import io.dataease.base.domain.*; +import io.dataease.base.mapper.DatasetTableFunctionMapper; +import io.dataease.commons.utils.DorisTableUtils; +import io.dataease.datasource.service.DatasourceService; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.UUID; + +/** + * @Author gin + * @Date 2021/7/29 11:58 上午 + */ +@Service +public class DatasetFunctionService { + @Resource + private DatasetTableFunctionMapper datasetTableFunctionMapper; + @Resource + private DataSetTableService dataSetTableService; + @Resource + private DatasourceService datasourceService; + + public DatasetTableFunction get(Long id) { + return datasetTableFunctionMapper.selectByPrimaryKey(id); + } + + public List list(DatasetTableFunction datasetTableFunction) { + DatasetTableFunctionExample datasetTableFunctionExample = new DatasetTableFunctionExample(); + DatasetTableFunctionExample.Criteria criteria = datasetTableFunctionExample.createCriteria(); + if (StringUtils.isNotEmpty(datasetTableFunction.getDbType())) { + criteria.andDbTypeEqualTo(datasetTableFunction.getDbType()); + } + return datasetTableFunctionMapper.selectByExampleWithBLOBs(datasetTableFunctionExample); + } + + public List listByTableId(String id) { + DatasetTable datasetTable = dataSetTableService.get(id); + String dbType; + if (datasetTable.getMode() == 0) { + Datasource datasource = datasourceService.get(datasetTable.getDataSourceId()); + dbType = datasource.getType(); + } else { + dbType = "doris"; + } + DatasetTableFunction datasetTableFunction = new DatasetTableFunction(); + datasetTableFunction.setDbType(dbType); + return list(datasetTableFunction); + } +} diff --git a/backend/src/main/resources/db/migration/V18__area_mapping.sql b/backend/src/main/resources/db/migration/V18__area_mapping.sql index de30335fc4..6e114370af 100644 --- a/backend/src/main/resources/db/migration/V18__area_mapping.sql +++ b/backend/src/main/resources/db/migration/V18__area_mapping.sql @@ -2939,3 +2939,62 @@ INSERT INTO `area_mapping` VALUES (2897, '澳门特别行政区', '156820000', ' COMMIT; SET FOREIGN_KEY_CHECKS = 1; + + + +ALTER TABLE `dataset_table_field` MODIFY COLUMN `origin_name` LONGTEXT; + + +/* + Navicat Premium Data Transfer + + Source Server : local + Source Server Type : MySQL + Source Server Version : 50730 + Source Host : 127.0.0.1:3306 + Source Schema : dataease + + Target Server Type : MySQL + Target Server Version : 50730 + File Encoding : 65001 + + Date: 29/07/2021 11:55:10 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for dataset_table_function +-- ---------------------------- +DROP TABLE IF EXISTS `dataset_table_function`; +CREATE TABLE `dataset_table_function` ( + `id` bigint(20) NOT NULL COMMENT 'ID', + `name` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '函数名称', + `func` varchar(500) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '函数表达式', + `db_type` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '所属数据库', + `func_type` int(10) DEFAULT NULL COMMENT '函数类型:0-聚合函数;1-快速计算函数;2-数学和三角函数;3-日期函数;4-文本函数;5-逻辑函数;6-其它函数', + `desc` longtext COLLATE utf8mb4_bin COMMENT '描述', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +-- ---------------------------- +-- Records of dataset_table_function +-- ---------------------------- +BEGIN; +INSERT INTO `dataset_table_function` VALUES (1, 'ABS', 'ABS(x)', 'mysql', 2, '返回x的绝对值'); +INSERT INTO `dataset_table_function` VALUES (2, 'PI', 'PI()', 'mysql', 2, '返回圆周率π,默认显示6位小数'); +INSERT INTO `dataset_table_function` VALUES (3, 'CHAR_LENGTH', 'CHAR_LENGTH(str)', 'mysql', 4, '计算字符串字符个数'); +INSERT INTO `dataset_table_function` VALUES (4, 'TRIM', 'TRIM(s)', 'mysql', 4, '返回字符串s删除了两边空格之后的字符串'); +INSERT INTO `dataset_table_function` VALUES (5, 'REPLACE', 'REPLACE(s,s1,s2)', 'mysql', 4, '返回一个字符串,用字符串s2替代字符串s中所有的字符串s1'); +INSERT INTO `dataset_table_function` VALUES (6, 'SUBSTRING', 'SUBSTRING(s,n,len)', 'mysql', 4, '获取从字符串s中的第n个位置开始长度为len的字符串'); +INSERT INTO `dataset_table_function` VALUES (7, 'IF', 'IF(expr,v1,v2)', 'mysql', 5, '如果expr是TRUE则返回v1,否则返回v2'); +INSERT INTO `dataset_table_function` VALUES (8, 'IFNULL', 'IFNULL(v1,v2)', 'mysql', 5, '如果v1不为NULL,则返回v1,否则返回v2'); +INSERT INTO `dataset_table_function` VALUES (9, 'FLOOR', 'FLOOR(x)', 'mysql', 2, '返回不大于x的最大整数'); +INSERT INTO `dataset_table_function` VALUES (10, 'ROUND', 'ROUND(x)', 'mysql', 2, '返回离x最近的整数'); +INSERT INTO `dataset_table_function` VALUES (11, 'ROUND', 'ROUND(x,y)', 'mysql', 2, '保留x小数点后y位的值,但截断时要进行四舍五入'); +INSERT INTO `dataset_table_function` VALUES (12, 'ABS', 'ABS(x)', 'doris', 2, '返回x的绝对值'); +INSERT INTO `dataset_table_function` VALUES (13, 'SUBSTR', 'SUBSTR(char, position, substring_length)', 'oracle', 4, '获取从字符串char中的第position个位置开始长度为substring_lenght的字符串'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 8eb8a0cc3f..f01340eb22 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -64,7 +64,7 @@ - +
diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index ddc99fa3fd..f791982a32 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -986,7 +986,8 @@ export default { data_type: 'Data Type', click_ref_field: 'Click Quote Field', click_ref_function: 'Click Quote Function', - field_manage: 'Field Manage' + field_manage: 'Field Manage', + edit_calc_field: 'Edit calc field' }, datasource: { datasource: 'Data Source', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 9edc105a1d..1c35897828 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -986,7 +986,8 @@ export default { data_type: '數據類型', click_ref_field: '點擊引用字段', click_ref_function: '點擊引用函數', - field_manage: '字段管理' + field_manage: '字段管理', + edit_calc_field: '編輯計算字段' }, datasource: { datasource: '數據源', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 4586fb8316..5f7c8262bd 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -986,7 +986,8 @@ export default { data_type: '数据类型', click_ref_field: '点击引用字段', click_ref_function: '点击引用函数', - field_manage: '字段管理' + field_manage: '字段管理', + edit_calc_field: '编辑计算字段' }, datasource: { datasource: '数据源', diff --git a/frontend/src/views/dataset/data/CalcFieldEdit.vue b/frontend/src/views/dataset/data/CalcFieldEdit.vue index b827a0b173..c5dd3d9cb8 100644 --- a/frontend/src/views/dataset/data/CalcFieldEdit.vue +++ b/frontend/src/views/dataset/data/CalcFieldEdit.vue @@ -14,7 +14,7 @@ {{ $t('dataset.field_exp') }} - + @@ -87,7 +87,7 @@ :disabled="true" > - + @@ -101,11 +101,31 @@ {{ $t('dataset.click_ref_function') }} - {{ item.name }} + +

{{ item.name }}

+

{{ item.func }}

+

{{ item.desc }}

+ {{ item.func }} +
+ + +
+ {{ $t('dataset.cancel') }} + {{ $t('dataset.confirm') }} +
+
@@ -134,6 +154,7 @@ import 'codemirror/keymap/emacs.js' import 'codemirror/addon/hint/show-hint.css' import 'codemirror/addon/hint/sql-hint' import 'codemirror/addon/hint/show-hint' +import { post } from '../../../api/dataset/dataset' export default { name: 'CalcFieldEdit', @@ -146,16 +167,26 @@ export default { tableFields: { type: Object, required: true + }, + field: { + type: Object, + required: true } }, data() { return { fieldForm: { + id: null, name: '', groupType: 'd', - deType: 0 + deType: 0, + originName: '', + tableId: this.param.id, + checked: 1, + columnIndex: this.tableFields.dimensionList.length + this.tableFields.quotaList.length, + size: 0, + extField: 2 }, - fieldExp: '', cmOption: { tabSize: 2, styleActiveLine: true, @@ -174,33 +205,7 @@ export default { { label: this.$t('dataset.value') + '(' + this.$t('dataset.float') + ')', value: 3 }, { label: this.$t('dataset.location'), value: 5 } ], - functions: [ - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' }, - { name: 'ABS(n)' } - ] + functions: [] } }, computed: { @@ -208,10 +213,23 @@ export default { return this.$refs.myCm.codemirror } }, + watch: { + 'param': function() { + this.initFunctions() + }, + 'field': function() { + if (this.field.id) { + this.fieldForm = JSON.parse(JSON.stringify(this.field)) + } else { + this.fieldForm = JSON.parse(JSON.stringify(this.fieldForm)) + } + } + }, mounted() { this.$refs.myCm.codemirror.on('keypress', () => { this.$refs.myCm.codemirror.showHint() }) + this.initFunctions() }, methods: { onCmReady(cm) { @@ -222,7 +240,7 @@ export default { }, onCmCodeChange(newCode) { // console.log(newCode) - this.fieldExp = newCode + this.fieldForm.originName = newCode }, insertParamToCodeMirror(param) { const pos1 = this.$refs.myCm.codemirror.getCursor() @@ -230,6 +248,26 @@ export default { pos2.line = pos1.line pos2.ch = pos1.ch this.$refs.myCm.codemirror.replaceRange(param, pos2) + }, + + initFunctions() { + post('/dataset/function/listByTableId/' + this.param.id, null).then(response => { + this.functions = response.data + }) + }, + + closeCalcField() { + this.$emit('onEditClose', {}) + }, + + saveCalcField() { + if (!this.fieldForm.id) { + this.fieldForm.type = this.fieldForm.deType + this.fieldForm.deExtractType = this.fieldForm.deType + } + post('/dataset/field/save', this.fieldForm).then(response => { + this.closeCalcField() + }) } } } @@ -329,9 +367,28 @@ export default { padding: 2px 4px; cursor: pointer; margin: 4px 0; + overflow-x: hidden; + white-space: nowrap; + text-overflow: ellipsis; } .function-height{ height: calc(100% - 20px); overflow: auto; } + .function-pop>>>.el-popover{ + padding: 6px!important; + } + .pop-title{ + margin: 6px 0 0 0; + font-size: 14px; + font-weight: 500; + } + .pop-info{ + margin: 6px 0 0 0; + font-size: 10px; + } + .dialog-button{ + float: right; + margin-top: 10px; + } diff --git a/frontend/src/views/dataset/data/FieldEdit.vue b/frontend/src/views/dataset/data/FieldEdit.vue index 65d9266e0a..82c0b28d32 100644 --- a/frontend/src/views/dataset/data/FieldEdit.vue +++ b/frontend/src/views/dataset/data/FieldEdit.vue @@ -33,12 +33,12 @@ @@ -50,7 +50,7 @@