mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-08 18:10:26 +08:00
feat: add checkstyle (#22)
This commit is contained in:
@@ -121,10 +121,11 @@ public class DocumentService {
|
||||
|
||||
Integer currentDatabaseDocumentId = databaseDocumentId;
|
||||
if (databaseDocumentId == null) {
|
||||
currentDatabaseDocumentId =
|
||||
databaseDocumentDao.insertAndReturnId(documentPojoConverter.toDatabasePojo(projectId, meta, 1L));
|
||||
var pojo = documentPojoConverter.toDatabasePojo(projectId, meta, 1L);
|
||||
currentDatabaseDocumentId = databaseDocumentDao.insertAndReturnId(pojo);
|
||||
} else {
|
||||
databaseDocumentDao.update(documentPojoConverter.toDatabasePojo(projectId, meta, databaseDocumentId, version));
|
||||
var pojo = documentPojoConverter.toDatabasePojo(projectId, meta, databaseDocumentId, version);
|
||||
databaseDocumentDao.update(pojo);
|
||||
}
|
||||
|
||||
final Integer docId = currentDatabaseDocumentId;
|
||||
@@ -132,11 +133,14 @@ public class DocumentService {
|
||||
TableDocumentPojo tableMeta =
|
||||
documentPojoConverter.toTablePojo(docId, table);
|
||||
Integer tableMetaId = tableDocumentDao.insertAndReturnId(tableMeta);
|
||||
List<TableColumnDocumentPojo> tableColumnMetas = documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns());
|
||||
List<TableColumnDocumentPojo> tableColumnMetas =
|
||||
documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns());
|
||||
tableColumnDocumentDao.batchInsert(tableColumnMetas);
|
||||
List<TableIndexDocumentPojo> tableIndexMetas = documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes());
|
||||
List<TableIndexDocumentPojo> tableIndexMetas =
|
||||
documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes());
|
||||
tableIndexDocumentDao.batchInsert(tableIndexMetas);
|
||||
List<TableTriggerDocumentPojo> tableTriggerMetas = documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers());
|
||||
List<TableTriggerDocumentPojo> tableTriggerMetas =
|
||||
documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers());
|
||||
tableTriggerDocumentDao.batchInsert(tableTriggerMetas);
|
||||
});
|
||||
log.info("save new meta info success");
|
||||
@@ -147,21 +151,25 @@ public class DocumentService {
|
||||
return databaseDocumentDao.selectOptionalByProjectId(projectId)
|
||||
.map(document -> {
|
||||
Integer id = document.getId();
|
||||
List<TableDocumentPojo> tables = tableDocumentDao.selectByDatabaseDocumentId(id);
|
||||
List<TableColumnDocumentPojo> columns = tableColumnDocumentDao.selectByDatabaseDocumentId(id);
|
||||
List<TableIndexDocumentPojo> indexes = tableIndexDocumentDao.selectByDatabaseMetaId(id);
|
||||
List<TableTriggerDocumentPojo> triggers = tableTriggerDocumentDao.selectByDatabaseDocumentId(id);
|
||||
var tables = tableDocumentDao.selectByDatabaseDocumentId(id);
|
||||
var columns = tableColumnDocumentDao.selectByDatabaseDocumentId(id);
|
||||
var indexes = tableIndexDocumentDao.selectByDatabaseMetaId(id);
|
||||
var triggers = tableTriggerDocumentDao.selectByDatabaseDocumentId(id);
|
||||
Map<Integer, List<TableColumnDocumentPojo>> columnsGroupByTableMetaId = columns.stream()
|
||||
.collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId));
|
||||
Map<Integer, List<TableIndexDocumentPojo>> indexesGroupByTableMetaId = indexes.stream()
|
||||
.collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId));
|
||||
Map<Integer, List<TableTriggerDocumentPojo>> triggersGroupByTableMetaId = triggers.stream()
|
||||
.collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId));
|
||||
List<DatabaseDocumentResponse.TableDocumentResponse> tableDocumentResponseList = tables.stream()
|
||||
var tableDocumentResponseList = tables.stream()
|
||||
.map(table -> {
|
||||
List<TableColumnDocumentPojo> subColumns = columnsGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList());
|
||||
List<TableIndexDocumentPojo> subIndexes = indexesGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList());
|
||||
List<TableTriggerDocumentPojo> subTriggers = triggersGroupByTableMetaId.getOrDefault(table.getId(), Collections.emptyList());
|
||||
Integer tableId = table.getId();
|
||||
var subColumns =
|
||||
columnsGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||
var subIndexes =
|
||||
indexesGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||
var subTriggers =
|
||||
triggersGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||
return documentResponseConverter.of(table, subColumns, subIndexes, subTriggers);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
@@ -175,11 +183,12 @@ public class DocumentService {
|
||||
|
||||
public Page<DatabaseDocumentVersionResponse> getVersionsBySchemaSourceId(Integer projectId, Pageable page) {
|
||||
return databaseDocumentDao.selectOptionalByProjectId(projectId)
|
||||
.map(schemaMeta -> databaseDocumentHistoryDao.selectVersionPageByDatabaseDocumentId(page, schemaMeta.getId())
|
||||
.map(history -> DatabaseDocumentVersionResponse.builder()
|
||||
.version(history.getVersion())
|
||||
.createAt(history.getCreateAt())
|
||||
.build()))
|
||||
.map(schemaMeta ->
|
||||
databaseDocumentHistoryDao.selectVersionPageByDatabaseDocumentId(page, schemaMeta.getId())
|
||||
.map(history -> DatabaseDocumentVersionResponse.builder()
|
||||
.version(history.getVersion())
|
||||
.createAt(history.getCreateAt())
|
||||
.build()))
|
||||
.orElseGet(Page::empty);
|
||||
}
|
||||
|
||||
@@ -193,11 +202,13 @@ public class DocumentService {
|
||||
List<List<String>> overviewContent = new ArrayList<>();
|
||||
for (int i = 0; i < doc.getTables().size(); i++) {
|
||||
DatabaseDocumentResponse.TableDocumentResponse table = doc.getTables().get(i);
|
||||
overviewContent.add(List.of((i + 1) + "", table.getName(), table.getType(), table.getComment()));
|
||||
overviewContent.add(List.of((i + 1) + "", table.getName(), table.getType(),
|
||||
table.getComment()));
|
||||
}
|
||||
builder.table(List.of("", "表名", "类型", "备注"), overviewContent);
|
||||
|
||||
Function<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse, String> columnDefaultValueMapping = column -> {
|
||||
Function<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse, String>
|
||||
columnDefaultValueMapping = column -> {
|
||||
if (Objects.equals(column.getNullable(), "YES")) {
|
||||
return Objects.requireNonNullElse(column.getDefaultValue(), "null");
|
||||
} else {
|
||||
|
@@ -3,7 +3,6 @@ package com.databasir.core.domain.group.data;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Data
|
||||
public class GroupMemberRoleUpdateRequest {
|
||||
|
@@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -88,10 +87,10 @@ public class GroupService {
|
||||
.stream()
|
||||
.map(GroupPojo::getId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, List<GroupMemberSimplePojo>> ownersGroupByGroupId = userRoleDao.selectOwnerNamesByGroupIdIn(groupIdList)
|
||||
var ownersGroupByGroupId = userRoleDao.selectOwnerNamesByGroupIdIn(groupIdList)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(GroupMemberSimplePojo::getGroupId));
|
||||
Map<Integer, GroupProjectCountPojo> projectCountMapByGroupId = projectDao.selectCountByGroupIds(groupIdList)
|
||||
var projectCountMapByGroupId = projectDao.selectCountByGroupIds(groupIdList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(GroupProjectCountPojo::getGroupId, v -> v));
|
||||
return page.map(groupPojo -> {
|
||||
|
@@ -1,20 +1,14 @@
|
||||
package com.databasir.core.domain.project.converter;
|
||||
|
||||
import com.databasir.core.domain.project.data.ProjectCreateRequest;
|
||||
import com.databasir.core.domain.project.data.ProjectDetailResponse;
|
||||
import com.databasir.core.domain.project.data.ProjectSimpleResponse;
|
||||
import com.databasir.core.domain.project.data.ProjectUpdateRequest;
|
||||
import com.databasir.core.infrastructure.converter.JsonConverter;
|
||||
import com.databasir.dao.tables.pojos.DataSourcePojo;
|
||||
import com.databasir.dao.tables.pojos.DataSourcePropertyPojo;
|
||||
import com.databasir.dao.tables.pojos.ProjectPojo;
|
||||
import com.databasir.dao.tables.pojos.ProjectSyncRulePojo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = JsonConverter.class)
|
||||
public interface ProjectPojoConverter {
|
||||
|
||||
|
@@ -119,7 +119,7 @@ public class ProjectService {
|
||||
return Optional.empty();
|
||||
}
|
||||
SysKeyPojo sysKey = sysKeyDao.selectTopOne();
|
||||
// String decryptedPassword = Rsa.decryptFromBase64DataByPrivateKey(password, sysKey.getRsaPrivateKey());
|
||||
// String decryptedPassword = Rsa.decryptFromBase64DataByPrivateKey(password, sysKey.getRsaPrivateKey());
|
||||
return Optional.of(Aes.encryptToBase64Data(password, sysKey.getAesKey()));
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,7 @@ public class SystemService {
|
||||
|
||||
private final UserRoleDao userRoleDao;
|
||||
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
@PostConstruct
|
||||
@@ -83,11 +84,12 @@ public class SystemService {
|
||||
}
|
||||
|
||||
public void updateEmailSetting(SystemEmailUpdateRequest request) {
|
||||
Optional<Integer> idOpt = sysMailDao.selectOptionTopOne().map(SysMailPojo::getId);
|
||||
SysMailPojo sysMailPojo = new SysMailPojo();
|
||||
sysMailPojo.setSmtpHost(request.getSmtpHost());
|
||||
sysMailPojo.setSmtpPort(request.getSmtpPort());
|
||||
sysMailPojo.setUsername(request.getUsername());
|
||||
|
||||
Optional<Integer> idOpt = sysMailDao.selectOptionTopOne().map(SysMailPojo::getId);
|
||||
idOpt.ifPresent(sysMailPojo::setId);
|
||||
if (request.getPassword() != null) {
|
||||
// TODO encrypt password ?
|
||||
|
@@ -13,7 +13,6 @@ import java.util.stream.Collectors;
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface UserResponseConverter {
|
||||
|
||||
|
||||
default UserDetailResponse detailResponse(UserPojo user,
|
||||
List<UserRolePojo> userRoles,
|
||||
Map<Integer, String> groupNameMapById) {
|
||||
|
@@ -25,7 +25,9 @@ public class UserLoginResponse {
|
||||
|
||||
@Data
|
||||
public static class RoleResponse {
|
||||
|
||||
private String role;
|
||||
|
||||
private Integer groupId;
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ public class UserService {
|
||||
|
||||
private final MailSender mailSender;
|
||||
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
public Page<UserPageResponse> list(Pageable pageable, UserPageCondition condition) {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.databasir.core.infrastructure.connection;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@@ -20,11 +20,6 @@ public class JsonConverter {
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public JSON toJson(List<String> array) {
|
||||
String json = objToJson(array);
|
||||
return JSON.valueOf(json);
|
||||
}
|
||||
|
||||
public List<String> fromJson(JSON json) {
|
||||
String data = json.data();
|
||||
if (data == null) {
|
||||
@@ -40,11 +35,21 @@ public class JsonConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public JSON toJson(List<String> array) {
|
||||
String json = objToJson(array);
|
||||
return JSON.valueOf(json);
|
||||
}
|
||||
|
||||
public JSON toJson(DatabaseDocumentResponse response) {
|
||||
String json = objToJson(response);
|
||||
return JSON.valueOf(json);
|
||||
}
|
||||
|
||||
public JSON toJson(JsonData<Object> data) {
|
||||
String json = objToJson(data);
|
||||
return JSON.valueOf(json);
|
||||
}
|
||||
|
||||
public DatabaseDocumentResponse of(JSON json) {
|
||||
try {
|
||||
if (json == null) {
|
||||
@@ -67,11 +72,6 @@ public class JsonConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public JSON toJson(JsonData<Object> data) {
|
||||
String json = objToJson(data);
|
||||
return JSON.valueOf(json);
|
||||
}
|
||||
|
||||
public JSON objToJsonData(Object obj) {
|
||||
String json = objToJson(obj);
|
||||
return JSON.valueOf(json);
|
||||
|
@@ -12,12 +12,13 @@ import java.nio.charset.StandardCharsets;
|
||||
public class MailSender {
|
||||
|
||||
public void send(SysMailPojo mail, String to, String subject, String content) {
|
||||
JavaMailSender sender = initJavaMailSender(mail);
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom(mail.getUsername());
|
||||
message.setTo(to);
|
||||
message.setSubject(subject);
|
||||
message.setText(content);
|
||||
|
||||
JavaMailSender sender = initJavaMailSender(mail);
|
||||
sender.send(message);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user