package com.iformall.service.impl;

import java.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxMsgSignature;
import com.iformall.mapper.WxMsgSignatureMapper;
import com.iformall.service.WxMsgSignatureService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

@Service
public class WxMsgSignatureServiceImpl implements WxMsgSignatureService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxMsgSignatureMapper wxMsgSignatureMapper;


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

    @Override
    public WxMsgSignature getById(Long id) {
        return wxMsgSignatureMapper.selectById(id);
    }

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

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

    @Override
    public ResultData getsignaturelist(String tenantId) {
        WxMsgSignature wxMsgSignature = new WxMsgSignature();
        wxMsgSignature.setTenantId(tenantId);
        List<WxMsgSignature> list = wxMsgSignatureMapper.findList(wxMsgSignature);
        return new ResultData(list);
    }


}
