package com.bonus.canteen.core.cook.service.impl;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.common.utils.DateUtil;
import com.bonus.canteen.core.common.utils.MqUtil;
import com.bonus.canteen.core.cook.domain.CookAppRecipe;
import com.bonus.canteen.core.cook.domain.CookRecipeDetail;
import com.bonus.canteen.core.cook.domain.CookRecipeDishes;
import com.bonus.canteen.core.cook.dto.*;
import com.bonus.canteen.core.cook.enums.CookRecipeSortEnum;
import com.bonus.canteen.core.cook.enums.RecipeDetailTypeEnum;
import com.bonus.canteen.core.cook.enums.RecipeTypeEnum;
import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper;
import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper;
import com.bonus.canteen.core.cook.vo.*;
import com.bonus.canteen.core.user.domain.DeviceMqPersonalUpdateMessageDTO;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.houqin.constant.GlobalConstants;
import com.bonus.common.houqin.mq.constant.LeMqConstant;
import com.bonus.common.houqin.utils.LeBeanUtil;
import com.bonus.common.security.utils.SecurityUtils;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.cook.mapper.CookRecipeMapper;
import com.bonus.canteen.core.cook.domain.CookRecipe;
import com.bonus.canteen.core.cook.service.ICookRecipeService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * 菜品计划信息Service业务层处理
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Service
public class CookRecipeServiceImpl implements ICookRecipeService {
    @Autowired
    private CookRecipeMapper cookRecipeMapper;
    @Autowired
    private CookRecipeDetailMapper cookRecipeDetailMapper;
    @Autowired
    private CookRecipeDishesMapper cookRecipeDishesMapper;

    /**
     * 查询菜品计划信息
     * 
     * @param recipeId 菜品计划信息主键
     * @return 菜品计划信息
     */
    @Override
    public CookRecipe selectCookRecipeByRecipeId(Long recipeId) {
        return cookRecipeMapper.selectCookRecipeByRecipeId(recipeId);
    }

    /**
     * 查询菜品计划信息列表
     * 
     * @param cookRecipe 菜品计划信息
     * @return 菜品计划信息
     */
    @Override
    public List<CookRecipe> selectCookRecipeList(CookRecipe cookRecipe) {
        List<CookRecipe> list = cookRecipeMapper.selectCookRecipeList(cookRecipe);
//        for (CookRecipe recipe : list) {
//            if (1 == recipe.getRecipeType()) {
//                recipe.setDishesCount(cookRecipeMapper.getDishesCount4PointDates(recipe.getRecipeId()));
//            } else {
//                recipe.setDishesCount(cookRecipeMapper.getDishesCount4Recycle(recipe.getRecipeId()));
//            }
//        }
        List<LocalDate> lastWeekDate = DateUtil.getLastWeekDate();
        List<Long> recipeIds = list.stream().map(CookRecipe::getRecipeId).collect(Collectors.toList());
        List<CookRecipeDishesCountVO> dishesCountByRecipeIdsList = cookRecipeMapper.getDishesCountByRecipeIds(recipeIds);
        Map<Long, Integer> dishesCountByRecipeIds = dishesCountByRecipeIdsList.stream().collect(Collectors.toMap(CookRecipeDishesCountVO::getRecipeId, CookRecipeDishesCountVO::getCount));
        List<CookRecipeDetailVO> recipeDatesList = this.cookRecipeMapper.selectApplyDateListByRecipeId(LocalDate.now(), recipeIds);
        Map<Long, TreeSet<LocalDate>> recipeDates = recipeDatesList.stream().collect(Collectors.groupingBy(CookRecipeDetailVO::getRecipeId, Collectors.mapping(CookRecipeDetailVO::getApplyDate, Collectors.toCollection(TreeSet::new))));
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        list.forEach(r -> {
            Long recipeId = r.getRecipeId();
            r.setDishesCount(dishesCountByRecipeIds.getOrDefault(recipeId, 0));
            Set<LocalDate> applyDateList = recipeDates.getOrDefault(recipeId, new TreeSet<>());
            Object finalDate;
            if (ObjectUtil.equal(r.getRecipeType(), 3)) {
                Stream<LocalDate> localDateStream = lastWeekDate.stream();
                Objects.requireNonNull(applyDateList);
                finalDate = localDateStream.filter(applyDateList::contains).collect(Collectors.toList());
            } else if (ObjectUtil.equal(r.getRecipeType(), 2)) {
                finalDate = DateUtil.getLastWeek();
            } else {
                finalDate = new ArrayList<>(applyDateList);
            }
            List<String> applyDateStringList = Lists.newArrayList();
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd");
            ((List) finalDate).forEach(d -> {
                applyDateStringList.add(dateTimeFormatter.format((TemporalAccessor) d));
            });
            r.setApplyDateList((List) finalDate);
            r.setApplyDateStringList(applyDateStringList);
        });
        return list;
    }

