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

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.storebusiness.vo.StoreBusinessPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.storebusiness.StoreBusinessDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

/**
 * 超市营业统计 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface StoreBusinessMapper extends BaseMapperX<StoreBusinessDO> {

    default PageResult<StoreBusinessDO> selectPage(StoreBusinessPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StoreBusinessDO>()
                .eqIfPresent(StoreBusinessDO::getTurnover, reqVO.getTurnover())
                .eqIfPresent(StoreBusinessDO::getOrderSum, reqVO.getOrderSum())
                .eqIfPresent(StoreBusinessDO::getCustomerSum, reqVO.getCustomerSum())
                .eqIfPresent(StoreBusinessDO::getPriceAvg, reqVO.getPriceAvg())
                .eqIfPresent(StoreBusinessDO::getReduce, reqVO.getReduce())
                .eqIfPresent(StoreBusinessDO::getSubsidyPurse, reqVO.getSubsidyPurse())
                .eqIfPresent(StoreBusinessDO::getGratis, reqVO.getGratis())
                .eqIfPresent(StoreBusinessDO::getBreakfast, reqVO.getBreakfast())
                .eqIfPresent(StoreBusinessDO::getBreakfastNum, reqVO.getBreakfastNum())
                .eqIfPresent(StoreBusinessDO::getLunch, reqVO.getLunch())
                .eqIfPresent(StoreBusinessDO::getLunchNum, reqVO.getLunchNum())
                .eqIfPresent(StoreBusinessDO::getDinner, reqVO.getDinner())
                .eqIfPresent(StoreBusinessDO::getDinnerNum, reqVO.getDinnerNum())
                .eqIfPresent(StoreBusinessDO::getWeigh, reqVO.getWeigh())
                .betweenIfPresent(StoreBusinessDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(StoreBusinessDO::getCarteenId, reqVO.getCarteenId())
                .orderByDesc(StoreBusinessDO::getId));
    }


    @Select("select * from member_store_business where carteen_id = #{carteenId} and create_time between #{startOfDay} and #{endOfDay}  limit 1 for update")
    StoreBusinessDO getTodayBusiness(@Param("carteenId") Long carteenId, @Param("startOfDay") LocalDateTime startOfDay, @Param("endOfDay") LocalDateTime endOfDay);


}