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

66 lines
2.5 KiB
Go
Raw Normal View History

2025-10-06 23:22:47 +08:00
package management
import (
"strconv"
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
"github.com/gin-gonic/gin"
)
// TransferPigsAcrossBatches godoc
// @Summary 跨猪群调栏
// @Description 将指定数量的猪只从一个猪群的猪栏调动到另一个猪群的猪栏
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
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 "调栏成功"
// @Router /api/v1/pig-batches/{sourceBatchID}/transfer-across-batches [post]
func (c *PigBatchController) TransferPigsAcrossBatches(ctx *gin.Context) {
const action = "跨猪群调栏"
var req dto.TransferPigsAcrossBatchesRequest
2025-10-06 23:48:31 +08:00
handleAPIRequest(
c, ctx, action, &req,
func(ctx *gin.Context, operatorID uint, primaryID uint, req *dto.TransferPigsAcrossBatchesRequest) error {
// primaryID 在这里是 sourceBatchID
return c.service.TransferPigsAcrossBatches(primaryID, req.DestBatchID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
},
"调栏成功",
func(ctx *gin.Context) (uint, error) { // 自定义ID提取器从 ":sourceBatchID" 路径参数提取
idParam := ctx.Param("sourceBatchID")
parsedID, err := strconv.ParseUint(idParam, 10, 32)
if err != nil {
return 0, err
}
return uint(parsedID), nil
},
)
2025-10-06 23:22:47 +08:00
}
// TransferPigsWithinBatch godoc
// @Summary 群内调栏
// @Description 将指定数量的猪只在同一个猪群的不同猪栏间调动
2025-10-07 00:18:17 +08:00
// @Tags 猪群管理
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 "调栏成功"
// @Router /api/v1/pig-batches/{id}/transfer-within-batch [post]
func (c *PigBatchController) TransferPigsWithinBatch(ctx *gin.Context) {
const action = "群内调栏"
var req dto.TransferPigsWithinBatchRequest
2025-10-06 23:48:31 +08:00
handleAPIRequest(
c, ctx, action, &req,
func(ctx *gin.Context, operatorID uint, primaryID uint, req *dto.TransferPigsWithinBatchRequest) error {
// primaryID 在这里是 batchID
return c.service.TransferPigsWithinBatch(primaryID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
},
"调栏成功",
nil, // 默认从 ":id" 路径参数提取ID
)
2025-10-06 23:22:47 +08:00
}