package cn.estsh.i3plus.ext.mes.apiservice.controller.base;

import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil.TRUE_OR_FALSE;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil.MESSAGE_RECEIVER_TYPE;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil.MESSAGE_TYPE;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil.MESSAGE_TYPE_CONTENT;
import cn.estsh.i3plus.pojo.platform.bean.SysMessage;
import cn.estsh.i3plus.pojo.wms.bean.WmsPushConfig;
import cn.estsh.i3plus.pojo.wms.bean.WmsPushLog;
import cn.estsh.i3plus.pojo.wms.modelbean.MailMessageModel;
import cn.estsh.impp.framework.boot.util.ResultBean;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmailPushService extends AbstractPushService<MailMessageModel> {
    private static final Logger LOGGER = LoggerFactory.getLogger(EmailPushService.class);
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public EmailPushService() {
    }

    @Override
    public ResultBean sendPush(MailMessageModel pushModel) {
        try {
            SysMessage sysMessage = new SysMessage();
            sysMessage.setMessageSenderNameRdd("MES Admin");
            sysMessage.setMessageTitle(pushModel.getTitle());
            sysMessage.setMessageContent(pushModel.getContent());
            sysMessage.setMessageContentType(MESSAGE_TYPE_CONTENT.HTML.getValue());
            sysMessage.setIsSystem(TRUE_OR_FALSE.TRUE.getValue());
            sysMessage.setMessageType(MESSAGE_TYPE.MAIL.getValue());
            sysMessage.setMessageReceiverType(MESSAGE_RECEIVER_TYPE.EXTERNAL.getValue());
            sysMessage.setMessageReceiversNameRdd(pushModel.getPathUrl());

            this.rabbitTemplate.convertAndSend("QUEUE_IMPP_MESSAGE_MAIL", JSON.toJSONString(sysMessage));
        } catch (Exception var7) {
            LOGGER.error("邮件发送失败");
        }

        return new ResultBean(true);
    }

    @Override
    public List queryData(WmsPushConfig var1) {
        return null;
    }

    @Override
    public void saveLog(WmsPushLog var1) {

    }

    @Override
    public void updateConfig(WmsPushConfig var1) {

    }
}
