From 0d53f398c71391932e174c762c0c9d825a4a1c80 Mon Sep 17 00:00:00 2001 From: vran Date: Thu, 17 Feb 2022 22:38:08 +0800 Subject: [PATCH] feat: auto record operation log --- .../com/databasir/api/DocumentController.java | 2 + .../api/DocumentRemarkController.java | 7 + .../com/databasir/api/GroupController.java | 20 + .../com/databasir/api/LoginController.java | 2 + .../com/databasir/api/ProjectController.java | 12 + .../com/databasir/api/SettingController.java | 2 + .../com/databasir/api/UserController.java | 9 + .../api/advice/OperationLogAspect.java | 117 ++++ .../job/ProjectDocumentAutoSyncJob.java | 40 +- .../core/domain/log/annotation/Operation.java | 42 ++ .../OperationLogRequestConverter.java | 13 + .../domain/log/data/OperationLogRequest.java | 32 + .../log/service/OperationLogService.java | 22 + .../converter/JsonConverter.java | 35 +- .../java/com/databasir/dao/Databasir.java | 7 + .../main/java/com/databasir/dao/Keys.java | 3 + .../main/java/com/databasir/dao/Tables.java | 6 + .../databasir/dao/tables/OperationLog.java | 204 ++++++ .../dao/tables/pojos/OperationLogPojo.java | 298 +++++++++ .../tables/records/OperationLogRecord.java | 590 ++++++++++++++++++ .../java/com/databasir/dao/impl/BaseDao.java | 55 +- .../com/databasir/dao/impl/DataSourceDao.java | 2 +- .../dao/impl/DataSourcePropertyDao.java | 3 +- .../dao/impl/DatabaseDocumentDao.java | 2 +- .../dao/impl/DatabaseDocumentHistoryDao.java | 3 +- .../databasir/dao/impl/DocumentRemarkDao.java | 3 +- .../java/com/databasir/dao/impl/GroupDao.java | 15 +- .../java/com/databasir/dao/impl/LoginDao.java | 3 +- .../databasir/dao/impl/OperationLogDao.java | 28 + .../com/databasir/dao/impl/ProjectDao.java | 8 +- .../dao/impl/ProjectSyncRuleDao.java | 2 +- .../com/databasir/dao/impl/SysKeyDao.java | 3 +- .../com/databasir/dao/impl/SysMailDao.java | 2 +- .../dao/impl/TableColumnDocumentDao.java | 3 +- .../databasir/dao/impl/TableDocumentDao.java | 3 +- .../dao/impl/TableIndexDocumentDao.java | 3 +- .../dao/impl/TableTriggerDocumentDao.java | 3 +- .../java/com/databasir/dao/impl/UserDao.java | 3 +- .../com/databasir/dao/impl/UserRoleDao.java | 3 +- .../db/migration/V1.2__operation_log.sql | 18 + 40 files changed, 1553 insertions(+), 75 deletions(-) create mode 100644 api/src/main/java/com/databasir/api/advice/OperationLogAspect.java create mode 100644 core/src/main/java/com/databasir/core/domain/log/annotation/Operation.java create mode 100644 core/src/main/java/com/databasir/core/domain/log/converter/OperationLogRequestConverter.java create mode 100644 core/src/main/java/com/databasir/core/domain/log/data/OperationLogRequest.java create mode 100644 core/src/main/java/com/databasir/core/domain/log/service/OperationLogService.java create mode 100644 dao/generated-src/jooq/main/java/com/databasir/dao/tables/OperationLog.java create mode 100644 dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/OperationLogPojo.java create mode 100644 dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/OperationLogRecord.java create mode 100644 dao/src/main/java/com/databasir/dao/impl/OperationLogDao.java create mode 100644 dao/src/main/resources/db/migration/V1.2__operation_log.sql diff --git a/api/src/main/java/com/databasir/api/DocumentController.java b/api/src/main/java/com/databasir/api/DocumentController.java index 70885ed..b42a307 100644 --- a/api/src/main/java/com/databasir/api/DocumentController.java +++ b/api/src/main/java/com/databasir/api/DocumentController.java @@ -5,6 +5,7 @@ import com.databasir.common.SystemException; import com.databasir.core.domain.document.data.DatabaseDocumentResponse; import com.databasir.core.domain.document.data.DatabaseDocumentVersionResponse; import com.databasir.core.domain.document.service.DocumentService; +import com.databasir.core.domain.log.annotation.Operation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -33,6 +34,7 @@ public class DocumentController { private final DocumentService documentService; @PostMapping(Routes.Document.SYNC_ONE) + @Operation(module = Operation.Modules.PROJECT, name = "文档同步", involvedProjectId = "#projectId") public JsonData sync(@PathVariable Integer projectId) { documentService.syncByProjectId(projectId); return JsonData.ok(); diff --git a/api/src/main/java/com/databasir/api/DocumentRemarkController.java b/api/src/main/java/com/databasir/api/DocumentRemarkController.java index 68264a0..071cc5c 100644 --- a/api/src/main/java/com/databasir/api/DocumentRemarkController.java +++ b/api/src/main/java/com/databasir/api/DocumentRemarkController.java @@ -2,6 +2,7 @@ package com.databasir.api; import com.databasir.api.config.security.DatabasirUserDetails; import com.databasir.common.JsonData; +import com.databasir.core.domain.log.annotation.Operation; import com.databasir.core.domain.remark.data.RemarkCreateRequest; import com.databasir.core.domain.remark.data.RemarkListCondition; import com.databasir.core.domain.remark.data.RemarkResponse; @@ -38,6 +39,9 @@ public class DocumentRemarkController { @DeleteMapping(Routes.DocumentRemark.DELETE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId)") + @Operation(module = Operation.Modules.PROJECT, + name = "删除批注", + involvedProjectId = "#projectId") public JsonData delete(@PathVariable Integer groupId, @PathVariable Integer projectId, @PathVariable Integer remarkId) { @@ -47,6 +51,9 @@ public class DocumentRemarkController { @PostMapping(Routes.DocumentRemark.CREATE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") + @Operation(module = Operation.Modules.PROJECT, + name = "新增批注", + involvedProjectId = "#projectId") public JsonData create(@PathVariable Integer groupId, @PathVariable Integer projectId, @RequestBody @Valid RemarkCreateRequest request) { diff --git a/api/src/main/java/com/databasir/api/GroupController.java b/api/src/main/java/com/databasir/api/GroupController.java index f69c7f5..cff4eb8 100644 --- a/api/src/main/java/com/databasir/api/GroupController.java +++ b/api/src/main/java/com/databasir/api/GroupController.java @@ -4,6 +4,7 @@ import com.databasir.api.validator.UserOperationValidator; import com.databasir.common.JsonData; import com.databasir.core.domain.group.data.*; import com.databasir.core.domain.group.service.GroupService; +import com.databasir.core.domain.log.annotation.Operation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -28,6 +29,7 @@ public class GroupController { @PostMapping(Routes.Group.CREATE) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.GROUP, name = "创建分组") public JsonData create(@RequestBody @Valid GroupCreateRequest request) { groupService.create(request); return JsonData.ok(); @@ -35,6 +37,9 @@ public class GroupController { @PatchMapping(Routes.Group.UPDATE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#request.id)))") + @Operation(module = Operation.Modules.GROUP, + name = "更新分组", + involvedGroupId = "#request.id") public JsonData update(@RequestBody @Valid GroupUpdateRequest request) { groupService.update(request); return JsonData.ok(); @@ -49,6 +54,9 @@ public class GroupController { @DeleteMapping(Routes.Group.DELETE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") + @Operation(module = Operation.Modules.GROUP, + name = "删除分组", + involvedGroupId = "#groupId") public JsonData deleteById(@PathVariable Integer groupId) { groupService.delete(groupId); return JsonData.ok(); @@ -69,6 +77,10 @@ public class GroupController { @PostMapping(Routes.Group.ADD_MEMBER) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") + @Operation(module = Operation.Modules.GROUP, + name = "添加组员", + involvedGroupId = "#groupId", + involvedUserId = "#request.userId") public JsonData addGroupMember(@PathVariable Integer groupId, @RequestBody @Valid GroupMemberCreateRequest request) { userOperationValidator.forbiddenIfUpdateSelfRole(request.getUserId()); @@ -82,6 +94,10 @@ public class GroupController { @DeleteMapping(Routes.Group.DELETE_MEMBER) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") + @Operation(module = Operation.Modules.GROUP, + name = "移除组员", + involvedGroupId = "#groupId", + involvedUserId = "#userId") public JsonData removeGroupMember(@PathVariable Integer groupId, @PathVariable Integer userId) { userOperationValidator.forbiddenIfUpdateSelfRole(userId); @@ -91,6 +107,10 @@ public class GroupController { @PatchMapping(Routes.Group.UPDATE_MEMBER) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") + @Operation(module = Operation.Modules.GROUP, + name = "更新组员角色", + involvedGroupId = "#groupId", + involvedUserId = "#userId") public JsonData updateGroupMemberRole(@PathVariable Integer groupId, @PathVariable Integer userId, @RequestBody GroupMemberRoleUpdateRequest request) { diff --git a/api/src/main/java/com/databasir/api/LoginController.java b/api/src/main/java/com/databasir/api/LoginController.java index e060129..64b1244 100644 --- a/api/src/main/java/com/databasir/api/LoginController.java +++ b/api/src/main/java/com/databasir/api/LoginController.java @@ -4,6 +4,7 @@ import com.databasir.common.DatabasirException; import com.databasir.common.JsonData; import com.databasir.common.exception.InvalidTokenException; import com.databasir.core.domain.DomainErrors; +import com.databasir.core.domain.log.annotation.Operation; import com.databasir.core.domain.login.data.AccessTokenRefreshRequest; import com.databasir.core.domain.login.data.AccessTokenRefreshResponse; import com.databasir.core.domain.login.service.LoginService; @@ -32,6 +33,7 @@ public class LoginController { private final LoginService loginService; @GetMapping(Routes.Login.LOGOUT) + @Operation(module = Operation.Modules.USER, name = "注销登录") public JsonData logout() { SecurityContextHolder.clearContext(); return JsonData.ok(); diff --git a/api/src/main/java/com/databasir/api/ProjectController.java b/api/src/main/java/com/databasir/api/ProjectController.java index c654e9e..3c82a4b 100644 --- a/api/src/main/java/com/databasir/api/ProjectController.java +++ b/api/src/main/java/com/databasir/api/ProjectController.java @@ -2,6 +2,7 @@ package com.databasir.api; import com.databasir.api.validator.CronExpressionValidator; import com.databasir.common.JsonData; +import com.databasir.core.domain.log.annotation.Operation; import com.databasir.core.domain.project.data.*; import com.databasir.core.domain.project.service.ProjectService; import lombok.RequiredArgsConstructor; @@ -26,6 +27,9 @@ public class ProjectController { @PostMapping(Routes.GroupProject.CREATE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#request.groupId, 'GROUP_MEMBER?groupId='+#request.groupId)") + @Operation(module = Operation.Modules.PROJECT, + name = "创建项目", + involvedGroupId = "#request.groupId") public JsonData create(@RequestBody @Valid ProjectCreateRequest request) { cronExpressionValidator.isValidCron(request); projectService.create(request); @@ -34,6 +38,10 @@ public class ProjectController { @PatchMapping(Routes.GroupProject.UPDATE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") + @Operation(module = Operation.Modules.PROJECT, + name = "更新项目", + involvedGroupId = "#groupId", + involvedProjectId = "#request.id") public JsonData update(@RequestBody @Valid ProjectUpdateRequest request, @PathVariable Integer groupId) { cronExpressionValidator.isValidCron(request); @@ -43,6 +51,10 @@ public class ProjectController { @DeleteMapping(Routes.GroupProject.DELETE) @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") + @Operation(module = Operation.Modules.PROJECT, + name = "删除项目", + involvedGroupId = "#groupId", + involvedProjectId = "#projectId") public JsonData delete(@PathVariable Integer groupId, @PathVariable Integer projectId) { projectService.delete(projectId); diff --git a/api/src/main/java/com/databasir/api/SettingController.java b/api/src/main/java/com/databasir/api/SettingController.java index e54257c..910f2a5 100644 --- a/api/src/main/java/com/databasir/api/SettingController.java +++ b/api/src/main/java/com/databasir/api/SettingController.java @@ -2,6 +2,7 @@ package com.databasir.api; import com.databasir.common.JsonData; +import com.databasir.core.domain.log.annotation.Operation; import com.databasir.core.domain.system.data.SystemEmailResponse; import com.databasir.core.domain.system.data.SystemEmailUpdateRequest; import com.databasir.core.domain.system.service.SystemService; @@ -28,6 +29,7 @@ public class SettingController { } @PostMapping(Routes.Setting.UPDATE_SYS_EMAIL) + @Operation(module = Operation.Modules.PROJECT, name = "更新邮件配置") public JsonData updateSystemEmailSetting(@RequestBody @Valid SystemEmailUpdateRequest request) { systemService.updateEmailSetting(request); return JsonData.ok(); diff --git a/api/src/main/java/com/databasir/api/UserController.java b/api/src/main/java/com/databasir/api/UserController.java index 33f12a8..5c6fc03 100644 --- a/api/src/main/java/com/databasir/api/UserController.java +++ b/api/src/main/java/com/databasir/api/UserController.java @@ -3,6 +3,7 @@ package com.databasir.api; import com.databasir.api.validator.UserOperationValidator; import com.databasir.common.JsonData; import com.databasir.common.exception.Forbidden; +import com.databasir.core.domain.log.annotation.Operation; import com.databasir.core.domain.user.data.*; import com.databasir.core.domain.user.service.UserService; import lombok.RequiredArgsConstructor; @@ -34,6 +35,7 @@ public class UserController { @PostMapping(Routes.User.DISABLE) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.USER, name = "禁用用户", involvedUserId = "#userId") public JsonData disableUser(@PathVariable Integer userId) { userService.switchEnableStatus(userId, false); return JsonData.ok(); @@ -41,6 +43,7 @@ public class UserController { @PostMapping(Routes.User.ENABLE) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.USER, name = "启用用户", involvedUserId = "#userId") public JsonData enableUser(@PathVariable Integer userId) { userService.switchEnableStatus(userId, true); return JsonData.ok(); @@ -48,6 +51,7 @@ public class UserController { @PostMapping(Routes.User.CREATE) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.USER, name = "创建用户") public JsonData create(@RequestBody @Valid UserCreateRequest request) { userService.create(request); return JsonData.ok(); @@ -60,6 +64,7 @@ public class UserController { @PostMapping(Routes.User.RENEW_PASSWORD) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.USER, name = "重置用户密码", involvedUserId = "#userId") public JsonData renewPassword(@PathVariable Integer userId) { userService.renewPassword(userId); return JsonData.ok(); @@ -67,6 +72,7 @@ public class UserController { @PostMapping(Routes.User.ADD_OR_REMOVE_SYS_OWNER) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.USER, name = "添加系统管理员", involvedUserId = "#userId") public JsonData addSysOwner(@PathVariable Integer userId) { userOperationValidator.forbiddenIfUpdateSelfRole(userId); userService.addSysOwnerTo(userId); @@ -75,6 +81,7 @@ public class UserController { @DeleteMapping(Routes.User.ADD_OR_REMOVE_SYS_OWNER) @PreAuthorize("hasAnyAuthority('SYS_OWNER')") + @Operation(module = Operation.Modules.USER, name = "移除系统管理员", involvedUserId = "#userId") public JsonData removeSysOwner(@PathVariable Integer userId) { userOperationValidator.forbiddenIfUpdateSelfRole(userId); userService.removeSysOwnerFrom(userId); @@ -82,6 +89,7 @@ public class UserController { } @PostMapping(Routes.User.UPDATE_PASSWORD) + @Operation(module = Operation.Modules.USER, name = "更新密码", involvedUserId = "#userId") public JsonData updatePassword(@PathVariable Integer userId, @RequestBody @Valid UserPasswordUpdateRequest request) { if (userOperationValidator.isMyself(userId)) { @@ -93,6 +101,7 @@ public class UserController { } @PostMapping(Routes.User.UPDATE_NICKNAME) + @Operation(module = Operation.Modules.USER, name = "更新昵称", involvedUserId = "#userId") public JsonData updateNickname(@PathVariable Integer userId, @RequestBody @Valid UserNicknameUpdateRequest request) { if (userOperationValidator.isMyself(userId)) { diff --git a/api/src/main/java/com/databasir/api/advice/OperationLogAspect.java b/api/src/main/java/com/databasir/api/advice/OperationLogAspect.java new file mode 100644 index 0000000..4b0695d --- /dev/null +++ b/api/src/main/java/com/databasir/api/advice/OperationLogAspect.java @@ -0,0 +1,117 @@ +package com.databasir.api.advice; + +import com.databasir.api.config.security.DatabasirUserDetails; +import com.databasir.common.JsonData; +import com.databasir.core.domain.log.annotation.Operation; +import com.databasir.core.domain.log.data.OperationLogRequest; +import com.databasir.core.domain.log.service.OperationLogService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.core.LocalVariableTableParameterNameDiscoverer; +import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.expression.EvaluationContext; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; +import java.util.Objects; +import java.util.Optional; + +@Component +@RequiredArgsConstructor +@Aspect +@Slf4j +public class OperationLogAspect { + + private final OperationLogService operationLogService; + + private SpelExpressionParser spelExpressionParser = new SpelExpressionParser(); + + private ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); + + @AfterReturning(value = "@annotation(operation)", returning = "returnValue") + public void log(JoinPoint joinPoint, Object returnValue, Operation operation) { + saveLog(operation, joinPoint, (JsonData) returnValue); + } + + @AfterThrowing(value = "@annotation(operation)", throwing = "ex") + public void log(JoinPoint joinPoint, RuntimeException ex, Operation operation) { + saveLog(operation, joinPoint, JsonData.error("-1", ex.getMessage())); + throw ex; + } + + private void saveLog(Operation operation, JoinPoint joinPoint, JsonData result) { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + Object[] arguments = joinPoint.getArgs(); + + DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + Integer involvedProjectId = getValueBySPEL(method, arguments, operation.involvedProjectId(), Integer.class) + .orElse(null); + Integer involvedGroupId = getValueBySPEL(method, arguments, operation.involvedGroupId(), Integer.class) + .orElse(null); + Integer involvedUserId = getValueBySPEL(method, arguments, operation.involvedUserId(), Integer.class) + .orElse(null); + int userId = userId(); + String username = principal.getUserPojo().getUsername(); + String nickname = principal.getUserPojo().getNickname(); + if (userId == Operation.Types.SYSTEM_USER_ID) { + username = "system"; + nickname = "system"; + } + OperationLogRequest request = OperationLogRequest.builder() + .operatorUserId(userId) + .operatorUsername(username) + .operatorNickname(nickname) + .operationModule(operation.module()) + .operationCode(method.getName()) + .operationName(operation.name()) + .operationResponse(result) + .isSuccess(result.getErrCode() == null) + .involvedProjectId(involvedProjectId) + .involvedGroupId(involvedGroupId) + .involvedUserId(involvedUserId) + .build(); + operationLogService.save(request); + } + + private int userId() { + DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + return principal.getUserPojo().getId(); + } + + private Optional getValueBySPEL(Method method, + Object[] arguments, + String expression, + Class valueType) { + if (expression == null || "N/A".equals(expression)) { + return Optional.empty(); + } + String[] parameterNames = + Objects.requireNonNullElse(parameterNameDiscoverer.getParameterNames(method), new String[0]); + EvaluationContext context = new StandardEvaluationContext(); + for (int len = 0; len < parameterNames.length; len++) { + context.setVariable(parameterNames[len], arguments[len]); + } + try { + Expression expr = spelExpressionParser.parseExpression(expression); + return Optional.ofNullable(expr.getValue(context, valueType)); + } catch (Exception e) { + log.warn("parse expression error: " + expression, e); + return Optional.empty(); + } + } + +} diff --git a/api/src/main/java/com/databasir/job/ProjectDocumentAutoSyncJob.java b/api/src/main/java/com/databasir/job/ProjectDocumentAutoSyncJob.java index 6ec5161..cfd3e77 100644 --- a/api/src/main/java/com/databasir/job/ProjectDocumentAutoSyncJob.java +++ b/api/src/main/java/com/databasir/job/ProjectDocumentAutoSyncJob.java @@ -1,6 +1,9 @@ package com.databasir.job; +import com.databasir.common.JsonData; import com.databasir.core.domain.document.service.DocumentService; +import com.databasir.core.domain.log.data.OperationLogRequest; +import com.databasir.core.domain.log.service.OperationLogService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.quartz.Job; @@ -12,14 +15,47 @@ import org.quartz.JobExecutionException; @Slf4j public class ProjectDocumentAutoSyncJob implements Job { + private final OperationLogService operationLogService; + @Override public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap dataMap = context.getMergedJobDataMap(); log.info("start sync project document: " + dataMap.toString()); DocumentService documentService = (DocumentService) dataMap.get("documentService"); Integer projectId = dataMap.getInt("projectId"); - documentService.syncByProjectId(projectId); - log.info("sync project document {} over....", projectId); + + try { + documentService.syncByProjectId(projectId); + OperationLogRequest request = OperationLogRequest.builder() + .isSuccess(true) + .operatorNickname("system") + .operatorUsername("system") + .operatorUserId(-1) + .operationName("文档自动同步") + .operationCode("autoSyncDocumentation") + .operationModule("project") + .operationResponse(JsonData.ok()) + .isSuccess(true) + .involvedProjectId(projectId) + .build(); + operationLogService.save(request); + log.info("sync project document {} over....", projectId); + } catch (Exception e) { + OperationLogRequest request = OperationLogRequest.builder() + .isSuccess(true) + .operatorNickname("system") + .operatorUsername("system") + .operatorUserId(-1) + .operationName("文档自动同步") + .operationCode("autoSyncDocumentation") + .operationModule("project") + .operationResponse(JsonData.error("-1", e.getMessage())) + .isSuccess(false) + .involvedProjectId(projectId) + .build(); + operationLogService.save(request); + throw e; + } } } diff --git a/core/src/main/java/com/databasir/core/domain/log/annotation/Operation.java b/core/src/main/java/com/databasir/core/domain/log/annotation/Operation.java new file mode 100644 index 0000000..17bfa21 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/log/annotation/Operation.java @@ -0,0 +1,42 @@ +package com.databasir.core.domain.log.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Operation { + + String module(); + + String name() default "UNKNOWN"; + + /** + * @return the Spring-EL expression + */ + String involvedProjectId() default "N/A"; + + /** + * @return the Spring-EL expression + */ + String involvedGroupId() default "N/A"; + + /** + * @return the Spring-EL expression + */ + String involvedUserId() default "N/A"; + + interface Modules { + String UNKNOWN = "UNKNOWN"; + String PROJECT = "project"; + String USER = "user"; + String GROUP = "group"; + String SETTING = "setting"; + } + + interface Types { + int SYSTEM_USER_ID = -1; + } +} diff --git a/core/src/main/java/com/databasir/core/domain/log/converter/OperationLogRequestConverter.java b/core/src/main/java/com/databasir/core/domain/log/converter/OperationLogRequestConverter.java new file mode 100644 index 0000000..35fbf6a --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/log/converter/OperationLogRequestConverter.java @@ -0,0 +1,13 @@ +package com.databasir.core.domain.log.converter; + +import com.databasir.core.domain.log.data.OperationLogRequest; +import com.databasir.core.infrastructure.converter.JsonConverter; +import com.databasir.dao.tables.pojos.OperationLogPojo; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring", uses = JsonConverter.class) +public interface OperationLogRequestConverter { + + OperationLogPojo toPojo(OperationLogRequest request); + +} diff --git a/core/src/main/java/com/databasir/core/domain/log/data/OperationLogRequest.java b/core/src/main/java/com/databasir/core/domain/log/data/OperationLogRequest.java new file mode 100644 index 0000000..5f73538 --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/log/data/OperationLogRequest.java @@ -0,0 +1,32 @@ +package com.databasir.core.domain.log.data; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class OperationLogRequest { + + private Integer operatorUserId; + + private String operatorUsername; + + private String operatorNickname; + + private String operationModule; + + private String operationCode; + + private String operationName; + + private Object operationResponse; + + private Boolean isSuccess; + + private Integer involvedProjectId; + + private Integer involvedGroupId; + + private Integer involvedUserId; + +} diff --git a/core/src/main/java/com/databasir/core/domain/log/service/OperationLogService.java b/core/src/main/java/com/databasir/core/domain/log/service/OperationLogService.java new file mode 100644 index 0000000..da4226e --- /dev/null +++ b/core/src/main/java/com/databasir/core/domain/log/service/OperationLogService.java @@ -0,0 +1,22 @@ +package com.databasir.core.domain.log.service; + +import com.databasir.core.domain.log.converter.OperationLogRequestConverter; +import com.databasir.core.domain.log.data.OperationLogRequest; +import com.databasir.dao.impl.OperationLogDao; +import com.databasir.dao.tables.pojos.OperationLogPojo; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OperationLogService { + + private final OperationLogDao operationLogDao; + + private final OperationLogRequestConverter operationLogRequestConverter; + + public void save(OperationLogRequest request) { + OperationLogPojo pojo = operationLogRequestConverter.toPojo(request); + operationLogDao.insertAndReturnId(pojo); + } +} diff --git a/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java b/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java index 6210c6f..ec2ecb6 100644 --- a/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java +++ b/core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java @@ -1,5 +1,6 @@ package com.databasir.core.infrastructure.converter; +import com.databasir.common.JsonData; import com.databasir.core.domain.document.data.DatabaseDocumentResponse; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -20,12 +21,8 @@ public class JsonConverter { private ObjectMapper objectMapper; public JSON toJson(List array) { - try { - String json = objectMapper.writeValueAsString(array); - return JSON.valueOf(json); - } catch (JsonProcessingException e) { - throw new IllegalArgumentException(e); - } + String json = objToJson(array); + return JSON.valueOf(json); } public List fromJson(JSON json) { @@ -44,12 +41,8 @@ public class JsonConverter { } public JSON toJson(DatabaseDocumentResponse response) { - try { - String json = objectMapper.writeValueAsString(response); - return JSON.valueOf(json); - } catch (JsonProcessingException e) { - throw new IllegalArgumentException(e); - } + String json = objToJson(response); + return JSON.valueOf(json); } public DatabaseDocumentResponse of(JSON json) { @@ -62,4 +55,22 @@ public class JsonConverter { throw new IllegalArgumentException(e); } } + + public JSON toJson(JsonData data) { + String json = objToJson(data); + return JSON.valueOf(json); + } + + public JSON objToJsonData(Object obj) { + String json = objToJson(obj); + return JSON.valueOf(json); + } + + private String objToJson(Object obj) { + try { + return objectMapper.writeValueAsString(obj); + } catch (JsonProcessingException e) { + throw new IllegalArgumentException(e); + } + } } 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 4e1346c..88e3539 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 @@ -11,6 +11,7 @@ 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.OperationLog; import com.databasir.dao.tables.Project; import com.databasir.dao.tables.ProjectSyncRule; import com.databasir.dao.tables.SysKey; @@ -78,6 +79,11 @@ public class Databasir extends SchemaImpl { */ public final Login LOGIN = Login.LOGIN; + /** + * The table databasir.operation_log. + */ + public final OperationLog OPERATION_LOG = OperationLog.OPERATION_LOG; + /** * The table databasir.project. */ @@ -151,6 +157,7 @@ public class Databasir extends SchemaImpl { DocumentRemark.DOCUMENT_REMARK, Group.GROUP, Login.LOGIN, + OperationLog.OPERATION_LOG, Project.PROJECT, ProjectSyncRule.PROJECT_SYNC_RULE, SysKey.SYS_KEY, 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 f746d6d..a4c7dc4 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 @@ -11,6 +11,7 @@ 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.OperationLog; import com.databasir.dao.tables.Project; import com.databasir.dao.tables.ProjectSyncRule; import com.databasir.dao.tables.SysKey; @@ -28,6 +29,7 @@ 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.OperationLogRecord; import com.databasir.dao.tables.records.ProjectRecord; import com.databasir.dao.tables.records.ProjectSyncRuleRecord; import com.databasir.dao.tables.records.SysKeyRecord; @@ -68,6 +70,7 @@ public class Keys { 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); public static final UniqueKey KEY_LOGIN_UK_USER_ID = Internal.createUniqueKey(Login.LOGIN, DSL.name("KEY_login_uk_user_id"), new TableField[] { Login.LOGIN.USER_ID }, true); + public static final UniqueKey KEY_OPERATION_LOG_PRIMARY = Internal.createUniqueKey(OperationLog.OPERATION_LOG, DSL.name("KEY_operation_log_PRIMARY"), new TableField[] { OperationLog.OPERATION_LOG.ID }, true); public static final UniqueKey KEY_PROJECT_PRIMARY = Internal.createUniqueKey(Project.PROJECT, DSL.name("KEY_project_PRIMARY"), new TableField[] { Project.PROJECT.ID }, true); public static final UniqueKey KEY_PROJECT_UK_GROUP_ID_NAME = Internal.createUniqueKey(Project.PROJECT, DSL.name("KEY_project_uk_group_id_name"), new TableField[] { Project.PROJECT.GROUP_ID, Project.PROJECT.NAME }, true); public static final UniqueKey KEY_PROJECT_SYNC_RULE_PRIMARY = Internal.createUniqueKey(ProjectSyncRule.PROJECT_SYNC_RULE, DSL.name("KEY_project_sync_rule_PRIMARY"), new TableField[] { ProjectSyncRule.PROJECT_SYNC_RULE.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 c4dfafb..7e6b962 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 @@ -11,6 +11,7 @@ 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.OperationLog; import com.databasir.dao.tables.Project; import com.databasir.dao.tables.ProjectSyncRule; import com.databasir.dao.tables.SysKey; @@ -64,6 +65,11 @@ public class Tables { */ public static final Login LOGIN = Login.LOGIN; + /** + * The table databasir.operation_log. + */ + public static final OperationLog OPERATION_LOG = OperationLog.OPERATION_LOG; + /** * The table databasir.project. */ diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/OperationLog.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/OperationLog.java new file mode 100644 index 0000000..21fb03e --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/OperationLog.java @@ -0,0 +1,204 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables; + + +import com.databasir.dao.Databasir; +import com.databasir.dao.Keys; +import com.databasir.dao.tables.records.OperationLogRecord; + +import java.time.LocalDateTime; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Identity; +import org.jooq.JSON; +import org.jooq.Name; +import org.jooq.Record; +import org.jooq.Row13; +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 OperationLog extends TableImpl { + + private static final long serialVersionUID = 1L; + + /** + * The reference instance of databasir.operation_log + */ + public static final OperationLog OPERATION_LOG = new OperationLog(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return OperationLogRecord.class; + } + + /** + * The column databasir.operation_log.id. + */ + public final TableField ID = createField(DSL.name("id"), SQLDataType.BIGINT.nullable(false).identity(true), this, ""); + + /** + * The column databasir.operation_log.operator_user_id. ref to + * user.id + */ + public final TableField OPERATOR_USER_ID = createField(DSL.name("operator_user_id"), SQLDataType.INTEGER.nullable(false), this, "ref to user.id"); + + /** + * The column databasir.operation_log.operator_username. + * user.username + */ + public final TableField OPERATOR_USERNAME = createField(DSL.name("operator_username"), SQLDataType.VARCHAR(128).nullable(false), this, "user.username"); + + /** + * The column databasir.operation_log.operator_nickname. + * user.nickname + */ + public final TableField OPERATOR_NICKNAME = createField(DSL.name("operator_nickname"), SQLDataType.VARCHAR(255).nullable(false), this, "user.nickname"); + + /** + * The column databasir.operation_log.operation_module. + */ + public final TableField OPERATION_MODULE = createField(DSL.name("operation_module"), SQLDataType.VARCHAR(128).nullable(false), this, ""); + + /** + * The column databasir.operation_log.operation_code. + */ + public final TableField OPERATION_CODE = createField(DSL.name("operation_code"), SQLDataType.VARCHAR(255).nullable(false), this, ""); + + /** + * The column databasir.operation_log.operation_name. + */ + public final TableField OPERATION_NAME = createField(DSL.name("operation_name"), SQLDataType.VARCHAR(255).nullable(false), this, ""); + + /** + * The column databasir.operation_log.operation_response. + */ + public final TableField OPERATION_RESPONSE = createField(DSL.name("operation_response"), SQLDataType.JSON.nullable(false), this, ""); + + /** + * The column databasir.operation_log.is_success. + */ + public final TableField IS_SUCCESS = createField(DSL.name("is_success"), SQLDataType.BOOLEAN.nullable(false).defaultValue(DSL.inline("0", SQLDataType.BOOLEAN)), this, ""); + + /** + * The column databasir.operation_log.involved_project_id. ref + * to project.id + */ + public final TableField INVOLVED_PROJECT_ID = createField(DSL.name("involved_project_id"), SQLDataType.INTEGER, this, "ref to project.id"); + + /** + * The column databasir.operation_log.involved_group_id. ref to + * group.id + */ + public final TableField INVOLVED_GROUP_ID = createField(DSL.name("involved_group_id"), SQLDataType.INTEGER, this, "ref to group.id"); + + /** + * The column databasir.operation_log.involved_user_id. ref to + * user.id + */ + public final TableField INVOLVED_USER_ID = createField(DSL.name("involved_user_id"), SQLDataType.INTEGER, this, "ref to user.id"); + + /** + * The column databasir.operation_log.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 OperationLog(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private OperationLog(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + } + + /** + * Create an aliased databasir.operation_log table reference + */ + public OperationLog(String alias) { + this(DSL.name(alias), OPERATION_LOG); + } + + /** + * Create an aliased databasir.operation_log table reference + */ + public OperationLog(Name alias) { + this(alias, OPERATION_LOG); + } + + /** + * Create a databasir.operation_log table reference + */ + public OperationLog() { + this(DSL.name("operation_log"), null); + } + + public OperationLog(Table child, ForeignKey key) { + super(child, key, OPERATION_LOG); + } + + @Override + public Schema getSchema() { + return aliased() ? null : Databasir.DATABASIR; + } + + @Override + public Identity getIdentity() { + return (Identity) super.getIdentity(); + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.KEY_OPERATION_LOG_PRIMARY; + } + + @Override + public OperationLog as(String alias) { + return new OperationLog(DSL.name(alias), this); + } + + @Override + public OperationLog as(Name alias) { + return new OperationLog(alias, this); + } + + /** + * Rename this table + */ + @Override + public OperationLog rename(String name) { + return new OperationLog(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public OperationLog rename(Name name) { + return new OperationLog(name, null); + } + + // ------------------------------------------------------------------------- + // Row13 type methods + // ------------------------------------------------------------------------- + + @Override + public Row13 fieldsRow() { + return (Row13) super.fieldsRow(); + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/OperationLogPojo.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/OperationLogPojo.java new file mode 100644 index 0000000..b8b1c8b --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/OperationLogPojo.java @@ -0,0 +1,298 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables.pojos; + + +import java.io.Serializable; +import java.time.LocalDateTime; + +import org.jooq.JSON; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class OperationLogPojo implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + private Integer operatorUserId; + private String operatorUsername; + private String operatorNickname; + private String operationModule; + private String operationCode; + private String operationName; + private JSON operationResponse; + private Boolean isSuccess; + private Integer involvedProjectId; + private Integer involvedGroupId; + private Integer involvedUserId; + private LocalDateTime createAt; + + public OperationLogPojo() {} + + public OperationLogPojo(OperationLogPojo value) { + this.id = value.id; + this.operatorUserId = value.operatorUserId; + this.operatorUsername = value.operatorUsername; + this.operatorNickname = value.operatorNickname; + this.operationModule = value.operationModule; + this.operationCode = value.operationCode; + this.operationName = value.operationName; + this.operationResponse = value.operationResponse; + this.isSuccess = value.isSuccess; + this.involvedProjectId = value.involvedProjectId; + this.involvedGroupId = value.involvedGroupId; + this.involvedUserId = value.involvedUserId; + this.createAt = value.createAt; + } + + public OperationLogPojo( + Long id, + Integer operatorUserId, + String operatorUsername, + String operatorNickname, + String operationModule, + String operationCode, + String operationName, + JSON operationResponse, + Boolean isSuccess, + Integer involvedProjectId, + Integer involvedGroupId, + Integer involvedUserId, + LocalDateTime createAt + ) { + this.id = id; + this.operatorUserId = operatorUserId; + this.operatorUsername = operatorUsername; + this.operatorNickname = operatorNickname; + this.operationModule = operationModule; + this.operationCode = operationCode; + this.operationName = operationName; + this.operationResponse = operationResponse; + this.isSuccess = isSuccess; + this.involvedProjectId = involvedProjectId; + this.involvedGroupId = involvedGroupId; + this.involvedUserId = involvedUserId; + this.createAt = createAt; + } + + /** + * Getter for databasir.operation_log.id. + */ + public Long getId() { + return this.id; + } + + /** + * Setter for databasir.operation_log.id. + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Getter for databasir.operation_log.operator_user_id. ref to + * user.id + */ + public Integer getOperatorUserId() { + return this.operatorUserId; + } + + /** + * Setter for databasir.operation_log.operator_user_id. ref to + * user.id + */ + public void setOperatorUserId(Integer operatorUserId) { + this.operatorUserId = operatorUserId; + } + + /** + * Getter for databasir.operation_log.operator_username. + * user.username + */ + public String getOperatorUsername() { + return this.operatorUsername; + } + + /** + * Setter for databasir.operation_log.operator_username. + * user.username + */ + public void setOperatorUsername(String operatorUsername) { + this.operatorUsername = operatorUsername; + } + + /** + * Getter for databasir.operation_log.operator_nickname. + * user.nickname + */ + public String getOperatorNickname() { + return this.operatorNickname; + } + + /** + * Setter for databasir.operation_log.operator_nickname. + * user.nickname + */ + public void setOperatorNickname(String operatorNickname) { + this.operatorNickname = operatorNickname; + } + + /** + * Getter for databasir.operation_log.operation_module. + */ + public String getOperationModule() { + return this.operationModule; + } + + /** + * Setter for databasir.operation_log.operation_module. + */ + public void setOperationModule(String operationModule) { + this.operationModule = operationModule; + } + + /** + * Getter for databasir.operation_log.operation_code. + */ + public String getOperationCode() { + return this.operationCode; + } + + /** + * Setter for databasir.operation_log.operation_code. + */ + public void setOperationCode(String operationCode) { + this.operationCode = operationCode; + } + + /** + * Getter for databasir.operation_log.operation_name. + */ + public String getOperationName() { + return this.operationName; + } + + /** + * Setter for databasir.operation_log.operation_name. + */ + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + /** + * Getter for databasir.operation_log.operation_response. + */ + public JSON getOperationResponse() { + return this.operationResponse; + } + + /** + * Setter for databasir.operation_log.operation_response. + */ + public void setOperationResponse(JSON operationResponse) { + this.operationResponse = operationResponse; + } + + /** + * Getter for databasir.operation_log.is_success. + */ + public Boolean getIsSuccess() { + return this.isSuccess; + } + + /** + * Setter for databasir.operation_log.is_success. + */ + public void setIsSuccess(Boolean isSuccess) { + this.isSuccess = isSuccess; + } + + /** + * Getter for databasir.operation_log.involved_project_id. ref + * to project.id + */ + public Integer getInvolvedProjectId() { + return this.involvedProjectId; + } + + /** + * Setter for databasir.operation_log.involved_project_id. ref + * to project.id + */ + public void setInvolvedProjectId(Integer involvedProjectId) { + this.involvedProjectId = involvedProjectId; + } + + /** + * Getter for databasir.operation_log.involved_group_id. ref to + * group.id + */ + public Integer getInvolvedGroupId() { + return this.involvedGroupId; + } + + /** + * Setter for databasir.operation_log.involved_group_id. ref to + * group.id + */ + public void setInvolvedGroupId(Integer involvedGroupId) { + this.involvedGroupId = involvedGroupId; + } + + /** + * Getter for databasir.operation_log.involved_user_id. ref to + * user.id + */ + public Integer getInvolvedUserId() { + return this.involvedUserId; + } + + /** + * Setter for databasir.operation_log.involved_user_id. ref to + * user.id + */ + public void setInvolvedUserId(Integer involvedUserId) { + this.involvedUserId = involvedUserId; + } + + /** + * Getter for databasir.operation_log.create_at. + */ + public LocalDateTime getCreateAt() { + return this.createAt; + } + + /** + * Setter for databasir.operation_log.create_at. + */ + public void setCreateAt(LocalDateTime createAt) { + this.createAt = createAt; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("OperationLogPojo ("); + + sb.append(id); + sb.append(", ").append(operatorUserId); + sb.append(", ").append(operatorUsername); + sb.append(", ").append(operatorNickname); + sb.append(", ").append(operationModule); + sb.append(", ").append(operationCode); + sb.append(", ").append(operationName); + sb.append(", ").append(operationResponse); + sb.append(", ").append(isSuccess); + sb.append(", ").append(involvedProjectId); + sb.append(", ").append(involvedGroupId); + sb.append(", ").append(involvedUserId); + sb.append(", ").append(createAt); + + sb.append(")"); + return sb.toString(); + } +} diff --git a/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/OperationLogRecord.java b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/OperationLogRecord.java new file mode 100644 index 0000000..b5f6094 --- /dev/null +++ b/dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/OperationLogRecord.java @@ -0,0 +1,590 @@ +/* + * This file is generated by jOOQ. + */ +package com.databasir.dao.tables.records; + + +import com.databasir.dao.tables.OperationLog; +import com.databasir.dao.tables.pojos.OperationLogPojo; + +import java.time.LocalDateTime; + +import org.jooq.Field; +import org.jooq.JSON; +import org.jooq.Record1; +import org.jooq.Record13; +import org.jooq.Row13; +import org.jooq.impl.UpdatableRecordImpl; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class OperationLogRecord extends UpdatableRecordImpl implements Record13 { + + private static final long serialVersionUID = 1L; + + /** + * Setter for databasir.operation_log.id. + */ + public void setId(Long value) { + set(0, value); + } + + /** + * Getter for databasir.operation_log.id. + */ + public Long getId() { + return (Long) get(0); + } + + /** + * Setter for databasir.operation_log.operator_user_id. ref to + * user.id + */ + public void setOperatorUserId(Integer value) { + set(1, value); + } + + /** + * Getter for databasir.operation_log.operator_user_id. ref to + * user.id + */ + public Integer getOperatorUserId() { + return (Integer) get(1); + } + + /** + * Setter for databasir.operation_log.operator_username. + * user.username + */ + public void setOperatorUsername(String value) { + set(2, value); + } + + /** + * Getter for databasir.operation_log.operator_username. + * user.username + */ + public String getOperatorUsername() { + return (String) get(2); + } + + /** + * Setter for databasir.operation_log.operator_nickname. + * user.nickname + */ + public void setOperatorNickname(String value) { + set(3, value); + } + + /** + * Getter for databasir.operation_log.operator_nickname. + * user.nickname + */ + public String getOperatorNickname() { + return (String) get(3); + } + + /** + * Setter for databasir.operation_log.operation_module. + */ + public void setOperationModule(String value) { + set(4, value); + } + + /** + * Getter for databasir.operation_log.operation_module. + */ + public String getOperationModule() { + return (String) get(4); + } + + /** + * Setter for databasir.operation_log.operation_code. + */ + public void setOperationCode(String value) { + set(5, value); + } + + /** + * Getter for databasir.operation_log.operation_code. + */ + public String getOperationCode() { + return (String) get(5); + } + + /** + * Setter for databasir.operation_log.operation_name. + */ + public void setOperationName(String value) { + set(6, value); + } + + /** + * Getter for databasir.operation_log.operation_name. + */ + public String getOperationName() { + return (String) get(6); + } + + /** + * Setter for databasir.operation_log.operation_response. + */ + public void setOperationResponse(JSON value) { + set(7, value); + } + + /** + * Getter for databasir.operation_log.operation_response. + */ + public JSON getOperationResponse() { + return (JSON) get(7); + } + + /** + * Setter for databasir.operation_log.is_success. + */ + public void setIsSuccess(Boolean value) { + set(8, value); + } + + /** + * Getter for databasir.operation_log.is_success. + */ + public Boolean getIsSuccess() { + return (Boolean) get(8); + } + + /** + * Setter for databasir.operation_log.involved_project_id. ref + * to project.id + */ + public void setInvolvedProjectId(Integer value) { + set(9, value); + } + + /** + * Getter for databasir.operation_log.involved_project_id. ref + * to project.id + */ + public Integer getInvolvedProjectId() { + return (Integer) get(9); + } + + /** + * Setter for databasir.operation_log.involved_group_id. ref to + * group.id + */ + public void setInvolvedGroupId(Integer value) { + set(10, value); + } + + /** + * Getter for databasir.operation_log.involved_group_id. ref to + * group.id + */ + public Integer getInvolvedGroupId() { + return (Integer) get(10); + } + + /** + * Setter for databasir.operation_log.involved_user_id. ref to + * user.id + */ + public void setInvolvedUserId(Integer value) { + set(11, value); + } + + /** + * Getter for databasir.operation_log.involved_user_id. ref to + * user.id + */ + public Integer getInvolvedUserId() { + return (Integer) get(11); + } + + /** + * Setter for databasir.operation_log.create_at. + */ + public void setCreateAt(LocalDateTime value) { + set(12, value); + } + + /** + * Getter for databasir.operation_log.create_at. + */ + public LocalDateTime getCreateAt() { + return (LocalDateTime) get(12); + } + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + @Override + public Record1 key() { + return (Record1) super.key(); + } + + // ------------------------------------------------------------------------- + // Record13 type implementation + // ------------------------------------------------------------------------- + + @Override + public Row13 fieldsRow() { + return (Row13) super.fieldsRow(); + } + + @Override + public Row13 valuesRow() { + return (Row13) super.valuesRow(); + } + + @Override + public Field field1() { + return OperationLog.OPERATION_LOG.ID; + } + + @Override + public Field field2() { + return OperationLog.OPERATION_LOG.OPERATOR_USER_ID; + } + + @Override + public Field field3() { + return OperationLog.OPERATION_LOG.OPERATOR_USERNAME; + } + + @Override + public Field field4() { + return OperationLog.OPERATION_LOG.OPERATOR_NICKNAME; + } + + @Override + public Field field5() { + return OperationLog.OPERATION_LOG.OPERATION_MODULE; + } + + @Override + public Field field6() { + return OperationLog.OPERATION_LOG.OPERATION_CODE; + } + + @Override + public Field field7() { + return OperationLog.OPERATION_LOG.OPERATION_NAME; + } + + @Override + public Field field8() { + return OperationLog.OPERATION_LOG.OPERATION_RESPONSE; + } + + @Override + public Field field9() { + return OperationLog.OPERATION_LOG.IS_SUCCESS; + } + + @Override + public Field field10() { + return OperationLog.OPERATION_LOG.INVOLVED_PROJECT_ID; + } + + @Override + public Field field11() { + return OperationLog.OPERATION_LOG.INVOLVED_GROUP_ID; + } + + @Override + public Field field12() { + return OperationLog.OPERATION_LOG.INVOLVED_USER_ID; + } + + @Override + public Field field13() { + return OperationLog.OPERATION_LOG.CREATE_AT; + } + + @Override + public Long component1() { + return getId(); + } + + @Override + public Integer component2() { + return getOperatorUserId(); + } + + @Override + public String component3() { + return getOperatorUsername(); + } + + @Override + public String component4() { + return getOperatorNickname(); + } + + @Override + public String component5() { + return getOperationModule(); + } + + @Override + public String component6() { + return getOperationCode(); + } + + @Override + public String component7() { + return getOperationName(); + } + + @Override + public JSON component8() { + return getOperationResponse(); + } + + @Override + public Boolean component9() { + return getIsSuccess(); + } + + @Override + public Integer component10() { + return getInvolvedProjectId(); + } + + @Override + public Integer component11() { + return getInvolvedGroupId(); + } + + @Override + public Integer component12() { + return getInvolvedUserId(); + } + + @Override + public LocalDateTime component13() { + return getCreateAt(); + } + + @Override + public Long value1() { + return getId(); + } + + @Override + public Integer value2() { + return getOperatorUserId(); + } + + @Override + public String value3() { + return getOperatorUsername(); + } + + @Override + public String value4() { + return getOperatorNickname(); + } + + @Override + public String value5() { + return getOperationModule(); + } + + @Override + public String value6() { + return getOperationCode(); + } + + @Override + public String value7() { + return getOperationName(); + } + + @Override + public JSON value8() { + return getOperationResponse(); + } + + @Override + public Boolean value9() { + return getIsSuccess(); + } + + @Override + public Integer value10() { + return getInvolvedProjectId(); + } + + @Override + public Integer value11() { + return getInvolvedGroupId(); + } + + @Override + public Integer value12() { + return getInvolvedUserId(); + } + + @Override + public LocalDateTime value13() { + return getCreateAt(); + } + + @Override + public OperationLogRecord value1(Long value) { + setId(value); + return this; + } + + @Override + public OperationLogRecord value2(Integer value) { + setOperatorUserId(value); + return this; + } + + @Override + public OperationLogRecord value3(String value) { + setOperatorUsername(value); + return this; + } + + @Override + public OperationLogRecord value4(String value) { + setOperatorNickname(value); + return this; + } + + @Override + public OperationLogRecord value5(String value) { + setOperationModule(value); + return this; + } + + @Override + public OperationLogRecord value6(String value) { + setOperationCode(value); + return this; + } + + @Override + public OperationLogRecord value7(String value) { + setOperationName(value); + return this; + } + + @Override + public OperationLogRecord value8(JSON value) { + setOperationResponse(value); + return this; + } + + @Override + public OperationLogRecord value9(Boolean value) { + setIsSuccess(value); + return this; + } + + @Override + public OperationLogRecord value10(Integer value) { + setInvolvedProjectId(value); + return this; + } + + @Override + public OperationLogRecord value11(Integer value) { + setInvolvedGroupId(value); + return this; + } + + @Override + public OperationLogRecord value12(Integer value) { + setInvolvedUserId(value); + return this; + } + + @Override + public OperationLogRecord value13(LocalDateTime value) { + setCreateAt(value); + return this; + } + + @Override + public OperationLogRecord values(Long value1, Integer value2, String value3, String value4, String value5, String value6, String value7, JSON value8, Boolean value9, Integer value10, Integer value11, Integer value12, LocalDateTime value13) { + value1(value1); + value2(value2); + value3(value3); + value4(value4); + value5(value5); + value6(value6); + value7(value7); + value8(value8); + value9(value9); + value10(value10); + value11(value11); + value12(value12); + value13(value13); + return this; + } + + // ------------------------------------------------------------------------- + // Constructors + // ------------------------------------------------------------------------- + + /** + * Create a detached OperationLogRecord + */ + public OperationLogRecord() { + super(OperationLog.OPERATION_LOG); + } + + /** + * Create a detached, initialised OperationLogRecord + */ + public OperationLogRecord(Long id, Integer operatorUserId, String operatorUsername, String operatorNickname, String operationModule, String operationCode, String operationName, JSON operationResponse, Boolean isSuccess, Integer involvedProjectId, Integer involvedGroupId, Integer involvedUserId, LocalDateTime createAt) { + super(OperationLog.OPERATION_LOG); + + setId(id); + setOperatorUserId(operatorUserId); + setOperatorUsername(operatorUsername); + setOperatorNickname(operatorNickname); + setOperationModule(operationModule); + setOperationCode(operationCode); + setOperationName(operationName); + setOperationResponse(operationResponse); + setIsSuccess(isSuccess); + setInvolvedProjectId(involvedProjectId); + setInvolvedGroupId(involvedGroupId); + setInvolvedUserId(involvedUserId); + setCreateAt(createAt); + } + + /** + * Create a detached, initialised OperationLogRecord + */ + public OperationLogRecord(OperationLogPojo value) { + super(OperationLog.OPERATION_LOG); + + if (value != null) { + setId(value.getId()); + setOperatorUserId(value.getOperatorUserId()); + setOperatorUsername(value.getOperatorUsername()); + setOperatorNickname(value.getOperatorNickname()); + setOperationModule(value.getOperationModule()); + setOperationCode(value.getOperationCode()); + setOperationName(value.getOperationName()); + setOperationResponse(value.getOperationResponse()); + setIsSuccess(value.getIsSuccess()); + setInvolvedProjectId(value.getInvolvedProjectId()); + setInvolvedGroupId(value.getInvolvedGroupId()); + setInvolvedUserId(value.getInvolvedUserId()); + setCreateAt(value.getCreateAt()); + } + } +} diff --git a/dao/src/main/java/com/databasir/dao/impl/BaseDao.java b/dao/src/main/java/com/databasir/dao/impl/BaseDao.java index 961fe53..0f16889 100644 --- a/dao/src/main/java/com/databasir/dao/impl/BaseDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/BaseDao.java @@ -2,72 +2,75 @@ package com.databasir.dao.impl; import com.databasir.dao.exception.DataNotExistsException; -import lombok.RequiredArgsConstructor; import org.jooq.*; -import org.jooq.Record; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; -@RequiredArgsConstructor -public abstract class BaseDao { +public abstract class BaseDao { - private final Table table; + private final Table table; - private final Class pojoType; + private final Class pojoType; + + public BaseDao(Table table, Class pojoType) { + this.table = table; + this.pojoType = pojoType; + } public abstract DSLContext getDslContext(); - public boolean existsById(Integer id) { + public boolean existsById(T id) { return getDslContext().fetchExists(table, identity().eq(id)); } - public Integer insertAndReturnId(R pojo) { - T record = getDslContext().newRecord(table, pojo); + public T insertAndReturnId(PO pojo) { + Record record = getDslContext().newRecord(table, pojo); UpdatableRecord updatableRecord = (UpdatableRecord) record; updatableRecord.store(); Object value = updatableRecord.getValue(table.getIdentity().getField()); - return (Integer) value; + return (T) identityType().cast(value); } - public int batchInsert(Collection pojoList) { + public int batchInsert(Collection pojoList) { List> records = pojoList.stream() .map(pojo -> { - T record = getDslContext().newRecord(table, pojo); + Record record = getDslContext().newRecord(table, pojo); return (TableRecord) record; }) .collect(Collectors.toList()); return Arrays.stream(getDslContext().batchInsert(records).execute()).sum(); } - public int deleteById(Integer id) { + public int deleteById(T id) { return getDslContext() .deleteFrom(table).where(identity().eq(id)) .execute(); } - public int updateById(R pojo) { - T record = getDslContext().newRecord(table, pojo); + public int updateById(PO pojo) { + Record record = getDslContext().newRecord(table, pojo); record.changed(table.getIdentity().getField(), false); return getDslContext().executeUpdate((UpdatableRecord) record); } - public Optional selectOptionalById(Integer id) { + public Optional selectOptionalById(T id) { return getDslContext() .select(table.fields()).from(table).where(identity().eq(id)) .fetchOptionalInto(pojoType); } - public R selectById(Integer id) { + public PO selectById(T id) { return selectOptionalById(id) .orElseThrow(() -> new DataNotExistsException("data not exists in " + table.getName() + " with id = " + id)); } - public List selectInIds(List ids) { + public List selectInIds(List ids) { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } @@ -77,12 +80,12 @@ public abstract class BaseDao { .fetchInto(pojoType); } - public Page selectByPage(Pageable request, Condition condition) { + public Page selectByPage(Pageable request, Condition condition) { Integer count = getDslContext() .selectCount().from(table).where(condition) .fetchOne(0, int.class); int total = count == null ? 0 : count; - List data = getDslContext() + List data = getDslContext() .selectFrom(table).where(condition) .orderBy(getSortFields(request.getSort())) .offset(request.getOffset()).limit(request.getPageSize()) @@ -110,15 +113,19 @@ public abstract class BaseDao { return querySortFields; } - protected Field identity() { - Identity identity = table.getIdentity(); + protected Field identity() { + Identity identity = table.getIdentity(); if (identity == null) { throw new IllegalStateException("can not find identity column in " + table.getName()); } - return identity.getField().cast(Integer.class); + return identity.getField().cast(identityType()); } - protected Table table() { + protected Class identityType() { + return (Class) Integer.class; + } + + protected Table table() { return this.table; } } diff --git a/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java b/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java index ae4bab4..217574a 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java @@ -16,7 +16,7 @@ import static com.databasir.dao.Tables.DATA_SOURCE; @Repository -public class DataSourceDao extends BaseDao { +public class DataSourceDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java b/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java index 9c2d1bc..99eccc7 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.DataSourcePropertyPojo; -import com.databasir.dao.tables.records.DataSourcePropertyRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.DATA_SOURCE_PROPERTY; @Repository -public class DataSourcePropertyDao extends BaseDao { +public class DataSourcePropertyDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java index b9e24de..6732561 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java @@ -13,7 +13,7 @@ import static com.databasir.dao.Tables.DATABASE_DOCUMENT; @Repository -public class DatabaseDocumentDao extends BaseDao { +public class DatabaseDocumentDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java index f088b1b..4fa97d1 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.DatabaseDocumentHistoryPojo; -import com.databasir.dao.tables.records.DatabaseDocumentHistoryRecord; import com.databasir.dao.value.DatabaseDocumentVersionPojo; import lombok.Getter; import org.jooq.Condition; @@ -19,7 +18,7 @@ import static com.databasir.dao.Tables.DATABASE_DOCUMENT_HISTORY; @Repository -public class DatabaseDocumentHistoryDao extends BaseDao { +public class DatabaseDocumentHistoryDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java b/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java index 7852ed2..0e6d958 100644 --- a/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java @@ -1,7 +1,6 @@ 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; @@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.DOCUMENT_REMARK; @Repository -public class DocumentRemarkDao extends BaseDao { +public class DocumentRemarkDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/GroupDao.java b/dao/src/main/java/com/databasir/dao/impl/GroupDao.java index e0f1340..b996f7d 100644 --- a/dao/src/main/java/com/databasir/dao/impl/GroupDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/GroupDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.GroupPojo; -import com.databasir.dao.tables.records.GroupRecord; import lombok.Getter; import org.jooq.Condition; import org.jooq.DSLContext; @@ -10,6 +9,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import java.io.Serializable; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -17,7 +17,7 @@ import java.util.Optional; import static com.databasir.dao.Tables.GROUP; @Repository -public class GroupDao extends BaseDao { +public class GroupDao extends BaseDao { @Autowired @Getter @@ -27,10 +27,11 @@ public class GroupDao extends BaseDao { super(GROUP, GroupPojo.class); } + @Override - public int deleteById(Integer id) { + public int deleteById(T id) { return dslContext - .update(table()).set(GROUP.DELETED, true).where(GROUP.ID.eq(id)) + .update(table()).set(GROUP.DELETED, true).where(GROUP.ID.eq((Integer) id)) .execute(); } @@ -40,14 +41,14 @@ public class GroupDao extends BaseDao { } @Override - public Optional selectOptionalById(Integer id) { + public Optional selectOptionalById(T id) { return getDslContext() - .select(GROUP.fields()).from(GROUP).where(GROUP.ID.eq(id).and(GROUP.DELETED.eq(false))) + .select(GROUP.fields()).from(GROUP).where(GROUP.ID.eq((Integer) id).and(GROUP.DELETED.eq(false))) .fetchOptionalInto(GroupPojo.class); } @Override - public List selectInIds(List ids) { + public List selectInIds(List ids) { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } diff --git a/dao/src/main/java/com/databasir/dao/impl/LoginDao.java b/dao/src/main/java/com/databasir/dao/impl/LoginDao.java index f3d870b..972e3a6 100644 --- a/dao/src/main/java/com/databasir/dao/impl/LoginDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/LoginDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.LoginPojo; -import com.databasir.dao.tables.records.LoginRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -14,7 +13,7 @@ import static com.databasir.dao.Tables.LOGIN; @Repository -public class LoginDao extends BaseDao { +public class LoginDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/OperationLogDao.java b/dao/src/main/java/com/databasir/dao/impl/OperationLogDao.java new file mode 100644 index 0000000..b700409 --- /dev/null +++ b/dao/src/main/java/com/databasir/dao/impl/OperationLogDao.java @@ -0,0 +1,28 @@ +package com.databasir.dao.impl; + +import com.databasir.dao.tables.pojos.OperationLogPojo; +import lombok.Getter; +import org.jooq.DSLContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.io.Serializable; + +import static com.databasir.dao.Tables.OPERATION_LOG; + +@Repository +public class OperationLogDao extends BaseDao { + + @Autowired + @Getter + private DSLContext dslContext; + + public OperationLogDao() { + super(OPERATION_LOG, OperationLogPojo.class); + } + + @Override + protected Class identityType() { + return (Class) Long.class; + } +} \ No newline at end of file diff --git a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java index 7e59940..bf0f9a9 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.ProjectPojo; -import com.databasir.dao.tables.records.ProjectRecord; import com.databasir.dao.value.GroupProjectCountPojo; import lombok.Getter; import org.jooq.Condition; @@ -12,6 +11,7 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; +import java.io.Serializable; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -22,7 +22,7 @@ import static com.databasir.dao.Tables.PROJECT; @Repository -public class ProjectDao extends BaseDao { +public class ProjectDao extends BaseDao { @Autowired @Getter @@ -39,7 +39,7 @@ public class ProjectDao extends BaseDao { } @Override - public Optional selectOptionalById(Integer id) { + public Optional selectOptionalById(T id) { return getDslContext() .select(PROJECT.fields()).from(PROJECT) .where(identity().eq(id).and(PROJECT.DELETED.eq(false))) @@ -47,7 +47,7 @@ public class ProjectDao extends BaseDao { } @Override - public boolean existsById(Integer id) { + public boolean existsById(T id) { return getDslContext().fetchExists(table(), identity().eq(id).and(PROJECT.DELETED.eq(false))); } diff --git a/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java b/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java index 06a3f3e..b347d00 100644 --- a/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java @@ -16,7 +16,7 @@ import java.util.Optional; import static com.databasir.dao.Tables.PROJECT_SYNC_RULE; @Repository -public class ProjectSyncRuleDao extends BaseDao { +public class ProjectSyncRuleDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/SysKeyDao.java b/dao/src/main/java/com/databasir/dao/impl/SysKeyDao.java index 0a4a94b..60790f0 100644 --- a/dao/src/main/java/com/databasir/dao/impl/SysKeyDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/SysKeyDao.java @@ -2,7 +2,6 @@ package com.databasir.dao.impl; import com.databasir.dao.exception.DataNotExistsException; import com.databasir.dao.tables.pojos.SysKeyPojo; -import com.databasir.dao.tables.records.SysKeyRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +12,7 @@ import java.util.Optional; import static com.databasir.dao.Tables.SYS_KEY; @Repository -public class SysKeyDao extends BaseDao { +public class SysKeyDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/SysMailDao.java b/dao/src/main/java/com/databasir/dao/impl/SysMailDao.java index 80c729e..2452043 100644 --- a/dao/src/main/java/com/databasir/dao/impl/SysMailDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/SysMailDao.java @@ -13,7 +13,7 @@ import java.util.Optional; import static com.databasir.dao.Tables.SYS_MAIL; @Repository -public class SysMailDao extends BaseDao { +public class SysMailDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java index 04414ef..ce14aaf 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.TableColumnDocumentPojo; -import com.databasir.dao.tables.records.TableColumnDocumentRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT; @Repository -public class TableColumnDocumentDao extends BaseDao { +public class TableColumnDocumentDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java index a95bdbd..dbed662 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.TableDocumentPojo; -import com.databasir.dao.tables.records.TableDocumentRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -12,7 +11,7 @@ import java.util.List; import static com.databasir.dao.Tables.TABLE_DOCUMENT; @Repository -public class TableDocumentDao extends BaseDao { +public class TableDocumentDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java index 7f741ed..7eeb1f0 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.TableIndexDocumentPojo; -import com.databasir.dao.tables.records.TableIndexDocumentRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT; @Repository -public class TableIndexDocumentDao extends BaseDao { +public class TableIndexDocumentDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java b/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java index 2351984..ee761a8 100644 --- a/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.TableTriggerDocumentPojo; -import com.databasir.dao.tables.records.TableTriggerDocumentRecord; import lombok.Getter; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; @@ -12,7 +11,7 @@ import java.util.List; import static com.databasir.dao.Tables.TABLE_TRIGGER_DOCUMENT; @Repository -public class TableTriggerDocumentDao extends BaseDao { +public class TableTriggerDocumentDao extends BaseDao { @Autowired @Getter 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 97b0442..0ba5db4 100644 --- a/dao/src/main/java/com/databasir/dao/impl/UserDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/UserDao.java @@ -2,7 +2,6 @@ package com.databasir.dao.impl; import com.databasir.dao.Databasir; import com.databasir.dao.tables.pojos.UserPojo; -import com.databasir.dao.tables.records.UserRecord; import com.databasir.dao.value.GroupMemberDetailPojo; import lombok.Getter; import org.jooq.Condition; @@ -23,7 +22,7 @@ import static com.databasir.dao.Tables.USER_ROLE; @Repository -public class UserDao extends BaseDao { +public class UserDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java b/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java index 706ec76..606fa37 100644 --- a/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java +++ b/dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java @@ -1,7 +1,6 @@ package com.databasir.dao.impl; import com.databasir.dao.tables.pojos.UserRolePojo; -import com.databasir.dao.tables.records.UserRoleRecord; import com.databasir.dao.value.GroupMemberSimplePojo; import lombok.Getter; import org.jooq.Condition; @@ -19,7 +18,7 @@ import static com.databasir.dao.Tables.USER_ROLE; @Repository -public class UserRoleDao extends BaseDao { +public class UserRoleDao extends BaseDao { @Autowired @Getter diff --git a/dao/src/main/resources/db/migration/V1.2__operation_log.sql b/dao/src/main/resources/db/migration/V1.2__operation_log.sql new file mode 100644 index 0000000..2ae7a05 --- /dev/null +++ b/dao/src/main/resources/db/migration/V1.2__operation_log.sql @@ -0,0 +1,18 @@ +CREATE TABLE operation_log +( + id BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL, + + operator_user_id INT NOT NULL COMMENT 'ref to user.id', + operator_username VARCHAR(128) NOT NULL COMMENT 'user.username', + operator_nickname VARCHAR(255) NOT NULL COMMENT 'user.nickname', + operation_module VARCHAR(128) NOT NULL, + operation_code VARCHAR(255) NOT NULL, + operation_name VARCHAR(255) NOT NULL, + operation_response JSON NOT NULL, + is_success BOOLEAN NOT NULL DEFAULT FALSE, + involved_project_id INT DEFAULT NULL COMMENT 'ref to project.id', + involved_group_id INT DEFAULT NULL COMMENT 'ref to group.id', + involved_user_id INT DEFAULT NULL COMMENT 'ref to user.id', + create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +) CHARSET utf8mb4 + COLLATE utf8mb4_unicode_ci;