package cn.com.ctop.job.kuaishou.handler;


import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
import cn.com.ctop.alarm.modules.mapper.RuleAccountTemplateMapper;
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.HttpUtils;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class KuaiShouAlarmRuleJob {
    @Autowired
    private IRuleGroupService ruleGroupService;

    @Autowired
    private RuleAccountTemplateMapper ruleAccountTemplateMapper;
    String URLPREFIX = "http://jiaoyangapi.shyouteng.com.cn/jeecg-boot/ruleGroup/checkRulesByAccountId?accountId=";
    /**
     * 定时任务
     *
     * @param
     * @return
     * @throws
     * @author ZHAOXA
     */
    @XxlJob("kuaiShoualarmRuleJob")
    public void execute() throws Exception {
        //查询账户绑定过的规则模板
        Map<String, Object> map = new HashMap<>();
        //0状态为启动
        map.put("template_status", 0);
        List<RuleAccountTemplate> ruleAccountTemplates = ruleAccountTemplateMapper.selectByMap(map);
        if (!Check.isNull(ruleAccountTemplates)) {
            ruleAccountTemplates.forEach(template -> {
                String url = URLPREFIX + template.getAccountId();
                HttpUtils.httpGet(url, null, null);
            });
        }
    }
}
