From 7ba218b08e9d70fb9173db5b4782f6f726df1fd2 Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期五, 24 十二月 2021 15:42:05 +0800
Subject: [PATCH] fix weather bug
---
deploy/crypto-js-master.zip | 0
deploy/utils.zip | 0
server/models/taskSchedule.js | 47 ++++++++++++++---------
server/utils/handle_db.js | 26 +++++++-----
deploy/jwt.txt | 1
5 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/deploy/crypto-js-master.zip b/deploy/crypto-js-master.zip
new file mode 100644
index 0000000..5ef1073
--- /dev/null
+++ b/deploy/crypto-js-master.zip
Binary files differ
diff --git a/deploy/jwt.txt b/deploy/jwt.txt
new file mode 100644
index 0000000..77b91eb
--- /dev/null
+++ b/deploy/jwt.txt
@@ -0,0 +1 @@
+http://223.167.111.168:8004/shanghai/index.html?JWT=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOiIxNjM5MTMzOTk4IiwidXNlcmlkIjoiMSIsInVzZXJuYW1lIjoi55Sz5qyj5LyY6L6-IiwiZXhwaXJlcyI6IjIwMjEtMTItMTAgMTA6NTk6NTcifQ.m4F64xEsnnLPCQQiOOUjG7m1uwu78-teVr2TkQ7a9fY
diff --git a/deploy/utils.zip b/deploy/utils.zip
new file mode 100644
index 0000000..e4ae56e
--- /dev/null
+++ b/deploy/utils.zip
Binary files differ
diff --git a/server/models/taskSchedule.js b/server/models/taskSchedule.js
index 2db6da1..a19722a 100644
--- a/server/models/taskSchedule.js
+++ b/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);
diff --git a/server/utils/handle_db.js b/server/utils/handle_db.js
index d57a776..5128696 100644
--- a/server/utils/handle_db.js
+++ b/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('')]
}
--
Gitblit v1.9.1