feat: add table field template field
This commit is contained in:
parent
89ffd95f8c
commit
11202b57c9
|
@ -33,6 +33,7 @@ dependencies {
|
||||||
implementation 'commons-io:commons-io'
|
implementation 'commons-io:commons-io'
|
||||||
implementation 'com.alibaba:easyexcel'
|
implementation 'com.alibaba:easyexcel'
|
||||||
implementation "org.freemarker:freemarker"
|
implementation "org.freemarker:freemarker"
|
||||||
|
implementation 'com.google.guava:guava:31.1-jre'
|
||||||
|
|
||||||
implementation "com.squareup.retrofit2:retrofit:${retrofitVersion}"
|
implementation "com.squareup.retrofit2:retrofit:${retrofitVersion}"
|
||||||
implementation "com.squareup.retrofit2:converter-jackson:${retrofitVersion}"
|
implementation "com.squareup.retrofit2:converter-jackson:${retrofitVersion}"
|
||||||
|
|
|
@ -16,6 +16,9 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class DocumentTemplatePropertiesResponse {
|
public class DocumentTemplatePropertiesResponse {
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private List<DocumentTemplatePropertyResponse> tableFieldNameProperties = Collections.emptyList();
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private List<DocumentTemplatePropertyResponse> columnFieldNameProperties = Collections.emptyList();
|
private List<DocumentTemplatePropertyResponse> columnFieldNameProperties = Collections.emptyList();
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class DocumentTemplateService {
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(d -> d.getType()));
|
.collect(Collectors.groupingBy(d -> d.getType()));
|
||||||
return DocumentTemplatePropertiesResponse.builder()
|
return DocumentTemplatePropertiesResponse.builder()
|
||||||
|
.tableFieldNameProperties(propertiesGroupByType.get(TABLE_FIELD_NAME))
|
||||||
.columnFieldNameProperties(propertiesGroupByType.get(COLUMN_FIELD_NAME))
|
.columnFieldNameProperties(propertiesGroupByType.get(COLUMN_FIELD_NAME))
|
||||||
.foreignKeyFieldNameProperties(propertiesGroupByType.get(FOREIGN_KEY_FIELD_NAME))
|
.foreignKeyFieldNameProperties(propertiesGroupByType.get(FOREIGN_KEY_FIELD_NAME))
|
||||||
.indexFieldNameProperties(propertiesGroupByType.get(INDEX_FIELD_NAME))
|
.indexFieldNameProperties(propertiesGroupByType.get(INDEX_FIELD_NAME))
|
||||||
|
@ -41,6 +42,6 @@ public class DocumentTemplateService {
|
||||||
|
|
||||||
public void updateByType(DocumentTemplatePropertiesUpdateRequest request) {
|
public void updateByType(DocumentTemplatePropertiesUpdateRequest request) {
|
||||||
List<DocumentTemplatePropertyPojo> pojoList = documentTemplatePropertiesUpdateRequestConverter.toPojo(request);
|
List<DocumentTemplatePropertyPojo> pojoList = documentTemplatePropertiesUpdateRequestConverter.toPojo(request);
|
||||||
documentTemplatePropertyDao.batchInsertOnDuplicateKeyUpdate(pojoList);
|
documentTemplatePropertyDao.batchInsertOnDuplicateKeyUpdateValue(pojoList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -55,16 +52,25 @@ public class SystemStartedEventSubscriber {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTemplatePropertiesIfNecessary() {
|
private void initTemplatePropertiesIfNecessary() {
|
||||||
List<String> ignoreFields = List.of("createAt", "discussionCount", "id");
|
List<String> ignoreFields = List.of("createAt", "discussionCount", "id",
|
||||||
|
"columns", "indexes", "triggers", "foreignKeys");
|
||||||
|
Map<String, String> fieldChineseMap = fieldChineseMap();
|
||||||
BiFunction<Field, DocumentTemplatePropertyType, DocumentTemplatePropertyPojo> mapping = (field, type) -> {
|
BiFunction<Field, DocumentTemplatePropertyType, DocumentTemplatePropertyPojo> mapping = (field, type) -> {
|
||||||
String key = field.getName();
|
String key = field.getName();
|
||||||
String def = field.getName();
|
String def = field.getName();
|
||||||
DocumentTemplatePropertyPojo pojo = new DocumentTemplatePropertyPojo();
|
DocumentTemplatePropertyPojo pojo = new DocumentTemplatePropertyPojo();
|
||||||
pojo.setType(type);
|
pojo.setType(type);
|
||||||
pojo.setKey(key);
|
pojo.setKey(key);
|
||||||
pojo.setDefaultValue(def);
|
pojo.setDefaultValue(fieldChineseMap.get(key));
|
||||||
return pojo;
|
return pojo;
|
||||||
};
|
};
|
||||||
|
// table field name;
|
||||||
|
Field[] fields = TableDocumentResponse.class.getDeclaredFields();
|
||||||
|
List<DocumentTemplatePropertyPojo> tableProperties = Arrays.stream(fields)
|
||||||
|
.filter(field -> !ignoreFields.contains(field.getName()))
|
||||||
|
.map(field -> mapping.apply(field, DocumentTemplatePropertyType.TABLE_FIELD_NAME))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// column field name;
|
// column field name;
|
||||||
Field[] columnFields = TableDocumentResponse.ColumnDocumentResponse.class.getDeclaredFields();
|
Field[] columnFields = TableDocumentResponse.ColumnDocumentResponse.class.getDeclaredFields();
|
||||||
List<DocumentTemplatePropertyPojo> columnProperties = Arrays.stream(columnFields)
|
List<DocumentTemplatePropertyPojo> columnProperties = Arrays.stream(columnFields)
|
||||||
|
@ -94,14 +100,44 @@ public class SystemStartedEventSubscriber {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<DocumentTemplatePropertyPojo> properties = new ArrayList<>();
|
List<DocumentTemplatePropertyPojo> properties = new ArrayList<>();
|
||||||
|
properties.addAll(tableProperties);
|
||||||
properties.addAll(columnProperties);
|
properties.addAll(columnProperties);
|
||||||
properties.addAll(indexProperties);
|
properties.addAll(indexProperties);
|
||||||
properties.addAll(fkProperties);
|
properties.addAll(fkProperties);
|
||||||
properties.addAll(triggerProperties);
|
properties.addAll(triggerProperties);
|
||||||
documentTemplatePropertyDao.batchInsertOnDuplicateIgnore(properties);
|
documentTemplatePropertyDao.batchInsertOnDuplicateUpdateDefaultValue(properties);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, String> fieldChineseMap() {
|
||||||
|
Map<String, String> map = new HashMap<>(32);
|
||||||
|
map.put("name", "名称");
|
||||||
|
map.put("type", "类型");
|
||||||
|
map.put("comment", "注释");
|
||||||
|
map.put("description", "描述");
|
||||||
|
map.put("size", "长度");
|
||||||
|
map.put("decimalDigits", "浮点精度");
|
||||||
|
map.put("isPrimaryKey", "主键");
|
||||||
|
map.put("nullable", "可空");
|
||||||
|
map.put("autoIncrement", "自增");
|
||||||
|
map.put("defaultValue", "默认值");
|
||||||
|
map.put("isUnique", "唯一");
|
||||||
|
map.put("columnNames", "列名");
|
||||||
|
map.put("fkName", "外键名");
|
||||||
|
map.put("fkTableName", "外键表名");
|
||||||
|
map.put("fkColumnName", "外键列名");
|
||||||
|
map.put("pkName", "主键名");
|
||||||
|
map.put("pkTableName", "主键表名");
|
||||||
|
map.put("pkColumnName", "主键列名");
|
||||||
|
map.put("updateRule", "更新规则");
|
||||||
|
map.put("deleteRule", "删除规则");
|
||||||
|
map.put("timing", "触发时机");
|
||||||
|
map.put("manipulation", "触发器");
|
||||||
|
map.put("statement", "表达式");
|
||||||
|
map.put("triggerCreateAt", "创建时间");
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
private void initDatabaseTypesIfNecessary() {
|
private void initDatabaseTypesIfNecessary() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,6 @@ package com.databasir.dao.enums;
|
||||||
|
|
||||||
public enum DocumentTemplatePropertyType {
|
public enum DocumentTemplatePropertyType {
|
||||||
|
|
||||||
INDEX_FIELD_NAME, COLUMN_FIELD_NAME, TRIGGER_FIELD_NAME, FOREIGN_KEY_FIELD_NAME;
|
TABLE_FIELD_NAME, INDEX_FIELD_NAME, COLUMN_FIELD_NAME, TRIGGER_FIELD_NAME, FOREIGN_KEY_FIELD_NAME;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,22 +25,21 @@ public class DocumentTemplatePropertyDao extends BaseDao<DocumentTemplatePropert
|
||||||
super(DOCUMENT_TEMPLATE_PROPERTY, DocumentTemplatePropertyPojo.class);
|
super(DOCUMENT_TEMPLATE_PROPERTY, DocumentTemplatePropertyPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchInsertOnDuplicateIgnore(Collection<DocumentTemplatePropertyPojo> data) {
|
public void batchInsertOnDuplicateUpdateDefaultValue(Collection<DocumentTemplatePropertyPojo> data) {
|
||||||
if (data == null || data.isEmpty()) {
|
if (data == null || data.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<InsertReturningStep<DocumentTemplatePropertyRecord>> query = data.stream()
|
List<InsertReturningStep<DocumentTemplatePropertyRecord>> query = data.stream()
|
||||||
.map(pojo ->
|
.map(pojo -> getDslContext()
|
||||||
|
.insertInto(DOCUMENT_TEMPLATE_PROPERTY)
|
||||||
getDslContext()
|
.set(getDslContext().newRecord(DOCUMENT_TEMPLATE_PROPERTY, pojo))
|
||||||
.insertInto(DOCUMENT_TEMPLATE_PROPERTY)
|
.onDuplicateKeyUpdate()
|
||||||
.set(getDslContext().newRecord(DOCUMENT_TEMPLATE_PROPERTY, pojo))
|
.set(DOCUMENT_TEMPLATE_PROPERTY.DEFAULT_VALUE, pojo.getDefaultValue()))
|
||||||
.onDuplicateKeyIgnore())
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
getDslContext().batch(query).execute();
|
getDslContext().batch(query).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchInsertOnDuplicateKeyUpdate(Collection<DocumentTemplatePropertyPojo> data) {
|
public void batchInsertOnDuplicateKeyUpdateValue(Collection<DocumentTemplatePropertyPojo> data) {
|
||||||
if (data == null || data.isEmpty()) {
|
if (data == null || data.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue