package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.template.mapper.WxAccessTokenMapper;
import com.template.model.pojo.WxAccessToken;
import com.template.services.WxAccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-08-01
 */
@Service
public class WxAccessTokenServiceImpl extends ServiceImpl<WxAccessTokenMapper, WxAccessToken> implements WxAccessTokenService {

    @Autowired
    private WxAccessTokenMapper wxAccessTokenMapper;

    @Override
    public int insertwxAccessToken(WxAccessToken wat) {
        int result = wxAccessTokenMapper.insert(wat);
        return result;
    }

    @Override
    public int updatewxAccessToken(WxAccessToken wat) {
        int result = wxAccessTokenMapper.updateById(wat);
        return result;
    }

    @Override
    public int deletewxAccessTokenById(int id) {
        int result = wxAccessTokenMapper.deleteById(id);
        return result;
    }

    @Override
    public WxAccessToken getRepairByDate(String dateNow) {
        QueryWrapper<WxAccessToken> queryWrapper = new QueryWrapper();
        queryWrapper.ge("expires_time",dateNow);
        queryWrapper.orderByDesc("expires_time");
        List<WxAccessToken> result = wxAccessTokenMapper.selectList(queryWrapper);
        return result.size() > 0 ? result.get(0) : null;
    }
}
