package cn.iocoder.yudao.module.system.dal.mysql.dishestype;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.dishestype.vo.DishesTypePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dishestype.DishesTypeDO;
import cn.iocoder.yudao.module.system.dal.dataobject.orderdetail.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 菜品分类 Mapper
 *
 * @author 开发账号
 */
@Mapper
public interface DishesTypeMapper extends BaseMapperX<DishesTypeDO> {

    default PageResult<DishesTypeDO> selectPage(DishesTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DishesTypeDO>()
                .likeIfPresent(DishesTypeDO::getDishesTypeName, reqVO.getDishesTypeName())
                .eqIfPresent(DishesTypeDO::getCarteenId,reqVO.getCarteenId())
                .betweenIfPresent(DishesTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DishesTypeDO::getId));
    }
    @Select("<script>"+"SELECT a.dishes_name AS dishesName,a.id,b.dishes_type_name AS dishUrl,c.create_time as createTime FROM t_dishes AS a INNER JOIN t_dishes_type AS b ON a.dishec_type = b.id INNER JOIN member_order_detail AS c ON c.dishes_id = a.id  where  c.deleted=0 and a.deleted=0 and b.deleted=0 and c.order_id in "+"<foreach collection='ids' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> "+ "</script>")
    List<OrderDetail> selectByIdAmdTypeName(@Param("ids") List<Long> ids);
    @Select("select id from member_dish_order where deleted=0 and store_id = #{carteenId} and create_time between #{startTime} and #{endTime}")
    List<Long> selectOrderIds(@Param("carteenId")Long carteenId,
                              @Param("startTime")LocalDateTime startTime,
                              @Param("endTime")LocalDateTime endTime);
}