Browse Source

Feature: add operation log (#16)

* feat: auto record operation log

* feat: add list project operation log api

* feat: update frontend resource
master
vran 3 years ago
committed by GitHub
parent
commit
2ed115d070
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      api/src/main/java/com/databasir/api/DocumentController.java
  2. 7
      api/src/main/java/com/databasir/api/DocumentRemarkController.java
  3. 20
      api/src/main/java/com/databasir/api/GroupController.java
  4. 2
      api/src/main/java/com/databasir/api/LoginController.java
  5. 30
      api/src/main/java/com/databasir/api/OperationLogController.java
  6. 12
      api/src/main/java/com/databasir/api/ProjectController.java
  7. 4
      api/src/main/java/com/databasir/api/Routes.java
  8. 2
      api/src/main/java/com/databasir/api/SettingController.java
  9. 9
      api/src/main/java/com/databasir/api/UserController.java
  10. 117
      api/src/main/java/com/databasir/api/advice/OperationLogAspect.java
  11. 36
      api/src/main/java/com/databasir/job/ProjectDocumentAutoSyncJob.java
  12. BIN
      api/src/main/resources/static/.DS_Store
  13. 0
      api/src/main/resources/static/css/app.36ecf611.css
  14. 0
      api/src/main/resources/static/css/chunk-04ac1c26.00ac37b1.css
  15. 0
      api/src/main/resources/static/css/chunk-7e394785.e51aa148.css
  16. 0
      api/src/main/resources/static/css/chunk-7fa689fe.80a92238.css
  17. 0
      api/src/main/resources/static/css/chunk-c2109158.06814884.css
  18. 2
      api/src/main/resources/static/index.html
  19. 4
      api/src/main/resources/static/js/app.7a0ffda3.js
  20. 2
      api/src/main/resources/static/js/app.7a0ffda3.js.map
  21. 1
      api/src/main/resources/static/js/chunk-04ac1c26.b03a6105.js.map
  22. 2
      api/src/main/resources/static/js/chunk-04ac1c26.b5c879b8.js
  23. 1
      api/src/main/resources/static/js/chunk-04ac1c26.b5c879b8.js.map
  24. 2
      api/src/main/resources/static/js/chunk-2d0cc811.c5d1ef9e.js
  25. 1
      api/src/main/resources/static/js/chunk-2d0cc811.c5d1ef9e.js.map
  26. 1
      api/src/main/resources/static/js/chunk-2d0cc811.feb081c8.js.map
  27. 2
      api/src/main/resources/static/js/chunk-48cebeac.162363c9.js
  28. 1
      api/src/main/resources/static/js/chunk-48cebeac.162363c9.js.map
  29. 1
      api/src/main/resources/static/js/chunk-48cebeac.b43a95b4.js.map
  30. 2
      api/src/main/resources/static/js/chunk-4fd080e4.d40c8d0d.js
  31. 1
      api/src/main/resources/static/js/chunk-4fd080e4.d40c8d0d.js.map
  32. 1
      api/src/main/resources/static/js/chunk-7e394785.b93f6d8c.js.map
  33. 2
      api/src/main/resources/static/js/chunk-7e394785.e090ef46.js
  34. 1
      api/src/main/resources/static/js/chunk-7e394785.e090ef46.js.map
  35. 2
      api/src/main/resources/static/js/chunk-7fa689fe.337b34fc.js
  36. 1
      api/src/main/resources/static/js/chunk-7fa689fe.337b34fc.js.map
  37. 1
      api/src/main/resources/static/js/chunk-7fa689fe.e971bfe1.js.map
  38. 2
      api/src/main/resources/static/js/chunk-abb10c56.4c323350.js
  39. 1
      api/src/main/resources/static/js/chunk-abb10c56.4c323350.js.map
  40. 2
      api/src/main/resources/static/js/chunk-abb10c56.bd8d31bf.js
  41. 1
      api/src/main/resources/static/js/chunk-abb10c56.bd8d31bf.js.map
  42. 2
      api/src/main/resources/static/js/chunk-c2109158.94b6c554.js
  43. 1
      api/src/main/resources/static/js/chunk-c2109158.94b6c554.js.map
  44. 2
      api/src/main/resources/static/js/chunk-fffb1b64.1ffb9f27.js
  45. 1
      api/src/main/resources/static/js/chunk-fffb1b64.1ffb9f27.js.map
  46. 1
      api/src/main/resources/static/js/chunk-fffb1b64.df1e960f.js.map
  47. 2
      api/src/main/resources/static/js/chunk-vendors.8b5336af.js.map
  48. 42
      core/src/main/java/com/databasir/core/domain/log/annotation/Operation.java
  49. 13
      core/src/main/java/com/databasir/core/domain/log/converter/OperationLogPojoConverter.java
  50. 13
      core/src/main/java/com/databasir/core/domain/log/converter/OperationLogRequestConverter.java
  51. 55
      core/src/main/java/com/databasir/core/domain/log/data/OperationLogPageCondition.java
  52. 39
      core/src/main/java/com/databasir/core/domain/log/data/OperationLogPageResponse.java
  53. 32
      core/src/main/java/com/databasir/core/domain/log/data/OperationLogRequest.java
  54. 35
      core/src/main/java/com/databasir/core/domain/log/service/OperationLogService.java
  55. 42
      core/src/main/java/com/databasir/core/infrastructure/converter/JsonConverter.java
  56. 7
      dao/generated-src/jooq/main/java/com/databasir/dao/Databasir.java
  57. 3
      dao/generated-src/jooq/main/java/com/databasir/dao/Keys.java
  58. 6
      dao/generated-src/jooq/main/java/com/databasir/dao/Tables.java
  59. 204
      dao/generated-src/jooq/main/java/com/databasir/dao/tables/OperationLog.java
  60. 298
      dao/generated-src/jooq/main/java/com/databasir/dao/tables/pojos/OperationLogPojo.java
  61. 590
      dao/generated-src/jooq/main/java/com/databasir/dao/tables/records/OperationLogRecord.java
  62. 55
      dao/src/main/java/com/databasir/dao/impl/BaseDao.java
  63. 2
      dao/src/main/java/com/databasir/dao/impl/DataSourceDao.java
  64. 3
      dao/src/main/java/com/databasir/dao/impl/DataSourcePropertyDao.java
  65. 2
      dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentDao.java
  66. 3
      dao/src/main/java/com/databasir/dao/impl/DatabaseDocumentHistoryDao.java
  67. 3
      dao/src/main/java/com/databasir/dao/impl/DocumentRemarkDao.java
  68. 15
      dao/src/main/java/com/databasir/dao/impl/GroupDao.java
  69. 3
      dao/src/main/java/com/databasir/dao/impl/LoginDao.java
  70. 28
      dao/src/main/java/com/databasir/dao/impl/OperationLogDao.java
  71. 8
      dao/src/main/java/com/databasir/dao/impl/ProjectDao.java
  72. 2
      dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java
  73. 3
      dao/src/main/java/com/databasir/dao/impl/SysKeyDao.java
  74. 2
      dao/src/main/java/com/databasir/dao/impl/SysMailDao.java
  75. 3
      dao/src/main/java/com/databasir/dao/impl/TableColumnDocumentDao.java
  76. 3
      dao/src/main/java/com/databasir/dao/impl/TableDocumentDao.java
  77. 3
      dao/src/main/java/com/databasir/dao/impl/TableIndexDocumentDao.java
  78. 3
      dao/src/main/java/com/databasir/dao/impl/TableTriggerDocumentDao.java
  79. 3
      dao/src/main/java/com/databasir/dao/impl/UserDao.java
  80. 3
      dao/src/main/java/com/databasir/dao/impl/UserRoleDao.java
  81. 18
      dao/src/main/resources/db/migration/V1.2__operation_log.sql

2
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<Void> sync(@PathVariable Integer projectId) {
documentService.syncByProjectId(projectId);
return JsonData.ok();

7
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<Void> 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<Void> create(@PathVariable Integer groupId,
@PathVariable Integer projectId,
@RequestBody @Valid RemarkCreateRequest request) {

20
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<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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<Void> updateGroupMemberRole(@PathVariable Integer groupId,
@PathVariable Integer userId,
@RequestBody GroupMemberRoleUpdateRequest request) {

2
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<Void> logout() {
SecurityContextHolder.clearContext();
return JsonData.ok();

30
api/src/main/java/com/databasir/api/OperationLogController.java

@ -0,0 +1,30 @@
package com.databasir.api;
import com.databasir.common.JsonData;
import com.databasir.core.domain.log.data.OperationLogPageCondition;
import com.databasir.core.domain.log.data.OperationLogPageResponse;
import com.databasir.core.domain.log.service.OperationLogService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@Validated
public class OperationLogController {
private final OperationLogService operationLogService;
@GetMapping(Routes.OperationLog.LIST)
public JsonData<Page<OperationLogPageResponse>> list(@PageableDefault(sort = "id", direction = Sort.Direction.DESC)
Pageable page,
OperationLogPageCondition condition) {
Page<OperationLogPageResponse> pageData = operationLogService.list(page, condition);
return JsonData.ok(pageData);
}
}

12
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<Void> 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<Void> 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<Void> delete(@PathVariable Integer groupId,
@PathVariable Integer projectId) {
projectService.delete(projectId);

4
api/src/main/java/com/databasir/api/Routes.java

@ -94,4 +94,8 @@ public interface Routes {
String REFRESH_ACCESS_TOKEN = "/access_tokens";
}
interface OperationLog {
String LIST = BASE + "/operation_logs";
}
}

2
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<Void> updateSystemEmailSetting(@RequestBody @Valid SystemEmailUpdateRequest request) {
systemService.updateEmailSetting(request);
return JsonData.ok();

9
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<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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<Void> updateNickname(@PathVariable Integer userId,
@RequestBody @Valid UserNicknameUpdateRequest request) {
if (userOperationValidator.isMyself(userId)) {

117
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<Object>) 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<Object> 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 <T> Optional<T> getValueBySPEL(Method method,
Object[] arguments,
String expression,
Class<T> 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();
}
}
}

36
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");
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;
}
}
}

BIN
api/src/main/resources/static/.DS_Store

Binary file not shown.

0
api/src/main/resources/static/css/app.df19208c.css → api/src/main/resources/static/css/app.36ecf611.css

0
api/src/main/resources/static/css/chunk-04ac1c26.a5cbc9e6.css → api/src/main/resources/static/css/chunk-04ac1c26.00ac37b1.css

0
api/src/main/resources/static/css/chunk-7e394785.ab54ac4c.css → api/src/main/resources/static/css/chunk-7e394785.e51aa148.css

0
api/src/main/resources/static/css/chunk-7fa689fe.a79c1787.css → api/src/main/resources/static/css/chunk-7fa689fe.80a92238.css

0
api/src/main/resources/static/css/chunk-4fd080e4.a5b9f9ad.css → api/src/main/resources/static/css/chunk-c2109158.06814884.css

2
api/src/main/resources/static/index.html

@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><link href="/css/chunk-04ac1c26.a5cbc9e6.css" rel="prefetch"><link href="/css/chunk-4fd080e4.a5b9f9ad.css" rel="prefetch"><link href="/css/chunk-7e394785.ab54ac4c.css" rel="prefetch"><link href="/css/chunk-7fa689fe.a79c1787.css" rel="prefetch"><link href="/js/chunk-04ac1c26.b03a6105.js" rel="prefetch"><link href="/js/chunk-2d0cc811.feb081c8.js" rel="prefetch"><link href="/js/chunk-48cebeac.b43a95b4.js" rel="prefetch"><link href="/js/chunk-4fd080e4.d40c8d0d.js" rel="prefetch"><link href="/js/chunk-7e394785.b93f6d8c.js" rel="prefetch"><link href="/js/chunk-7fa689fe.e971bfe1.js" rel="prefetch"><link href="/js/chunk-abb10c56.4c323350.js" rel="prefetch"><link href="/js/chunk-fffb1b64.df1e960f.js" rel="prefetch"><link href="/css/app.df19208c.css" rel="preload" as="style"><link href="/css/chunk-vendors.d4aa889d.css" rel="preload" as="style"><link href="/js/app.943c1753.js" rel="preload" as="script"><link href="/js/chunk-vendors.8b5336af.js" rel="preload" as="script"><link href="/css/chunk-vendors.d4aa889d.css" rel="stylesheet"><link href="/css/app.df19208c.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.8b5336af.js"></script><script src="/js/app.943c1753.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><link href="/css/chunk-04ac1c26.00ac37b1.css" rel="prefetch"><link href="/css/chunk-7e394785.e51aa148.css" rel="prefetch"><link href="/css/chunk-7fa689fe.80a92238.css" rel="prefetch"><link href="/css/chunk-c2109158.06814884.css" rel="prefetch"><link href="/js/chunk-04ac1c26.b5c879b8.js" rel="prefetch"><link href="/js/chunk-2d0cc811.c5d1ef9e.js" rel="prefetch"><link href="/js/chunk-48cebeac.162363c9.js" rel="prefetch"><link href="/js/chunk-7e394785.e090ef46.js" rel="prefetch"><link href="/js/chunk-7fa689fe.337b34fc.js" rel="prefetch"><link href="/js/chunk-abb10c56.bd8d31bf.js" rel="prefetch"><link href="/js/chunk-c2109158.94b6c554.js" rel="prefetch"><link href="/js/chunk-fffb1b64.1ffb9f27.js" rel="prefetch"><link href="/css/app.36ecf611.css" rel="preload" as="style"><link href="/css/chunk-vendors.d4aa889d.css" rel="preload" as="style"><link href="/js/app.7a0ffda3.js" rel="preload" as="script"><link href="/js/chunk-vendors.8b5336af.js" rel="preload" as="script"><link href="/css/chunk-vendors.d4aa889d.css" rel="stylesheet"><link href="/css/app.36ecf611.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.8b5336af.js"></script><script src="/js/app.7a0ffda3.js"></script></body></html>

4
api/src/main/resources/static/js/app.943c1753.js → api/src/main/resources/static/js/app.7a0ffda3.js

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/app.943c1753.js.map → api/src/main/resources/static/js/app.7a0ffda3.js.map

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-04ac1c26.b03a6105.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-04ac1c26.b03a6105.js → api/src/main/resources/static/js/chunk-04ac1c26.b5c879b8.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-04ac1c26.b5c879b8.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-2d0cc811.feb081c8.js → api/src/main/resources/static/js/chunk-2d0cc811.c5d1ef9e.js

@ -1,2 +1,2 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0cc811"],{"4de0":function(e,t,r){"use strict";r.r(t);var n=r("7a23"),o=Object(n["createTextVNode"])(" : "),u=Object(n["createTextVNode"])("保存");function l(e,t,r,l,a,c){var s=Object(n["resolveComponent"])("el-input"),i=Object(n["resolveComponent"])("el-form-item"),d=Object(n["resolveComponent"])("el-col"),m=Object(n["resolveComponent"])("el-button"),f=Object(n["resolveComponent"])("el-form"),p=Object(n["resolveComponent"])("el-card"),b=Object(n["resolveComponent"])("el-main"),j=Object(n["resolveComponent"])("el-container");return Object(n["openBlock"])(),Object(n["createBlock"])(j,null,{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(b,null,{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(p,null,{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(f,{model:a.form,"label-position":"top",rules:a.formRule,ref:"formRef",style:{"max-width":"900px"}},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(i,{label:"邮箱账号",prop:"username"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.username,"onUpdate:modelValue":t[0]||(t[0]=function(e){return a.form.username=e})},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(i,{label:"邮箱密码",prop:"password"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.password,"onUpdate:modelValue":t[1]||(t[1]=function(e){return a.form.password=e}),type:"password",placeholder:"请输入密码","show-password":""},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(i,{label:"SMTP",prop:"smtpHost"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(d,{span:12},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.smtpHost,"onUpdate:modelValue":t[2]||(t[2]=function(e){return a.form.smtpHost=e}),placeholder:"SMTP Host"},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(d,{span:1,style:{"text-align":"center"}},{default:Object(n["withCtx"])((function(){return[o]})),_:1}),Object(n["createVNode"])(d,{span:6},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.smtpPort,"onUpdate:modelValue":t[3]||(t[3]=function(e){return a.form.smtpPort=e}),placeholder:"SMTP Port"},null,8,["modelValue"])]})),_:1})]})),_:1}),Object(n["createVNode"])(i,{style:{"margin-top":"38px"}},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(m,{type:"primary",onClick:t[4]||(t[4]=function(e){return c.onSubmit("formRef")})},{default:Object(n["withCtx"])((function(){return[u]})),_:1})]})),_:1})]})),_:1},8,["model","rules"])]})),_:1})]})),_:1})]})),_:1})}var a=r("1da1"),c=(r("96cf"),r("1c1e")),s="/api/v1.0/settings",i=function(){return c["a"].get(s+"/sys_email")},d=function(e){return c["a"].post(s+"/sys_email",e)},m={data:function(){return{form:{smtpHost:null,smtpPort:null,username:null,password:null},formRule:{username:[this.requiredInputValidRule("请输入邮箱账号"),{type:"email",message:"邮箱格式不正确",trigger:"blur"}],password:[this.requiredInputValidRule("请输入邮箱密码")],smtpHost:[this.requiredInputValidRule("请输入 SMTP 地址")],smtpPort:[this.requiredInputValidRule("请输入 SMTP 端口"),{min:1,max:65535,message:"端口有效值为 1~65535",trigger:"blur"}]}}},mounted:function(){this.fetchSysMail()},methods:{requiredInputValidRule:function(e){return{required:!0,message:e,trigger:"blur"}},fetchSysMail:function(){var e=this;return Object(a["a"])(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,i().then((function(e){return e.data}));case 2:r=t.sent,r&&(e.form=r);case 4:case"end":return t.stop()}}),t)})))()},onSubmit:function(){var e=this;this.$refs.formRef.validate((function(t){return t?(d(e.form).then((function(t){t.errCode||e.$message.success("更新成功")})),!0):(e.$message.error("请完善表单相关信息!"),!1)}))}}},f=r("6b0d"),p=r.n(f);const b=p()(m,[["render",l]]);t["default"]=b}}]);
//# sourceMappingURL=chunk-2d0cc811.feb081c8.js.map
//# sourceMappingURL=chunk-2d0cc811.c5d1ef9e.js.map

1
api/src/main/resources/static/js/chunk-2d0cc811.c5d1ef9e.js.map

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-2d0cc811.feb081c8.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-48cebeac.b43a95b4.js → api/src/main/resources/static/js/chunk-48cebeac.162363c9.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-48cebeac.162363c9.js.map

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-48cebeac.b43a95b4.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-4fd080e4.d40c8d0d.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-4fd080e4.d40c8d0d.js.map

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-7e394785.b93f6d8c.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-7e394785.b93f6d8c.js → api/src/main/resources/static/js/chunk-7e394785.e090ef46.js

@ -1,2 +1,2 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-7e394785"],{a55b:function(e,t,n){"use strict";n.r(t);var o=n("7a23"),r={class:"login-card"},c=Object(o["createElementVNode"])("h1",null,"Databasir",-1),a=Object(o["createTextVNode"])(" 登录 "),u=Object(o["createTextVNode"])(" 忘记密码? ");function l(e,t,n,l,i,d){var s=Object(o["resolveComponent"])("el-header"),b=Object(o["resolveComponent"])("el-link"),f=Object(o["resolveComponent"])("el-divider"),m=Object(o["resolveComponent"])("el-form-item"),j=Object(o["resolveComponent"])("el-button"),p=Object(o["resolveComponent"])("el-tooltip"),O=Object(o["resolveComponent"])("el-space"),h=Object(o["resolveComponent"])("el-form"),w=Object(o["resolveComponent"])("el-main"),C=Object(o["resolveComponent"])("el-footer"),v=Object(o["resolveComponent"])("el-container");return Object(o["openBlock"])(),Object(o["createBlock"])(v,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(s),Object(o["createVNode"])(w,{class:"login-main"},{default:Object(o["withCtx"])((function(){return[Object(o["createElementVNode"])("div",r,[Object(o["createVNode"])(h,{ref:"formRef",rules:i.formRule,model:i.form,style:{border:"none"}},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(m,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(f,{"content-position":"left"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(b,{href:"https://github.com/vran-dev/databasir",target:"_blank",underline:!1,type:"info"},{default:Object(o["withCtx"])((function(){return[c]})),_:1})]})),_:1})]})),_:1}),Object(o["createVNode"])(m,{prop:"username"},{default:Object(o["withCtx"])((function(){return[Object(o["withDirectives"])(Object(o["createElementVNode"])("input",{type:"text",class:"login-input",placeholder:"用户名或邮箱","onUpdate:modelValue":t[0]||(t[0]=function(e){return i.form.username=e})},null,512),[[o["vModelText"],i.form.username]])]})),_:1}),Object(o["createVNode"])(m,{prop:"password"},{default:Object(o["withCtx"])((function(){return[Object(o["withDirectives"])(Object(o["createElementVNode"])("input",{type:"password",class:"login-input",placeholder:"密码","onUpdate:modelValue":t[1]||(t[1]=function(e){return i.form.password=e})},null,512),[[o["vModelText"],i.form.password]])]})),_:1}),Object(o["createVNode"])(m,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(O,{size:32},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(j,{style:{width:"120px","margin-top":"10px"},color:"#000",onClick:t[2]||(t[2]=function(e){return d.onLogin("formRef")}),plain:"",round:""},{default:Object(o["withCtx"])((function(){return[a]})),_:1}),Object(o["createVNode"])(p,{content:"请联系管理员为您重置密码"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(b,{target:"_blank",underline:!1,type:"info"},{default:Object(o["withCtx"])((function(){return[u]})),_:1})]})),_:1})]})),_:1})]})),_:1})]})),_:1},8,["rules","model"])])]})),_:1}),Object(o["createVNode"])(C,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(O)]})),_:1})]})),_:1})}var i=n("b0af"),d=n("5f87"),s={data:function(){return{form:{username:null,password:null},formRule:{username:[{required:!0,message:"请输入用户名或邮箱",trigger:"blur"}],password:[{required:!0,message:"请输入密码",trigger:"blur"}]}}},methods:{toIndexPage:function(){this.$router.push({path:"/groups"})},onLogin:function(){var e=this;this.$refs.formRef.validate((function(t){t&&Object(i["a"])(e.form).then((function(t){t.errCode||(d["b"].saveUserLoginData(t.data),e.$store.commit("userUpdate",{nickname:t.data.nickname,username:t.data.username,email:t.data.email}),e.toIndexPage())}))}))}}},b=(n("d30d"),n("6b0d")),f=n.n(b);const m=f()(s,[["render",l]]);t["default"]=m},d30d:function(e,t,n){"use strict";n("edba")},edba:function(e,t,n){}}]);
//# sourceMappingURL=chunk-7e394785.b93f6d8c.js.map
//# sourceMappingURL=chunk-7e394785.e090ef46.js.map

1
api/src/main/resources/static/js/chunk-7e394785.e090ef46.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-7fa689fe.e971bfe1.js → api/src/main/resources/static/js/chunk-7fa689fe.337b34fc.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-7fa689fe.337b34fc.js.map

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-7fa689fe.e971bfe1.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-abb10c56.4c323350.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-abb10c56.4c323350.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-abb10c56.bd8d31bf.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-abb10c56.bd8d31bf.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-c2109158.94b6c554.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-c2109158.94b6c554.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-fffb1b64.df1e960f.js → api/src/main/resources/static/js/chunk-fffb1b64.1ffb9f27.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-fffb1b64.1ffb9f27.js.map

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-fffb1b64.df1e960f.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-vendors.8b5336af.js.map

File diff suppressed because one or more lines are too long

42
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;
}
}

