feat: auto record operation log

This commit is contained in:
vran 2022-02-17 22:38:08 +08:00
parent 133b9476e5
commit 0d53f398c7
40 changed files with 1553 additions and 75 deletions

View File

@ -5,6 +5,7 @@ import com.databasir.common.SystemException;
import com.databasir.core.domain.document.data.DatabaseDocumentResponse; import com.databasir.core.domain.document.data.DatabaseDocumentResponse;
import com.databasir.core.domain.document.data.DatabaseDocumentVersionResponse; import com.databasir.core.domain.document.data.DatabaseDocumentVersionResponse;
import com.databasir.core.domain.document.service.DocumentService; import com.databasir.core.domain.document.service.DocumentService;
import com.databasir.core.domain.log.annotation.Operation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -33,6 +34,7 @@ public class DocumentController {
private final DocumentService documentService; private final DocumentService documentService;
@PostMapping(Routes.Document.SYNC_ONE) @PostMapping(Routes.Document.SYNC_ONE)
@Operation(module = Operation.Modules.PROJECT, name = "文档同步", involvedProjectId = "#projectId")
public JsonData<Void> sync(@PathVariable Integer projectId) { public JsonData<Void> sync(@PathVariable Integer projectId) {
documentService.syncByProjectId(projectId); documentService.syncByProjectId(projectId);
return JsonData.ok(); return JsonData.ok();

View File

@ -2,6 +2,7 @@ package com.databasir.api;
import com.databasir.api.config.security.DatabasirUserDetails; import com.databasir.api.config.security.DatabasirUserDetails;
import com.databasir.common.JsonData; 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.RemarkCreateRequest;
import com.databasir.core.domain.remark.data.RemarkListCondition; import com.databasir.core.domain.remark.data.RemarkListCondition;
import com.databasir.core.domain.remark.data.RemarkResponse; import com.databasir.core.domain.remark.data.RemarkResponse;
@ -38,6 +39,9 @@ public class DocumentRemarkController {
@DeleteMapping(Routes.DocumentRemark.DELETE) @DeleteMapping(Routes.DocumentRemark.DELETE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId)") @PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId)")
@Operation(module = Operation.Modules.PROJECT,
name = "删除批注",
involvedProjectId = "#projectId")
public JsonData<Void> delete(@PathVariable Integer groupId, public JsonData<Void> delete(@PathVariable Integer groupId,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@PathVariable Integer remarkId) { @PathVariable Integer remarkId) {
@ -47,6 +51,9 @@ public class DocumentRemarkController {
@PostMapping(Routes.DocumentRemark.CREATE) @PostMapping(Routes.DocumentRemark.CREATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") @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, public JsonData<Void> create(@PathVariable Integer groupId,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@RequestBody @Valid RemarkCreateRequest request) { @RequestBody @Valid RemarkCreateRequest request) {

View File

@ -4,6 +4,7 @@ import com.databasir.api.validator.UserOperationValidator;
import com.databasir.common.JsonData; import com.databasir.common.JsonData;
import com.databasir.core.domain.group.data.*; import com.databasir.core.domain.group.data.*;
import com.databasir.core.domain.group.service.GroupService; import com.databasir.core.domain.group.service.GroupService;
import com.databasir.core.domain.log.annotation.Operation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -28,6 +29,7 @@ public class GroupController {
@PostMapping(Routes.Group.CREATE) @PostMapping(Routes.Group.CREATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.GROUP, name = "创建分组")
public JsonData<Void> create(@RequestBody @Valid GroupCreateRequest request) { public JsonData<Void> create(@RequestBody @Valid GroupCreateRequest request) {
groupService.create(request); groupService.create(request);
return JsonData.ok(); return JsonData.ok();
@ -35,6 +37,9 @@ public class GroupController {
@PatchMapping(Routes.Group.UPDATE) @PatchMapping(Routes.Group.UPDATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#request.id)))") @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) { public JsonData<Void> update(@RequestBody @Valid GroupUpdateRequest request) {
groupService.update(request); groupService.update(request);
return JsonData.ok(); return JsonData.ok();
@ -49,6 +54,9 @@ public class GroupController {
@DeleteMapping(Routes.Group.DELETE) @DeleteMapping(Routes.Group.DELETE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") @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) { public JsonData<Void> deleteById(@PathVariable Integer groupId) {
groupService.delete(groupId); groupService.delete(groupId);
return JsonData.ok(); return JsonData.ok();
@ -69,6 +77,10 @@ public class GroupController {
@PostMapping(Routes.Group.ADD_MEMBER) @PostMapping(Routes.Group.ADD_MEMBER)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") @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, public JsonData<Void> addGroupMember(@PathVariable Integer groupId,
@RequestBody @Valid GroupMemberCreateRequest request) { @RequestBody @Valid GroupMemberCreateRequest request) {
userOperationValidator.forbiddenIfUpdateSelfRole(request.getUserId()); userOperationValidator.forbiddenIfUpdateSelfRole(request.getUserId());
@ -82,6 +94,10 @@ public class GroupController {
@DeleteMapping(Routes.Group.DELETE_MEMBER) @DeleteMapping(Routes.Group.DELETE_MEMBER)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") @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, public JsonData<Void> removeGroupMember(@PathVariable Integer groupId,
@PathVariable Integer userId) { @PathVariable Integer userId) {
userOperationValidator.forbiddenIfUpdateSelfRole(userId); userOperationValidator.forbiddenIfUpdateSelfRole(userId);
@ -91,6 +107,10 @@ public class GroupController {
@PatchMapping(Routes.Group.UPDATE_MEMBER) @PatchMapping(Routes.Group.UPDATE_MEMBER)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER'.concat('?groupId='.concat(#groupId)))") @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, public JsonData<Void> updateGroupMemberRole(@PathVariable Integer groupId,
@PathVariable Integer userId, @PathVariable Integer userId,
@RequestBody GroupMemberRoleUpdateRequest request) { @RequestBody GroupMemberRoleUpdateRequest request) {

View File

@ -4,6 +4,7 @@ import com.databasir.common.DatabasirException;
import com.databasir.common.JsonData; import com.databasir.common.JsonData;
import com.databasir.common.exception.InvalidTokenException; import com.databasir.common.exception.InvalidTokenException;
import com.databasir.core.domain.DomainErrors; 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.AccessTokenRefreshRequest;
import com.databasir.core.domain.login.data.AccessTokenRefreshResponse; import com.databasir.core.domain.login.data.AccessTokenRefreshResponse;
import com.databasir.core.domain.login.service.LoginService; import com.databasir.core.domain.login.service.LoginService;
@ -32,6 +33,7 @@ public class LoginController {
private final LoginService loginService; private final LoginService loginService;
@GetMapping(Routes.Login.LOGOUT) @GetMapping(Routes.Login.LOGOUT)
@Operation(module = Operation.Modules.USER, name = "注销登录")
public JsonData<Void> logout() { public JsonData<Void> logout() {
SecurityContextHolder.clearContext(); SecurityContextHolder.clearContext();
return JsonData.ok(); return JsonData.ok();

View File

@ -2,6 +2,7 @@ package com.databasir.api;
import com.databasir.api.validator.CronExpressionValidator; import com.databasir.api.validator.CronExpressionValidator;
import com.databasir.common.JsonData; 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.data.*;
import com.databasir.core.domain.project.service.ProjectService; import com.databasir.core.domain.project.service.ProjectService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -26,6 +27,9 @@ public class ProjectController {
@PostMapping(Routes.GroupProject.CREATE) @PostMapping(Routes.GroupProject.CREATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#request.groupId, 'GROUP_MEMBER?groupId='+#request.groupId)") @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) { public JsonData<Void> create(@RequestBody @Valid ProjectCreateRequest request) {
cronExpressionValidator.isValidCron(request); cronExpressionValidator.isValidCron(request);
projectService.create(request); projectService.create(request);
@ -34,6 +38,10 @@ public class ProjectController {
@PatchMapping(Routes.GroupProject.UPDATE) @PatchMapping(Routes.GroupProject.UPDATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") @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, public JsonData<Void> update(@RequestBody @Valid ProjectUpdateRequest request,
@PathVariable Integer groupId) { @PathVariable Integer groupId) {
cronExpressionValidator.isValidCron(request); cronExpressionValidator.isValidCron(request);
@ -43,6 +51,10 @@ public class ProjectController {
@DeleteMapping(Routes.GroupProject.DELETE) @DeleteMapping(Routes.GroupProject.DELETE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)") @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, public JsonData<Void> delete(@PathVariable Integer groupId,
@PathVariable Integer projectId) { @PathVariable Integer projectId) {
projectService.delete(projectId); projectService.delete(projectId);

View File

@ -2,6 +2,7 @@ package com.databasir.api;
import com.databasir.common.JsonData; 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.SystemEmailResponse;
import com.databasir.core.domain.system.data.SystemEmailUpdateRequest; import com.databasir.core.domain.system.data.SystemEmailUpdateRequest;
import com.databasir.core.domain.system.service.SystemService; import com.databasir.core.domain.system.service.SystemService;
@ -28,6 +29,7 @@ public class SettingController {
} }
@PostMapping(Routes.Setting.UPDATE_SYS_EMAIL) @PostMapping(Routes.Setting.UPDATE_SYS_EMAIL)
@Operation(module = Operation.Modules.PROJECT, name = "更新邮件配置")
public JsonData<Void> updateSystemEmailSetting(@RequestBody @Valid SystemEmailUpdateRequest request) { public JsonData<Void> updateSystemEmailSetting(@RequestBody @Valid SystemEmailUpdateRequest request) {
systemService.updateEmailSetting(request); systemService.updateEmailSetting(request);
return JsonData.ok(); return JsonData.ok();

View File

@ -3,6 +3,7 @@ package com.databasir.api;
import com.databasir.api.validator.UserOperationValidator; import com.databasir.api.validator.UserOperationValidator;
import com.databasir.common.JsonData; import com.databasir.common.JsonData;
import com.databasir.common.exception.Forbidden; 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.data.*;
import com.databasir.core.domain.user.service.UserService; import com.databasir.core.domain.user.service.UserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -34,6 +35,7 @@ public class UserController {
@PostMapping(Routes.User.DISABLE) @PostMapping(Routes.User.DISABLE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.USER, name = "禁用用户", involvedUserId = "#userId")
public JsonData<Void> disableUser(@PathVariable Integer userId) { public JsonData<Void> disableUser(@PathVariable Integer userId) {
userService.switchEnableStatus(userId, false); userService.switchEnableStatus(userId, false);
return JsonData.ok(); return JsonData.ok();
@ -41,6 +43,7 @@ public class UserController {
@PostMapping(Routes.User.ENABLE) @PostMapping(Routes.User.ENABLE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.USER, name = "启用用户", involvedUserId = "#userId")
public JsonData<Void> enableUser(@PathVariable Integer userId) { public JsonData<Void> enableUser(@PathVariable Integer userId) {
userService.switchEnableStatus(userId, true); userService.switchEnableStatus(userId, true);
return JsonData.ok(); return JsonData.ok();
@ -48,6 +51,7 @@ public class UserController {
@PostMapping(Routes.User.CREATE) @PostMapping(Routes.User.CREATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.USER, name = "创建用户")
public JsonData<Void> create(@RequestBody @Valid UserCreateRequest request) { public JsonData<Void> create(@RequestBody @Valid UserCreateRequest request) {
userService.create(request); userService.create(request);
return JsonData.ok(); return JsonData.ok();
@ -60,6 +64,7 @@ public class UserController {
@PostMapping(Routes.User.RENEW_PASSWORD) @PostMapping(Routes.User.RENEW_PASSWORD)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.USER, name = "重置用户密码", involvedUserId = "#userId")
public JsonData<Void> renewPassword(@PathVariable Integer userId) { public JsonData<Void> renewPassword(@PathVariable Integer userId) {
userService.renewPassword(userId); userService.renewPassword(userId);
return JsonData.ok(); return JsonData.ok();
@ -67,6 +72,7 @@ public class UserController {
@PostMapping(Routes.User.ADD_OR_REMOVE_SYS_OWNER) @PostMapping(Routes.User.ADD_OR_REMOVE_SYS_OWNER)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.USER, name = "添加系统管理员", involvedUserId = "#userId")
public JsonData<Void> addSysOwner(@PathVariable Integer userId) { public JsonData<Void> addSysOwner(@PathVariable Integer userId) {
userOperationValidator.forbiddenIfUpdateSelfRole(userId); userOperationValidator.forbiddenIfUpdateSelfRole(userId);
userService.addSysOwnerTo(userId); userService.addSysOwnerTo(userId);
@ -75,6 +81,7 @@ public class UserController {
@DeleteMapping(Routes.User.ADD_OR_REMOVE_SYS_OWNER) @DeleteMapping(Routes.User.ADD_OR_REMOVE_SYS_OWNER)
@PreAuthorize("hasAnyAuthority('SYS_OWNER')") @PreAuthorize("hasAnyAuthority('SYS_OWNER')")
@Operation(module = Operation.Modules.USER, name = "移除系统管理员", involvedUserId = "#userId")
public JsonData<Void> removeSysOwner(@PathVariable Integer userId) { public JsonData<Void> removeSysOwner(@PathVariable Integer userId) {
userOperationValidator.forbiddenIfUpdateSelfRole(userId); userOperationValidator.forbiddenIfUpdateSelfRole(userId);
userService.removeSysOwnerFrom(userId); userService.removeSysOwnerFrom(userId);
@ -82,6 +89,7 @@ public class UserController {
} }
@PostMapping(Routes.User.UPDATE_PASSWORD) @PostMapping(Routes.User.UPDATE_PASSWORD)
@Operation(module = Operation.Modules.USER, name = "更新密码", involvedUserId = "#userId")
public JsonData<Void> updatePassword(@PathVariable Integer userId, public JsonData<Void> updatePassword(@PathVariable Integer userId,
@RequestBody @Valid UserPasswordUpdateRequest request) { @RequestBody @Valid UserPasswordUpdateRequest request) {
if (userOperationValidator.isMyself(userId)) { if (userOperationValidator.isMyself(userId)) {
@ -93,6 +101,7 @@ public class UserController {
} }
@PostMapping(Routes.User.UPDATE_NICKNAME) @PostMapping(Routes.User.UPDATE_NICKNAME)
@Operation(module = Operation.Modules.USER, name = "更新昵称", involvedUserId = "#userId")
public JsonData<Void> updateNickname(@PathVariable Integer userId, public JsonData<Void> updateNickname(@PathVariable Integer userId,
@RequestBody @Valid UserNicknameUpdateRequest request) { @RequestBody @Valid UserNicknameUpdateRequest request) {
if (userOperationValidator.isMyself(userId)) { if (userOperationValidator.isMyself(userId)) {

View File

@ -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();
}
}
}

View File

@ -1,6 +1,9 @@
package com.databasir.job; package com.databasir.job;
import com.databasir.common.JsonData;
import com.databasir.core.domain.document.service.DocumentService; 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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.quartz.Job; import org.quartz.Job;
@ -12,14 +15,47 @@ import org.quartz.JobExecutionException;
@Slf4j @Slf4j
public class ProjectDocumentAutoSyncJob implements Job { public class ProjectDocumentAutoSyncJob implements Job {
private final OperationLogService operationLogService;
@Override @Override
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap dataMap = context.getMergedJobDataMap(); JobDataMap dataMap = context.getMergedJobDataMap();
log.info("start sync project document: " + dataMap.toString()); log.info("start sync project document: " + dataMap.toString());
DocumentService documentService = (DocumentService) dataMap.get("documentService"); DocumentService documentService = (DocumentService) dataMap.get("documentService");
Integer projectId = dataMap.getInt("projectId"); Integer projectId = dataMap.getInt("projectId");
try {
documentService.syncByProjectId(projectId); 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); 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;
}
} }
} }

View File

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

View File

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

View File

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

View File

@ -0,0 +1,22 @@
package com.databasir.core.domain.log.service;
import com.databasir.core.domain.log.converter.OperationLogRequestConverter;
import com.databasir.core.domain.log.data.OperationLogRequest;
import com.databasir.dao.impl.OperationLogDao;
import com.databasir.dao.tables.pojos.OperationLogPojo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class OperationLogService {
private final OperationLogDao operationLogDao;
private final OperationLogRequestConverter operationLogRequestConverter;
public void save(OperationLogRequest request) {
OperationLogPojo pojo = operationLogRequestConverter.toPojo(request);
operationLogDao.insertAndReturnId(pojo);
}
}

View File

@ -1,5 +1,6 @@
package com.databasir.core.infrastructure.converter; package com.databasir.core.infrastructure.converter;
import com.databasir.common.JsonData;
import com.databasir.core.domain.document.data.DatabaseDocumentResponse; import com.databasir.core.domain.document.data.DatabaseDocumentResponse;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
@ -20,12 +21,8 @@ public class JsonConverter {
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
public JSON toJson(List<String> array) { public JSON toJson(List<String> array) {
try { String json = objToJson(array);
String json = objectMapper.writeValueAsString(array);
return JSON.valueOf(json); return JSON.valueOf(json);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
} }
public List<String> fromJson(JSON json) { public List<String> fromJson(JSON json) {
@ -44,12 +41,8 @@ public class JsonConverter {
} }
public JSON toJson(DatabaseDocumentResponse response) { public JSON toJson(DatabaseDocumentResponse response) {
try { String json = objToJson(response);
String json = objectMapper.writeValueAsString(response);
return JSON.valueOf(json); return JSON.valueOf(json);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
} }
public DatabaseDocumentResponse of(JSON json) { public DatabaseDocumentResponse of(JSON json) {
@ -62,4 +55,22 @@ public class JsonConverter {
throw new IllegalArgumentException(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);
}
}
} }

View File

@ -11,6 +11,7 @@ import com.databasir.dao.tables.DatabaseDocumentHistory;
import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.DocumentRemark;
import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Group;
import com.databasir.dao.tables.Login; import com.databasir.dao.tables.Login;
import com.databasir.dao.tables.OperationLog;
import com.databasir.dao.tables.Project; import com.databasir.dao.tables.Project;
import com.databasir.dao.tables.ProjectSyncRule; import com.databasir.dao.tables.ProjectSyncRule;
import com.databasir.dao.tables.SysKey; import com.databasir.dao.tables.SysKey;
@ -78,6 +79,11 @@ public class Databasir extends SchemaImpl {
*/ */
public final Login LOGIN = Login.LOGIN; 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>. * The table <code>databasir.project</code>.
*/ */
@ -151,6 +157,7 @@ public class Databasir extends SchemaImpl {
DocumentRemark.DOCUMENT_REMARK, DocumentRemark.DOCUMENT_REMARK,
Group.GROUP, Group.GROUP,
Login.LOGIN, Login.LOGIN,
OperationLog.OPERATION_LOG,
Project.PROJECT, Project.PROJECT,
ProjectSyncRule.PROJECT_SYNC_RULE, ProjectSyncRule.PROJECT_SYNC_RULE,
SysKey.SYS_KEY, SysKey.SYS_KEY,

View File

@ -11,6 +11,7 @@ import com.databasir.dao.tables.DatabaseDocumentHistory;
import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.DocumentRemark;
import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Group;
import com.databasir.dao.tables.Login; import com.databasir.dao.tables.Login;
import com.databasir.dao.tables.OperationLog;
import com.databasir.dao.tables.Project; import com.databasir.dao.tables.Project;
import com.databasir.dao.tables.ProjectSyncRule; import com.databasir.dao.tables.ProjectSyncRule;
import com.databasir.dao.tables.SysKey; 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.DocumentRemarkRecord;
import com.databasir.dao.tables.records.GroupRecord; import com.databasir.dao.tables.records.GroupRecord;
import com.databasir.dao.tables.records.LoginRecord; 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.ProjectRecord;
import com.databasir.dao.tables.records.ProjectSyncRuleRecord; import com.databasir.dao.tables.records.ProjectSyncRuleRecord;
import com.databasir.dao.tables.records.SysKeyRecord; 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<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_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<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_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<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); 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);

View File

@ -11,6 +11,7 @@ import com.databasir.dao.tables.DatabaseDocumentHistory;
import com.databasir.dao.tables.DocumentRemark; import com.databasir.dao.tables.DocumentRemark;
import com.databasir.dao.tables.Group; import com.databasir.dao.tables.Group;
import com.databasir.dao.tables.Login; import com.databasir.dao.tables.Login;
import com.databasir.dao.tables.OperationLog;
import com.databasir.dao.tables.Project; import com.databasir.dao.tables.Project;
import com.databasir.dao.tables.ProjectSyncRule; import com.databasir.dao.tables.ProjectSyncRule;
import com.databasir.dao.tables.SysKey; import com.databasir.dao.tables.SysKey;
@ -64,6 +65,11 @@ public class Tables {
*/ */
public static final Login LOGIN = Login.LOGIN; 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>. * The table <code>databasir.project</code>.
*/ */

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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());
}
}
}

View File

@ -2,72 +2,75 @@ package com.databasir.dao.impl;
import com.databasir.dao.exception.DataNotExistsException; import com.databasir.dao.exception.DataNotExistsException;
import lombok.RequiredArgsConstructor;
import org.jooq.*; import org.jooq.*;
import org.jooq.Record;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import java.io.Serializable;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@RequiredArgsConstructor public abstract class BaseDao<PO> {
public abstract class BaseDao<T extends Record, R> {
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 abstract DSLContext getDslContext();
public boolean existsById(Integer id) { public <T extends Serializable> boolean existsById(T id) {
return getDslContext().fetchExists(table, identity().eq(id)); return getDslContext().fetchExists(table, identity().eq(id));
} }
public Integer insertAndReturnId(R pojo) { public <T> T insertAndReturnId(PO pojo) {
T record = getDslContext().newRecord(table, pojo); Record record = getDslContext().newRecord(table, pojo);
UpdatableRecord<?> updatableRecord = (UpdatableRecord<?>) record; UpdatableRecord<?> updatableRecord = (UpdatableRecord<?>) record;
updatableRecord.store(); updatableRecord.store();
Object value = updatableRecord.getValue(table.getIdentity().getField()); 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() List<TableRecord<?>> records = pojoList.stream()
.map(pojo -> { .map(pojo -> {
T record = getDslContext().newRecord(table, pojo); Record record = getDslContext().newRecord(table, pojo);
return (TableRecord<?>) record; return (TableRecord<?>) record;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
return Arrays.stream(getDslContext().batchInsert(records).execute()).sum(); return Arrays.stream(getDslContext().batchInsert(records).execute()).sum();
} }
public int deleteById(Integer id) { public <T extends Serializable> int deleteById(T id) {
return getDslContext() return getDslContext()
.deleteFrom(table).where(identity().eq(id)) .deleteFrom(table).where(identity().eq(id))
.execute(); .execute();
} }
public int updateById(R pojo) { public int updateById(PO pojo) {
T record = getDslContext().newRecord(table, pojo); Record record = getDslContext().newRecord(table, pojo);
record.changed(table.getIdentity().getField(), false); record.changed(table.getIdentity().getField(), false);
return getDslContext().executeUpdate((UpdatableRecord<?>) record); return getDslContext().executeUpdate((UpdatableRecord<?>) record);
} }
public Optional<R> selectOptionalById(Integer id) { public <T extends Serializable> Optional<PO> selectOptionalById(T id) {
return getDslContext() return getDslContext()
.select(table.fields()).from(table).where(identity().eq(id)) .select(table.fields()).from(table).where(identity().eq(id))
.fetchOptionalInto(pojoType); .fetchOptionalInto(pojoType);
} }
public R selectById(Integer id) { public <T extends Serializable> PO selectById(T id) {
return selectOptionalById(id) return selectOptionalById(id)
.orElseThrow(() -> new DataNotExistsException("data not exists in " + table.getName() + " with id = " + 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()) { if (ids == null || ids.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -77,12 +80,12 @@ public abstract class BaseDao<T extends Record, R> {
.fetchInto(pojoType); .fetchInto(pojoType);
} }
public Page<R> selectByPage(Pageable request, Condition condition) { public Page<PO> selectByPage(Pageable request, Condition condition) {
Integer count = getDslContext() Integer count = getDslContext()
.selectCount().from(table).where(condition) .selectCount().from(table).where(condition)
.fetchOne(0, int.class); .fetchOne(0, int.class);
int total = count == null ? 0 : count; int total = count == null ? 0 : count;
List<R> data = getDslContext() List<PO> data = getDslContext()
.selectFrom(table).where(condition) .selectFrom(table).where(condition)
.orderBy(getSortFields(request.getSort())) .orderBy(getSortFields(request.getSort()))
.offset(request.getOffset()).limit(request.getPageSize()) .offset(request.getOffset()).limit(request.getPageSize())
@ -110,15 +113,19 @@ public abstract class BaseDao<T extends Record, R> {
return querySortFields; return querySortFields;
} }
protected Field<Integer> identity() { protected <T extends Serializable> Field<T> identity() {
Identity<T, ?> identity = table.getIdentity(); Identity<?, ?> identity = table.getIdentity();
if (identity == null) { if (identity == null) {
throw new IllegalStateException("can not find identity column in " + table.getName()); throw new IllegalStateException("can not find identity column in " + table.getName());
} }
return identity.getField().cast(Integer.class); return identity.getField().cast(identityType());
} }
protected Table<T> table() { protected <T extends Serializable> Class<T> identityType() {
return (Class<T>) Integer.class;
}
protected Table<?> table() {
return this.table; return this.table;
} }
} }

View File

@ -16,7 +16,7 @@ import static com.databasir.dao.Tables.DATA_SOURCE;
@Repository @Repository
public class DataSourceDao extends BaseDao<DataSourceRecord, DataSourcePojo> { public class DataSourceDao extends BaseDao<DataSourcePojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.DataSourcePropertyPojo; import com.databasir.dao.tables.pojos.DataSourcePropertyPojo;
import com.databasir.dao.tables.records.DataSourcePropertyRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.DATA_SOURCE_PROPERTY;
@Repository @Repository
public class DataSourcePropertyDao extends BaseDao<DataSourcePropertyRecord, DataSourcePropertyPojo> { public class DataSourcePropertyDao extends BaseDao<DataSourcePropertyPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -13,7 +13,7 @@ import static com.databasir.dao.Tables.DATABASE_DOCUMENT;
@Repository @Repository
public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentRecord, DatabaseDocumentPojo> { public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.DatabaseDocumentHistoryPojo; import com.databasir.dao.tables.pojos.DatabaseDocumentHistoryPojo;
import com.databasir.dao.tables.records.DatabaseDocumentHistoryRecord;
import com.databasir.dao.value.DatabaseDocumentVersionPojo; import com.databasir.dao.value.DatabaseDocumentVersionPojo;
import lombok.Getter; import lombok.Getter;
import org.jooq.Condition; import org.jooq.Condition;
@ -19,7 +18,7 @@ import static com.databasir.dao.Tables.DATABASE_DOCUMENT_HISTORY;
@Repository @Repository
public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryRecord, DatabaseDocumentHistoryPojo> { public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.DocumentRemarkPojo; import com.databasir.dao.tables.pojos.DocumentRemarkPojo;
import com.databasir.dao.tables.records.DocumentRemarkRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.DOCUMENT_REMARK;
@Repository @Repository
public class DocumentRemarkDao extends BaseDao<DocumentRemarkRecord, DocumentRemarkPojo> { public class DocumentRemarkDao extends BaseDao<DocumentRemarkPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.GroupPojo; import com.databasir.dao.tables.pojos.GroupPojo;
import com.databasir.dao.tables.records.GroupRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.Condition; import org.jooq.Condition;
import org.jooq.DSLContext; import org.jooq.DSLContext;
@ -10,6 +9,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -17,7 +17,7 @@ import java.util.Optional;
import static com.databasir.dao.Tables.GROUP; import static com.databasir.dao.Tables.GROUP;
@Repository @Repository
public class GroupDao extends BaseDao<GroupRecord, GroupPojo> { public class GroupDao extends BaseDao<GroupPojo> {
@Autowired @Autowired
@Getter @Getter
@ -27,10 +27,11 @@ public class GroupDao extends BaseDao<GroupRecord, GroupPojo> {
super(GROUP, GroupPojo.class); super(GROUP, GroupPojo.class);
} }
@Override @Override
public int deleteById(Integer id) { public <T extends Serializable> int deleteById(T id) {
return dslContext 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(); .execute();
} }
@ -40,14 +41,14 @@ public class GroupDao extends BaseDao<GroupRecord, GroupPojo> {
} }
@Override @Override
public Optional<GroupPojo> selectOptionalById(Integer id) { public <T extends Serializable> Optional<GroupPojo> selectOptionalById(T id) {
return getDslContext() 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); .fetchOptionalInto(GroupPojo.class);
} }
@Override @Override
public List<GroupPojo> selectInIds(List<Integer> ids) { public List<GroupPojo> selectInIds(List<? extends Serializable> ids) {
if (ids == null || ids.isEmpty()) { if (ids == null || ids.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.LoginPojo; import com.databasir.dao.tables.pojos.LoginPojo;
import com.databasir.dao.tables.records.LoginRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -14,7 +13,7 @@ import static com.databasir.dao.Tables.LOGIN;
@Repository @Repository
public class LoginDao extends BaseDao<LoginRecord, LoginPojo> { public class LoginDao extends BaseDao<LoginPojo> {
@Autowired @Autowired
@Getter @Getter

View File

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

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.ProjectPojo; import com.databasir.dao.tables.pojos.ProjectPojo;
import com.databasir.dao.tables.records.ProjectRecord;
import com.databasir.dao.value.GroupProjectCountPojo; import com.databasir.dao.value.GroupProjectCountPojo;
import lombok.Getter; import lombok.Getter;
import org.jooq.Condition; import org.jooq.Condition;
@ -12,6 +11,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -22,7 +22,7 @@ import static com.databasir.dao.Tables.PROJECT;
@Repository @Repository
public class ProjectDao extends BaseDao<ProjectRecord, ProjectPojo> { public class ProjectDao extends BaseDao<ProjectPojo> {
@Autowired @Autowired
@Getter @Getter
@ -39,7 +39,7 @@ public class ProjectDao extends BaseDao<ProjectRecord, ProjectPojo> {
} }
@Override @Override
public Optional<ProjectPojo> selectOptionalById(Integer id) { public <T extends Serializable> Optional<ProjectPojo> selectOptionalById(T id) {
return getDslContext() return getDslContext()
.select(PROJECT.fields()).from(PROJECT) .select(PROJECT.fields()).from(PROJECT)
.where(identity().eq(id).and(PROJECT.DELETED.eq(false))) .where(identity().eq(id).and(PROJECT.DELETED.eq(false)))
@ -47,7 +47,7 @@ public class ProjectDao extends BaseDao<ProjectRecord, ProjectPojo> {
} }
@Override @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))); return getDslContext().fetchExists(table(), identity().eq(id).and(PROJECT.DELETED.eq(false)));
} }

View File

@ -16,7 +16,7 @@ import java.util.Optional;
import static com.databasir.dao.Tables.PROJECT_SYNC_RULE; import static com.databasir.dao.Tables.PROJECT_SYNC_RULE;
@Repository @Repository
public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRuleRecord, ProjectSyncRulePojo> { public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRulePojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -2,7 +2,6 @@ package com.databasir.dao.impl;
import com.databasir.dao.exception.DataNotExistsException; import com.databasir.dao.exception.DataNotExistsException;
import com.databasir.dao.tables.pojos.SysKeyPojo; import com.databasir.dao.tables.pojos.SysKeyPojo;
import com.databasir.dao.tables.records.SysKeyRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,7 +12,7 @@ import java.util.Optional;
import static com.databasir.dao.Tables.SYS_KEY; import static com.databasir.dao.Tables.SYS_KEY;
@Repository @Repository
public class SysKeyDao extends BaseDao<SysKeyRecord, SysKeyPojo> { public class SysKeyDao extends BaseDao<SysKeyPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -13,7 +13,7 @@ import java.util.Optional;
import static com.databasir.dao.Tables.SYS_MAIL; import static com.databasir.dao.Tables.SYS_MAIL;
@Repository @Repository
public class SysMailDao extends BaseDao<SysMailRecord, SysMailPojo> { public class SysMailDao extends BaseDao<SysMailPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.TableColumnDocumentPojo; import com.databasir.dao.tables.pojos.TableColumnDocumentPojo;
import com.databasir.dao.tables.records.TableColumnDocumentRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT;
@Repository @Repository
public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentRecord, TableColumnDocumentPojo> { public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.TableDocumentPojo; import com.databasir.dao.tables.pojos.TableDocumentPojo;
import com.databasir.dao.tables.records.TableDocumentRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -12,7 +11,7 @@ import java.util.List;
import static com.databasir.dao.Tables.TABLE_DOCUMENT; import static com.databasir.dao.Tables.TABLE_DOCUMENT;
@Repository @Repository
public class TableDocumentDao extends BaseDao<TableDocumentRecord, TableDocumentPojo> { public class TableDocumentDao extends BaseDao<TableDocumentPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.TableIndexDocumentPojo; import com.databasir.dao.tables.pojos.TableIndexDocumentPojo;
import com.databasir.dao.tables.records.TableIndexDocumentRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,7 +12,7 @@ import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT;
@Repository @Repository
public class TableIndexDocumentDao extends BaseDao<TableIndexDocumentRecord, TableIndexDocumentPojo> { public class TableIndexDocumentDao extends BaseDao<TableIndexDocumentPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.TableTriggerDocumentPojo; import com.databasir.dao.tables.pojos.TableTriggerDocumentPojo;
import com.databasir.dao.tables.records.TableTriggerDocumentRecord;
import lombok.Getter; import lombok.Getter;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -12,7 +11,7 @@ import java.util.List;
import static com.databasir.dao.Tables.TABLE_TRIGGER_DOCUMENT; import static com.databasir.dao.Tables.TABLE_TRIGGER_DOCUMENT;
@Repository @Repository
public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentRecord, TableTriggerDocumentPojo> { public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -2,7 +2,6 @@ package com.databasir.dao.impl;
import com.databasir.dao.Databasir; import com.databasir.dao.Databasir;
import com.databasir.dao.tables.pojos.UserPojo; import com.databasir.dao.tables.pojos.UserPojo;
import com.databasir.dao.tables.records.UserRecord;
import com.databasir.dao.value.GroupMemberDetailPojo; import com.databasir.dao.value.GroupMemberDetailPojo;
import lombok.Getter; import lombok.Getter;
import org.jooq.Condition; import org.jooq.Condition;
@ -23,7 +22,7 @@ import static com.databasir.dao.Tables.USER_ROLE;
@Repository @Repository
public class UserDao extends BaseDao<UserRecord, UserPojo> { public class UserDao extends BaseDao<UserPojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -1,7 +1,6 @@
package com.databasir.dao.impl; package com.databasir.dao.impl;
import com.databasir.dao.tables.pojos.UserRolePojo; import com.databasir.dao.tables.pojos.UserRolePojo;
import com.databasir.dao.tables.records.UserRoleRecord;
import com.databasir.dao.value.GroupMemberSimplePojo; import com.databasir.dao.value.GroupMemberSimplePojo;
import lombok.Getter; import lombok.Getter;
import org.jooq.Condition; import org.jooq.Condition;
@ -19,7 +18,7 @@ import static com.databasir.dao.Tables.USER_ROLE;
@Repository @Repository
public class UserRoleDao extends BaseDao<UserRoleRecord, UserRolePojo> { public class UserRoleDao extends BaseDao<UserRolePojo> {
@Autowired @Autowired
@Getter @Getter

View File

@ -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;