|
|
@@ -60,14 +60,24 @@ export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
|
|
}
|
|
|
|
|
|
toVo(entity: Product): ProductVo {
|
|
|
- // 计算ME值(每克产品的能量)
|
|
|
- const mePerGram = this.calculateME(
|
|
|
- entity.protein,
|
|
|
- entity.fat,
|
|
|
- entity.fiber,
|
|
|
- entity.ash,
|
|
|
- entity.moisture,
|
|
|
- );
|
|
|
+ // ME值计算逻辑:
|
|
|
+ // 1. 如果配置了meValue,优先使用配置值
|
|
|
+ // 2. 否则通过营养成分计算
|
|
|
+ let mePerGram: number;
|
|
|
+
|
|
|
+ if (entity.meValue !== null && entity.meValue !== undefined) {
|
|
|
+ // 使用直接配置的ME值(kcal/g)
|
|
|
+ mePerGram = entity.meValue;
|
|
|
+ } else {
|
|
|
+ // 通过营养成分计算ME值
|
|
|
+ mePerGram = this.calculateME(
|
|
|
+ entity.protein,
|
|
|
+ entity.fat,
|
|
|
+ entity.fiber,
|
|
|
+ entity.ash,
|
|
|
+ entity.moisture,
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
// 计算整包产品的总能量
|
|
|
const totalCalories = mePerGram * entity.totalWeight;
|
|
|
@@ -84,6 +94,7 @@ export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
|
|
ash: entity.ash,
|
|
|
moisture: entity.moisture,
|
|
|
totalWeight: entity.totalWeight,
|
|
|
+ meValue: entity.meValue,
|
|
|
totalCalories: Number(totalCalories.toFixed(2)), // 保留2位小数
|
|
|
};
|
|
|
}
|