13
core/src/main/java/com/databasir/core/domain/log/converter/OperationLogPojoConverter.java

@ -0,0 +1,13 @@
package com.databasir.core.domain.log.converter;
import com.databasir.core.domain.log.data.OperationLogPageResponse;
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 OperationLogPojoConverter {
OperationLogPageResponse to(OperationLogPojo pojo);
}

13
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);
}

55
core/src/main/java/com/databasir/core/domain/log/data/OperationLogPageCondition.java

@ -0,0 +1,55 @@
package com.databasir.core.domain.log.data;
import com.databasir.dao.Tables;
import lombok.Data;
import org.jooq.Condition;
import org.jooq.impl.DSL;
import java.util.ArrayList;
import java.util.List;
@Data
public class OperationLogPageCondition {
private String module;
private String code;
private Integer operatorUserId;
private Integer involveProjectId;
private Integer involveGroupId;
private Integer involveUserId;
private Boolean isSuccess;
public Condition toCondition() {
List<Condition> conditions = new ArrayList<>();
if (module != null) {
conditions.add(Tables.OPERATION_LOG.OPERATION_MODULE.eq(module));
}
if (code != null) {
conditions.add(Tables.OPERATION_LOG.OPERATION_CODE.eq(module));
}
if (operatorUserId != null) {
conditions.add(Tables.OPERATION_LOG.OPERATOR_USER_ID.eq(operatorUserId));
}
if (involveProjectId != null) {
conditions.add(Tables.OPERATION_LOG.INVOLVED_PROJECT_ID.eq(involveProjectId));
}
if (involveGroupId != null) {
conditions.add(Tables.OPERATION_LOG.INVOLVED_GROUP_ID.eq(involveGroupId));
}
if (involveUserId != null) {
conditions.add(Tables.OPERATION_LOG.INVOLVED_USER_ID.eq(involveUserId));
}
if (isSuccess != null) {
conditions.add(Tables.OPERATION_LOG.IS_SUCCESS.eq(isSuccess));
}
return conditions.stream()
.reduce(Condition::and)
.orElse(DSL.trueCondition());
}
}

