edurouter.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. // ROUTES FOR OUR API
  2. // =============================================================================
  3. var express = require('express');
  4. var bcrypt = require('bcryptjs');
  5. var router = express.Router(); // get an instance of the express Router
  6. const querystring = require('querystring');
  7. var mysql = require('./mysql');
  8. const { json } = require('express');
  9. // const _mysqlLabor = ["123.58.32.151", "LaborEdu"]; //edu數據庫信息
  10. const _mysqlLabor = ["172.16.12.5", "LaborEdu"]; // edu數據庫信息
  11. //統壹處理區域
  12. router.use(async function (req, res, next) {
  13. await asynnext(req, res, next);
  14. //// make sure we go to the next routes and don't stop here
  15. //res.end("");
  16. });
  17. /**
  18. * @des 參數解釋同上
  19. */
  20. function asynnext(req, res, next) {
  21. //異步處理
  22. return new Promise(async (resolve, reject) => {
  23. next();
  24. //resolve(true);
  25. });
  26. }
  27. router.route('/register').post(function (req, res, next) {
  28. //mode的处理
  29. if (req.body[0]) {
  30. // 0 用户名 1 用户密码 2用户身份 3 第三方id(可有可无)
  31. p = Object.values(req.body[0]); //获取用户密码
  32. //没有第三方id的处理
  33. // if (p.length < 4) {
  34. // p.push("")
  35. // }
  36. p[1] = bcrypt.hashSync(p[1], bcrypt.genSaltSync(10));
  37. //密码加密
  38. // bcrypt.hash(p[1], 10, function (err, hash) {
  39. // if (err) {
  40. // return next(err);
  41. // }
  42. // p[1] = hash;
  43. // });
  44. //参数拼接,注册
  45. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "add_register");
  46. //返回注册用户数据
  47. // mysql.usselect(p, function (ret) {
  48. // res.end(ret);
  49. // });
  50. mysql.usselect(p, function (ret) {
  51. res.end(JSON.stringify(ret));
  52. });
  53. }
  54. });
  55. router.route('/registerStudent').post(function (req, res, next) {
  56. //mode的处理
  57. if (req.body[0]) {
  58. // 0 用户名 1 用户密码 2用户身份 3 第三方id(可有可无)
  59. p = Object.values(req.body[0]); //获取用户密码
  60. p[1] = bcrypt.hashSync(p[1], bcrypt.genSaltSync(10));
  61. //参数拼接,注册
  62. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "add_registerStudent");
  63. mysql.usselect(p, function (ret) {
  64. res.end(JSON.stringify(ret));
  65. });
  66. }
  67. });
  68. /*登录接口*/
  69. router.route('/login').all((req, res, next) => {
  70. //mode的处理
  71. if (req.body[0]) {
  72. // 0 用户名 1 用户密码
  73. c = Object.values(req.body[0]); //获取用户密码
  74. p = [c[0]]
  75. // p[1] = bcrypt.hashSync(p[1], bcrypt.genSaltSync(10));
  76. var _password = [c[0]];
  77. _password.unshift(_mysqlLabor[0], _mysqlLabor[1], "select_password");
  78. mysql.usselect(_password, function (ret) {
  79. var _ret = ret
  80. var paJ = _ret[0][0].userpassword
  81. bcrypt.compare(c[1], paJ, function (err, result) {
  82. // console.log(result)
  83. if (result) {
  84. //参数拼接,登录
  85. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "select_login");
  86. //执行存储过程
  87. mysql.usselect(p, function (ret) {
  88. res.end(JSON.stringify({ status: "1", ...ret }));
  89. });
  90. } else {
  91. res.end(JSON.stringify([{ status: "0" }]));
  92. }
  93. })
  94. });
  95. // console.log(isEqual)
  96. }
  97. });
  98. //修改用户密码
  99. router.route('/updateUserPassword').all((req, res, next) => {
  100. req.body[0].p = bcrypt.hashSync(req.body[0].p, bcrypt.genSaltSync(10));
  101. postmysql(req, res, "updateUserPassword");
  102. });
  103. //获取班级数据
  104. router.route('/getClass').all((req, res, next) => {
  105. var json = queryString(req.url);
  106. getmysql(req, res, "select_class", json['username'], json['cn'], json['page'], 10);
  107. });
  108. //获取申请修改班级的数量
  109. router.route('/getClassC').all((req, res, next) => {
  110. getmysql(req, res, "select_updateClass");
  111. });
  112. //获取添加班级
  113. router.route('/insertClass').all((req, res, next) => {
  114. postmysql(req, res, "insert_class");
  115. });
  116. //删除班级
  117. router.route('/deleteClass').all((req, res, next) => {
  118. postmysql(req, res, "delete_class");
  119. });
  120. //删除班级
  121. router.route('/deleteZone').all((req, res, next) => {
  122. postmysql(req, res, "delete_zone");
  123. });
  124. //查询所有学校
  125. router.route('/getAllOrg').all((req, res, next) => {
  126. getmysql(req, res, "selectAll_org");
  127. });
  128. //查询课程
  129. router.route('/getCourse').all((req, res, next) => {
  130. var json = queryString(req.url);
  131. getmysql(req, res, "select_course", json['jid'], json['gid'], json['class'], json['cn'], json['page'], 10);
  132. });
  133. //根据课程id查询课程
  134. router.route('/getCourseByid').all((req, res, next) => {
  135. var json = queryString(req.url);
  136. getmysql(req, res, "select_courseBycid", json['cid']);
  137. });
  138. //查询消息
  139. router.route('/getNews').all((req, res, next) => {
  140. var json = queryString(req.url);
  141. getmysql(req, res, "select_news", json['uid'], json['page'], 15);
  142. });
  143. //查询教师端消息
  144. router.route('/getNewsTeacher').all((req, res, next) => {
  145. var json = queryString(req.url);
  146. getmysql(req, res, "select_news", json['uid'], json['page'], 10);
  147. });
  148. //根据消息id查询消息
  149. router.route('/getNewByid').all((req, res, next) => {
  150. var json = queryString(req.url);
  151. getmysql(req, res, "select_newsByid", json['nid']);
  152. });
  153. //获取家校区文章
  154. router.route('/getHomeByid').all((req, res, next) => {
  155. var json = queryString(req.url);
  156. getmysql(req, res, "select_homecampusByid", json['id']);
  157. });
  158. //删除家校区文章
  159. router.route('/deleteHome').all((req, res, next) => {
  160. postmysql(req, res, "delete_homecampus");
  161. });
  162. //查询课程详情
  163. router.route('/getCourseDetail').all((req, res, next) => {
  164. var json = queryString(req.url);
  165. getmysql(req, res, "select_courseDetail_teacher", json['cid']);
  166. });
  167. //根据家校区类型获取
  168. router.route('/getHomeByPid').all((req, res, next) => {
  169. var json = queryString(req.url);
  170. getmysql(req, res, "select_homecampusByPid", json['pid'], json['page'], 10);
  171. });
  172. //获取家校区
  173. router.route('/getHome').all((req, res, next) => {
  174. var json = queryString(req.url);
  175. getmysql(req, res, "select_homecampus", json['page'], 10);
  176. });
  177. //提交作业
  178. router.route('/submitWork').all((req, res, next) => {
  179. postmysql(req, res, "insert_works");
  180. });
  181. //查询这个老师底下的学生
  182. router.route('/getStudent').all((req, res, next) => {
  183. var json = queryString(req.url);
  184. getmysql(req, res, "select_student2", json['cuid'], json['cn'], json['class'], json['page'], 10);
  185. });
  186. //查询这个老师底下的学生提交的作业
  187. router.route('/getWorks').all((req, res, next) => {
  188. var json = queryString(req.url);
  189. getmysql(req, res, "select_works", json['bid'], json['isRate'], json['class'], json['name'], json['gid'], json['cid'], json['page'], 10);
  190. });
  191. //删除学生提交的作业
  192. router.route('/deleteWork').all((req, res, next) => {
  193. postmysql(req, res, "delete_works");
  194. });
  195. router.route('/findWorkRepeat').all((req, res, next) => {
  196. var json = queryString(req.url);
  197. getmysql(req, res, "select_workRepeat", json['cid'], json['uid'], json['hid']);
  198. });
  199. //查看学生提交的作业
  200. router.route('/getWork').all((req, res, next) => {
  201. var json = queryString(req.url);
  202. getmysql(req, res, "select_workByid", json['aid'], json['cid']);
  203. });
  204. //修改用户头像
  205. router.route('/UpdateUserS').all((req, res, next) => {
  206. postmysql(req, res, "update_userS");
  207. });
  208. //修改用户名字
  209. router.route('/UpdateUserName').all((req, res, next) => {
  210. postmysql(req, res, "update_userName");
  211. });
  212. //修改用户地区
  213. router.route('/UpdateUserDest').all((req, res, next) => {
  214. postmysql(req, res, "update_userDest");
  215. });
  216. //修改用户家长姓名
  217. router.route('/UpdateUserParent').all((req, res, next) => {
  218. postmysql(req, res, "update_userParent");
  219. });
  220. //修改用户家长姓名
  221. router.route('/UpdateUserClassName').all((req, res, next) => {
  222. postmysql(req, res, "update_userClassName");
  223. });
  224. //查看前四个作业
  225. router.route('/getWorkTopFour').all((req, res, next) => {
  226. var json = queryString(req.url);
  227. getmysql(req, res, "select_workTopFour", json['cid']);
  228. });
  229. //添加家校区文章
  230. router.route('/addHome').all((req, res, next) => {
  231. if (!req.body[0].p) {
  232. req.body[0].p = ""
  233. }
  234. postmysql(req, res, "insert_homecampus");
  235. });
  236. //管理端查询家校区文章
  237. router.route('/findHome').all((req, res, next) => {
  238. var json = queryString(req.url);
  239. getmysql(req, res, "select_homecampus_admin", json['pid'], json['page'], 10);
  240. });
  241. //对学生提交的作业评分
  242. router.route('/rate').all((req, res, next) => {
  243. postmysql(req, res, "rate_work");
  244. });
  245. //查看学生提交的作业
  246. router.route('/getWorkByUid').all((req, res, next) => {
  247. var json = queryString(req.url);
  248. getmysql(req, res, "select_workByUid", json['aid'], json['page'], 10);
  249. });
  250. //查出分组分类
  251. router.route('/getGroup').all((req, res, next) => {
  252. getmysql(req, res, "select_group_teacher");
  253. });
  254. //查看此老师的所有权限
  255. router.route('/getJuri').all((req, res, next) => {
  256. var json = queryString(req.url);
  257. getmysql(req, res, "select_juri_teacher", json['cid']);
  258. });
  259. //根据作业id查看作业
  260. router.route('/getWorkByWid').all((req, res, next) => {
  261. var json = queryString(req.url);
  262. getmysql(req, res, "select_workByWid", json['aid']);
  263. });
  264. //根据作业id查看作业
  265. router.route('/getWorkByWidT').all((req, res, next) => {
  266. var json = queryString(req.url);
  267. getmysql(req, res, "select_workByWid_teacher", json['aid']);
  268. });
  269. //添加课程
  270. router.route('/addCourse').all((req, res, next) => {
  271. postmysql(req, res, "insert_course");
  272. });
  273. //查询老师底下的课程
  274. router.route('/getCourseTeacher').all((req, res, next) => {
  275. var json = queryString(req.url);
  276. getmysql(req, res, "select_course_teacher", json['uid'], json['gid'], json['page'], 10);
  277. });
  278. //查询是否有重复的账号
  279. router.route('/findPhone').all((req, res, next) => {
  280. var json = queryString(req.url);
  281. getmysql(req, res, "select_username", json['phone']);
  282. });
  283. //查询是否有重复的账号
  284. router.route('/getUser').all((req, res, next) => {
  285. var json = queryString(req.url);
  286. getmysql(req, res, "select_userByUid", json['uid']);
  287. });
  288. //查询所有课程专区
  289. router.route('/getZone').all((req, res, next) => {
  290. getmysql(req, res, "select_zone");
  291. });
  292. //查询所有课程专区下的课程
  293. router.route('/getZoneClass').all((req, res, next) => {
  294. var json = queryString(req.url);
  295. getmysql(req, res, "select_zoneClass", json['bid'], json['page'], 10);
  296. });
  297. //查询所有课程专区下的课程
  298. router.route('/getZoneCourse').all((req, res, next) => {
  299. var json = queryString(req.url);
  300. getmysql(req, res, "select_zoneCourse", json['bid'], json['jid'], json['page'], 10);
  301. });
  302. //添加课程
  303. router.route('/addZone').all((req, res, next) => {
  304. postmysql(req, res, "insert_classZone");
  305. });
  306. //课程专区搜索的课程
  307. router.route('/getSearchCourse').all((req, res, next) => {
  308. var json = queryString(req.url);
  309. getmysql(req, res, "selectAll_courseSearch", json['t']);
  310. });
  311. //把课程添加进专区
  312. router.route('/addZoneCourse').all((req, res, next) => {
  313. postmysql(req, res, "insert_app");
  314. });
  315. //删除课程专区底下的课程
  316. router.route('/deleteZoneCourse').all((req, res, next) => {
  317. postmysql(req, res, "delete_app");
  318. });
  319. //添加banner
  320. router.route('/addBanner').all((req, res, next) => {
  321. postmysql(req, res, "insert_banner");
  322. });
  323. //获取banner
  324. router.route('/getBanner').all((req, res, next) => {
  325. getmysql(req, res, "select_banner");
  326. });
  327. //删除banner
  328. router.route('/deleteBanner').all((req, res, next) => {
  329. postmysql(req, res, "delete_banner");
  330. });
  331. //查询发现
  332. router.route('/getFind').all((req, res, next) => {
  333. var json = queryString(req.url);
  334. getmysql(req, res, "select_find", json['page'], 7);
  335. });
  336. //查询在学课程数量和作品数量
  337. router.route('/getNum').all((req, res, next) => {
  338. var json = queryString(req.url);
  339. getmysql(req, res, "select_workAndCourseNum", json['uid']);
  340. });
  341. //查询作品推荐
  342. router.route('/getWrokI').all((req, res, next) => {
  343. var json = queryString(req.url);
  344. getmysql(req, res, "select_workRand", json['page'], 10);
  345. });
  346. //根据id查询发现文章
  347. router.route('/getFindById').all((req, res, next) => {
  348. var json = queryString(req.url);
  349. getmysql(req, res, "select_findById", json['id']);
  350. });
  351. //根据作业id查询此作业的学生评论
  352. router.route('/findSComment').all((req, res, next) => {
  353. var json = queryString(req.url);
  354. getmysql(req, res, "select_studentComment", json['pid']);
  355. });
  356. //根据id查询查询此作业的家长评论
  357. router.route('/findPComment').all((req, res, next) => {
  358. var json = queryString(req.url);
  359. getmysql(req, res, "select_parentComment", json['pid']);
  360. });
  361. //修改课程观看量
  362. router.route('/addCourseCount').all((req, res, next) => {
  363. postmysql(req, res, "update_CourseVcount");
  364. });
  365. //把课程添加到我的课程
  366. router.route('/addUserRate').all((req, res, next) => {
  367. postmysql(req, res, "insert_userRate");
  368. });
  369. //查看学生我的课程列表 select_userRate_student
  370. router.route('/findMyClass').all((req, res, next) => {
  371. var json = queryString(req.url);
  372. getmysql(req, res, "select_userRate_student", json['uid'], json['page'], 10);
  373. });
  374. //评论
  375. router.route('/comment').all((req, res, next) => {
  376. postmysql(req, res, "insert_evaluate");
  377. });
  378. //修改老师
  379. router.route('/UpdateTeacher').all((req, res, next) => {
  380. postmysql(req, res, "update_teacher");
  381. });
  382. //修改年级
  383. router.route('/UpdateSClass').all((req, res, next) => {
  384. postmysql(req, res, "update_UserClass");
  385. });
  386. //提交修改年级申请
  387. router.route('/UpdateSClassC').all((req, res, next) => {
  388. postmysql(req, res, "update_UserClassC");
  389. });
  390. //查询这个学校底下的老师
  391. router.route('/findTeacher').all((req, res, next) => {
  392. var json = queryString(req.url);
  393. getmysql(req, res, "select_teacher", json['oid']);
  394. });
  395. //查询这个老师底下的年级
  396. router.route('/findClassByTeacher').all((req, res, next) => {
  397. var json = queryString(req.url);
  398. getmysql(req, res, "select_classByCid", json['cid']);
  399. });
  400. //修改课程
  401. router.route('/updateCourse').all((req, res, next) => {
  402. postmysql(req, res, "update_course");
  403. });
  404. //删除课程
  405. router.route('/deleteCourse').all((req, res, next) => {
  406. postmysql(req, res, "delete_course");
  407. });
  408. //查询这个老师底下的作业的课程分类
  409. router.route('/findWorkType').all((req, res, next) => {
  410. var json = queryString(req.url);
  411. getmysql(req, res, "select_workType2", json['uid']);
  412. });
  413. //查询这个老师底下的作业的课程分类
  414. router.route('/findWorkType2').all((req, res, next) => {
  415. var json = queryString(req.url);
  416. getmysql(req, res, "select_workCourseType", json['uid']);
  417. });
  418. //修改老师个人信息
  419. router.route('/updateTeacherDetail').all((req, res, next) => {
  420. if (!req.body[0].mail) {
  421. req.body[0].mail = ""
  422. }
  423. if (!req.body[0].intro) {
  424. req.body[0].intro = ""
  425. }
  426. postmysql(req, res, "update_teacherDetail");
  427. });
  428. //查询这个老师的信息
  429. router.route('/findteacherDeatail').all((req, res, next) => {
  430. var json = queryString(req.url);
  431. getmysql(req, res, "select_teacherDetail", json['uid']);
  432. });
  433. //添加学生
  434. router.route('/addStudent').all((req, res, next) => {
  435. // req.body[0].upassword = bcrypt.hashSync(req.body[0].upassword, bcrypt.genSaltSync(10));
  436. // postmysql(req, res, "add_student");
  437. var json = queryString(req.url);
  438. json['upassword'] = bcrypt.hashSync(json['upassword'], bcrypt.genSaltSync(10))
  439. getmysql(req, res, "add_student", json['uname'], json['upassword'], json['oid'], json['n'], json['cid'], json['tid']);
  440. });
  441. //查询这个手机号码有没有被注册
  442. router.route('/findPhoneBoolean').all((req, res, next) => {
  443. var json = queryString(req.url);
  444. getmysql(req, res, "select_usernameBoolean", json['un']);
  445. });
  446. //查询这个班级存不存在
  447. router.route('/findClassBoolean').all((req, res, next) => {
  448. var json = queryString(req.url);
  449. getmysql(req, res, "select_classBoolean", json['uid'], json['name'], json['bn']);
  450. });
  451. //删除这个学生
  452. router.route('/deleteStudent').all((req, res, next) => {
  453. postmysql(req, res, "delete_user");
  454. });
  455. //后台添加分组
  456. router.route('/addGroup').all((req, res, next) => {
  457. postmysql(req, res, "insert_group");
  458. });
  459. //后台添加年级
  460. router.route('/addGroupGrade').all((req, res, next) => {
  461. postmysql(req, res, "insert_classGrade");
  462. });
  463. //后台查看分组下的年级
  464. router.route('/getGroupGrade').all((req, res, next) => {
  465. var json = queryString(req.url);
  466. getmysql(req, res, "select_classGrade", json['pid']);
  467. });
  468. //后台查看分组
  469. router.route('/getGroupAdmin').all((req, res, next) => {
  470. var json = queryString(req.url);
  471. getmysql(req, res, "select_group_admin", json['page'], 10);
  472. });
  473. //删除学校
  474. router.route('/deleteSchool').all((req, res, next) => {
  475. postmysql(req, res, "delete_school");
  476. });
  477. //获取通知
  478. router.route('/getNotice').all((req, res, next) => {
  479. var json = queryString(req.url);
  480. getmysql(req, res, "select_notice_admin", json['page'], 10);
  481. });
  482. //删除通知
  483. router.route('/deleteNotice').all((req, res, next) => {
  484. postmysql(req, res, "delete_notice");
  485. });
  486. //添加通知
  487. router.route('/addNotice').all((req, res, next) => {
  488. postmysql(req, res, "insert_notice");
  489. });
  490. //获取通知文章
  491. router.route('/getNoticeById').all((req, res, next) => {
  492. var json = queryString(req.url);
  493. getmysql(req, res, "select_noticeByid", json['nid']);
  494. });
  495. //后台添加学校
  496. router.route('/addSchool').all((req, res, next) => {
  497. postmysql(req, res, "insert_school");
  498. });
  499. //后台查看学校
  500. router.route('/getSchoolAdmin').all((req, res, next) => {
  501. var json = queryString(req.url);
  502. getmysql(req, res, "select_school_admin", json['page'], 10);
  503. });
  504. //后台添加发现文章
  505. router.route('/addFind').all((req, res, next) => {
  506. if (!req.body[0].p) {
  507. req.body[0].p = ""
  508. }
  509. postmysql(req, res, "insert_find");
  510. });
  511. //后台删除发现文章
  512. router.route('/deleteFind').all((req, res, next) => {
  513. postmysql(req, res, "delete_find");
  514. });
  515. //后台查看发现文章列表
  516. router.route('/getFindAdmin').all((req, res, next) => {
  517. var json = queryString(req.url);
  518. getmysql(req, res, "select_find_admin", json['page'], 10);
  519. });
  520. //后台查看所有课程
  521. router.route('/getCourseAdmin').all((req, res, next) => {
  522. var json = queryString(req.url);
  523. getmysql(req, res, "select_course_admin", json['cn'], json['page'], 10);
  524. });
  525. //后台查看专区下课程的数量
  526. router.route('/getZoneClassNum').all((req, res, next) => {
  527. var json = queryString(req.url);
  528. getmysql(req, res, "select_zoneClassNum", json['bid']);
  529. });
  530. //后台添加课程专区时查看课程是否在此专区重复
  531. router.route('/getZoneClassRepeat').all((req, res, next) => {
  532. var json = queryString(req.url);
  533. getmysql(req, res, "select_zoneClassRepeat", json['pid'], json['cid']);
  534. });
  535. //后台添加班级是否重复
  536. router.route('/getClassRepeat').all((req, res, next) => {
  537. var json = queryString(req.url);
  538. getmysql(req, res, "select_classRepeat", json['pid'], json['n']);
  539. });
  540. //后台专区上移下移
  541. router.route('/zoneRank').all((req, res, next) => {
  542. postmysql(req, res, "update_classRank");
  543. });
  544. //修改分组名字
  545. router.route('/updateClass').all((req, res, next) => {
  546. postmysql(req, res, "update_class");
  547. });
  548. //修改发现文章
  549. router.route('/updateFind').all((req, res, next) => {
  550. if (!req.body[0].p) {
  551. req.body[0].p = ""
  552. }
  553. postmysql(req, res, "update_find");
  554. });
  555. //修改家校区文章
  556. router.route('/updateHomecampus').all((req, res, next) => {
  557. if (!req.body[0].p) {
  558. req.body[0].p = ""
  559. }
  560. postmysql(req, res, "update_homecampus");
  561. });
  562. //获取所有用户
  563. router.route('/getAllUser').all((req, res, next) => {
  564. var json = queryString(req.url);
  565. getmysql(req, res, "select_user_admin2", json['cn'], json['cclass'], json['school'], json['class'], json['type'], json['page'], 10);
  566. });
  567. //获取所有作业
  568. router.route('/getAllWorks').all((req, res, next) => {
  569. var json = queryString(req.url);
  570. getmysql(req, res, "select_works_admin", json['cn'], json['page'], 10);
  571. });
  572. //后台删除作业
  573. router.route('/deleteWorkAdmin').all((req, res, next) => {
  574. postmysql(req, res, "delect_work_admin");
  575. });
  576. //上移作业
  577. router.route('/upWorks').all((req, res, next) => {
  578. postmysql(req, res, "up_works");
  579. });
  580. //下移作业
  581. router.route('/downWorks').all((req, res, next) => {
  582. postmysql(req, res, "down_works");
  583. });
  584. //置顶作业
  585. router.route('/firstWorks').all((req, res, next) => {
  586. postmysql(req, res, "first_works");
  587. });
  588. //修改用户角色
  589. router.route('/updateUserType').all((req, res, next) => {
  590. postmysql(req, res, "update_userType");
  591. });
  592. //创建调查问卷
  593. router.route('/addAsk').all((req, res, next) => {
  594. postmysql(req, res, "insert_ask");
  595. });
  596. //获取调查问卷
  597. router.route('/getAsk').all((req, res, next) => {
  598. var json = queryString(req.url);
  599. getmysql(req, res, "select_ask", json['uid'], json['page'], 10);
  600. });
  601. //获取调查问卷
  602. router.route('/getAskApp').all((req, res, next) => {
  603. var json = queryString(req.url);
  604. getmysql(req, res, "select_ask_app", json['page'], 15);
  605. });
  606. //根据id获取调查问卷
  607. router.route('/getAskById').all((req, res, next) => {
  608. var json = queryString(req.url);
  609. getmysql(req, res, "select_askById", json['id']);
  610. });
  611. //学生提交问卷
  612. router.route('/addAskList').all((req, res, next) => {
  613. postmysql(req, res, "insert_askList");
  614. });
  615. //根据id获取调查问卷
  616. router.route('/getAskList').all((req, res, next) => {
  617. var json = queryString(req.url);
  618. getmysql(req, res, "select_askList", json['uid'], json['page'], 10);
  619. });
  620. //删除学生提交问卷
  621. router.route('/deleteAskList').all((req, res, next) => {
  622. postmysql(req, res, "update_askList_delete");
  623. });
  624. //问卷调查数据统计
  625. router.route('/getAskListByAskid').all((req, res, next) => {
  626. var json = queryString(req.url);
  627. getmysql(req, res, "select_askListByAskid", json['aid']);
  628. });
  629. //查看未读作业的数量
  630. router.route('/getNcount').all((req, res, next) => {
  631. var json = queryString(req.url);
  632. getmysql(req, res, "select_worksCount", json['bid']);
  633. });
  634. //查看作业改成已读
  635. router.route('/updateWorkRead').all((req, res, next) => {
  636. postmysql(req, res, "update_workRead");
  637. });
  638. //查看消息的数量
  639. router.route('/getNewsCount').all((req, res, next) => {
  640. var json = queryString(req.url);
  641. getmysql(req, res, "select_newsCount", json['uid']);
  642. });
  643. //消息改成已读
  644. router.route('/updateNewsRead').all((req, res, next) => {
  645. postmysql(req, res, "update_newsRead");
  646. });
  647. //查看学生评价得信息
  648. router.route('/getStudentE').all((req, res, next) => {
  649. var json = queryString(req.url);
  650. getmysql(req, res, "select_studentE2", json['cn'], json['page'], 10);
  651. });
  652. //查看学生评价得信息通过学生id
  653. router.route('/getStudentEByUid').all((req, res, next) => {
  654. var json = queryString(req.url);
  655. getmysql(req, res, "select_studentEByuid", json['uid']);
  656. });
  657. //导入用户
  658. router.route('/addUser').all((req, res, next) => {
  659. // req.body[0].upassword = bcrypt.hashSync(req.body[0].upassword, bcrypt.genSaltSync(10));
  660. // postmysql(req, res, "add_user");
  661. var json = queryString(req.url);
  662. json['upassword'] = bcrypt.hashSync(json['upassword'], bcrypt.genSaltSync(10))
  663. getmysql(req, res, "add_user", json['uname'], json['upassword'], json['t'], json['oid'], json['n']);
  664. });
  665. //查找有无学校
  666. router.route('/findSchool').all((req, res, next) => {
  667. var json = queryString(req.url);
  668. getmysql(req, res, "find_school", json['n']);
  669. });
  670. queryString = function (url) {
  671. var a = url.split("?");
  672. var json = querystring.parse(a[1])
  673. return json;
  674. }
  675. //post存儲過程處理
  676. postmysql = function (req, res, functionname) {
  677. //mode的處理
  678. if (req.body[0]) {
  679. p = Object.values(req.body[0]);
  680. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  681. //執行存儲過程
  682. mysql.usselect(p, function (ret) { res.end(JSON.stringify(ret)); });
  683. }
  684. }
  685. //get獲取數據庫信息
  686. getmysql = function (req, res, functionname, ...p) {
  687. p = p || [];
  688. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  689. //執行存儲過程
  690. mysql.usselect(p, function (ret) {
  691. res.end(JSON.stringify(ret));
  692. }); //
  693. }
  694. module.exports = router;