//tag规则 release-v188.19.*  同步fqboss状态到峰擎/检查10分钟未推送的任务并发短信
const TaskBase = require("../../task.base");
const system = require("../../../system");
var settings = require("../../../../config/settings");
class pushAliTmStatus2Fq extends TaskBase {
  constructor() {
    super(TaskBase.getServiceName(pushAliTmStatus2Fq));
    this.restclient = system.getObject("util.restClient");
    this.smsClient = system.getObject("util.smsClient");
    this.fqbossUrl = settings.fqbossUrl();
    this.centerchannel = "https://gsbweb.qifu-dev.gongsibao.com/"//settings.centerChannelUrl();
    this.phone = ["17001277629","13381139519","15010929366"]//李学超 蒋勇 宋毅
  }
  async beforeTask(params) {
    console.log("前置操作......", this.serviceName);
    //this.isThrough=true; 
    //console.log(this.cacheManager);
  }
  async subDoTask() {
    console.log("--------------");
    console.log("TestTask1.....");
    try {
      var url = this.fqbossUrl + "api/tmInfoPusherApi/collectInfo";
      this.restclient.execGet(null, url);
      let now = Date.now()
      var needurl = this.centerchannel + "web/action/opNeed/springBoard";
      this.restclient.execPost({
        actionType:"getNeedComparisonList",
        actionBody:{
          "start": new Date(now - 10 * 60 * 1000),
          "end": new Date(now),
          "status": "wts",
          "listType": "business",
          "pageNum": 1,
          "pageSize": 10,
          tag:"need"
        }
      }, needurl).then(res=>{
        if (res.stdout){
          var data = JSON.parse(res.stdout);
          if (data.data&&data.data.rows&&data.data.total>0){
            let content = `⚠️⚠️⚠️️报警⚠️⚠️⚠️️ : ️️10分钟内有${data.data.total}条未推送的需求❗️❗️❗️`
            this.phone.forEach(phone=>{
              this.smsClient.sendMsg(phone,content)
            })
          }
        }
      }).catch(e=>{
        console.log(e)
      })
      return  system.getResultSuccess();
    } catch (error) {
      console.log(error);
      return null;
    }
  }
}
module.exports = pushAliTmStatus2Fq;