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

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.controller.app.integralchangelog.vo.IntegralChangeLogPageReqVO;
import cn.newfeifan.mall.module.distri.dal.dataobject.integralchangelog.IntegralChangeLogDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 平台消费分变动记录 Mapper
 *
 * @author 非繁人
 */
@Mapper
public interface ConsumptionChangeLogMapper extends BaseMapperX<IntegralChangeLogDO> {

    default PageResult<IntegralChangeLogDO> selectPage(IntegralChangeLogPageReqVO reqVO) {
        LambdaQueryWrapperX<IntegralChangeLogDO> wrapper = new LambdaQueryWrapperX<IntegralChangeLogDO>()
                .eqIfPresent(IntegralChangeLogDO::getUserId, reqVO.getUserId())
                .eqIfPresent(IntegralChangeLogDO::getIntegralType, reqVO.getIntegralType())
                .betweenIfPresent(IntegralChangeLogDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IntegralChangeLogDO::getId);
        if (reqVO.getIntegralType() == null ){
            wrapper.ne(IntegralChangeLogDO::getMaxAvailablePointsAmount, 0);
        }
        return selectPage(reqVO, wrapper);
    }

}