123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- // ROUTES FOR OUR API
- // =============================================================================
- var express = require("express");
- var request = require("request");
- var bcrypt = require("bcryptjs");
- var router = express.Router(); // get an instance of the express Router
- const querystring = require("querystring");
- var mysql = require("./mysql");
- // const _mysqlLabor = ["123.58.32.151", "evenYT"]; //edu數據庫信息
- // const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
- const _mysqlLabor = ["172.16.12.5", "evenYT"]; //edu數據庫信息
- const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
- var crypto = require("crypto");
- var https = require("https");
- //統壹處理區域
- router.use(async function(req, res, next) {
- await asynnext(req, res, next);
- //// make sure we go to the next routes and don't stop here
- //res.end("");
- });
- /**
- * @des 參數解釋同上
- */
- function asynnext(req, res, next) {
- //異步處理
- return new Promise(async(resolve, reject) => {
- next();
- //resolve(true);aa
- });
- }
- /*測試*/
- router.route("/a").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "a", json["ph"], json["pa"]);
- });
- router.route("/b").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "b", json["ph"], json["pa"]);
- });
- /* 根据市级用户查询评审员 */
- router.route("/selectReviewer").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectReviewer",
- json["uid"],
- json["cn"],
- json["page"],
- 10
- );
- });
- /* 市级区县管理接口 */
- router.route("/selectCReviewer").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectCReviewer",
- json["uid"],
- json["cn"],
- json["page"],
- 10
- );
- });
- /* 修改评审员 */
- router.route("/updateReviewer").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "updateReviewer",
- json["n"],
- json["p"],
- json["t"],
- json["s"],
- json["uid"]
- );
- });
- /* 删除评审员 */
- router.route("/deleteReviewer").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "deleteReviewer", json["uid"]);
- });
- /* 查询区县案例 */
- router.route("/selecAnliBox").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selecAnliBox", json["title"]);
- });
- /* 查询市级案例 */
- router.route("/selecAnliBox1").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selecAnliBox1", json["title"]);
- });
- /* 查询省级案例 */
- router.route("/selecAnliBox2").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selecAnliBox2");
- });
- /* 案例征集查询通知公告 */
- router.route("/selectRaceNotice").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectRaceNotice", json["page"], 10);
- });
- /* 案例征集查询通知公告详情 */
- router.route("/getRaceNoticeDetail").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "getRaceNoticeDetail", json["nid"]);
- });
- /* 案例征集发送通知 */
- router.route("/insertRaceNote").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "insertRaceNote", json["t"], json["c"], json["uid"]);
- });
- //新增赛事项目
- router.route("/addRace").all((req, res, next) => {
- if (req.body[0]) {
- p = [
- req.body[0].uid,
- req.body[0].info,
- req.body[0].over,
- req.body[0].pro,
- req.body[0].act,
- req.body[0].exc,
- req.body[0].res,
- ];
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], "addRace"); //執行存儲過程
- mysql.usselect(p, function(ret) {
- let course = req.body[0].courseType;
- let courseId = ret[0][0].id;
- let userid = req.body[0].uid;
- delCourseType1(course, courseId, userid);
- res.end(JSON.stringify({ courseId: courseId, success: 1 }));
- });
- }
- });
- function delCourseType1(course, courseId, userid) {
- let _courseId = courseId;
- var _userdata = [_courseId];
- _userdata.unshift(_mysqlLabor[0], _mysqlLabor[1], "delete_courseType1");
- mysql.usselect(_userdata, function(ret) {
- // console.log(ret);
- });
- setTimeout(() => {
- addCourseType1(userid, course, _courseId);
- }, 1000);
- }
- function addCourseType1(userid, course, _courseId) {
- var _uid = userid;
- var _courses = _courseId;
- var _tid = JSON.parse(course);
- for (let i = 0; i < _tid.length; i++) {
- if (_tid[i] == "") {
- continue;
- }
- var _userdata = [_courses, _tid[i], _uid];
- _userdata.unshift(_mysqlLabor[0], _mysqlLabor[1], "add_courseType1");
- mysql.usselect(_userdata, function(ret) {
- // console.log(ret);
- });
- }
- }
- //修改赛事项目
- router.route("/updateRace").all((req, res, next) => {
- if (req.body[0]) {
- p = [
- req.body[0].id,
- req.body[0].info,
- req.body[0].over,
- req.body[0].pro,
- req.body[0].act,
- req.body[0].exc,
- req.body[0].res,
- ];
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], "updateRace"); //執行存儲過程
- mysql.usselect(p, function(ret) {
- let course = req.body[0].courseType;
- let courseId = req.body[0].id;
- let userid = req.body[0].uid;
- delCourseType1(course, courseId, userid);
- res.end(JSON.stringify({ success: 1 }));
- });
- }
- });
- //查询赛事项目列表
- router.route("/selectRaceList").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectRaceList", json["uid"], json["t"]);
- });
- //修改赛事状态
- router.route("/updateRaceState").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "updateRaceState", json["id"], json["s"]);
- });
- //查询赛事项目详情
- router.route("/selectRaceDetail").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectRaceDetail", json["id"]);
- });
- //race 查询学校
- router.route("/getSchool").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "getSchool", json["n"]);
- });
- //根据区级管理者查询案例
- router.route("/selectAnliList").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectAnliList",
- json["typea"],
- json["typeb"],
- json["typec"],
- json["typed"],
- json["typeE"],
- json["cn"],
- json["cid"],
- json["title"],
- json["page"],
- 10
- );
- });
- //根据市级管理者查询案例
- router.route("/selectAnliList1").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectAnliList1",
- json["typea"],
- json["typeb"],
- json["typec"],
- json["typed"],
- json["typeE"],
- json["cn"],
- json["cid"],
- json["title"],
- json["page"],
- 10
- );
- });
- //根据省级级管理者查询案例
- router.route("/selectAnliList2").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectAnliList2",
- json["typea"],
- json["typeb"],
- json["typec"],
- json["typed"],
- json["typeE"],
- json["cn"],
- json["cid"],
- json["title"],
- json["page"],
- 10
- );
- });
- //删除案例
- router.route("/deleteAnli").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "deleteAnli", json["id"]);
- });
- //根据区县管理者查询评分
- router.route("/selectPoint").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectPoint",
- json["typea"],
- json["typeb"],
- json["typec"],
- json["typed"],
- json["typeE"],
- json["cn"],
- json["cid"],
- json["title"],
- json["page"],
- 10
- );
- });
- //根据市级管理者查询评分
- router.route("/selectPoint1").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectPoint1",
- json["typea"],
- json["typeb"],
- json["typec"],
- json["typed"],
- json["typeE"],
- json["cn"],
- json["cid"],
- json["title"],
- json["page"],
- 10
- );
- });
- //根据市级管理者查询全部评分
- router.route("/selectPointAll").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(
- req,
- res,
- "selectPointAll",
- json["typea"],
- json["typeb"],
- json["typec"],
- json["typed"],
- json["typeE"],
- json["cn"],
- json["cid"],
- json["title"]
- );
- });
- //查询分配案例
- router.route("/selectCaseUser").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "select_case", json["uid"]);
- });
- //分配案例
- router.route("/insertCase").all((req, res, next) => {
- if (req.body[0]) {
- p = [req.body[0].uid, req.body[0].box];
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], "insertCase"); //執行存儲過程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify({ success: 1 }));
- });
- }
- });
- //新增评分
- router.route("/addScore").all((req, res, next) => {
- postmysql(req, res, "addScore");
- });
- //查询评分
- router.route("/selectScore").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectScore", json["rid"], json["suser"]);
- });
- //查询所有评分
- router.route("/selectAllScore").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectAllScore");
- });
- //根据用户id查询评分
- router.route("/selectScoreByUid").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectScoreByUid", json["uid"]);
- });
- //查询单个案例所有评分
- router.route("/selectAnliScore").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectAnliScore", json["rid"]);
- });
- //赛事推荐
- router.route("/updateRaceRec").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "updateRaceRec", json["id"], json["rec"]);
- });
- //案例新项目登录接口
- router.route("/loginNewEvenManage").all((req, res, next) => {
- postmysql(req, res, "loginNewEvenManage");
- });
- //案例新项目创建用户接口
- router.route("/addNewRaceUser").all((req, res, next) => {
- postmysql(req, res, "addNewRaceUser");
- });
- //查询老师的信息
- router.route("/getRaceUser1").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "getRaceUser1", json["uid"]);
- });
- //修改用户信息
- router.route("/updateRaceUser").all((req, res, next) => {
- postmysql(req, res, "updateRaceUser");
- });
- //race 查询学校
- router.route("/getSchool1").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "getSchool1", json["n"]);
- });
- //查询赛事项目列表
- router.route("/selectRaceList1").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectRaceList1", json["uid"], json["t"], json["oid"], json["org"]);
- });
- //查询赛事分类及子分类
- router.route("/selectMatTypeYT").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectMatTypeYT");
- });
- //查询Banner列表
- router.route("/selectAllBanner").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectAllBanner", json["t"]);
- });
- /* 赛事修改密码 */
- router.route("/updatePassword1").post(function(req, res, next) {
- //mode的处理
- if (req.body[0]) {
- let p = [req.body[0].userid];
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getPassword1"); //執行存儲過程
- mysql.usselect(p, function(ret) {
- var paJ = ret[0][0].password;
- var op = bcrypt.hashSync(req.body[0].opassword, bcrypt.genSaltSync(10));
- bcrypt.compare(req.body[0].opassword, paJ, function(err, result) {
- // console.log(result)
- if (result) {
- let p2 = [
- req.body[0].userid,
- bcrypt.hashSync(req.body[0].password, bcrypt.genSaltSync(10)),
- ];
- p2.unshift(_mysqlLabor[0], _mysqlLabor[1], "updatePassword1"); //執行存儲過程
- mysql.usselect(p2, function(ret) {
- res.end(JSON.stringify([{ success: 1 }]));
- });
- } else {
- res.end(JSON.stringify([{ success: 0 }]));
- }
- });
- });
- }
- });
- // 管理员查询项目下所有的评分
- router.route("/selectScoreByAdmin").all(function(req, res, next) {
- var json = queryString(req.url);
- getmysql(req, res, "selectScoreByAdmin", json["rid"]);
- })
- queryString = function(url) {
- var a = url.split("?");
- var json = querystring.parse(a[1]);
- return json;
- };
- //post存儲過程處理
- postmysql = function(req, res, functionname) {
- //mode的處理
- if (req.body[0]) {
- p = Object.values(req.body[0]);
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
- //執行存儲過程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify(ret));
- });
- }
- };
- //post存儲過程處理
- postmysql2 = function(req, res, functionname) {
- //mode的處理
- if (req.body) {
- p = Object.values(req.body)[0].split(",");
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
- //執行存儲過程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify(ret));
- });
- }
- };
- //post存儲過程處理
- postmysql3 = function(req, res, functionname) {
- //mode的處理
- if (req.body) {
- p = Object.values(req.body);
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
- //執行存儲過程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify(ret));
- });
- }
- };
- //get獲取數據庫信息
- getmysql = function(req, res, functionname, ...p) {
- p = p || [];
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
- //執行存儲過程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify(ret));
- }); //
- };
- //post存储过程处理
- userpostmysql = function(req, res, functionname) {
- //mode的处理
- if (req.body.mode) {
- p = req.body.mode.split(",");
- p.unshift(_mysqluser[0], _mysqluser[1], functionname);
- //执行存储过程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify(ret));
- });
- }
- };
- //get获取数据库信息
- usergetmysql = function(req, res, functionname, ...p) {
- p = p || [];
- p.unshift(_mysqluser[0], _mysqluser[1], functionname);
- //执行存储过程
- mysql.usselect(p, function(ret) {
- res.end(JSON.stringify(ret));
- }); //
- };
- module.exports = router;
|