    public List<CookRecipeVO> selectCookRecipeList4Current(CookRecipeDTO content) {
        Map<Integer, CookRecipeSortEnum> bindTypeMap = CookRecipeSortEnum.getKeyMap();
        CookRecipeSortEnum sortEnum = bindTypeMap.get(content.getKey());
        List<CookRecipeVO> records = new ArrayList<>();
        if (ObjectUtil.isEmpty(sortEnum)) {
            throw new ServiceException("参数错误");
        }else{
            content.setDeviceTypeList(sortEnum.getDeviceType());
            content.setBindType(sortEnum.getBindType());
            content.setRecipeName(LeBeanUtil.fieldLikeHandle(content.getRecipeName()));
            records = cookRecipeMapper.selectCookRecipeListV2(content);
            if (ObjectUtil.isNotEmpty(records)) {
                List<Long> recipeIds;
                Map<Long ,Long> maping;
                List<Long> stallIds = records.stream().map(CookRecipeVO::getStallId).collect(Collectors.toList());
                List<StallAndRecipeBindVO> 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<CookRecipeDetailVO> cookRecipeDetailVOs = this.cookRecipeMapper.selectTmpBetweenDateDetailList(recipeIds, content.getApplyDate(), content.getApplyDate());
                Map<Long, CookRecipe> recipeMap = (recipeIds == null || recipeIds.isEmpty())
                        ? new HashMap<>()
                        : this.cookRecipeMapper.selectRecipeListByRecipeIds(recipeIds)
                        .stream()
                        .collect(Collectors.toMap(CookRecipe::getRecipeId, Function.identity()));
                Map<Long, CookRecipeDetailVO> 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<CookRecipeVO> 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 (ObjectUtil.isNotEmpty(item.getRecipeDateDetail()) && ObjectUtil.isNotEmpty(item.getRecipeDateList().get(0).getDetailList())) {
                        count = item.getRecipeDateList().get(0).getDetailList().stream().filter((x) -> {
                            return ObjectUtil.isNotEmpty(x.getDishesList());
                        }).flatMap((x) -> {
                            return x.getDishesList().stream();
                        }).map(CookRecipeDishesVO::getDishesId).distinct().count();
                    }
                }
            }
        }
        return records;
    }

    @Override
    public List<CookRecipeDetailVO> getRecipeDetailByDate(CookRecipeDetailDTO dto) {
        List<CookRecipeDetailVO> menuRecipeDetails = cookRecipeMapper.selectRecipeDetailList(dto.getRecipeId(), dto.getApplyDate());
        return menuRecipeDetails.stream().sorted(Comparator.comparing(CookRecipeDetailVO::getMealtimeType)).collect(Collectors.toList());
    }

    @Override
    public List<CookRecipeDetailVO> getRecipeDetail(CookRecipeDetailDTO dto) {
        return cookRecipeMapper.getRecipeDetail(dto);
    }

    @Override
    public List<CookRecipeDetailVO> selectTemplateDetailList(CookRecipeDetailDTO dto) {
        return cookRecipeMapper.selectTemplateDetailList(dto);
    }

    /**
     * 新增菜品计划信息
     * 
     * @param cookRecipeDTO 菜品计划信息
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertCookRecipe(CookRecipeDTO cookRecipeDTO) {
        cookRecipeDTO.setCreateTime(DateUtils.getNowDate());
        cookRecipeDTO.setCreateBy(SecurityUtils.getUsername());
        try {
            CookRecipe cookRecipe = cookRecipeMapper.selectCookRecipeByRecipeName(cookRecipeDTO.getRecipeName());
            if (Objects.nonNull(cookRecipe)) {
                throw new ServiceException("该菜谱名称已存在，请重新输入");
            }
            int count = cookRecipeMapper.insertCookRecipe(cookRecipeDTO); //插入菜谱
            createRecipeDetails(cookRecipeDTO, true);
            return count;
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    private void createRecipeDetails(CookRecipeDTO cookRecipeDTO, boolean isCreate) {
        // 更新菜谱时，
        // 指定日期菜谱，删掉指定日期的菜谱
        // 循环菜谱，删掉模板数据 + 今日开始的详情数据
        if (!isCreate) {
            List<Long> cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds(cookRecipeDTO.getRecipeId());
            if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) {
                Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new);
                cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(cookRecipeDetailArray);
                cookRecipeDetailMapper.deleteCookRecipeDetailByRecipeDetailIds(cookRecipeDetailArray);
            }
        }
        // 插入指定日期、日循环摸板、周循环模板
        if (!CollectionUtils.isEmpty(cookRecipeDTO.getRecipeDateList())) {
            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())) { //指定日期，不插入空数据
                        continue;
                    }
                    insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO);
                }
            }
        }
        // 插入生成的日循环详情数据、周循环详情数据
        List<CookRecipeDateDTO> generatedRecipeDateList = generateCookRecipeDateList(cookRecipeDTO);
        if (!CollectionUtils.isEmpty(generatedRecipeDateList)) {
            for (CookRecipeDateDTO recipeDateDTO : generatedRecipeDateList) {
                List<CookRecipeDetailDTO> detailList = recipeDateDTO.getDetailList();
                for (CookRecipeDetailDTO detailDTO : detailList) {
                    insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO);
                }
            }
        }
    }

    private static List<CookRecipeDateDTO> generateCookRecipeDateList(CookRecipeDTO cookRecipeDTO) {
        List<CookRecipeDateDTO> recipeDateList = cookRecipeDTO.getRecipeDateList();
        if (CollectionUtils.isEmpty(recipeDateList)) {
            return null;
        }
        List<CookRecipeDateDTO> recipeDateListNew = new ArrayList<>();
        if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType()) && Objects.nonNull(recipeDateList.get(0))) {  //每日循环
            List<CookRecipeDetailDTO> recipeDetailList = recipeDateList.get(0).getDetailList();
            //新增详情
            LocalDate now = LocalDate.now();
            for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) {
                CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO();
                cookRecipeDateDTO.setDetailList(recipeDetailList);
                cookRecipeDateDTO.setApplyDate(now.plusDays(i));
                recipeDateListNew.add(cookRecipeDateDTO);
            }
        } else if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) {  //每周循环
            LocalDate now = LocalDate.now();
            HashMap<Integer, LocalDate> dateHashMap = new HashMap<>();
            for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) {
                LocalDate applyWeek = now.plusDays((long) i);
                dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek);
            }
            //新增详情
            Iterator<Map.Entry<Integer, LocalDate>> iterator = dateHashMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<Integer, LocalDate> entry = iterator.next();
                CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO();
                cookRecipeDateDTO.setApplyWeek(Long.valueOf(entry.getKey()));
                cookRecipeDateDTO.setApplyDate(entry.getValue());
                for (CookRecipeDateDTO recipeDateDTO : recipeDateList) {
                    if (Long.valueOf(entry.getKey()).equals(recipeDateDTO.getApplyWeek())) {
                        cookRecipeDateDTO.setDetailList(recipeDateDTO.getDetailList());
                    }
                }
                recipeDateListNew.add(cookRecipeDateDTO);
            }
        }
        return recipeDateListNew;
    }

    private void insertDetailAndDishes(CookRecipeDTO cookRecipeDTO, CookRecipeDateDTO recipeDateDTO, CookRecipeDetailDTO detailDTO) {
        CookRecipeDetail cookRecipeDetail = new CookRecipeDetail();
        cookRecipeDetail.setRecipeDetailId(detailDTO.getRecipeDetailId());
        cookRecipeDetail.setMealtimeType(detailDTO.getMealtimeType());
        cookRecipeDetail.setSaleTypeId(detailDTO.getSaleTypeId());
        cookRecipeDetail.setApplyDate(recipeDateDTO.getApplyDate());
        cookRecipeDetail.setApplyWeek(recipeDateDTO.getApplyWeek());
        cookRecipeDetail.setApplyMonth(detailDTO.getApplyMonth());
        cookRecipeDetail.setRecipeId(cookRecipeDTO.getRecipeId());
        cookRecipeDetail.setCreateBy(SecurityUtils.getUsername());
        cookRecipeDetail.setCreateTime(DateUtils.getNowDate());
        if (Objects.isNull(cookRecipeDetail.getApplyDate())) {
            cookRecipeDetail.setDetailType(RecipeDetailTypeEnum.TEMPLATE_DATA.key()); //模板数据
        } else {
            cookRecipeDetail.setDetailType(RecipeDetailTypeEnum.DETAIL_DATA.key()); //详情数据
        }
        cookRecipeDetailMapper.insertCookRecipeDetail(cookRecipeDetail); //插入菜谱之执行计划
        List<CookRecipeDishesDTO> dishesList = detailDTO.getDishesList();
        for (CookRecipeDishesDTO dishesDTO : dishesList) {
            CookRecipeDishes cookRecipeDishes = new CookRecipeDishes();
            BeanUtils.copyProperties(dishesDTO, cookRecipeDishes);
            cookRecipeDishes.setCreateTime(DateUtils.getNowDate());
            long supplyNum = Objects.isNull(cookRecipeDishes.getSupplyNum()) ? 0 : cookRecipeDishes.getSupplyNum();
            long saleNum = Objects.isNull(cookRecipeDishes.getSaleNum()) ? 0 : cookRecipeDishes.getSaleNum();
            cookRecipeDishes.setRemanentNum((int) (supplyNum - saleNum));
            cookRecipeDishes.setRecipeDetailId(cookRecipeDetail.getRecipeDetailId());
            cookRecipeDishesMapper.insertCookRecipeDishes(cookRecipeDishes);  //插入菜谱之菜品详情
        }
    }

    /**
     * 修改菜品计划信息
     * 
     * @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);
            createRecipeDetails(cookRecipeDTO, false);
            return count;
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO) {
        CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId());
        List<Integer> deviceInfoList = new ArrayList<>();
        List<String> deviceSnList = new ArrayList<>();
        if(cookRecipeDTO.getStallId() !=null){
            deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(cookRecipeDTO.getStallId()));
            if(deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0){
                throw new ServiceException("该食堂档口下没有设备信息");
            }
            deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList);
        }
        CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(cookRecipeDTO.getBindType());
        CookAppRecipe mar = new CookAppRecipe();
        mar.setRecipeId(cookRecipeDTO.getRecipeId());
        mar.setMealLineId(cookRecipeDTO.getMealLineId());
        mar.setBindType(cookRecipeDTO.getBindType());
        List<Integer> deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId()));
        if (ObjectUtil.isEmpty(sortEnum)) {
            throw new ServiceException("bingType值异常");
        } else {
            List<Integer> deviceTypes = sortEnum.getDeviceType();
            if (cookRecipeDTO.getHandleType().equals(1)) {
                boolean exists;
//                if (CookBindTypeEnum.RESERVE.key().equals(cookRecipeDTO.getBindType())) {
//                    exists = this.checkCanteenIfReserve(menuRecipe.getCanteenId(), menuRecipe.getStallId());
//                    if (!exists) {
//                        throw new ServiceException("不支持预订餐");
//                    }
//                }
                exists = this.cookRecipeMapper.checkIfAlreadyBind(mar);
                if (exists) {
                    throw new ServiceException("菜谱已被使用，请勿重复绑定");
                }
                List<Long> sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), cookRecipeDTO.getBindType(), cookRecipeDTO.getMealLineId());
                if (ObjectUtil.isNotEmpty(sourceRecipeList)) {
                    mar.setRecipeIds(sourceRecipeList);
                    this.cookRecipeMapper.deleteBind(mar);
                }
                CookAppRecipe appRecipe = new CookAppRecipe();
                appRecipe.setRecipeId(cookRecipeDTO.getRecipeId());
                appRecipe.setBindType(cookRecipeDTO.getBindType());
                appRecipe.setMealLineId(cookRecipeDTO.getMealLineId());
                appRecipe.setBindTime(LocalDateTime.now());
                this.cookRecipeMapper.insertBind(appRecipe);
                if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
                    this.cookRecipeMapper.updateRecipeByCanteenStallMeal(String.valueOf(cookRecipeDTO.getRecipeId()), String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()),deviceTypeList);
                }
                MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE);
            } else {
                mar.setRecipeIds(Collections.singletonList(mar.getRecipeId()));
                this.cookRecipeMapper.deleteBind(mar);
                if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
                    this.cookRecipeMapper.updateRecipeByCanteenStallMeal("-1",  String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList);
                }
            }
            //发送mq
            if (!CollectionUtils.isEmpty(deviceSnList)) {
                for (String deviceSn : deviceSnList) {
                    DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, cookRecipeDTO.getHandleType().equals(1) ? "update" : "del");
                    MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn);
                }
            }
        }
    }

    /**
     * 批量删除菜品计划信息
     * 
     * @param recipeIds 需要删除的菜品计划信息主键
     * @return 结果
     */
    @Override
    public int deleteCookRecipeByRecipeIds(Long[] recipeIds) {
        List<Long> cookRecipeDetailIds = cookRecipeDetailMapper.getAllCookRecipeDetailIds(recipeIds);
        Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new);
        cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(cookRecipeDetailArray);
        cookRecipeDetailMapper.deleteCookRecipeDetailByRecipeDetailIds(cookRecipeDetailArray);
        return cookRecipeMapper.deleteCookRecipeByRecipeIds(recipeIds);
    }

    /**
     * 删除菜品计划信息信息
     * 
     * @param recipeId 菜品计划信息主键
     * @return 结果
     */
    @Override
    public int deleteCookRecipeByRecipeId(Long recipeId) {
        return cookRecipeMapper.deleteCookRecipeByRecipeId(recipeId);
    }
}
