package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.domain.ZsOperationSendconfig;
import com.ruoyi.system.mapper.ZsOperationSendconfigMapper;
import com.ruoyi.system.service.ZsEmailService;
import com.ruoyi.system.utils.EmailUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
@Slf4j
public class ZsEmailServiceImpl implements ZsEmailService {

    @Autowired
    private ZsOperationSendconfigMapper zsOperationSendconfigMapper;
    @Autowired
    private EmailUtils emailUtils;
    @Override
    public boolean sendEmail(String receiveEmail,String title,String context) {
        QueryWrapper<ZsOperationSendconfig> sendWrapper= new QueryWrapper<>();
        sendWrapper.eq("module",1);//站点模块
        sendWrapper.eq("code",0);//邮箱方式
        //根据预警编码   查询出对应的预警信息接收地址
        List<ZsOperationSendconfig> zsOperationSendconfigList = zsOperationSendconfigMapper.selectList(sendWrapper);
        if (zsOperationSendconfigList!=null&&zsOperationSendconfigList.size()>0) {
            for (ZsOperationSendconfig zsOperationSendconfig : zsOperationSendconfigList) {
                emailUtils.sendMailByTransport(zsOperationSendconfig.getSendEmail(),receiveEmail,title,context,zsOperationSendconfig.getSmtpId());
            }
        }
        return true;
    }

}
