edurouter.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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. //工作室管理
  671. router.route('/updateStudioWorkNew4').all((req, res, next) => { //学生
  672. if (req.body[0]) {
  673. let p = [req.body[0].cid];
  674. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "select_studio_course_detail2"); //執行存儲過程
  675. mysql.usselect(p, function(ret) {
  676. let _unitIndex = parseInt(req.body[0].unitIndex);
  677. let _chapters = JSON.parse(req.body[0].chapters);
  678. let _unitJson = JSON.parse(ret[0][0].chapters)
  679. if ((_unitJson.length - 1) < _unitIndex) {
  680. let _i = _unitIndex - (_unitJson.length - 1)
  681. for (let i = 0; i < _i; i++) {
  682. _unitJson.push({
  683. dyName: "", //单元标题
  684. chapterInfo: [{
  685. isread: false,
  686. chapterid: guid(),
  687. title: "",
  688. courseName: "",
  689. taskJson: [{
  690. task: "",
  691. taskDetail: "",
  692. chapterData: [],
  693. toolText: "",
  694. toolChoose: [{
  695. tool: [],
  696. toolDetail: "",
  697. toolType: 0,
  698. askCount: 1,
  699. askTitle: "",
  700. askJson: [{ askstitle: "", askItem: 1, checkList: [] }],
  701. }, ],
  702. isShowTools: false,
  703. askCount: 1,
  704. isFold: 0,
  705. askTitle: "",
  706. askJson: [{ askstitle: "", askItem: 1, checkList: [] }],
  707. checkJson: [{ checkCount: [], checkPerent: [] }],
  708. homeworkList: [],
  709. }, ],
  710. itemCount: 1,
  711. fileList1: [],
  712. video: [],
  713. testData: [],
  714. pData: [],
  715. templateArray: [],
  716. }, ],
  717. })
  718. }
  719. _unitJson[_unitIndex] = _chapters[_unitIndex]
  720. } else {
  721. _unitJson[_unitIndex] = _chapters[_unitIndex]
  722. }
  723. // console.log(_unitJson);
  724. let p2 = [req.body[0].cid, JSON.stringify(_unitJson).replaceAll(/%/g, "%25")];
  725. p2.unshift(_mysqlLabor[0], _mysqlLabor[1], "updateStudioWorkNew4"); //執行存儲過程
  726. mysql.usselect(p2, function(ret) {
  727. res.end(JSON.stringify({ success: 1 }));
  728. });
  729. // res.end(JSON.stringify({ success: 1 }));
  730. });
  731. }
  732. });
  733. router.route('/updateStudioWorkNew2').all((req, res, next) => { //学生
  734. if (req.body[0]) {
  735. p = [req.body[0].cid, req.body[0].title, req.body[0].brief, req.body[0].cover, req.body[0].evaId, req.body[0].astudent, req.body[0].see, req.body[0].chapters, req.body[0].template, req.body[0].ateacher];
  736. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "updateStudioWorkNew2"); //執行存儲過程
  737. mysql.usselect(p, function(ret) {
  738. let course = req.body[0].courseType;
  739. let courseId = req.body[0].cid;
  740. let userid = req.body[0].uid;
  741. delStudioCourseTypeS(course, courseId, userid);
  742. res.end(JSON.stringify({ success: 1 }));
  743. });
  744. }
  745. });
  746. router.route('/addStudioCourseWorkNew2').all((req, res, next) => { //学生
  747. if (req.body[0]) {
  748. p = [req.body[0].uid, req.body[0].title, req.body[0].brief, req.body[0].cover, req.body[0].evaId, req.body[0].astudent, req.body[0].see, req.body[0].chapters, req.body[0].template, req.body[0].ateacher];
  749. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "addStudioCourseWorkNew2"); //執行存儲過程
  750. mysql.usselect(p, function(ret) {
  751. let course = req.body[0].courseType;
  752. let courseId = ret[0][0].courseId;
  753. let userid = req.body[0].uid;
  754. delStudioCourseTypeS(course, courseId, userid);
  755. res.end(JSON.stringify({ ordernumber: ret[0][0].ordernumber, courseId: ret[0][0].courseId, success: 1 }));
  756. });
  757. }
  758. });
  759. //teacher 查询项目模板
  760. router.route('/getStudioTemplateTs').all((req, res, next) => {
  761. var json = queryString(req.url);
  762. getmysql(req, res, "getStudioTemplateTs", json['oid']);
  763. });
  764. //查看课程
  765. router.route('/select_studio_course_detail').all((req, res, next) => { //学生
  766. var json = queryString(req.url);
  767. getmysql(req, res, "select_studio_course_detail", json['cid']);
  768. });
  769. //查看课程
  770. router.route('/select_studio_course_detail2').all((req, res, next) => { //学生
  771. var json = queryString(req.url);
  772. getmysql(req, res, "select_studio_course_detail2", json['cid']);
  773. });
  774. //协同恢复删除的阶段
  775. router.route('/restoreStudioWork').all((req, res, next) => { //学生
  776. if (req.body[0]) {
  777. let p = [req.body[0].cid];
  778. p.unshift(_mysqlLabor[0], _mysqlLabor[1], "select_studio_course_detail2"); //執行存儲過程
  779. mysql.usselect(p, function(ret) {
  780. let _chapid = req.body[0].chapid;
  781. // console.log(_chapid);
  782. let _chapters = JSON.parse(req.body[0].chapters);
  783. let _unitJson = JSON.parse(ret[0][0].chapters)
  784. let _unitJson2 = []
  785. let chpaindex;
  786. for (var i = 0; i < _chapters.length; i++) {
  787. if (_chapters[i].chapterInfo[0].chapterid == _chapid) {
  788. chpaindex = i
  789. }
  790. }
  791. for (var i = 0; i < _unitJson.length; i++) {
  792. if (_unitJson[i].chapterInfo[0].chapterid != _chapid) {
  793. // console.log(1);
  794. // _unitJson.splice(i, -1)
  795. _unitJson2.push(_unitJson[i])
  796. // break;
  797. }
  798. }
  799. _unitJson2.splice(chpaindex, 0, _chapters[chpaindex])
  800. // console.log(_unitJson2);
  801. let p2 = [req.body[0].cid, JSON.stringify(_unitJson2).replaceAll(/%/g, "%25")];
  802. p2.unshift(_mysqlLabor[0], _mysqlLabor[1], "updateStudioWorkNew4"); //執行存儲過程
  803. mysql.usselect(p2, function(ret) {
  804. res.end(JSON.stringify({ success: 1 }));
  805. });
  806. // res.end(JSON.stringify({ success: 1 }));
  807. });
  808. }
  809. });
  810. //查询分类及所有子分类
  811. router.route('/selectAllTypeStudio').all((req, res, next) => {
  812. var json = queryString(req.url);
  813. getmysql(req, res, "selectAllTypeStudio", json['org'], json['oid']);
  814. });
  815. //上传文件
  816. router.route('/addStudioCourseWorksS').all((req, res, next) => {
  817. postmysql(req, res, "addStudioCourseWorksS");
  818. });
  819. //删除提交的作业
  820. router.route('/deleteStudioCourseWorkS').all((req, res, next) => {
  821. postmysql(req, res, "deleteStudioCourseWorkS");
  822. });
  823. router.route('/selectStudioCourseNew222').all((req, res, next) => {
  824. var json = queryString(req.url);
  825. getmysql(req, res, "selectStudioCourseNew222", json['type'], json['uid'], json['oid'], json['org'], json['typea'], json['typeb'], json['typec'], json['typed'], json['typef'], json['typeE'], json['cu'], json['cn'], json['page'], json['pageSize']);
  826. });
  827. //删除课程
  828. router.route('/deleteStudioCourse').all((req, res, next) => {
  829. var json = queryString(req.url);
  830. getmysql(req, res, "deleteStudioCourse", json['cid']);
  831. });
  832. function delStudioCourseTypeS(course, courseId, userid) {
  833. let _courseId = courseId;
  834. var _userdata = [
  835. _courseId
  836. ];
  837. _userdata.unshift(_mysqlLabor[0], _mysqlLabor[1], "delete_studioCourseTypeS");
  838. mysql.usselect(_userdata, function(ret) {
  839. // console.log(ret);
  840. addStudioCourseTypeS(userid, course, _courseId)
  841. });
  842. // setTimeout(() => {
  843. // }, 1000);
  844. }
  845. function addStudioCourseTypeS(userid, course, _courseId) {
  846. var _uid = userid;
  847. var _courses = _courseId
  848. var _tid = JSON.parse(course)
  849. for (let i = 0; i < _tid.length; i++) {
  850. if (_tid[i] == '') {
  851. continue;
  852. }
  853. var _userdata = [
  854. _courses,
  855. _tid[i],
  856. _uid,
  857. ];
  858. _userdata.unshift(_mysqlLabor[0], _mysqlLabor[1], "add_studioCourseTypeS");
  859. mysql.usselect(_userdata, function(ret) {
  860. // console.log(ret);
  861. });
  862. }
  863. }
  864. queryString = function (url) {
  865. var a = url.split("?");
  866. var json = querystring.parse(a[1])
  867. return json;
  868. }
  869. //post存儲過程處理
  870. postmysql = function (req, res, functionname) {
  871. //mode的處理
  872. if (req.body[0]) {
  873. p = Object.values(req.body[0]);
  874. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  875. //執行存儲過程
  876. mysql.usselect(p, function (ret) { res.end(JSON.stringify(ret)); });
  877. }
  878. }
  879. //get獲取數據庫信息
  880. getmysql = function (req, res, functionname, ...p) {
  881. p = p || [];
  882. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  883. //執行存儲過程
  884. mysql.usselect(p, function (ret) {
  885. res.end(JSON.stringify(ret));
  886. }); //
  887. }
  888. module.exports = router;