import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.reyun.saas.WebApplication;
import com.reyun.saas.mob.user.domain.App;
import com.reyun.saas.mob.user.domain.WarningDataInfo;
import com.reyun.saas.mob.util.SendCloudComponent;
import com.reyun.saas.report.data.dao.WarningReportMapper;
import com.reyun.saas.report.realtimecommon.dao.ChannelInfoMapper;
import com.reyun.saas.report.realtimecommon.domain.ChannelInfo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.*;


/**
 * @desc
 * @date
 */
@SpringBootTest(classes = WebApplication.class)
class TestApplication {


    @Autowired
    private ChannelInfoMapper channelInfoMapper;

    @Autowired
    private SendCloudComponent sendCloudComponent;

    @Resource
    private WarningReportMapper warningReportMapper;

    @Test
    public void test(){
        List<ChannelInfo> channelInfoByDate = channelInfoMapper.findChannelInfoByDate();
        System.out.println(channelInfoByDate);
    }

    /**
     * 测试发送邮件
     */
    @Test
    public void testSendMail(){
        List<String> email = Arrays.asList("tanxin@reyun.com", "liyin@reyun.com");
        String subject = "热云数据MobDNA“一个预警名称”预警邮件";
        String contents = "<div id = \"warning_email\" style=\"max-width:420px; margin: 0 auto;\"><p style=\"font-size:14px;\">亲爱的用户：</p><p style=\"font-size:14px;\">&nbsp; &nbsp; &nbsp; &nbsp;您好，由用户Luka配置的预警规则【一个预警名称】已达到预警阈值上线，请您及时关注异常数据变化。</p><p style=\"font-size:14px;\">以下是预警报告的缩略信息，分析详情请<u><a href=\"https://mobdna.reyun.com/\">登录MobDNA</a></span></u>前往预警中心查看。</p><p style=\"font-size:14px;\"><br /></p><table  border=\"1px solid #ddd\" cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%;\" ><tr ><td align=\"center\">预警名称</td><td align=\"center\">一个预警名称</td></tr><tr><td align=\"center\">应用名称</td><td align=\"center\">PUBG</td></tr><tr><td align=\"center\">渠道名称</td><td align=\"center\">HUAWEI</td></tr><tr><td align=\"center\">计算区间</td><td align=\"center\">按天计算</td></tr><tr><td align=\"center\">日期</td><td align=\"center\">2021-10-24</td></tr><tr><td align=\"center\">触发预警时段</td><td align=\"center\">0:00~23:00</td></tr><tr><td align=\"center\">当日累计预警次数</td><td align=\"center\">10次</td></tr></table><br /><p align=\"right\">如需退订预警服务，请联系Luka（luka@reyun.com）进入MobDNA后台配置。</p><p align=\"right\">感谢您的支持</p><p align=\"right\">热云数据MobDNA团队</p></div>";
        try {
            boolean b = sendCloudComponent.sendMailReuse(email, subject, contents, null, null,"mobdna@reyun.com","MobDNA");
            System.out.println(b);
        }catch (Exception e){
            System.out.println("捕捉到了异常");
        }

    }

    @Test
    public void testWarningReport(){
        Map<String, String> data = new HashMap<>();
        data.put("os","2");
        data.put("eval","");
        data.put("appkey","115Dc5a8527bN169A1");
        data.put("cid","huawei");
        data.put("ds","2021-10-26");
        data.put("startHour","0");
        data.put("endHour","23");
        WarningDataInfo report = warningReportMapper.report(data);
        System.out.println(report);
    }

    @Test
    public void testWarningSMS(){
        JSONObject vars = JSONUtil.createObj().set("username", "Luka").set("name", "仙游-广点通预警");
        sendCloudComponent.sendSMS("13269905259,13683215357",sendCloudComponent.getWarningModel(),vars.toString());
    }
}
