diff --git a/diet-core/src/main/java/com/mathvision/diet/excel/BigDecimalStringConverter.java b/diet-core/src/main/java/com/mathvision/diet/excel/BigDecimalStringConverter.java index c80f2d6..102c4a0 100644 --- a/diet-core/src/main/java/com/mathvision/diet/excel/BigDecimalStringConverter.java +++ b/diet-core/src/main/java/com/mathvision/diet/excel/BigDecimalStringConverter.java @@ -7,10 +7,12 @@ import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.util.NumberUtils; +import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; import java.text.ParseException; +@Slf4j public class BigDecimalStringConverter implements Converter { public BigDecimalStringConverter() { } @@ -31,7 +33,12 @@ public class BigDecimalStringConverter implements Converter { return cellData.getNumberValue(); } if (CellDataTypeEnum.STRING.equals(cellData.getType())) { - return NumberUtils.parseBigDecimal(cellData.getStringValue().trim(), contentProperty); + try { + return NumberUtils.parseBigDecimal(cellData.getStringValue().trim(), contentProperty); + } catch (Exception e) { + log.error("[BigDecimalStringConverter] convertToJavaData exception :" + e.getMessage(), e); + return new BigDecimal(-1); + } } return null; } diff --git a/diet-core/src/main/java/com/mathvision/diet/service/IngredientService.java b/diet-core/src/main/java/com/mathvision/diet/service/IngredientService.java index dfb6238..857ecb7 100644 --- a/diet-core/src/main/java/com/mathvision/diet/service/IngredientService.java +++ b/diet-core/src/main/java/com/mathvision/diet/service/IngredientService.java @@ -110,13 +110,21 @@ public class IngredientService { resultModels.add(ResultModel.builder().key(resultKey).result("食物类型为空或者不支持").build()); return; } - if (MapUtils.isEmpty(ingredient.getNutrient()) || !ingredient.getNutrient().entrySet().stream().allMatch(x -> enumService.checkNutrient(x.getKey()))) { - resultModels.add(ResultModel.builder().key(resultKey).result("营养素内容全空或者不支持").build()); + if (MapUtils.isEmpty(ingredient.getNutrient())) { + resultModels.add(ResultModel.builder().key(resultKey).result("营养素内容全空").build()); + return; + } + if (ingredient.getNutrient().entrySet().stream().anyMatch(x -> !enumService.checkNutrient(x.getKey()))) { + resultModels.add(ResultModel.builder().key(resultKey).result("包含不支持的营养素").build()); + return; + } + if (ingredient.getNutrient().entrySet().stream().anyMatch(x -> x.getValue().floatValue() < 0)) { + resultModels.add(ResultModel.builder().key(resultKey).result("营养素含量不能识别").build()); return; } ingredients.add(ingredient); - resultModels.add(ResultModel.builder().key(resultKey).result("导入成功").build()); + resultModels.add(ResultModel.builder().key(resultKey).result("导入结果").build()); } catch (Exception e) { resultModels.add(ResultModel.builder().key(resultKey).result("导入失败:" + e.getMessage()).build()); log.error(String.format("%s-%s-%s 导入失败: %s", o.getKey(), o.getName(), o.getType(), e.getMessage()), e); @@ -185,7 +193,7 @@ public class IngredientService { } public List getByKeyword(String keyword) { - return ingredientRepository.findByKeyLikeOrNameStartsWithOrderByKeyAsc(keyword); + return ingredientRepository.findByKeyLikeOrNameLikeOrderByKeyAsc(keyword); } public List getFullByKeys(Collection keys) { diff --git a/diet-core/src/main/java/com/mathvision/diet/service/MenuDishService.java b/diet-core/src/main/java/com/mathvision/diet/service/MenuDishService.java index 225318b..cc3fbed 100644 --- a/diet-core/src/main/java/com/mathvision/diet/service/MenuDishService.java +++ b/diet-core/src/main/java/com/mathvision/diet/service/MenuDishService.java @@ -81,7 +81,7 @@ public class MenuDishService { List allDays = menuDishes.entrySet().stream().flatMap(kv -> kv.getValue().keySet().stream()).distinct().sorted().collect(Collectors.toList()); List allCrows = menu.getCrows(); if (CollectionUtils.isEmpty(allDays)) { - allDays = IntStream.rangeClosed(1, Math.toIntExact(menu.getDay())).mapToObj(Long::valueOf).collect(Collectors.toList()); + allDays = menu.getDay(); } List> headers = Lists.newArrayList(); 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 f250392..ff6846c 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,7 +9,6 @@ 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; @@ -38,9 +37,17 @@ public class MenuReportService { BigDecimal overflow = nutrition.getOverflow(); Map> itemStandard = nutrition.getIngredient().getOrDefault(crow, new HashMap<>()); 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)); - Map items = dishes.stream().flatMap(dish -> dish.getIngredient().stream().filter(item -> item.getValue().containsKey(crow) && item.getValue().get(crow).doubleValue() > 0 && ingredientMap.containsKey(item.getKey()))).flatMap(x -> ingredientMap.get(x.getKey()).getNutrient().entrySet().stream().map(n -> Pair.of(n.getKey(), n.getValue().multiply(x.getValue().get(crow)).divide(new BigDecimal(100), RoundingMode.HALF_UP)))).collect(Collectors.toMap(Pair::getKey, Pair::getValue, BigDecimal::add)); + Map items = dishes.stream().flatMap(dish -> dish.getIngredient().stream().filter(item -> item.getValue().containsKey(crow) && item.getValue().get(crow).doubleValue() > 0 && ingredientMap.containsKey(item.getKey()))) + .flatMap(x -> ingredientMap.get(x.getKey()).getNutrient().entrySet().stream().map(n -> Pair.of(n.getKey(), n.getValue().multiply(x.getValue().get(crow)).divide(new BigDecimal(100), RoundingMode.HALF_UP)))) + .collect(Collectors.toMap(Pair::getKey, Pair::getValue, BigDecimal::add)); Map types = dishes.stream().flatMap(dish -> dish.getIngredient().stream().filter(item -> ingredientMap.containsKey(item.getKey())).map(item -> ingredientMap.get(item.getKey()).getType())).collect(Collectors.toMap(x -> x, x -> 1, Integer::sum)); + itemStandard.forEach((key, value) -> { + if (!items.containsKey(key)) { + items.put(key, BigDecimal.ZERO); + } + }); + JSONObject result = new JSONObject(); result.put("day", day); result.put("crow", crow); @@ -62,73 +69,72 @@ public class MenuReportService { BigDecimal max = standard == null ? null : standard.get("max"); BigDecimal min = standard == null ? null : standard.get("min"); BigDecimal ul = standard == null ? null : standard.get("ul"); + content.put("ul", ul == null ? "-" : ul.toString()); + + boolean byMax = false; + boolean byMin = false; if (max == null || max.compareTo(BigDecimal.ZERO) == 0) { if (min == null || min.compareTo(BigDecimal.ZERO) == 0) { content.put("standard", "-"); - content.put("ul", ul == null ? "-" : ul.toString()); content.put("overload", "-"); content.put("conclusion", "-"); + return; } else { content.put("standard", "≥" + min); - content.put("ul", ul == null ? "-" : ul.toString()); - if (min.compareTo(value) > 0) { - content.put("overload", value.subtract(min).divide(min, RoundingMode.FLOOR)); - if(min.subtract(value).compareTo(overflow.divide(new BigDecimal(100), RoundingMode.FLOOR).multiply(value)) > 0) { - content.put("conclusion", "不足"); - } else { - content.put("conclusion", "适量"); - } - } else { - content.put("overload", BigDecimal.ZERO); + if (value.compareTo(min) >= 0) { + content.put("overload", "-"); content.put("conclusion", "适量"); + } else { + byMin = true; } } } else { if (min == null || min.compareTo(BigDecimal.ZERO) == 0) { content.put("standard", "≤" + max); - content.put("ul", ul == null ? "-" : ul.toString()); - if (max.compareTo(value) < 0) { - if(value.subtract(max).compareTo(overflow.divide(new BigDecimal(100), RoundingMode.FLOOR).multiply(value)) > 0) { - if(ul != null && value.compareTo(ul) > 0) { - content.put("conclusion", "严重超标"); - } else { - content.put("conclusion", "过量"); - } - } else { - content.put("conclusion", "适量"); - } - content.put("overload", value.subtract(max).divide(max, RoundingMode.FLOOR)); + if (max.compareTo(value) >= 0) { + content.put("overload", "-"); + content.put("conclusion", "适量"); } else { - content.put("overload", BigDecimal.ZERO); + byMax = true; } } else { content.put("standard", min + "~" + max); - content.put("ul", ul == null ? "-" : ul.toString()); - if (min.compareTo(value) > 0) { - content.put("overload", value.subtract(min).divide(min, RoundingMode.FLOOR)); - if(min.subtract(value).compareTo(overflow.divide(new BigDecimal(100), RoundingMode.FLOOR).multiply(value)) > 0) { - content.put("conclusion", "不足"); - } else { - content.put("conclusion", "适量"); - } + if (Range.closed(min, max).contains(value)) { + content.put("overload", "-"); + content.put("conclusion", "适量"); + } + if(value.compareTo(max) > 0) { + byMax = true; + } else { + byMin = true; + } + } + } + + if (byMin) { + BigDecimal overload = calculatePercentage(value, min); + content.put("overload", overload + "%"); + if(overload.abs().compareTo(overflow) > 0) { + content.put("conclusion", "不足"); + } else { + content.put("conclusion", "适量"); + } + } + + if (byMax) { + BigDecimal overload = calculatePercentage(value, max); + content.put("overload", overload + "%"); + if(overload.compareTo(overflow) > 0) { + if(ul != null && value.compareTo(ul) > 0) { + content.put("conclusion", "严重超标"); } else { - if (max.compareTo(value) < 0) { - content.put("overload", value.subtract(max).divide(max, RoundingMode.FLOOR)); - if(value.subtract(max).compareTo(overflow.divide(new BigDecimal(100), RoundingMode.FLOOR).multiply(value)) > 0) { - if(ul != null && value.compareTo(ul) > 0) { - content.put("conclusion", "严重超标"); - } else { - content.put("conclusion", "过量"); - } - } else { - content.put("conclusion", "适量"); - } - } else { - content.put("overload", "0%"); - } + content.put("conclusion", "过量"); } + } else { + content.put("conclusion", "适量"); } } + contents.add(content); }); result.put("ingredient", contents); @@ -198,29 +204,44 @@ public class MenuReportService { .filter(x -> allConcerned.contains(x.getKey())) .collect(Collectors.toMap(Pair::getKey, Pair::getValue, BigDecimal::add)); + allConcerned.forEach(key -> { + if (!items.containsKey(key)) { + items.put(key, BigDecimal.ZERO); + } + }); + JSONObject result = new JSONObject(); result.put("day", day); result.put("crow", crow); result.put("meals", dishes.stream().map(MenuDish::getMeal).collect(Collectors.toSet())); - BigDecimal energy = items.get("energy"); - if (energy == null || energy.doubleValue() <= 0) { - return result; - } + //BigDecimal energy = items.get("energy").multiply(new BigDecimal("4.18")); + BigDecimal protein = items.get("protein").multiply(new BigDecimal("4")); + BigDecimal fat = items.get("fat").multiply(new BigDecimal("9")); + BigDecimal carbs = items.get("carbs").multiply(new BigDecimal("4")); + BigDecimal total = protein.add(fat).add(carbs); + JSONArray contents = new JSONArray(); - contents.add(toEnergyContent(energy, "protein", Range.closed(10, 20), items)); - contents.add(toEnergyContent(energy, "fat", Range.closed(20, 30), items)); - contents.add(toEnergyContent(energy, "carbs", Range.closed(50, 60), items)); + contents.add(toEnergyContent(total, "protein", protein, Range.closed(10, 20))); + contents.add(toEnergyContent(total, "fat", fat, Range.closed(20, 30))); + contents.add(toEnergyContent(total, "carbs", carbs, Range.closed(50, 60))); result.put("energy", contents); return result; } - private JSONObject toEnergyContent(BigDecimal energy, String key, Range standard, Map items) { - double value = items.getOrDefault(key, BigDecimal.ZERO).divide(energy, RoundingMode.FLOOR).multiply(new BigDecimal(100)).doubleValue(); + private JSONObject toEnergyContent(BigDecimal total, String key, BigDecimal value, Range standard) { + BigDecimal percentage = total.intValue() == 0 ? BigDecimal.ZERO : value.divide(total, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); + percentage = percentage.setScale(2, RoundingMode.HALF_UP); + JSONObject result = JSONObject.of("name", enumService.getNutrient(key).getValue() + "/总能量"); result.put("standard", String.format("%s~%s", standard.lowerEndpoint(), standard.upperEndpoint())); - result.put("value", value); - result.put("conclusion", standard.lowerEndpoint() > value ? "略低" : standard.upperEndpoint() < value ? "略高" : "合适"); + result.put("value", percentage); + result.put("conclusion", standard.lowerEndpoint() > percentage.intValue() ? "略低" : standard.upperEndpoint() < percentage.intValue() ? "略高" : "合适"); return result; } + + private static BigDecimal calculatePercentage(BigDecimal value, BigDecimal base) { + BigDecimal percentage = value.subtract(base).divide(base, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); + return percentage.setScale(2, RoundingMode.HALF_UP); + } } \ No newline at end of file diff --git a/diet-core/src/main/java/com/mathvision/diet/service/MenuService.java b/diet-core/src/main/java/com/mathvision/diet/service/MenuService.java index 84fcffd..4d9c6fa 100644 --- a/diet-core/src/main/java/com/mathvision/diet/service/MenuService.java +++ b/diet-core/src/main/java/com/mathvision/diet/service/MenuService.java @@ -55,7 +55,7 @@ public class MenuService { } public void update(Menu menu) { - menuDishRepository.deleteByMenuAndDayGreaterThanAndMealNotIn(menu.getId(), menu.getDay(), menu.getMeals()); + menuDishRepository.deleteByMenuAndDayNotInAndMealNotIn(menu.getId(), menu.getDay(), menu.getMeals()); menuDishRepository.findByMenu(menu.getId()).forEach(x -> { List ingredient = x.getIngredient(); if (CollectionUtils.isNotEmpty(ingredient)) { diff --git a/diet-dao/src/main/java/com/mathvision/diet/entity/Menu.java b/diet-dao/src/main/java/com/mathvision/diet/entity/Menu.java index f21435d..932b664 100644 --- a/diet-dao/src/main/java/com/mathvision/diet/entity/Menu.java +++ b/diet-dao/src/main/java/com/mathvision/diet/entity/Menu.java @@ -37,8 +37,9 @@ public class Menu { @Column(name = "name", nullable = false, length = 20) private String name; - @Column(name = "day", columnDefinition = "int UNSIGNED not null") - private Long day; + @Type(type = "json") + @Column(name = "day", columnDefinition = "json", nullable = false) + private List day; @Type(type = "json") @Column(name = "meals", columnDefinition = "json", nullable = false) diff --git a/diet-dao/src/main/java/com/mathvision/diet/repository/IngredientRepository.java b/diet-dao/src/main/java/com/mathvision/diet/repository/IngredientRepository.java index b2a7d5f..7278f57 100644 --- a/diet-dao/src/main/java/com/mathvision/diet/repository/IngredientRepository.java +++ b/diet-dao/src/main/java/com/mathvision/diet/repository/IngredientRepository.java @@ -13,7 +13,7 @@ import java.util.List; public interface IngredientRepository extends JpaRepository, JpaSpecificationExecutor { @Query("select new Ingredient(i.key,i.name,i.type) from Ingredient i where i.key like concat('%', ?1, '%') or i.name like concat('%', ?1, '%') order by i.key") - List findByKeyLikeOrNameStartsWithOrderByKeyAsc(String keyword); + List findByKeyLikeOrNameLikeOrderByKeyAsc(String keyword); @Query("select new Ingredient(i.key,i.name,i.type) from Ingredient i where i.key in ?1 order by i.key") List findByKeyInOrderByKeyAsc(Collection keys); @Query("select new Ingredient(i.key,i.name) from Ingredient i") diff --git a/diet-dao/src/main/java/com/mathvision/diet/repository/MenuDishRepository.java b/diet-dao/src/main/java/com/mathvision/diet/repository/MenuDishRepository.java index 28d0c13..eac3ff3 100644 --- a/diet-dao/src/main/java/com/mathvision/diet/repository/MenuDishRepository.java +++ b/diet-dao/src/main/java/com/mathvision/diet/repository/MenuDishRepository.java @@ -17,7 +17,7 @@ public interface MenuDishRepository extends JpaRepository, JpaSp MenuDish findByIdAndVender(Long id, Long vender); List findByMenu(Long menu); @Transactional - long deleteByMenuAndDayGreaterThanAndMealNotIn(Long menu, Long day, Collection meals); + long deleteByMenuAndDayNotInAndMealNotIn(Long menu, Collection day, Collection meals); @Transactional long deleteByMenuAndVender(Long menu, Long vender); @Transactional diff --git a/diet-web/src/main/java/com/mathvision/diet/controller/MenuController.java b/diet-web/src/main/java/com/mathvision/diet/controller/MenuController.java index 9ef379b..53c0b8f 100644 --- a/diet-web/src/main/java/com/mathvision/diet/controller/MenuController.java +++ b/diet-web/src/main/java/com/mathvision/diet/controller/MenuController.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.LongStream; @RequestMapping("/api/menu") @Controller @@ -44,12 +45,17 @@ public class MenuController extends BaseController { @ResponseBody @RequestMapping(method = RequestMethod.PUT) - public List add(@RequestParam String name, @RequestParam(required = false) List vendors, @RequestParam Long nutrient, @RequestParam Integer day, @RequestParam List meals, @RequestParam List month, @RequestParam List crows) { + public List add(@RequestParam String name, @RequestParam(required = false) List vendors, @RequestParam Long nutrient, @RequestParam Long day, @RequestParam(required = false) List days, @RequestParam List meals, @RequestParam List month, @RequestParam List crows) { Assert.isTrue(StringUtils.isNotBlank(name), "[参数错误]食谱名称必填!"); - Assert.isTrue(Range.closed(1, 7).contains(day), "[参数错误]天数取值[1~7]!"); Assert.isTrue(CollectionUtils.isNotEmpty(month) && month.stream().allMatch(x -> Range.closed(1, 12).contains(x)), "[参数错误]请选择正确的月份!"); Assert.isTrue(CollectionUtils.isNotEmpty(meals), "[参数错误]餐次必填!"); Assert.isTrue(meals.stream().allMatch(x -> MealType.toType(x) != null), "[参数错误]餐次取值[早餐,午餐,晚餐]!"); + if (days == null || days.isEmpty()) { + Assert.isTrue(Range.closed(1L, 7L).contains(day), "[参数错误]星期取值[周一~周日]!"); + days = LongStream.rangeClosed(1L, day).boxed().collect(Collectors.toList()); + } else { + Assert.isTrue(Range.closed(1L, 7L).containsAll(days), "[参数错误]星期取值[周一~周日]!"); + } Nutrition nutrition = nutritionService.get(nutrient); Assert.notNull(nutrition, "[参数错误]营养计划必选!"); @@ -61,7 +67,8 @@ public class MenuController extends BaseController { Assert.isTrue(CollectionUtils.isNotEmpty(crows), "[参数错误]人群取值[参照营养计划]必填!"); Assert.isTrue(allCrows.containsAll(crows), "[参数错误]营养计划不包含所选的人群!"); Instant dateTime = Instant.now(); - List menus = vendors.stream().map(v -> Menu.builder().name(name).meals(meals).crows(crows).scale(crows.stream().collect(Collectors.toMap(x -> x, x -> 0))).day(Long.valueOf(day)).nutrient(nutrient).month(month).vender(v).status(MenuStatus.draft).operate(getUid()).created(dateTime).modify(dateTime).build()).collect(Collectors.toList()); + List finalDays = days; + List menus = vendors.stream().map(v -> Menu.builder().name(name).meals(meals).crows(crows).scale(crows.stream().collect(Collectors.toMap(x -> x, x -> 0))).day(finalDays).nutrient(nutrient).month(month).vender(v).status(MenuStatus.draft).operate(getUid()).created(dateTime).modify(dateTime).build()).collect(Collectors.toList()); return menuService.add(menus).stream().map(Menu::getId).collect(Collectors.toList()); } @@ -77,13 +84,20 @@ public class MenuController extends BaseController { @ResponseBody @RequestMapping(method = RequestMethod.POST) - public void update(@RequestParam Long id, @RequestParam(required = false) String name, @RequestParam(required = false) List month, @RequestParam Long nutrient, @RequestParam(required = false) Integer day, @RequestParam(required = false) List meals, @RequestParam(required = false) List crows) { + public void update(@RequestParam Long id, @RequestParam(required = false) String name, @RequestParam(required = false) List month, @RequestParam Long nutrient, @RequestParam(required = false) Long day, @RequestParam(required = false) List days, @RequestParam(required = false) List meals, @RequestParam(required = false) List crows) { Menu menu = menuService.get(id); Assert.notNull(menu, "[参数错误]食谱不存在!"); Assert.isTrue(menu.getVender().equals(getVender()) || isAdmin(), "[参数错误]食谱不存在!"); Assert.isTrue(menu.getStatus() != MenuStatus.publish, "[参数错误]该食谱已发布,不可编辑!"); Assert.isTrue(CollectionUtils.isEmpty(month) || month.stream().allMatch(x -> Range.closed(1, 12).contains(x)), "[参数错误]请选择正确的月份!"); - Assert.isTrue(day == null || Range.closed(1, 7).contains(day), "[参数错误]天数取值[1~7]!"); + if (days == null || days.isEmpty()) { + Assert.isTrue(day == null || Range.closed(1L, 7L).contains(day), "[参数错误]天数取值[1~7]!"); + if (day != null) { + days = LongStream.rangeClosed(1L, day).boxed().collect(Collectors.toList()); + } + } else { + Assert.isTrue(Range.closed(1L, 7L).containsAll(days), "[参数错误]星期取值[周一~周日]!"); + } boolean flag = false; boolean check = false; @@ -100,8 +114,8 @@ public class MenuController extends BaseController { menu.setMeals(meals); flag = true; } - if (day != null && !day.equals(menu.getDay().intValue())) { - menu.setDay(day.longValue()); + if (days != null && !days.equals(menu.getDay())) { + menu.setDay(days); flag = true; } if (nutrient != null && !nutrient.equals(menu.getNutrient())) { diff --git a/diet-web/src/main/java/com/mathvision/diet/controller/MenuDishController.java b/diet-web/src/main/java/com/mathvision/diet/controller/MenuDishController.java index 5354931..3d5b4c8 100644 --- a/diet-web/src/main/java/com/mathvision/diet/controller/MenuDishController.java +++ b/diet-web/src/main/java/com/mathvision/diet/controller/MenuDishController.java @@ -1,7 +1,6 @@ package com.mathvision.diet.controller; import com.alibaba.fastjson2.JSON; -import com.google.common.collect.Range; import com.mathvision.diet.domian.MenuDishItemDTO; import com.mathvision.diet.domian.MenuStatus; import com.mathvision.diet.entity.Dish; @@ -47,7 +46,7 @@ public class MenuDishController extends BaseController { @ResponseBody @RequestMapping(method = RequestMethod.PUT) - public Long add(@RequestParam Long menuId, @RequestParam Long dishId, @RequestParam Integer day, @RequestParam String meal, @RequestParam(required = false) String mark, @RequestParam(required = false) String poly, @RequestParam String ingredient) { + public Long add(@RequestParam Long menuId, @RequestParam Long dishId, @RequestParam Long day, @RequestParam String meal, @RequestParam(required = false) String mark, @RequestParam(required = false) String poly, @RequestParam String ingredient) { Menu menu = checkAndConvert(menuId, MenuStatus.pass, MenuStatus.publish); return menuDishService.add(checkAndConvert(menu, checkAndConvert(dishId), day, meal, mark, poly, parseItems(ingredient, new HashSet<>(menu.getCrows())))).getId(); } @@ -129,8 +128,8 @@ public class MenuDishController extends BaseController { return isAdmin() ? menuDishService.query(menuId) : menuDishService.query(menuId, getVender()); } - private MenuDish checkAndConvert(Menu menu, Dish dish, Integer day, String meal, String mark, String poly, List ingredient) { - Assert.isTrue(Range.closed(1, menu.getDay().intValue()).contains(day), "[参数错误]天数不在食谱的设置范围内!"); + private MenuDish checkAndConvert(Menu menu, Dish dish, Long day, String meal, String mark, String poly, List ingredient) { + Assert.isTrue(menu.getDay().contains(day), "[参数错误]天数不在食谱的设置范围内!"); Assert.isTrue(menu.getMeals().contains(meal), "[参数错误]餐次不在食谱的设置范围内!"); mark = StringUtils.isBlank(mark) ? dish.getMarks() : mark; @@ -140,7 +139,7 @@ public class MenuDishController extends BaseController { Assert.isTrue(enumService.checkPoly(poly), "[参数错误]烹饪手法不在取值范围内!"); Instant dateTime = Instant.now(); - return MenuDish.builder().vender(menu.getVender()).menu(menu.getId()).dish(dish.getId()).day(day.longValue()).meal(meal).name(dish.getName()).marks(mark).poly(poly).ingredient(ingredient).operate(getUid()).created(dateTime).modify(dateTime).build(); + return MenuDish.builder().vender(menu.getVender()).menu(menu.getId()).dish(dish.getId()).day(day).meal(meal).name(dish.getName()).marks(mark).poly(poly).ingredient(ingredient).operate(getUid()).created(dateTime).modify(dateTime).build(); } private Menu checkAndConvert(Long menuId, MenuStatus ... statuses) { diff --git a/diet-web/src/main/java/com/mathvision/diet/controller/MenuReleaseController.java b/diet-web/src/main/java/com/mathvision/diet/controller/MenuReleaseController.java index ba19901..caab131 100644 --- a/diet-web/src/main/java/com/mathvision/diet/controller/MenuReleaseController.java +++ b/diet-web/src/main/java/com/mathvision/diet/controller/MenuReleaseController.java @@ -35,7 +35,7 @@ public class MenuReleaseController extends BaseController { Assert.isTrue(menu.getVender().equals(getVender()) || isAdmin(), "[参数错误]食谱不存在!"); Assert.isTrue(menu.getStatus() == MenuStatus.pass, "[参数错误]该食谱当前非审批通过状态,不可发布!"); menu.getScale().entrySet().forEach(x -> x.setValue(scale.getOrDefault(x.getKey(), 0))); - menuReleaseService.publish(id, menu.getScale(), parseDate(startTime, new Date()), parseDate(endTime, DateUtils.addDays(new Date(), menu.getDay().intValue())), getUid()); + menuReleaseService.publish(id, menu.getScale(), parseDate(startTime, new Date()), parseDate(endTime, DateUtils.addDays(new Date(), 7)), getUid()); } @ResponseBody 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 9adc792..44ed11c 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 @@ -75,8 +75,8 @@ public class MenuReportController extends BaseController { return menu; } - private Long checkAndGetDay(Long day, Long defaultDay) { - return (day == null || day < 1 || day > defaultDay) ? (long) LocalDate.now().getDayOfWeek().getValue() : day; + private Long checkAndGetDay(Long day, List days) { + return day == null || !days.contains(day) ? (long) LocalDate.now().getDayOfWeek().getValue() : day; } private String checkAndGetCrow(String crow, List allCrow) { diff --git a/diet-web/src/main/java/com/mathvision/diet/vo/MenuDishDetailVO.java b/diet-web/src/main/java/com/mathvision/diet/vo/MenuDishDetailVO.java index 685bd33..8648d51 100644 --- a/diet-web/src/main/java/com/mathvision/diet/vo/MenuDishDetailVO.java +++ b/diet-web/src/main/java/com/mathvision/diet/vo/MenuDishDetailVO.java @@ -14,7 +14,7 @@ import java.util.List; @NoArgsConstructor public class MenuDishDetailVO { /** 用于那天*/ - Integer day; + Long day; /** 用于那餐*/ String meal; /**打标,默认用原菜品标签*/ diff --git a/diet-web/src/main/resources/static/change.html b/diet-web/src/main/resources/static/change.html index f0b5810..5f561d3 100644 --- a/diet-web/src/main/resources/static/change.html +++ b/diet-web/src/main/resources/static/change.html @@ -40,4 +40,8 @@
  • ʳײƷ: ɾIJ֧polyֶ(ַ);
  • ͼƬӿ: ͼƬϴӿ, ʹurlͼƬ; 漰λͷͲƷͼƬ߼;
  • +

    11.23

    +
      +
    • ʳ׽ӿ: ޸ʳdaysֶ, ѡܼ; ԭdayԭĺ岻, daydaysѡһ;
    • +
    diff --git a/diet-web/src/main/resources/static/menu/menu.html b/diet-web/src/main/resources/static/menu/menu.html index c8a61a4..955b13d 100644 --- a/diet-web/src/main/resources/static/menu/menu.html +++ b/diet-web/src/main/resources/static/menu/menu.html @@ -118,7 +118,8 @@ endTime=2024-03-01
    vendors=1,2,3  // Чҵ˲
     name=Ѽ   // 
     nutrient=1      // Ӫƻ
    -day=7           // 
    +day=7           // , 7ʶһ~
    +days=[1,3,5]    // , һ,,,   daysdayѡһ
     meals=,, // ʹ
     month=1,2,3,4,5,6,7,8,9,10,11,12  // ·
     crows=,  //Ⱥ  
    @@ -143,7 +144,8 @@ crows=
     
    id=1 // ʳID
     name=Ѽ   // 
     nutrient=1      // Ӫƻ
    -day=7           // 
    +day=7           // , 7ʶһ~
    +days=[1,3,5]    // , һ,,,   daysdayѡһ
     meals=,, // ʹ
     month=1,2,3,4,5,6,7,8,9,10,11,12  // ·
     crows=,  //Ⱥ  
    diff --git a/doc/change.md b/doc/change.md
    index 5507ab7..c190037 100644
    --- a/doc/change.md
    +++ b/doc/change.md
    @@ -37,4 +37,8 @@
     * 枚举接口: 营养素增加了钠
     * 菜品接口: 增删改查支持poly字段(烹饪手法);
     * 食谱菜品: 增删改查支持poly字段(烹饪手法);
    -* 图片接口: 图片上传接口, 使用url访问图片; 涉及到单位头像和菜品图片的逻辑变更;
    \ No newline at end of file
    +* 图片接口: 图片上传接口, 使用url访问图片; 涉及到单位头像和菜品图片的逻辑变更;
    +
    +
    +### 11.23
    +* 食谱接口: 添加修改食谱增加days字段,  代表选择的周几; 原来的day保持原来的含义不变, day和days二选一;
    \ No newline at end of file
    diff --git a/doc/menu/menu.md b/doc/menu/menu.md
    index 8cd50fa..5116da5 100644
    --- a/doc/menu/menu.md
    +++ b/doc/menu/menu.md
    @@ -129,7 +129,8 @@ endTime=2024-03-01
     vendors=1,2,3  // 管理端有效,业务端不用
     name=番茄鸡蛋汤   // 名称
     nutrient=1      // 营养计划编号
    -day=7           // 天数
    +day=7           // 天数, 如果传7则标识周一~周日
    +days=[1,3,5]    // 天数, 代表周一,周三,周五,   days和day二选一
     meals=早餐,午餐,晚餐 // 餐次
     month=1,2,3,4,5,6,7,8,9,10,11,12  // 适用月份
     crows=重体力,轻体力  //人群  
    @@ -159,7 +160,8 @@ crows=重体力,轻体力  //人群
     id=1 // 食谱ID
     name=番茄鸡蛋汤   // 名称
     nutrient=1      // 营养计划编号
    -day=7           // 天数
    +day=7           // 天数, 如果传7则标识周一~周日
    +days=[1,3,5]    // 天数, 代表周一,周三,周五,   days和day二选一
     meals=早餐,午餐,晚餐 // 餐次
     month=1,2,3,4,5,6,7,8,9,10,11,12  // 适用月份
     crows=重体力,轻体力  //人群