| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package com.zxyj.controller.admin;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.zxyj.common.Result;
- import com.zxyj.entity.UserOperationLog;
- import com.zxyj.service.UserOperationLogService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.format.annotation.DateTimeFormat;
- import javax.annotation.Resource;
- import org.springframework.web.bind.annotation.*;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- @Tag(name = "日志管理", description = "操作日志查询接口")
- @RestController
- @RequestMapping("/api/admin/logs")
- public class OperationLogController {
- @Resource
- private UserOperationLogService logService;
- @Operation(summary = "分页查询操作日志")
- @PostMapping("/operations")
- public Result<Page<UserOperationLog>> queryLogs(
- @RequestAttribute("userId") Long adminId,
- @RequestBody Map<String, Object> params) {
- Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
- String operationType = (String) params.get("operationType");
- Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
- Integer size = params.get("size") != null ? (Integer) params.get("size") : 20;
- // 解析日期
- Date startDate = null;
- Date endDate = null;
- try {
- if (params.get("startDate") != null) {
- java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
- startDate = sdf.parse((String) params.get("startDate"));
- }
- if (params.get("endDate") != null) {
- java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
- endDate = sdf.parse((String) params.get("endDate"));
- }
- } catch (Exception e) {
- // 日期解析失败
- }
- Page<UserOperationLog> result = logService.queryLogs(
- userId, operationType, startDate, endDate, page, size);
- return Result.success(result);
- }
- @Operation(summary = "获取用户最近操作记录")
- @PostMapping("/recent")
- public Result<List<UserOperationLog>> getRecentLogs(
- @RequestAttribute("userId") Long adminId,
- @RequestBody Map<String, Object> params) {
- Long userId = ((Number) params.get("userId")).longValue();
- Integer limit = params.get("limit") != null ? (Integer) params.get("limit") : 10;
- List<UserOperationLog> logs = logService.getRecentLogs(userId, limit);
- return Result.success(logs);
- }
- }
|