Commit 68449eaa by yuwei

项目初始化

parent ec4dd780
...@@ -39,6 +39,8 @@ public class ModelColumnDto implements Serializable { ...@@ -39,6 +39,8 @@ public class ModelColumnDto implements Serializable {
private String columnLength; private String columnLength;
@ApiModelProperty(value = "列小数位数") @ApiModelProperty(value = "列小数位数")
private String columnScale; private String columnScale;
@ApiModelProperty(value = "列默认值")
private String defaultValue;
@ApiModelProperty(value = "是否主键(0否,1是)") @ApiModelProperty(value = "是否主键(0否,1是)")
private String isPk; private String isPk;
@ApiModelProperty(value = "是否必填(0否,1是)") @ApiModelProperty(value = "是否必填(0否,1是)")
......
package cn.datax.service.data.masterdata.api.entity; package cn.datax.service.data.masterdata.api.entity;
import cn.datax.service.data.masterdata.api.enums.OracleDataTypeEnum;
import cn.datax.service.data.masterdata.api.parser.ColumnParser;
import cn.datax.service.data.masterdata.api.parser.DataType;
import cn.datax.service.data.masterdata.api.parser.oracle.OracleColumnParser;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import cn.datax.common.base.BaseEntity; import cn.datax.common.base.BaseEntity;
import lombok.Data; import lombok.Data;
...@@ -53,6 +58,11 @@ public class ModelColumnEntity extends BaseEntity { ...@@ -53,6 +58,11 @@ public class ModelColumnEntity extends BaseEntity {
private String columnScale; private String columnScale;
/** /**
* 列默认值
*/
private String defaultValue;
/**
* 是否主键(0否,1是) * 是否主键(0否,1是)
*/ */
private String isPk; private String isPk;
...@@ -111,4 +121,16 @@ public class ModelColumnEntity extends BaseEntity { ...@@ -111,4 +121,16 @@ public class ModelColumnEntity extends BaseEntity {
* 排序 * 排序
*/ */
private Integer sort; private Integer sort;
/**
* 列属性
*/
@TableField(exist = false)
private String columnDefinition;
public String getColumnDefinition() throws Exception {
ColumnParser columnParser = new OracleColumnParser();
DataType parse = columnParser.parse(OracleDataTypeEnum.match(this.columnType, OracleDataTypeEnum.CHAR));
return parse.fillTypeString(this.columnLength, this.columnScale);
}
} }
package cn.datax.service.data.masterdata.api.entity;
import lombok.Data;
import java.io.Serializable;
@Data
public class ModelCommentEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String tableName;
private String columnName;
private String comment;
}
package cn.datax.service.data.masterdata.api.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
@Data
public class ModelDataEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String tableName;
private Map<String, Object> datas;
}
...@@ -20,7 +20,7 @@ import java.util.List; ...@@ -20,7 +20,7 @@ import java.util.List;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Accessors(chain = true) @Accessors(chain = true)
@TableName("masterdata_model") @TableName(value = "masterdata_model", resultMap = "BaseResultMap")
public class ModelEntity extends DataScopeBaseEntity { public class ModelEntity extends DataScopeBaseEntity {
private static final long serialVersionUID=1L; private static final long serialVersionUID=1L;
......
package cn.datax.service.data.masterdata.api.enums;
public enum OracleDataTypeEnum {
CHAR("char", "字符串"), NUMBER("number", "数值"), DATE("date", "日期"), CLOB("clob", "大文本"), BLOB("blob", "二进制");
private String value;
private String title;
OracleDataTypeEnum(String value, String title) {
this.value = value;
this.title = title;
}
public String getValue() {
return value;
}
public String getTitle() {
return title;
}
public static OracleDataTypeEnum match(String value, OracleDataTypeEnum defaultItem) {
if (value != null) {
for (OracleDataTypeEnum item: OracleDataTypeEnum.values()) {
if (item.getValue().equals(value)) {
return item;
}
}
}
return defaultItem;
}
}
package cn.datax.service.data.masterdata.api.parser;
import cn.datax.service.data.masterdata.api.enums.OracleDataTypeEnum;
public interface ColumnParser {
DataType parse(OracleDataTypeEnum dataTypeEnum) throws Exception;
}
package cn.datax.service.data.masterdata.api.parser;
public interface DataType {
String fillTypeString(String columnLength, String columnScale);
}
package cn.datax.service.data.masterdata.api.parser.oracle;
import cn.datax.service.data.masterdata.api.parser.DataType;
public class OracleBlobDataType implements DataType {
@Override
public String fillTypeString(String columnLength, String columnScale) {
return "BLOB";
}
}
package cn.datax.service.data.masterdata.api.parser.oracle;
import cn.datax.service.data.masterdata.api.parser.DataType;
import java.util.Optional;
public class OracleCharDataType implements DataType {
@Override
public String fillTypeString(String columnLength, String columnScale) {
return "VARCHAR2(" + Optional.ofNullable(columnLength).orElse("255") + ")";
}
}
package cn.datax.service.data.masterdata.api.parser.oracle;
import cn.datax.service.data.masterdata.api.parser.DataType;
public class OracleClobDataType implements DataType {
@Override
public String fillTypeString(String columnLength, String columnScale) {
return "CLOB";
}
}
package cn.datax.service.data.masterdata.api.parser.oracle;
import cn.datax.common.exception.DataException;
import cn.datax.service.data.masterdata.api.enums.OracleDataTypeEnum;
import cn.datax.service.data.masterdata.api.parser.ColumnParser;
import cn.datax.service.data.masterdata.api.parser.DataType;
public class OracleColumnParser implements ColumnParser {
@Override
public DataType parse(OracleDataTypeEnum dataTypeEnum) throws Exception {
switch(dataTypeEnum) {
case CHAR:
return new OracleCharDataType();
case DATE:
return new OracleDateDataType();
case NUMBER:
return new OracleNumberDataType();
case CLOB:
return new OracleClobDataType();
case BLOB:
return new OracleBlobDataType();
}
throw new DataException("字段数据类型错误");
}
}
package cn.datax.service.data.masterdata.api.parser.oracle;
import cn.datax.service.data.masterdata.api.parser.DataType;
public class OracleDateDataType implements DataType {
@Override
public String fillTypeString(String columnLength, String columnScale) {
return "DATE";
}
}
package cn.datax.service.data.masterdata.api.parser.oracle;
import cn.datax.service.data.masterdata.api.parser.DataType;
import java.util.Optional;
public class OracleNumberDataType implements DataType {
@Override
public String fillTypeString(String columnLength, String columnScale) {
return "NUMBER(" + Optional.ofNullable(columnLength).orElse("22") + ", " + Optional.ofNullable(columnScale).orElse("0") + ")";
}
}
...@@ -29,6 +29,7 @@ public class ModelColumnVo implements Serializable { ...@@ -29,6 +29,7 @@ public class ModelColumnVo implements Serializable {
private String columnType; private String columnType;
private String columnLength; private String columnLength;
private String columnScale; private String columnScale;
private String defaultValue;
private String isPk; private String isPk;
private String isRequired; private String isRequired;
private String isInsert; private String isInsert;
......
package cn.datax.service.data.masterdata.dao;
import cn.datax.service.data.masterdata.api.entity.ModelCommentEntity;
import cn.datax.service.data.masterdata.api.entity.ModelDataEntity;
import cn.datax.service.data.masterdata.api.entity.ModelEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface OracleDynamicDao {
void createTable(ModelEntity modelEntity);
void commentTable(ModelCommentEntity modelCommentEntity);
void commentColumn(ModelCommentEntity modelCommentEntity);
void dropTable(@Param("tableName") String tableName);
void insertData(ModelDataEntity modelDataEntity);
void updateData(ModelDataEntity modelDataEntity);
void deleteData(ModelDataEntity modelDataEntity);
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<result column="column_type" property="columnType" /> <result column="column_type" property="columnType" />
<result column="column_length" property="columnLength" /> <result column="column_length" property="columnLength" />
<result column="column_scale" property="columnScale" /> <result column="column_scale" property="columnScale" />
<result column="default_value" property="defaultValue" />
<result column="is_pk" property="isPk" /> <result column="is_pk" property="isPk" />
<result column="is_required" property="isRequired" /> <result column="is_required" property="isRequired" />
<result column="is_insert" property="isInsert" /> <result column="is_insert" property="isInsert" />
...@@ -40,7 +41,7 @@ ...@@ -40,7 +41,7 @@
update_by, update_by,
update_time, update_time,
remark, remark,
model_id, column_name, column_comment, column_type, column_length, column_scale, is_pk, is_required, is_insert, is_edit, is_list, is_query, query_type, is_bind_dict, bind_dict_type_id, bind_dict_column, html_type, sort model_id, column_name, column_comment, column_type, column_length, column_scale, default_value, is_pk, is_required, is_insert, is_edit, is_list, is_query, query_type, is_bind_dict, bind_dict_type_id, bind_dict_column, html_type, sort
</sql> </sql>
</mapper> </mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.datax.service.data.masterdata.dao.OracleDynamicDao">
<insert id="createTable" parameterType="cn.datax.service.data.masterdata.api.entity.ModelEntity">
CREATE TABLE ${modelLogicTable} (
ID VARCHAR2(20) NOT NULL PRIMARY KEY,
STATUS NUMBER(1, 0) DEFAULT '1' NOT NULL,
CREATE_BY VARCHAR2(20),
CREATE_TIME DATE,
CREATE_DEPT VARCHAR2(20),
UPDATE_BY VARCHAR2(20),
UPDATE_TIME DATE,
REMARK VARCHAR2(2000),
<foreach collection="modelColumns" item="column" separator=",">
${column.columnName} ${column.columnDefinition}
<if test="column.defaultValue != null and column.defaultValue != ''">
DEFAULT #{column.defaultValue}
</if>
<if test="column.isRequired != null and column.isRequired == '1'.toString()">
NOT NULL
</if>
<if test="column.isPk != null and column.isPk == '1'.toString()">
PRIMARY KEY
</if>
</foreach>
)
</insert>
<!-- 表注释 -->
<update id="commentTable" parameterType="cn.datax.service.data.masterdata.api.entity.ModelCommentEntity">
COMMENT ON TABLE ${tableName} IS #{comment}
</update>
<!-- 字段注释 -->
<update id="commentColumn" parameterType="cn.datax.service.data.masterdata.api.entity.ModelCommentEntity">
COMMENT ON COLUMN ${tableName}.${columnName} IS #{comment}
</update>
<!-- 验证表是否存在 -->
<update id="dropTable" parameterType="java.lang.String">
DROP TABLE IF EXISTS ${tableName}
</update>
<!-- 插入数据 -->
<insert id="insertData" parameterType="cn.datax.service.data.masterdata.api.entity.ModelDataEntity">
INSERT INTO ${tableName}
<foreach collection="datas.keys" item="key" open="(" close=")" separator=",">
${key}
</foreach>
VALUES
<foreach collection="datas.values" item="value" open="(" close=")" separator=",">
#{value}
</foreach>
</insert>
<!-- 更新数据 -->
<update id="updateData" parameterType="cn.datax.service.data.masterdata.api.entity.ModelDataEntity">
UPDATE ${tableName} SET
<foreach collection="datas.keys" index="key" item="value" separator=",">
${key} = #{value}
</foreach>
WHERE ID = #{datas[ID]}
</update>
<!-- 删除数据 -->
<delete id="deleteData" parameterType="cn.datax.service.data.masterdata.api.entity.ModelDataEntity">
DELETE FROM ${tableName} WHERE ID = #{datas[ID]}
</delete>
</mapper>
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="字段信息" name="second"> <el-tab-pane label="字段属性" name="second">
<el-button @click="addRow">添加</el-button> <el-button @click="addRow">添加</el-button>
<el-form ref="table" :model="form" :rules="rules" size="mini"> <el-form ref="table" :model="form" :rules="rules" size="mini">
<el-table :data="form.modelColumns" border style="width: 100%; margin: 15px 0;"> <el-table :data="form.modelColumns" border style="width: 100%; margin: 15px 0;">
...@@ -53,7 +53,14 @@ ...@@ -53,7 +53,14 @@
<el-table-column label="列类型"> <el-table-column label="列类型">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'modelColumns.' + scope.$index + '.columnType'" :rules="rules.columnType"> <el-form-item :prop="'modelColumns.' + scope.$index + '.columnType'" :rules="rules.columnType">
<el-input v-model="scope.row.columnType" clearable placeholder="请输入列类型" /> <el-select v-model="scope.row.columnType" clearable placeholder="请选择">
<el-option
v-for="item in columnTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
...@@ -71,6 +78,13 @@ ...@@ -71,6 +78,13 @@
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="默认值">
<template slot-scope="scope">
<el-form-item :prop="'modelColumns.' + scope.$index + '.defaultValue'">
<el-input v-model="scope.row.defaultValue" clearable placeholder="请输入默认值" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="主键" align="center" width="55"> <el-table-column label="主键" align="center" width="55">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'modelColumns.' + scope.$index + '.isPk'"> <el-form-item :prop="'modelColumns.' + scope.$index + '.isPk'">
...@@ -153,6 +167,10 @@ ...@@ -153,6 +167,10 @@
</el-table> </el-table>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="唯一约束" name="fourth">唯一约束</el-tab-pane>
<el-tab-pane label="条件约束" name="fifth">条件约束</el-tab-pane>
<el-tab-pane label="外键约束" name="sixth">外键约束</el-tab-pane>
<el-tab-pane label="索引" name="seventh">索引</el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
</el-card> </el-card>
...@@ -208,7 +226,7 @@ export default { ...@@ -208,7 +226,7 @@ export default {
{ required: true, message: '列描述不能为空', trigger: 'blur' } { required: true, message: '列描述不能为空', trigger: 'blur' }
], ],
columnType: [ columnType: [
{ required: true, message: '列类型不能为空', trigger: 'blur' } { required: true, message: '列类型不能为空', trigger: 'change' }
], ],
htmlType: [ htmlType: [
{ required: true, message: '显示类型不能为空', trigger: 'change' } { required: true, message: '显示类型不能为空', trigger: 'change' }
...@@ -217,6 +235,8 @@ export default { ...@@ -217,6 +235,8 @@ export default {
// 状态数据字典 // 状态数据字典
statusOptions: [], statusOptions: [],
activeName: 'first', activeName: 'first',
// 列类型数据字典
columnTypeOptions: [],
// 查询方式数据字典 // 查询方式数据字典
queryTypeOptions: [], queryTypeOptions: [],
// 显示类型数据字典 // 显示类型数据字典
...@@ -229,6 +249,11 @@ export default { ...@@ -229,6 +249,11 @@ export default {
this.statusOptions = response.data this.statusOptions = response.data
} }
}) })
this.getDicts('data_type_oracle').then(response => {
if (response.success) {
this.columnTypeOptions = response.data
}
})
this.getDicts('data_query_type').then(response => { this.getDicts('data_query_type').then(response => {
if (response.success) { if (response.success) {
this.queryTypeOptions = response.data this.queryTypeOptions = response.data
...@@ -248,9 +273,10 @@ export default { ...@@ -248,9 +273,10 @@ export default {
const item = { const item = {
columnName: '', columnName: '',
columnComment: '', columnComment: '',
columnType: '', columnType: 'char',
columnLength: '255', columnLength: '255',
columnScale: '0', columnScale: '0',
defaultValue: '',
isPk: '0', isPk: '0',
isRequired: '0', isRequired: '0',
isInsert: '0', isInsert: '0',
......
...@@ -51,7 +51,14 @@ ...@@ -51,7 +51,14 @@
<el-table-column label="列类型"> <el-table-column label="列类型">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item> <el-form-item>
<el-input v-model="scope.row.columnType" clearable placeholder="请输入列类型" /> <el-select v-model="scope.row.columnType" clearable placeholder="请选择">
<el-option
v-for="item in columnTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
...@@ -69,6 +76,13 @@ ...@@ -69,6 +76,13 @@
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="默认值">
<template slot-scope="scope">
<el-form-item>
<el-input v-model="scope.row.defaultValue" clearable placeholder="请输入默认值" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="主键" align="center" width="55"> <el-table-column label="主键" align="center" width="55">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item> <el-form-item>
...@@ -176,6 +190,7 @@ export default { ...@@ -176,6 +190,7 @@ export default {
// 状态数据字典 // 状态数据字典
statusOptions: [], statusOptions: [],
activeName: 'first', activeName: 'first',
columnTypeOptions: [],
queryTypeOptions: [], queryTypeOptions: [],
htmlTypeOptions: [] htmlTypeOptions: []
} }
...@@ -187,6 +202,11 @@ export default { ...@@ -187,6 +202,11 @@ export default {
this.statusOptions = response.data this.statusOptions = response.data
} }
}) })
this.getDicts('data_type_oracle').then(response => {
if (response.success) {
this.columnTypeOptions = response.data
}
})
this.getDicts('data_query_type').then(response => { this.getDicts('data_query_type').then(response => {
if (response.success) { if (response.success) {
this.queryTypeOptions = response.data this.queryTypeOptions = response.data
......
...@@ -53,7 +53,14 @@ ...@@ -53,7 +53,14 @@
<el-table-column label="列类型"> <el-table-column label="列类型">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'modelColumns.' + scope.$index + '.columnType'" :rules="rules.columnType"> <el-form-item :prop="'modelColumns.' + scope.$index + '.columnType'" :rules="rules.columnType">
<el-input v-model="scope.row.columnType" clearable placeholder="请输入列类型" /> <el-select v-model="scope.row.columnType" clearable placeholder="请选择">
<el-option
v-for="item in columnTypeOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
...@@ -71,6 +78,13 @@ ...@@ -71,6 +78,13 @@
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="默认值">
<template slot-scope="scope">
<el-form-item :prop="'modelColumns.' + scope.$index + '.defaultValue'">
<el-input v-model="scope.row.defaultValue" clearable placeholder="请输入默认值" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="主键" align="center" width="55"> <el-table-column label="主键" align="center" width="55">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'modelColumns.' + scope.$index + '.isPk'"> <el-form-item :prop="'modelColumns.' + scope.$index + '.isPk'">
...@@ -205,7 +219,7 @@ export default { ...@@ -205,7 +219,7 @@ export default {
{ required: true, message: '列描述不能为空', trigger: 'blur' } { required: true, message: '列描述不能为空', trigger: 'blur' }
], ],
columnType: [ columnType: [
{ required: true, message: '列类型不能为空', trigger: 'blur' } { required: true, message: '列类型不能为空', trigger: 'change' }
], ],
htmlType: [ htmlType: [
{ required: true, message: '显示类型不能为空', trigger: 'change' } { required: true, message: '显示类型不能为空', trigger: 'change' }
...@@ -214,6 +228,7 @@ export default { ...@@ -214,6 +228,7 @@ export default {
// 状态数据字典 // 状态数据字典
statusOptions: [], statusOptions: [],
activeName: 'first', activeName: 'first',
columnTypeOptions: [],
queryTypeOptions: [], queryTypeOptions: [],
htmlTypeOptions: [] htmlTypeOptions: []
} }
...@@ -225,6 +240,11 @@ export default { ...@@ -225,6 +240,11 @@ export default {
this.statusOptions = response.data this.statusOptions = response.data
} }
}) })
this.getDicts('data_type_oracle').then(response => {
if (response.success) {
this.columnTypeOptions = response.data
}
})
this.getDicts('data_query_type').then(response => { this.getDicts('data_query_type').then(response => {
if (response.success) { if (response.success) {
this.queryTypeOptions = response.data this.queryTypeOptions = response.data
...@@ -255,9 +275,10 @@ export default { ...@@ -255,9 +275,10 @@ export default {
const item = { const item = {
columnName: '', columnName: '',
columnComment: '', columnComment: '',
columnType: '', columnType: 'char',
columnLength: '255', columnLength: '255',
columnScale: '0', columnScale: '0',
defaultValue: '',
isPk: '0', isPk: '0',
isRequired: '0', isRequired: '0',
isInsert: '0', isInsert: '0',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment