refactor: 适配pure-admin登录日志页面

This commit is contained in:
valarchie
2023-07-16 21:39:07 +08:00
parent 97fc6d0367
commit 1382d2a32d
6 changed files with 31 additions and 28 deletions

View File

@@ -7,8 +7,8 @@ import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.utils.poi.CustomExcelUtil;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.system.log.LogApplicationService;
import com.agileboot.domain.system.log.dto.LoginInfoDTO;
import com.agileboot.domain.system.log.query.LoginInfoQuery;
import com.agileboot.domain.system.log.dto.LoginLogDTO;
import com.agileboot.domain.system.log.query.LoginLogQuery;
import com.agileboot.domain.system.log.dto.OperationLogDTO;
import com.agileboot.domain.system.log.dto.OperationLogQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
@@ -45,27 +45,27 @@ public class SysLogsController extends BaseController {
@Operation(summary = "登录日志列表")
@PreAuthorize("@permission.has('monitor:logininfor:list')")
@GetMapping("/loginInfos")
public ResponseDTO<PageDTO<LoginInfoDTO>> loginInfoList(LoginInfoQuery query) {
PageDTO<LoginInfoDTO> pageDTO = logApplicationService.getLoginInfoList(query);
@GetMapping("/loginLogs")
public ResponseDTO<PageDTO<LoginLogDTO>> loginInfoList(LoginLogQuery query) {
PageDTO<LoginLogDTO> pageDTO = logApplicationService.getLoginInfoList(query);
return ResponseDTO.ok(pageDTO);
}
@Operation(summary = "登录日志导出", description = "将登录日志导出到excel")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('monitor:logininfor:export')")
@PostMapping("/loginInfos/excel")
public void loginInfosExcel(HttpServletResponse response, LoginInfoQuery query) {
PageDTO<LoginInfoDTO> pageDTO = logApplicationService.getLoginInfoList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), LoginInfoDTO.class, response);
@GetMapping("/loginLogs/excel")
public void loginInfosExcel(HttpServletResponse response, LoginLogQuery query) {
PageDTO<LoginLogDTO> pageDTO = logApplicationService.getLoginInfoList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), LoginLogDTO.class, response);
}
@Operation(summary = "删除登录日志")
@PreAuthorize("@permission.has('monitor:logininfor:remove')")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/loginInfos")
public ResponseDTO<Void> removeLoginInfos(@RequestParam @NotNull @NotEmpty List<Long> infoIds) {
logApplicationService.deleteLoginInfo(new BulkOperationCommand<>(infoIds));
@DeleteMapping("/loginLogs")
public ResponseDTO<Void> removeLoginInfos(@RequestParam @NotNull @NotEmpty List<Long> ids) {
logApplicationService.deleteLoginInfo(new BulkOperationCommand<>(ids));
return ResponseDTO.ok();
}

View File

@@ -3,9 +3,10 @@ package com.agileboot.domain.common.command;
import cn.hutool.core.collection.CollUtil;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.Data;
/**
@@ -22,6 +23,6 @@ public class BulkOperationCommand<T> {
this.ids = new HashSet<>(idList);
}
private Collection<T> ids;
private Set<T> ids;
}

View File

@@ -2,8 +2,8 @@ package com.agileboot.domain.system.log;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.system.log.dto.LoginInfoDTO;
import com.agileboot.domain.system.log.query.LoginInfoQuery;
import com.agileboot.domain.system.log.dto.LoginLogDTO;
import com.agileboot.domain.system.log.query.LoginLogQuery;
import com.agileboot.domain.system.log.dto.OperationLogDTO;
import com.agileboot.domain.system.log.dto.OperationLogQuery;
import com.agileboot.orm.system.entity.SysLoginInfoEntity;
@@ -25,15 +25,16 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class LogApplicationService {
// TODO 命名到时候统一改成叫LoginLog
@NonNull
private ISysLoginInfoService loginInfoService;
@NonNull
private ISysOperationLogService operationLogService;
public PageDTO<LoginInfoDTO> getLoginInfoList(LoginInfoQuery query) {
public PageDTO<LoginLogDTO> getLoginInfoList(LoginLogQuery query) {
Page<SysLoginInfoEntity> page = loginInfoService.page(query.toPage(), query.toQueryWrapper());
List<LoginInfoDTO> records = page.getRecords().stream().map(LoginInfoDTO::new).collect(Collectors.toList());
List<LoginLogDTO> records = page.getRecords().stream().map(LoginLogDTO::new).collect(Collectors.toList());
return new PageDTO<>(records, page.getTotal());
}

View File

@@ -13,11 +13,11 @@ import lombok.Data;
*/
@Data
@ExcelSheet(name = "登录日志")
public class LoginInfoDTO {
public class LoginLogDTO {
public LoginInfoDTO(SysLoginInfoEntity entity) {
public LoginLogDTO(SysLoginInfoEntity entity) {
if (entity != null) {
infoId = entity.getInfoId() + "";
logId = entity.getInfoId() + "";
username = entity.getUsername();
ipAddress = entity.getIpAddress();
loginLocation = entity.getLoginLocation();
@@ -32,7 +32,7 @@ public class LoginInfoDTO {
@ExcelColumn(name = "ID")
private String infoId;
private String logId;
@ExcelColumn(name = "用户名")
private String username;

View File

@@ -12,9 +12,9 @@ import lombok.EqualsAndHashCode;
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class LoginInfoQuery extends AbstractPageQuery<SysLoginInfoEntity> {
public class LoginLogQuery extends AbstractPageQuery<SysLoginInfoEntity> {
private String ipaddr;
private String ipAddress;
private String status;
private String username;
@@ -22,13 +22,14 @@ public class LoginInfoQuery extends AbstractPageQuery<SysLoginInfoEntity> {
@Override
public QueryWrapper<SysLoginInfoEntity> addQueryCondition() {
QueryWrapper<SysLoginInfoEntity> queryWrapper = new QueryWrapper<SysLoginInfoEntity>()
.like(StrUtil.isNotEmpty(ipaddr), "ip_address", ipaddr)
.like(StrUtil.isNotEmpty(ipAddress), "ip_address", ipAddress)
.eq(StrUtil.isNotEmpty(status), "status", status)
.like(StrUtil.isNotEmpty(username), "username", username);
addSortCondition(queryWrapper);
this.timeRangeColumn = "login_time";
// 可以手动设置 也可以由前端传回
// this.timeRangeColumn = "login_time";
// addTimeCondition(queryWrapper, "login_time");
return queryWrapper;

View File

@@ -6,10 +6,10 @@ import com.agileboot.orm.common.interfaces.DictionaryEnum;
/**
* 用户状态
*
* @author valarchie
*/
@Dictionary(name = "sysLoginInfo.status")
// TODO 表记得改成LoginLog
@Dictionary(name = "sysLoginLog.status")
public enum LoginStatusEnum implements DictionaryEnum<Integer> {
/**
* status of user