57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package management
 | 
						|
 | 
						|
import (
 | 
						|
	"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
 | 
						|
	"github.com/labstack/echo/v4"
 | 
						|
)
 | 
						|
 | 
						|
// SellPigs godoc
 | 
						|
// @Summary      处理卖猪的业务逻辑
 | 
						|
// @Description  记录猪批次中的猪只出售事件
 | 
						|
// @Tags         猪群管理
 | 
						|
// @Security     BearerAuth
 | 
						|
// @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/sell-pigs/{id} [post]
 | 
						|
func (c *PigBatchController) SellPigs(ctx echo.Context) error {
 | 
						|
	const action = "卖猪"
 | 
						|
	var req dto.SellPigsRequest
 | 
						|
 | 
						|
	return handleAPIRequest(
 | 
						|
		c, ctx, action, &req,
 | 
						|
		func(ctx echo.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         猪群管理
 | 
						|
// @Security     BearerAuth
 | 
						|
// @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/buy-pigs/{id} [post]
 | 
						|
func (c *PigBatchController) BuyPigs(ctx echo.Context) error {
 | 
						|
	const action = "买猪"
 | 
						|
	var req dto.BuyPigsRequest
 | 
						|
 | 
						|
	return handleAPIRequest(
 | 
						|
		c, ctx, action, &req,
 | 
						|
		func(ctx echo.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
 | 
						|
	)
 | 
						|
}
 |