feat: add more detail info in log
This commit is contained in:
parent
e91f78541e
commit
2f09b2e42e
|
@ -4,6 +4,7 @@ import com.databasir.common.JsonData;
|
||||||
import com.databasir.core.domain.app.OpenAuthAppService;
|
import com.databasir.core.domain.app.OpenAuthAppService;
|
||||||
import com.databasir.core.domain.app.data.*;
|
import com.databasir.core.domain.app.data.*;
|
||||||
import com.databasir.core.domain.app.handler.OpenAuthHandlers;
|
import com.databasir.core.domain.app.handler.OpenAuthHandlers;
|
||||||
|
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;
|
||||||
|
@ -21,12 +22,21 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OpenAuth2AppController {
|
public class LoginAppController {
|
||||||
|
|
||||||
private final OpenAuthAppService openAuthAppService;
|
private final OpenAuthAppService openAuthAppService;
|
||||||
|
|
||||||
private final OpenAuthHandlers openAuthHandlers;
|
private final OpenAuthHandlers openAuthHandlers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无需授权
|
||||||
|
*/
|
||||||
|
@GetMapping("/oauth2/apps")
|
||||||
|
@ResponseBody
|
||||||
|
public JsonData<List<OAuthAppResponse>> listApps() {
|
||||||
|
return JsonData.ok(openAuthAppService.listAll());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无需授权
|
* 无需授权
|
||||||
*/
|
*/
|
||||||
|
@ -39,15 +49,6 @@ public class OpenAuth2AppController {
|
||||||
return JsonData.ok(authorization);
|
return JsonData.ok(authorization);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 无需授权
|
|
||||||
*/
|
|
||||||
@GetMapping("/oauth2/apps")
|
|
||||||
@ResponseBody
|
|
||||||
public JsonData<List<OAuthAppResponse>> listApps() {
|
|
||||||
return JsonData.ok(openAuthAppService.listAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(Routes.OAuth2App.LIST_PAGE)
|
@GetMapping(Routes.OAuth2App.LIST_PAGE)
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -68,6 +69,7 @@ public class OpenAuth2AppController {
|
||||||
@PostMapping(Routes.OAuth2App.CREATE)
|
@PostMapping(Routes.OAuth2App.CREATE)
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@Operation(module = Operation.Modules.LOGIN_APP, name = "创建登录应用")
|
||||||
public JsonData<Integer> create(@RequestBody @Valid OAuthAppCreateRequest request) {
|
public JsonData<Integer> create(@RequestBody @Valid OAuthAppCreateRequest request) {
|
||||||
Integer id = openAuthAppService.create(request);
|
Integer id = openAuthAppService.create(request);
|
||||||
return JsonData.ok(id);
|
return JsonData.ok(id);
|
||||||
|
@ -76,6 +78,7 @@ public class OpenAuth2AppController {
|
||||||
@PatchMapping(Routes.OAuth2App.UPDATE)
|
@PatchMapping(Routes.OAuth2App.UPDATE)
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@Operation(module = Operation.Modules.LOGIN_APP, name = "更新登录应用")
|
||||||
public JsonData<Void> updateById(@RequestBody @Valid OAuthAppUpdateRequest request) {
|
public JsonData<Void> updateById(@RequestBody @Valid OAuthAppUpdateRequest request) {
|
||||||
openAuthAppService.updateById(request);
|
openAuthAppService.updateById(request);
|
||||||
return JsonData.ok();
|
return JsonData.ok();
|
||||||
|
@ -84,6 +87,7 @@ public class OpenAuth2AppController {
|
||||||
@DeleteMapping(Routes.OAuth2App.DELETE)
|
@DeleteMapping(Routes.OAuth2App.DELETE)
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
@PreAuthorize("hasAnyAuthority('SYS_OWNER')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@Operation(module = Operation.Modules.LOGIN_APP, name = "删除登录应用")
|
||||||
public JsonData<Void> deleteById(@PathVariable Integer id) {
|
public JsonData<Void> deleteById(@PathVariable Integer id) {
|
||||||
openAuthAppService.deleteById(id);
|
openAuthAppService.deleteById(id);
|
||||||
return JsonData.ok();
|
return JsonData.ok();
|
|
@ -28,13 +28,14 @@ public class SettingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping(Routes.Setting.DELETE_SYS_EMAIL)
|
@DeleteMapping(Routes.Setting.DELETE_SYS_EMAIL)
|
||||||
|
@Operation(module = Operation.Modules.SETTING, name = "重置系统邮箱")
|
||||||
public JsonData<Void> deleteSysEmail() {
|
public JsonData<Void> deleteSysEmail() {
|
||||||
systemService.deleteSystemEmail();
|
systemService.deleteSystemEmail();
|
||||||
return JsonData.ok();
|
return JsonData.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(Routes.Setting.UPDATE_SYS_EMAIL)
|
@PostMapping(Routes.Setting.UPDATE_SYS_EMAIL)
|
||||||
@Operation(module = Operation.Modules.PROJECT, name = "更新邮件配置")
|
@Operation(module = Operation.Modules.SETTING, 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();
|
||||||
|
|
|
@ -5,7 +5,6 @@ spring.datasource.username=root
|
||||||
spring.datasource.password=123456
|
spring.datasource.password=123456
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/databasir
|
spring.datasource.url=jdbc:mysql://localhost:3306/databasir
|
||||||
spring.jooq.sql-dialect=mysql
|
spring.jooq.sql-dialect=mysql
|
||||||
|
|
||||||
spring.flyway.enabled=true
|
spring.flyway.enabled=true
|
||||||
spring.flyway.baseline-on-migrate=true
|
spring.flyway.baseline-on-migrate=true
|
||||||
spring.flyway.locations=classpath:db/migration
|
spring.flyway.locations=classpath:db/migration
|
||||||
|
|
|
@ -33,6 +33,7 @@ public @interface Operation {
|
||||||
String PROJECT = "project";
|
String PROJECT = "project";
|
||||||
String USER = "user";
|
String USER = "user";
|
||||||
String GROUP = "group";
|
String GROUP = "group";
|
||||||
|
String LOGIN_APP = "login_app";
|
||||||
String SETTING = "setting";
|
String SETTING = "setting";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,41 @@ package com.databasir.core.domain.log.converter;
|
||||||
|
|
||||||
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
||||||
import com.databasir.core.infrastructure.converter.JsonConverter;
|
import com.databasir.core.infrastructure.converter.JsonConverter;
|
||||||
|
import com.databasir.dao.tables.pojos.GroupPojo;
|
||||||
import com.databasir.dao.tables.pojos.OperationLogPojo;
|
import com.databasir.dao.tables.pojos.OperationLogPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.ProjectPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.UserPojo;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper(componentModel = "spring", uses = JsonConverter.class)
|
@Mapper(componentModel = "spring", uses = JsonConverter.class)
|
||||||
public interface OperationLogPojoConverter {
|
public interface OperationLogPojoConverter {
|
||||||
|
|
||||||
OperationLogPageResponse to(OperationLogPojo pojo);
|
@Mapping(target = "id", source = "pojo.id")
|
||||||
|
@Mapping(target = "createAt", source = "pojo.createAt")
|
||||||
|
OperationLogPageResponse to(OperationLogPojo pojo,
|
||||||
|
GroupPojo involvedGroup,
|
||||||
|
UserPojo involvedUser,
|
||||||
|
ProjectPojo involvedProject);
|
||||||
|
|
||||||
|
default OperationLogPageResponse to(OperationLogPojo operationLogPojo,
|
||||||
|
Map<Integer, GroupPojo> groupMapById,
|
||||||
|
Map<Integer, UserPojo> userMapById,
|
||||||
|
Map<Integer, ProjectPojo> projectMapById) {
|
||||||
|
GroupPojo group = null;
|
||||||
|
if (operationLogPojo.getInvolvedGroupId() != null) {
|
||||||
|
group = groupMapById.get(operationLogPojo.getInvolvedGroupId());
|
||||||
|
}
|
||||||
|
UserPojo user = null;
|
||||||
|
if (operationLogPojo.getInvolvedUserId() != null) {
|
||||||
|
user = userMapById.get(operationLogPojo.getInvolvedUserId());
|
||||||
|
}
|
||||||
|
ProjectPojo project = null;
|
||||||
|
if (operationLogPojo.getInvolvedProjectId() != null) {
|
||||||
|
project = projectMapById.get(operationLogPojo.getInvolvedProjectId());
|
||||||
|
}
|
||||||
|
return to(operationLogPojo, group, user, project);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.databasir.core.domain.log.data;
|
package com.databasir.core.domain.log.data;
|
||||||
|
|
||||||
import com.databasir.common.JsonData;
|
import com.databasir.common.JsonData;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@ -28,12 +30,43 @@ public class OperationLogPageResponse {
|
||||||
|
|
||||||
private Boolean isSuccess;
|
private Boolean isSuccess;
|
||||||
|
|
||||||
private Integer involvedProjectId;
|
private InvolvedProjectData involvedProject;
|
||||||
|
|
||||||
private Integer involvedGroupId;
|
private InvolvedGroupData involvedGroup;
|
||||||
|
|
||||||
private Integer involvedUserId;
|
private InvolvedUserData involvedUser;
|
||||||
|
|
||||||
private LocalDateTime createAt;
|
private LocalDateTime createAt;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class InvolvedProjectData {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class InvolvedGroupData {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class InvolvedUserData {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String nickname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,36 @@ import com.databasir.core.domain.log.converter.OperationLogRequestConverter;
|
||||||
import com.databasir.core.domain.log.data.OperationLogPageCondition;
|
import com.databasir.core.domain.log.data.OperationLogPageCondition;
|
||||||
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
import com.databasir.core.domain.log.data.OperationLogPageResponse;
|
||||||
import com.databasir.core.domain.log.data.OperationLogRequest;
|
import com.databasir.core.domain.log.data.OperationLogRequest;
|
||||||
|
import com.databasir.dao.impl.GroupDao;
|
||||||
import com.databasir.dao.impl.OperationLogDao;
|
import com.databasir.dao.impl.OperationLogDao;
|
||||||
|
import com.databasir.dao.impl.ProjectDao;
|
||||||
|
import com.databasir.dao.impl.UserDao;
|
||||||
|
import com.databasir.dao.tables.pojos.GroupPojo;
|
||||||
import com.databasir.dao.tables.pojos.OperationLogPojo;
|
import com.databasir.dao.tables.pojos.OperationLogPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.ProjectPojo;
|
||||||
|
import com.databasir.dao.tables.pojos.UserPojo;
|
||||||
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;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OperationLogService {
|
public class OperationLogService {
|
||||||
|
|
||||||
private final OperationLogDao operationLogDao;
|
private final OperationLogDao operationLogDao;
|
||||||
|
|
||||||
|
private final UserDao userDao;
|
||||||
|
|
||||||
|
private final GroupDao groupDao;
|
||||||
|
|
||||||
|
private final ProjectDao projectDao;
|
||||||
|
|
||||||
private final OperationLogRequestConverter operationLogRequestConverter;
|
private final OperationLogRequestConverter operationLogRequestConverter;
|
||||||
|
|
||||||
private final OperationLogPojoConverter operationLogPojoConverter;
|
private final OperationLogPojoConverter operationLogPojoConverter;
|
||||||
|
@ -30,6 +47,26 @@ public class OperationLogService {
|
||||||
public Page<OperationLogPageResponse> list(Pageable page,
|
public Page<OperationLogPageResponse> list(Pageable page,
|
||||||
OperationLogPageCondition condition) {
|
OperationLogPageCondition condition) {
|
||||||
Page<OperationLogPojo> pojoData = operationLogDao.selectByPage(page, condition.toCondition());
|
Page<OperationLogPojo> pojoData = operationLogDao.selectByPage(page, condition.toCondition());
|
||||||
return pojoData.map(operationLogPojoConverter::to);
|
List<Integer> groupIds = pojoData.filter(p -> p.getInvolvedGroupId() != null)
|
||||||
|
.map(OperationLogPojo::getInvolvedGroupId)
|
||||||
|
.toList();
|
||||||
|
Map<Integer, GroupPojo> groupMapById = groupDao.selectAllInIds(groupIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(GroupPojo::getId, Function.identity()));
|
||||||
|
|
||||||
|
List<Integer> userIds = pojoData.filter(p -> p.getInvolvedUserId() != null)
|
||||||
|
.map(OperationLogPojo::getInvolvedUserId)
|
||||||
|
.toList();
|
||||||
|
Map<Integer, UserPojo> userMapById = userDao.selectInIds(userIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(UserPojo::getId, Function.identity()));
|
||||||
|
|
||||||
|
List<Integer> projectIds = pojoData.filter(p -> p.getInvolvedProjectId() != null)
|
||||||
|
.map(OperationLogPojo::getInvolvedProjectId)
|
||||||
|
.toList();
|
||||||
|
Map<Integer, ProjectPojo> projectMapById = projectDao.selectInIds(projectIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ProjectPojo::getId, Function.identity()));
|
||||||
|
return pojoData.map(pojo -> operationLogPojoConverter.to(pojo, groupMapById, userMapById, projectMapById));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,17 @@ public class GroupDao extends BaseDao<GroupPojo> {
|
||||||
.where(GROUP.ID.in(ids)).and(GROUP.DELETED.eq(false))
|
.where(GROUP.ID.in(ids)).and(GROUP.DELETED.eq(false))
|
||||||
.fetchInto(GroupPojo.class);
|
.fetchInto(GroupPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* with deleted
|
||||||
|
*/
|
||||||
|
public List<GroupPojo> selectAllInIds(List<? extends Serializable> ids) {
|
||||||
|
if (ids == null || ids.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return getDslContext()
|
||||||
|
.select(GROUP.fields()).from(GROUP)
|
||||||
|
.where(GROUP.ID.in(ids))
|
||||||
|
.fetchInto(GroupPojo.class);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue