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 4d68620..02cae34 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 @@ -5,6 +5,7 @@ import java.util.List; import java.util.Set; import com.bonus.canteen.core.cook.domain.CookRecipeDetail; +import com.bonus.canteen.core.cook.vo.CookRecipeDetailIDVO; import org.apache.ibatis.annotations.Param; /** @@ -77,4 +78,7 @@ public interface CookRecipeDetailMapper { List getByRecipeIdAndDatesAndIntervalId(@Param("recipeId") Long recipeId, @Param("dateList") Set dateList, @Param("mealtimeType") Long mealtimeType); + List getCookRecipeDetailsByApplyDateAndRecipeIds(@Param("recipeIdList") List recipeIdList); + + List getCookRecipeDetailsByDetailTypeAndRecipeIds(@Param("recipeIdList") List recipeIdList); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDishesMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDishesMapper.java index 8768181..e8b8cd3 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDishesMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDishesMapper.java @@ -19,6 +19,8 @@ public interface CookRecipeDishesMapper { */ public CookRecipeDishes selectCookRecipeDishesById(Long id); + public List selectCookRecipeDishesByDetailIds(@Param("recipeDetailIds") List recipeDetailIds); + /** * 查询菜品计划菜品关联列表 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java index 01c9e0a..efa7d25 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java @@ -39,6 +39,10 @@ public interface CookRecipeMapper { public List selectRecipeListByRecipeIds(@Param("recipeIds") List recipeIds); + public List selectRecipeListByRecipeTypes(); + + public List selectRecipeListByRecipeTypesAndRecipeIds(@Param("recipeIds") List recipeIds); + public int getDishesCount4PointDates(Long recipeId); public int getDishesCount4Recycle(Long recipeId); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java index 8e32ea8..bf8daac 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java @@ -81,4 +81,6 @@ public interface ICookRecipeService { * @return 结果 */ public int deleteCookRecipeByRecipeId(Long recipeId); + + public void generateRecipe(); } 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 5a9e110..71aba74 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 @@ -12,7 +12,6 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.read.metadata.ReadSheet; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.bonus.canteen.core.android.vo.CookMealtimeTypeEnum; import com.bonus.canteen.core.common.utils.DateUtil; import com.bonus.canteen.core.common.utils.MqUtil; @@ -123,60 +122,6 @@ public class CookRecipeServiceImpl implements ICookRecipeService { return list; } -// public List selectCookRecipeList4Current(CookRecipeDTO content) { -// Map bindTypeMap = CookRecipeSortEnum.getKeyMap(); -// CookRecipeSortEnum sortEnum = bindTypeMap.get(content.getKey()); -// List records = new ArrayList<>(); -// if (Objects.isNull(sortEnum)) { -// throw new ServiceException("参数错误"); -// }else{ -// content.setDeviceTypeList(sortEnum.getDeviceType()); -// content.setBindType(sortEnum.getBindType()); -// content.setRecipeName(LeBeanUtil.fieldLikeHandle(content.getRecipeName())); -// records = cookRecipeMapper.selectCookRecipeListV2(content); -// if (!CollectionUtils.isEmpty(records)) { -// List recipeIds; -// Map maping; -// List stallIds = records.stream().map(CookRecipeVO::getStallId).collect(Collectors.toList()); -// List stallAndRecipeBindDtos = this.cookRecipeMapper.selectRecipeByStallIdsAndBindType(stallIds, content.getBindType()); -// maping = stallAndRecipeBindDtos.stream().collect(Collectors.toMap(StallAndRecipeBindVO::getStallId, StallAndRecipeBindVO::getRecipeId)); -// recipeIds = stallAndRecipeBindDtos.stream().map(StallAndRecipeBindVO::getRecipeId).distinct().collect(Collectors.toList()); -//// this.generateRecipe(recipeIds, content.getApplyDate()); -// List cookRecipeDetailVOs = this.cookRecipeMapper.selectTmpBetweenDateDetailList(recipeIds, content.getApplyDate(), content.getApplyDate()); -// Map recipeMap = (recipeIds == null || recipeIds.isEmpty()) -// ? new HashMap<>() -// : this.cookRecipeMapper.selectRecipeListByRecipeIds(recipeIds) -// .stream() -// .collect(Collectors.toMap(CookRecipe::getRecipeId, Function.identity())); -// Map detailMap = cookRecipeDetailVOs.stream().collect(Collectors.toMap(CookRecipeDetailVO::getRecipeId, Function.identity(), (t1, t2) -> { -// return t1; -// })); -// System.err.println("records = " + records.size()); -// CookRecipeVO item; -// long count; -// for(Iterator var12 = records.iterator(); var12.hasNext(); item.setDishesCount(count)) { -// item = var12.next(); -// Long recipeId; -// recipeId = maping.get(item.getStallId()); -// item.setRecipeId(recipeId); -// CookRecipeDateVO cookRecipeDateVO = new CookRecipeDateVO(); -// cookRecipeDateVO.setDetailList(Arrays.asList(detailMap.get(recipeId))); -// item.setRecipeDateList(Arrays.asList(cookRecipeDateVO)); -// item.setRecipeName(Optional.ofNullable(recipeMap.get(recipeId)).map(CookRecipe::getRecipeName).orElse(null)); -// count = 0L; -// if (Objects.nonNull(item.getRecipeDateDetail()) && !CollectionUtils.isEmpty(item.getRecipeDateList().get(0).getDetailList())) { -// count = item.getRecipeDateList().get(0).getDetailList().stream().filter((x) -> { -// return !CollectionUtils.isEmpty(x.getDishesList()); -// }).flatMap((x) -> { -// return x.getDishesList().stream(); -// }).map(CookRecipeDishesVO::getDishesId).distinct().count(); -// } -// } -// } -// } -// return records; -// } - @Override public List selectCookRecipeList4Current(AllocRecipeStallDTO content) { Map bindTypeMap = CookRecipeSortEnum.getKeyMap(); @@ -565,4 +510,106 @@ public class CookRecipeServiceImpl implements ICookRecipeService { public int deleteCookRecipeByRecipeId(Long recipeId) { return cookRecipeMapper.deleteCookRecipeByRecipeId(recipeId); } + + @Transactional( + rollbackFor = {Exception.class} + ) + public void generateRecipe() { + List recipeIds = cookRecipeMapper.selectRecipeListByRecipeTypes().stream().map(CookRecipe::getRecipeId).collect(Collectors.toList()); + for(int i = 0; i < 7; ++i) { + this.generateRecipe(recipeIds, LocalDate.now().plusDays((long)i)); + } + } + + @Transactional( + rollbackFor = {Exception.class} + ) + public synchronized void generateRecipe(List inputRecipeIdList, LocalDate applyDate) { + if (!ObjectUtil.isEmpty(inputRecipeIdList) && !ObjectUtil.isEmpty(applyDate)) { + List recipeIdList = new ArrayList(inputRecipeIdList); + List cookRecipeDetails = cookRecipeDetailMapper.getCookRecipeDetailsByApplyDateAndRecipeIds(recipeIdList); + Map recipeDetailContMap = cookRecipeDetails.stream().collect(Collectors.groupingBy(CookRecipeDetail::getRecipeId, Collectors.counting())); + recipeIdList.removeAll(recipeDetailContMap.keySet()); + if (!ObjectUtil.isEmpty(recipeIdList)) { + List menuRecipes = cookRecipeMapper.selectRecipeListByRecipeTypesAndRecipeIds(recipeIdList); + if (!ObjectUtil.isEmpty(menuRecipes)) { + Map recipeMap = (Map)menuRecipes.stream().collect(Collectors.toMap(CookRecipe::getRecipeId, Function.identity())); + List menuRecipeDetails = cookRecipeDetailMapper.getCookRecipeDetailsByDetailTypeAndRecipeIds(recipeIdList); + Map recipeTypeMap = (Map)menuRecipes.stream().collect(Collectors.toMap(CookRecipe::getRecipeId, CookRecipe::getRecipeType)); + menuRecipeDetails = this.filterCookRecipeDetails(recipeTypeMap, menuRecipeDetails, applyDate); + if (!ObjectUtil.isEmpty(menuRecipeDetails)) { + Map> detailMap = (Map)menuRecipeDetails.stream().collect(Collectors.groupingBy(CookRecipeDetail::getRecipeId)); + List detailIds = (List)menuRecipeDetails.stream().map(CookRecipeDetail::getRecipeDetailId).collect(Collectors.toList()); + List foundDishes = cookRecipeDishesMapper.selectCookRecipeDishesByDetailIds(detailIds); + Map> recipeDishes = (Map)foundDishes.stream().collect(Collectors.groupingBy(CookRecipeDishes::getRecipeDetailId)); + List recipeDetailV2List = Lists.newArrayList(); + List recipeDishesV2List = Lists.newArrayList(); + Iterator var13 = recipeMap.keySet().iterator(); +// label59: +// while(true) { +// Long recipeId; +// Integer type; +// List menuRecipeDetail; +// do { +// if (!var13.hasNext()) { +// this.cookRecipeDetailMapper.insert(recipeDetailV2List); +// if (ObjectUtil.isNotEmpty(recipeDishesV2List)) { +// this.cookRecipeDishesService.saveBatch(recipeDishesV2List); +// } +// return; +// } +// recipeId = (Long)var13.next(); +// type = (Integer)recipeTypeMap.get(recipeId); +// menuRecipeDetail = (List)detailMap.get(recipeId); +// } while(!ObjectUtil.isNotEmpty(menuRecipeDetail)); +// Iterator var17 = menuRecipeDetail.iterator(); +// while(true) { +// Long detailId; +// List dishes; +// do { +// if (!var17.hasNext()) { +// continue label59; +// } +// CookRecipeDetail recipeDetail = (CookRecipeDetail)var17.next(); +// CookRecipeDetail detailItem = new CookRecipeDetail(); +// detailId = Id.next(); +// detailItem.setDetailId(detailId); +// detailItem.setRecipeId(recipeId); +// if (ObjectUtil.equal(type, 3)) { +// detailItem.setApplyWeek(applyDate.getDayOfWeek().getValue()); +// } +// detailItem.setApplyDate(applyDate); +// detailItem.setMealtimeType(recipeDetail.getMealtimeType()); +// detailItem.setCreateBy(""); +// detailItem.setDetailType(2); +// recipeDetailV2List.add(detailItem); +// dishes = (List)recipeDishes.get(recipeDetail.getDetailId()); +// } while(!ObjectUtil.isNotEmpty(dishes)); +// Iterator var22 = dishes.iterator(); +// while(var22.hasNext()) { +// CookRecipeDishes dish = (CookRecipeDishes)var22.next(); +// CookRecipeDishes dishesItem = (CookRecipeDishes) BeanUtil.copyProperties(dish, CookRecipeDishes.class, new String[0]); +// dishesItem.setDetailId(detailId); +// dishesItem.setId((Long)null); +// recipeDishesV2List.add(dishesItem); +// } +// } +// } + } + } + } + } + } + + public List filterCookRecipeDetails(Map recipeTypeMap, List cookRecipeDetails, LocalDate applyDate) { + return (List)cookRecipeDetails.stream().filter((item) -> { + Long recipeId = item.getRecipeId(); + Integer type = (Integer)recipeTypeMap.get(recipeId); + if (type == 3) { + return ObjectUtil.equal(item.getApplyWeek(), applyDate.getDayOfWeek().getValue()); + } else { + return type == 2; + } + }).collect(Collectors.toList()); + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDetailIDVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDetailIDVO.java new file mode 100644 index 0000000..3dbb9d2 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDetailIDVO.java @@ -0,0 +1,9 @@ +package com.bonus.canteen.core.cook.vo; + +public class CookRecipeDetailIDVO { + /** 菜谱id */ + private Long recipeId; + + /** 菜谱计划详情id */ + private Long recipeDetailId; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml index 857ba90..a971097 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml @@ -19,7 +19,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select recipe_detail_id, sale_type_id, recipe_id, apply_date, apply_week, apply_month, mealtime_type, detail_type, create_by, create_time, update_by, update_time from cook_recipe_detail + select recipe_detail_id, sale_type_id, recipe_id, apply_date, apply_week, apply_month, mealtime_type, + detail_type, create_by, create_time, update_by, update_time + from cook_recipe_detail + + + + diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDishesMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDishesMapper.xml index 266d4e4..b379995 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDishesMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDishesMapper.xml @@ -23,7 +23,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, recipe_detail_id, dishes_id, price, sale_price, size_type, supply_num, sale_num, remanent_num, limit_num, chef_id, recommend_flag, create_by, create_time, update_by, update_time from cook_recipe_dishes + select id, recipe_detail_id, dishes_id, price, sale_price, size_type, supply_num, sale_num, + remanent_num, limit_num, chef_id, recommend_flag, create_by, create_time, update_by, update_time + from cook_recipe_dishes + + insert into cook_recipe_dishes diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml index f0e67ab..2d2bbc2 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml @@ -108,6 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + +