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

import java.util.Date;

@Service
public class WxTemplateMsgServiceImpl implements WxTemplateMsgService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxTemplateMsgMapper wxTemplateMsgMapper;


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

    @Override
    public WxTemplateMsg getById(Long id) {
        return wxTemplateMsgMapper.selectById(id);
    }

    @Override
    public WxTemplateMsg getByObj(WxTemplateMsg record) {

        return wxTemplateMsgMapper.selectOne(new QueryWrapper(record));
    }

    @Override
    public void saveOrUpdate(WxTemplateMsg record) {
        Date curDate = new Date();
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
        	record.setId(idWorker.nextId());
        	record.setCreateDate(curDate);
        	record.setUpdateDate(curDate);
            wxTemplateMsgMapper.insert(record);
        } else {
            record.setUpdateDate(curDate);
            wxTemplateMsgMapper.updateById(record);
        }
    }

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