diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java index 05af1b2..a7be698 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java @@ -1,9 +1,12 @@ package com.bonus.canteen.core.common.utils; +import com.bonus.common.houqin.constant.GlobalConstants; + import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class DateUtil { @@ -27,4 +30,14 @@ public class DateUtil { return dates; } + public static HashMap getDaysInWeekMap() { + LocalDate now = LocalDate.now(); + HashMap dateHashMap = new HashMap<>(); + for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { + LocalDate applyWeek = now.plusDays((long) i); + dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek); + } + return dateHashMap; + } + } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java index 446230b..b2c333c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java @@ -1,5 +1,6 @@ package com.bonus.canteen.core.cook.mapper; +import java.time.LocalDate; import java.util.List; import com.bonus.canteen.core.cook.domain.CookRecipeDetail; import org.apache.ibatis.annotations.Param; @@ -61,7 +62,15 @@ public interface CookRecipeDetailMapper { public List getAllCookRecipeDetailIds(Long[] recipeIds); - public List getToDeleteCookRecipeDetailIds(Long recipeId); + + public List getToDeleteCookRecipeDetailIds4PointDays(@Param("recipeId") Long recipeId, @Param("dateList") List dateList); + + public List getToDeleteCookRecipeDetailIds4Daily(@Param("recipeId") Long recipeId); + + public List getToDeleteCookRecipeDetailIds4WeeklyTemplate(@Param("recipeId") Long recipeId, @Param("applyWeeks") List applyWeeks); + + public List getToDeleteCookRecipeDetailIds4WeeklyDetail(@Param("recipeId")Long recipeId, @Param("dateList") List dateList); List getCookRecipeDetailLTemplate(@Param("recipeId") Long recipeId, @Param("detailType") String detailType); + } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java index 1a33cdc..653fb25 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java @@ -201,35 +201,53 @@ public class CookRecipeServiceImpl implements ICookRecipeService { throw new ServiceException("该菜谱名称已存在,请重新输入"); } int count = cookRecipeMapper.insertCookRecipe(cookRecipeDTO); //插入菜谱 - createRecipeDetails(cookRecipeDTO, true); + createRecipeDetails(cookRecipeDTO); //创建详情+菜品数据 return count; } catch (Exception e) { throw new ServiceException(e.getMessage()); } } - private void createRecipeDetails(CookRecipeDTO cookRecipeDTO, boolean isCreate) { - // 更新菜谱时, - // 指定日期菜谱,删掉指定日期的菜谱 - // 循环菜谱,删掉模板数据 + 今日开始的详情数据 - if (!isCreate) { - List cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds(cookRecipeDTO.getRecipeId()); - if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) { - Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new); - cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(cookRecipeDetailArray); - cookRecipeDetailMapper.deleteCookRecipeDetailByRecipeDetailIds(cookRecipeDetailArray); + /** + * 修改菜品计划信息 + * + * @param cookRecipeDTO 菜品计划信息 + * @return 结果 + */ + @Override + public int updateCookRecipe(CookRecipeDTO cookRecipeDTO) { + cookRecipeDTO.setUpdateTime(DateUtils.getNowDate()); + cookRecipeDTO.setUpdateBy(SecurityUtils.getUsername()); + try { + List cookRecipes = cookRecipeMapper.selectCookRecipeList(new CookRecipe()); + List otherCookRecipes = cookRecipes.stream().filter(item -> !item.getRecipeId().equals(cookRecipeDTO.getRecipeId())) + .map(CookRecipe::getRecipeName).collect(Collectors.toList()); + if (otherCookRecipes.contains(cookRecipeDTO.getRecipeName())) { + throw new ServiceException("该菜谱名称已存在,请重新输入"); } + int count = cookRecipeMapper.updateCookRecipe(cookRecipeDTO); + // 删除旧的详情+菜品数据 + deleteOldCookRecipeDetailsAndDishes(cookRecipeDTO); + // 重新创建详情+菜品数据 + createRecipeDetails(cookRecipeDTO); + return count; + } catch (Exception e) { + throw new ServiceException(e.getMessage()); } + } + + private void createRecipeDetails(CookRecipeDTO cookRecipeDTO) { // 插入指定日期、日循环摸板、周循环模板 if (!CollectionUtils.isEmpty(cookRecipeDTO.getRecipeDateList())) { for (CookRecipeDateDTO recipeDateDTO : cookRecipeDTO.getRecipeDateList()) { List detailList = recipeDateDTO.getDetailList(); - for (CookRecipeDetailDTO detailDTO : detailList) { - if (RecipeTypeEnum.POINT_DATE.key().equals(cookRecipeDTO.getRecipeType()) - && CollectionUtils.isEmpty(detailDTO.getDishesList())) { //指定日期,不插入空数据 - continue; + if (!CollectionUtils.isEmpty(detailList)) { + for (CookRecipeDetailDTO detailDTO : detailList) { + if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据 + continue; + } + insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } - insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } } } @@ -238,8 +256,13 @@ public class CookRecipeServiceImpl implements ICookRecipeService { if (!CollectionUtils.isEmpty(generatedRecipeDateList)) { for (CookRecipeDateDTO recipeDateDTO : generatedRecipeDateList) { List detailList = recipeDateDTO.getDetailList(); - for (CookRecipeDetailDTO detailDTO : detailList) { - insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); + if (!CollectionUtils.isEmpty(detailList)) { + for (CookRecipeDetailDTO detailDTO : detailList) { + if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据 + continue; + } + insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); + } } } } @@ -253,7 +276,6 @@ public class CookRecipeServiceImpl implements ICookRecipeService { List recipeDateListNew = new ArrayList<>(); if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType()) && Objects.nonNull(recipeDateList.get(0))) { //每日循环 List recipeDetailList = recipeDateList.get(0).getDetailList(); - //新增详情 LocalDate now = LocalDate.now(); for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO(); @@ -262,13 +284,7 @@ public class CookRecipeServiceImpl implements ICookRecipeService { recipeDateListNew.add(cookRecipeDateDTO); } } else if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { //每周循环 - LocalDate now = LocalDate.now(); - HashMap dateHashMap = new HashMap<>(); - for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { - LocalDate applyWeek = now.plusDays((long) i); - dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek); - } - //新增详情 + HashMap dateHashMap = DateUtil.getDaysInWeekMap(); Iterator> iterator = dateHashMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); @@ -316,28 +332,34 @@ public class CookRecipeServiceImpl implements ICookRecipeService { } } - /** - * 修改菜品计划信息 - * - * @param cookRecipeDTO 菜品计划信息 - * @return 结果 - */ - @Override - public int updateCookRecipe(CookRecipeDTO cookRecipeDTO) { - cookRecipeDTO.setUpdateTime(DateUtils.getNowDate()); - cookRecipeDTO.setUpdateBy(SecurityUtils.getUsername()); - try { - List cookRecipes = cookRecipeMapper.selectCookRecipeList(new CookRecipe()); - List otherCookRecipes = cookRecipes.stream().filter(item -> !item.getRecipeId().equals(cookRecipeDTO.getRecipeId())) - .map(CookRecipe::getRecipeName).collect(Collectors.toList()); - if (otherCookRecipes.contains(cookRecipeDTO.getRecipeName())) { - throw new ServiceException("该菜谱名称已存在,请重新输入"); + private void deleteOldCookRecipeDetailsAndDishes(CookRecipeDTO cookRecipeDTO) { + List cookRecipeDetailIds = new ArrayList<>(); + // 更新菜谱时,指定日期菜谱,删掉指定日期的菜谱 + if (RecipeTypeEnum.POINT_DATE.key().equals(cookRecipeDTO.getRecipeType())) { + List dateList = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyDate).collect(Collectors.toList()); + cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4PointDays(cookRecipeDTO.getRecipeId(), dateList); + } + // 循环日菜谱,删掉模板数据 + 今日开始的详情数据 + if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType())) { + cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4Daily(cookRecipeDTO.getRecipeId()); + } + // 循环周菜谱,删掉指定周x模板数据 + 今日开始的周x的详情数据 + if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { + List applyWeeks = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList()); + HashMap dateHashMap = DateUtil.getDaysInWeekMap(); + List dateList = new ArrayList<>(); + for (Long applyWeek : applyWeeks) { + dateList.add(dateHashMap.get(applyWeek.intValue())); } - int count = cookRecipeMapper.updateCookRecipe(cookRecipeDTO); - createRecipeDetails(cookRecipeDTO, false); - return count; - } catch (Exception e) { - throw new ServiceException(e.getMessage()); + //模板数据 + cookRecipeDetailIds.addAll(cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4WeeklyTemplate(cookRecipeDTO.getRecipeId(), applyWeeks)); + //详情数据 + cookRecipeDetailIds.addAll(cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4WeeklyDetail(cookRecipeDTO.getRecipeId(), dateList)); + } + if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) { + Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new); + cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(cookRecipeDetailArray); + cookRecipeDetailMapper.deleteCookRecipeDetailByRecipeDetailIds(cookRecipeDetailArray); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicAreaMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicAreaMapper.xml index ac8f6f7..aa64737 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicAreaMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicAreaMapper.xml @@ -25,7 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - where del_flag = 0 and area_name = #{areaName} + where del_flag = '0' and area_name = #{areaName} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml index 2423238..f28116c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml @@ -40,7 +40,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - where bc.canteen_id = #{canteenId} and bc.del_flag = 0 + where bc.canteen_id = #{canteenId} and bc.del_flag = '0' - + + bs.del_flag = '0' and bs.stall_name like concat('%', #{stallName}, '%') and bs.area_id = #{areaId} and bs.canteen_id = #{canteenId} @@ -65,12 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT distinct(crd.recipe_detail_id) FROM cook_recipe_detail crd - left join cook_recipe cr ON cr.recipe_id = crd.recipe_id - where cr.recipe_id = #{recipeId} and cr.recipe_type = 1 and crd.apply_date >= NOW()-1 - - UNION + left join cook_recipe cr ON cr.recipe_id = crd.recipe_id + where cr.recipe_id = #{recipeId} and cr.recipe_type = 1 and crd.apply_date in + + #{applyDate} + + + - UNION - + + + ba.del_flag = '0' and bc.del_flag = '0' and bs.del_flag = '0' and cr.del_flag = '0' and cr.recipe_name like concat('%', #{recipeName}, '%') and cr.recipe_type = #{recipeType} and cr.stall_id = #{stallId} @@ -78,7 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - AND recipe_id in + AND cr.recipe_id in #{item} @@ -236,12 +237,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -381,12 +382,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" basic_stall t1 LEFT JOIN basic_canteen t2 ON t1.canteen_id = t2.canteen_id LEFT JOIN basic_area t3 ON t2.area_id = t3.area_id - where 1=1 + where t1.del_flag = '0' and t2.del_flag = '0' and t3.del_flag = '0' AND EXISTS ( select null from cook_recipe_bind_app t4 INNER JOIN cook_recipe t5 on t4.recipe_id = t5.recipe_id - where t5.stall_id = t1.stall_id AND t4.bind_type = #{bindType} + where t5.del_flag = '0' and t5.stall_id = t1.stall_id AND t4.bind_type = #{bindType} and t5.recipe_name like #{recipeName} ) @@ -419,14 +420,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"