package com.dsk.monitor.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsk.common.utils.DateUtils;
import com.dsk.monitor.domain.dto.PushMonitorRules;
import com.dsk.monitor.mapper.PushMonitorInfoMapper;
import com.dsk.monitor.mapper.PushMonitorRulesMapper;
import com.dsk.monitor.util.SendMessageUtil;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

/**
 * @ClassName PushScheduling
 * @Description 发送短信
 * @Author Dgm
 * @Date 2023/12/9 13:51
 * @Version
 */
public class PushScheduling {

    @Resource
    private PushMonitorInfoMapper monitorInfoMapper;

    @Resource
    private PushMonitorRulesMapper rulesMapper;

    @Scheduled(cron = "0 0 5 * * * ?")
    public void receiveModePhone() {
        // 获取当前整点时间
        Integer concurrentHour = DateUtils.getHour();
        QueryWrapper queryWrapper = new QueryWrapper();
        PushMonitorRules detail  = rulesMapper.selectOne(queryWrapper);
        // 推送时段-起
        Integer timePeriodStart = detail.getTimePeriodStart();
        // 推送时段-止
        Integer timePeriodEnd = detail.getTimePeriodEnd();
        if (concurrentHour > timePeriodStart && concurrentHour < timePeriodEnd) {
            QueryWrapper monitorInfoWrapper = new QueryWrapper();
            // 风险类型
            monitorInfoWrapper.in("risk_type", detail.getRiskType());
            // 监控维度
            monitorInfoWrapper.in("dimension", detail.getDimension());
            Long count = monitorInfoMapper.selectCount(monitorInfoWrapper);
            if (count >0 ) {
                SendMessageUtil.sendMessage(detail.getPhones(), count.toString());
            }
        }
    }
}
