package com.ruoyi.web.v2.v1.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.v2.v1.entity.PayRecord;
import com.ruoyi.web.v2.v1.entity.request.PayRecordRequest;
import com.ruoyi.web.v2.v1.mapper.PayRecordMapper;
import com.ruoyi.web.v2.v1.service.IPayRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-12-25
 */
@Service
public class PayRecordServiceImpl extends ServiceImpl<PayRecordMapper, PayRecord> implements IPayRecordService {


    @Override
    public AjaxResult getListPayRecordPage(PayRecordRequest payRecordRequest) {
        String recordIds = payRecordRequest.getRecordIds();
        QueryWrapper<PayRecord> payRecordQueryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(recordIds)){
            payRecordQueryWrapper.in("id", Arrays.asList(recordIds.split(",")));
        }
        return AjaxResult.success(this.page(new Page<PayRecord>( payRecordRequest.getPageNum(),payRecordRequest.getPageSize()),payRecordQueryWrapper
                .ge(StringUtils.isNotEmpty(payRecordRequest.getStartDate()), "pay_time", payRecordRequest.getStartDate())
                .le(StringUtils.isNotEmpty(payRecordRequest.getEndDate()),"pay_time",payRecordRequest.getEndDate())
                .eq(StringUtils.isNotEmpty(payRecordRequest.getUserId()),"user_id",payRecordRequest.getUserId())
        ));
    }

    @Override
    public AjaxResult getList(PayRecordRequest payRecordRequest) {
        String recordIds = payRecordRequest.getRecordIds();
        QueryWrapper<PayRecord> payRecordQueryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(recordIds)){
            payRecordQueryWrapper.in("id", Arrays.asList(recordIds.split(",")));
        }
        return AjaxResult.success(this.list(payRecordQueryWrapper
                .ge(StringUtils.isNotEmpty(payRecordRequest.getStartDate()), "pay_time", payRecordRequest.getStartDate())
                .le(StringUtils.isNotEmpty(payRecordRequest.getEndDate()),"pay_time",payRecordRequest.getEndDate())
                .eq(StringUtils.isNotEmpty(payRecordRequest.getUserId()),"user_id",payRecordRequest.getUserId())
        ));
    }
}
