ListPigSickLogs
This commit is contained in:
@@ -693,3 +693,57 @@ func (c *Controller) ListPigTransferLogs(ctx *gin.Context) {
|
||||
c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
|
||||
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 *gin.Context) {
|
||||
const actionType = "获取病猪日志列表"
|
||||
|
||||
var req dto.ListPigSickLogRequest
|
||||
if err := ctx.ShouldBindQuery(&req); err != nil {
|
||||
c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的分页参数: "+err.Error(), actionType, "无效分页参数", req)
|
||||
return
|
||||
}
|
||||
|
||||
c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "获取病猪日志失败: "+err.Error(), actionType, "服务层查询失败", req)
|
||||
return
|
||||
}
|
||||
|
||||
resp := dto.NewListPigSickLogResponse(data, total, req.Page, req.PageSize)
|
||||
c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
|
||||
controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取病猪日志成功", resp, actionType, "获取病猪日志成功", req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user