移除废弃接口
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
			
		||||
package user
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"strconv"
 | 
			
		||||
 | 
			
		||||
	"git.huangwc.com/pig/pig-farm-controller/internal/app/controller"
 | 
			
		||||
@@ -128,68 +127,6 @@ func (c *Controller) Login(ctx echo.Context) error {
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListUserHistory godoc
 | 
			
		||||
// @Summary      获取指定用户的操作历史
 | 
			
		||||
// @Description  根据用户ID,分页获取该用户的操作审计日志。支持与通用日志查询接口相同的过滤和排序参数。
 | 
			
		||||
// @Tags         用户管理
 | 
			
		||||
// @Security     BearerAuth
 | 
			
		||||
// @Produce      json
 | 
			
		||||
// @Param        id    path      int  true  "用户ID"
 | 
			
		||||
// @Param        query query     dto.ListUserActionLogRequest false "查询参数 (除了 user_id,它被路径中的ID覆盖)"
 | 
			
		||||
// @Success      200   {object}  controller.Response{data=dto.ListUserActionLogResponse} "业务码为200代表成功获取"
 | 
			
		||||
// @Router       /api/v1/users/{id}/history [get]
 | 
			
		||||
func (c *Controller) ListUserHistory(ctx echo.Context) error {
 | 
			
		||||
	const actionType = "获取用户操作历史"
 | 
			
		||||
 | 
			
		||||
	// 1. 解析路径中的用户ID,它的优先级最高
 | 
			
		||||
	userIDStr := ctx.Param("id")
 | 
			
		||||
	userID, err := strconv.ParseUint(userIDStr, 10, 64)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		c.logger.Errorf("%s: 无效的用户ID格式: %v, ID: %s", actionType, err, userIDStr)
 | 
			
		||||
		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的用户ID格式", actionType, "无效的用户ID格式", userIDStr)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 2. 绑定通用的查询请求 DTO
 | 
			
		||||
	var req dto.ListUserActionLogRequest
 | 
			
		||||
	if err := ctx.Bind(&req); err != nil {
 | 
			
		||||
		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | 
			
		||||
		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 3. 准备 Service 调用参数,并强制使用路径中的 UserID
 | 
			
		||||
	uid := uint(userID)
 | 
			
		||||
	req.UserID = &uid // 强制覆盖
 | 
			
		||||
 | 
			
		||||
	opts := repository.UserActionLogListOptions{
 | 
			
		||||
		UserID:     req.UserID,
 | 
			
		||||
		Username:   req.Username,
 | 
			
		||||
		ActionType: req.ActionType,
 | 
			
		||||
		OrderBy:    req.OrderBy,
 | 
			
		||||
		StartTime:  req.StartTime,
 | 
			
		||||
		EndTime:    req.EndTime,
 | 
			
		||||
	}
 | 
			
		||||
	if req.Status != nil {
 | 
			
		||||
		status := models.AuditStatus(*req.Status)
 | 
			
		||||
		opts.Status = &status
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 4. 调用 monitorService,复用其业务逻辑
 | 
			
		||||
	data, total, err := c.monitorService.ListUserActionLogs(opts, req.Page, req.PageSize)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if errors.Is(err, repository.ErrInvalidPagination) {
 | 
			
		||||
			c.logger.Warnf("%s: 无效的分页参数: %v", actionType, err)
 | 
			
		||||
			return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的分页参数: "+err.Error(), actionType, "无效分页参数", opts)
 | 
			
		||||
		}
 | 
			
		||||
		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | 
			
		||||
		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取用户历史记录失败", actionType, "服务层查询失败", opts)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 5. 使用复用的 DTO 构建并发送成功响应
 | 
			
		||||
	resp := dto.NewListUserActionLogResponse(data, total, req.Page, req.PageSize)
 | 
			
		||||
	c.logger.Infof("%s: 成功获取用户 %d 的操作历史, 数量: %d", actionType, userID, len(data))
 | 
			
		||||
	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取用户操作历史成功", resp, actionType, "获取用户操作历史成功", opts)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendTestNotification godoc
 | 
			
		||||
// @Summary      发送测试通知
 | 
			
		||||
// @Description  为指定用户发送一条特定渠道的测试消息,以验证其配置是否正确。
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user