完成任务4

This commit is contained in:
2025-10-30 17:15:14 +08:00
parent f0982839e0
commit d235130d11
11 changed files with 531 additions and 765 deletions

View File

@@ -4,7 +4,7 @@ import (
"strconv"
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
)
// TransferPigsAcrossBatches godoc
@@ -18,18 +18,18 @@ import (
// @Param body body dto.TransferPigsAcrossBatchesRequest true "跨群调栏请求信息"
// @Success 200 {object} controller.Response "调栏成功"
// @Router /api/v1/pig-batches/transfer-across-batches/{sourceBatchID} [post]
func (c *PigBatchController) TransferPigsAcrossBatches(ctx *gin.Context) {
func (c *PigBatchController) TransferPigsAcrossBatches(ctx echo.Context) error {
const action = "跨猪群调栏"
var req dto.TransferPigsAcrossBatchesRequest
handleAPIRequest(
return handleAPIRequest(
c, ctx, action, &req,
func(ctx *gin.Context, operatorID uint, primaryID uint, req *dto.TransferPigsAcrossBatchesRequest) error {
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)
},
"调栏成功",
func(ctx *gin.Context) (uint, error) { // 自定义ID提取器从 ":sourceBatchID" 路径参数提取
func(ctx echo.Context) (uint, error) { // 自定义ID提取器从 ":sourceBatchID" 路径参数提取
idParam := ctx.Param("sourceBatchID")
parsedID, err := strconv.ParseUint(idParam, 10, 32)
if err != nil {
@@ -51,13 +51,13 @@ func (c *PigBatchController) TransferPigsAcrossBatches(ctx *gin.Context) {
// @Param body body dto.TransferPigsWithinBatchRequest true "群内调栏请求信息"
// @Success 200 {object} controller.Response "调栏成功"
// @Router /api/v1/pig-batches/transfer-within-batch/{id} [post]
func (c *PigBatchController) TransferPigsWithinBatch(ctx *gin.Context) {
func (c *PigBatchController) TransferPigsWithinBatch(ctx echo.Context) error {
const action = "群内调栏"
var req dto.TransferPigsWithinBatchRequest
handleAPIRequest(
return handleAPIRequest(
c, ctx, action, &req,
func(ctx *gin.Context, operatorID uint, primaryID uint, req *dto.TransferPigsWithinBatchRequest) error {
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)
},