package com.gxwebsoft.shop.service.impl;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.param.UserParam;
import com.gxwebsoft.shop.mapper.PaymentMapper;
import com.gxwebsoft.shop.service.PaymentService;
import com.gxwebsoft.shop.entity.Payment;
import com.gxwebsoft.shop.param.PaymentParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 商城支付方式记录表Service实现
 *
 * @author 科技小王子
 * @since 2022-12-15 19:11:07
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {

    @Override
    public PageResult<Payment> pageRel(PaymentParam param) {
        PageParam<Payment, PaymentParam> page = new PageParam<>(param);
        //page.setDefaultOrder("create_time desc");
        List<Payment> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<Payment> listRel(PaymentParam param) {
        List<Payment> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<Payment, PaymentParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public Payment getByIdRel(Integer paymentId) {
        PaymentParam param = new PaymentParam();
        param.setPaymentId(paymentId);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public Payment getPaymentByMethod(String method){
      System.out.println(method+".......");
      PaymentParam param = new PaymentParam();
      param.setMethod(method);
      param.setTenantId(6);
      System.out.println(param);
//      System.out.println(param.getOne(baseMapper.selectListRel(param)));
      return param.getOne(baseMapper.selectListRel(param));
    }

}
