package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.IdWorker;
import com.iformall.domain.po.WxGameTemplate;
import com.iformall.mapper.WxGameTemplateMapper;
import com.iformall.service.WxGameTemplateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxGameTemplateServiceImpl implements WxGameTemplateService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    WxGameTemplateMapper wxGameTemplateMapper;


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

    @Override
    public List<WxGameTemplate> getList(WxGameTemplate record) {
        return wxGameTemplateMapper.findList(record);
    }

    @Override
    public WxGameTemplate getById(Long id) {
        return wxGameTemplateMapper.selectById(id);
    }

    @Override
    public void saveOrUpdate(WxGameTemplate record) {
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
            record.setId(idWorker.nextId());
            wxGameTemplateMapper.insert(record);
        } else {
            wxGameTemplateMapper.updateById(record);
        }
    }

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

}
