835 lines
		
	
	
		
			38 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			835 lines
		
	
	
		
			38 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package monitor
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 
 | |
| 	"git.huangwc.com/pig/pig-farm-controller/internal/app/controller"
 | |
| 	"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
 | |
| 	"git.huangwc.com/pig/pig-farm-controller/internal/app/service"
 | |
| 	"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
 | |
| 	"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
 | |
| 	"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
 | |
| 	"github.com/labstack/echo/v4"
 | |
| )
 | |
| 
 | |
| // Controller 监控控制器,封装了所有与数据监控相关的业务逻辑
 | |
| type Controller struct {
 | |
| 	monitorService service.MonitorService
 | |
| 	logger         *logs.Logger
 | |
| }
 | |
| 
 | |
| // NewController 创建一个新的监控控制器实例
 | |
| func NewController(monitorService service.MonitorService, logger *logs.Logger) *Controller {
 | |
| 	return &Controller{
 | |
| 		monitorService: monitorService,
 | |
| 		logger:         logger,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // ListSensorData godoc
 | |
| // @Summary      获取传感器数据列表
 | |
| // @Description  根据提供的过滤条件,分页获取传感器数据
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListSensorDataRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListSensorDataResponse}
 | |
| // @Router       /api/v1/monitor/sensor-data [get]
 | |
| func (c *Controller) ListSensorData(ctx echo.Context) error {
 | |
| 	const actionType = "获取传感器数据列表"
 | |
| 
 | |
| 	var req dto.ListSensorDataRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.SensorDataListOptions{
 | |
| 		DeviceID:  req.DeviceID,
 | |
| 		OrderBy:   req.OrderBy,
 | |
| 		StartTime: req.StartTime,
 | |
| 		EndTime:   req.EndTime,
 | |
| 	}
 | |
| 	if req.SensorType != nil {
 | |
| 		sensorType := models.SensorType(*req.SensorType)
 | |
| 		opts.SensorType = &sensorType
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListSensorData(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取传感器数据失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListSensorDataResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取传感器数据成功", resp, actionType, "获取传感器数据成功", req)
 | |
| }
 | |
| 
 | |
| // ListDeviceCommandLogs godoc
 | |
| // @Summary      获取设备命令日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取设备命令日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListDeviceCommandLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListDeviceCommandLogResponse}
 | |
| // @Router       /api/v1/monitor/device-command-logs [get]
 | |
| func (c *Controller) ListDeviceCommandLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取设备命令日志列表"
 | |
| 
 | |
| 	var req dto.ListDeviceCommandLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.DeviceCommandLogListOptions{
 | |
| 		DeviceID:        req.DeviceID,
 | |
| 		ReceivedSuccess: req.ReceivedSuccess,
 | |
| 		OrderBy:         req.OrderBy,
 | |
| 		StartTime:       req.StartTime,
 | |
| 		EndTime:         req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListDeviceCommandLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取设备命令日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListDeviceCommandLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取设备命令日志成功", resp, actionType, "获取设备命令日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListPlanExecutionLogs godoc
 | |
| // @Summary      获取计划执行日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取计划执行日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPlanExecutionLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPlanExecutionLogResponse}
 | |
| // @Router       /api/v1/monitor/plan-execution-logs [get]
 | |
| func (c *Controller) ListPlanExecutionLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取计划执行日志列表"
 | |
| 
 | |
| 	var req dto.ListPlanExecutionLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PlanExecutionLogListOptions{
 | |
| 		PlanID:    req.PlanID,
 | |
| 		OrderBy:   req.OrderBy,
 | |
| 		StartTime: req.StartTime,
 | |
| 		EndTime:   req.EndTime,
 | |
| 	}
 | |
| 	if req.Status != nil {
 | |
| 		status := models.ExecutionStatus(*req.Status)
 | |
| 		opts.Status = &status
 | |
| 	}
 | |
| 
 | |
| 	planLogs, plans, total, err := c.monitorService.ListPlanExecutionLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取计划执行日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPlanExecutionLogResponse(planLogs, plans, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(planLogs), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取计划执行日志成功", resp, actionType, "获取计划执行日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListTaskExecutionLogs godoc
 | |
| // @Summary      获取任务执行日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取任务执行日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListTaskExecutionLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListTaskExecutionLogResponse}
 | |
| // @Router       /api/v1/monitor/task-execution-logs [get]
 | |
| func (c *Controller) ListTaskExecutionLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取任务执行日志列表"
 | |
| 
 | |
| 	var req dto.ListTaskExecutionLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.TaskExecutionLogListOptions{
 | |
| 		PlanExecutionLogID: req.PlanExecutionLogID,
 | |
| 		TaskID:             req.TaskID,
 | |
| 		OrderBy:            req.OrderBy,
 | |
| 		StartTime:          req.StartTime,
 | |
| 		EndTime:            req.EndTime,
 | |
| 	}
 | |
| 	if req.Status != nil {
 | |
| 		status := models.ExecutionStatus(*req.Status)
 | |
| 		opts.Status = &status
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListTaskExecutionLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取任务执行日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListTaskExecutionLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取任务执行日志成功", resp, actionType, "获取任务执行日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListPendingCollections godoc
 | |
| // @Summary      获取待采集请求列表
 | |
| // @Description  根据提供的过滤条件,分页获取待采集请求
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPendingCollectionRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPendingCollectionResponse}
 | |
| // @Router       /api/v1/monitor/pending-collections [get]
 | |
| func (c *Controller) ListPendingCollections(ctx echo.Context) error {
 | |
| 	const actionType = "获取待采集请求列表"
 | |
| 
 | |
| 	var req dto.ListPendingCollectionRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PendingCollectionListOptions{
 | |
| 		DeviceID:  req.DeviceID,
 | |
| 		OrderBy:   req.OrderBy,
 | |
| 		StartTime: req.StartTime,
 | |
| 		EndTime:   req.EndTime,
 | |
| 	}
 | |
| 	if req.Status != nil {
 | |
| 		status := models.PendingCollectionStatus(*req.Status)
 | |
| 		opts.Status = &status
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListPendingCollections(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取待采集请求失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPendingCollectionResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取待采集请求成功", resp, actionType, "获取待采集请求成功", req)
 | |
| }
 | |
| 
 | |
| // ListUserActionLogs godoc
 | |
| // @Summary      获取用户操作日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取用户操作日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListUserActionLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListUserActionLogResponse}
 | |
| // @Router       /api/v1/monitor/user-action-logs [get]
 | |
| func (c *Controller) ListUserActionLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取用户操作日志列表"
 | |
| 
 | |
| 	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)
 | |
| 	}
 | |
| 
 | |
| 	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
 | |
| 	}
 | |
| 
 | |
| 	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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取用户操作日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListUserActionLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取用户操作日志成功", resp, actionType, "获取用户操作日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListRawMaterialPurchases godoc
 | |
| // @Summary      获取原料采购记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取原料采购记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListRawMaterialPurchaseRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListRawMaterialPurchaseResponse}
 | |
| // @Router       /api/v1/monitor/raw-material-purchases [get]
 | |
| func (c *Controller) ListRawMaterialPurchases(ctx echo.Context) error {
 | |
| 	const actionType = "获取原料采购记录列表"
 | |
| 
 | |
| 	var req dto.ListRawMaterialPurchaseRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.RawMaterialPurchaseListOptions{
 | |
| 		RawMaterialID: req.RawMaterialID,
 | |
| 		Supplier:      req.Supplier,
 | |
| 		OrderBy:       req.OrderBy,
 | |
| 		StartTime:     req.StartTime,
 | |
| 		EndTime:       req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListRawMaterialPurchases(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取原料采购记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListRawMaterialPurchaseResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取原料采购记录成功", resp, actionType, "获取原料采购记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListRawMaterialStockLogs godoc
 | |
| // @Summary      获取原料库存日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取原料库存日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListRawMaterialStockLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListRawMaterialStockLogResponse}
 | |
| // @Router       /api/v1/monitor/raw-material-stock-logs [get]
 | |
| func (c *Controller) ListRawMaterialStockLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取原料库存日志列表"
 | |
| 
 | |
| 	var req dto.ListRawMaterialStockLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.RawMaterialStockLogListOptions{
 | |
| 		RawMaterialID: req.RawMaterialID,
 | |
| 		SourceID:      req.SourceID,
 | |
| 		OrderBy:       req.OrderBy,
 | |
| 		StartTime:     req.StartTime,
 | |
| 		EndTime:       req.EndTime,
 | |
| 	}
 | |
| 	if req.SourceType != nil {
 | |
| 		sourceType := models.StockLogSourceType(*req.SourceType)
 | |
| 		opts.SourceType = &sourceType
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListRawMaterialStockLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取原料库存日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListRawMaterialStockLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取原料库存日志成功", resp, actionType, "获取原料库存日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListFeedUsageRecords godoc
 | |
| // @Summary      获取饲料使用记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取饲料使用记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListFeedUsageRecordRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListFeedUsageRecordResponse}
 | |
| // @Router       /api/v1/monitor/feed-usage-records [get]
 | |
| func (c *Controller) ListFeedUsageRecords(ctx echo.Context) error {
 | |
| 	const actionType = "获取饲料使用记录列表"
 | |
| 
 | |
| 	var req dto.ListFeedUsageRecordRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.FeedUsageRecordListOptions{
 | |
| 		PenID:         req.PenID,
 | |
| 		FeedFormulaID: req.FeedFormulaID,
 | |
| 		OperatorID:    req.OperatorID,
 | |
| 		OrderBy:       req.OrderBy,
 | |
| 		StartTime:     req.StartTime,
 | |
| 		EndTime:       req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListFeedUsageRecords(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取饲料使用记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListFeedUsageRecordResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取饲料使用记录成功", resp, actionType, "获取饲料使用记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListMedicationLogs godoc
 | |
| // @Summary      获取用药记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取用药记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListMedicationLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListMedicationLogResponse}
 | |
| // @Router       /api/v1/monitor/medication-logs [get]
 | |
| func (c *Controller) ListMedicationLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取用药记录列表"
 | |
| 
 | |
| 	var req dto.ListMedicationLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.MedicationLogListOptions{
 | |
| 		PigBatchID:   req.PigBatchID,
 | |
| 		MedicationID: req.MedicationID,
 | |
| 		OperatorID:   req.OperatorID,
 | |
| 		OrderBy:      req.OrderBy,
 | |
| 		StartTime:    req.StartTime,
 | |
| 		EndTime:      req.EndTime,
 | |
| 	}
 | |
| 	if req.Reason != nil {
 | |
| 		reason := models.MedicationReasonType(*req.Reason)
 | |
| 		opts.Reason = &reason
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListMedicationLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取用药记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListMedicationLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取用药记录成功", resp, actionType, "获取用药记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListPigBatchLogs godoc
 | |
| // @Summary      获取猪批次日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取猪批次日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPigBatchLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPigBatchLogResponse}
 | |
| // @Router       /api/v1/monitor/pig-batch-logs [get]
 | |
| func (c *Controller) ListPigBatchLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取猪批次日志列表"
 | |
| 
 | |
| 	var req dto.ListPigBatchLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PigBatchLogListOptions{
 | |
| 		PigBatchID: req.PigBatchID,
 | |
| 		OperatorID: req.OperatorID,
 | |
| 		OrderBy:    req.OrderBy,
 | |
| 		StartTime:  req.StartTime,
 | |
| 		EndTime:    req.EndTime,
 | |
| 	}
 | |
| 	if req.ChangeType != nil {
 | |
| 		changeType := models.LogChangeType(*req.ChangeType)
 | |
| 		opts.ChangeType = &changeType
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListPigBatchLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取猪批次日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPigBatchLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取猪批次日志成功", resp, actionType, "获取猪批次日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListWeighingBatches godoc
 | |
| // @Summary      获取批次称重记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取批次称重记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListWeighingBatchRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListWeighingBatchResponse}
 | |
| // @Router       /api/v1/monitor/weighing-batches [get]
 | |
| func (c *Controller) ListWeighingBatches(ctx echo.Context) error {
 | |
| 	const actionType = "获取批次称重记录列表"
 | |
| 
 | |
| 	var req dto.ListWeighingBatchRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.WeighingBatchListOptions{
 | |
| 		PigBatchID: req.PigBatchID,
 | |
| 		OrderBy:    req.OrderBy,
 | |
| 		StartTime:  req.StartTime,
 | |
| 		EndTime:    req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListWeighingBatches(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取批次称重记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListWeighingBatchResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取批次称重记录成功", resp, actionType, "获取批次称重记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListWeighingRecords godoc
 | |
| // @Summary      获取单次称重记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取单次称重记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListWeighingRecordRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListWeighingRecordResponse}
 | |
| // @Router       /api/v1/monitor/weighing-records [get]
 | |
| func (c *Controller) ListWeighingRecords(ctx echo.Context) error {
 | |
| 	const actionType = "获取单次称重记录列表"
 | |
| 
 | |
| 	var req dto.ListWeighingRecordRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.WeighingRecordListOptions{
 | |
| 		WeighingBatchID: req.WeighingBatchID,
 | |
| 		PenID:           req.PenID,
 | |
| 		OperatorID:      req.OperatorID,
 | |
| 		OrderBy:         req.OrderBy,
 | |
| 		StartTime:       req.StartTime,
 | |
| 		EndTime:         req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListWeighingRecords(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取单次称重记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListWeighingRecordResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取单次称重记录成功", resp, actionType, "获取单次称重记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListPigTransferLogs godoc
 | |
| // @Summary      获取猪只迁移日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取猪只迁移日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPigTransferLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPigTransferLogResponse}
 | |
| // @Router       /api/v1/monitor/pig-transfer-logs [get]
 | |
| func (c *Controller) ListPigTransferLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取猪只迁移日志列表"
 | |
| 
 | |
| 	var req dto.ListPigTransferLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PigTransferLogListOptions{
 | |
| 		PigBatchID:    req.PigBatchID,
 | |
| 		PenID:         req.PenID,
 | |
| 		OperatorID:    req.OperatorID,
 | |
| 		CorrelationID: req.CorrelationID,
 | |
| 		OrderBy:       req.OrderBy,
 | |
| 		StartTime:     req.StartTime,
 | |
| 		EndTime:       req.EndTime,
 | |
| 	}
 | |
| 	if req.TransferType != nil {
 | |
| 		transferType := models.PigTransferType(*req.TransferType)
 | |
| 		opts.TransferType = &transferType
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListPigTransferLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取猪只迁移日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPigTransferLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取猪只迁移日志成功", resp, actionType, "获取猪只迁移日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListPigSickLogs godoc
 | |
| // @Summary      获取病猪日志列表
 | |
| // @Description  根据提供的过滤条件,分页获取病猪日志
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPigSickLogRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPigSickLogResponse}
 | |
| // @Router       /api/v1/monitor/pig-sick-logs [get]
 | |
| func (c *Controller) ListPigSickLogs(ctx echo.Context) error {
 | |
| 	const actionType = "获取病猪日志列表"
 | |
| 
 | |
| 	var req dto.ListPigSickLogRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PigSickLogListOptions{
 | |
| 		PigBatchID: req.PigBatchID,
 | |
| 		PenID:      req.PenID,
 | |
| 		OperatorID: req.OperatorID,
 | |
| 		OrderBy:    req.OrderBy,
 | |
| 		StartTime:  req.StartTime,
 | |
| 		EndTime:    req.EndTime,
 | |
| 	}
 | |
| 	if req.Reason != nil {
 | |
| 		reason := models.PigBatchSickPigReasonType(*req.Reason)
 | |
| 		opts.Reason = &reason
 | |
| 	}
 | |
| 	if req.TreatmentLocation != nil {
 | |
| 		treatmentLocation := models.PigBatchSickPigTreatmentLocation(*req.TreatmentLocation)
 | |
| 		opts.TreatmentLocation = &treatmentLocation
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListPigSickLogs(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取病猪日志失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPigSickLogResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取病猪日志成功", resp, actionType, "获取病猪日志成功", req)
 | |
| }
 | |
| 
 | |
| // ListPigPurchases godoc
 | |
| // @Summary      获取猪只采购记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取猪只采购记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPigPurchaseRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPigPurchaseResponse}
 | |
| // @Router       /api/v1/monitor/pig-purchases [get]
 | |
| func (c *Controller) ListPigPurchases(ctx echo.Context) error {
 | |
| 	const actionType = "获取猪只采购记录列表"
 | |
| 
 | |
| 	var req dto.ListPigPurchaseRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PigPurchaseListOptions{
 | |
| 		PigBatchID: req.PigBatchID,
 | |
| 		Supplier:   req.Supplier,
 | |
| 		OperatorID: req.OperatorID,
 | |
| 		OrderBy:    req.OrderBy,
 | |
| 		StartTime:  req.StartTime,
 | |
| 		EndTime:    req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListPigPurchases(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取猪只采购记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPigPurchaseResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取猪只采购记录成功", resp, actionType, "获取猪只采购记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListPigSales godoc
 | |
| // @Summary      获取猪只售卖记录列表
 | |
| // @Description  根据提供的过滤条件,分页获取猪只售卖记录
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListPigSaleRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListPigSaleResponse}
 | |
| // @Router       /api/v1/monitor/pig-sales [get]
 | |
| func (c *Controller) ListPigSales(ctx echo.Context) error {
 | |
| 	const actionType = "获取猪只售卖记录列表"
 | |
| 
 | |
| 	var req dto.ListPigSaleRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.PigSaleListOptions{
 | |
| 		PigBatchID: req.PigBatchID,
 | |
| 		Buyer:      req.Buyer,
 | |
| 		OperatorID: req.OperatorID,
 | |
| 		OrderBy:    req.OrderBy,
 | |
| 		StartTime:  req.StartTime,
 | |
| 		EndTime:    req.EndTime,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListPigSales(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取猪只售卖记录失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListPigSaleResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取猪只售卖记录成功", resp, actionType, "获取猪只售卖记录成功", req)
 | |
| }
 | |
| 
 | |
| // ListNotifications godoc
 | |
| // @Summary      批量查询通知
 | |
| // @Description  根据提供的过滤条件,分页获取通知列表
 | |
| // @Tags         数据监控
 | |
| // @Security     BearerAuth
 | |
| // @Produce      json
 | |
| // @Param        query query dto.ListNotificationRequest true "查询参数"
 | |
| // @Success      200 {object} controller.Response{data=dto.ListNotificationResponse}
 | |
| // @Router       /api/v1/monitor/notifications [get]
 | |
| func (c *Controller) ListNotifications(ctx echo.Context) error {
 | |
| 	const actionType = "批量查询通知"
 | |
| 
 | |
| 	var req dto.ListNotificationRequest
 | |
| 	if err := ctx.Bind(&req); err != nil {
 | |
| 		c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
 | |
| 	}
 | |
| 
 | |
| 	opts := repository.NotificationListOptions{
 | |
| 		UserID:       req.UserID,
 | |
| 		NotifierType: req.NotifierType,
 | |
| 		Level:        req.Level,
 | |
| 		StartTime:    req.StartTime,
 | |
| 		EndTime:      req.EndTime,
 | |
| 		OrderBy:      req.OrderBy,
 | |
| 		Status:       req.Status,
 | |
| 	}
 | |
| 
 | |
| 	data, total, err := c.monitorService.ListNotifications(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, "无效分页参数", req)
 | |
| 		}
 | |
| 
 | |
| 		c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
 | |
| 		return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "批量查询通知失败: "+err.Error(), actionType, "服务层查询失败", req)
 | |
| 	}
 | |
| 
 | |
| 	resp := dto.NewListNotificationResponse(data, total, req.Page, req.PageSize)
 | |
| 	c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
 | |
| 	return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "批量查询通知成功", resp, actionType, "批量查询通知成功", req)
 | |
| }
 |