fix(工作报告、我的绩效、加班申请、日志管理): 优化报表导出逻辑并补充日志用户昵称,团队模式查询现正确包含当前用户数据。

This commit is contained in:
dk
2026-07-01 17:06:44 +08:00
parent 79f48bd283
commit 77b660cc34
12 changed files with 151 additions and 47 deletions

View File

@@ -4,12 +4,15 @@ import com.njcn.rdms.framework.apilog.core.annotation.ApiAccessLog;
import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageParam;
import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.framework.common.util.collection.CollectionUtils;
import com.njcn.rdms.framework.common.util.object.BeanUtils;
import com.njcn.rdms.framework.excel.core.util.ExcelUtils;
import com.njcn.rdms.module.system.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
import com.njcn.rdms.module.system.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO;
import com.njcn.rdms.module.system.dal.dataobject.logger.ApiAccessLogDO;
import com.njcn.rdms.module.system.dal.dataobject.user.AdminUserDO;
import com.njcn.rdms.module.system.service.logger.ApiAccessLogService;
import com.njcn.rdms.module.system.service.user.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -24,7 +27,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.njcn.rdms.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.njcn.rdms.framework.common.pojo.CommonResult.success;
@@ -37,14 +42,17 @@ public class ApiAccessLogController {
@Resource
private ApiAccessLogService apiAccessLogService;
@Resource
private AdminUserService adminUserService;
@GetMapping("/get")
@Operation(summary = "获得 API 访问日志")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:api-access-log:query')")
public CommonResult<ApiAccessLogRespVO> getApiAccessLog(@RequestParam("id") Long id) {
ApiAccessLogDO apiAccessLog = apiAccessLogService.getApiAccessLog(id);
return success(BeanUtils.toBean(apiAccessLog, ApiAccessLogRespVO.class));
ApiAccessLogRespVO respVO = BeanUtils.toBean(apiAccessLogService.getApiAccessLog(id), ApiAccessLogRespVO.class);
fillUserNicknames(Collections.singletonList(respVO));
return success(respVO);
}
@GetMapping("/page")
@@ -52,7 +60,9 @@ public class ApiAccessLogController {
@PreAuthorize("@ss.hasPermission('system:api-access-log:query')")
public CommonResult<PageResult<ApiAccessLogRespVO>> getApiAccessLogPage(@Valid ApiAccessLogPageReqVO pageReqVO) {
PageResult<ApiAccessLogDO> pageResult = apiAccessLogService.getApiAccessLogPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ApiAccessLogRespVO.class));
PageResult<ApiAccessLogRespVO> respPageResult = BeanUtils.toBean(pageResult, ApiAccessLogRespVO.class);
fillUserNicknames(respPageResult.getList());
return success(respPageResult);
}
@GetMapping("/export-excel")
@@ -62,10 +72,26 @@ public class ApiAccessLogController {
public void exportApiAccessLogExcel(@Valid ApiAccessLogPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ApiAccessLogDO> list = apiAccessLogService.getApiAccessLogPage(exportReqVO).getList();
List<ApiAccessLogRespVO> respVOList = BeanUtils.toBean(
apiAccessLogService.getApiAccessLogPage(exportReqVO).getList(), ApiAccessLogRespVO.class);
fillUserNicknames(respVOList);
// 导出 Excel
ExcelUtils.write(response, "API 访问日志.xls", "数据", ApiAccessLogRespVO.class,
BeanUtils.toBean(list, ApiAccessLogRespVO.class));
respVOList);
}
private void fillUserNicknames(List<ApiAccessLogRespVO> respVOList) {
if (respVOList == null || respVOList.isEmpty()) {
return;
}
Map<Long, AdminUserDO> userMap = adminUserService.getUserMap(
CollectionUtils.convertSet(respVOList, ApiAccessLogRespVO::getUserId));
respVOList.forEach(respVO -> {
AdminUserDO user = userMap.get(respVO.getUserId());
if (user != null) {
respVO.setUserNickname(user.getNickname());
}
});
}
}

View File

