cshenfu
2025-04-10 231ff2d244352a236d3da55c23e972a6adab2049
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const schedule = require('node-schedule');
const axios = require('axios');
const mysql = require("../utils/mysql_db");
 
 
var jsonData = '';//存储天气信息
// 定义规则
let rule = new schedule.RecurrenceRule();
rule.minute = [15, 30, 45, 55]
//rule.second = [30, 60]; // 每隔 10 秒执行一次
 
let rule_dealdata = new schedule.RecurrenceRule();
// rule_dealdata.minute = [04]
 
 
 
module.exports = {
  async job_ () {
    // schedule.scheduleJob('5 * * * * *', async () => {
 
    // });
  },
 
};
function repair(i){
  if (i >= 0 && i <= 9) {
      return "0" + i;
  } else {
      return i;
  }
}
 
// schedule.scheduleJob(rule_dealdata, async () => {//每小时处理车载指标数据
//   //http://192.168.1.4:5000/api
//   // Exemplary payload
//   let nowtime = new Date();//当前时间
//   let date=new Date(nowtime.getTime()- 1*60*60*1000);
//   let year = date.getFullYear() //返回指定日期的年份
//   let month = repair(date.getMonth() + 1);//月
//   let day = repair(date.getDate());//日
//   let hour = repair(date.getHours());//时
//   let minute = repair(date.getMinutes());//分
//   let second = repair(date.getSeconds());//秒
 
//   //当前时间 
//   let curTime = year + "-" + month + "-" + day
//     + " " + hour + ":" + minute + ":" + second;
//   if(hour == '01') {
//     date=new Date(nowtime.getTime()- 24*60*60*1000);
//     year = date.getFullYear() //前一天的时间
//     month = repair(date.getMonth() + 1);//月
//     day = repair(date.getDate());//日
//     hour = repair(date.getHours());//时
//     minute = repair(date.getMinutes());//分
//     second = repair(date.getSeconds());//秒
//     curTime = year + "-" + month + "-" + day
//       + " " + hour + ":" + minute + ":" + second;
//     mysql.query_data(`call proc_reset_taxi_data('${curTime}')`, 'master', null);
//   }
 
// });
 
 
 
 
//  https://devapi.heweather.net/v7/weather/now?location=101021700&key=495b433d21c84986a99c4ac52d42fd3b
 
 
function httpGet (uri) {
  console.log(uri);
  axios.get(uri).then(response => {
    console.log(response.data);
    return response.data;
  }).catch(error => {
    console.log(error);
  });
}
 
function httpPost (uri, postdata) {
  // let data = {
  //     name: 'John Doe',
  //     job: 'Content Writer'
  // };
  axios.post(uri, postdata).then((res) => {
    return res.data;
    console.log(`Status: ${res.status}`);
    console.log('Body: ', res.data);
  }).catch((err) => {
    console.error(err);
  });
}