菜谱问题修复

This commit is contained in:
liux 2025-04-28 09:22:11 +08:00
parent 9b2045952e
commit a107b2b170
6 changed files with 157 additions and 64 deletions

View File

@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.common.utils.RedisUtil;
import com.bonus.canteen.core.common.utils.TenantContextHolder;
import com.bonus.canteen.core.menu.dto.*;
@ -199,5 +200,23 @@ public class MenuRecipeController extends BaseController {
return AjaxResult.success();
}
// @PostMapping({"/page"})
// @ApiOperation("菜谱计划发布记录分页列表")
// public Page<MenuRecipeV2PageVO> getMenuRecipeV2Page(@RequestBody MenuRecipeV2PageDTO dto) {
// return this.menuRecipeService.getMenuRecipeV2Page(dto);
// }
//
// @PostMapping({"/template/detail"})
// @ApiOperation("获取指定菜谱模版详情")
// public List<MenuRecipeDetailDateVO> queryRecipeTemplateDate(@RequestBody QueryRecipeTemplateDateDTO dto) {
// return this.menuRecipeService.queryRecipeTemplateDate(dto);
// }
//
//
// @PostMapping({"/date/detail"})
// @ApiOperation("获取指定日期菜谱计划菜品详情")
// public List<MenuRecipeDetailDateVO> getMenuRecipeDateDetail(@RequestBody MenuRecipeDetailDateDTO dto) {
// return this.menuRecipeService.getMenuRecipeDateDetail(dto);
// }
}

View File

@ -2,6 +2,7 @@ package com.bonus.canteen.core.menu.domain;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
@ -27,6 +28,7 @@ public class MenuAppRecipe extends Model<MenuAppRecipe> {
private static final long serialVersionUID = 1L;
private Long recipeId;
private Integer bindType;
private List<Long> recipeIds;
/** 绑定时间 */
@ApiModelProperty(value = "绑定时间")

View File

@ -270,6 +270,7 @@ public class MenuDishesServiceImpl extends ServiceImpl<MenuDishesMapper, MenuDis
nutritionEntityList.add(nutritionEntity);
}
}
if(materialList != null && materialList.size() > 0){
//添加菜品和材料关系表
menuDishesMapper.addMenuMaterialDishes(dishesId,materialList);
NutritionEntityUtil nutritionEntityUtil = new NutritionEntityUtil();
@ -281,6 +282,8 @@ public class MenuDishesServiceImpl extends ServiceImpl<MenuDishesMapper, MenuDis
System.err.println("计算后:"+nutritionEntity.getCalcium());
return menuDishesMapper.addFinalNutrition(nutritionEntity,dishesId);
}
}
return 1;
}

View File

