package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxCardInfo;
import com.iformall.domain.vo.WxCardVo;
import com.iformall.mapper.WxCardInfoMapper;
import com.iformall.service.WxCardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

import java.util.List;

@Service
public class WxCardInfoServiceImpl implements WxCardInfoService {
	
	@Autowired
    WxCardInfoMapper wxCardInfoMapper;


    @Override
    public PageInfo<WxCardVo> listAsPage(WxCardVo record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCardInfoMapper.findVoList(record));
    }

    @Override
    public WxCardInfo getById(Long id) {
        return wxCardInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(WxCardInfo record) {
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
        	record.setId(idWorker.nextId());
            wxCardInfoMapper.insertSelective(record);
        } else {
            wxCardInfoMapper.updateByPrimaryKeySelective(record);
        }
    }

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