diff --git a/api/src/main/java/com/databasir/api/DocumentRemarkController.java b/api/src/main/java/com/databasir/api/DocumentRemarkController.java new file mode 100644 index 0000000..68264a0 --- /dev/null +++ b/api/src/main/java/com/databasir/api/DocumentRemarkController.java @@ -0,0 +1,60 @@ +package com.databasir.api; + +import com.databasir.api.config.security.DatabasirUserDetails; +import com.databasir.common.JsonData; +import com.databasir.core.domain.remark.data.RemarkCreateRequest; +import com.databasir.core.domain.remark.data.RemarkListCondition; +import com.databasir.core.domain.remark.data.RemarkResponse; +import com.databasir.core.domain.remark.service.DocumentRemarkService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +@RestController +@Validated +@RequiredArgsConstructor +public class DocumentRemarkController { + + private final DocumentRemarkService documentRemarkService; + + @GetMapping(Routes.DocumentRemark.LIST) + public JsonData> listByProjectId(@PathVariable Integer groupId, + @PathVariable Integer projectId, + @PageableDefault(sort = "id", + direction = Sort.Direction.DESC) + Pageable request, + RemarkListCondition condition) { + var data = documentRemarkService.list(groupId, projectId, request, condition); + return JsonData.ok(data); + } + + @DeleteMapping(Routes.DocumentRemark.DELETE) + @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId)") + public JsonData delete(@PathVariable Integer groupId, + @PathVariable Integer projectId, + @PathVariable Integer remarkId) { + documentRemarkService.deleteById(groupId, projectId, remarkId); + return JsonData.ok(); + } + + @PostMapping(Routes.DocumentRemark.CREATE) + @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") + public JsonData create(@PathVariable Integer groupId, + @PathVariable Integer projectId, + @RequestBody @Valid RemarkCreateRequest request) { + DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + Integer userId = principal.getUserPojo().getId(); + documentRemarkService.create(groupId, projectId, userId, request); + return JsonData.ok(); + } +} diff --git a/api/src/main/java/com/databasir/api/Routes.java b/api/src/main/java/com/databasir/api/Routes.java index b30a546..b05fc94 100644 --- a/api/src/main/java/com/databasir/api/Routes.java +++ b/api/src/main/java/com/databasir/api/Routes.java @@ -70,6 +70,15 @@ public interface Routes { String LIST_VERSIONS = BASE + "/projects/{projectId}/document_versions"; } + interface DocumentRemark { + + String LIST = BASE + "/groups/{groupId}/projects/{projectId}/remarks"; + + String CREATE = BASE + "/groups/{groupId}/projects/{projectId}/remarks"; + + String DELETE = BASE + "/groups/{groupId}/projects/{projectId}/remarks/{remarkId}"; + } + interface Setting { String GET_SYS_EMAIL = BASE + "/settings/sys_email"; diff --git a/api/src/main/resources/application-local.properties b/api/src/main/resources/application-local.properties index b3da7a4..8f47aef 100644 --- a/api/src/main/resources/application-local.properties +++ b/api/src/main/resources/application-local.properties @@ -6,6 +6,6 @@ spring.datasource.password=123456 spring.datasource.url=jdbc:mysql://localhost:3306/databasir spring.jooq.sql-dialect=mysql -spring.flyway.enabled=true +spring.flyway.enabled=false spring.flyway.baseline-on-migrate=true spring.flyway.locations=classpath:db/migration \ No newline at end of file diff --git a/core/src/main/java/com/databasir/core/domain/remark/converter/RemarkResponseConverter.java b/core/src/main/java/com/databasir/core/domain/remark/converter/RemarkResponseConverter.java new file mode 100644 index 0000000..13fc574 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/remark/converter/RemarkResponseConverter.java @@ -0,0 +1,19 @@ +package com.databasir.core.domain.remark.converter; + +import com.databasir.core.domain.remark.data.RemarkResponse; +import com.databasir.dao.tables.pojos.DocumentRemarkPojo; +import com.databasir.dao.tables.pojos.UserPojo; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(componentModel = "spring") +public interface RemarkResponseConverter { + + @Mapping(target = "remarkBy.userId", source = "remarkBy.id") + @Mapping(target = "remarkBy.nickname", source = "remarkBy.nickname") + @Mapping(target = "remarkBy.email", source = "remarkBy.email") + @Mapping(target = "id", source = "remark.id") + @Mapping(target = "createAt", source = "remark.createAt") + RemarkResponse of(DocumentRemarkPojo remark, + UserPojo remarkBy); +} diff --git a/core/src/main/java/com/databasir/core/domain/remark/data/RemarkCreateRequest.java b/core/src/main/java/com/databasir/core/domain/remark/data/RemarkCreateRequest.java new file mode 100644 index 0000000..4e3455d --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/remark/data/RemarkCreateRequest.java @@ -0,0 +1,18 @@ +package com.databasir.core.domain.remark.data; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +public class RemarkCreateRequest { + + @NotBlank + private String remark; + + @NotNull + private String tableName; + + private String columnName; +} diff --git a/core/src/main/java/com/databasir/core/domain/remark/data/RemarkListCondition.java b/core/src/main/java/com/databasir/core/domain/remark/data/RemarkListCondition.java new file mode 100644 index 0000000..5eec4f4 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/remark/data/RemarkListCondition.java @@ -0,0 +1,35 @@ +package com.databasir.core.domain.remark.data; + +import com.databasir.dao.Tables; +import lombok.Data; +import org.jooq.Condition; +import org.jooq.impl.DSL; + +import javax.validation.constraints.NotBlank; +import java.util.ArrayList; +import java.util.List; + +@Data +public class RemarkListCondition { + + @NotBlank + private String tableName; + + private String columnName; + + public Condition toCondition(Integer projectId) { + List conditions = new ArrayList<>(); + Condition condition = Tables.DOCUMENT_REMARK.TABLE_NAME.eq(tableName); + conditions.add(condition); + + Condition columnCondition; + if (columnName != null) { + columnCondition = Tables.DOCUMENT_REMARK.COLUMN_NAME.eq(columnName); + } else { + columnCondition = Tables.DOCUMENT_REMARK.COLUMN_NAME.isNull(); + } + conditions.add(columnCondition); + conditions.add(Tables.DOCUMENT_REMARK.PROJECT_ID.eq(projectId)); + return conditions.stream().reduce(Condition::and).orElse(DSL.trueCondition()); + } +} diff --git a/core/src/main/java/com/databasir/core/domain/remark/data/RemarkResponse.java b/core/src/main/java/com/databasir/core/domain/remark/data/RemarkResponse.java new file mode 100644 index 0000000..73c599c --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/remark/data/RemarkResponse.java @@ -0,0 +1,30 @@ +package com.databasir.core.domain.remark.data; + +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class RemarkResponse { + + private Integer id; + + private Integer projectId; + + private String remark; + + private RemarkUser remarkBy; + + private LocalDateTime createAt; + + @Data + public static class RemarkUser { + + private Integer userId; + + private String nickname; + + private String email; + } + +} diff --git a/core/src/main/java/com/databasir/core/domain/remark/service/DocumentRemarkService.java b/core/src/main/java/com/databasir/core/domain/remark/service/DocumentRemarkService.java new file mode 100644 index 0000000..e7fe492 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/remark/service/DocumentRemarkService.java @@ -0,0 +1,81 @@ +package com.databasir.core.domain.remark.service; + +import com.databasir.common.exception.Forbidden; +import com.databasir.core.domain.remark.converter.RemarkResponseConverter; +import com.databasir.core.domain.remark.data.RemarkCreateRequest; +import com.databasir.core.domain.remark.data.RemarkListCondition; +import com.databasir.core.domain.remark.data.RemarkResponse; +import com.databasir.dao.impl.DocumentRemarkDao; +import com.databasir.dao.impl.ProjectDao; +import com.databasir.dao.impl.UserDao; +import com.databasir.dao.tables.pojos.DocumentRemarkPojo; +import com.databasir.dao.tables.pojos.UserPojo; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class DocumentRemarkService { + + private final DocumentRemarkDao documentRemarkDao; + + private final ProjectDao projectDao; + + private final UserDao userDao; + + private final RemarkResponseConverter remarkResponseConverter; + + public void deleteById(Integer groupId, + Integer projectId, + Integer remarkId) { + if (projectDao.exists(groupId, projectId)) { + documentRemarkDao.deleteById(remarkId); + } else { + throw new Forbidden(); + } + } + + public Page list(Integer groupId, + Integer projectId, + Pageable pageable, + RemarkListCondition condition) { + if (projectDao.exists(groupId, projectId)) { + Page data = documentRemarkDao.selectByPage(pageable, condition.toCondition(projectId)); + Set userIdList = data.getContent() + .stream() + .map(DocumentRemarkPojo::getUserId) + .collect(Collectors.toSet()); + Map userMapById = userDao.selectUserIdIn(userIdList) + .stream() + .collect(Collectors.toMap(UserPojo::getId, Function.identity())); + return data + .map(remarkPojo -> { + UserPojo userPojo = userMapById.get(remarkPojo.getUserId()); + return remarkResponseConverter.of(remarkPojo, userPojo); + }); + } else { + throw new Forbidden(); + } + } + + public void create(Integer groupId, Integer projectId, Integer userId, RemarkCreateRequest request) { + if (projectDao.exists(groupId, projectId)) { + DocumentRemarkPojo pojo = new DocumentRemarkPojo(); + pojo.setUserId(userId); + pojo.setProjectId(projectId); + pojo.setRemark(request.getRemark()); + pojo.setTableName(request.getTableName()); + pojo.setColumnName(request.getColumnName()); + documentRemarkDao.insertAndReturnId(pojo); + } else { + throw new Forbidden(); + } + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java index 2a4dd46..4e1346c 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java @@ -8,6 +8,7 @@ import com.databasir.dao.tables.DataSource; import com.databasir.dao.tables.DataSourceProperty; import com.databasir.dao.tables.DatabaseDocument; import com.databasir.dao.tables.DatabaseDocumentHistory; +import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Login; import com.databasir.dao.tables.Project; @@ -62,6 +63,11 @@ public class Databasir extends SchemaImpl { */ public final DatabaseDocumentHistory DATABASE_DOCUMENT_HISTORY = DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY; + /** + * The table databasir.document_remark. + */ + public final DocumentRemark DOCUMENT_REMARK = DocumentRemark.DOCUMENT_REMARK; + /** * The table databasir.group. */ @@ -142,6 +148,7 @@ public class Databasir extends SchemaImpl { DataSourceProperty.DATA_SOURCE_PROPERTY, DatabaseDocument.DATABASE_DOCUMENT, DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY, + DocumentRemark.DOCUMENT_REMARK, Group.GROUP, Login.LOGIN, Project.PROJECT, diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java index 90ac1bb..9c24e68 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Indexes.java @@ -6,6 +6,7 @@ package com.databasir.dao; import com.databasir.dao.tables.DataSourceProperty; import com.databasir.dao.tables.DatabaseDocumentHistory; +import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.TableColumnDocument; import com.databasir.dao.tables.TableDocument; import com.databasir.dao.tables.TableIndexDocument; @@ -33,6 +34,7 @@ public class Indexes { public static final Index TABLE_INDEX_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableIndexDocument.TABLE_INDEX_DOCUMENT, new OrderField[] { TableIndexDocument.TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID }, false); public static final Index TABLE_TRIGGER_DOCUMENT_IDX_DATABASE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_database_document_id"), TableTriggerDocument.TABLE_TRIGGER_DOCUMENT, new OrderField[] { TableTriggerDocument.TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID }, false); public static final Index DATABASE_DOCUMENT_HISTORY_IDX_PROJECT_ID = Internal.createIndex(DSL.name("idx_project_id"), DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY, new OrderField[] { DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY.PROJECT_ID }, false); + public static final Index DOCUMENT_REMARK_IDX_PROJECT_ID = Internal.createIndex(DSL.name("idx_project_id"), DocumentRemark.DOCUMENT_REMARK, new OrderField[] { DocumentRemark.DOCUMENT_REMARK.PROJECT_ID }, false); public static final Index TABLE_COLUMN_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableColumnDocument.TABLE_COLUMN_DOCUMENT, new OrderField[] { TableColumnDocument.TABLE_COLUMN_DOCUMENT.TABLE_DOCUMENT_ID }, false); public static final Index TABLE_INDEX_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableIndexDocument.TABLE_INDEX_DOCUMENT, new OrderField[] { TableIndexDocument.TABLE_INDEX_DOCUMENT.TABLE_DOCUMENT_ID }, false); public static final Index TABLE_TRIGGER_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableTriggerDocument.TABLE_TRIGGER_DOCUMENT, new OrderField[] { TableTriggerDocument.TABLE_TRIGGER_DOCUMENT.TABLE_DOCUMENT_ID }, false); diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java index 7a8706a..f746d6d 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java @@ -8,6 +8,7 @@ import com.databasir.dao.tables.DataSource; import com.databasir.dao.tables.DataSourceProperty; import com.databasir.dao.tables.DatabaseDocument; import com.databasir.dao.tables.DatabaseDocumentHistory; +import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Login; import com.databasir.dao.tables.Project; @@ -24,6 +25,7 @@ import com.databasir.dao.tables.records.DataSourcePropertyRecord; import com.databasir.dao.tables.records.DataSourceRecord; import com.databasir.dao.tables.records.DatabaseDocumentHistoryRecord; import com.databasir.dao.tables.records.DatabaseDocumentRecord; +import com.databasir.dao.tables.records.DocumentRemarkRecord; import com.databasir.dao.tables.records.GroupRecord; import com.databasir.dao.tables.records.LoginRecord; import com.databasir.dao.tables.records.ProjectRecord; @@ -61,6 +63,7 @@ public class Keys { public static final UniqueKey KEY_DATABASE_DOCUMENT_UK_PROJECT_ID = Internal.createUniqueKey(DatabaseDocument.DATABASE_DOCUMENT, DSL.name("KEY_database_document_uk_project_id"), new TableField[] { DatabaseDocument.DATABASE_DOCUMENT.PROJECT_ID }, true); public static final UniqueKey KEY_DATABASE_DOCUMENT_HISTORY_PRIMARY = Internal.createUniqueKey(DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY, DSL.name("KEY_database_document_history_PRIMARY"), new TableField[] { DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY.ID }, true); public static final UniqueKey KEY_DATABASE_DOCUMENT_HISTORY_UK_CONNECTION_ID_VERSION = Internal.createUniqueKey(DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY, DSL.name("KEY_database_document_history_uk_connection_id_version"), new TableField[] { DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY.DATABASE_DOCUMENT_ID, DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY.VERSION }, true); + public static final UniqueKey KEY_DOCUMENT_REMARK_PRIMARY = Internal.createUniqueKey(DocumentRemark.DOCUMENT_REMARK, DSL.name("KEY_document_remark_PRIMARY"), new TableField[] { DocumentRemark.DOCUMENT_REMARK.ID }, true); public static final UniqueKey KEY_GROUP_PRIMARY = Internal.createUniqueKey(Group.GROUP, DSL.name("KEY_group_PRIMARY"), new TableField[] { Group.GROUP.ID }, true); public static final UniqueKey KEY_GROUP_UK_NAME = Internal.createUniqueKey(Group.GROUP, DSL.name("KEY_group_uk_name"), new TableField[] { Group.GROUP.NAME }, true); public static final UniqueKey KEY_LOGIN_PRIMARY = Internal.createUniqueKey(Login.LOGIN, DSL.name("KEY_login_PRIMARY"), new TableField[] { Login.LOGIN.ID }, true); diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java b/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java index 3eed126..c4dfafb 100644 --- a/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java @@ -8,6 +8,7 @@ import com.databasir.dao.tables.DataSource; import com.databasir.dao.tables.DataSourceProperty; import com.databasir.dao.tables.DatabaseDocument; import com.databasir.dao.tables.DatabaseDocumentHistory; +import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Login; import com.databasir.dao.tables.Project; @@ -48,6 +49,11 @@ public class Tables { */ public static final DatabaseDocumentHistory DATABASE_DOCUMENT_HISTORY = DatabaseDocumentHistory.DATABASE_DOCUMENT_HISTORY; + /** + * The table databasir.document_remark. + */ + public static final DocumentRemark DOCUMENT_REMARK = DocumentRemark.DOCUMENT_REMARK; + /** * The table databasir.group. */ diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentRemark.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentRemark.java new file mode 100644 index 0000000..302f01a --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/DocumentRemark.java @@ -0,0 +1,176 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables; + + +import com.databasir.dao.Databasir; +import com.databasir.dao.Indexes; +import com.databasir.dao.Keys; +import com.databasir.dao.tables.records.DocumentRemarkRecord; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Identity; +import org.jooq.Index; +import org.jooq.Name; +import org.jooq.Record; +import org.jooq.Row7; +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; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DocumentRemark extends TableImpl { + + private static final long serialVersionUID = 1L; + + /** + * The reference instance of databasir.document_remark + */ + public static final DocumentRemark DOCUMENT_REMARK = new DocumentRemark(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return DocumentRemarkRecord.class; + } + + /** + * The column databasir.document_remark.id. + */ + public final TableField ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, ""); + + /** + * The column databasir.document_remark.remark. + */ + public final TableField REMARK = createField(DSL.name("remark"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column databasir.document_remark.user_id. user.id + */ + public final TableField USER_ID = createField(DSL.name("user_id"), SQLDataType.INTEGER.nullable(false), this, "user.id"); + + /** + * The column databasir.document_remark.project_id. + */ + public final TableField PROJECT_ID = createField(DSL.name("project_id"), SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column databasir.document_remark.table_name. + */ + public final TableField TABLE_NAME = createField(DSL.name("table_name"), SQLDataType.VARCHAR(255).nullable(false), this, ""); + + /** + * The column databasir.document_remark.column_name. + */ + public final TableField COLUMN_NAME = createField(DSL.name("column_name"), SQLDataType.VARCHAR(255), this, ""); + + /** + * The column databasir.document_remark.create_at. + */ + public final TableField CREATE_AT = createField(DSL.name("create_at"), SQLDataType.LOCALDATETIME(0).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this, ""); + + private DocumentRemark(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private DocumentRemark(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + } + + /** + * Create an aliased databasir.document_remark table reference + */ + public DocumentRemark(String alias) { + this(DSL.name(alias), DOCUMENT_REMARK); + } + + /** + * Create an aliased databasir.document_remark table reference + */ + public DocumentRemark(Name alias) { + this(alias, DOCUMENT_REMARK); + } + + /** + * Create a databasir.document_remark table reference + */ + public DocumentRemark() { + this(DSL.name("document_remark"), null); + } + + public DocumentRemark(Table child, ForeignKey key) { + super(child, key, DOCUMENT_REMARK); + } + + @Override + public Schema getSchema() { + return aliased() ? null : Databasir.DATABASIR; + } + + @Override + public List getIndexes() { + return Arrays.asList(Indexes.DOCUMENT_REMARK_IDX_PROJECT_ID); + } + + @Override + public Identity getIdentity() { + return (Identity) super.getIdentity(); + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.KEY_DOCUMENT_REMARK_PRIMARY; + } + + @Override + public DocumentRemark as(String alias) { + return new DocumentRemark(DSL.name(alias), this); + } + + @Override + public DocumentRemark as(Name alias) { + return new DocumentRemark(alias, this); + } + + /** + * Rename this table + */ + @Override + public DocumentRemark rename(String name) { + return new DocumentRemark(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public DocumentRemark rename(Name name) { + return new DocumentRemark(name, null); + } + + // ------------------------------------------------------------------------- + // Row7 type methods + // ------------------------------------------------------------------------- + + @Override + public Row7 fieldsRow() { + return (Row7) super.fieldsRow(); + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentRemarkPojo.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentRemarkPojo.java new file mode 100644 index 0000000..b504413 --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/DocumentRemarkPojo.java @@ -0,0 +1,170 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables.pojos; + + +import java.io.Serializable; +import java.time.LocalDateTime; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DocumentRemarkPojo implements Serializable { + + private static final long serialVersionUID = 1L; + + private Integer id; + private String remark; + private Integer userId; + private Integer projectId; + private String tableName; + private String columnName; + private LocalDateTime createAt; + + public DocumentRemarkPojo() {} + + public DocumentRemarkPojo(DocumentRemarkPojo value) { + this.id = value.id; + this.remark = value.remark; + this.userId = value.userId; + this.projectId = value.projectId; + this.tableName = value.tableName; + this.columnName = value.columnName; + this.createAt = value.createAt; + } + + public DocumentRemarkPojo( + Integer id, + String remark, + Integer userId, + Integer projectId, + String tableName, + String columnName, + LocalDateTime createAt + ) { + this.id = id; + this.remark = remark; + this.userId = userId; + this.projectId = projectId; + this.tableName = tableName; + this.columnName = columnName; + this.createAt = createAt; + } + + /** + * Getter for databasir.document_remark.id. + */ + public Integer getId() { + return this.id; + } + + /** + * Setter for databasir.document_remark.id. + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * Getter for databasir.document_remark.remark. + */ + public String getRemark() { + return this.remark; + } + + /** + * Setter for databasir.document_remark.remark. + */ + public void setRemark(String remark) { + this.remark = remark; + } + + /** + * Getter for databasir.document_remark.user_id. user.id + */ + public Integer getUserId() { + return this.userId; + } + + /** + * Setter for databasir.document_remark.user_id. user.id + */ + public void setUserId(Integer userId) { + this.userId = userId; + } + + /** + * Getter for databasir.document_remark.project_id. + */ + public Integer getProjectId() { + return this.projectId; + } + + /** + * Setter for databasir.document_remark.project_id. + */ + public void setProjectId(Integer projectId) { + this.projectId = projectId; + } + + /** + * Getter for databasir.document_remark.table_name. + */ + public String getTableName() { + return this.tableName; + } + + /** + * Setter for databasir.document_remark.table_name. + */ + public void setTableName(String tableName) { + this.tableName = tableName; + } + + /** + * Getter for databasir.document_remark.column_name. + */ + public String getColumnName() { + return this.columnName; + } + + /** + * Setter for databasir.document_remark.column_name. + */ + public void setColumnName(String columnName) { + this.columnName = columnName; + } + + /** + * Getter for databasir.document_remark.create_at. + */ + public LocalDateTime getCreateAt() { + return this.createAt; + } + + /** + * Setter for databasir.document_remark.create_at. + */ + public void setCreateAt(LocalDateTime createAt) { + this.createAt = createAt; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("DocumentRemarkPojo ("); + + sb.append(id); + sb.append(", ").append(remark); + sb.append(", ").append(userId); + sb.append(", ").append(projectId); + sb.append(", ").append(tableName); + sb.append(", ").append(columnName); + sb.append(", ").append(createAt); + + sb.append(")"); + return sb.toString(); + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentRemarkRecord.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentRemarkRecord.java new file mode 100644 index 0000000..0d93e24 --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/DocumentRemarkRecord.java @@ -0,0 +1,349 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables.records; + + +import com.databasir.dao.tables.DocumentRemark; +import com.databasir.dao.tables.pojos.DocumentRemarkPojo; + +import java.time.LocalDateTime; + +import org.jooq.Field; +import org.jooq.Record1; +import org.jooq.Record7; +import org.jooq.Row7; +import org.jooq.impl.UpdatableRecordImpl; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DocumentRemarkRecord extends UpdatableRecordImpl implements Record7 { + + private static final long serialVersionUID = 1L; + + /** + * Setter for databasir.document_remark.id. + */ + public void setId(Integer value) { + set(0, value); + } + + /** + * Getter for databasir.document_remark.id. + */ + public Integer getId() { + return (Integer) get(0); + } + + /** + * Setter for databasir.document_remark.remark. + */ + public void setRemark(String value) { + set(1, value); + } + + /** + * Getter for databasir.document_remark.remark. + */ + public String getRemark() { + return (String) get(1); + } + + /** + * Setter for databasir.document_remark.user_id. user.id + */ + public void setUserId(Integer value) { + set(2, value); + } + + /** + * Getter for databasir.document_remark.user_id. user.id + */ + public Integer getUserId() { + return (Integer) get(2); + } + + /** + * Setter for databasir.document_remark.project_id. + */ + public void setProjectId(Integer value) { + set(3, value); + } + + /** + * Getter for databasir.document_remark.project_id. + */ + public Integer getProjectId() { + return (Integer) get(3); + } + + /** + * Setter for databasir.document_remark.table_name. + */ + public void setTableName(String value) { + set(4, value); + } + + /** + * Getter for databasir.document_remark.table_name. + */ + public String getTableName() { + return (String) get(4); + } + + /** + * Setter for databasir.document_remark.column_name. + */ + public void setColumnName(String value) { + set(5, value); + } + + /** + * Getter for databasir.document_remark.column_name. + */ + public String getColumnName() { + return (String) get(5); + } + + /** + * Setter for databasir.document_remark.create_at. + */ + public void setCreateAt(LocalDateTime value) { + set(6, value); + } + + /** + * Getter for databasir.document_remark.create_at. + */ + public LocalDateTime getCreateAt() { + return (LocalDateTime) get(6); + } + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + @Override + public Record1 key() { + return (Record1) super.key(); + } + + // ------------------------------------------------------------------------- + // Record7 type implementation + // ------------------------------------------------------------------------- + + @Override + public Row7 fieldsRow() { + return (Row7) super.fieldsRow(); + } + + @Override + public Row7 valuesRow() { + return (Row7) super.valuesRow(); + } + + @Override + public Field field1() { + return DocumentRemark.DOCUMENT_REMARK.ID; + } + + @Override + public Field field2() { + return DocumentRemark.DOCUMENT_REMARK.REMARK; + } + + @Override + public Field field3() { + return DocumentRemark.DOCUMENT_REMARK.USER_ID; + } + + @Override + public Field field4() { + return DocumentRemark.DOCUMENT_REMARK.PROJECT_ID; + } + + @Override + public Field field5() { + return DocumentRemark.DOCUMENT_REMARK.TABLE_NAME; + } + + @Override + public Field field6() { + return DocumentRemark.DOCUMENT_REMARK.COLUMN_NAME; + } + + @Override + public Field field7() { + return DocumentRemark.DOCUMENT_REMARK.CREATE_AT; + } + + @Override + public Integer component1() { + return getId(); + } + + @Override + public String component2() { + return getRemark(); + } + + @Override + public Integer component3() { + return getUserId(); + } + + @Override + public Integer component4() { + return getProjectId(); + } + + @Override + public String component5() { + return getTableName(); + } + + @Override + public String component6() { + return getColumnName(); + } + + @Override + public LocalDateTime component7() { + return getCreateAt(); + } + + @Override + public Integer value1() { + return getId(); + } + + @Override + public String value2() { + return getRemark(); + } + + @Override + public Integer value3() { + return getUserId(); + } + + @Override + public Integer value4() { + return getProjectId(); + } + + @Override + public String value5() { + return getTableName(); + } + + @Override + public String value6() { + return getColumnName(); + } + + @Override + public LocalDateTime value7() { + return getCreateAt(); + } + + @Override + public DocumentRemarkRecord value1(Integer value) { + setId(value); + return this; + } + + @Override + public DocumentRemarkRecord value2(String value) { + setRemark(value); + return this; + } + + @Override + public DocumentRemarkRecord value3(Integer value) { + setUserId(value); + return this; + } + + @Override + public DocumentRemarkRecord value4(Integer value) { + setProjectId(value); + return this; + } + + @Override + public DocumentRemarkRecord value5(String value) { + setTableName(value); + return this; + } + + @Override + public DocumentRemarkRecord value6(String value) { + setColumnName(value); + return this; + } + + @Override + public DocumentRemarkRecord value7(LocalDateTime value) { + setCreateAt(value); + return this; + } + + @Override + public DocumentRemarkRecord values(Integer value1, String value2, Integer value3, Integer value4, String value5, String value6, LocalDateTime value7) { + value1(value1); + value2(value2); + value3(value3); + value4(value4); + value5(value5); + value6(value6); + value7(value7); + return this; + } + + // ------------------------------------------------------------------------- + // Constructors + // ------------------------------------------------------------------------- + + /** + * Create a detached DocumentRemarkRecord + */ + public DocumentRemarkRecord() { + super(DocumentRemark.DOCUMENT_REMARK); + } + + /** + * Create a detached, initialised DocumentRemarkRecord + */ + public DocumentRemarkRecord(Integer id, String remark, Integer userId, Integer projectId, String tableName, String columnName, LocalDateTime createAt) { + super(DocumentRemark.DOCUMENT_REMARK); + + setId(id); + setRemark(remark); + setUserId(userId); + setProjectId(projectId); + setTableName(tableName); + setColumnName(columnName); + setCreateAt(createAt); + } + + /** + * Create a detached, initialised DocumentRemarkRecord + */ + public DocumentRemarkRecord(DocumentRemarkPojo value) { + super(DocumentRemark.DOCUMENT_REMARK); + + if (value != null) { + setId(value.getId()); + setRemark(value.getRemark()); + setUserId(value.getUserId()); + setProjectId(value.getProjectId()); + setTableName(value.getTableName()); + setColumnName(value.getColumnName()); + setCreateAt(value.getCreateAt()); + } + } +} diff --git a/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java b/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java new file mode 100644 index 0000000..7852ed2 --- /dev/null +++ b/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java @@ -0,0 +1,32 @@ +package com.databasir.dao.impl; + +import com.databasir.dao.tables.pojos.DocumentRemarkPojo; +import com.databasir.dao.tables.records.DocumentRemarkRecord; +import lombok.Getter; +import org.jooq.DSLContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +import static com.databasir.dao.Tables.DOCUMENT_REMARK; + + +@Repository +public class DocumentRemarkDao extends BaseDao { + + @Autowired + @Getter + private DSLContext dslContext; + + public DocumentRemarkDao() { + super(DOCUMENT_REMARK, DocumentRemarkPojo.class); + } + + public Optional selectByProjectIdAndId(Integer projectId, Integer id) { + return this.getDslContext() + .selectFrom(DOCUMENT_REMARK).where(DOCUMENT_REMARK.PROJECT_ID.eq(projectId) + .and(DOCUMENT_REMARK.ID.eq(id))) + .fetchOptionalInto(DocumentRemarkPojo.class); + } +} diff --git a/dao/src/main/java/com/databasir/dao/impl/UserDao.java b/dao/src/main/java/com/databasir/dao/impl/UserDao.java index 5718a73..97b0442 100644 --- a/dao/src/main/java/com/databasir/dao/impl/UserDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/UserDao.java @@ -45,7 +45,7 @@ public class UserDao extends BaseDao { .execute(); } - public List selectUserIdIn(List userIds) { + public List selectUserIdIn(Collection userIds) { if (userIds == null || userIds.isEmpty()) { return Collections.emptyList(); } diff --git a/dao/src/main/resources/db/migration/V1__init.sql b/dao/src/main/resources/db/migration/V1__init.sql index 8facb26..7e2889b 100644 --- a/dao/src/main/resources/db/migration/V1__init.sql +++ b/dao/src/main/resources/db/migration/V1__init.sql @@ -218,5 +218,18 @@ CREATE TABLE login update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT UNIQUE uk_user_id (user_id) +) CHARSET utf8mb4 + COLLATE utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS document_remark +( + id INT PRIMARY KEY AUTO_INCREMENT, + remark TEXT NOT NULL, + user_id INT NOT NULL COMMENT 'user.id', + project_id INT NOT NULL, + table_name VARCHAR(255) NOT NULL, + column_name VARCHAR(255) DEFAULT NULL, + create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX idx_project_id (project_id) ) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci; \ No newline at end of file