package com.iformall.service.impl;

import com.iformall.common.IdWorker;
import com.iformall.domain.po.*;
import com.iformall.mapper.*;
import com.iformall.service.WxMsgRecordService;
import com.iformall.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.UUID;

/**
 * @author luozukai
 * 业务短信发送实现
 */
@Service
public class WxMsgRecordServiceImpl implements WxMsgRecordService {
    @Autowired
    private WxMsgRecordMapper wxMsgRecordMapper;

    @Override
    public void save(BaseMsg data) {
        WxMsgRecord msgRecord = new WxMsgRecord();
        final IdWorker idWorker = IdWorker.get();

        if(data instanceof WxMsgRecord){
            msgRecord = (WxMsgRecord)data;
        }

        msgRecord.setMsgType(data.getMsgType());
        msgRecord.setUuid(data.getUuid());
        msgRecord.setMsgJson(JsonUtil.obj2Json(data));
        msgRecord.setId(idWorker.nextId());
        wxMsgRecordMapper.save(msgRecord);
    }

    @Override
    public List<WxMsgRecord> findList(WxMsgRecord record) {
        return wxMsgRecordMapper.findList(record);
    }

    @Override
    public void update(WxMsgRecord record) {
        wxMsgRecordMapper.update(record);
    }
}
