diff --git a/diet-core/src/main/java/com/mathvision/diet/service/MenuReportService.java b/diet-core/src/main/java/com/mathvision/diet/service/MenuReportService.java index bf7e712..f250392 100644 --- a/diet-core/src/main/java/com/mathvision/diet/service/MenuReportService.java +++ b/diet-core/src/main/java/com/mathvision/diet/service/MenuReportService.java @@ -9,6 +9,7 @@ import com.mathvision.diet.domian.MenuDishItemDTO; import com.mathvision.diet.entity.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.springframework.stereotype.Service; @@ -134,7 +135,8 @@ public class MenuReportService { return result; } - public JSONObject types(Menu menu, List dishes) { + public JSONObject types(Menu menu, String crow, List dishes) { + dishes = dishes.stream().filter(menuDish -> menuDish.getIngredient().stream().anyMatch(item -> item.getValue().containsKey(crow))).collect(Collectors.toList()); Nutrition nutrition = nutritionService.get(menu.getNutrient()); Map dayStandard = nutrition.getFoodCategoryDay(); Map weekStandard = nutrition.getFoodCategoryWeek(); @@ -171,11 +173,22 @@ public class MenuReportService { }); JSONObject result = new JSONObject(); + result.put("crow", crow); result.put("dayRule", dayRule); result.put("weekRule", weekRule); return result; } + public JSONObject poly(String crow, List dishes) { + dishes = dishes.stream().filter(menuDish -> menuDish.getIngredient().stream().anyMatch(item -> item.getValue().containsKey(crow))).collect(Collectors.toList()); + Map> data = dishes.stream().collect(Collectors.groupingBy(MenuDish::getPoly)); + JSONObject result = new JSONObject(); + result.put("crow", crow); + result.put("0", data.entrySet().stream().map(x -> Pair.of(x.getKey(), x.getValue().size())).collect(Collectors.toMap(Pair::getKey, Pair::getValue))); + dishes.stream().collect(Collectors.groupingBy(MenuDish::getDay, Collectors.groupingBy(MenuDish::getPoly))).forEach((k, v) -> result.put(k.toString(), v.entrySet().stream().map(x -> Pair.of(x.getKey(), x.getValue().size())).collect(Collectors.toMap(Pair::getKey, Pair::getValue)))); + return result; + } + public JSONObject energy(long day, String crow, List dishes) { List allConcerned= Lists.newArrayList("energy", "protein", "fat", "carbs"); Map ingredientMap = ingredientService.getFullByKeys(dishes.stream().filter(x -> CollectionUtils.isNotEmpty(x.getIngredient())).flatMap(x -> x.getIngredient().stream().map(MenuDishItemDTO::getKey)).collect(Collectors.toSet())).stream().collect(Collectors.toMap(Ingredient::getKey, v -> v)); diff --git a/diet-web/src/main/java/com/mathvision/diet/controller/MenuReportController.java b/diet-web/src/main/java/com/mathvision/diet/controller/MenuReportController.java index 4d0a125..9adc792 100644 --- a/diet-web/src/main/java/com/mathvision/diet/controller/MenuReportController.java +++ b/diet-web/src/main/java/com/mathvision/diet/controller/MenuReportController.java @@ -43,10 +43,20 @@ public class MenuReportController extends BaseController { @ResponseBody @RequestMapping(value = "types", method = RequestMethod.GET) - public JSONObject types(@RequestParam Long id) { + public JSONObject types(@RequestParam Long id, @RequestParam(required = false) String crow) { Menu menu = checkAndGetMenu(id); + crow = checkAndGetCrow(crow, menu.getCrows()); + List dishes = menuDishService.query(id, menu.getVender()); + return menuReportService.types(menu, crow, dishes); + } + + @ResponseBody + @RequestMapping(value = "poly", method = RequestMethod.GET) + public JSONObject poly(@RequestParam Long id, @RequestParam(required = false) String crow) { + Menu menu = checkAndGetMenu(id); + crow = checkAndGetCrow(crow, menu.getCrows()); List dishes = menuDishService.query(id, menu.getVender()); - return menuReportService.types(menu, dishes); + return menuReportService.poly(crow, dishes); } @ResponseBody diff --git a/diet-web/src/main/resources/static/menu/report.html b/diet-web/src/main/resources/static/menu/report.html index 7fed525..07f9805 100644 --- a/diet-web/src/main/resources/static/menu/report.html +++ b/diet-web/src/main/resources/static/menu/report.html @@ -108,7 +108,7 @@ crow=xxx // "success": true } -

2. 食谱分析

+

2. 能量分析

GET /api/menu/analysis/energy

@@ -151,7 +151,7 @@ crow=xxx // "success": true } -

3. 食谱分析

+

3. 类型分析

GET /api/menu/analysis/types

@@ -162,6 +162,7 @@ crow=xxx //

输出:

{
   "body": {
+    "crow": "6岁~8岁 女",
     "dayRule": [
       [
         {
@@ -351,4 +352,34 @@ crow=xxx  //
   "success": true
 }
 
+

4. 烹饪方式分析

+
+

GET /api/menu/analysis/poly

+
+

输入:

+
id=1      // 食谱ID, 必填
+crow=xxx  //人群,默认第一个人群
+
+

输出:

+
{
+  "body": {
+    "crow": "6岁~8岁 女",
+    "0": { // 总计
+      "蒸": 10,
+      "煮": 6
+    },
+    "1": { // 第一天
+      "蒸": 10,
+      "煮": 6
+    },
+    "2": { // 第二天
+      "蒸": 10,
+      "煮": 6
+    }
+  },
+  "code": 200,
+  "desc": "成功",
+  "success": true
+}
+
diff --git a/doc/menu/report.md b/doc/menu/report.md index 3b21304..deb3e7a 100644 --- a/doc/menu/report.md +++ b/doc/menu/report.md @@ -114,7 +114,7 @@ crow=xxx // ~~~ -# 2. 食谱分析 +# 2. 能量分析 > GET /api/menu/analysis/energy @@ -161,7 +161,7 @@ crow=xxx // } ~~~ -# 3. 食谱分析 +# 3. 类型分析 > GET /api/menu/analysis/types @@ -175,6 +175,7 @@ crow=xxx // ~~~json { "body": { + "crow": "6岁~8岁 女", "dayRule": [ [ { @@ -363,4 +364,38 @@ crow=xxx // "desc": "成功", "success": true } +~~~ + +# 4. 烹饪方式分析 + +> GET /api/menu/analysis/poly + +### 输入: +```text +id=1 // 食谱ID, 必填 +crow=xxx //人群,默认第一个人群 +``` + +### 输出: +~~~json +{ + "body": { + "crow": "6岁~8岁 女", + "0": { // 总计 + "蒸": 10, + "煮": 6 + }, + "1": { // 第一天 + "蒸": 10, + "煮": 6 + }, + "2": { // 第二天 + "蒸": 10, + "煮": 6 + } + }, + "code": 200, + "desc": "成功", + "success": true +} ~~~ \ No newline at end of file