原料模型增加参考价
This commit is contained in:
@@ -34,7 +34,7 @@ func NewRawMaterialController(ctx context.Context, feedManagementService service
|
||||
// @Security BearerAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param rawMaterial body dto.CreateRawMaterialRequest true "原料信息"
|
||||
// @Param rawMaterial body dto.CreateRawMaterialRequest true "原料信息,包含名称、描述和参考价格"
|
||||
// @Success 200 {object} controller.Response{data=dto.RawMaterialResponse} "业务码为201代表创建成功"
|
||||
// @Router /api/v1/feed/raw-materials [post]
|
||||
func (c *RawMaterialController) CreateRawMaterial(ctx echo.Context) error {
|
||||
@@ -67,7 +67,7 @@ func (c *RawMaterialController) CreateRawMaterial(ctx echo.Context) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "原料ID"
|
||||
// @Param rawMaterial body dto.UpdateRawMaterialRequest true "更新后的原料信息"
|
||||
// @Param rawMaterial body dto.UpdateRawMaterialRequest true "更新后的原料信息,包含名称、描述和参考价格"
|
||||
// @Success 200 {object} controller.Response{data=dto.RawMaterialResponse} "业务码为200代表更新成功"
|
||||
// @Router /api/v1/feed/raw-materials/{id} [put]
|
||||
func (c *RawMaterialController) UpdateRawMaterial(ctx echo.Context) error {
|
||||
@@ -172,7 +172,7 @@ func (c *RawMaterialController) GetRawMaterial(ctx echo.Context) error {
|
||||
// @Tags 饲料管理-原料
|
||||
// @Security BearerAuth
|
||||
// @Produce json
|
||||
// @Param query query dto.ListRawMaterialRequest false "查询参数"
|
||||
// @Param query query dto.ListRawMaterialRequest false "查询参数,支持按名称、营养名称、参考价格范围过滤"
|
||||
// @Success 200 {object} controller.Response{data=dto.ListRawMaterialResponse} "业务码为200代表成功获取列表"
|
||||
// @Router /api/v1/feed/raw-materials [get]
|
||||
func (c *RawMaterialController) ListRawMaterials(ctx echo.Context) error {
|
||||
|
||||
@@ -65,6 +65,7 @@ func ConvertRawMaterialToDTO(rm *models.RawMaterial) *RawMaterialResponse {
|
||||
ID: rm.ID,
|
||||
Name: rm.Name,
|
||||
Description: rm.Description,
|
||||
ReferencePrice: rm.ReferencePrice,
|
||||
RawMaterialNutrients: rawMaterialNutrientDTOs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +52,16 @@ type ListNutrientResponse struct {
|
||||
|
||||
// CreateRawMaterialRequest 创建原料的请求体
|
||||
type CreateRawMaterialRequest struct {
|
||||
Name string `json:"name" validate:"required,max=100"` // 原料名称
|
||||
Description string `json:"description" validate:"max=255"` // 描述
|
||||
Name string `json:"name" validate:"required,max=100"` // 原料名称
|
||||
Description string `json:"description" validate:"max=255"` // 描述
|
||||
ReferencePrice float32 `json:"reference_price"` // 参考价格(kg/元)
|
||||
}
|
||||
|
||||
// UpdateRawMaterialRequest 更新原料的请求体
|
||||
type UpdateRawMaterialRequest struct {
|
||||
Name string `json:"name" validate:"required,max=100"` // 原料名称
|
||||
Description string `json:"description" validate:"max=255"` // 描述
|
||||
Name string `json:"name" validate:"required,max=100"` // 原料名称
|
||||
Description string `json:"description" validate:"max=255"` // 描述
|
||||
ReferencePrice float32 `json:"reference_price"` // 参考价格(kg/元)
|
||||
}
|
||||
|
||||
// RawMaterialNutrientDTO 原料营养素响应体
|
||||
@@ -75,16 +77,19 @@ type RawMaterialResponse struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ReferencePrice float32 `json:"reference_price"` // 参考价格(kg/元)
|
||||
RawMaterialNutrients []RawMaterialNutrientDTO `json:"raw_material_nutrients"` // 关联的营养素信息
|
||||
}
|
||||
|
||||
// ListRawMaterialRequest 定义了获取原料列表的请求参数
|
||||
type ListRawMaterialRequest struct {
|
||||
Page int `json:"page" query:"page"` // 页码
|
||||
PageSize int `json:"page_size" query:"page_size"` // 每页数量
|
||||
Name *string `json:"name" query:"name"` // 按原料名称模糊查询
|
||||
NutrientName *string `json:"nutrient_name" query:"nutrient_name"` // 按营养名称模糊查询
|
||||
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
|
||||
Page int `json:"page" query:"page"` // 页码
|
||||
PageSize int `json:"page_size" query:"page_size"` // 每页数量
|
||||
Name *string `json:"name" query:"name"` // 按原料名称模糊查询
|
||||
NutrientName *string `json:"nutrient_name" query:"nutrient_name"` // 按营养名称模糊查询
|
||||
MinReferencePrice *float32 `json:"min_reference_price" query:"min_reference_price"` // 参考价格最小值
|
||||
MaxReferencePrice *float32 `json:"max_reference_price" query:"max_reference_price"` // 参考价格最大值
|
||||
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "id DESC"
|
||||
}
|
||||
|
||||
// ListRawMaterialResponse 是获取原料列表的响应结构
|
||||
|
||||
@@ -46,7 +46,7 @@ func NewRawMaterialService(ctx context.Context, recipeSvc recipe.Service) RawMat
|
||||
func (s *rawMaterialServiceImpl) CreateRawMaterial(ctx context.Context, req *dto.CreateRawMaterialRequest) (*dto.RawMaterialResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "CreateRawMaterial")
|
||||
|
||||
rawMaterial, err := s.recipeSvc.CreateRawMaterial(serviceCtx, req.Name, req.Description)
|
||||
rawMaterial, err := s.recipeSvc.CreateRawMaterial(serviceCtx, req.Name, req.Description, req.ReferencePrice)
|
||||
if err != nil {
|
||||
if errors.Is(err, recipe.ErrRawMaterialNameConflict) {
|
||||
return nil, ErrRawMaterialNameConflict
|
||||
@@ -61,7 +61,7 @@ func (s *rawMaterialServiceImpl) CreateRawMaterial(ctx context.Context, req *dto
|
||||
func (s *rawMaterialServiceImpl) UpdateRawMaterial(ctx context.Context, id uint32, req *dto.UpdateRawMaterialRequest) (*dto.RawMaterialResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "UpdateRawMaterial")
|
||||
|
||||
rawMaterial, err := s.recipeSvc.UpdateRawMaterial(serviceCtx, id, req.Name, req.Description)
|
||||
rawMaterial, err := s.recipeSvc.UpdateRawMaterial(serviceCtx, id, req.Name, req.Description, req.ReferencePrice)
|
||||
if err != nil {
|
||||
if errors.Is(err, recipe.ErrRawMaterialNotFound) {
|
||||
return nil, ErrRawMaterialNotFound
|
||||
@@ -106,9 +106,11 @@ func (s *rawMaterialServiceImpl) ListRawMaterials(ctx context.Context, req *dto.
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListRawMaterials")
|
||||
|
||||
opts := repository.RawMaterialListOptions{
|
||||
Name: req.Name,
|
||||
NutrientName: req.NutrientName,
|
||||
OrderBy: req.OrderBy,
|
||||
Name: req.Name,
|
||||
NutrientName: req.NutrientName,
|
||||
MinReferencePrice: req.MinReferencePrice,
|
||||
MaxReferencePrice: req.MaxReferencePrice,
|
||||
OrderBy: req.OrderBy,
|
||||
}
|
||||
rawMaterials, total, err := s.recipeSvc.ListRawMaterials(serviceCtx, opts, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user