package com.dayou.message.handler;

import cn.hutool.core.bean.BeanUtil;
import com.dayou.entity.Message;
import com.dayou.mapper.MessageMapper;
import com.dayou.message.MessageServerCenter;
import com.dayou.message.bo.SystemMessageBO;
import com.dayou.utils.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * 类说明：
 *
 * @author: wucl
 * @since: 2023/6/30
 * created with IntelliJ IDEA.
 */
@Service
public class SystemMessageHandler extends MessageServerCenter<SystemMessageBO> {

    @Autowired
    private MessageMapper messageMapper;
    public Boolean sendMessage(Set<SystemMessageBO> systemMessages) {
        Set<Message> messages = ConvertUtil.copySet(systemMessages, Message.class);
        messageMapper.insertBatch(messages);
        return Boolean.TRUE;
    }

    @Override
    public Boolean sendMessage(SystemMessageBO systemMessageBO) {
        Message message = BeanUtil.copyProperties(systemMessageBO, Message.class);
        messageMapper.insert(message);
        return Boolean.TRUE;
    }

}
