package com.jeequan.jeepay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeequan.jeepay.db.entity.InfoAccountHistory;
import com.jeequan.jeepay.service.mapper.InfoAccountHistoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 钱包流水表 服务实现类
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2022-03-23
 */
@Service
public class InfoAccountHistoryService extends ServiceImpl<InfoAccountHistoryMapper, InfoAccountHistory> {


    public IPage<InfoAccountHistory> listByPage(IPage iPage, InfoAccountHistory queryObject) {

        LambdaQueryWrapper<InfoAccountHistory> wrapper = InfoAccountHistory.gw();

        wrapper.eq(queryObject.getHid() != null, InfoAccountHistory::getHid, queryObject.getHid());
        wrapper.eq(StringUtils.isNotEmpty(queryObject.getInfoId()), InfoAccountHistory::getInfoId, queryObject.getInfoId());
        wrapper.eq(StringUtils.isNotEmpty(queryObject.getInfoType()), InfoAccountHistory::getInfoType, queryObject.getInfoType());
        wrapper.eq(queryObject.getOpAccountType() != null, InfoAccountHistory::getOpAccountType, queryObject.getOpAccountType());
        wrapper.eq(queryObject.getBizType() != null, InfoAccountHistory::getBizType, queryObject.getBizType());
        wrapper.eq(queryObject.getRelaBizOrderType() != null, InfoAccountHistory::getRelaBizOrderType, queryObject.getRelaBizOrderType());
        wrapper.eq(StringUtils.isNotEmpty(queryObject.getRelaBizOrderId()), InfoAccountHistory::getRelaBizOrderId, queryObject.getRelaBizOrderId());
        wrapper.eq(queryObject.getSettId() != null, InfoAccountHistory::getSettId, queryObject.getSettId());

        // 时间范围条件
        Date[] dateRange = queryObject.buildQueryDateRange();
        if (dateRange[0] != null) {
            wrapper.ge(InfoAccountHistory::getCreatedAt, dateRange[0]);
        }
        if (dateRange[1] != null) {
            wrapper.le(InfoAccountHistory::getCreatedAt, dateRange[1]);
        }
        wrapper.orderByDesc(InfoAccountHistory::getHid);

        return page(iPage, wrapper);
    }
}