39
core/src/main/java/com/databasir/core/domain/log/data/OperationLogPageResponse.java

@ -0,0 +1,39 @@
package com.databasir.core.domain.log.data;
import com.databasir.common.JsonData;
import lombok.Builder;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@Builder
public class OperationLogPageResponse {
private Integer id;
private Integer operatorUserId;
private String operatorUsername;
private String operatorNickname;
private String operationModule;
private String operationCode;
private String operationName;
private JsonData<Object> operationResponse;
private Boolean isSuccess;
private Integer involvedProjectId;
private Integer involvedGroupId;
private Integer involvedUserId;
private LocalDateTime createAt;
}

32
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;
}

35
core/src/main/java/com/databasir/core/domain/log/service/OperationLogService.java

@ -0,0 +1,35 @@
package com.databasir.core.domain.log.service;
import com.databasir.core.domain.log.converter.OperationLogPojoConverter;
import com.databasir.core.domain.log.converter.OperationLogRequestConverter;
import com.databasir.core.domain.log.data.OperationLogPageCondition;
import com.databasir.core.domain.log.data.OperationLogPageResponse;
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.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class OperationLogService {
private final OperationLogDao operationLogDao;
private final OperationLogRequestConverter operationLogRequestConverter;
private final OperationLogPojoConverter operationLogPojoConverter;
public void save(OperationLogRequest request) {
OperationLogPojo pojo = operationLogRequestConverter.toPojo(request);
operationLogDao.insertAndReturnId(pojo);
}
public Page<OperationLogPageResponse> list(Pageable page,
OperationLogPageCondition condition) {
Page<OperationLogPojo> pojoData = operationLogDao.selectByPage(page, condition.toCondition());
return pojoData.map(operationLogPojoConverter::to);
}
}

