修改controller包

This commit is contained in:
2025-11-05 17:24:19 +08:00
parent 4cae93ef34
commit ef4ca397ce
11 changed files with 449 additions and 354 deletions

View File

@@ -4,6 +4,7 @@ import (
"strconv"
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
"github.com/labstack/echo/v4"
)
@@ -19,6 +20,8 @@ import (
// @Success 200 {object} controller.Response "调栏成功"
// @Router /api/v1/pig-batches/transfer-across-batches/{sourceBatchID} [post]
func (c *PigBatchController) TransferPigsAcrossBatches(ctx echo.Context) error {
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "TransferPigsAcrossBatches")
const action = "跨猪群调栏"
var req dto.TransferPigsAcrossBatchesRequest
@@ -26,7 +29,7 @@ func (c *PigBatchController) TransferPigsAcrossBatches(ctx echo.Context) error {
c, ctx, action, &req,
func(ctx echo.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)
return c.service.TransferPigsAcrossBatches(reqCtx, primaryID, req.DestBatchID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
},
"调栏成功",
func(ctx echo.Context) (uint, error) { // 自定义ID提取器从 ":sourceBatchID" 路径参数提取
@@ -52,6 +55,8 @@ func (c *PigBatchController) TransferPigsAcrossBatches(ctx echo.Context) error {
// @Success 200 {object} controller.Response "调栏成功"
// @Router /api/v1/pig-batches/transfer-within-batch/{id} [post]
func (c *PigBatchController) TransferPigsWithinBatch(ctx echo.Context) error {
reqCtx := logs.AddFuncName(ctx.Request().Context(), c.ctx, "TransferPigsWithinBatch")
const action = "群内调栏"
var req dto.TransferPigsWithinBatchRequest
@@ -59,7 +64,7 @@ func (c *PigBatchController) TransferPigsWithinBatch(ctx echo.Context) error {
c, ctx, action, &req,
func(ctx echo.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)
return c.service.TransferPigsWithinBatch(reqCtx, primaryID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
},
"调栏成功",
nil, // 默认从 ":id" 路径参数提取ID