Files
pig-farm-controller/internal/app/controller/management/pig_batch_trade_controller.go
2025-10-07 00:18:17 +08:00

55 lines
1.9 KiB
Go

package management
import (
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
"github.com/gin-gonic/gin"
)
// SellPigs godoc
// @Summary 处理卖猪的业务逻辑
// @Description 记录猪批次中的猪只出售事件
// @Tags 猪群管理
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.SellPigsRequest true "卖猪请求信息"
// @Success 200 {object} controller.Response "卖猪成功"
// @Router /api/v1/pig-batches/{id}/sell-pigs [post]
func (c *PigBatchController) SellPigs(ctx *gin.Context) {
const action = "卖猪"
var req dto.SellPigsRequest
handleAPIRequest(
c, ctx, action, &req,
func(ctx *gin.Context, operatorID uint, primaryID uint, req *dto.SellPigsRequest) error {
return c.service.SellPigs(primaryID, req.PenID, req.Quantity, req.UnitPrice, req.TotalPrice, req.TraderName, req.TradeDate, req.Remarks, operatorID)
},
"卖猪成功",
nil, // 默认从 ":id" 路径参数提取ID
)
}
// BuyPigs godoc
// @Summary 处理买猪的业务逻辑
// @Description 记录猪批次中的猪只购买事件
// @Tags 猪群管理
// @Accept json
// @Produce json
// @Param id path int true "猪批次ID"
// @Param body body dto.BuyPigsRequest true "买猪请求信息"
// @Success 200 {object} controller.Response "买猪成功"
// @Router /api/v1/pig-batches/{id}/buy-pigs [post]
func (c *PigBatchController) BuyPigs(ctx *gin.Context) {
const action = "买猪"
var req dto.BuyPigsRequest
handleAPIRequest(
c, ctx, action, &req,
func(ctx *gin.Context, operatorID uint, primaryID uint, req *dto.BuyPigsRequest) error {
return c.service.BuyPigs(primaryID, req.PenID, req.Quantity, req.UnitPrice, req.TotalPrice, req.TraderName, req.TradeDate, req.Remarks, operatorID)
},
"买猪成功",
nil, // 默认从 ":id" 路径参数提取ID
)
}