42
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<String> array) {
try {
String json = objectMapper.writeValueAsString(array);
String json = objToJson(array);
return JSON.valueOf(json);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
}
public List<String> fromJson(JSON json) {
@ -44,12 +41,8 @@ public class JsonConverter {
}
public JSON toJson(DatabaseDocumentResponse response) {
try {
String json = objectMapper.writeValueAsString(response);
String json = objToJson(response);
return JSON.valueOf(json);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
}
public DatabaseDocumentResponse of(JSON json) {
@ -62,4 +55,33 @@ public class JsonConverter {
throw new IllegalArgumentException(e);
}
}
public JsonData toJsonData(JSON json) {
try {
if (json == null) {
return null;
}
return objectMapper.readValue(json.data().getBytes(StandardCharsets.UTF_8), JsonData.class);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
public JSON toJson(JsonData<Object> data) {
String json = objToJson(data);
return JSON.valueOf(json);
}
public JSON objToJsonData(Object obj) {
String json = objToJson(obj);
return JSON.valueOf(json);
}
private String objToJson(Object obj) {
try {
return objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
}
}

7
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 <code>databasir.operation_log</code>.
*/
public final OperationLog OPERATION_LOG = OperationLog.OPERATION_LOG;
/**
* The table <code>databasir.project</code>.
*/
@ -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,

3
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<GroupRecord> KEY_GROUP_UK_NAME = Internal.createUniqueKey(Group.GROUP, DSL.name("KEY_group_uk_name"), new TableField[] { Group.GROUP.NAME }, true);
public static final UniqueKey<LoginRecord> KEY_LOGIN_PRIMARY = Internal.createUniqueKey(Login.LOGIN, DSL.name("KEY_login_PRIMARY"), new TableField[] { Login.LOGIN.ID }, true);
public static final UniqueKey<LoginRecord> 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<OperationLogRecord> 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<ProjectRecord> KEY_PROJECT_PRIMARY = Internal.createUniqueKey(Project.PROJECT, DSL.name("KEY_project_PRIMARY"), new TableField[] { Project.PROJECT.ID }, true);
public static final UniqueKey<ProjectRecord> 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<ProjectSyncRuleRecord> 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);

6
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 <code>databasir.operation_log</code>.
*/
public static final OperationLog OPERATION_LOG = OperationLog.OPERATION_LOG;
/**
* The table <code>databasir.project</code>.
*/

204
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<OperationLogRecord> {
private static final long serialVersionUID = 1L;
/**
* The reference instance of <code>databasir.operation_log</code>
*/
public static final OperationLog OPERATION_LOG = new OperationLog();
/**
* The class holding records for this type
*/
@Override
public Class<OperationLogRecord> getRecordType() {
return OperationLogRecord.class;
}
/**
* The column <code>databasir.operation_log.id</code>.
*/
public final TableField<OperationLogRecord, Long> ID = createField(DSL.name("id"), SQLDataType.BIGINT.nullable(false).identity(true), this, "");
/**
* The column <code>databasir.operation_log.operator_user_id</code>. ref to
* user.id
*/
public final TableField<OperationLogRecord, Integer> OPERATOR_USER_ID = createField(DSL.name("operator_user_id"), SQLDataType.INTEGER.nullable(false), this, "ref to user.id");
/**
* The column <code>databasir.operation_log.operator_username</code>.
* user.username
*/
public final TableField<OperationLogRecord, String> OPERATOR_USERNAME = createField(DSL.name("operator_username"), SQLDataType.VARCHAR(128).nullable(false), this, "user.username");
/**
* The column <code>databasir.operation_log.operator_nickname</code>.
* user.nickname
*/
public final TableField<OperationLogRecord, String> OPERATOR_NICKNAME = createField(DSL.name("operator_nickname"), SQLDataType.VARCHAR(255).nullable(false), this, "user.nickname");
/**
* The column <code>databasir.operation_log.operation_module</code>.
*/
public final TableField<OperationLogRecord, String> OPERATION_MODULE = createField(DSL.name("operation_module"), SQLDataType.VARCHAR(128).nullable(false), this, "");
/**
* The column <code>databasir.operation_log.operation_code</code>.
*/
public final TableField<OperationLogRecord, String> OPERATION_CODE = createField(DSL.name("operation_code"), SQLDataType.VARCHAR(255).nullable(false), this, "");
/**
* The column <code>databasir.operation_log.operation_name</code>.
*/
public final TableField<OperationLogRecord, String> OPERATION_NAME = createField(DSL.name("operation_name"), SQLDataType.VARCHAR(255).nullable(false), this, "");
/**
* The column <code>databasir.operation_log.operation_response</code>.
*/
public final TableField<OperationLogRecord, JSON> OPERATION_RESPONSE = createField(DSL.name("operation_response"), SQLDataType.JSON.nullable(false), this, "");
/**
* The column <code>databasir.operation_log.is_success</code>.
*/
public final TableField<OperationLogRecord, Boolean> IS_SUCCESS = createField(DSL.name("is_success"), SQLDataType.BOOLEAN.nullable(false).defaultValue(DSL.inline("0", SQLDataType.BOOLEAN)), this, "");
/**
* The column <code>databasir.operation_log.involved_project_id</code>. ref
* to project.id
*/
public final TableField<OperationLogRecord, Integer> INVOLVED_PROJECT_ID = createField(DSL.name("involved_project_id"), SQLDataType.INTEGER, this, "ref to project.id");
/**
* The column <code>databasir.operation_log.involved_group_id</code>. ref to
* group.id
*/
public final TableField<OperationLogRecord, Integer> INVOLVED_GROUP_ID = createField(DSL.name("involved_group_id"), SQLDataType.INTEGER, this, "ref to group.id");
/**
* The column <code>databasir.operation_log.involved_user_id</code>. ref to
* user.id
*/
public final TableField<OperationLogRecord, Integer> INVOLVED_USER_ID = createField(DSL.name("involved_user_id"), SQLDataType.INTEGER, this, "ref to user.id");
/**
* The column <code>databasir.operation_log.create_at</code>.
*/
public final TableField<OperationLogRecord, LocalDateTime> 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<OperationLogRecord> aliased) {
this(alias, aliased, null);
}
private OperationLog(Name alias, Table<OperationLogRecord> aliased, Field<?>[] parameters) {
super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
}
/**
* Create an aliased <code>databasir.operation_log</code> table reference
*/
public OperationLog(String alias) {
this(DSL.name(alias), OPERATION_LOG);
}
/**
* Create an aliased <code>databasir.operation_log</code> table reference
*/
public OperationLog(Name alias) {
this(alias, OPERATION_LOG);
}
/**
* Create a <code>databasir.operation_log</code> table reference
*/
public OperationLog() {
this(DSL.name("operation_log"), null);
}
public <O extends Record> OperationLog(Table<O> child, ForeignKey<O, OperationLogRecord> key) {
super(child, key, OPERATION_LOG);
}
@Override
public Schema getSchema() {
return aliased() ? null : Databasir.DATABASIR;
}
@Override
public Identity<OperationLogRecord, Long> getIdentity() {
return (Identity<OperationLogRecord, Long>) super.getIdentity();
}
@Override
public UniqueKey<OperationLogRecord> 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<Long, Integer, String, String, String, String, String, JSON, Boolean, Integer, Integer, Integer, LocalDateTime> fieldsRow() {
return (Row13) super.fieldsRow();
}
}

298
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 <code>databasir.operation_log.id</code>.
*/
public Long getId() {
return this.id;
}
/**
* Setter for <code>databasir.operation_log.id</code>.
*/
public void setId(Long id) {
this.id = id;
}
/**
* Getter for <code>databasir.operation_log.operator_user_id</code>. ref to
* user.id
*/
public Integer getOperatorUserId() {
return this.operatorUserId;
}
/**
* Setter for <code>databasir.operation_log.operator_user_id</code>. ref to
* user.id
*/
public void setOperatorUserId(Integer operatorUserId) {
this.operatorUserId = operatorUserId;
}
/**
* Getter for <code>databasir.operation_log.operator_username</code>.
* user.username
*/
public String getOperatorUsername() {
return this.operatorUsername;
}
/**
* Setter for <code>databasir.operation_log.operator_username</code>.
* user.username
*/
public void setOperatorUsername(String operatorUsername) {
this.operatorUsername = operatorUsername;
}
/**
* Getter for <code>databasir.operation_log.operator_nickname</code>.
* user.nickname
*/
public String getOperatorNickname() {
return this.operatorNickname;
}
/**
* Setter for <code>databasir.operation_log.operator_nickname</code>.
* user.nickname
*/
public void setOperatorNickname(String operatorNickname) {
this.operatorNickname = operatorNickname;
}
/**
* Getter for <code>databasir.operation_log.operation_module</code>.
*/
public String getOperationModule() {
return this.operationModule;
}
/**
* Setter for <code>databasir.operation_log.operation_module</code>.
*/
public void setOperationModule(String operationModule) {
this.operationModule = operationModule;
}
/**
* Getter for <code>databasir.operation_log.operation_code</code>.
*/
public String getOperationCode() {
return this.operationCode;
}
/**
* Setter for <code>databasir.operation_log.operation_code</code>.
*/
public void setOperationCode(String operationCode) {
this.operationCode = operationCode;
}
/**
* Getter for <code>databasir.operation_log.operation_name</code>.
*/
public String getOperationName() {
return this.operationName;
}
/**
* Setter for <code>databasir.operation_log.operation_name</code>.
*/
public void setOperationName(String operationName) {
this.operationName = operationName;
}
/**
* Getter for <code>databasir.operation_log.operation_response</code>.
*/
public JSON getOperationResponse() {
return this.operationResponse;
}
/**
* Setter for <code>databasir.operation_log.operation_response</code>.
*/
public void setOperationResponse(JSON operationResponse) {
this.operationResponse = operationResponse;
}
/**
* Getter for <code>databasir.operation_log.is_success</code>.
*/
public Boolean getIsSuccess() {
return this.isSuccess;
}
/**
* Setter for <code>databasir.operation_log.is_success</code>.
*/
public void setIsSuccess(Boolean isSuccess) {
this.isSuccess = isSuccess;
}
/**
* Getter for <code>databasir.operation_log.involved_project_id</code>. ref
* to project.id
*/
public Integer getInvolvedProjectId() {
return this.involvedProjectId;
}
/**
* Setter for <code>databasir.operation_log.involved_project_id</code>. ref
* to project.id
*/
public void setInvolvedProjectId(Integer involvedProjectId) {
this.involvedProjectId = involvedProjectId;
}
/**
* Getter for <code>databasir.operation_log.involved_group_id</code>. ref to
* group.id
*/
public Integer getInvolvedGroupId() {
return this.involvedGroupId;
}
/**
* Setter for <code>databasir.operation_log.involved_group_id</code>. ref to
* group.id
*/
public void setInvolvedGroupId(Integer involvedGroupId) {
this.involvedGroupId = involvedGroupId;
}
/**
* Getter for <code>databasir.operation_log.involved_user_id</code>. ref to
* user.id
*/
public Integer getInvolvedUserId() {
return this.involvedUserId;
}
/**
* Setter for <code>databasir.operation_log.involved_user_id</code>. ref to
* user.id
*/
public void setInvolvedUserId(Integer involvedUserId) {
this.involvedUserId = involvedUserId;
}
/**
* Getter for <code>databasir.operation_log.create_at</code>.
*/
public LocalDateTime getCreateAt() {
return this.createAt;
}
/**
* Setter for <code>databasir.operation_log.create_at</code>.
*/
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();
}
}

590
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<OperationLogRecord> implements Record13<Long, Integer, String, String, String, String, String, JSON, Boolean, Integer, Integer, Integer, LocalDateTime> {
private static final long serialVersionUID = 1L;
/**
* Setter for <code>databasir.operation_log.id</code>.
*/
public void setId(Long value) {
set(0, value);
}
/**
* Getter for <code>databasir.operation_log.id</code>.
*/
public Long getId() {
return (Long) get(0);
}
/**
* Setter for <code>databasir.operation_log.operator_user_id</code>. ref to
* user.id
*/
public void setOperatorUserId(Integer value) {
set(1, value);
}
/**
* Getter for <code>databasir.operation_log.operator_user_id</code>. ref to
* user.id
*/
public Integer getOperatorUserId() {
return (Integer) get(1);
}
/**
* Setter for <code>databasir.operation_log.operator_username</code>.
* user.username
*/
public void setOperatorUsername(String value) {
set(2, value);
}
/**
* Getter for <code>databasir.operation_log.operator_username</code>.
* user.username
*/
public String getOperatorUsername() {
return (String) get(2);
}
/**
* Setter for <code>databasir.operation_log.operator_nickname</code>.
* user.nickname
*/
public void setOperatorNickname(String value) {
set(3, value);
}
/**
* Getter for <code>databasir.operation_log.operator_nickname</code>.
* user.nickname
*/
public String getOperatorNickname() {
return (String) get(3);
}
/**
* Setter for <code>databasir.operation_log.operation_module</code>.
*/
public void setOperationModule(String value) {
set(4, value);
}
/**
* Getter for <code>databasir.operation_log.operation_module</code>.
*/
public String getOperationModule() {
return (String) get(4);
}
/**
* Setter for <code>databasir.operation_log.operation_code</code>.
*/
public void setOperationCode(String value) {
set(5, value);
}
/**
* Getter for <code>databasir.operation_log.operation_code</code>.
*/
public String getOperationCode() {
return (String) get(5);
}
/**
* Setter for <code>databasir.operation_log.operation_name</code>.
*/
public void setOperationName(String value) {
set(6, value);
}
/**
* Getter for <code>databasir.operation_log.operation_name</code>.
*/
public String getOperationName() {
return (String) get(6);
}
/**
* Setter for <code>databasir.operation_log.operation_response</code>.
*/
public void setOperationResponse(JSON value) {
set(7, value);
}
/**
* Getter for <code>databasir.operation_log.operation_response</code>.
*/
public JSON getOperationResponse() {
return (JSON) get(7);
}
/**
* Setter for <code>databasir.operation_log.is_success</code>.
*/
public void setIsSuccess(Boolean value) {
set(8, value);
}
/**
* Getter for <code>databasir.operation_log.is_success</code>.
*/
public Boolean getIsSuccess() {
return (Boolean) get(8);
}
/**
* Setter for <code>databasir.operation_log.involved_project_id</code>. ref
* to project.id
*/
public void setInvolvedProjectId(Integer value) {
set(9, value);
}
/**
* Getter for <code>databasir.operation_log.involved_project_id</code>. ref
* to project.id
*/
public Integer getInvolvedProjectId() {
return (Integer) get(9);
}
/**
* Setter for <code>databasir.operation_log.involved_group_id</code>. ref to
* group.id
*/
public void setInvolvedGroupId(Integer value) {
set(10, value);
}
/**
* Getter for <code>databasir.operation_log.involved_group_id</code>. ref to
* group.id
*/
public Integer getInvolvedGroupId() {
return (Integer) get(10);
}
/**
* Setter for <code>databasir.operation_log.involved_user_id</code>. ref to
* user.id
*/
public void setInvolvedUserId(Integer value) {
set(11, value);
}
/**
* Getter for <code>databasir.operation_log.involved_user_id</code>. ref to
* user.id
*/
public Integer getInvolvedUserId() {
return (Integer) get(11);
}
/**
* Setter for <code>databasir.operation_log.create_at</code>.
*/
public void setCreateAt(LocalDateTime value) {
set(12, value);
}
/**
* Getter for <code>databasir.operation_log.create_at</code>.
*/
public LocalDateTime getCreateAt() {
return (LocalDateTime) get(12);
}
// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------
@Override
public Record1<Long> key() {
return (Record1) super.key();
}
// -------------------------------------------------------------------------
// Record13 type implementation
// -------------------------------------------------------------------------
@Override
public Row13<Long, Integer, String, String, String, String, String, JSON, Boolean, Integer, Integer, Integer, LocalDateTime> fieldsRow() {
return (Row13) super.fieldsRow();
}
@Override
public Row13<Long, Integer, String, String, String, String, String, JSON, Boolean, Integer, Integer, Integer, LocalDateTime> valuesRow() {
return (Row13) super.valuesRow();
}
@Override
public Field<Long> field1() {
return OperationLog.OPERATION_LOG.ID;
}
@Override
public Field<Integer> field2() {
return OperationLog.OPERATION_LOG.OPERATOR_USER_ID;
}
@Override
public Field<String> field3() {
return OperationLog.OPERATION_LOG.OPERATOR_USERNAME;
}
@Override
public Field<String> field4() {
return OperationLog.OPERATION_LOG.OPERATOR_NICKNAME;
}
@Override
public Field<String> field5() {
return OperationLog.OPERATION_LOG.OPERATION_MODULE;
}
@Override
public Field<String> field6() {
return OperationLog.OPERATION_LOG.OPERATION_CODE;
}
@Override
public Field<String> field7() {
return OperationLog.OPERATION_LOG.OPERATION_NAME;
}
@Override
public Field<JSON> field8() {
return OperationLog.OPERATION_LOG.OPERATION_RESPONSE;
}
@Override
public Field<Boolean> field9() {
return OperationLog.OPERATION_LOG.IS_SUCCESS;
}
@Override
public Field<Integer> field10() {
return OperationLog.OPERATION_LOG.INVOLVED_PROJECT_ID;
}
@Override
public Field<Integer> field11() {
return OperationLog.OPERATION_LOG.INVOLVED_GROUP_ID;
}
@Override
public Field<Integer> field12() {
return OperationLog.OPERATION_LOG.INVOLVED_USER_ID;
}
@Override
public Field<LocalDateTime> 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());
}
}
}

