优化算法
This commit is contained in:
@@ -13,6 +13,28 @@ func (Recipe) TableName() string {
|
||||
return "recipes"
|
||||
}
|
||||
|
||||
// CalculateTotalRawMaterialProportion 计算配方中所有原料的总比例
|
||||
func (r Recipe) CalculateTotalRawMaterialProportion() float32 {
|
||||
var totalPercentage float32
|
||||
for _, ingredient := range r.RecipeIngredients {
|
||||
totalPercentage += ingredient.Percentage
|
||||
}
|
||||
return totalPercentage
|
||||
}
|
||||
|
||||
// CalculateReferencePricePerKilogram 根据原料参考价计算配方每公斤的成本
|
||||
func (r Recipe) CalculateReferencePricePerKilogram() float32 {
|
||||
var totalCost float32
|
||||
for _, ingredient := range r.RecipeIngredients {
|
||||
// 确保 RawMaterial 已经被加载
|
||||
if ingredient.RawMaterial.ID == 0 {
|
||||
return 0.0
|
||||
}
|
||||
totalCost += ingredient.RawMaterial.ReferencePrice * ingredient.Percentage
|
||||
}
|
||||
return totalCost
|
||||
}
|
||||
|
||||
// RecipeIngredient 配方原料组成模型
|
||||
type RecipeIngredient struct {
|
||||
Model
|
||||
|
||||
Reference in New Issue
Block a user