package cn.iocoder.yudao.module.member.dal.mysql.order;

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.member.controller.admin.order.vo.OrderDetailsReqVO;
import cn.iocoder.yudao.module.member.controller.app.order.vo.AppOrderPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * 会员订单 Mapper
 *
 * @author 开发账号
 */
@Mapper
public interface DishOrderMapper extends BaseMapperX<DishOrderDO> {

    default PageResult<DishOrderDO> selectPage(AppOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DishOrderDO>()
                .eqIfPresent(DishOrderDO::getStoreId, reqVO.getStoreId())
                .likeIfPresent(DishOrderDO::getStoreName, reqVO.getStoreName())
                .eqIfPresent(DishOrderDO::getOrderStatus, reqVO.getOrderStatus())
                .eqIfPresent(DishOrderDO::getTotalMoney, reqVO.getTotalMoney())
                .betweenIfPresent(DishOrderDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(DishOrderDO::getUserId, reqVO.getUserId())
                .orderByDesc(DishOrderDO::getId));
    }
  default PageResult<DishOrderDO> selectPageList(OrderDetailsReqVO reqVO, List<Long> userIds, LocalDateTime startTime, LocalDateTime endTime) {
    return selectPage(  reqVO, new LambdaQueryWrapperX<DishOrderDO>()
              .eqIfPresent(DishOrderDO::getStoreId, reqVO.getStoreId())
              .betweenIfPresent(DishOrderDO::getCreateTime, reqVO.getStartDate(), reqVO.getEndDate())
              .eqIfPresent(DishOrderDO::getOrderStatus, reqVO.getOrderStatus())
              .inIfPresent(DishOrderDO::getUserId, userIds)
              .eqIfPresent(DishOrderDO::getId, reqVO.getOrderId())
              .betweenIfPresent(DishOrderDO::getTotalMoney, reqVO.getMinAmount(), reqVO.getMaxAmount())
              .betweenIfPresent(DishOrderDO::getCreateTime, startTime, endTime)
              .eqIfPresent(DishOrderDO::getPayMethods, reqVO.getPayMethods())
              .eqIfPresent(DishOrderDO::getDiningPlatesNum,reqVO.getDiningPlatesNum())
              .orderByDesc(DishOrderDO::getId));
  }


  Integer selectUser(@Param("time")Long storeId,@Param("storeId")String time);

  BigDecimal getSaleMoney(@Param("storeId")Long storeId, @Param("time")String time);
  Integer updateByIdBillingExist(@Param("ids")Set<Long> ids,@Param("exist")Boolean exist);
  Integer updateByIdBillingNum(@Param("ids")Set<Long> ids,@Param("num")String num);
}