feat(数据集): 字段类型抽象转换

This commit is contained in:
junjie
2021-02-25 18:15:10 +08:00
parent b642ba1c78
commit 201cc6f4a6
10 changed files with 190 additions and 21 deletions

View File

@@ -21,5 +21,7 @@ public class DatasetTableField implements Serializable {
private Long lastSyncTime;
private Integer deType;
private static final long serialVersionUID = 1L;
}

View File

@@ -633,6 +633,66 @@ public class DatasetTableFieldExample {
addCriterion("last_sync_time not between", value1, value2, "lastSyncTime");
return (Criteria) this;
}
public Criteria andDeTypeIsNull() {
addCriterion("de_type is null");
return (Criteria) this;
}
public Criteria andDeTypeIsNotNull() {
addCriterion("de_type is not null");
return (Criteria) this;
}
public Criteria andDeTypeEqualTo(Integer value) {
addCriterion("de_type =", value, "deType");
return (Criteria) this;
}
public Criteria andDeTypeNotEqualTo(Integer value) {
addCriterion("de_type <>", value, "deType");
return (Criteria) this;
}
public Criteria andDeTypeGreaterThan(Integer value) {
addCriterion("de_type >", value, "deType");
return (Criteria) this;
}
public Criteria andDeTypeGreaterThanOrEqualTo(Integer value) {
addCriterion("de_type >=", value, "deType");
return (Criteria) this;
}
public Criteria andDeTypeLessThan(Integer value) {
addCriterion("de_type <", value, "deType");
return (Criteria) this;
}
public Criteria andDeTypeLessThanOrEqualTo(Integer value) {
addCriterion("de_type <=", value, "deType");
return (Criteria) this;
}
public Criteria andDeTypeIn(List<Integer> values) {
addCriterion("de_type in", values, "deType");
return (Criteria) this;
}
public Criteria andDeTypeNotIn(List<Integer> values) {
addCriterion("de_type not in", values, "deType");
return (Criteria) this;
}
public Criteria andDeTypeBetween(Integer value1, Integer value2) {
addCriterion("de_type between", value1, value2, "deType");
return (Criteria) this;
}
public Criteria andDeTypeNotBetween(Integer value1, Integer value2) {
addCriterion("de_type not between", value1, value2, "deType");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@@ -10,6 +10,7 @@
<result column="checked" jdbcType="BIT" property="checked" />
<result column="column_index" jdbcType="INTEGER" property="columnIndex" />
<result column="last_sync_time" jdbcType="BIGINT" property="lastSyncTime" />
<result column="de_type" jdbcType="INTEGER" property="deType" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@@ -70,7 +71,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, table_id, origin_name, `name`, `type`, `checked`, column_index, last_sync_time
id, table_id, origin_name, `name`, `type`, `checked`, column_index, last_sync_time,
de_type
</sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.DatasetTableFieldExample" resultMap="BaseResultMap">
select
@@ -105,10 +107,10 @@
<insert id="insert" parameterType="io.dataease.base.domain.DatasetTableField">
insert into dataset_table_field (id, table_id, origin_name,
`name`, `type`, `checked`, column_index,
last_sync_time)
last_sync_time, de_type)
values (#{id,jdbcType=VARCHAR}, #{tableId,jdbcType=VARCHAR}, #{originName,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{checked,jdbcType=BIT}, #{columnIndex,jdbcType=INTEGER},
#{lastSyncTime,jdbcType=BIGINT})
#{lastSyncTime,jdbcType=BIGINT}, #{deType,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.DatasetTableField">
insert into dataset_table_field
@@ -137,6 +139,9 @@
<if test="lastSyncTime != null">
last_sync_time,
</if>
<if test="deType != null">
de_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@@ -163,6 +168,9 @@
<if test="lastSyncTime != null">
#{lastSyncTime,jdbcType=BIGINT},
</if>
<if test="deType != null">
#{deType,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.dataease.base.domain.DatasetTableFieldExample" resultType="java.lang.Long">
@@ -198,6 +206,9 @@
<if test="record.lastSyncTime != null">
last_sync_time = #{record.lastSyncTime,jdbcType=BIGINT},
</if>
<if test="record.deType != null">
de_type = #{record.deType,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@@ -212,7 +223,8 @@
`type` = #{record.type,jdbcType=VARCHAR},
`checked` = #{record.checked,jdbcType=BIT},
column_index = #{record.columnIndex,jdbcType=INTEGER},
last_sync_time = #{record.lastSyncTime,jdbcType=BIGINT}
last_sync_time = #{record.lastSyncTime,jdbcType=BIGINT},
de_type = #{record.deType,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@@ -241,6 +253,9 @@
<if test="lastSyncTime != null">
last_sync_time = #{lastSyncTime,jdbcType=BIGINT},
</if>
<if test="deType != null">
de_type = #{deType,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@@ -252,7 +267,8 @@
`type` = #{type,jdbcType=VARCHAR},
`checked` = #{checked,jdbcType=BIT},
column_index = #{columnIndex,jdbcType=INTEGER},
last_sync_time = #{lastSyncTime,jdbcType=BIGINT}
last_sync_time = #{lastSyncTime,jdbcType=BIGINT},
de_type = #{deType,jdbcType=INTEGER}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@@ -2,9 +2,11 @@ package io.dataease.service.dataset;
import io.dataease.base.domain.DatasetGroup;
import io.dataease.base.domain.DatasetGroupExample;
import io.dataease.base.domain.DatasetTable;
import io.dataease.base.mapper.DatasetGroupMapper;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.request.dataset.DataSetGroupRequest;
import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.dto.dataset.DataSetGroupDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -24,6 +26,8 @@ import java.util.stream.Collectors;
public class DataSetGroupService {
@Resource
private DatasetGroupMapper datasetGroupMapper;
@Resource
private DataSetTableService dataSetTableService;
public DataSetGroupDTO save(DatasetGroup datasetGroup) {
if (StringUtils.isEmpty(datasetGroup.getId())) {
@@ -48,6 +52,21 @@ public class DataSetGroupService {
DatasetGroupExample datasetGroupExample = new DatasetGroupExample();
datasetGroupExample.createCriteria().andIdIn(ids);
datasetGroupMapper.deleteByExample(datasetGroupExample);
// 获取type为scene的id删除场景下的表和字段
deleteTableAndField(tree.stream().filter(ele -> {
return StringUtils.equalsIgnoreCase(ele.getType(), "scene");
}).map(DatasetGroup::getId).collect(Collectors.toList()));
}
public void deleteTableAndField(List<String> sceneIds) {
for (String sceneId : sceneIds) {
DataSetTableRequest dataSetTableRequest = new DataSetTableRequest();
dataSetTableRequest.setSceneId(sceneId);
List<DatasetTable> list = dataSetTableService.list(dataSetTableRequest);
for (DatasetTable table : list) {
dataSetTableService.delete(table.getId());
}
}
}
public List<DataSetGroupDTO> tree(DataSetGroupRequest datasetGroup) {

View File

@@ -19,6 +19,7 @@ import io.dataease.dto.dataset.DataTableInfoDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.*;
@@ -161,6 +162,7 @@ public class DataSetTableService {
}
public void saveTableField(DatasetTable datasetTable) throws Exception {
Datasource ds = datasourceMapper.selectByPrimaryKey(datasetTable.getDataSourceId());
DataSetTableRequest dataSetTableRequest = new DataSetTableRequest();
BeanUtils.copyBean(dataSetTableRequest, datasetTable);
List<TableFiled> fields = getFields(dataSetTableRequest);
@@ -173,6 +175,7 @@ public class DataSetTableService {
datasetTableField.setOriginName(filed.getFieldName());
datasetTableField.setName(filed.getRemarks());
datasetTableField.setType(filed.getFieldType());
datasetTableField.setDeType(transFieldType(ds.getType(), filed.getFieldType()));
datasetTableField.setChecked(true);
datasetTableField.setColumnIndex(i);
datasetTableField.setLastSyncTime(syncTime);
@@ -192,4 +195,47 @@ public class DataSetTableService {
return MessageFormat.format("SELECT {0} FROM {1}", StringUtils.join(fields, ","), table);
}
}
public Integer transFieldType(String type, String field) {
DatasourceTypes datasourceType = DatasourceTypes.valueOf(type);
switch (datasourceType) {
case mysql:
return transMysqlField(field);
case sqlServer:
default:
return 0;
}
}
public Integer transMysqlField(String field) {
switch (field) {
case "CHAR":
case "VARCHAR":
case "TEXT":
case "TINYTEXT":
case "MEDIUMTEXT":
case "LONGTEXT":
case "ENUM":
return 0;// 文本
case "DATE":
case "TIME":
case "YEAR":
case "DATETIME":
case "TIMESTAMP":
return 1;// 时间
case "INT":
case "BIT":
case "TINYINT":
case "SMALLINT":
case "MEDIUMINT":
case "INTEGER":
case "BIGINT":
case "FLOAT":
case "DOUBLE":
case "DECIMAL":
return 2;// 数值
default:
return 0;
}
}
}