package com.yc.ship.module.otc.dal.mysql.storetradelog;

import com.baomidou.mybatisplus.core.metadata.IPage;
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.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.otc.controller.admin.storetradelog.vo.StoreTradeLogPageReqVO;
import com.yc.ship.module.otc.controller.admin.storetradelog.vo.StoreTradeLogRespVO;
import com.yc.ship.module.otc.dal.dataobject.storetradelog.StoreTradeLogDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 旅行社门店交易记录：余额充值、预付购票、预付退款、余额购票 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface StoreTradeLogMapper extends BaseMapperX<StoreTradeLogDO> {

    default PageResult<StoreTradeLogDO> selectPage(StoreTradeLogPageReqVO reqVO) {
        LambdaQueryWrapperX<StoreTradeLogDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getDistributorId, reqVO.getDistributorId());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getStoreId, reqVO.getStoreId());
        queryWrapperX.likeIfPresent(StoreTradeLogDO::getTradeName, reqVO.getTradeName());

        switch (reqVO.getType()) {
            case "1":
                // 余额
                queryWrapperX.inIfPresent(StoreTradeLogDO::getTradeType, 1, 3, 5, 7);
                break;
            case "2":
                // 授信
                queryWrapperX.inIfPresent(StoreTradeLogDO::getTradeType, 2, 4, 6, 8);
                break;
            default:

        }
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getTradeType, reqVO.getTradeType());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getBeforeBalance, reqVO.getBeforeBalance());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getAfterBalance, reqVO.getAfterBalance());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getTradeAmount, reqVO.getTradeAmount());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getTradeMode, reqVO.getTradeMode());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getRemark, reqVO.getRemark());
        queryWrapperX.eqIfPresent(StoreTradeLogDO::getOrderId, reqVO.getOrderId());
        queryWrapperX.betweenIfPresent(StoreTradeLogDO::getCreateTime, reqVO.getCreateTime());
        queryWrapperX.orderByDesc(StoreTradeLogDO::getId);
        return selectPage(reqVO, queryWrapperX);
    }

    int deleteStoreTradeLogById(@Param("id") Long id);

    @TenantIgnore
    StoreTradeLogRespVO getStoreTradeLogById(@Param("id") Long id);


    IPage<StoreTradeLogDO> selectStorePage(IPage<StoreTradeLogDO> iPage, @Param("param") StoreTradeLogPageReqVO pageReqVO);

}
