Files
pig-farm-controller/internal/app/controller/management/pig_batch_health_controller.go

171 lines
6.8 KiB
Go
Raw Normal View History

2025-10-06 23:22:47 +08:00
package management
import (
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
2025-11-05 17:24:19 +08:00
"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
2025-11-05 19:57:30 +08:00
2025-10-30 17:15:14 +08:00
"github.com/labstack/echo/v4"
2025-10-06 23:22:47 +08:00
)
// RecordSickPigs godoc
// @Summary 记录新增病猪事件
// @Description 记录猪批次中新增病猪的数量、治疗地点和发生时间
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
2025-10-13 14:15:38 +08:00
// @Security BearerAuth
2025-10-06 23:22:47 +08:00
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.RecordSickPigsRequest true "记录病猪请求信息"
// @Success 200 {object} controller.Response "记录成功"
2025-10-10 18:23:06 +08:00
// @Router /api/v1/pig-batches/record-sick-pigs/{id} [post]
2025-10-30 17:15:14 +08:00
func (c *PigBatchController) RecordSickPigs(ctx echo.Context) error {
2025-11-05 17:24:19 +08:00
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "RecordSickPigs")
2025-10-06 23:22:47 +08:00
const action = "记录新增病猪事件"
var req dto.RecordSickPigsRequest
2025-10-30 17:15:14 +08:00
return handleAPIRequest(
2025-10-06 23:48:31 +08:00
c, ctx, action, &req,
2025-10-30 17:15:14 +08:00
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigsRequest) error {
2025-11-05 17:24:19 +08:00
return c.service.RecordSickPigs(reqCtx, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
2025-10-06 23:48:31 +08:00
},
"记录成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}
// RecordSickPigRecovery godoc
// @Summary 记录病猪康复事件
// @Description 记录猪批次中病猪康复的数量、治疗地点和发生时间
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
2025-10-13 14:15:38 +08:00
// @Security BearerAuth
2025-10-06 23:22:47 +08:00
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.RecordSickPigRecoveryRequest true "记录病猪康复请求信息"
// @Success 200 {object} controller.Response "记录成功"
2025-10-10 18:23:06 +08:00
// @Router /api/v1/pig-batches/record-sick-pig-recovery/{id} [post]
2025-10-30 17:15:14 +08:00
func (c *PigBatchController) RecordSickPigRecovery(ctx echo.Context) error {
2025-11-05 17:24:19 +08:00
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "RecordSickPigRecovery")
2025-10-06 23:22:47 +08:00
const action = "记录病猪康复事件"
var req dto.RecordSickPigRecoveryRequest
2025-10-30 17:15:14 +08:00
return handleAPIRequest(
2025-10-06 23:48:31 +08:00
c, ctx, action, &req,
2025-10-30 17:15:14 +08:00
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigRecoveryRequest) error {
2025-11-05 17:24:19 +08:00
return c.service.RecordSickPigRecovery(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
2025-10-06 23:48:31 +08:00
},
"记录成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}
// RecordSickPigDeath godoc
// @Summary 记录病猪死亡事件
// @Description 记录猪批次中病猪死亡的数量、治疗地点和发生时间
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
2025-10-13 14:15:38 +08:00
// @Security BearerAuth
2025-10-06 23:22:47 +08:00
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.RecordSickPigDeathRequest true "记录病猪死亡请求信息"
// @Success 200 {object} controller.Response "记录成功"
2025-10-10 18:23:06 +08:00
// @Router /api/v1/pig-batches/record-sick-pig-death/{id} [post]
2025-10-30 17:15:14 +08:00
func (c *PigBatchController) RecordSickPigDeath(ctx echo.Context) error {
2025-11-05 17:24:19 +08:00
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "RecordSickPigDeath")
2025-10-06 23:22:47 +08:00
const action = "记录病猪死亡事件"
var req dto.RecordSickPigDeathRequest
2025-10-30 17:15:14 +08:00
return handleAPIRequest(
2025-10-06 23:48:31 +08:00
c, ctx, action, &req,
2025-10-30 17:15:14 +08:00
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigDeathRequest) error {
2025-11-05 17:24:19 +08:00
return c.service.RecordSickPigDeath(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
2025-10-06 23:48:31 +08:00
},
"记录成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}
// RecordSickPigCull godoc
// @Summary 记录病猪淘汰事件
// @Description 记录猪批次中病猪淘汰的数量、治疗地点和发生时间
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
2025-10-13 14:15:38 +08:00
// @Security BearerAuth
2025-10-06 23:22:47 +08:00
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.RecordSickPigCullRequest true "记录病猪淘汰请求信息"
// @Success 200 {object} controller.Response "记录成功"
2025-10-10 18:23:06 +08:00
// @Router /api/v1/pig-batches/record-sick-pig-cull/{id} [post]
2025-10-30 17:15:14 +08:00
func (c *PigBatchController) RecordSickPigCull(ctx echo.Context) error {
2025-11-05 17:24:19 +08:00
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "RecordSickPigCull")
2025-10-06 23:22:47 +08:00
const action = "记录病猪淘汰事件"
var req dto.RecordSickPigCullRequest
2025-10-30 17:15:14 +08:00
return handleAPIRequest(
2025-10-06 23:48:31 +08:00
c, ctx, action, &req,
2025-10-30 17:15:14 +08:00
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigCullRequest) error {
2025-11-05 17:24:19 +08:00
return c.service.RecordSickPigCull(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
2025-10-06 23:48:31 +08:00
},
"记录成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}
// RecordDeath godoc
// @Summary 记录正常猪只死亡事件
// @Description 记录猪批次中正常猪只死亡的数量和发生时间
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
2025-10-13 14:15:38 +08:00
// @Security BearerAuth
2025-10-06 23:22:47 +08:00
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.RecordDeathRequest true "记录正常猪只死亡请求信息"
// @Success 200 {object} controller.Response "记录成功"
2025-10-10 18:23:06 +08:00
// @Router /api/v1/pig-batches/record-death/{id} [post]
2025-10-30 17:15:14 +08:00
func (c *PigBatchController) RecordDeath(ctx echo.Context) error {
2025-11-05 17:24:19 +08:00
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "RecordDeath")
2025-10-06 23:22:47 +08:00
const action = "记录正常猪只死亡事件"
var req dto.RecordDeathRequest
2025-10-30 17:15:14 +08:00
return handleAPIRequest(
2025-10-06 23:48:31 +08:00
c, ctx, action, &req,
2025-10-30 17:15:14 +08:00
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordDeathRequest) error {
2025-11-05 17:24:19 +08:00
return c.service.RecordDeath(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.HappenedAt, req.Remarks)
2025-10-06 23:48:31 +08:00
},
"记录成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}
// RecordCull godoc
// @Summary 记录正常猪只淘汰事件
// @Description 记录猪批次中正常猪只淘汰的数量和发生时间
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
2025-10-13 14:15:38 +08:00
// @Security BearerAuth
2025-10-06 23:22:47 +08:00
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.RecordCullRequest true "记录正常猪只淘汰请求信息"
// @Success 200 {object} controller.Response "记录成功"
2025-10-10 18:23:06 +08:00
// @Router /api/v1/pig-batches/record-cull/{id} [post]
2025-10-30 17:15:14 +08:00
func (c *PigBatchController) RecordCull(ctx echo.Context) error {
2025-11-05 17:24:19 +08:00
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "RecordCull")
2025-10-06 23:22:47 +08:00
const action = "记录正常猪只淘汰事件"
var req dto.RecordCullRequest
2025-10-30 17:15:14 +08:00
return handleAPIRequest(
2025-10-06 23:48:31 +08:00
c, ctx, action, &req,
2025-10-30 17:15:14 +08:00
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordCullRequest) error {
2025-11-05 17:24:19 +08:00
return c.service.RecordCull(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.HappenedAt, req.Remarks)
2025-10-06 23:48:31 +08:00
},
"记录成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}