feat: add template property api
This commit is contained in:
parent
2939359486
commit
effa449228
|
@ -0,0 +1,36 @@
|
||||||
|
package com.databasir.api;
|
||||||
|
|
||||||
|
import com.databasir.common.JsonData;
|
||||||
|
import com.databasir.core.domain.document.data.DocumentTemplatePropertiesResponse;
|
||||||
|
import com.databasir.core.domain.document.data.DocumentTemplatePropertiesUpdateRequest;
|
||||||
|
import com.databasir.core.domain.document.service.DocumentTemplateService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Validated
|
||||||
|
@RestController
|
||||||
|
public class DocumentTemplateController {
|
||||||
|
|
||||||
|
private final DocumentTemplateService documentTemplateService;
|
||||||
|
|
||||||
|
@GetMapping(Routes.DocumentTemplateProperty.API)
|
||||||
|
public JsonData<DocumentTemplatePropertiesResponse> getAllProperties() {
|
||||||
|
return JsonData.ok(documentTemplateService.getAllProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping(Routes.DocumentTemplateProperty.API)
|
||||||
|
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||||
|
public JsonData<Void> updateByType(@RequestBody @Valid DocumentTemplatePropertiesUpdateRequest request) {
|
||||||
|
documentTemplateService.updateByType(request);
|
||||||
|
return JsonData.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -105,6 +105,10 @@ public interface Routes {
|
||||||
String SAVE = DISCUSSION_BASE;
|
String SAVE = DISCUSSION_BASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DocumentTemplateProperty {
|
||||||
|
String API = BASE + "/document_template/properties";
|
||||||
|
}
|
||||||
|
|
||||||
interface Setting {
|
interface Setting {
|
||||||
|
|
||||||
String GET_SYS_EMAIL = BASE + "/settings/sys_email";
|
String GET_SYS_EMAIL = BASE + "/settings/sys_email";
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.databasir.core.domain.document.converter;
|
||||||
|
|
||||||
|
import com.databasir.core.domain.document.data.DocumentTemplatePropertiesUpdateRequest;
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
|
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface DocumentTemplatePropertiesUpdateRequestConverter {
|
||||||
|
|
||||||
|
@Mapping(target = "defaultValue", constant = "")
|
||||||
|
DocumentTemplatePropertyPojo toPojo(DocumentTemplatePropertiesUpdateRequest.PropertyRequest property,
|
||||||
|
DocumentTemplatePropertyType type);
|
||||||
|
|
||||||
|
default List<DocumentTemplatePropertyPojo> toPojo(DocumentTemplatePropertiesUpdateRequest request) {
|
||||||
|
return request.getProperties().stream()
|
||||||
|
.map(prop -> toPojo(prop, request.getType()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.databasir.core.domain.document.converter;
|
||||||
|
|
||||||
|
import com.databasir.core.domain.document.data.DocumentTemplatePropertiesResponse;
|
||||||
|
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface DocumentTemplatePropertyResponseConverter {
|
||||||
|
|
||||||
|
List<DocumentTemplatePropertiesResponse.DocumentTemplatePropertyResponse> of(
|
||||||
|
List<DocumentTemplatePropertyPojo> pojoList);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.databasir.core.domain.document.data;
|
||||||
|
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DocumentTemplatePropertiesResponse {
|
||||||
|
|
||||||
|
private List<DocumentTemplatePropertyResponse> columnFieldNameProperties = Collections.emptyList();
|
||||||
|
|
||||||
|
private List<DocumentTemplatePropertyResponse> indexFieldNameProperties = Collections.emptyList();
|
||||||
|
|
||||||
|
private List<DocumentTemplatePropertyResponse> triggerFieldNameProperties = Collections.emptyList();
|
||||||
|
|
||||||
|
private List<DocumentTemplatePropertyResponse> foreignKeyFieldNameProperties = Collections.emptyList();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class DocumentTemplatePropertyResponse {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
private DocumentTemplatePropertyType type;
|
||||||
|
|
||||||
|
private LocalDateTime createAt;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.databasir.core.domain.document.data;
|
||||||
|
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DocumentTemplatePropertiesUpdateRequest {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private DocumentTemplatePropertyType type;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
private List<PropertyRequest> properties = Collections.emptyList();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class PropertyRequest {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.databasir.core.domain.document.service;
|
||||||
|
|
||||||
|
import com.databasir.core.domain.document.converter.DocumentTemplatePropertiesUpdateRequestConverter;
|
||||||
|
import com.databasir.core.domain.document.converter.DocumentTemplatePropertyResponseConverter;
|
||||||
|
import com.databasir.core.domain.document.data.DocumentTemplatePropertiesResponse;
|
||||||
|
import com.databasir.core.domain.document.data.DocumentTemplatePropertiesUpdateRequest;
|
||||||
|
import com.databasir.dao.impl.DocumentTemplatePropertyDao;
|
||||||
|
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.databasir.dao.enums.DocumentTemplatePropertyType.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class DocumentTemplateService {
|
||||||
|
|
||||||
|
private final DocumentTemplatePropertyDao documentTemplatePropertyDao;
|
||||||
|
|
||||||
|
private final DocumentTemplatePropertyResponseConverter documentTemplatePropertyResponseConverter;
|
||||||
|
|
||||||
|
private final DocumentTemplatePropertiesUpdateRequestConverter documentTemplatePropertiesUpdateRequestConverter;
|
||||||
|
|
||||||
|
public DocumentTemplatePropertiesResponse getAllProperties() {
|
||||||
|
List<DocumentTemplatePropertyPojo> properties = documentTemplatePropertyDao.selectAll();
|
||||||
|
var propertiesGroupByType = documentTemplatePropertyResponseConverter.of(properties)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(d -> d.getType()));
|
||||||
|
return DocumentTemplatePropertiesResponse.builder()
|
||||||
|
.columnFieldNameProperties(propertiesGroupByType.get(COLUMN_FIELD_NAME))
|
||||||
|
.foreignKeyFieldNameProperties(propertiesGroupByType.get(FOREIGN_KEY_FIELD_NAME))
|
||||||
|
.indexFieldNameProperties(propertiesGroupByType.get(INDEX_FIELD_NAME))
|
||||||
|
.triggerFieldNameProperties(propertiesGroupByType.get(TRIGGER_FIELD_NAME))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateByType(DocumentTemplatePropertiesUpdateRequest request) {
|
||||||
|
List<DocumentTemplatePropertyPojo> pojoList = documentTemplatePropertiesUpdateRequestConverter.toPojo(request);
|
||||||
|
documentTemplatePropertyDao.batchInsertOnDuplicateKeyUpdate(pojoList);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,72 +1,22 @@
|
||||||
package com.databasir.core.domain.system.service;
|
package com.databasir.core.domain.system.service;
|
||||||
|
|
||||||
import com.databasir.common.codec.Aes;
|
|
||||||
import com.databasir.common.codec.Rsa;
|
|
||||||
import com.databasir.core.domain.DomainErrors;
|
import com.databasir.core.domain.DomainErrors;
|
||||||
import com.databasir.core.domain.system.data.SystemEmailResponse;
|
import com.databasir.core.domain.system.data.SystemEmailResponse;
|
||||||
import com.databasir.core.domain.system.data.SystemEmailUpdateRequest;
|
import com.databasir.core.domain.system.data.SystemEmailUpdateRequest;
|
||||||
import com.databasir.dao.impl.SysKeyDao;
|
|
||||||
import com.databasir.dao.impl.SysMailDao;
|
import com.databasir.dao.impl.SysMailDao;
|
||||||
import com.databasir.dao.impl.UserDao;
|
|
||||||
import com.databasir.dao.impl.UserRoleDao;
|
|
||||||
import com.databasir.dao.tables.pojos.SysKeyPojo;
|
|
||||||
import com.databasir.dao.tables.pojos.SysMailPojo;
|
import com.databasir.dao.tables.pojos.SysMailPojo;
|
||||||
import com.databasir.dao.tables.pojos.UserPojo;
|
|
||||||
import com.databasir.dao.tables.pojos.UserRolePojo;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SystemService {
|
public class SystemService {
|
||||||
|
|
||||||
private final SysKeyDao sysKeyDao;
|
|
||||||
|
|
||||||
private final SysMailDao sysMailDao;
|
private final SysMailDao sysMailDao;
|
||||||
|
|
||||||
private final UserDao userDao;
|
|
||||||
|
|
||||||
private final UserRoleDao userRoleDao;
|
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:all")
|
|
||||||
private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void postInit() {
|
|
||||||
sysKeyDao.selectOptionTopOne()
|
|
||||||
.orElseGet(() -> {
|
|
||||||
SysKeyPojo pojo = new SysKeyPojo();
|
|
||||||
pojo.setAesKey(Aes.randomBase64Key());
|
|
||||||
Rsa.RsaBase64Key key = Rsa.generateBase64Key();
|
|
||||||
pojo.setRsaPublicKey(key.getPublicBase64Key());
|
|
||||||
pojo.setRsaPrivateKey(key.getPrivateBase64Key());
|
|
||||||
sysKeyDao.insertAndReturnId(pojo);
|
|
||||||
return pojo;
|
|
||||||
});
|
|
||||||
|
|
||||||
String email = "N/A";
|
|
||||||
String username = "databasir";
|
|
||||||
Optional<UserPojo> userOpt = userDao.selectByEmailOrUsername(username);
|
|
||||||
if (!userOpt.isPresent()) {
|
|
||||||
UserPojo admin = new UserPojo();
|
|
||||||
admin.setEmail(email);
|
|
||||||
admin.setUsername(username);
|
|
||||||
admin.setPassword(bCryptPasswordEncoder.encode(username));
|
|
||||||
admin.setEnabled(true);
|
|
||||||
admin.setNickname("Databasir Admin");
|
|
||||||
Integer userId = userDao.insertAndReturnId(admin);
|
|
||||||
UserRolePojo role = new UserRolePojo();
|
|
||||||
role.setUserId(userId);
|
|
||||||
role.setRole("SYS_OWNER");
|
|
||||||
userRoleDao.insertAndReturnId(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renewKey() {
|
public void renewKey() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.databasir.core.infrastructure.mail.MailSender;
|
||||||
import com.databasir.dao.impl.ProjectDao;
|
import com.databasir.dao.impl.ProjectDao;
|
||||||
import com.databasir.dao.impl.SysMailDao;
|
import com.databasir.dao.impl.SysMailDao;
|
||||||
import com.databasir.dao.impl.UserDao;
|
import com.databasir.dao.impl.UserDao;
|
||||||
import com.databasir.dao.impl.UserRoleDao;
|
|
||||||
import com.databasir.dao.tables.pojos.ProjectPojo;
|
import com.databasir.dao.tables.pojos.ProjectPojo;
|
||||||
import com.databasir.dao.tables.pojos.UserPojo;
|
import com.databasir.dao.tables.pojos.UserPojo;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
@ -27,8 +26,6 @@ public class DocumentEventSubscriber {
|
||||||
|
|
||||||
private final MailSender mailSender;
|
private final MailSender mailSender;
|
||||||
|
|
||||||
private final UserRoleDao userRoleDao;
|
|
||||||
|
|
||||||
private final UserDao userDao;
|
private final UserDao userDao;
|
||||||
|
|
||||||
private final SysMailDao sysMailDao;
|
private final SysMailDao sysMailDao;
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
package com.databasir.core.infrastructure.event.subscriber;
|
||||||
|
|
||||||
|
import com.databasir.common.codec.Aes;
|
||||||
|
import com.databasir.common.codec.Rsa;
|
||||||
|
import com.databasir.core.domain.document.data.TableDocumentResponse;
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
|
import com.databasir.dao.impl.DocumentTemplatePropertyDao;
|
||||||
|
import com.databasir.dao.impl.SysKeyDao;
|
||||||
|
import com.databasir.dao.impl.UserDao;
|
||||||
|
import com.databasir.dao.impl.UserRoleDao;
|
||||||
|
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.SysKeyPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.UserPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.UserRolePojo;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
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.function.BiFunction;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SystemStartedEventSubscriber {
|
||||||
|
|
||||||
|
private final SysKeyDao sysKeyDao;
|
||||||
|
|
||||||
|
private final UserDao userDao;
|
||||||
|
|
||||||
|
private final UserRoleDao userRoleDao;
|
||||||
|
|
||||||
|
private final DocumentTemplatePropertyDao documentTemplatePropertyDao;
|
||||||
|
|
||||||
|
@SuppressWarnings("checkstyle:all")
|
||||||
|
private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||||
|
|
||||||
|
@EventListener(classes = ContextRefreshedEvent.class)
|
||||||
|
public void onStarted(ContextRefreshedEvent event) {
|
||||||
|
log.info("begin to init system data");
|
||||||
|
initSysOwnerIfNecessary();
|
||||||
|
initDatabaseTypesIfNecessary();
|
||||||
|
initTemplatePropertiesIfNecessary();
|
||||||
|
log.info("system data init finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTemplatePropertiesIfNecessary() {
|
||||||
|
List<String> ignoreFields = List.of("createAt", "discussionCount", "id");
|
||||||
|
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);
|
||||||
|
return pojo;
|
||||||
|
};
|
||||||
|
// column field name;
|
||||||
|
Field[] columnFields = TableDocumentResponse.ColumnDocumentResponse.class.getDeclaredFields();
|
||||||
|
List<DocumentTemplatePropertyPojo> columnProperties = Arrays.stream(columnFields)
|
||||||
|
.filter(f -> !ignoreFields.contains(f.getName()))
|
||||||
|
.map(field -> mapping.apply(field, DocumentTemplatePropertyType.COLUMN_FIELD_NAME))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// index field name;
|
||||||
|
Field[] indexFields = TableDocumentResponse.IndexDocumentResponse.class.getDeclaredFields();
|
||||||
|
List<DocumentTemplatePropertyPojo> indexProperties = Arrays.stream(indexFields)
|
||||||
|
.filter(f -> !ignoreFields.contains(f.getName()))
|
||||||
|
.map(field -> mapping.apply(field, DocumentTemplatePropertyType.INDEX_FIELD_NAME))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// foreign key field name;
|
||||||
|
Field[] fkFields = TableDocumentResponse.ForeignKeyDocumentResponse.class.getDeclaredFields();
|
||||||
|
List<DocumentTemplatePropertyPojo> fkProperties = Arrays.stream(fkFields)
|
||||||
|
.filter(f -> !ignoreFields.contains(f.getName()))
|
||||||
|
.map(field -> mapping.apply(field, DocumentTemplatePropertyType.FOREIGN_KEY_FIELD_NAME))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// trigger field name;
|
||||||
|
Field[] triggerFields = TableDocumentResponse.TriggerDocumentResponse.class.getDeclaredFields();
|
||||||
|
List<DocumentTemplatePropertyPojo> triggerProperties = Arrays.stream(triggerFields)
|
||||||
|
.filter(f -> !ignoreFields.contains(f.getName()))
|
||||||
|
.map(field -> mapping.apply(field, DocumentTemplatePropertyType.TRIGGER_FIELD_NAME))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<DocumentTemplatePropertyPojo> properties = new ArrayList<>();
|
||||||
|
properties.addAll(columnProperties);
|
||||||
|
properties.addAll(indexProperties);
|
||||||
|
properties.addAll(fkProperties);
|
||||||
|
properties.addAll(triggerProperties);
|
||||||
|
documentTemplatePropertyDao.batchInsertOnDuplicateIgnore(properties);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDatabaseTypesIfNecessary() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initSysOwnerIfNecessary() {
|
||||||
|
sysKeyDao.selectOptionTopOne()
|
||||||
|
.orElseGet(() -> {
|
||||||
|
SysKeyPojo pojo = new SysKeyPojo();
|
||||||
|
pojo.setAesKey(Aes.randomBase64Key());
|
||||||
|
Rsa.RsaBase64Key key = Rsa.generateBase64Key();
|
||||||
|
pojo.setRsaPublicKey(key.getPublicBase64Key());
|
||||||
|
pojo.setRsaPrivateKey(key.getPrivateBase64Key());
|
||||||
|
sysKeyDao.insertAndReturnId(pojo);
|
||||||
|
return pojo;
|
||||||
|
});
|
||||||
|
|
||||||
|
String email = "N/A";
|
||||||
|
String username = "databasir";
|
||||||
|
Optional<UserPojo> userOpt = userDao.selectByEmailOrUsername(username);
|
||||||
|
if (!userOpt.isPresent()) {
|
||||||
|
UserPojo admin = new UserPojo();
|
||||||
|
admin.setEmail(email);
|
||||||
|
admin.setUsername(username);
|
||||||
|
admin.setPassword(bCryptPasswordEncoder.encode(username));
|
||||||
|
admin.setEnabled(true);
|
||||||
|
admin.setNickname("Databasir Admin");
|
||||||
|
Integer userId = userDao.insertAndReturnId(admin);
|
||||||
|
UserRolePojo role = new UserRolePojo();
|
||||||
|
role.setUserId(userId);
|
||||||
|
role.setRole("SYS_OWNER");
|
||||||
|
userRoleDao.insertAndReturnId(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -66,6 +66,12 @@ jooq {
|
||||||
includeExpression = 'app_type'
|
includeExpression = 'app_type'
|
||||||
includeTypes = '.*'
|
includeTypes = '.*'
|
||||||
}
|
}
|
||||||
|
forcedType {
|
||||||
|
userType = 'com.databasir.dao.enums.DocumentTemplatePropertyType'
|
||||||
|
converter = 'com.databasir.dao.converter.DocumentTemplatePropertyTypeConverter'
|
||||||
|
includeExpression = 'document_template_property.type'
|
||||||
|
includeTypes = '.*'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generate {
|
generate {
|
||||||
|
|
|
@ -6,16 +6,29 @@ package com.databasir.dao.tables;
|
||||||
|
|
||||||
import com.databasir.dao.Databasir;
|
import com.databasir.dao.Databasir;
|
||||||
import com.databasir.dao.Keys;
|
import com.databasir.dao.Keys;
|
||||||
|
import com.databasir.dao.converter.DocumentTemplatePropertyTypeConverter;
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
import com.databasir.dao.tables.records.DocumentTemplatePropertyRecord;
|
import com.databasir.dao.tables.records.DocumentTemplatePropertyRecord;
|
||||||
import org.jooq.*;
|
|
||||||
import org.jooq.impl.DSL;
|
|
||||||
import org.jooq.impl.SQLDataType;
|
|
||||||
import org.jooq.impl.TableImpl;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jooq.Field;
|
||||||
|
import org.jooq.ForeignKey;
|
||||||
|
import org.jooq.Identity;
|
||||||
|
import org.jooq.Name;
|
||||||
|
import org.jooq.Record;
|
||||||
|
import org.jooq.Row6;
|
||||||
|
import org.jooq.Schema;
|
||||||
|
import org.jooq.Table;
|
||||||
|
import org.jooq.TableField;
|
||||||
|
import org.jooq.TableOptions;
|
||||||
|
import org.jooq.UniqueKey;
|
||||||
|
import org.jooq.impl.DSL;
|
||||||
|
import org.jooq.impl.SQLDataType;
|
||||||
|
import org.jooq.impl.TableImpl;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* template property
|
* template property
|
||||||
|
@ -63,7 +76,7 @@ public class DocumentTemplateProperty extends TableImpl<DocumentTemplateProperty
|
||||||
/**
|
/**
|
||||||
* The column <code>databasir.document_template_property.type</code>.
|
* The column <code>databasir.document_template_property.type</code>.
|
||||||
*/
|
*/
|
||||||
public final TableField<DocumentTemplatePropertyRecord, String> TYPE = createField(DSL.name("type"), SQLDataType.VARCHAR(64).nullable(false), this, "");
|
public final TableField<DocumentTemplatePropertyRecord, DocumentTemplatePropertyType> TYPE = createField(DSL.name("type"), SQLDataType.VARCHAR(64).nullable(false), this, "", new DocumentTemplatePropertyTypeConverter());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The column <code>databasir.document_template_property.create_at</code>.
|
* The column <code>databasir.document_template_property.create_at</code>.
|
||||||
|
@ -157,7 +170,7 @@ public class DocumentTemplateProperty extends TableImpl<DocumentTemplateProperty
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Row6<Integer, String, String, String, String, LocalDateTime> fieldsRow() {
|
public Row6<Integer, String, String, String, DocumentTemplatePropertyType, LocalDateTime> fieldsRow() {
|
||||||
return (Row6) super.fieldsRow();
|
return (Row6) super.fieldsRow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
package com.databasir.dao.tables.pojos;
|
package com.databasir.dao.tables.pojos;
|
||||||
|
|
||||||
|
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@ -16,12 +18,12 @@ public class DocumentTemplatePropertyPojo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String key;
|
private String key;
|
||||||
private String value;
|
private String value;
|
||||||
private String defaultValue;
|
private String defaultValue;
|
||||||
private String type;
|
private DocumentTemplatePropertyType type;
|
||||||
private LocalDateTime createAt;
|
private LocalDateTime createAt;
|
||||||
|
|
||||||
public DocumentTemplatePropertyPojo() {}
|
public DocumentTemplatePropertyPojo() {}
|
||||||
|
|
||||||
|
@ -35,12 +37,12 @@ public class DocumentTemplatePropertyPojo implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocumentTemplatePropertyPojo(
|
public DocumentTemplatePropertyPojo(
|
||||||
Integer id,
|
Integer id,
|
||||||
String key,
|
String key,
|
||||||
String value,
|
String value,
|
||||||
String defaultValue,
|
String defaultValue,
|
||||||
String type,
|
DocumentTemplatePropertyType type,
|
||||||
LocalDateTime createAt
|
LocalDateTime createAt
|
||||||
) {
|
) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
@ -111,14 +113,14 @@ public class DocumentTemplatePropertyPojo implements Serializable {
|
||||||
/**
|
/**
|
||||||
* Getter for <code>databasir.document_template_property.type</code>.
|
* Getter for <code>databasir.document_template_property.type</code>.
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public DocumentTemplatePropertyType getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for <code>databasir.document_template_property.type</code>.
|
* Setter for <code>databasir.document_template_property.type</code>.
|
||||||
*/
|
*/
|
||||||
public void setType(String type) {
|
public void setType(DocumentTemplatePropertyType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package com.databasir.dao.tables.records;
|
package com.databasir.dao.tables.records;
|
||||||
|
|
||||||
|
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
import com.databasir.dao.tables.DocumentTemplateProperty;
|
import com.databasir.dao.tables.DocumentTemplateProperty;
|
||||||
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ import org.jooq.impl.UpdatableRecordImpl;
|
||||||
* template property
|
* template property
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||||
public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<DocumentTemplatePropertyRecord> implements Record6<Integer, String, String, String, String, LocalDateTime> {
|
public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<DocumentTemplatePropertyRecord> implements Record6<Integer, String, String, String, DocumentTemplatePropertyType, LocalDateTime> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -85,15 +86,15 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
/**
|
/**
|
||||||
* Setter for <code>databasir.document_template_property.type</code>.
|
* Setter for <code>databasir.document_template_property.type</code>.
|
||||||
*/
|
*/
|
||||||
public void setType(String value) {
|
public void setType(DocumentTemplatePropertyType value) {
|
||||||
set(4, value);
|
set(4, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for <code>databasir.document_template_property.type</code>.
|
* Getter for <code>databasir.document_template_property.type</code>.
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public DocumentTemplatePropertyType getType() {
|
||||||
return (String) get(4);
|
return (DocumentTemplatePropertyType) get(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,12 +125,12 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Row6<Integer, String, String, String, String, LocalDateTime> fieldsRow() {
|
public Row6<Integer, String, String, String, DocumentTemplatePropertyType, LocalDateTime> fieldsRow() {
|
||||||
return (Row6) super.fieldsRow();
|
return (Row6) super.fieldsRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Row6<Integer, String, String, String, String, LocalDateTime> valuesRow() {
|
public Row6<Integer, String, String, String, DocumentTemplatePropertyType, LocalDateTime> valuesRow() {
|
||||||
return (Row6) super.valuesRow();
|
return (Row6) super.valuesRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Field<String> field5() {
|
public Field<DocumentTemplatePropertyType> field5() {
|
||||||
return DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY.TYPE;
|
return DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY.TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +185,7 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String component5() {
|
public DocumentTemplatePropertyType component5() {
|
||||||
return getType();
|
return getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value5() {
|
public DocumentTemplatePropertyType value5() {
|
||||||
return getType();
|
return getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +249,7 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DocumentTemplatePropertyRecord value5(String value) {
|
public DocumentTemplatePropertyRecord value5(DocumentTemplatePropertyType value) {
|
||||||
setType(value);
|
setType(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -260,7 +261,7 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DocumentTemplatePropertyRecord values(Integer value1, String value2, String value3, String value4, String value5, LocalDateTime value6) {
|
public DocumentTemplatePropertyRecord values(Integer value1, String value2, String value3, String value4, DocumentTemplatePropertyType value5, LocalDateTime value6) {
|
||||||
value1(value1);
|
value1(value1);
|
||||||
value2(value2);
|
value2(value2);
|
||||||
value3(value3);
|
value3(value3);
|
||||||
|
@ -284,7 +285,7 @@ public class DocumentTemplatePropertyRecord extends UpdatableRecordImpl<Document
|
||||||
/**
|
/**
|
||||||
* Create a detached, initialised DocumentTemplatePropertyRecord
|
* Create a detached, initialised DocumentTemplatePropertyRecord
|
||||||
*/
|
*/
|
||||||
public DocumentTemplatePropertyRecord(Integer id, String key, String value, String defaultValue, String type, LocalDateTime createAt) {
|
public DocumentTemplatePropertyRecord(Integer id, String key, String value, String defaultValue, DocumentTemplatePropertyType type, LocalDateTime createAt) {
|
||||||
super(DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY);
|
super(DocumentTemplateProperty.DOCUMENT_TEMPLATE_PROPERTY);
|
||||||
|
|
||||||
setId(id);
|
setId(id);
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.databasir.dao.converter;
|
||||||
|
|
||||||
|
import com.databasir.dao.enums.DocumentTemplatePropertyType;
|
||||||
|
import org.jooq.impl.EnumConverter;
|
||||||
|
|
||||||
|
public class DocumentTemplatePropertyTypeConverter extends EnumConverter<String, DocumentTemplatePropertyType> {
|
||||||
|
|
||||||
|
public DocumentTemplatePropertyTypeConverter() {
|
||||||
|
super(String.class, DocumentTemplatePropertyType.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.databasir.dao.enums;
|
||||||
|
|
||||||
|
public enum DocumentTemplatePropertyType {
|
||||||
|
|
||||||
|
INDEX_FIELD_NAME, COLUMN_FIELD_NAME, TRIGGER_FIELD_NAME, FOREIGN_KEY_FIELD_NAME;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.databasir.dao.impl;
|
||||||
|
|
||||||
|
import com.databasir.dao.tables.pojos.DocumentTemplatePropertyPojo;
|
||||||
|
import com.databasir.dao.tables.records.DocumentTemplatePropertyRecord;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.jooq.DSLContext;
|
||||||
|
import org.jooq.InsertReturningStep;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.databasir.dao.Tables.DOCUMENT_TEMPLATE_PROPERTY;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class DocumentTemplatePropertyDao extends BaseDao<DocumentTemplatePropertyPojo> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Getter
|
||||||
|
private DSLContext dslContext;
|
||||||
|
|
||||||
|
public DocumentTemplatePropertyDao() {
|
||||||
|
super(DOCUMENT_TEMPLATE_PROPERTY, DocumentTemplatePropertyPojo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void batchInsertOnDuplicateIgnore(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())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
getDslContext().batch(query).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void batchInsertOnDuplicateKeyUpdate(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))
|
||||||
|
.onDuplicateKeyUpdate()
|
||||||
|
.set(DOCUMENT_TEMPLATE_PROPERTY.VALUE, pojo.getValue()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
getDslContext().batch(query).execute();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue