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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 115 additions and 85 deletions

View File

@ -1 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.787360f3.js"></script><script defer="defer" type="module" src="/js/app.d1a59b80.js"></script><link href="/css/chunk-vendors.8e1003a6.css" rel="stylesheet"><link href="/css/app.15b40a89.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.405c78b5.js" nomodule></script><script defer="defer" src="/js/app-legacy.433198e1.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.787360f3.js"></script><script defer="defer" type="module" src="/js/app.29a225fb.js"></script><link href="/css/chunk-vendors.8e1003a6.css" rel="stylesheet"><link href="/css/app.15b40a89.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.405c78b5.js" nomodule></script><script defer="defer" src="/js/app-legacy.3f95f6dc.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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
}

View File

@ -2,6 +2,6 @@ package com.databasir.dao.enums;
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;
}

View File

@ -25,22 +25,21 @@ public class DocumentTemplatePropertyDao extends BaseDao<DocumentTemplatePropert
super(DOCUMENT_TEMPLATE_PROPERTY, DocumentTemplatePropertyPojo.class);
}
public void batchInsertOnDuplicateIgnore(Collection<DocumentTemplatePropertyPojo> data) {
public void batchInsertOnDuplicateUpdateDefaultValue(Collection<DocumentTemplatePropertyPojo> data) {
if (data == null || data.isEmpty()) {
return;
}
List<InsertReturningStep<DocumentTemplatePropertyRecord>> query = data.stream()
.map(pojo ->
getDslContext()
.insertInto(DOCUMENT_TEMPLATE_PROPERTY)
.set(getDslContext().newRecord(DOCUMENT_TEMPLATE_PROPERTY, pojo))
.onDuplicateKeyIgnore())
.map(pojo -> getDslContext()
.insertInto(DOCUMENT_TEMPLATE_PROPERTY)
.set(getDslContext().newRecord(DOCUMENT_TEMPLATE_PROPERTY, pojo))
.onDuplicateKeyUpdate()
.set(DOCUMENT_TEMPLATE_PROPERTY.DEFAULT_VALUE, pojo.getDefaultValue()))
.collect(Collectors.toList());
getDslContext().batch(query).execute();
}
public void batchInsertOnDuplicateKeyUpdate(Collection<DocumentTemplatePropertyPojo> data) {
public void batchInsertOnDuplicateKeyUpdateValue(Collection<DocumentTemplatePropertyPojo> data) {
if (data == null || data.isEmpty()) {
return;
}