feature: support custom table template (#102)

* feat: add table field template field

* feat:update frontend resources
This commit is contained in:
vran
2022-04-17 12:37:10 +08:00
committed by GitHub
parent 89ffd95f8c
commit 6b6a7f4e40
36 changed files with 115 additions and 85 deletions

View File

@@ -33,6 +33,7 @@ dependencies {
implementation 'commons-io:commons-io'
implementation 'com.alibaba:easyexcel'
implementation "org.freemarker:freemarker"
implementation 'com.google.guava:guava:31.1-jre'
implementation "com.squareup.retrofit2:retrofit:${retrofitVersion}"
implementation "com.squareup.retrofit2:converter-jackson:${retrofitVersion}"

View File

@@ -16,6 +16,9 @@ import java.util.List;
@AllArgsConstructor
public class DocumentTemplatePropertiesResponse {
@Builder.Default
private List<DocumentTemplatePropertyResponse> tableFieldNameProperties = Collections.emptyList();
@Builder.Default
private List<DocumentTemplatePropertyResponse> columnFieldNameProperties = Collections.emptyList();

View File

@@ -32,6 +32,7 @@ public class DocumentTemplateService {
.stream()
.collect(Collectors.groupingBy(d -> d.getType()));
return DocumentTemplatePropertiesResponse.builder()
.tableFieldNameProperties(propertiesGroupByType.get(TABLE_FIELD_NAME))
.columnFieldNameProperties(propertiesGroupByType.get(COLUMN_FIELD_NAME))
.foreignKeyFieldNameProperties(propertiesGroupByType.get(FOREIGN_KEY_FIELD_NAME))
.indexFieldNameProperties(propertiesGroupByType.get(INDEX_FIELD_NAME))
@@ -41,6 +42,6 @@ public class DocumentTemplateService {
public void updateByType(DocumentTemplatePropertiesUpdateRequest request) {
List<DocumentTemplatePropertyPojo> pojoList = documentTemplatePropertiesUpdateRequestConverter.toPojo(request);
documentTemplatePropertyDao.batchInsertOnDuplicateKeyUpdate(pojoList);
documentTemplatePropertyDao.batchInsertOnDuplicateKeyUpdateValue(pojoList);
}
}

View File

@@ -71,16 +71,6 @@ public class LoginService {
return new AccessTokenRefreshResponse(accessToken, accessTokenExpireAtMilli);
}
public Optional<LoginKeyResponse> getLoginKey(Integer userId) {
return loginDao.selectByUserId(userId)
.map(loginPojo -> LoginKeyResponse.builder()
.accessToken(loginPojo.getAccessToken())
.accessTokenExpireAt(loginPojo.getAccessTokenExpireAt())
.refreshToken(loginPojo.getRefreshToken())
.refreshTokenExpireAt(loginPojo.getRefreshTokenExpireAt())
.build());
}
public LoginKeyResponse generate(Integer userId) {
UserPojo user = userDao.selectById(userId);
String accessToken = jwtTokens.accessToken(user.getEmail());

View File

@@ -20,10 +20,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@@ -55,16 +52,25 @@ public class SystemStartedEventSubscriber {
}
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) -> {
String key = field.getName();
String def = field.getName();
DocumentTemplatePropertyPojo pojo = new DocumentTemplatePropertyPojo();
pojo.setType(type);
pojo.setKey(key);
pojo.setDefaultValue(def);
pojo.setDefaultValue(fieldChineseMap.get(key));
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;
Field[] columnFields = TableDocumentResponse.ColumnDocumentResponse.class.getDeclaredFields();
List<DocumentTemplatePropertyPojo> columnProperties = Arrays.stream(columnFields)
@@ -94,14 +100,44 @@ public class SystemStartedEventSubscriber {
.collect(Collectors.toList());
List<DocumentTemplatePropertyPojo> properties = new ArrayList<>();
properties.addAll(tableProperties);
properties.addAll(columnProperties);
properties.addAll(indexProperties);
properties.addAll(fkProperties);
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() {
// TODO
}