菜谱管理

This commit is contained in:
sxu 2025-05-31 10:08:03 +08:00
parent 33373d50f9
commit 596c7d16fd
5 changed files with 88 additions and 77 deletions

View File

@ -201,6 +201,34 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
throw new ServiceException("该菜谱名称已存在,请重新输入");
}
int count = cookRecipeMapper.insertCookRecipe(cookRecipeDTO); //插入菜谱
createRecipeDetails(cookRecipeDTO); //创建详情+菜品数据
return count;
} catch (Exception e) {
throw new ServiceException(e.getMessage());
}
}
/**
* 修改菜品计划信息
*
* @param cookRecipeDTO 菜品计划信息
* @return 结果
*/
@Override
public int updateCookRecipe(CookRecipeDTO cookRecipeDTO) {
cookRecipeDTO.setUpdateTime(DateUtils.getNowDate());
cookRecipeDTO.setUpdateBy(SecurityUtils.getUsername());
try {
List<CookRecipe> cookRecipes = cookRecipeMapper.selectCookRecipeList(new CookRecipe());
List<String> 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) {
@ -214,8 +242,7 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
for (CookRecipeDateDTO recipeDateDTO : cookRecipeDTO.getRecipeDateList()) {
List<CookRecipeDetailDTO> detailList = recipeDateDTO.getDetailList();
for (CookRecipeDetailDTO detailDTO : detailList) {
if (RecipeTypeEnum.POINT_DATE.key().equals(cookRecipeDTO.getRecipeType())
&& CollectionUtils.isEmpty(detailDTO.getDishesList())) { //指定日期不插入空数据
if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据
continue;
}
insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO);
@ -228,6 +255,9 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
for (CookRecipeDateDTO recipeDateDTO : generatedRecipeDateList) {
List<CookRecipeDetailDTO> detailList = recipeDateDTO.getDetailList();
for (CookRecipeDetailDTO detailDTO : detailList) {
if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据
continue;
}
insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO);
}
}
@ -262,15 +292,16 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
cookRecipeDateDTO.setDetailList(recipeDateDTO.getDetailList());
}
}
if (!CollectionUtils.isEmpty(cookRecipeDateDTO.getDetailList())) {
List<CookRecipeDetailDTO> detailList = cookRecipeDateDTO.getDetailList();
for (CookRecipeDetailDTO detail : detailList) {
if (!CollectionUtils.isEmpty(detail.getDishesList())) {
recipeDateListNew.add(cookRecipeDateDTO);
}
break;
}
}
recipeDateListNew.add(cookRecipeDateDTO);
// if (!CollectionUtils.isEmpty(cookRecipeDateDTO.getDetailList())) {
// List<CookRecipeDetailDTO> detailList = cookRecipeDateDTO.getDetailList();
// for (CookRecipeDetailDTO detail : detailList) {
// if (!CollectionUtils.isEmpty(detail.getDishesList())) {
// recipeDateListNew.add(cookRecipeDateDTO);
// }
// break;
// }
// }
}
}
return recipeDateListNew;
@ -306,57 +337,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<CookRecipe> cookRecipes = cookRecipeMapper.selectCookRecipeList(new CookRecipe());
List<String> 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<Long> cookRecipeDetailIds = new ArrayList<>();
// 更新菜谱时指定日期菜谱删掉指定日期的菜谱
if (RecipeTypeEnum.POINT_DATE.key().equals(cookRecipeDTO.getRecipeType())) {
List<LocalDate> 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<Long> applyWeeks = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList());
HashMap<Integer, LocalDate> dateHashMap = DateUtil.getDaysInWeekMap();
List<LocalDate> dateList = new ArrayList<>();
for (Long applyWeek : applyWeeks) {
dateList.add(dateHashMap.get(applyWeek.intValue()));
}
int count = cookRecipeMapper.updateCookRecipe(cookRecipeDTO);
List<Long> cookRecipeDetailIds = new ArrayList<>();
// 更新菜谱时指定日期菜谱删掉指定日期的菜谱
if (RecipeTypeEnum.POINT_DATE.key().equals(cookRecipeDTO.getRecipeType())) {
List<LocalDate> 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<Long> applyWeeks = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList());
HashMap<Integer, LocalDate> dateHashMap = DateUtil.getDaysInWeekMap();
List<LocalDate> dateList = new ArrayList<>();
for (Long applyWeek : applyWeeks) {
dateList.add(dateHashMap.get(applyWeek.intValue()));
}
//模板数据
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);
}
// 重新创建菜谱
createRecipeDetails(cookRecipeDTO);
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);
}
}

View File

@ -25,7 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasicAreaList" parameterType="com.bonus.canteen.core.basic.domain.BasicArea" resultMap="BasicAreaResult">
<include refid="selectBasicAreaVo"/>
<where>
<where>
del_flag = '0'
<if test="areaName != null and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="manager != null and manager != ''"> and manager = #{manager}</if>
@ -37,12 +38,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasicAreaByAreaName" parameterType="String" resultMap="BasicAreaResult">
<include refid="selectBasicAreaVo"/>
where del_flag = 0 and area_name = #{areaName}
where del_flag = '0' and area_name = #{areaName}
</select>
<select id="selectBasicAreaByAreaId" parameterType="Long" resultMap="BasicAreaResult">
<include refid="selectBasicAreaVo"/>
where del_flag = 0 and area_id = #{areaId}
where del_flag = '0' and area_id = #{areaId}
</select>
<insert id="insertBasicArea" parameterType="com.bonus.canteen.core.basic.domain.BasicArea" useGeneratedKeys="true" keyProperty="areaId">

