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> queryLogs( @RequestAttribute("userId") Long adminId, @RequestBody Map 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 result = logService.queryLogs( userId, operationType, startDate, endDate, page, size); return Result.success(result); } @Operation(summary = "获取用户最近操作记录") @PostMapping("/recent") public Result> getRecentLogs( @RequestAttribute("userId") Long adminId, @RequestBody Map params) { Long userId = ((Number) params.get("userId")).longValue(); Integer limit = params.get("limit") != null ? (Integer) params.get("limit") : 10; List logs = logService.getRecentLogs(userId, limit); return Result.success(logs); } }