package cn.newfeifan.mall.module.distri.dal.mysql.partitioncrash;


import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
import cn.newfeifan.mall.module.distri.dal.dataobject.partitioncrash.PartitionCrashDO;
import cn.newfeifan.mall.module.distri.tools.LocalDateTimeTool;
import org.apache.ibatis.annotations.Mapper;
import cn.newfeifan.mall.module.distri.controller.admin.partitioncrash.vo.*;

/**
 * 分区碰撞 Mapper
 *
 * @author 非繁人
 */
@Mapper
public interface PartitionCrashMapper extends BaseMapperX<PartitionCrashDO> {


    default PageResult<PartitionCrashDO> selectPage(PartitionCrashPageReqVO reqVO) {
        LambdaQueryWrapperX<PartitionCrashDO> queryWrapper = new LambdaQueryWrapperX<PartitionCrashDO>()
                .eqIfPresent(PartitionCrashDO::getUserId, reqVO.getUserId())
                .eqIfPresent(PartitionCrashDO::getPartNo, reqVO.getPartNo())
                .eqIfPresent(PartitionCrashDO::getBrotherPrice, reqVO.getBrotherPrice())
                .eqIfPresent(PartitionCrashDO::getSonPrice, reqVO.getSonPrice())
                .eqIfPresent(PartitionCrashDO::getAfterHitQuota, reqVO.getAfterHitQuota())
                .betweenIfPresent(PartitionCrashDO::getCreateTime, LocalDateTimeTool.startTime(reqVO.getEveryday()), LocalDateTimeTool.endTime(reqVO.getEveryday()))
                .likeIfPresent(PartitionCrashDO::getUserName, reqVO.getUserName())
                .likeIfPresent(PartitionCrashDO::getNickName, reqVO.getNickName())
                .orderByDesc(PartitionCrashDO::getBrotherPrice)
                .orderByDesc(PartitionCrashDO::getSonPrice);
        if (reqVO.getIsSelectCrash() != null && reqVO.getIsSelectCrash()) {
            queryWrapper.ne(PartitionCrashDO::getBrotherPrice, 0);
            queryWrapper.ne(PartitionCrashDO::getSonPrice, 0);
        }
        return selectPage(reqVO, queryWrapper);
    }

}