lsc hai 1 día
pai
achega
93430c1379
Modificáronse 4 ficheiros con 191 adicións e 0 borrados
  1. 2 0
      app.js
  2. 1 0
      package.json
  3. 5 0
      pbl.js
  4. 183 0
      szdjg.js

+ 2 - 0
app.js

@@ -7,6 +7,7 @@ const edurouter = require('./pbl');
 const mongo = require('./mongo');
 const weixin = require('./weixin');
 const cocoflow = require('./cocoflow');
+const szdjg = require('./szdjg');
 const baoantoken = require('./baoantoken')
 const morgan = require('morgan');
 var path = require("path");
@@ -49,6 +50,7 @@ app.use('/api/pbl', edurouter);
 app.use('/api/mongo', mongo);
 app.use('/api/weixin', weixin);
 app.use('/api/cocoflow', cocoflow);
+app.use('/api/szdjg', szdjg);
 app.use('/api/bat/getToken', async function (req, res, next) {
     let ticket = req.query.ticket
     await baoantoken.getToken(ticket, res)

+ 1 - 0
package.json

@@ -276,6 +276,7 @@
     },
     "node-gyp": "^7.1.2",
     "node-pre-gyp": "^0.14.0",
+    "node-schedule": "^2.1.1",
     "on-finished": {
       "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
       "requires": {

+ 5 - 0
pbl.js

@@ -4927,6 +4927,11 @@ router.route("/getClassAdmin").all((req, res, next) => {
     var json = queryString(req.url);
     getmysql(req, res, "select_classAdmin", json["cn"], json["page"], 10);
 });
+//查询班级
+router.route("/getClassById").all((req, res, next) => {
+    var json = queryString(req.url);
+    getmysql(req, res, "getClassById", json["id"]);
+});
 //查询ai权限
 router.route("/getAIJ").all((req, res, next) => {
     getmysql(req, res, "getAIJ");

+ 183 - 0
szdjg.js

@@ -0,0 +1,183 @@
+const express = require("express");
+const axios = require("axios");
+const router = express.Router();
+const schedule = require("node-schedule");
+var mysql = require("./mysql");
+
+// 本地
+
+// const _mysqlLabor = ["183.36.25.93", "pbl"]; //edu數據庫信息
+// const _mysqluser = ["183.36.25.93", "cocorobouser"]; //用户数据库信息
+// const _getmysqlLabor2 = ["183.36.25.93", "pbl"]; //edu數據庫信息
+// const _getmysqlLabor = ["183.36.25.93", "pbl"]; //edu數據庫信息
+
+//线上
+
+const _mysqlLabor = ["172.16.12.5", "pbl"]; //edu數據庫信息
+const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
+const _getmysqlLabor2 = ["172.16.12.7", "pbl"]; //edu數據庫信息
+const _getmysqlLabor = ["172.16.12.7", "pbl"]; //edu數據庫信息
+
+// 定时任务:每天凌晨2点触发
+schedule.scheduleJob("0 2 * * *", async () => {
+  try {
+    let p = []
+    p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getSzdjgData");
+    mysql.usselect(p, async function (ret) {
+      let allDownloadCount = 0;
+      if (ret[7].length) {
+        for (let i = 0; i < ret[7].length; i++) {
+          allDownloadCount += ret[7][i].count;
+        }
+      }
+      let dataAddParam = {
+        serverName: "深教AI6",
+        schoolNum: ret[0][0].count,
+        classNum: ret[1][0].count,
+        teacherNum: ret[2][0].count,
+        studentNum: ret[3][0].count,
+        totalVisit: ret[4][0].count,
+        ssoVisit: ret[5][0].count,
+        visitNum: ret[6][0].count,
+        allDownloadCount: allDownloadCount,
+        activeTeacherNum: ret[8][0].count,
+        activeStudentNum: ret[9][0].count,
+        allPrepareCount: ret[10][0].count,
+        allClassCount: ret[11][0].count,
+        classClickCount: ret[12][0].count,
+      };
+      console.log(dataAddParam);
+      if (!dataAddParam || !dataAddParam.serverName) {
+        console.error("上报失败:缺少必填参数 serverName");
+        return;
+      }
+      const response = await axios.post(
+        "http://36.213.31.21:8090/api/data/integrate",
+        dataAddParam,
+        { headers: { "Content-Type": "application/json" } }
+      );
+      console.log("数据上报成功", response.data);
+    });
+  } catch (error) {
+    console.error("数据上报异常", error.response?.data?.msg || error.message);
+  }
+});
+
+/**
+ * 新增:上课/备课数据实时同步接口
+ * POST /sync/class
+ * body参数请参考接口文档说明
+ */
+router.post("/sync/class", async (req, res) => {
+  try {
+    // 校验必填参数
+    const {
+      serverName,
+      dataType,
+      courseId,
+      courseName,
+      courseGrade,
+      courseTime,
+    } = req.body;
+
+    if (
+      !serverName ||
+      typeof dataType !== "number" ||
+      !courseId ||
+      !courseName ||
+      !courseGrade
+    ) {
+      return res
+        .status(400)
+        .json({
+          code: 400,
+          msg: "缺少必填参数",
+          serverName,
+          dataType: typeof dataType,
+          courseId,
+          courseName,
+          courseGrade,
+          courseTime,
+        });
+    }
+
+    // 组装请求体,允许所有字段透传
+    const realClassParam = { ...req.body };
+
+    // 向深教AI学习平台同步数据
+    const response = await axios.post(
+      "http://36.213.31.21:8090/api/data/integrateClass",
+      realClassParam,
+      { headers: { "Content-Type": "application/json" } }
+    );
+
+    // 返回平台响应
+    res.status(200).json(response.data);
+  } catch (error) {
+    const msg =
+      error.response?.data?.msg ||
+      error.response?.data ||
+      error.message ||
+      "同步失败";
+    res.status(500).json({ code: 500, msg });
+  }
+});
+
+router.post("/data", async (req, res) => {
+  let p = []
+  p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getSzdjgData");
+  mysql.usselect(p, async function (ret) {
+    let allDownloadCount = 0;
+    if (ret[7].length) {
+      for (let i = 0; i < ret[7].length; i++) {
+        allDownloadCount += ret[7][i].count;
+      }
+    }
+    let dataAddParam = {
+      serverName: "深教AI6",
+      schoolNum: ret[0][0].count,
+      classNum: ret[1][0].count,
+      teacherNum: ret[2][0].count,
+      studentNum: ret[3][0].count,
+      totalVisit: ret[4][0].count,
+      ssoVisit: ret[5][0].count,
+      visitNum: ret[6][0].count,
+      allDownloadCount: allDownloadCount,
+      activeTeacherNum: ret[8][0].count,
+      activeStudentNum: ret[9][0].count,
+      allPrepareCount: ret[10][0].count,
+      allClassCount: ret[11][0].count,
+      classClickCount: ret[12][0].count,
+    };
+    console.log(dataAddParam);
+  });
+});
+
+module.exports = router;
+
+/*
+用法示例:
+POST /sync/class
+Content-Type: application/json
+
+{
+  "serverName": "深教AI1",
+  "dataType": 0,
+  "teacherName": "张老师",
+  "teacherAccount": "E12356334",
+  "teacherPhone": "13235671123",
+  "eduId": "",
+  "schoolName": "第一中学",
+  "schoolType": "公办",
+  "area": "南山区",
+  "coursePackageName": "AI课程",
+  "courseId": "1234",
+  "courseName": "AI画画",
+  "courseGrade": "三年级",
+  "courseTime": "40",
+  "startTime": "2025-07-10 13:00:00",
+  "endTime": "2025-07-10 13:40:00"
+}
+*/
+
+// gpt-4