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.WxMsgConfig;
import com.iformall.mapper.WxMsgConfigMapper;
import com.iformall.service.WxMsgConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WxMsgConfigServiceImpl implements WxMsgConfigService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxMsgConfigMapper wxMsgConfigMapper;


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

    @Override
    public WxMsgConfig getById(Long id) {
        return wxMsgConfigMapper.selectById(id);
    }

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

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

    @Override
    public WxMsgConfig findObject(WxMsgConfig wxMsgConfig) {
        return wxMsgConfigMapper.selectOne(new QueryWrapper(wxMsgConfig));
    }


}
