pbl.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. // ROUTES FOR OUR API
  2. // =============================================================================
  3. var express = require("express");
  4. var request = require("request");
  5. var bcrypt = require("bcryptjs");
  6. var router = express.Router(); // get an instance of the express Router
  7. const querystring = require("querystring");
  8. var mysql = require("./mysql");
  9. // const _mysqlLabor = ["123.58.32.151", "evenYT"]; //edu數據庫信息
  10. // const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
  11. const _mysqlLabor = ["172.16.12.5", "evenYT"]; //edu數據庫信息
  12. const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
  13. var crypto = require("crypto");
  14. var https = require("https");
  15. //統壹處理區域
  16. router.use(async function(req, res, next) {
  17. await asynnext(req, res, next);
  18. //// make sure we go to the next routes and don't stop here
  19. //res.end("");
  20. });
  21. /**
  22. * @des 參數解釋同上
  23. */
  24. function asynnext(req, res, next) {
  25. //異步處理
  26. return new Promise(async(resolve, reject) => {
  27. next();
  28. //resolve(true);aa
  29. });
  30. }
  31. /*測試*/
  32. router.route("/a").all((req, res, next) => {
  33. var json = queryString(req.url);
  34. getmysql(req, res, "a", json["ph"], json["pa"]);
  35. });
  36. router.route("/b").all((req, res, next) => {
  37. var json = queryString(req.url);
  38. getmysql(req, res, "b", json["ph"], json["pa"]);
  39. });
  40. /* 根据市级用户查询评审员 */
  41. router.route("/selectReviewer").all((req, res, next) => {
  42. var json = queryString(req.url);
  43. getmysql(
  44. req,
  45. res,
  46. "selectReviewer",
  47. json["uid"],
  48. json["cn"],
  49. json["page"],
  50. 10
  51. );
  52. });
  53. /* 市级区县管理接口 */
  54. router.route("/selectCReviewer").all((req, res, next) => {
  55. var json = queryString(req.url);
  56. getmysql(
  57. req,
  58. res,
  59. "selectCReviewer",
  60. json["uid"],
  61. json["cn"],
  62. json["page"],
  63. 10
  64. );
  65. });
  66. /* 修改评审员 */
  67. router.route("/updateReviewer").all((req, res, next) => {
  68. var json = queryString(req.url);
  69. getmysql(
  70. req,
  71. res,
  72. "updateReviewer",
  73. json["n"],
  74. json["p"],
  75. json["t"],
  76. json["s"],
  77. json["uid"]
  78. );
  79. });
  80. /* 删除评审员 */
  81. router.route("/deleteReviewer").all((req, res, next) => {
  82. var json = queryString(req.url);
  83. getmysql(req, res, "deleteReviewer", json["uid"]);
  84. });
  85. /* 查询区县案例 */
  86. router.route("/selecAnliBox").all((req, res, next) => {
  87. var json = queryString(req.url);
  88. getmysql(req, res, "selecAnliBox", json["title"]);
  89. });
  90. /* 查询市级案例 */
  91. router.route("/selecAnliBox1").all((req, res, next) => {
  92. var json = queryString(req.url);
  93. getmysql(req, res, "selecAnliBox1", json["title"]);
  94. });
  95. /* 查询省级案例 */
  96. router.route("/selecAnliBox2").all((req, res, next) => {
  97. var json = queryString(req.url);
  98. getmysql(req, res, "selecAnliBox2");
  99. });
  100. /* 案例征集查询通知公告 */
  101. router.route("/selectRaceNotice").all((req, res, next) => {
  102. var json = queryString(req.url);
  103. getmysql(req, res, "selectRaceNotice", json["page"], 10);
  104. });
  105. /* 案例征集查询通知公告详情 */
  106. router.route("/getRaceNoticeDetail").all((req, res, next) => {
  107. var json = queryString(req.url);
  108. getmysql(req, res, "getRaceNoticeDetail", json["nid"]);
  109. });
  110. /* 案例征集发送通知 */
  111. router.route("/insertRaceNote").all((req, res, next) => {
  112. var json = queryString(req.url);
  113. getmysql(req, res, "insertRaceNote", json["t"], json["c"], json["uid"]);
  114. });
  115. //新增赛事项目
  116. router.route("/addRace").all((req, res, next) => {
  117. if (req.body[0]) {
  118. p = [
  119. req.body[0].uid,
  120. req.body[0].info,
  121. req.body[0].over,
  122. req.body[0].pro,
  123. req.body[0].act,
  124. req.body[0].exc,
  125. req.body[0].res,
  126. ];
  127. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "addRace"); //執行存儲過程
  128. mysql.usselect(p, function(ret) {
  129. let course = req.body[0].courseType;
  130. let courseId = ret[0][0].id;
  131. let userid = req.body[0].uid;
  132. delCourseType1(course, courseId, userid);
  133. res.end(JSON.stringify({ courseId: courseId, success: 1 }));
  134. });
  135. }
  136. });
  137. function delCourseType1(course, courseId, userid) {
  138. let _courseId = courseId;
  139. var _userdata = [_courseId];
  140. _userdata.unshift(_mysqlLabor[0], _mysqlLabor[1], "delete_courseType1");
  141. mysql.usselect(_userdata, function(ret) {
  142. // console.log(ret);
  143. });
  144. setTimeout(() => {
  145. addCourseType1(userid, course, _courseId);
  146. }, 1000);
  147. }
  148. function addCourseType1(userid, course, _courseId) {
  149. var _uid = userid;
  150. var _courses = _courseId;
  151. var _tid = JSON.parse(course);
  152. for (let i = 0; i < _tid.length; i++) {
  153. if (_tid[i] == "") {
  154. continue;
  155. }
  156. var _userdata = [_courses, _tid[i], _uid];
  157. _userdata.unshift(_mysqlLabor[0], _mysqlLabor[1], "add_courseType1");
  158. mysql.usselect(_userdata, function(ret) {
  159. // console.log(ret);
  160. });
  161. }
  162. }
  163. //修改赛事项目
  164. router.route("/updateRace").all((req, res, next) => {
  165. if (req.body[0]) {
  166. p = [
  167. req.body[0].id,
  168. req.body[0].info,
  169. req.body[0].over,
  170. req.body[0].pro,
  171. req.body[0].act,
  172. req.body[0].exc,
  173. req.body[0].res,
  174. ];
  175. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "updateRace"); //執行存儲過程
  176. mysql.usselect(p, function(ret) {
  177. let course = req.body[0].courseType;
  178. let courseId = req.body[0].id;
  179. let userid = req.body[0].uid;
  180. delCourseType1(course, courseId, userid);
  181. res.end(JSON.stringify({ success: 1 }));
  182. });
  183. }
  184. });
  185. //查询赛事项目列表
  186. router.route("/selectRaceList").all((req, res, next) => {
  187. var json = queryString(req.url);
  188. getmysql(req, res, "selectRaceList", json["uid"], json["t"]);
  189. });
  190. //修改赛事状态
  191. router.route("/updateRaceState").all((req, res, next) => {
  192. var json = queryString(req.url);
  193. getmysql(req, res, "updateRaceState", json["id"], json["s"]);
  194. });
  195. //查询赛事项目详情
  196. router.route("/selectRaceDetail").all((req, res, next) => {
  197. var json = queryString(req.url);
  198. getmysql(req, res, "selectRaceDetail", json["id"]);
  199. });
  200. //race 查询学校
  201. router.route("/getSchool").all((req, res, next) => {
  202. var json = queryString(req.url);
  203. getmysql(req, res, "getSchool", json["n"]);
  204. });
  205. //根据区级管理者查询案例
  206. router.route("/selectAnliList").all((req, res, next) => {
  207. var json = queryString(req.url);
  208. getmysql(
  209. req,
  210. res,
  211. "selectAnliList",
  212. json["typea"],
  213. json["typeb"],
  214. json["typec"],
  215. json["typed"],
  216. json["typeE"],
  217. json["cn"],
  218. json["cid"],
  219. json["title"],
  220. json["page"],
  221. 10
  222. );
  223. });
  224. //根据市级管理者查询案例
  225. router.route("/selectAnliList1").all((req, res, next) => {
  226. var json = queryString(req.url);
  227. getmysql(
  228. req,
  229. res,
  230. "selectAnliList1",
  231. json["typea"],
  232. json["typeb"],
  233. json["typec"],
  234. json["typed"],
  235. json["typeE"],
  236. json["cn"],
  237. json["cid"],
  238. json["title"],
  239. json["page"],
  240. 10
  241. );
  242. });
  243. //根据省级级管理者查询案例
  244. router.route("/selectAnliList2").all((req, res, next) => {
  245. var json = queryString(req.url);
  246. getmysql(
  247. req,
  248. res,
  249. "selectAnliList2",
  250. json["typea"],
  251. json["typeb"],
  252. json["typec"],
  253. json["typed"],
  254. json["typeE"],
  255. json["cn"],
  256. json["cid"],
  257. json["title"],
  258. json["page"],
  259. 10
  260. );
  261. });
  262. //删除案例
  263. router.route("/deleteAnli").all((req, res, next) => {
  264. var json = queryString(req.url);
  265. getmysql(req, res, "deleteAnli", json["id"]);
  266. });
  267. //根据区县管理者查询评分
  268. router.route("/selectPoint").all((req, res, next) => {
  269. var json = queryString(req.url);
  270. getmysql(
  271. req,
  272. res,
  273. "selectPoint",
  274. json["typea"],
  275. json["typeb"],
  276. json["typec"],
  277. json["typed"],
  278. json["typeE"],
  279. json["cn"],
  280. json["cid"],
  281. json["title"],
  282. json["page"],
  283. 10
  284. );
  285. });
  286. //根据市级管理者查询评分
  287. router.route("/selectPoint1").all((req, res, next) => {
  288. var json = queryString(req.url);
  289. getmysql(
  290. req,
  291. res,
  292. "selectPoint1",
  293. json["typea"],
  294. json["typeb"],
  295. json["typec"],
  296. json["typed"],
  297. json["typeE"],
  298. json["cn"],
  299. json["cid"],
  300. json["title"],
  301. json["page"],
  302. 10
  303. );
  304. });
  305. //根据市级管理者查询全部评分
  306. router.route("/selectPointAll").all((req, res, next) => {
  307. var json = queryString(req.url);
  308. getmysql(
  309. req,
  310. res,
  311. "selectPointAll",
  312. json["typea"],
  313. json["typeb"],
  314. json["typec"],
  315. json["typed"],
  316. json["typeE"],
  317. json["cn"],
  318. json["cid"],
  319. json["title"]
  320. );
  321. });
  322. //查询分配案例
  323. router.route("/selectCaseUser").all((req, res, next) => {
  324. var json = queryString(req.url);
  325. getmysql(req, res, "select_case", json["uid"]);
  326. });
  327. //分配案例
  328. router.route("/insertCase").all((req, res, next) => {
  329. if (req.body[0]) {
  330. p = [req.body[0].uid, req.body[0].box];
  331. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "insertCase"); //執行存儲過程
  332. mysql.usselect(p, function(ret) {
  333. res.end(JSON.stringify({ success: 1 }));
  334. });
  335. }
  336. });
  337. //新增评分
  338. router.route("/addScore").all((req, res, next) => {
  339. postmysql(req, res, "addScore");
  340. });
  341. //查询评分
  342. router.route("/selectScore").all((req, res, next) => {
  343. var json = queryString(req.url);
  344. getmysql(req, res, "selectScore", json["rid"], json["suser"]);
  345. });
  346. //查询所有评分
  347. router.route("/selectAllScore").all((req, res, next) => {
  348. var json = queryString(req.url);
  349. getmysql(req, res, "selectAllScore");
  350. });
  351. //根据用户id查询评分
  352. router.route("/selectScoreByUid").all((req, res, next) => {
  353. var json = queryString(req.url);
  354. getmysql(req, res, "selectScoreByUid", json["uid"]);
  355. });
  356. //查询单个案例所有评分
  357. router.route("/selectAnliScore").all((req, res, next) => {
  358. var json = queryString(req.url);
  359. getmysql(req, res, "selectAnliScore", json["rid"]);
  360. });
  361. //赛事推荐
  362. router.route("/updateRaceRec").all((req, res, next) => {
  363. var json = queryString(req.url);
  364. getmysql(req, res, "updateRaceRec", json["id"], json["rec"]);
  365. });
  366. //案例新项目登录接口
  367. router.route("/loginNewEvenManage").all((req, res, next) => {
  368. postmysql(req, res, "loginNewEvenManage");
  369. });
  370. //案例新项目创建用户接口
  371. router.route("/addNewRaceUser").all((req, res, next) => {
  372. postmysql(req, res, "addNewRaceUser");
  373. });
  374. //查询老师的信息
  375. router.route("/getRaceUser1").all((req, res, next) => {
  376. var json = queryString(req.url);
  377. getmysql(req, res, "getRaceUser1", json["uid"]);
  378. });
  379. //修改用户信息
  380. router.route("/updateRaceUser").all((req, res, next) => {
  381. postmysql(req, res, "updateRaceUser");
  382. });
  383. //race 查询学校
  384. router.route("/getSchool1").all((req, res, next) => {
  385. var json = queryString(req.url);
  386. getmysql(req, res, "getSchool1", json["n"]);
  387. });
  388. //查询赛事项目列表
  389. router.route("/selectRaceList1").all((req, res, next) => {
  390. var json = queryString(req.url);
  391. getmysql(req, res, "selectRaceList1", json["uid"], json["t"], json["oid"], json["org"]);
  392. });
  393. //查询赛事分类及子分类
  394. router.route("/selectMatTypeYT").all((req, res, next) => {
  395. var json = queryString(req.url);
  396. getmysql(req, res, "selectMatTypeYT");
  397. });
  398. //查询Banner列表
  399. router.route("/selectAllBanner").all((req, res, next) => {
  400. var json = queryString(req.url);
  401. getmysql(req, res, "selectAllBanner", json["t"]);
  402. });
  403. /* 赛事修改密码 */
  404. router.route("/updatePassword1").post(function(req, res, next) {
  405. //mode的处理
  406. if (req.body[0]) {
  407. let p = [req.body[0].userid];
  408. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getPassword1"); //執行存儲過程
  409. mysql.usselect(p, function(ret) {
  410. var paJ = ret[0][0].password;
  411. var op = bcrypt.hashSync(req.body[0].opassword, bcrypt.genSaltSync(10));
  412. bcrypt.compare(req.body[0].opassword, paJ, function(err, result) {
  413. // console.log(result)
  414. if (result) {
  415. let p2 = [
  416. req.body[0].userid,
  417. bcrypt.hashSync(req.body[0].password, bcrypt.genSaltSync(10)),
  418. ];
  419. p2.unshift(_mysqlLabor[0], _mysqlLabor[1], "updatePassword1"); //執行存儲過程
  420. mysql.usselect(p2, function(ret) {
  421. res.end(JSON.stringify([{ success: 1 }]));
  422. });
  423. } else {
  424. res.end(JSON.stringify([{ success: 0 }]));
  425. }
  426. });
  427. });
  428. }
  429. });
  430. // 管理员查询项目下所有的评分
  431. router.route("/selectScoreByAdmin").all(function(req, res, next) {
  432. var json = queryString(req.url);
  433. getmysql(req, res, "selectScoreByAdmin", json["rid"]);
  434. })
  435. queryString = function(url) {
  436. var a = url.split("?");
  437. var json = querystring.parse(a[1]);
  438. return json;
  439. };
  440. //post存儲過程處理
  441. postmysql = function(req, res, functionname) {
  442. //mode的處理
  443. if (req.body[0]) {
  444. p = Object.values(req.body[0]);
  445. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  446. //執行存儲過程
  447. mysql.usselect(p, function(ret) {
  448. res.end(JSON.stringify(ret));
  449. });
  450. }
  451. };
  452. //post存儲過程處理
  453. postmysql2 = function(req, res, functionname) {
  454. //mode的處理
  455. if (req.body) {
  456. p = Object.values(req.body)[0].split(",");
  457. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  458. //執行存儲過程
  459. mysql.usselect(p, function(ret) {
  460. res.end(JSON.stringify(ret));
  461. });
  462. }
  463. };
  464. //post存儲過程處理
  465. postmysql3 = function(req, res, functionname) {
  466. //mode的處理
  467. if (req.body) {
  468. p = Object.values(req.body);
  469. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  470. //執行存儲過程
  471. mysql.usselect(p, function(ret) {
  472. res.end(JSON.stringify(ret));
  473. });
  474. }
  475. };
  476. //get獲取數據庫信息
  477. getmysql = function(req, res, functionname, ...p) {
  478. p = p || [];
  479. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  480. //執行存儲過程
  481. mysql.usselect(p, function(ret) {
  482. res.end(JSON.stringify(ret));
  483. }); //
  484. };
  485. //post存储过程处理
  486. userpostmysql = function(req, res, functionname) {
  487. //mode的处理
  488. if (req.body.mode) {
  489. p = req.body.mode.split(",");
  490. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  491. //执行存储过程
  492. mysql.usselect(p, function(ret) {
  493. res.end(JSON.stringify(ret));
  494. });
  495. }
  496. };
  497. //get获取数据库信息
  498. usergetmysql = function(req, res, functionname, ...p) {
  499. p = p || [];
  500. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  501. //执行存储过程
  502. mysql.usselect(p, function(ret) {
  503. res.end(JSON.stringify(ret));
  504. }); //
  505. };
  506. module.exports = router;