View File

@ -40,7 +40,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasicCanteenList" parameterType="com.bonus.canteen.core.basic.domain.BasicCanteen" resultMap="BasicCanteenResult">
<include refid="selectBasicCanteenVo"/>
<where>
<where>
bc.del_flag = '0'
<if test="canteenName != null and canteenName != ''"> and bc.canteen_name like concat('%', #{canteenName}, '%')</if>
<if test="areaId != null "> and bc.area_id = #{areaId}</if>
<if test="manager != null and manager != ''"> and bc.manager = #{manager}</if>
@ -63,18 +64,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasicCanteenByCanteenId" parameterType="Long" resultMap="BasicCanteenResult">
<include refid="selectBasicCanteenVo"/>
where bc.canteen_id = #{canteenId} and bc.del_flag = 0
where bc.canteen_id = #{canteenId} and bc.del_flag = '0'
</select>
<select id="selectBasicCanteenByCanteenName" parameterType="com.bonus.canteen.core.basic.domain.BasicCanteen" resultMap="BasicCanteenResult">
<include refid="selectBasicCanteenVo"/>
where bc.canteen_name = #{canteenName} and bc.area_id = #{areaId} and bc.del_flag = 0
where bc.canteen_name = #{canteenName} and bc.area_id = #{areaId} and bc.del_flag = '0'
</select>
<select id="getBasicCanteenCountByAreaIds" resultType="Integer">
select count(1)
from basic_canteen
where del_flag = 0 and area_id in
where del_flag = '0' and area_id in
<foreach item="areaId" collection="array" open="(" separator="," close=")">
#{areaId}
</foreach>

View File

@ -42,7 +42,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasicStallList" parameterType="com.bonus.canteen.core.basic.domain.BasicStall" resultMap="BasicStallResult">
<include refid="selectBasicStallVo"/>
<where>
<where>
bs.del_flag = '0'
<if test="stallName != null and stallName != ''"> and bs.stall_name like concat('%', #{stallName}, '%')</if>
<if test="areaId != null "> and bs.area_id = #{areaId}</if>
<if test="canteenId != null "> and bs.canteen_id = #{canteenId}</if>
@ -65,12 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectBasicStallByStallId" parameterType="Long" resultMap="BasicStallResult">
<include refid="selectBasicStallVo"/>
where bs.stall_id = #{stallId} and bs.del_flag = 0
where bs.stall_id = #{stallId} and bs.del_flag = '0'
</select>
<select id="selectBasicStallByStallName" parameterType="com.bonus.canteen.core.basic.domain.BasicStall" resultMap="BasicStallResult">
<include refid="selectBasicStallVo"/>
where bs.stall_name = #{stallName} and bs.canteen_id = #{canteenId} and bs.del_flag = 0
where bs.stall_name = #{stallName} and bs.canteen_id = #{canteenId} and bs.del_flag = '0'
</select>
<select id="selectBasicStallCountByCanteenIds" resultType="Integer">

View File

@ -62,7 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectCookRecipeList" parameterType="com.bonus.canteen.core.cook.domain.CookRecipe" resultMap="CookRecipeResult">
<include refid="selectCookRecipeVo"/>
<where>
cr.del_flag = 0
ba.del_flag = '0' and bc.del_flag = '0' and bs.del_flag = '0' and cr.del_flag = '0'
<if test="recipeName != null and recipeName != ''"> and cr.recipe_name like concat('%', #{recipeName}, '%')</if>
<if test="recipeType != null "> and cr.recipe_type = #{recipeType}</if>
<if test="stallId != null "> and cr.stall_id = #{stallId}</if>
@ -79,7 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectCookRecipeVo"/>
<where>
<if test="recipeIds !=null and recipeIds.size()>0">
AND recipe_id in
AND cr.recipe_id in
<foreach collection="recipeIds" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
@ -237,12 +237,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectCookRecipeByRecipeId" parameterType="Long" resultMap="CookRecipeResult">
<include refid="selectCookRecipeVo"/>
where cr.recipe_id = #{recipeId} and cr.del_flag = 0
where cr.recipe_id = #{recipeId} and ba.del_flag = '0' and bc.del_flag = '0' and bs.del_flag = '0' and cr.del_flag = '0'
</select>
<select id="selectCookRecipeByRecipeName" parameterType="String" resultMap="CookRecipeResult">
<include refid="selectCookRecipeVo"/>
where cr.recipe_name = #{recipeName} and cr.del_flag = 0
where cr.recipe_name = #{recipeName} and ba.del_flag = '0' and bc.del_flag = '0' and bs.del_flag = '0' and cr.del_flag = '0'
</select>
<insert id="insertCookRecipe" parameterType="com.bonus.canteen.core.cook.domain.CookRecipe" useGeneratedKeys="true" keyProperty="recipeId">
@ -382,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'
<if test="recipeName !=null and recipeName !=''">
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}
)
</if>