package org.springblade.resource;

import org.springblade.modules.system.entity.MessageEntity;
import org.springblade.modules.system.service.MessageService;
import org.springblade.system.client.MessageClient;
import org.springblade.system.client.model.MessageModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

@RestController
@ApiIgnore
public class MessageResource implements MessageClient {

    @Autowired
    private MessageService messageService;

    @Override
    public void save(MessageModel messageModel) {
        MessageEntity messageEntity=new MessageEntity();
        BeanUtils.copyProperties(messageModel,messageEntity);
        messageService.save(messageEntity);
    }

    @Override
    public void saveBatch(List<MessageModel> list) {
        List<MessageEntity>messageEntityList=new ArrayList<>();
        if (list!= null && list.size()>0){
            for (MessageModel messageModel : list){
                MessageEntity messageEntity=new MessageEntity();
                BeanUtils.copyProperties(messageModel,messageEntity);
                messageEntityList.add(messageEntity);
            }
        }
        messageService.saveBatch(messageEntityList);
    }
}
