package com.brframework.commonapppush.service.impl;

import com.brframework.commonapppush.dao.PushLogDao;
import com.brframework.commonapppush.entity.PushLog;
import com.brframework.commonapppush.service.PushLogService;
import com.brframework.commondb.core.AbstractEntityService;
import com.brframework.commondb.core.CommonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 推送记录
 * @author xu
 * @date 2019/11/18 19:22
 */
@Service
public class PushLogServiceImpl extends AbstractEntityService<PushLog, Long, Object>
        implements PushLogService {

    @Autowired
    PushLogDao pushLogDao;

    @Override
    public CommonRepository<Long, PushLog> getRepository() {
        return pushLogDao;
    }

    @Override
    public void createUnicastLog(String messageId, String deviceTokens, String userTokens, String os, String title,
                          String text, String uri, String description, Integer status, String errorInfo) {
        PushLog log = new PushLog();
        log.setCreateDate(LocalDateTime.now());
        log.setMessageId(messageId);
        log.setDeviceTokens(deviceTokens);
        log.setUserTokens(userTokens);
        log.setTitle(title);
        log.setOs(os);
        log.setText(text);
        log.setUri(uri);
        log.setDescription(description);
        log.setStatus(status);
        log.setErrorInfo(errorInfo);
        log.setMessageType(PushLog.MESSAGE_TYPE_UNICAST);
        pushLogDao.save(log);

    }

    @Override
    public void createBroadcastLog(String messageId, String os, String title, String text, String uri, String description, Integer status, String errorInfo) {
        PushLog log = new PushLog();
        log.setCreateDate(LocalDateTime.now());
        log.setMessageId(messageId);
        log.setTitle(title);
        log.setOs(os);
        log.setText(text);
        log.setUri(uri);
        log.setDescription(description);
        log.setStatus(status);
        log.setErrorInfo(errorInfo);
        log.setMessageType(PushLog.MESSAGE_TYPE_BROADCAST);
        pushLogDao.save(log);
    }
}
