package com.yc.ship.module.ota.dal.mysql.tradelog;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.ota.controller.admin.tradelog.vo.TradeLogPageReqVO;
import com.yc.ship.module.ota.dal.dataobject.tradelog.TradeLogDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 分销商交易日志 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface TradeLogMapper extends BaseMapperX<TradeLogDO> {

    default PageResult<TradeLogDO> selectPage(TradeLogPageReqVO reqVO) {
        LambdaQueryWrapperX<TradeLogDO> query = new LambdaQueryWrapperX<>();
        query.eqIfPresent(TradeLogDO::getOperatorId, reqVO.getOperatorId());
        query.likeIfPresent(TradeLogDO::getOperatorName, reqVO.getOperatorName());
        query.eqIfPresent(TradeLogDO::getTradeType, reqVO.getTradeType());
        query.betweenIfPresent(TradeLogDO::getTradeTime, reqVO.getTradeTime());
        query.eqIfPresent(TradeLogDO::getBeforeBalance, reqVO.getBeforeBalance());
        query.eqIfPresent(TradeLogDO::getAfterBalance, reqVO.getAfterBalance());
        query.eqIfPresent(TradeLogDO::getTradeAmount, reqVO.getTradeAmount());
        query.eqIfPresent(TradeLogDO::getTradeMode, reqVO.getTradeMode());
        query.eqIfPresent(TradeLogDO::getRemark, reqVO.getRemark());
        if (StringUtils.isNotBlank(reqVO.getOrderNo())) {
            // 根据订单查交易记录

        }
        query.eqIfPresent(TradeLogDO::getDistributorId, reqVO.getDistributorId());
        query.betweenIfPresent(TradeLogDO::getCreateTime, reqVO.getCreateTime());
        query.orderByDesc(TradeLogDO::getCreateTime);
        return selectPage(reqVO, query);
    }

    IPage<TradeLogDO> getTradeLogPage(IPage<TradeLogDO> page, @Param("pageReqVO") TradeLogPageReqVO pageReqVO);

}
