2025-10-06 23:22:47 +08:00
|
|
|
|
package management
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
|
|
"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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// TransferPigsAcrossBatches 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 sourceBatchID path int true "源猪批次ID"
|
|
|
|
|
|
// @Param body body dto.TransferPigsAcrossBatchesRequest true "跨群调栏请求信息"
|
|
|
|
|
|
// @Success 200 {object} controller.Response "调栏成功"
|
2025-10-10 18:23:06 +08:00
|
|
|
|
// @Router /api/v1/pig-batches/transfer-across-batches/{sourceBatchID} [post]
|
2025-10-30 17:15:14 +08:00
|
|
|
|
func (c *PigBatchController) TransferPigsAcrossBatches(ctx echo.Context) error {
|
2025-11-05 17:24:19 +08:00
|
|
|
|
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "TransferPigsAcrossBatches")
|
|
|
|
|
|
|
2025-10-06 23:22:47 +08:00
|
|
|
|
const action = "跨猪群调栏"
|
|
|
|
|
|
var req dto.TransferPigsAcrossBatchesRequest
|
|
|
|
|
|
|
2025-10-30 17:15:14 +08:00
|
|
|
|
return handleAPIRequest(
|
2025-11-05 23:10:51 +08:00
|
|
|
|
reqCtx, c, ctx, action, &req,
|
2025-11-10 22:23:31 +08:00
|
|
|
|
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.TransferPigsAcrossBatchesRequest) error {
|
2025-10-06 23:48:31 +08:00
|
|
|
|
// primaryID 在这里是 sourceBatchID
|
2025-11-05 17:24:19 +08:00
|
|
|
|
return c.service.TransferPigsAcrossBatches(reqCtx, primaryID, req.DestBatchID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
|
2025-10-06 23:48:31 +08:00
|
|
|
|
},
|
|
|
|
|
|
"调栏成功",
|
2025-11-10 22:23:31 +08:00
|
|
|
|
func(ctx echo.Context) (uint32, error) { // 自定义ID提取器,从 ":sourceBatchID" 路径参数提取
|
2025-10-06 23:48:31 +08:00
|
|
|
|
idParam := ctx.Param("sourceBatchID")
|
|
|
|
|
|
parsedID, err := strconv.ParseUint(idParam, 10, 32)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
}
|
2025-11-10 22:23:31 +08:00
|
|
|
|
return uint32(parsedID), nil
|
2025-10-06 23:48:31 +08:00
|
|
|
|
},
|
|
|
|
|
|
)
|
2025-10-06 23:22:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TransferPigsWithinBatch 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.TransferPigsWithinBatchRequest true "群内调栏请求信息"
|
|
|
|
|
|
// @Success 200 {object} controller.Response "调栏成功"
|
2025-10-10 18:23:06 +08:00
|
|
|
|
// @Router /api/v1/pig-batches/transfer-within-batch/{id} [post]
|
2025-10-30 17:15:14 +08:00
|
|
|
|
func (c *PigBatchController) TransferPigsWithinBatch(ctx echo.Context) error {
|
2025-11-05 17:24:19 +08:00
|
|
|
|
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "TransferPigsWithinBatch")
|
|
|
|
|
|
|
2025-10-06 23:22:47 +08:00
|
|
|
|
const action = "群内调栏"
|
|
|
|
|
|
var req dto.TransferPigsWithinBatchRequest
|
|
|
|
|
|
|
2025-10-30 17:15:14 +08:00
|
|
|
|
return handleAPIRequest(
|
2025-11-05 23:10:51 +08:00
|
|
|
|
reqCtx, c, ctx, action, &req,
|
2025-11-10 22:23:31 +08:00
|
|
|
|
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.TransferPigsWithinBatchRequest) error {
|
2025-10-06 23:48:31 +08:00
|
|
|
|
// primaryID 在这里是 batchID
|
2025-11-05 17:24:19 +08:00
|
|
|
|
return c.service.TransferPigsWithinBatch(reqCtx, primaryID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
|
2025-10-06 23:48:31 +08:00
|
|
|
|
},
|
|
|
|
|
|
"调栏成功",
|
|
|
|
|
|
nil, // 默认从 ":id" 路径参数提取ID
|
|
|
|
|
|
)
|
2025-10-06 23:22:47 +08:00
|
|
|
|
}
|