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.WxTagsGroup;
import com.iformall.mapper.WxTagsGroupMapper;
import com.iformall.service.WxTagsGroupService;
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 WxTagsGroupServiceImpl implements WxTagsGroupService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxTagsGroupMapper wxTagsGroupMapper;

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

    @Override
    public WxTagsGroup getById(Long id) {
        return wxTagsGroupMapper.selectById(id);
    }

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

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

    @Override
    public List<WxTagsGroup> findList(WxTagsGroup wxTagsGroup) {
       return wxTagsGroupMapper.findList(wxTagsGroup);
    }

}