55
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<T extends Record, R> {
public abstract class BaseDao<PO> {
private final Table<T> table;
private final Table<?> table;
private final Class<R> pojoType;
private final Class<PO> pojoType;
public BaseDao(Table<?> table, Class<PO> pojoType) {
this.table = table;
this.pojoType = pojoType;
}
public abstract DSLContext getDslContext();
public boolean existsById(Integer id) {
public <T extends Serializable> boolean existsById(T id) {
return getDslContext().fetchExists(table, identity().eq(id));
}
public Integer insertAndReturnId(R pojo) {
T record = getDslContext().newRecord(table, pojo);
public <T> 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<R> pojoList) {
public int batchInsert(Collection<PO> pojoList) {
List<TableRecord<?>> 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 <T extends Serializable> 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<R> selectOptionalById(Integer id) {
public <T extends Serializable> Optional<PO> selectOptionalById(T id) {
return getDslContext()
.select(table.fields()).from(table).where(identity().eq(id))
.fetchOptionalInto(pojoType);
}
public R selectById(Integer id) {
public <T extends Serializable> PO selectById(T id) {
return selectOptionalById(id)
.orElseThrow(() -> new DataNotExistsException("data not exists in " + table.getName() + " with id = " + id));
}
public List<R> selectInIds(List<Integer> ids) {
public List<PO> selectInIds(List<? extends Serializable> ids) {
if (ids == null || ids.isEmpty()) {
return Collections.emptyList();
}
@ -77,12 +80,12 @@ public abstract class BaseDao<T extends Record, R> {
.fetchInto(pojoType);
}
public Page<R> selectByPage(Pageable request, Condition condition) {
public Page<PO> selectByPage(Pageable request, Condition condition) {
Integer count = getDslContext()
.selectCount().from(table).where(condition)
.fetchOne(0, int.class);
int total = count == null ? 0 : count;
List<R> data = getDslContext()
List<PO> data = getDslContext()
.selectFrom(table).where(condition)
.orderBy(getSortFields(request.getSort()))
.offset(request.getOffset()).limit(request.getPageSize())
@ -110,15 +113,19 @@ public abstract class BaseDao<T extends Record, R> {
return querySortFields;
}
protected Field<Integer> identity() {
Identity<T, ?> identity = table.getIdentity();
protected <T extends Serializable> Field<T> 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 <T extends Serializable> Class<T> identityType() {
return (Class<T>) Integer.class;
}
protected Table<T> table() {
protected Table<?> table() {
return this.table;
}
}

2
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<DataSourceRecord, DataSourcePojo> {
public class DataSourceDao extends BaseDao<DataSourcePojo> {
@Autowired
@Getter

3
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<DataSourcePropertyRecord, DataSourcePropertyPojo> {
public class DataSourcePropertyDao extends BaseDao<DataSourcePropertyPojo> {
@Autowired
@Getter

2
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<DatabaseDocumentRecord, DatabaseDocumentPojo> {
public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
@Autowired
@Getter

3
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<DatabaseDocumentHistoryRecord, DatabaseDocumentHistoryPojo> {
public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryPojo> {
@Autowired
@Getter

3
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<DocumentRemarkRecord, DocumentRemarkPojo> {
public class DocumentRemarkDao extends BaseDao<DocumentRemarkPojo> {
@Autowired
@Getter

15
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<GroupRecord, GroupPojo> {
public class GroupDao extends BaseDao<GroupPojo> {
@Autowired
@Getter
@ -27,10 +27,11 @@ public class GroupDao extends BaseDao<GroupRecord, GroupPojo> {
super(GROUP, GroupPojo.class);
}
@Override
public int deleteById(Integer id) {
public <T extends Serializable> 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<GroupRecord, GroupPojo> {
}
@Override
public Optional<GroupPojo> selectOptionalById(Integer id) {
public <T extends Serializable> Optional<GroupPojo> 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<GroupPojo> selectInIds(List<Integer> ids) {
public List<GroupPojo> selectInIds(List<? extends Serializable> ids) {
if (ids == null || ids.isEmpty()) {
return Collections.emptyList();
}

3
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<LoginRecord, LoginPojo> {
public class LoginDao extends BaseDao<LoginPojo> {
@Autowired
@Getter

28
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<OperationLogPojo> {
@Autowired
@Getter
private DSLContext dslContext;
public OperationLogDao() {
super(OPERATION_LOG, OperationLogPojo.class);
}
@Override
protected <T extends Serializable> Class<T> identityType() {
return (Class<T>) Long.class;
}
}

8
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<ProjectRecord, ProjectPojo> {
public class ProjectDao extends BaseDao<ProjectPojo> {
@Autowired
@Getter
@ -39,7 +39,7 @@ public class ProjectDao extends BaseDao<ProjectRecord, ProjectPojo> {
}
@Override
public Optional<ProjectPojo> selectOptionalById(Integer id) {
public <T extends Serializable> Optional<ProjectPojo> 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<ProjectRecord, ProjectPojo> {
}
@Override
public boolean existsById(Integer id) {
public <T extends Serializable> boolean existsById(T id) {
return getDslContext().fetchExists(table(), identity().eq(id).and(PROJECT.DELETED.eq(false)));
}

2
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<ProjectSyncRuleRecord, ProjectSyncRulePojo> {
public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRulePojo> {
@Autowired
@Getter

3
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<SysKeyRecord, SysKeyPojo> {
public class SysKeyDao extends BaseDao<SysKeyPojo> {
@Autowired
@Getter

2
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<SysMailRecord, SysMailPojo> {
public class SysMailDao extends BaseDao<SysMailPojo> {
@Autowired
@Getter

3
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<TableColumnDocumentRecord, TableColumnDocumentPojo> {
public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
@Autowired
@Getter

3
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<TableDocumentRecord, TableDocumentPojo> {
public class TableDocumentDao extends BaseDao<TableDocumentPojo> {
@Autowired
@Getter

3
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<TableIndexDocumentRecord, TableIndexDocumentPojo> {
public class TableIndexDocumentDao extends BaseDao<TableIndexDocumentPojo> {
@Autowired
@Getter

3
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<TableTriggerDocumentRecord, TableTriggerDocumentPojo> {
public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentPojo> {
@Autowired
@Getter

3
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<UserRecord, UserPojo> {
public class UserDao extends BaseDao<UserPojo> {
@Autowired
@Getter

3
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<UserRoleRecord, UserRolePojo> {
public class UserRoleDao extends BaseDao<UserRolePojo> {
@Autowired
@Getter

18
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;
Loading…
Cancel
Save