@@ -4,12 +4,15 @@ import com.njcn.rdms.framework.apilog.core.annotation.ApiAccessLog;
import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageParam;
import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.framework.common.util.collection.CollectionUtils;
import com.njcn.rdms.framework.common.util.object.BeanUtils;
import com.njcn.rdms.framework.excel.core.util.ExcelUtils;
import com.njcn.rdms.module.system.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
import com.njcn.rdms.module.system.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO;
import com.njcn.rdms.module.system.dal.dataobject.logger.ApiErrorLogDO;
import com.njcn.rdms.module.system.service.logger.ApiErrorLogService;
import com.njcn.rdms.module.system.dal.dataobject.user.AdminUserDO;
import com.njcn.rdms.module.system.service.user.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@@ -22,7 +25,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.njcn.rdms.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.njcn.rdms.framework.common.pojo.CommonResult.success;
@@ -36,6 +41,8 @@ public class ApiErrorLogController {
@Resource
private ApiErrorLogService apiErrorLogService;
@Resource
private AdminUserService adminUserService;
@PutMapping("/update-status")
@Operation(summary = "更新 API 错误日志的状态")
@@ -55,8 +62,9 @@ public class ApiErrorLogController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:api-error-log:query')")
public CommonResult<ApiErrorLogRespVO> getApiErrorLog(@RequestParam("id") Long id) {
ApiErrorLogDO apiErrorLog = apiErrorLogService.getApiErrorLog(id);
return success(BeanUtils.toBean(apiErrorLog, ApiErrorLogRespVO.class));
ApiErrorLogRespVO respVO = BeanUtils.toBean(apiErrorLogService.getApiErrorLog(id), ApiErrorLogRespVO.class);
fillUserNicknames(Collections.singletonList(respVO));
return success(respVO);
}
@GetMapping("/page")
@@ -64,7 +72,9 @@ public class ApiErrorLogController {
@PreAuthorize("@ss.hasPermission('system:api-error-log:query')")
public CommonResult<PageResult<ApiErrorLogRespVO>> getApiErrorLogPage(@Valid ApiErrorLogPageReqVO pageReqVO) {
PageResult<ApiErrorLogDO> pageResult = apiErrorLogService.getApiErrorLogPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ApiErrorLogRespVO.class));
PageResult<ApiErrorLogRespVO> respPageResult = BeanUtils.toBean(pageResult, ApiErrorLogRespVO.class);
fillUserNicknames(respPageResult.getList());
return success(respPageResult);
}
@GetMapping("/export-excel")
@@ -74,10 +84,26 @@ public class ApiErrorLogController {
public void exportApiErrorLogExcel(@Valid ApiErrorLogPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ApiErrorLogDO> list = apiErrorLogService.getApiErrorLogPage(exportReqVO).getList();
List<ApiErrorLogRespVO> respVOList = BeanUtils.toBean(
apiErrorLogService.getApiErrorLogPage(exportReqVO).getList(), ApiErrorLogRespVO.class);
fillUserNicknames(respVOList);
// 导出 Excel
ExcelUtils.write(response, "API 错误日志.xls", "数据", ApiErrorLogRespVO.class,
BeanUtils.toBean(list, ApiErrorLogRespVO.class));
respVOList);
}
private void fillUserNicknames(List<ApiErrorLogRespVO> respVOList) {
if (respVOList == null || respVOList.isEmpty()) {
return;
}
Map<Long, AdminUserDO> userMap = adminUserService.getUserMap(
CollectionUtils.convertSet(respVOList, ApiErrorLogRespVO::getUserId));
respVOList.forEach(respVO -> {
AdminUserDO user = userMap.get(respVO.getUserId());
if (user != null) {
respVO.setUserNickname(user.getNickname());
}
});
}
}

View File

@@ -16,7 +16,7 @@ import java.time.LocalDateTime;
public class ApiAccessLogRespVO {
@Schema(description = "日志主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("日志主键")
//@ExcelProperty("日志主键")
private Long id;
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002")
@@ -24,9 +24,13 @@ public class ApiAccessLogRespVO {
private String traceId;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
@ExcelProperty("用户编号")
//@ExcelProperty("用户编号")
private Long userId;
@Schema(description = "用户姓名", example = "灿能管理员")
@ExcelProperty("用户姓名")
private String userNickname;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.USER_TYPE)

View File

@@ -16,7 +16,7 @@ import java.time.LocalDateTime;
public class ApiErrorLogRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("编号")
//@ExcelProperty("编号")
private Long id;
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002")
@@ -24,9 +24,13 @@ public class ApiErrorLogRespVO {
private String traceId;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
@ExcelProperty("用户编号")
//@ExcelProperty("用户编号")
private Long userId;
@Schema(description = "用户姓名", example = "灿能管理员")
@ExcelProperty("用户姓名")
private String userNickname;
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.USER_TYPE)

View File

@@ -16,7 +16,7 @@ import java.time.LocalDateTime;
public class LoginLogRespVO {
@Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("日志主键")
//@ExcelProperty("日志主键")
private Long id;
@Schema(description = "日志类型,参见 LoginLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")

View File

@@ -17,7 +17,7 @@ import java.time.LocalDateTime;
public class OperateLogRespVO implements VO {
@Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("日志编号")
//@ExcelProperty("日志编号")
private Long id;
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab")