myapp_sjy 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Dockerfile +7 -0
- package/app.js +58 -0
- package/bin/www +92 -0
- package/package.json +100 -0
- package/pkg.zip +0 -0
- package/public/css/layui.css +1 -0
- package/public/css/modules/code.css +1 -0
- package/public/css/modules/laydate/default/laydate.css +1 -0
- package/public/css/modules/layer/default/icon-ext.png +0 -0
- package/public/css/modules/layer/default/icon.png +0 -0
- package/public/css/modules/layer/default/layer.css +1 -0
- package/public/css/modules/layer/default/loading-0.gif +0 -0
- package/public/css/modules/layer/default/loading-1.gif +0 -0
- package/public/css/modules/layer/default/loading-2.gif +0 -0
- package/public/font/iconfont.eot +0 -0
- package/public/font/iconfont.svg +554 -0
- package/public/font/iconfont.ttf +0 -0
- package/public/font/iconfont.woff +0 -0
- package/public/font/iconfont.woff2 +0 -0
- package/public/layui.js +5 -0
- package/public/stylesheets/style.css +8 -0
- package/routes/api.js +642 -0
- package/routes/datatime.js +16 -0
- package/routes/db.js +145 -0
- package/routes/index.js +28 -0
- package/routes/nppBackup/sql.js.2024-07-08_082213.bak +25 -0
- package/routes/nppBackup/sql.js.2024-07-08_082214.bak +25 -0
- package/routes/sql.js +25 -0
- package/routes/switch.js +33 -0
- package/routes/switch1.js +12 -0
- package/views/addroom.ejs +223 -0
- package/views/addstu.ejs +318 -0
- package/views/error.ejs +3 -0
- package/views/hisinfo.ejs +442 -0
- package/views/hisinfo1.ejs +291 -0
- package/views/login.ejs +227 -0
- package/views/modroom.ejs +365 -0
- package/views/modstu.ejs +375 -0
- package/views/rtinfo.ejs +342 -0
- package/views/rtinfo1.ejs +268 -0
package/routes/api.js
ADDED
@@ -0,0 +1,642 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
|
4
|
+
// const bodyParser = require('body-parser');
|
5
|
+
const app = express();
|
6
|
+
app.use(express.json());
|
7
|
+
|
8
|
+
|
9
|
+
const db = require('./sql.js');
|
10
|
+
const EventEmitter = require('events'); //引入事件模块
|
11
|
+
var flag = 0;
|
12
|
+
var flag1 = 0;
|
13
|
+
var mac1;
|
14
|
+
var attend;
|
15
|
+
var f;
|
16
|
+
var bt = '1970-01-01 00:00:00';
|
17
|
+
var et = '2100-01-01 00:00:00';
|
18
|
+
var btrt = '1970-01-01 00:00:00';
|
19
|
+
var etrt = '1970-01-01 00:00:00';
|
20
|
+
var qdt = "";
|
21
|
+
var mem = "%";
|
22
|
+
var rom = "%";
|
23
|
+
var adm = "%";
|
24
|
+
var normal = 0;
|
25
|
+
var late = 0;
|
26
|
+
|
27
|
+
const myEmitter = new EventEmitter.EventEmitter();//创建EventEmitter对象用于监听
|
28
|
+
// const myEmitterRcvJsonData = new EventEmitter.EventEmitter();//创建EventEmitter对象用于监听
|
29
|
+
//注册seen事件用于监视
|
30
|
+
|
31
|
+
myEmitter.on('seen', () => {//签到成功
|
32
|
+
flag = 1;
|
33
|
+
});
|
34
|
+
myEmitter.on('seen1', () => {//重复刷卡
|
35
|
+
flag = 2;
|
36
|
+
});
|
37
|
+
router.get('/check', function (req, res) {
|
38
|
+
res.send({ 'status': 'success', 'flag': flag, 'id': attend, 'flag1': flag1 });
|
39
|
+
flag = 0;
|
40
|
+
flag1 = 1;
|
41
|
+
});
|
42
|
+
|
43
|
+
router.get('/chartcheck', function (req, res) {
|
44
|
+
res.send({ 'status': 'success', 'la': late, 'no': normal });
|
45
|
+
});
|
46
|
+
|
47
|
+
router.post('/', (req, res, next) => {
|
48
|
+
let data = '';
|
49
|
+
req.on('data', chunk => {
|
50
|
+
data += chunk;
|
51
|
+
console.log(data);
|
52
|
+
});
|
53
|
+
|
54
|
+
req.on('end', () => {
|
55
|
+
const jsonData = JSON.parse(data);
|
56
|
+
|
57
|
+
var mac = jsonData.mac;
|
58
|
+
var uid = jsonData.uid;
|
59
|
+
|
60
|
+
console.log(mac);
|
61
|
+
console.log(uid);
|
62
|
+
var aaa = '%' + uid + '%';
|
63
|
+
db.query('SELECT * FROM members WHERE cardid LIKE ?;', aaa, (err, rows) => {
|
64
|
+
if (rows[0]) {
|
65
|
+
var bbb = '%' + mac + '%';
|
66
|
+
db.query('SELECT * FROM rooms WHERE mac LIKE ?;', bbb, (err, rooms) => {
|
67
|
+
if (rooms == "") {
|
68
|
+
let user = {
|
69
|
+
result: "failed",
|
70
|
+
mes: "",
|
71
|
+
reason: "wrong room"
|
72
|
+
}
|
73
|
+
console.log(user);
|
74
|
+
res.send(user);
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
db.query('SELECT * FROM types WHERE key=?;', rows[0].type, (err, types) => {
|
78
|
+
f = rows[0].stuid;
|
79
|
+
mac1 = rooms[0].num;
|
80
|
+
var date = new Date();
|
81
|
+
var year = date.getFullYear();
|
82
|
+
var month = date.getMonth() + 1;
|
83
|
+
month = month < 10 ? ('0' + month) : month;
|
84
|
+
var day = date.getDate();
|
85
|
+
day = day < 10 ? ('0' + day) : day;
|
86
|
+
var hour = date.getHours();
|
87
|
+
hour = hour < 10 ? ('0' + hour) : hour;
|
88
|
+
var minute = date.getMinutes();
|
89
|
+
minute = minute < 10 ? ('0' + minute) : minute;
|
90
|
+
var second = date.getSeconds();
|
91
|
+
second = second < 10 ? ('0' + second) : second;
|
92
|
+
var t0 = hour + ':' + minute + ':' + second;
|
93
|
+
var qd = "";
|
94
|
+
console.log(qdt);
|
95
|
+
console.log(t0);
|
96
|
+
if (qdt != "") {
|
97
|
+
if (t0 > qdt) {
|
98
|
+
console.log(t0);
|
99
|
+
qd = '迟到';
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
qd = '正常';
|
103
|
+
console.log(qd);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
else qd = '正常';
|
107
|
+
var ccc = '%' + rows[0].stuid + '%';
|
108
|
+
db.query('SELECT * FROM records WHERE stuid LIKE ?;', ccc, (err, cards) => {
|
109
|
+
if (cards[0]) {
|
110
|
+
let user = {
|
111
|
+
result: "repetition",
|
112
|
+
idcard: rows[0].stuid,
|
113
|
+
name: rows[0].name
|
114
|
+
}
|
115
|
+
console.log(user);
|
116
|
+
res.send(user);
|
117
|
+
attend = user.idcard + " " + user.name;
|
118
|
+
myEmitter.emit('seen1');
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
var t = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
|
122
|
+
db.query('INSERT INTO records (stuid,name,type,room,time,qd) VALUES (?,?,?,?,?,?);', [rows[0].stuid, rows[0].name, rows[0].type, rooms[0].num, t, qd], function (err, result) {
|
123
|
+
if (qd == '迟到') {
|
124
|
+
let user = {
|
125
|
+
result: "late",
|
126
|
+
idcard: rows[0].stuid,
|
127
|
+
name: rows[0].name
|
128
|
+
}
|
129
|
+
console.log(user);
|
130
|
+
res.send(user);
|
131
|
+
attend = user.idcard + " " + user.name;
|
132
|
+
myEmitter.emit('seen');
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
let user = {
|
136
|
+
result: "success",
|
137
|
+
idcard: rows[0].stuid,
|
138
|
+
name: rows[0].name
|
139
|
+
}
|
140
|
+
console.log(user);
|
141
|
+
res.send(user);
|
142
|
+
attend = user.idcard + " " + user.name;
|
143
|
+
|
144
|
+
myEmitter.emit('seen');
|
145
|
+
}
|
146
|
+
});
|
147
|
+
}
|
148
|
+
})
|
149
|
+
|
150
|
+
});
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
let user = {
|
156
|
+
result: "failed",
|
157
|
+
mes: req.body.id,
|
158
|
+
reason: "not found"
|
159
|
+
}
|
160
|
+
console.log(user);
|
161
|
+
res.send(user);
|
162
|
+
}
|
163
|
+
});
|
164
|
+
});
|
165
|
+
});
|
166
|
+
|
167
|
+
|
168
|
+
router.get('/', (req, res, next) => {
|
169
|
+
let user = {
|
170
|
+
result: "failed",
|
171
|
+
reason: "not found"
|
172
|
+
}
|
173
|
+
console.log(user);
|
174
|
+
res.send(user);
|
175
|
+
});
|
176
|
+
|
177
|
+
router.post('/login', (req, res, next) => {
|
178
|
+
db.query('SELECT * FROM admins WHERE username = ?;', req.body.usernameinput, (err, row) => {
|
179
|
+
if (row != "") {
|
180
|
+
if (req.body.passwordinput == row[0].password) {
|
181
|
+
if (row[0].type == 0)
|
182
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
183
|
+
else if (row[0].type == 1)
|
184
|
+
res.send({ 'status': 'success', 'sign': 3 });
|
185
|
+
// else
|
186
|
+
// res.send({ 'status': 'success', 'sign': 4 });
|
187
|
+
}
|
188
|
+
else {
|
189
|
+
res.send({ 'status': 'success', 'sign': 1 });
|
190
|
+
}
|
191
|
+
}
|
192
|
+
else {
|
193
|
+
res.send({ 'status': 'success', 'sign': 2 });
|
194
|
+
}
|
195
|
+
});
|
196
|
+
});
|
197
|
+
|
198
|
+
//注册新加
|
199
|
+
router.post('/register', (req, res, next) => {
|
200
|
+
const { username, password, type } = req.body;
|
201
|
+
db.query('SELECT * FROM admins WHERE username = ?', username, (err, row) => {
|
202
|
+
if (err) {
|
203
|
+
return res.status(500).send({ 'status': 'error', 'message': '数据库错误' });
|
204
|
+
}
|
205
|
+
if (row.length > 0) {
|
206
|
+
return res.send({ 'status': 'error', 'message': '用户名已存在' });
|
207
|
+
}
|
208
|
+
|
209
|
+
db.query('INSERT INTO admins (username, password, type) VALUES (?, ?, ?)', [username, password, type], (err, result) => {
|
210
|
+
if (err) {
|
211
|
+
return res.status(500).send({ 'status': 'error', 'message': '注册失败' });
|
212
|
+
}
|
213
|
+
res.send({ 'status': 'success', 'message': '注册成功' });
|
214
|
+
});
|
215
|
+
});
|
216
|
+
});
|
217
|
+
|
218
|
+
router.get('/user/logincheck', (req, res, next) => {
|
219
|
+
const { usernameinput, passwordinput, usertype } = req.query;
|
220
|
+
db.query('SELECT * FROM admins WHERE username = ? AND password = ?', [usernameinput, passwordinput], (err, row) => {
|
221
|
+
if (err) {
|
222
|
+
return res.status(500).send({ 'status': 'error', 'message': '数据库错误' });
|
223
|
+
}
|
224
|
+
if (row.length > 0) {
|
225
|
+
if (usertype === '0' && row[0].type === 0) {
|
226
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
227
|
+
} else if (usertype === '1' && row[0].type !== 0) {
|
228
|
+
res.send({ 'status': 'success', 'sign': 3 });
|
229
|
+
} else {
|
230
|
+
res.send({ 'status': 'success', 'sign': 1 });
|
231
|
+
}
|
232
|
+
} else {
|
233
|
+
res.send({ 'status': 'success', 'sign': 2 });
|
234
|
+
}
|
235
|
+
});
|
236
|
+
});
|
237
|
+
|
238
|
+
router.post('/timesearchrt', (req, res, next) => {
|
239
|
+
console.log("1");
|
240
|
+
if (req.body.sign == 0) {
|
241
|
+
btrt = '1970-01-01 00:00:00';
|
242
|
+
etrt = '2100-01-01 00:00:00';
|
243
|
+
console.log("2");
|
244
|
+
}
|
245
|
+
else if (req.body.sign == 1) {
|
246
|
+
btrt = req.body.bt;
|
247
|
+
etrt = req.body.et;
|
248
|
+
qdt = req.body.et;
|
249
|
+
}
|
250
|
+
else if (req.body.sign == 2) {
|
251
|
+
var time = new Date();
|
252
|
+
btrt = time.getFullYear() + '-' + ("0" + (time.getMonth() + 1)).slice(-2) + '-' + ("0" + time.getDate()).slice(-2) + ' 00:00:00';
|
253
|
+
etrt = time.getFullYear() + '-' + ("0" + (time.getMonth() + 1)).slice(-2) + '-' + ("0" + time.getDate()).slice(-2) + ' ' + req.body.et;
|
254
|
+
qdt = req.body.et;
|
255
|
+
}
|
256
|
+
res.send({ 'status': 'success' });
|
257
|
+
});
|
258
|
+
|
259
|
+
router.post('/timesearch', (req, res, next) => {
|
260
|
+
if (req.body.sign == 0) {
|
261
|
+
bt = '1970-01-01 00:00:00';
|
262
|
+
et = '2100-01-01 00:00:00';
|
263
|
+
}
|
264
|
+
else if (req.body.sign == 1) {
|
265
|
+
bt = req.body.bt;
|
266
|
+
et = req.body.et;
|
267
|
+
}
|
268
|
+
res.send({ 'status': 'success', 'la': late, 'no': normal });
|
269
|
+
});
|
270
|
+
|
271
|
+
// function updateSearchParam(param, sign, id) {
|
272
|
+
// if (sign == 0) {
|
273
|
+
// param = "%";
|
274
|
+
// } else {
|
275
|
+
// param = "%" + id + "%";
|
276
|
+
// }
|
277
|
+
// }
|
278
|
+
|
279
|
+
router.post('/qdtime', (req, res, next) => {
|
280
|
+
if (req.body.sign == 0) {
|
281
|
+
qdt = "";
|
282
|
+
}
|
283
|
+
else {
|
284
|
+
qdt = req.body.time_h + ':' + req.body.time_m + ':' + req.body.time_s;
|
285
|
+
}
|
286
|
+
res.send({ 'status': 'success', 'la': late, 'no': normal });
|
287
|
+
});
|
288
|
+
|
289
|
+
router.post('/idsearch', (req, res, next) => {
|
290
|
+
if (req.body.sign == 0) {
|
291
|
+
mem = "%";
|
292
|
+
}
|
293
|
+
else {
|
294
|
+
mem = "%" + req.body.id + "%";
|
295
|
+
}
|
296
|
+
|
297
|
+
res.send({ 'status': 'success' });
|
298
|
+
});
|
299
|
+
|
300
|
+
router.post('/roomsearch', (req, res, next) => {
|
301
|
+
if (req.body.sign == 0) {
|
302
|
+
rom = "%";
|
303
|
+
}
|
304
|
+
else {
|
305
|
+
rom = "%" + req.body.id + "%";
|
306
|
+
}
|
307
|
+
res.send({ 'status': 'success' });
|
308
|
+
});
|
309
|
+
|
310
|
+
router.post('/adminsearch', (req, res, next) => {
|
311
|
+
if (req.body.sign == 0) {
|
312
|
+
adm = "%";
|
313
|
+
}
|
314
|
+
else {
|
315
|
+
adm = "%" + req.body.id + "%";
|
316
|
+
}
|
317
|
+
res.send({ 'status': 'success' });
|
318
|
+
});
|
319
|
+
|
320
|
+
//学号
|
321
|
+
router.post('/inputcheck0', (req, res, next) => {
|
322
|
+
db.query('SELECT * FROM members WHERE stuid = ?;', req.body.idinput, (err, row) => {
|
323
|
+
if (row != "") {
|
324
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
325
|
+
}
|
326
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
327
|
+
});
|
328
|
+
});
|
329
|
+
|
330
|
+
//卡号
|
331
|
+
router.post('/inputcheck1', (req, res, next) => {
|
332
|
+
var idinput = "%" + req.body.idinput + ";%";
|
333
|
+
db.query('SELECT * FROM members WHERE cardid LIKE ? OR cardid = ?;', [idinput, req.body.idinput], (err, row) => {
|
334
|
+
if (row != "") {
|
335
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
336
|
+
}
|
337
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
338
|
+
});
|
339
|
+
});
|
340
|
+
|
341
|
+
//房间号
|
342
|
+
router.post('/inputcheck2', (req, res, next) => {
|
343
|
+
db.query('SELECT * FROM rooms WHERE num = ?;', req.body.idinput, (err, row) => {
|
344
|
+
if (row != "") {
|
345
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
346
|
+
}
|
347
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
348
|
+
});
|
349
|
+
});
|
350
|
+
|
351
|
+
//房间地址
|
352
|
+
router.post('/inputcheck3', (req, res, next) => {
|
353
|
+
var idinput = "%" + req.body.idinput + ";%";
|
354
|
+
db.query('SELECT * FROM rooms WHERE mac LIKE ? OR mac = ?;', [idinput, req.body.idinput], (err, row) => {
|
355
|
+
if (row != "") {
|
356
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
357
|
+
}
|
358
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
359
|
+
});
|
360
|
+
});
|
361
|
+
|
362
|
+
router.post('/inputcheck4', (req, res, next) => {
|
363
|
+
db.query('SELECT * FROM admins WHERE username = ?;', req.body.usernameinput, (err, row) => {
|
364
|
+
if (row != "") {
|
365
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
366
|
+
}
|
367
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
368
|
+
});
|
369
|
+
});
|
370
|
+
|
371
|
+
router.get('/list', (req, res, next) => {
|
372
|
+
db.query('SELECT * FROM members WHERE stuid LIKE ? ORDER BY id DESC;', mem, (err, rows) => {
|
373
|
+
let rets = [];
|
374
|
+
if (rows) {
|
375
|
+
rows.forEach(row => {
|
376
|
+
let user = {
|
377
|
+
id: row.id,
|
378
|
+
stuid: row.stuid,
|
379
|
+
name: row.name,
|
380
|
+
cardid: row.cardid,
|
381
|
+
type: row.type
|
382
|
+
}
|
383
|
+
rets.push(user);
|
384
|
+
});
|
385
|
+
let retdata = {
|
386
|
+
code: 0,
|
387
|
+
msg: "",
|
388
|
+
count: 10,
|
389
|
+
data: rets
|
390
|
+
}
|
391
|
+
res.send(JSON.stringify(retdata));
|
392
|
+
}
|
393
|
+
});
|
394
|
+
});
|
395
|
+
|
396
|
+
router.get('/recordlistrt', (req, res, next) => {
|
397
|
+
late = 0; normal = 0;
|
398
|
+
sw = 'SELECT * FROM records WHERE time BETWEEN \'' + btrt + '\' AND \'' + etrt + '\' ORDER BY time DESC;'
|
399
|
+
db.query(sw, (err, rows) => {
|
400
|
+
let rets = [];
|
401
|
+
rows.forEach(row => {
|
402
|
+
let user = {
|
403
|
+
id: row.id,
|
404
|
+
stuid: row.stuid,
|
405
|
+
name: row.name,
|
406
|
+
type: row.type,
|
407
|
+
room: row.room,
|
408
|
+
time: row.time
|
409
|
+
}
|
410
|
+
rets.push(user);
|
411
|
+
});
|
412
|
+
let retdata = {
|
413
|
+
code: 0,
|
414
|
+
msg: "",
|
415
|
+
count: 10,
|
416
|
+
data: rets
|
417
|
+
}
|
418
|
+
res.send(JSON.stringify(retdata));
|
419
|
+
});
|
420
|
+
});
|
421
|
+
|
422
|
+
|
423
|
+
router.get('/recordlist', (req, res, next) => {
|
424
|
+
late = 0; normal = 0;
|
425
|
+
sw = 'SELECT * FROM records WHERE time BETWEEN \'' + bt + '\' AND \'' + et + '\' ORDER BY time DESC;'
|
426
|
+
db.query(sw, (err, rows) => {
|
427
|
+
let rets = [];
|
428
|
+
rows.forEach(row => {
|
429
|
+
let user = {
|
430
|
+
id: row.id,
|
431
|
+
stuid: row.stuid,
|
432
|
+
name: row.name,
|
433
|
+
type: row.type,
|
434
|
+
room: row.room,
|
435
|
+
time: row.time,
|
436
|
+
qd: row.qd
|
437
|
+
}
|
438
|
+
if (user.qd == '迟到') {
|
439
|
+
late = late + 1;
|
440
|
+
}
|
441
|
+
else normal = normal + 1;
|
442
|
+
rets.push(user);
|
443
|
+
});
|
444
|
+
let retdata = {
|
445
|
+
code: 0,
|
446
|
+
msg: "",
|
447
|
+
count: 10,
|
448
|
+
data: rets
|
449
|
+
}
|
450
|
+
res.send(JSON.stringify(retdata));
|
451
|
+
});
|
452
|
+
});
|
453
|
+
|
454
|
+
// 使用router对象来定义路由
|
455
|
+
// router.get('/searchStudentsByStuid', function (req, res) {
|
456
|
+
// var studentId = req.query.stuid;
|
457
|
+
// var page = parseInt(req.query.page) || 1; // 默认第一页
|
458
|
+
// var limit = parseInt(req.query.limit) || 10; // 默认每页10条记录
|
459
|
+
// var sort = req.query.sort || 'time'; // 默认按time字段排序
|
460
|
+
// var order = req.query.order || 'desc'; // 默认降序
|
461
|
+
|
462
|
+
// // 计算SQL查询的偏移量
|
463
|
+
// var offset = (page - 1) * limit;
|
464
|
+
|
465
|
+
// // 修改SQL查询语句以支持分页
|
466
|
+
// var sqlQuery = 'SELECT * FROM records WHERE stuid = ? ORDER BY ' + sort + ' ' + order + ' LIMIT ?, ?';
|
467
|
+
// db.query(sqlQuery, [studentId, offset, limit], function (err, results) {
|
468
|
+
// if (err) {
|
469
|
+
// console.error('Database query failed:', err);
|
470
|
+
// return res.status(500).json({ code: -1, msg: 'Database query failed' });
|
471
|
+
// }
|
472
|
+
|
473
|
+
// // 可以在这里添加获取总记录数的逻辑,用于前端分页控件
|
474
|
+
// var countQuery = 'SELECT COUNT(*) AS count FROM records WHERE stuid = ?';
|
475
|
+
// db.query(countQuery, [studentId], function (err, countResult) {
|
476
|
+
// if (err) {
|
477
|
+
// console.error('Count query failed:', err);
|
478
|
+
// return res.status(500).json({ code: -1, msg: 'Count query failed' });
|
479
|
+
// }
|
480
|
+
|
481
|
+
// // 返回分页结果和总记录数
|
482
|
+
// res.json({
|
483
|
+
// code: 0,
|
484
|
+
// msg: "查询成功",
|
485
|
+
// count: countResult[0].count, // 总记录数
|
486
|
+
// data: results.map(function (row) {
|
487
|
+
// // 可以根据需要转换或格式化结果数据
|
488
|
+
// return {
|
489
|
+
// stuid: row.stuid,
|
490
|
+
// name: row.name,
|
491
|
+
// type: row.type,
|
492
|
+
// room: row.room,
|
493
|
+
// time: row.time,
|
494
|
+
// qd: row.qd
|
495
|
+
// };
|
496
|
+
// })
|
497
|
+
// });
|
498
|
+
// });
|
499
|
+
// });
|
500
|
+
// });
|
501
|
+
|
502
|
+
router.get('/combinedSearch', function (req, res) {
|
503
|
+
// 获取查询参数,并进行非空校验
|
504
|
+
var studentId = req.query.stuid || '';
|
505
|
+
var roomNumber = req.query.roomNumber || '';
|
506
|
+
var page = parseInt(req.query.page) || 1;
|
507
|
+
var limit = parseInt(req.query.limit) || 10;
|
508
|
+
var sort = req.query.sort || 'time';
|
509
|
+
var order = req.query.order || 'desc';
|
510
|
+
|
511
|
+
// 校验输入是否为空
|
512
|
+
if (!studentId || !roomNumber) {
|
513
|
+
return res.status(400).json({ code: -1, msg: '学号和房间号不能为空' });
|
514
|
+
}
|
515
|
+
|
516
|
+
// 构建SQL查询语句
|
517
|
+
var sqlQuery = 'SELECT * FROM records WHERE stuid LIKE ? AND room LIKE ? ORDER BY ' + sort + ' ' + order + ' LIMIT ?, ?';
|
518
|
+
var params = [studentId, roomNumber, (page - 1) * limit, limit];
|
519
|
+
|
520
|
+
// 执行数据库查询
|
521
|
+
db.query(sqlQuery, params, function (err, results) {
|
522
|
+
if (err) {
|
523
|
+
console.error('Database query failed:', err);
|
524
|
+
return res.status(500).json({ code: -1, msg: '数据库查询失败' });
|
525
|
+
}
|
526
|
+
|
527
|
+
// 获取总记录数的逻辑
|
528
|
+
var countQuery = 'SELECT COUNT(*) AS count FROM records WHERE stuid LIKE ? AND room LIKE ?';
|
529
|
+
var countParams = [studentId, roomNumber];
|
530
|
+
|
531
|
+
db.query(countQuery, countParams, function (err, countResult) {
|
532
|
+
if (err) {
|
533
|
+
console.error('Count query failed:', err);
|
534
|
+
return res.status(500).json({ code: -1, msg: 'Count query failed' });
|
535
|
+
}
|
536
|
+
|
537
|
+
// 返回分页结果和总记录数
|
538
|
+
res.json({
|
539
|
+
code: 0,
|
540
|
+
msg: "Query successful",
|
541
|
+
count: countResult[0].count, // 总记录数
|
542
|
+
data: results.map(function (row) {
|
543
|
+
// 格式化结果数据
|
544
|
+
return {
|
545
|
+
stuid: row.stuid,
|
546
|
+
name: row.name,
|
547
|
+
type: row.type,
|
548
|
+
room: row.room,
|
549
|
+
time: row.time,
|
550
|
+
qd: row.qd
|
551
|
+
};
|
552
|
+
})
|
553
|
+
});
|
554
|
+
});
|
555
|
+
});
|
556
|
+
});
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
router.get('/roomslist', (req, res, next) => {
|
561
|
+
db.query('SELECT * FROM rooms WHERE num LIKE ? ORDER BY id DESC;', rom, (err, rows) => {
|
562
|
+
let rets = [];
|
563
|
+
rows.forEach(row => {
|
564
|
+
let user = {
|
565
|
+
id: row.id.toString(),
|
566
|
+
num: row.num.toString(),
|
567
|
+
mac: row.mac
|
568
|
+
}
|
569
|
+
rets.push(user);
|
570
|
+
});
|
571
|
+
let retdata = {
|
572
|
+
code: 0,
|
573
|
+
msg: "",
|
574
|
+
count: 10,
|
575
|
+
data: rets
|
576
|
+
}
|
577
|
+
res.send(JSON.stringify(retdata));
|
578
|
+
});
|
579
|
+
});
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
router.get('/adminslist', (req, res, next) => {
|
584
|
+
db.query('SELECT * FROM admins WHERE username LIKE ? ORDER BY id DESC;', adm, (err, rows) => {
|
585
|
+
let rets = [];
|
586
|
+
rows.forEach(row => {
|
587
|
+
let user = {
|
588
|
+
id: row.id,
|
589
|
+
username: row.username,
|
590
|
+
password: row.password
|
591
|
+
}
|
592
|
+
rets.push(user);
|
593
|
+
});
|
594
|
+
let retdata = {
|
595
|
+
code: 0,
|
596
|
+
msg: "",
|
597
|
+
count: 10,
|
598
|
+
data: rets
|
599
|
+
}
|
600
|
+
res.send(JSON.stringify(retdata));
|
601
|
+
});
|
602
|
+
});
|
603
|
+
|
604
|
+
// router.post('/update_password', (req, res, next) => {
|
605
|
+
// // 从请求体中获取密码
|
606
|
+
// const { current_password, new_password, confirm_password } = req.body;
|
607
|
+
|
608
|
+
// // 验证新密码和确认密码是否一致
|
609
|
+
// if (new_password !== confirm_password) {
|
610
|
+
// return res.status(400).send({ 'status': 'error', 'message': 'New password and confirm password do not match.' });
|
611
|
+
// }
|
612
|
+
|
613
|
+
// // 检查密码是否已更改
|
614
|
+
// if (!new_password || !current_password) {
|
615
|
+
// return res.status(400).send({ 'status': 'error', 'message': 'Please provide both current and new passwords.' });
|
616
|
+
// }
|
617
|
+
|
618
|
+
// // 查询数据库以验证当前密码
|
619
|
+
// db.query('SELECT * FROM admins WHERE username = ? AND password = ?', [req.body.username, current_password], (err, row) => {
|
620
|
+
// if (err) {
|
621
|
+
// return res.status(500).send({ 'status': 'error', 'message': 'Database error.' });
|
622
|
+
// }
|
623
|
+
// if (!row || row.length === 0) {
|
624
|
+
// return res.status(400).send({ 'status': 'error', 'message': 'Current password is incorrect.' });
|
625
|
+
// }
|
626
|
+
|
627
|
+
// // 更新密码
|
628
|
+
// db.query('UPDATE admins SET password = ? WHERE username = ?', [new_password, req.body.username], (err, result) => {
|
629
|
+
// if (err) {
|
630
|
+
// return res.status(500).send({ 'status': 'error', 'message': 'Error updating password.' });
|
631
|
+
// }
|
632
|
+
// if (result.affectedRows === 0) {
|
633
|
+
// return res.status(400).send({ 'status': 'error', 'message': 'No user found with that username.' });
|
634
|
+
// }
|
635
|
+
|
636
|
+
// // 密码更新成功
|
637
|
+
// res.send({ 'status': 'success', 'message': 'Password updated successfully.' });
|
638
|
+
// });
|
639
|
+
// });
|
640
|
+
// });
|
641
|
+
|
642
|
+
module.exports = router;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
|
4
|
+
const app = express();
|
5
|
+
app.use(express.json());
|
6
|
+
|
7
|
+
router.post('/', (req, res, next) => {
|
8
|
+
var datetime = new Date()
|
9
|
+
DT = {
|
10
|
+
date: datetime.toLocaleDateString(),
|
11
|
+
time: datetime.toLocaleTimeString(),
|
12
|
+
}
|
13
|
+
res.send(JSON.stringify(DT))
|
14
|
+
});
|
15
|
+
|
16
|
+
module.exports = router;
|