package cn.iocoder.yudao.module.system.service.restaurant;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.excel.DishesOrderStatisticsExcelVO;
import cn.iocoder.yudao.module.system.controller.admin.restaurant.enums.UserType;
import cn.iocoder.yudao.module.system.controller.admin.restaurant.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.DailyExpensesDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyInfoDO;
import cn.iocoder.yudao.module.system.dal.dataobject.restaurant.*;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.biz.DailyExpensesMapper;
import cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyInfoMapper;
import cn.iocoder.yudao.module.system.dal.mysql.restaurant.*;
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
import cn.iocoder.yudao.module.system.enums.common.BooleanEnum;
import cn.iocoder.yudao.module.system.service.biz.BuildService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 长者点餐统计 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class DishesOrderStatisticsServiceImpl implements DishesOrderStatisticsService {

    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

    @Resource
    private DishesOrderStatisticsMapper dishesOrderStatisticsMapper;

    @Resource
    private DishesOrderItemMapper dishesOrderItemMapper;

    @Resource
    private DishOrderReportDetailMapper dishOrderReportDetailMapper;

    @Resource
    private ElderlyInfoMapper elderlyInfoMapper;
    @Resource
    private DailyExpensesMapper dailyExpensesMapper;

    @Resource
    private BuildService buildService;

    @Resource
    private DishesMapper dishesMapper;

    @Resource
    private RestaurantManagementMapper restaurantManagementMapper;
    @Resource
    private DishesOrderReportTimeslotMapper dishesOrderReportTimeslotMapper;

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Resource
    private AdminUserMapper adminUserMapper;


    @Override
    public void createDishesOrderStatistics(DishesOrderStatisticsSaveReqVO createReqVO) {
        List<DishesOrderItemDO> items = createReqVO.getItems();
        DishesOrderStatisticsDO dishesOrderStatistics = new DishesOrderStatisticsDO();
        BeanUtils.copyProperties(createReqVO, dishesOrderStatistics);
        dishesOrderStatistics.setCreatedBy(SecurityFrameworkUtils.getLoginUserNickname());
        dishesOrderStatistics.setCreatedTime(new Date());
        dishesOrderStatistics.setMonth(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM")));
        dishesOrderStatistics.setCount(items.size());
        if(StringUtils.isBlank(createReqVO.getSubmitterName())){
            dishesOrderStatistics.setSubmitterName(dishesOrderStatistics.getCreatedBy());
        }
        dishesOrderStatisticsMapper.insert(dishesOrderStatistics);

        List<String> stringList = new ArrayList<>();
        BigDecimal totalAmount = BigDecimal.ZERO;
        for (DishesOrderItemDO item : items) {
            item.setOrderStatisticsId(dishesOrderStatistics.getId());
            item.setElderId(dishesOrderStatistics.getElderId());
            item.setOrderTime(new Date());
            dishesOrderItemMapper.insert(item);
            totalAmount = totalAmount.add(item.getAmount());

            stringList.add(item.getFoodName() + item.getAmount() + "元");
        }
        dishesOrderStatistics.setTotalAmount(totalAmount);
        dishesOrderStatisticsMapper.updateById(dishesOrderStatistics);

        //组装备注
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < stringList.size(); i++) {
            sb.append("菜品名称:").append(stringList.get(i));
            if (i < stringList.size() - 1) {
                sb.append(",");
            }
        }
        //生成日常费用
        DailyExpensesDO dailyExpenses = new DailyExpensesDO();
        dailyExpenses.setType(4); // 4：额外
        dailyExpenses.setElderId(createReqVO.getElderId());
        dailyExpenses.setAttributionBillTime(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM")));
        dailyExpenses.setItemId(dishesOrderStatistics.getId());  //大单ID
        dailyExpenses.setItemCategory("额外费用/点餐");
        dailyExpenses.setItemName("点餐");
        dailyExpenses.setPrice(dishesOrderStatistics.getTotalAmount());
        dailyExpenses.setAmount(dishesOrderStatistics.getTotalAmount());
        dailyExpenses.setRoundAmount(dailyExpenses.getAmount().setScale(0, RoundingMode.HALF_UP));
        dailyExpenses.setRemarks("长者额外点餐：" + sb);
        dailyExpenses.setCount(1);
        dailyExpenses.setCreatedTime(new Date());
        dailyExpenses.setAccountingTime(new Date());
        dailyExpenses.setIsGenerateBill(BooleanEnum.FALSE.getValue());
        dailyExpensesMapper.insert(dailyExpenses);

    }

    @Override
    public void deleteDishesOrderStatistics(Long[] ids) {
        for (Long id : ids) {
            dishesOrderItemMapper.delete(new LambdaQueryWrapperX<DishesOrderItemDO>()
                    .eq(DishesOrderItemDO::getOrderStatisticsId, id));

            dishesOrderStatisticsMapper.deleteById(id);

            //删除日常费用
            dailyExpensesMapper.delete(new LambdaQueryWrapperX<DailyExpensesDO>().eq(DailyExpensesDO::getItemId, id));
        }
    }

    @Override
    public DishesOrderStatisticsRespVO getDishesOrderStatistics(Long id) {
        DishesOrderStatisticsDO dishesOrderStatisticsDO = dishesOrderStatisticsMapper.selectById(id);
        List<DishesOrderItemDO> dishesOrderItems = dishesOrderItemMapper.selectList(new LambdaQueryWrapperX<DishesOrderItemDO>()
                .eq(DishesOrderItemDO::getOrderStatisticsId, id));
        // TODO 临时方案增加菜品名称，后续删除
        dishesOrderItems = dishesOrderItems.stream().map(item -> {
            item.setFoodName(dishesMapper.selectOne(new LambdaQueryWrapperX<DishesDO>().eq(DishesDO::getId, item.getFoodId())).getFoodName());
            return item;
        }).collect(Collectors.toList());
        DishesOrderStatisticsRespVO respVO = new DishesOrderStatisticsRespVO();
        BeanUtils.copyProperties(dishesOrderStatisticsDO, respVO);
        respVO.setBedName(buildService.getFullBedName(respVO.getElderId()));
        respVO.setItems(dishesOrderItems);
        return respVO;
    }

    @Override
    public void updateDishesOrderStatistics(DishesOrderStatisticsSaveReqVO updateReqVO) {
        DishesOrderStatisticsDO dishesOrderStatistics = dishesOrderStatisticsMapper.selectById(updateReqVO.getId());
        BeanUtils.copyProperties(updateReqVO, dishesOrderStatistics);
        dishesOrderStatistics.setCount(updateReqVO.getItems().size());

        //先删除在添加
        dishesOrderItemMapper.delete(new LambdaQueryWrapperX<DishesOrderItemDO>()
                .eq(DishesOrderItemDO::getOrderStatisticsId, updateReqVO.getId()));

        List<DishesOrderItemDO> items = updateReqVO.getItems();


        BigDecimal totalAmount = BigDecimal.ZERO;
        for (DishesOrderItemDO item : items) {
            item.setOrderStatisticsId(dishesOrderStatistics.getId());
            item.setElderId(dishesOrderStatistics.getElderId());
            item.setOrderTime(new Date());
            dishesOrderItemMapper.insert(item);
            totalAmount = totalAmount.add(item.getAmount());
        }
        dishesOrderStatistics.setTotalAmount(totalAmount);
        dishesOrderStatisticsMapper.updateById(dishesOrderStatistics);
    }

    @Override
    public PageResult<DishesOrderStatisticsDO> getDishesOrderStatisticsPage(DishesOrderStatisticsPageReqVO pageReqVO) {
        Page<DishesOrderStatisticsDO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
        Page<DishesOrderStatisticsDO> resultPage = dishesOrderStatisticsMapper.getDishesOrderStatisticsPage(page,pageReqVO);
        return new PageResult<>(resultPage.getRecords(), resultPage.getTotal());
    }

    @Override
    public PageResult<DishesOrderExportVO> exportDishesOrderStatisticsPage(DishesOrderStatisticsPageReqVO pageReqVO) {
        Page<DishesOrderExportVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
        Page<DishesOrderExportVO> resultPage = dishesOrderStatisticsMapper.getDishesOrderExportPage(page, pageReqVO);
        List<DishesOrderExportVO> records = resultPage.getRecords();
        if (CollectionUtil.isNotEmpty(records)) {
            Long tenantId = pageReqVO.getTenantId() != null ? pageReqVO.getTenantId() : TenantContextHolder.getTenantId();
            Map<String, Boolean> employeeSubmitterMap = new HashMap<>();
            if (tenantId != null) {
                List<AdminUserDO> adminUsers = adminUserMapper.getUserListByTenantId(tenantId);
                employeeSubmitterMap = adminUsers.stream()
                        .map(AdminUserDO::getNickname)
                        .filter(StringUtils::isNotBlank)
                        .collect(Collectors.toMap(name -> name, name -> true, (a, b) -> a));
            }
            Map<String, Boolean> finalEmployeeSubmitterMap = employeeSubmitterMap;
            records.forEach(item -> {
                if (item.getUserType() == UserType.ELDER) {
                    if (Boolean.TRUE.equals(finalEmployeeSubmitterMap.get(item.getSubmitterName()))) {
                        item.setType("员工代点");
                    } else if (StringUtils.equals(item.getSubmitterName(), item.getElderName())) {
                        item.setType("长者自点");
                    } else {
                        item.setType("家属点餐");
                    }
                }
            });
        }
        return new PageResult<>(records, resultPage.getTotal());
    }

    @Override
    public List<DishesOrderExportVO> exportDishesOrderItemExcel(Long id) {
//        List<DishesOrderItemDO> dishesOrderItems = dishesOrderItemMapper.selectList(new LambdaQueryWrapperX<DishesOrderItemDO>().eq(DishesOrderItemDO::getOrderStatisticsId, id));
//        for (DishesOrderItemDO dishesOrderItem : dishesOrderItems) {
//            DishesOrderItemExcelVO excelVO = new DishesOrderItemExcelVO();
//            BeanUtils.copyProperties(dishesOrderItem, excelVO);
//            ElderlyInfoDO elderlyInfo = elderlyInfoMapper.selectById(dishesOrderItem.getElderId());
//            excelVO.setElderName(elderlyInfo.getElderName());
//        }
//        return dishesOrderItems.stream().map(e -> {
//            DishesOrderItemExcelVO excelVO = new DishesOrderItemExcelVO();
//            BeanUtils.copyProperties(e, excelVO);
//            ElderlyInfoDO elderlyInfo = elderlyInfoMapper.selectById(e.getElderId());
//            excelVO.setElderName(elderlyInfo.getElderName());
//            return excelVO;
//        }).collect(Collectors.toList());
        DishesOrderStatisticsPageReqVO pageReqVO = new DishesOrderStatisticsPageReqVO();
        pageReqVO.setId(id);
        List<DishesOrderExportVO> exportList = dishesOrderStatisticsMapper.getDishesOrderExportList(pageReqVO);
        // 处理床位号
        for (DishesOrderExportVO item : exportList) {
            // 获取床位号
            String bedName = buildService.getFullBedName(item.getElderId());
            item.setBedNumber(bedName);
        }
        return exportList;
    }

    @Override
    public void cancel(Long id) {
        DishesOrderStatisticsDO dishesOrderStatistics = dishesOrderStatisticsMapper.selectById(id);
        dishesOrderStatistics.setStatus(2);
        dishesOrderStatisticsMapper.updateById(dishesOrderStatistics);
        //删除日常费用
        dailyExpensesMapper.delete(new LambdaQueryWrapperX<DailyExpensesDO>()
                .eq(DailyExpensesDO::getItemId, id));
    }

    @Override
    public PageResult<EmployeeDishesOrderReportVO> getEmployeeDishesOrderReportPage(EmployeeDishesOrderReportPageReqVO pageReqVO) {
        // 处理 mealTimes 参数（将字符串转换为List）
        if (StringUtils.isNotBlank(pageReqVO.getMealTimes())) {
            String mealTimes = pageReqVO.getMealTimes()
                    .replace("[", "")
                    .replace("]", "")
                    .replace("\"", "");
            pageReqVO.setMealTimesList(Arrays.asList(mealTimes.split(",")));
        }
        // 第一步：创建分页对象，查询主表数据（不包含子表数据）
        Page<EmployeeDishesOrderReportVO> page = new Page<>(
                pageReqVO.getPageNo(),
                pageReqVO.getPageSize()
        );
        IPage<EmployeeDishesOrderReportVO> mainPage = dishesOrderStatisticsMapper.selectMainPage(page, pageReqVO);
        // 如果没有数据，直接返回空结果
        if (mainPage.getRecords() == null || mainPage.getRecords().isEmpty()) {
            return new PageResult<>(Collections.emptyList(), 0L);
        }
        // 获取主表ID列表
        List<Long> mainIds = mainPage.getRecords().stream()
                .map(EmployeeDishesOrderReportVO::getId)
                .collect(Collectors.toList());
        // 第二步：根据主表ID列表批量查询子表数据
        List<DishesOrderReportDetail> details = dishesOrderStatisticsMapper.selectDetailsByMainIds(mainIds, pageReqVO);
        // 将子表数据按主表ID分组
        Map<Long, List<DishesOrderReportDetail>> detailMap = details.stream()
                .collect(Collectors.groupingBy(DishesOrderReportDetail::getOrderId));
        // 第三步：组装数据
        mainPage.getRecords().forEach(vo -> {
            // 设置子表数据
            List<DishesOrderReportDetail> detailList = detailMap.get(vo.getId());
            if (detailList != null) {
                vo.setDishesOrderReportDetailList(detailList);
            } else {
                vo.setDishesOrderReportDetailList(Collections.emptyList());
            }
            // 格式化日期
            if (vo.getCreatedTime() != null) {
                vo.setCreatedTimeFormat(formatter.format(vo.getCreatedTime()));
            }
            if (vo.getMealDate() != null) {
                vo.setMealDateFormat(formatter.format(vo.getMealDate()));
            }
        });

        return new PageResult<>(mainPage.getRecords(), mainPage.getTotal());
    }
    @Override
    public Map<String,Object> importDailyExpensesExcel(List<DishesOrderStatisticsExcelVO> list){
        Set<String> absentRestaurantSet = new HashSet<>();
        Set<String> absentFoodSet = new HashSet<>();
        Map<String,List<DishesOrderItemDO>> elderMonthOrderMap = new HashMap<>();
        Long tenantId = TenantContextHolder.getTenantId();
        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
        StringBuilder errorMsg = new StringBuilder();
        for (DishesOrderStatisticsExcelVO excelItem : list) {
            YearMonth yearMonth = YearMonth.from(excelItem.getOrderDate());
            String key = excelItem.getIdCard()+"::" + excelItem.getRestaurantName() + "::" + yearMonth;
            List<DishesOrderItemDO> dishesOrderItemDOS = elderMonthOrderMap.computeIfAbsent(key, k -> new ArrayList<>());
            DishesOrderItemDO dishesOrderItemDO = new DishesOrderItemDO();
            dishesOrderItemDO.setFoodName(excelItem.getFoodName());
            dishesOrderItemDO.setPrice(excelItem.getPrice());
            dishesOrderItemDO.setCount(excelItem.getNum());
            dishesOrderItemDO.setAmount(dishesOrderItemDO.getPrice().multiply(new BigDecimal(dishesOrderItemDO.getCount())));
            dishesOrderItemDO.setOrderTime(Date.from(excelItem.getOrderDate().atStartOfDay(ZoneId.systemDefault()).toInstant()));
            List<DishesDO> dishesDOList = dishesMapper.selectList(new LambdaQueryWrapperX<DishesDO>()
                    .eq(DishesDO::getFoodName, excelItem.getFoodName())
                    .eq(DishesDO::getTenantId, tenantId)
                    .eq(DishesDO::getRestaurantName, excelItem.getRestaurantName())
                    .eq(DishesDO::getPrice, excelItem.getPrice()));
            if(CollectionUtil.isEmpty(dishesDOList)){
                String absentValue = excelItem.getRestaurantName() + excelItem.getPrice() + excelItem.getFoodName();
                if(!absentFoodSet.contains(absentValue)){
                    absentFoodSet.add(absentValue);
                    errorMsg.append("餐厅名称：").append(excelItem.getRestaurantName())
                            .append("，单价：").append(excelItem.getPrice()).append("，菜品名称：")
                            .append(excelItem.getFoodName()).append(",不存在请检查！。\n");
                }
                continue;
            }
            dishesOrderItemDO.setFoodId(dishesDOList.get(0).getId());
            dishesOrderItemDOS.add(dishesOrderItemDO);
        }
        for (Map.Entry<String, List<DishesOrderItemDO>> entry : elderMonthOrderMap.entrySet()) {
            String[] split = entry.getKey().split("::");
            List<DishesOrderItemDO> dishesOrderItemDOList = entry.getValue();
            String idCard = split[0];
            String restaurantName = split[1];
            String yearMonth = split[2];
            List<RestaurantManagementDO> restaurantManagementDOList = restaurantManagementMapper.selectList(new LambdaQueryWrapperX<RestaurantManagementDO>()
                    .eq(RestaurantManagementDO::getTenantId, tenantId)
                    .eq(RestaurantManagementDO::getRestaurantName, restaurantName)
                    .orderByDesc(RestaurantManagementDO::getCreatedTime));
            if(CollectionUtil.isEmpty(restaurantManagementDOList)){
                if(!absentRestaurantSet.contains(restaurantName)){
                    absentRestaurantSet.add(restaurantName);
                    errorMsg.append("餐厅名称:").append(restaurantName).append(",不存在请检查！。\n");
                }
                continue;
            }
            List<ElderlyInfoDO> elderlyInfoDOList = elderlyInfoMapper.selectList(new LambdaQueryWrapperX<ElderlyInfoDO>()
                    .eq(ElderlyInfoDO::getIdCard, idCard)
                    .eq(ElderlyInfoDO::getTenantId, tenantId)
                    .orderByDesc(ElderlyInfoDO::getCreateTime));
            if(CollectionUtil.isEmpty(elderlyInfoDOList)){
                errorMsg.append("身份证:").append(idCard).append(",的长者不存在请检查！。\n");
                continue;
            }
            DishesOrderStatisticsDO dishesOrderStatisticsDO = new DishesOrderStatisticsDO();
            ElderlyInfoDO elderlyInfoDO = elderlyInfoDOList.get(0);
            RestaurantManagementDO restaurantManagementDO = restaurantManagementDOList.get(0);
            dishesOrderStatisticsDO.setUserType(UserType.ELDER);
            dishesOrderStatisticsDO.setSubmitterName(userNickname);
            dishesOrderStatisticsDO.setElderId(elderlyInfoDO.getId());
            dishesOrderStatisticsDO.setElderName(elderlyInfoDO.getElderName());
            dishesOrderStatisticsDO.setRestaurantId(restaurantManagementDO.getId());
            dishesOrderStatisticsDO.setRestaurantName(restaurantManagementDO.getRestaurantName());
            dishesOrderStatisticsDO.setMonth(yearMonth);
            dishesOrderStatisticsDO.setCount(dishesOrderItemDOList.size());
            dishesOrderStatisticsMapper.insert(dishesOrderStatisticsDO);
            BigDecimal totalAmount = BigDecimal.ZERO;
            for (DishesOrderItemDO dishesOrderItemDO : dishesOrderItemDOList) {
                dishesOrderStatisticsDO.setOrderDate(dishesOrderItemDO.getOrderTime());
                dishesOrderItemDO.setOrderStatisticsId(dishesOrderStatisticsDO.getId());
                dishesOrderItemDO.setElderId(elderlyInfoDO.getId());
                dishesOrderItemDO.setTenantId(tenantId);
                totalAmount = totalAmount.add(dishesOrderItemDO.getAmount());
            }
            dishesOrderStatisticsDO.setTotalAmount(totalAmount);
            dishesOrderStatisticsDO.setCreatedTime(new Date());
            DailyExpensesDO dailyExpensesDO = new DailyExpensesDO();
            dailyExpensesDO.setElderId(dishesOrderStatisticsDO.getElderId());
            dailyExpensesDO.setElderName(dishesOrderStatisticsDO.getElderName());
            dailyExpensesDO.setItemId(dishesOrderStatisticsDO.getId());
            dailyExpensesDO.setItemName("点餐");
            dailyExpensesDO.setItemCategory("点餐");
            // 点餐
            dailyExpensesDO.setType(7);
            dailyExpensesDO.setPrice(dishesOrderStatisticsDO.getTotalAmount());
            dailyExpensesDO.setPrice(dishesOrderStatisticsDO.getTotalAmount());
            dailyExpensesDO.setRoundAmount(dishesOrderStatisticsDO.getTotalAmount().round(new MathContext(0,RoundingMode.HALF_UP)));
            dailyExpensesDO.setRoundTwoDecimalAmount(dishesOrderStatisticsDO.getTotalAmount().round(new MathContext(2,RoundingMode.HALF_UP)));
            dailyExpensesDO.setCount(1);
            dailyExpensesDO.setStatus(0);
            dailyExpensesDO.setCreatedBy(userNickname);
            dailyExpensesDO.setCreatedTime(new Date());
            dailyExpensesDO.setAccountingTime(new Date());
            dailyExpensesDO.setIsGenerateBill(0);
            dailyExpensesDO.setAttributionBillTime(dishesOrderStatisticsDO.getMonth());
            dailyExpensesMapper.insert(dailyExpensesDO);
            dishesOrderStatisticsMapper.updateById(dishesOrderStatisticsDO);
            dishesOrderItemMapper.insertBatch(dishesOrderItemDOList);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("errorMsg", errorMsg.toString());
        return result;
    }

    public void createReportTimeslot(List<DishesOrderReportTimeslotDO> dishesOrderReportTimeslotList){
        Long tenantId = TenantContextHolder.getTenantId();
        for (DishesOrderReportTimeslotDO dishesOrderReportTimeslotDO : dishesOrderReportTimeslotList) {
            List<DishesOrderReportTimeslotDO> dishesOrderReportTimeslotDOS = dishesOrderReportTimeslotMapper.selectList(new LambdaQueryWrapperX<DishesOrderReportTimeslotDO>()
                    .eq(DishesOrderReportTimeslotDO::getTenantId, tenantId)
                    .eq(DishesOrderReportTimeslotDO::getMealName, dishesOrderReportTimeslotDO.getMealName()));
            if(CollectionUtil.isNotEmpty(dishesOrderReportTimeslotDOS)){
                continue;
            }
            dishesOrderReportTimeslotDO.setTenantId(tenantId);
            dishesOrderReportTimeslotMapper.insert(dishesOrderReportTimeslotDO);
        }
        redisTemplate.delete("meal_timeslot_config:" + tenantId);
    }
    public List<DishesOrderReportTimeslotDO> getReportTimeslot(Long tenantId){
        return dishesOrderReportTimeslotMapper.selectList(new LambdaQueryWrapperX<DishesOrderReportTimeslotDO>().eq(DishesOrderReportTimeslotDO::getTenantId,tenantId));
    }

    public void updateReportTimeslot(List<DishesOrderReportTimeslotDO> dishesOrderReportTimeslotList){
        Long tenantId = TenantContextHolder.getTenantId();
        dishesOrderReportTimeslotMapper.updateBatch(dishesOrderReportTimeslotList);
        redisTemplate.delete("meal_timeslot_config:" + tenantId);
    }
}