caoyiwen 1 year ago
parent
commit
acaf6f42fb
  1. 15
      diet-core/src/main/java/com/mathvision/diet/service/MenuReportService.java
  2. 14
      diet-web/src/main/java/com/mathvision/diet/controller/MenuReportController.java
  3. 35
      diet-web/src/main/resources/static/menu/report.html
  4. 39
      doc/menu/report.md

15
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<MenuDish> dishes) {
public JSONObject types(Menu menu, String crow, List<MenuDish> 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<String, BigDecimal> dayStandard = nutrition.getFoodCategoryDay();
Map<String, BigDecimal> 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<MenuDish> dishes) {
dishes = dishes.stream().filter(menuDish -> menuDish.getIngredient().stream().anyMatch(item -> item.getValue().containsKey(crow))).collect(Collectors.toList());
Map<String, List<MenuDish>> 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<MenuDish> dishes) {
List<String> allConcerned= Lists.newArrayList("energy", "protein", "fat", "carbs");
Map<String, Ingredient> 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));

14
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<MenuDish> 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<MenuDish> dishes = menuDishService.query(id, menu.getVender());
return menuReportService.types(menu, dishes);
return menuReportService.poly(crow, dishes);
}
@ResponseBody

35
diet-web/src/main/resources/static/menu/report.html

@ -108,7 +108,7 @@ crow=xxx //
&quot;success&quot;: true
}
</code></pre>
<h1>2. 食谱分析</h1>
<h1>2. 能量分析</h1>
<blockquote>
<p>GET /api/menu/analysis/energy</p>
</blockquote>
@ -151,7 +151,7 @@ crow=xxx //
&quot;success&quot;: true
}
</code></pre>
<h1>3. 食谱分析</h1>
<h1>3. 类型分析</h1>
<blockquote>
<p>GET /api/menu/analysis/types</p>
</blockquote>
@ -162,6 +162,7 @@ crow=xxx //
<h3>Êä³ö:</h3>
<pre><code class="json">{
&quot;body&quot;: {
&quot;crow&quot;: &quot;6岁~8岁 女&quot;,
&quot;dayRule&quot;: [
[
{
@ -351,4 +352,34 @@ crow=xxx //
&quot;success&quot;: true
}
</code></pre>
<h1>4. 烹饪方式分析</h1>
<blockquote>
<p>GET /api/menu/analysis/poly</p>
</blockquote>
<h3>输入:</h3>
<pre><code class="text">id=1 // 食谱ID, 必填
crow=xxx //人群,默认第一个人群
</code></pre>
<h3>输出:</h3>
<pre><code class="json">{
&quot;body&quot;: {
&quot;crow&quot;: &quot;6岁~8岁 女&quot;,
&quot;0&quot;: { // 总计
&quot;&quot;: 10,
&quot;&quot;: 6
},
&quot;1&quot;: { // 第一天
&quot;&quot;: 10,
&quot;&quot;: 6
},
&quot;2&quot;: { // 第二天
&quot;&quot;: 10,
&quot;&quot;: 6
}
},
&quot;code&quot;: 200,
&quot;desc&quot;: &quot;成功&quot;,
&quot;success&quot;: true
}
</code></pre>

39
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": [
[
{
@ -364,3 +365,37 @@ crow=xxx //
"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
}
~~~
Loading…
Cancel
Save