@ -24,6 +24,8 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.alloc.domain.AllocArea;
import com.bonus.canteen.core.alloc.domain.AllocCanteen;
@ -45,6 +47,7 @@ import com.bonus.canteen.core.menu.enums.*;
import com.bonus.canteen.core.menu.enums.MenuRecipeSortEnum;
import com.bonus.canteen.core.menu.mapper.*;
import com.bonus.canteen.core.menu.model.*;
import com.bonus.canteen.core.menu.service.IMenuRecipeDetailService;
import com.bonus.canteen.core.menu.service.IMenuRecipeService;
import com.bonus.canteen.core.menu.service.MenuDishesBaseService;
import com.bonus.canteen.core.menu.service.MenuDishesSizeService;
@ -65,6 +68,7 @@ import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.constant.DelFlagEnum;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.houqin.mq.constant.LeMqConstant;
import com.bonus.common.houqin.utils.LeBeanUtil;
import com.bonus.common.houqin.utils.id.Id;
import com.bonus.common.security.utils.SecurityUtils;
import com.google.common.collect.Lists;
@ -152,6 +156,7 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
}else{
content.setDeviceTypeList(sortEnum.getDeviceType());
content.setBindType(sortEnum.getBindType());
content.setRecipeName(LeBeanUtil.fieldLikeHandle(content.getRecipeName()));
records = menuRecipeMapper.selectMenuRecipeListV2(content);
if (ObjectUtil.isNotEmpty(records)) {
List<Long> recipeIds;
@ -161,6 +166,7 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
List<StallAndRecipeBindDto> stallAndRecipeBindDtos = this.menuRecipeMapper.selectRecipeByStallIdsAndBindType(menuRecipeDateVOS, content.getBindType());
maping = stallAndRecipeBindDtos.stream().collect(Collectors.toMap(StallAndRecipeBindDto::getStallId, StallAndRecipeBindDto::getRecipeId));
recipeIds = stallAndRecipeBindDtos.stream().map(StallAndRecipeBindDto::getRecipeId).distinct().collect(Collectors.toList());
this.generateRecipe(recipeIds, content.getApplyDate());
List<MenuRecipeDateVO> menuRecipeDateVOS1 = this.menuRecipeMapper.selectTmpBetweenDateDetailList(recipeIds, content.getApplyDate(), content.getApplyDate());
Map<Long, MenuRecipe> recipeMap = (recipeIds == null || recipeIds.isEmpty())
@ -172,7 +178,7 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
Map<Long, MenuRecipeDateVO> detailMap = menuRecipeDateVOS1.stream().collect(Collectors.toMap(MenuRecipeDateVO::getRecipeId, Function.identity(), (t1, t2) -> {
return t1;
}));
System.err.println("records = " + records.size());
AllocRecipeStallVO item;
long count;
for(Iterator<AllocRecipeStallVO> var12 = records.iterator(); var12.hasNext(); item.setDishesCount(count)) {
@ -226,7 +232,7 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
if (MenuBindTypeEnum.RESERVE.key().equals(content.getBindType())) {
exists = this.checkCanteenIfReserve(menuRecipe.getCanteenId(), menuRecipe.getStallId());
if (!exists) {
throw new ServiceException(I18n.getMessage("不支持订餐", new Object[0]));
throw new ServiceException(I18n.getMessage("不支持订餐", new Object[0]));
}
}
exists = this.menuRecipeMapper.exists(mar);
@ -235,6 +241,7 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
}
List<Long> sourceRecipeList = this.menuRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), null, content.getBindType(), content.getMealLineId());
if (ObjectUtil.isNotEmpty(sourceRecipeList)) {
mar.setRecipeIds(sourceRecipeList);
this.menuRecipeMapper.delete(mar);
}
@ -249,6 +256,7 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
}
MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE);
} else {
mar.setRecipeIds(Collections.singletonList(mar.getRecipeId()));
this.menuRecipeMapper.delete(mar);
if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
this.menuRecipeMapper.updateRecipeByCanteeStallMeal("-1", String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList);
@ -574,14 +582,17 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
}
}
@Resource
private IMenuRecipeDetailService menuRecipeDetailService;
@Transactional(rollbackFor = {Exception.class})
public synchronized void generateRecipe(List<Long> recipeIdList, LocalDate applyDate) {
if (!ObjectUtil.isEmpty(recipeIdList) && !ObjectUtil.isEmpty(applyDate)) {
recipeIdList = new ArrayList<>(recipeIdList);
Map<Long, Long> recipeDetailContMap = this.menuRecipeMapper.selectMenuRecipeDetailList(new QueryWrapper<MenuRecipeDetail>()
.eq("apply_date", applyDate)
.in("recipe_id", recipeIdList))
.stream().collect(Collectors.groupingBy(MenuRecipeDetail::getRecipeId, Collectors.counting()));
// Map<Long, Long> recipeDetailContMap = this.menuRecipeMapper.selectMenuRecipeDetailList(new QueryWrapper<MenuRecipeDetail>()
// .eq("apply_date", applyDate)
// .in("recipe_id", recipeIdList))
// .stream().collect(Collectors.groupingBy(MenuRecipeDetail::getRecipeId, Collectors.counting()));
Map<Long, Long> recipeDetailContMap = (Map) menuRecipeDetailService.list((Wrapper<MenuRecipeDetail>) ((LambdaQueryWrapper<MenuRecipeDetail>) Wrappers.lambdaQuery(MenuRecipeDetail.class).select(MenuRecipeDetail::getRecipeId).eq(MenuRecipeDetail::getApplyDate, applyDate)).in(MenuRecipeDetail::getRecipeId, recipeIdList)).stream().collect(Collectors.groupingBy(MenuRecipeDetail::getRecipeId, Collectors.counting()));
recipeIdList.removeAll(recipeDetailContMap.keySet());
if (!ObjectUtil.isEmpty(recipeIdList)) {
List<MenuRecipe> menuRecipes = this.list(Wrappers.lambdaQuery(MenuRecipe.class).in(MenuRecipe::getRecipeType, new Object[]{2, 3})

View File

@ -105,6 +105,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="shopstallId != null "> and b.shopstall_id = #{shopstallId}</if>
<if test="areaId != null "> and b.area_id = #{areaId}</if>
<if test="typeId != null "> and b.type_id = #{typeId}</if>
<if test="dishesName !=null and dishesName !=''"> and b.dishes_name like concat('%',#{dishesName},'%')</if>
<if test="typeIdList != null and typeIdList.size() > 0">
and b.type_id in
<foreach item="id" collection="typeIdList" open="(" separator="," close=")">

View File

@ -23,6 +23,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
</resultMap>
<!-- 获取指定日期菜谱详情 -->
<resultMap id="menuRecipeDateVO" type="com.bonus.canteen.core.menu.vo.MenuRecipeDateVO">
<result property="day" column="apply_date"/>
<result property="recipeId" column="recipe_id"/>
<collection property="details" ofType="com.bonus.canteen.core.menu.vo.MenuRecipeDetailDateVO">
<result property="mealtimeType" column="mealtime_type"/>
<result property="detailId" column="detail_id"/>
<collection property="dishesList" ofType="com.bonus.canteen.core.menu.vo.MenuRecipeDetailDishesVO">
<result property="dishesId" column="dishes_id"/>
<result property="dishesName" column="dishes_name"/>
<result property="dishesId" column="dishesId"/>
<result property="price" column="price"/>
<result property="sizeType" column="size_type"/>
<result property="supplyNum" column="supply_num"/>
<result property="saleNum" column="sale_num"/>
<result property="surplusNum" column="surplus_num"/>
<result property="restrictNum" column="restrict_num"/>
<result property="salePrice" column="sale_price"/>
<result property="recommendFlag" column="recommend_flag"/>
<result property="sortNum" column="sort_num"/>
<result property="typeId" column="type_id"/>
<result property="typeName" column="type_name"/>
<result property="salesMode" column="sales_mode"/>
<result property="canteenName" column="canteen_name"/>
<result property="unitPrice" column="unit_price"/>
<result property="mealType" column="meal_type"/>
<result property="dishesNum" column="dishes_num"/>
<result property="materialCost" column="material_cost"/>
</collection>
</collection>
</resultMap>
<sql id="selectMenuRecipeVo">
select id, recipe_id, plan_id, recipe_name, is_default, recipe_type, effect_date, expire_date, canteen_id, stall_id, enable_flag, revision, create_by, create_time, update_by, update_time, remark from menu_recipe
</sql>
@ -1004,7 +1036,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<delete id="delete" parameterType="com.bonus.canteen.core.menu.domain.MenuAppRecipe">
delete from menu_app_recipe where recipe_id = #{recipeId}
delete from menu_app_recipe where recipe_id in
<foreach collection="recipeIds" item="recipeId" separator="," open="(" close=")">
#{recipeId}
</foreach>
<if test="mealLineId != null">
and meal_line_id = #{mealLineId}
</if>
@ -1136,26 +1171,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMenuRecipeListV2" resultType="com.bonus.canteen.core.menu.vo.AllocRecipeStallVO">
SELECT
t3.area_id as areaId, t3.area_name as areaName, t2.canteen_id as canteenId,
t2.canteen_name as canteenName, t1.stall_id as stallId, t1.stall_name as stallName,
a.recipe_id as recipeId,a.recipe_name as recipeName
t3.area_id, t3.area_name, t2.canteen_id, t2.canteen_name, t1.stall_id, t1.stall_name
FROM
alloc_stall t1
LEFT JOIN alloc_canteen t2 ON t1.canteen_id = t2.canteen_id
LEFT JOIN alloc_area t3 ON t2.area_id = t3.area_id
LEFT JOIN(
select
mar.recipe_id,
mr.stall_id,
mar.bind_type,
mr.recipe_name
from menu_app_recipe mar
left join menu_recipe mr on mar.recipe_id = mr.recipe_id
where bind_type = #{bindType}
) a on a.stall_id =t1.stall_id
where 1=1
<if test="recipeName !=null and recipeName !=''">
AND EXISTS (
select null
from menu_app_recipe t4 INNER JOIN menu_recipe t5 on t4.recipe_id = t5.recipe_id
where t5.stall_id = t1.stall_id AND t4.bind_type = #{bindType}
and t5.recipe_name like #{recipeName}
)
</if>
<if test="deviceTypeList != null and deviceTypeList.size() > 0">
and
EXISTS (
AND EXISTS (
SELECT NULL
FROM
device_bind t6
@ -1169,9 +1200,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
)
</if>
where 1= 1
<if test="areaId !=null">
and t3.area_id = #{areaId}
</if>
@ -1182,28 +1210,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and t1.stall_id = #{stallId}
</if>
<!-- <if test="areaIds !=null and areaIds.size()>0">-->
<!-- and t3.area_id in-->
<!-- <foreach collection="areaIds" open="(" close=")" item="item" separator=",">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="canteenIds !=null and canteenIds.size()>0">-->
<!-- and t2.canteen_id in-->
<!-- <foreach collection="canteenIds" open="(" close=")" item="item" separator=",">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="stallIds !=null and stallIds.size()>0">-->
<!-- and t1.stall_id in-->
<!-- <foreach collection="stallIds" open="(" close=")" item="item" separator=",">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- SELECT-->
<!-- t3.area_id as areaId, t3.area_name as areaName, t2.canteen_id as canteenId,-->
<!-- t2.canteen_name as canteenName, t1.stall_id as stallId, t1.stall_name as stallName,-->
<!-- a.recipe_id as recipeId,a.recipe_name as recipeName-->
<!-- FROM-->
<!-- alloc_stall t1-->
<!-- LEFT JOIN alloc_canteen t2 ON t1.canteen_id = t2.canteen_id-->
<!-- LEFT JOIN alloc_area t3 ON t2.area_id = t3.area_id-->
<!-- LEFT JOIN(-->
<!-- select-->
<!-- mar.recipe_id,-->
<!-- mr.stall_id,-->
<!-- mar.bind_type,-->
<!-- mr.recipe_name-->
<!-- from menu_app_recipe mar-->
<!-- left join menu_recipe mr on mar.recipe_id = mr.recipe_id-->
<!-- where bind_type = #{bindType}-->
<!-- ) a on a.stall_id =t1.stall_id-->
<!-- <if test="deviceTypeList != null and deviceTypeList.size() > 0">-->
<!-- and-->
<!-- EXISTS (-->
<!-- SELECT NULL-->
<!-- FROM-->
<!-- device_bind t6-->
<!-- LEFT JOIN device_info t7 ON t7.device_id = t6.device_id-->
<!-- WHERE-->
<!-- t6.canteen_id = t2.canteen_id-->
<!-- AND t6.stall_id = t1.stall_id-->
<!-- AND t7.device_type IN-->
<!-- <foreach collection="deviceTypeList" item="deviceType" separator="," open="(" close=")">-->
<!-- #{deviceType}-->
<!-- </foreach>-->
<!-- )-->
<!-- </if>-->
<if test="recipeName !=null and recipeName !=''">
and a.recipe_name like concat('%', #{recipeName}, '%')
</if>
<!-- where 1= 1-->
<!-- <if test="areaId !=null">-->
<!-- and t3.area_id = #{areaId}-->
<!-- </if>-->
<!-- <if test="canteenId !=null">-->
<!-- and t2.canteen_id = #{canteenId}-->
<!-- </if>-->
<!-- <if test="stallId !=null ">-->
<!-- and t1.stall_id = #{stallId}-->
<!-- </if>-->
<!-- <if test="recipeName !=null and recipeName !=''">-->
<!-- and a.recipe_name like concat('%', #{recipeName}, '%')-->
<!-- </if>-->
</select>
<select id="selectRecipeByStallIdsAndBindType"
@ -1223,7 +1279,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</select>
<select id="selectTmpBetweenDateDetailList" resultType="com.bonus.canteen.core.menu.vo.MenuRecipeDateVO">
<select id="selectTmpBetweenDateDetailList" resultMap="menuRecipeDateVO">
select mrd.mealtime_type,
mrd.recipe_id,