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

@@ -42,12 +42,13 @@ import org.springframework.util.StringUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Collection;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -229,8 +230,22 @@ public class OvertimeApplicationServiceImpl implements OvertimeApplicationServic
@Override @Override
public List<OvertimeApplicationExportVO> getExportList(OvertimeApplicationPageReqVO reqVO) { public List<OvertimeApplicationExportVO> getExportList(OvertimeApplicationPageReqVO reqVO) {
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
PageResult<OvertimeApplicationRespVO> page = getMyPage(reqVO); PageResult<OvertimeApplicationDO> page;
return BeanUtils.toBean(page.getList(), OvertimeApplicationExportVO.class); if (reqVO.getApplicantIds() != null) {
List<Long> applicantIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds(
reqVO.getApplicantIds(), OvertimeApplicationConstants.PERMISSION_TEAM_DASHBOARD);
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
if (loginUserId != null) {
LinkedHashSet<Long> mergedIds = new LinkedHashSet<>(applicantIds);
mergedIds.add(loginUserId);
applicantIds = new ArrayList<>(mergedIds);
}
page = overtimeApplicationMapper.selectMyPage(applicantIds, reqVO, TEAM_VISIBLE_STATUS_CODES);
} else {
page = overtimeApplicationMapper.selectMyPage(SecurityFrameworkUtils.getLoginUserId(), reqVO);
}
return BeanUtils.toBean(BeanUtils.toBean(page, OvertimeApplicationRespVO.class, this::applyStatusView).getList(),
OvertimeApplicationExportVO.class);
} }
private void processApprovalAction(Long id, String actionCode, OvertimeApplicationStatusActionReqVO reqVO) { private void processApprovalAction(Long id, String actionCode, OvertimeApplicationStatusActionReqVO reqVO) {

View File

@@ -265,6 +265,12 @@ public class PerformanceSheetServiceImpl implements PerformanceSheetService {
if (reqVO.getEmployeeIds() != null) { if (reqVO.getEmployeeIds() != null) {
employeeIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds( employeeIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds(
reqVO.getEmployeeIds(), PerformanceConstants.PERMISSION_TEAM_DASHBOARD); reqVO.getEmployeeIds(), PerformanceConstants.PERMISSION_TEAM_DASHBOARD);
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
if (loginUserId != null) {
LinkedHashSet<Long> mergedIds = new LinkedHashSet<>(employeeIds);
mergedIds.add(loginUserId);
employeeIds = new ArrayList<>(mergedIds);
}
} else { } else {
employeeIds = List.of(Objects.requireNonNull(SecurityFrameworkUtils.getLoginUserId())); employeeIds = List.of(Objects.requireNonNull(SecurityFrameworkUtils.getLoginUserId()));
} }

View File

@@ -181,19 +181,6 @@ public class WorkReportCommonService {
return createWeeklyReportInternal(reqVO, overrideReporterId); return createWeeklyReportInternal(reqVO, overrideReporterId);
} }
public WeeklyReportRespVO mergeWeeklyDraft(WeeklyReportRespVO latestDraft, WeeklyReportRefreshDraftReqVO reqVO) {
WeeklyReportRespVO respVO = latestDraft;
respVO.setIsBusinessTrip(Boolean.TRUE.equals(reqVO.getIsBusinessTrip()));
respVO.setTravelSegments(BeanUtils.toBean(defaultList(reqVO.getTravelSegments()), WeeklyReportTravelSegmentRespVO.class));
respVO.setReviewItems(mergeWeeklyReviewItems(reqVO.getReviewItems(), latestDraft.getReviewItems()));
respVO.setPlanItems(mergePlanItems(reqVO.getPlanItems(), latestDraft.getPlanItems()));
respVO.setTotalTravelDays(Boolean.TRUE.equals(reqVO.getIsBusinessTrip())
? defaultIfNull(sumTravelDays(reqVO.getTravelSegments()))
: BigDecimal.ZERO);
respVO.setTotalWorkHours(sumReviewWorkHoursResp(respVO.getReviewItems()));
return respVO;
}
private Long createWeeklyReportInternal(WeeklyReportSaveReqVO reqVO, Long overrideReporterId) { private Long createWeeklyReportInternal(WeeklyReportSaveReqVO reqVO, Long overrideReporterId) {
validatePeriod(reqVO.getPeriodStartDate(), reqVO.getPeriodEndDate()); validatePeriod(reqVO.getPeriodStartDate(), reqVO.getPeriodEndDate());
CurrentUserProfile profile = resolveProfile(overrideReporterId, true); CurrentUserProfile profile = resolveProfile(overrideReporterId, true);
@@ -239,11 +226,23 @@ public class WorkReportCommonService {
} }
public PageResult<WeeklyReportRespVO> getWeeklyReportPage(WeeklyReportPageReqVO reqVO) { public PageResult<WeeklyReportRespVO> getWeeklyReportPage(WeeklyReportPageReqVO reqVO) {
return getWeeklyReportPage(reqVO, false);
}
public PageResult<WeeklyReportRespVO> getWeeklyReportExportPage(WeeklyReportPageReqVO reqVO) {
return getWeeklyReportPage(reqVO, true);
}
private PageResult<WeeklyReportRespVO> getWeeklyReportPage(WeeklyReportPageReqVO reqVO,
boolean includeSelfInTeamMode) {
Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
PageResult<WeeklyReportDO> pageResult; PageResult<WeeklyReportDO> pageResult;
if (reqVO.getReporterIds() != null) { if (reqVO.getReporterIds() != null) {
List<Long> reporterIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds( List<Long> reporterIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds(
reqVO.getReporterIds(), WorkReportConstants.PERMISSION_TEAM_DASHBOARD); reqVO.getReporterIds(), WorkReportConstants.PERMISSION_TEAM_DASHBOARD);
if (includeSelfInTeamMode) {
reporterIds = appendLoginUser(reporterIds);
}
pageResult = weeklyReportMapper.selectReporterPage(reporterIds, reqVO, TEAM_VISIBLE_STATUS_CODES); pageResult = weeklyReportMapper.selectReporterPage(reporterIds, reqVO, TEAM_VISIBLE_STATUS_CODES);
} else { } else {
pageResult = weeklyReportMapper.selectReporterPage(loginUserId, reqVO, getEnabledStatusCodes()); pageResult = weeklyReportMapper.selectReporterPage(loginUserId, reqVO, getEnabledStatusCodes());
@@ -351,14 +350,6 @@ public class WorkReportCommonService {
return createMonthlyReportInternal(reqVO, overrideReporterId); return createMonthlyReportInternal(reqVO, overrideReporterId);
} }
public MonthlyReportRespVO mergeMonthlyDraft(MonthlyReportRespVO latestDraft, MonthlyReportRefreshDraftReqVO reqVO) {
MonthlyReportRespVO respVO = latestDraft;
respVO.setReviewItems(mergeReviewItems(reqVO.getReviewItems(), latestDraft.getReviewItems()));
respVO.setPlanItems(mergePlanItems(reqVO.getPlanItems(), latestDraft.getPlanItems()));
respVO.setTotalWorkHours(sumReviewWorkHoursResp(respVO.getReviewItems()));
return respVO;
}
private Long createMonthlyReportInternal(MonthlyReportSaveReqVO reqVO, Long overrideReporterId) { private Long createMonthlyReportInternal(MonthlyReportSaveReqVO reqVO, Long overrideReporterId) {
validatePeriod(reqVO.getPeriodStartDate(), reqVO.getPeriodEndDate()); validatePeriod(reqVO.getPeriodStartDate(), reqVO.getPeriodEndDate());
CurrentUserProfile profile = resolveProfile(overrideReporterId, true); CurrentUserProfile profile = resolveProfile(overrideReporterId, true);
@@ -404,11 +395,23 @@ public class WorkReportCommonService {
} }
public PageResult<MonthlyReportRespVO> getMonthlyReportPage(MonthlyReportPageReqVO reqVO) { public PageResult<MonthlyReportRespVO> getMonthlyReportPage(MonthlyReportPageReqVO reqVO) {
return getMonthlyReportPage(reqVO, false);
}
public PageResult<MonthlyReportRespVO> getMonthlyReportExportPage(MonthlyReportPageReqVO reqVO) {
return getMonthlyReportPage(reqVO, true);
}
private PageResult<MonthlyReportRespVO> getMonthlyReportPage(MonthlyReportPageReqVO reqVO,
boolean includeSelfInTeamMode) {
Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
PageResult<MonthlyReportDO> pageResult; PageResult<MonthlyReportDO> pageResult;
if (reqVO.getReporterIds() != null) { if (reqVO.getReporterIds() != null) {
List<Long> reporterIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds( List<Long> reporterIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds(
reqVO.getReporterIds(), WorkReportConstants.PERMISSION_TEAM_DASHBOARD); reqVO.getReporterIds(), WorkReportConstants.PERMISSION_TEAM_DASHBOARD);
if (includeSelfInTeamMode) {
reporterIds = appendLoginUser(reporterIds);
}
pageResult = monthlyReportMapper.selectReporterPage(reporterIds, reqVO, TEAM_VISIBLE_STATUS_CODES); pageResult = monthlyReportMapper.selectReporterPage(reporterIds, reqVO, TEAM_VISIBLE_STATUS_CODES);
} else { } else {
pageResult = monthlyReportMapper.selectReporterPage(loginUserId, reqVO, getEnabledStatusCodes()); pageResult = monthlyReportMapper.selectReporterPage(loginUserId, reqVO, getEnabledStatusCodes());
@@ -588,11 +591,23 @@ public class WorkReportCommonService {
} }
public PageResult<ProjectReportRespVO> getProjectReportPage(ProjectReportPageReqVO reqVO) { public PageResult<ProjectReportRespVO> getProjectReportPage(ProjectReportPageReqVO reqVO) {
return getProjectReportPage(reqVO, false);
}
public PageResult<ProjectReportRespVO> getProjectReportExportPage(ProjectReportPageReqVO reqVO) {
return getProjectReportPage(reqVO, true);
}
private PageResult<ProjectReportRespVO> getProjectReportPage(ProjectReportPageReqVO reqVO,
boolean includeSelfInTeamMode) {
Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
PageResult<ProjectReportDO> pageResult; PageResult<ProjectReportDO> pageResult;
if (reqVO.getProjectOwnerIds() != null) { if (reqVO.getProjectOwnerIds() != null) {
List<Long> projectOwnerIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds( List<Long> projectOwnerIds = teamDashboardAccessService.resolveRequestedSubordinateUserIds(
reqVO.getProjectOwnerIds(), WorkReportConstants.PERMISSION_TEAM_DASHBOARD); reqVO.getProjectOwnerIds(), WorkReportConstants.PERMISSION_TEAM_DASHBOARD);
if (includeSelfInTeamMode) {
projectOwnerIds = appendLoginUser(projectOwnerIds);
}
pageResult = projectReportMapper.selectReporterPage(projectOwnerIds, reqVO, TEAM_VISIBLE_STATUS_CODES); pageResult = projectReportMapper.selectReporterPage(projectOwnerIds, reqVO, TEAM_VISIBLE_STATUS_CODES);
} else { } else {
pageResult = projectReportMapper.selectReporterPage(loginUserId, reqVO, getEnabledStatusCodes()); pageResult = projectReportMapper.selectReporterPage(loginUserId, reqVO, getEnabledStatusCodes());
@@ -854,6 +869,16 @@ public class WorkReportCommonService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private List<Long> appendLoginUser(List<Long> userIds) {
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
if (loginUserId == null) {
return userIds;
}
LinkedHashSet<Long> merged = new LinkedHashSet<>(userIds);
merged.add(loginUserId);
return new ArrayList<>(merged);
}
private ObjectStatusModelDO getInitialStatusModel() { private ObjectStatusModelDO getInitialStatusModel() {
ObjectStatusModelDO statusModel = objectStatusModelMapper ObjectStatusModelDO statusModel = objectStatusModelMapper
.selectInitialByObjectTypeEnabled(WorkReportConstants.STATUS_OBJECT_TYPE); .selectInitialByObjectTypeEnabled(WorkReportConstants.STATUS_OBJECT_TYPE);

View File

@@ -91,7 +91,7 @@ public class WorkReportContentExportService {
if (Boolean.TRUE.equals(reqVO.getExportAll())) { if (Boolean.TRUE.equals(reqVO.getExportAll())) {
reqVO.setPageNo(1); reqVO.setPageNo(1);
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
return workReportCommonService.getWeeklyReportPage(reqVO).getList().stream() return workReportCommonService.getWeeklyReportExportPage(reqVO).getList().stream()
.map(item -> workReportCommonService.getWeeklyReport(item.getId())) .map(item -> workReportCommonService.getWeeklyReport(item.getId()))
.toList(); .toList();
} }
@@ -104,7 +104,7 @@ public class WorkReportContentExportService {
if (Boolean.TRUE.equals(reqVO.getExportAll())) { if (Boolean.TRUE.equals(reqVO.getExportAll())) {
reqVO.setPageNo(1); reqVO.setPageNo(1);
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
return workReportCommonService.getMonthlyReportPage(reqVO).getList().stream() return workReportCommonService.getMonthlyReportExportPage(reqVO).getList().stream()
.map(item -> workReportCommonService.getMonthlyReport(item.getId())) .map(item -> workReportCommonService.getMonthlyReport(item.getId()))
.toList(); .toList();
} }
@@ -117,7 +117,7 @@ public class WorkReportContentExportService {
if (Boolean.TRUE.equals(reqVO.getExportAll())) { if (Boolean.TRUE.equals(reqVO.getExportAll())) {
reqVO.setPageNo(1); reqVO.setPageNo(1);
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
return workReportCommonService.getProjectReportPage(reqVO).getList().stream() return workReportCommonService.getProjectReportExportPage(reqVO).getList().stream()
.map(item -> workReportCommonService.getProjectReport(item.getId())) .map(item -> workReportCommonService.getProjectReport(item.getId()))
.toList(); .toList();
} }

View File

@@ -43,8 +43,7 @@ public class MonthlyReportServiceImpl implements MonthlyReportService {
draftReqVO.setPeriodLabel(reqVO.getPeriodLabel()); draftReqVO.setPeriodLabel(reqVO.getPeriodLabel());
draftReqVO.setPeriodStartDate(reqVO.getPeriodStartDate()); draftReqVO.setPeriodStartDate(reqVO.getPeriodStartDate());
draftReqVO.setPeriodEndDate(reqVO.getPeriodEndDate()); draftReqVO.setPeriodEndDate(reqVO.getPeriodEndDate());
MonthlyReportRespVO latestDraft = workReportDefaultDraftService.previewMonthlyDefaultDraft(draftReqVO); return workReportDefaultDraftService.previewMonthlyDefaultDraft(draftReqVO);
return workReportCommonService.mergeMonthlyDraft(latestDraft, reqVO);
} }
@Override @Override

View File

@@ -42,8 +42,7 @@ public class WeeklyReportServiceImpl implements WeeklyReportService {
draftReqVO.setPeriodLabel(reqVO.getPeriodLabel()); draftReqVO.setPeriodLabel(reqVO.getPeriodLabel());
draftReqVO.setPeriodStartDate(reqVO.getPeriodStartDate()); draftReqVO.setPeriodStartDate(reqVO.getPeriodStartDate());
draftReqVO.setPeriodEndDate(reqVO.getPeriodEndDate()); draftReqVO.setPeriodEndDate(reqVO.getPeriodEndDate());
WeeklyReportRespVO latestDraft = workReportDefaultDraftService.previewWeeklyDefaultDraft(draftReqVO); return workReportDefaultDraftService.previewWeeklyDefaultDraft(draftReqVO);
return workReportCommonService.mergeWeeklyDraft(latestDraft, reqVO);
} }
@Override @Override

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.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageParam; import com.njcn.rdms.framework.common.pojo.PageParam;
import com.njcn.rdms.framework.common.pojo.PageResult; 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.common.util.object.BeanUtils;
import com.njcn.rdms.framework.excel.core.util.ExcelUtils; 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.ApiAccessLogPageReqVO;
import com.njcn.rdms.module.system.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO; 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.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.logger.ApiAccessLogService;
import com.njcn.rdms.module.system.service.user.AdminUserService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; 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 org.springframework.web.bind.annotation.RestController;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List; 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.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.njcn.rdms.framework.common.pojo.CommonResult.success; import static com.njcn.rdms.framework.common.pojo.CommonResult.success;
@@ -37,14 +42,17 @@ public class ApiAccessLogController {
@Resource @Resource
private ApiAccessLogService apiAccessLogService; private ApiAccessLogService apiAccessLogService;
@Resource
private AdminUserService adminUserService;
@GetMapping("/get") @GetMapping("/get")
@Operation(summary = "获得 API 访问日志") @Operation(summary = "获得 API 访问日志")
@Parameter(name = "id", description = "编号", required = true, example = "1024") @Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:api-access-log:query')") @PreAuthorize("@ss.hasPermission('system:api-access-log:query')")
public CommonResult<ApiAccessLogRespVO> getApiAccessLog(@RequestParam("id") Long id) { public CommonResult<ApiAccessLogRespVO> getApiAccessLog(@RequestParam("id") Long id) {
ApiAccessLogDO apiAccessLog = apiAccessLogService.getApiAccessLog(id); ApiAccessLogRespVO respVO = BeanUtils.toBean(apiAccessLogService.getApiAccessLog(id), ApiAccessLogRespVO.class);
return success(BeanUtils.toBean(apiAccessLog, ApiAccessLogRespVO.class)); fillUserNicknames(Collections.singletonList(respVO));
return success(respVO);
} }
@GetMapping("/page") @GetMapping("/page")
@@ -52,7 +60,9 @@ public class ApiAccessLogController {
@PreAuthorize("@ss.hasPermission('system:api-access-log:query')") @PreAuthorize("@ss.hasPermission('system:api-access-log:query')")
public CommonResult<PageResult<ApiAccessLogRespVO>> getApiAccessLogPage(@Valid ApiAccessLogPageReqVO pageReqVO) { public CommonResult<PageResult<ApiAccessLogRespVO>> getApiAccessLogPage(@Valid ApiAccessLogPageReqVO pageReqVO) {
PageResult<ApiAccessLogDO> pageResult = apiAccessLogService.getApiAccessLogPage(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") @GetMapping("/export-excel")
@@ -62,10 +72,26 @@ public class ApiAccessLogController {
public void exportApiAccessLogExcel(@Valid ApiAccessLogPageReqVO exportReqVO, public void exportApiAccessLogExcel(@Valid ApiAccessLogPageReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); 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 // 导出 Excel
ExcelUtils.write(response, "API 访问日志.xls", "数据", ApiAccessLogRespVO.class, 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.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageParam; import com.njcn.rdms.framework.common.pojo.PageParam;
import com.njcn.rdms.framework.common.pojo.PageResult; 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.common.util.object.BeanUtils;
import com.njcn.rdms.framework.excel.core.util.ExcelUtils; 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.ApiErrorLogPageReqVO;
import com.njcn.rdms.module.system.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO; 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.dal.dataobject.logger.ApiErrorLogDO;
import com.njcn.rdms.module.system.service.logger.ApiErrorLogService; 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.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
@@ -22,7 +25,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List; 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.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.njcn.rdms.framework.common.pojo.CommonResult.success; import static com.njcn.rdms.framework.common.pojo.CommonResult.success;
@@ -36,6 +41,8 @@ public class ApiErrorLogController {
@Resource @Resource
private ApiErrorLogService apiErrorLogService; private ApiErrorLogService apiErrorLogService;
@Resource
private AdminUserService adminUserService;
@PutMapping("/update-status") @PutMapping("/update-status")
@Operation(summary = "更新 API 错误日志的状态") @Operation(summary = "更新 API 错误日志的状态")
@@ -55,8 +62,9 @@ public class ApiErrorLogController {
@Parameter(name = "id", description = "编号", required = true, example = "1024") @Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:api-error-log:query')") @PreAuthorize("@ss.hasPermission('system:api-error-log:query')")
public CommonResult<ApiErrorLogRespVO> getApiErrorLog(@RequestParam("id") Long id) { public CommonResult<ApiErrorLogRespVO> getApiErrorLog(@RequestParam("id") Long id) {
ApiErrorLogDO apiErrorLog = apiErrorLogService.getApiErrorLog(id); ApiErrorLogRespVO respVO = BeanUtils.toBean(apiErrorLogService.getApiErrorLog(id), ApiErrorLogRespVO.class);
return success(BeanUtils.toBean(apiErrorLog, ApiErrorLogRespVO.class)); fillUserNicknames(Collections.singletonList(respVO));
return success(respVO);
} }
@GetMapping("/page") @GetMapping("/page")
@@ -64,7 +72,9 @@ public class ApiErrorLogController {
@PreAuthorize("@ss.hasPermission('system:api-error-log:query')") @PreAuthorize("@ss.hasPermission('system:api-error-log:query')")
public CommonResult<PageResult<ApiErrorLogRespVO>> getApiErrorLogPage(@Valid ApiErrorLogPageReqVO pageReqVO) { public CommonResult<PageResult<ApiErrorLogRespVO>> getApiErrorLogPage(@Valid ApiErrorLogPageReqVO pageReqVO) {
PageResult<ApiErrorLogDO> pageResult = apiErrorLogService.getApiErrorLogPage(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") @GetMapping("/export-excel")
@@ -74,10 +84,26 @@ public class ApiErrorLogController {
public void exportApiErrorLogExcel(@Valid ApiErrorLogPageReqVO exportReqVO, public void exportApiErrorLogExcel(@Valid ApiErrorLogPageReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); 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 // 导出 Excel
ExcelUtils.write(response, "API 错误日志.xls", "数据", ApiErrorLogRespVO.class, 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 { public class ApiAccessLogRespVO {
@Schema(description = "日志主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "日志主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("日志主键") //@ExcelProperty("日志主键")
private Long id; private Long id;
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002") @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002")
@@ -24,9 +24,13 @@ public class ApiAccessLogRespVO {
private String traceId; private String traceId;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
@ExcelProperty("用户编号") //@ExcelProperty("用户编号")
private Long userId; private Long userId;
@Schema(description = "用户姓名", example = "灿能管理员")
@ExcelProperty("用户姓名")
private String userNickname;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty(value = "用户类型", converter = DictConvert.class) @ExcelProperty(value = "用户类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.USER_TYPE) @DictFormat(DictTypeConstants.USER_TYPE)

View File

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

View File

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

View File

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