package com.iformall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.IdWorker;
import com.iformall.domain.po.WxComponentVerifyTicket;
import com.iformall.mapper.WxComponentVerifyTicketMapper;
import com.iformall.service.WxComponentVerifyTicketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WxComponentVerifyTicketServiceImpl implements WxComponentVerifyTicketService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxComponentVerifyTicketMapper wxComponentVerifyTicketMapper;


    @Override
    public PageInfo<WxComponentVerifyTicket> listAsPage(WxComponentVerifyTicket record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxComponentVerifyTicketMapper.findList(record));
    }

    @Override
    public WxComponentVerifyTicket getById(Long id) {
        return wxComponentVerifyTicketMapper.selectById(id);
    }

    @Override
    public void saveOrUpdate(WxComponentVerifyTicket record) {
        WxComponentVerifyTicket wxComponentVerifyTicket = null;
        try {
            WxComponentVerifyTicket ctQ = new WxComponentVerifyTicket();
            ctQ.setComponentAppid(record.getComponentAppid());
            wxComponentVerifyTicket = wxComponentVerifyTicketMapper.selectOne(new QueryWrapper(ctQ));
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        if (wxComponentVerifyTicket == null) {
            final IdWorker idWorker = IdWorker.get();
            record.setId(idWorker.nextId());
            wxComponentVerifyTicketMapper.insert(record);
        } else {
            record.setId(wxComponentVerifyTicket.getId());
            wxComponentVerifyTicketMapper.updateById(record);
        }
    }

    @Override
    public void deleteById(Long id) {
        wxComponentVerifyTicketMapper.deleteById(id);
    }
    
    
    
    
    
    
    
    
}
