package com.jeequan.jeepay.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeequan.jeepay.db.entity.AccountChangeInfo;
import com.jeequan.jeepay.service.mapper.AccountChangeInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 账户变动明细 服务实现类
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2023-12-11
 */
@Service
@Slf4j
public class AccountChangeInfoService extends ServiceImpl<AccountChangeInfoMapper, AccountChangeInfo>{

    @Resource
    private AccountInfoService accountInfoService;

    /**
     * 分页查询
     * @param iPage
     * @param wrapper
     * @param info
     * @param paramJSON
     * @return
     */
    public Page<AccountChangeInfo> pageList(Page<AccountChangeInfo> iPage, LambdaQueryWrapper<AccountChangeInfo> wrapper, AccountChangeInfo info, JSONObject paramJSON) {
        // 时间范围条件
        Date[] dateRange = info.buildQueryDateRange();
        if (dateRange[0] != null) {
            wrapper.ge(AccountChangeInfo::getUpdatedAt, dateRange[0]);
        }
        if (dateRange[1] != null) {
            wrapper.le(AccountChangeInfo::getUpdatedAt, dateRange[1]);
        }
        wrapper.orderByDesc(AccountChangeInfo::getUpdatedAt);
        return page(iPage, wrapper);
    }

}
