道路环境监测node后端和java后台代码
wangrong
2021-12-24 7ba218b08e9d70fb9173db5b4782f6f726df1fd2
fix weather bug
2个文件已修改
3个文件已添加
74 ■■■■■ 已修改文件
deploy/crypto-js-master.zip 补丁 | 查看 | 原始文档 | blame | 历史
deploy/jwt.txt 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
deploy/utils.zip 补丁 | 查看 | 原始文档 | blame | 历史
server/models/taskSchedule.js 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/utils/handle_db.js 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
deploy/crypto-js-master.zip
Binary files differ
deploy/jwt.txt
New file
@@ -0,0 +1 @@
http://223.167.111.168:8004/shanghai/index.html?JWT=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOiIxNjM5MTMzOTk4IiwidXNlcmlkIjoiMSIsInVzZXJuYW1lIjoi55Sz5qyj5LyY6L6-IiwiZXhwaXJlcyI6IjIwMjEtMTItMTAgMTA6NTk6NTcifQ.m4F64xEsnnLPCQQiOOUjG7m1uwu78-teVr2TkQ7a9fY
deploy/utils.zip
Binary files differ
server/models/taskSchedule.js
@@ -6,7 +6,7 @@
var jsonData = '';//存储天气信息
// 定义规则
let rule = new schedule.RecurrenceRule();
rule.minute = [1,6,11,16,21,26,31,36,41,46,51,56]
rule.minute = [15,30,45,55]
//rule.second = [30, 60]; // 每隔 10 秒执行一次
@@ -22,7 +22,7 @@
schedule.scheduleJob(rule, async () => {//每小时定时取天气数据
    //https://devapi.heweather.net/v7/weather/now?location=101021700&key=495b433d21c84986a99c4ac52d42fd3b
    let urlstr = "https://devapi.heweather.net/v7/weather/now?location=location_code&key=495b433d21c84986a99c4ac52d42fd3b";
    let urlstr = "https://devapi.heweather.net/v7/weather/now?location=location_code&key=fca708c817034474b6969579ab61a380";
    sqlstr = `select * from t_s_weather_city order by code`;
    let data_rets = await mysql.query_data(sqlstr, 'master', null)
    for (let index = 0; index < data_rets.length; index++) {
@@ -30,17 +30,24 @@
        // 检测当前是否已有天气数据
        let sqlstr = `select count(1) as counter from t_d_weather_hour where citycode='`+element.code+`' and TO_DAYS(now())=TO_DAYS(posttime) and HOUR(now())=hour(posttime) `;
        let lastdata_times = await mysql.query_data(sqlstr, 'master', null);
        if( lastdata_times[0].counter > 0 ) { continue ;}
        console.log(lastdata_times[0].counter);
        console.log(lastdata_times[0].counter > 0)
        if( lastdata_times[0].counter > 0 ) { continue ;}
        // 若当前无天气数据,重新抓取  
        axios.get(urlstr.replace('location_code', element.code)).then(response => {
            console.log(response.data)
            if(response.data.now) {
                let w = response.data.now;
                let posttime_ = w.obsTime.replace('T',' ').substr(0,13)+ ':00:00';
                let sql_ = `insert into t_d_weather_hour (type,citycode,cityname,posttime,temp,feelsLike,icon,text,wind360,windDir,windScale,windSpeed,humidity,precip,pressure,vis,cloud,dew,responsedata)
                    values ('${element.type}','${element.code}','${element.name}','${posttime_}','${w.temp}','${w.feelsLike}','${w.icon}','${w.text}','${w.wind360}',
                    '${w.windDir}','${w.windScale}','${w.windSpeed}','${w.humidity}','${w.precip}','${w.pressure}','${w.vis}','${w.cloud}','${w.dew}','${JSON.stringify(response.data)}'
                )`;
                mysql.query_data(sql_, 'master', null)
                let currHours = (new Date()).getHours();
                let postHours = (new Date(posttime_)).getHours();
                if(postHours == currHours) {
                    let sql_ = `insert into t_d_weather_hour (type,citycode,cityname,posttime,temp,feelsLike,icon,text,wind360,windDir,windScale,windSpeed,humidity,precip,pressure,vis,cloud,dew,responsedata)
                        values ('${element.type}','${element.code}','${element.name}','${posttime_}','${w.temp}','${w.feelsLike}','${w.icon}','${w.text}','${w.wind360}',
                        '${w.windDir}','${w.windScale}','${w.windSpeed}','${w.humidity}','${w.precip}','${w.pressure}','${w.vis}','${w.cloud}','${w.dew}','${JSON.stringify(response.data)}'
                    )`;
                    mysql.query_data(sql_, 'master', null)
                }
            }
        }).catch(error => {
            console.log(error);
@@ -53,7 +60,7 @@
schedule.scheduleJob(rule, async () => {//每天定时更新天气数据
    //https://devapi.qweather.com/v7/weather/3d?location=101021700&key=495b433d21c84986a99c4ac52d42fd3b
    
    let urlstr = "https://devapi.qweather.com/v7/weather/3d?location=location_code&key=495b433d21c84986a99c4ac52d42fd3b";
    let urlstr = "https://devapi.qweather.com/v7/weather/3d?location=location_code&key=fca708c817034474b6969579ab61a380";
    sqlstr = `select * from t_s_weather_city order by code`;
    let data_rets = await mysql.query_data(sqlstr, 'master', null)
    for (let index = 0; index < data_rets.length; index++) {
@@ -67,15 +74,19 @@
            if(response.data.daily) {
                let w = response.data.daily[0];
                let posttime_ = w.fxDate+ ' 00:00:00';
                let sql_ = `insert into t_d_weather_day (type,citycode,cityname,posttime,iconNight,iconDay,humidity,precip,pressure,vis,cloud,
                    moonPhase,moonPhaseIcon,moonrise,moonset,sunrise,sunset,tempMax,tempMin,textDay,textNight,uvIndex,
                    wind360Day,windDirDay,wind360Night,windDirNight,windScaleDay,windScaleNight,windSpeedDay,windSpeedNight,responsedata)
                    values ('${element.type}','${element.code}','${element.name}','${posttime_}','${w.iconNight}','${w.iconDay}','${w.humidity}','${w.precip}','${w.pressure}','${w.vis}',
                    '${w.cloud}','${w.moonPhase}','${w.moonPhaseIcon}','${w.moonrise}','${w.moonset}','${w.sunrise}','${w.sunset}','${w.tempMax}','${w.tempMin}','${w.textDay}','${w.textNight}','${w.uvIndex}',
                    '${w.wind360Day}','${w.windDirDay}','${w.wind360Night}','${w.windDirNight}','${w.windScaleDay}','${w.windScaleNight}','${w.windSpeedDay}','${w.windSpeedNight}',
                    '${JSON.stringify(response.data)}'
                )`;
                mysql.query_data(sql_, 'master', null)
                let currdate = (new Date()).getDate();
                let postdate = (new Date(posttime_)).getDate();
                if (currdate == postdate) {
                    let sql_ = `insert into t_d_weather_day (type,citycode,cityname,posttime,iconNight,iconDay,humidity,precip,pressure,vis,cloud,
                        moonPhase,moonPhaseIcon,moonrise,moonset,sunrise,sunset,tempMax,tempMin,textDay,textNight,uvIndex,
                        wind360Day,windDirDay,wind360Night,windDirNight,windScaleDay,windScaleNight,windSpeedDay,windSpeedNight,responsedata)
                        values ('${element.type}','${element.code}','${element.name}','${posttime_}','${w.iconNight}','${w.iconDay}','${w.humidity}','${w.precip}','${w.pressure}','${w.vis}',
                        '${w.cloud}','${w.moonPhase}','${w.moonPhaseIcon}','${w.moonrise}','${w.moonset}','${w.sunrise}','${w.sunset}','${w.tempMax}','${w.tempMin}','${w.textDay}','${w.textNight}','${w.uvIndex}',
                        '${w.wind360Day}','${w.windDirDay}','${w.wind360Night}','${w.windDirNight}','${w.windScaleDay}','${w.windScaleNight}','${w.windSpeedDay}','${w.windSpeedNight}',
                        '${JSON.stringify(response.data)}'
                    )`;
                    mysql.query_data(sql_, 'master', null)
                }
            }
        }).catch(error => {
            console.log(error);
server/utils/handle_db.js
@@ -143,15 +143,19 @@
 let create_sql = function(obj,pagesize_,pageindex_) {
  let str_select_ = [];
  let str_select_count = [];  
  str_select_.push(obj.select_ + obj.from_ + obj.where_ + obj.order_);
  str_select_count.push('select count(1) as counter '+obj.from_ + obj.where_ + obj.order_);
  if (obj.server_paging == '1') {
    let pageindex = (Number(pageindex_)>=0) ? Number(pageindex_) : 1;
    let pagesize = (Number(pagesize_)>=0) ? Number(pagesize_) : 10;
    str_select_.push(' limit ')
    str_select_.push((pageindex-1)*pagesize)
    str_select_.push(', ')
    str_select_.push(pagesize);
  str_select_.push(obj.select_ + ' ' + obj.from_ + ' ' + obj.where_ + ' ' + obj.order_);
  str_select_count.push('select count(1) as counter '+obj.from_ +' ' + obj.where_ + ' ' + obj.order_);
  try {
    if (pagesize_ && Number(pagesize_)>=0) {
      let pageindex = (Number(pageindex_)>=0) ? Number(pageindex_) : 1;
      let pagesize = (Number(pagesize_)>=0) ? Number(pagesize_) : 10;
      str_select_.push(' limit ')
      str_select_.push((pageindex-1)*pagesize)
      str_select_.push(', ')
      str_select_.push(pagesize);
    }
  } catch (error) {
  }
  return [str_select_count.join(''),str_select_.join('')]
}
@@ -163,8 +167,8 @@
 let create_sync_sql = function(obj) {
  let str_select_ = [];
  let str_sync = [];  
  str_select_.push(obj.select_ + obj.from_ + obj.where_ + obj.order_);
  str_sync.push(obj.insert_ + obj.column_ + obj.values_ + obj.updateDuplicate_);
  str_select_.push(obj.select_ + ' ' + obj.from_ + ' ' + obj.where_ + ' ' + obj.order_);
  str_sync.push(obj.insert_ + ' ' + obj.column_ + ' ' + obj.values_ + ' ' + obj.updateDuplicate_);
  return [str_select_.join(''),str_sync.join('')]
}