-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpserver_perlist.js
139 lines (96 loc) · 3.59 KB
/
httpserver_perlist.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
logmdx = require('./jsdk/log.js');
logger = logmdx.logger;
logger.info("this is a info msg");
mdx = require('./conn.js');
connection = mdx.conn;
query = require('./jsdk/mysql.js')
// node D:\prj\spdJs\httpserver_perlist.js
// connection.query(, (err, results) => {
// if (err) {
// console.log(err);
// logger.error(err);
// }
// logger.info(results);
// String lists=JSON.stringify(results);
// startServer(lists);
// // process.exit();
// })
// function startServer(lists) {
// }
// node D:\prj\spdJs\httpserver_perlist.js
t = parseInt('5')
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
var url = require('url');
var q = url.parse(req.url, true).query;
// res.write(req.url);
if (req.url == '/get7data') {
try {
get7data(req, res);
} catch (e) {
logger.error(req.url)
}
}
else if (q.act == 'tonzhiDownOk') {
try {
logger.info(req.url)
console.info(req.url)
tonzhiDownOk(req, res);
} catch (e) {
logger.error(req.url)
}
} else {
res.write("ok main"); //write a response to the client
res.end();
}
}).listen(888); //the server object listens on port 8080
function tonzhiDownOk(req, res) {
(async () => {
var url = require('url');
var q = url.parse(req.url, true).query;
// var txt = q.year + " " + q.month;
vid = q.vid
try {
sql = " update 抓取数据记录 set 其他扩展字段 = json_set(其他扩展字段,'$.data_video_id','@vid@') where json_unquote (urlid) like '%@urlid@%' ";
sql = sql.replace('@vid@', vid)
sql = sql.replace('@urlid@', q.urlid)
logger.info(sql);
let rzt = await query(connection, sql)
logger.info(rzt);
res.write("ok"); //write a response to the client
res.end(); //end the response
} catch (e) {
logger.error(e);
res.write(e.message);
// res.write( JSON.stringify( e )); //write a response to the client
res.end(); //end the response
}
})();
}
function get7data(req, res) {
(async () => {
try {
// json_unquote (json_extract ( 其他扩展字段, '$.downed' ))
sql = "select json_unquote (urlid) as urlid from 抓取数据记录 where (urlid is not null and json_unquote(json_extract( 其他扩展字段, '$.downed' ))='n' ) OR ( urlid is not null and 其他扩展字段 is null ) or ( urlid is not null and json_extract( 其他扩展字段, '$.downed' ) is null ) order by id desc limit 9"
logger.info(sql);
let rows = await query(connection, sql)
logger.info(rows);
lists = JSON.stringify(rows);
for (row of rows) {
sql = " update 抓取数据记录 set 其他扩展字段 = json_set(其他扩展字段,'$.downed','y','$.downtime',NOW()) where json_unquote (urlid)='@urlid@' ";
sql = sql.replace('@urlid@', row.urlid)
logger.info(sql);
let rzt = await query(connection, sql)
logger.info(rzt);
}
res.write(lists); //write a response to the client
res.end(); //end the response
} catch (e) {
logger.error(e);
res.write(e.message);
// res.write( JSON.stringify( e )); //write a response to the client
res.end(); //end the response
}
})();
}