lrf402788946 4 سال پیش
والد
کامیت
be04acb62f

+ 51 - 0
app/controller/.answerchat.js

@@ -0,0 +1,51 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!sender_id",
+      "!sender_name",
+      "!receiver_id",
+      "!receiver_name",
+      "!room",
+      "!content",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "!sender_id",
+      "!sender_name",
+      "!receiver_id",
+      "!receiver_name",
+      "!room",
+      "!content",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        sender_id: "sender_id",
+        sender_name: "sender_name",
+        receiver_id: "receiver_id",
+        receiver_name: "receiver_name",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 35 - 0
app/controller/.chatroom.js

@@ -0,0 +1,35 @@
+module.exports = {
+  create: {
+    requestBody: ["!teacherid", "!studentid"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["number", "!teacherid", "!studentid"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        number: "number",
+        teacherid: "teacherid",
+        studentid: "studentid",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 2 - 1
app/controller/.liveroom.js

@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["number", "!subid", "!teacherid", "status", "reason"],
+    requestBody: ["number", "!subid", "!teacherid", "status", "reason", 'start'],
   },
   show: {
     parameters: {
@@ -22,6 +22,7 @@ module.exports = {
         number: "number",
         subid: "subid",
         teacherid: "teacherid",
+        start:"start",
         status: "status",
       },
     },

+ 36 - 0
app/controller/.trainvideo.js

@@ -0,0 +1,36 @@
+module.exports = {
+  create: {
+    requestBody: ["!url", "!subid", "!teacher", "!teacherid", "touser"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["!url", "!subid", "!teacher", "!teacherid", "touser"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        subid: "subid",
+        teacher: "teacher",
+        teacherid: "teacherid",
+        touser: "touser",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 1 - 0
app/controller/.user.js

@@ -39,6 +39,7 @@ module.exports = {
       query: {
         name: 'name',
         mobile: 'mobile',
+        type:"type",
         openid: 'openid'
       }
     },

+ 18 - 0
app/controller/answerchat.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.answerchat.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 教师申请讲课表管理
+class AnswerchatController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.answerchat;
+  }
+
+}
+
+module.exports = CrudController(AnswerchatController, meta);

+ 18 - 0
app/controller/chatroom.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.chatroom.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 课后答疑房间
+class ChatroomController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.chatroom;
+  }
+
+}
+
+module.exports = CrudController(ChatroomController, meta);

+ 16 - 0
app/controller/trainvideo.js

@@ -0,0 +1,16 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.trainvideo.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 教师申请讲课表管理
+class TrainvideoController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.trainvideo;
+  }
+}
+
+module.exports = CrudController(TrainvideoController, meta);

+ 22 - 0
app/model/answerchat.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const Answerchat = {
+  sender_id: { type: String, required: true, maxLength: 200 }, // 发言人id
+  sender_name: { type: String, required: true, maxLength: 200 }, // 发言人名称
+  receiver_id: { type: String, required: true, maxLength: 200 }, // 接收人id
+  receiver_name: { type: String, required: true, maxLength: 200 }, // 接收人名字
+  room: { type: String, required: true, maxLength: 200 }, // 房间号
+  content: { type: String, required: true }, // 发言内容
+  send_time: { type: String, required: true, maxLength: 100 }, // 发言时间:年月日时分秒
+  status: { type: String, maxLength: 200, default: '0' }, // 状态:0=>未读;1=>已读
+};
+const schema = new Schema(Answerchat, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Answerchat', schema, 'answerchat');
+};

+ 20 - 0
app/model/chatroom.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 教师直播房间
+const ChatroommSchema = {
+  number: { type: String, required: false, maxLength: 200, default: new Date().getTime() }, // 房间号
+  teacherid: { type: String, required: true, maxLength: 200 }, // 教师id
+  studentid: { type: String, required: true, maxLength: 200 }, // 学生id
+};
+
+
+const schema = new Schema(ChatroommSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Chatroom', schema, 'chatroom');
+};

+ 1 - 0
app/model/liveroom.js

@@ -8,6 +8,7 @@ const LiveroomSchema = {
   subid: { type: String, required: true, maxLength: 200 }, // 科目id
   teacherid: { type: String, required: true, maxLength: 200 }, // 教师id
   status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态:0=>未审核;1=>通过;2=>拒绝
+  start: { type: Boolean, required: true, maxLength: 200, default: false }, // true=>开始直播;false=>未开始
   reason: { type: String, required: false, maxLength: 2000 }, // 申请原因
 };
 

+ 22 - 0
app/model/trainvideo.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 教师申请讲课表
+const TrainVideoSchema = {
+  url: { type: String, required: true, maxLength: 200 }, // 视频地址
+  subid: { type: String, required: true, maxLength: 200 }, // 科目id
+  teacher: { type: String, required: true, maxLength: 200 }, // 教师姓名
+  teacherid: { type: String, required: true, maxLength: 200 }, // 教师id
+  touser: { type: String, required: false, maxLength: 20 }, // 面向对象:0=>所有人;1=>教师;2=>学生;3=>班主任
+};
+
+
+const schema = new Schema(TrainVideoSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Trainvideo', schema, 'trainvideo');
+};

+ 21 - 0
app/router.js

@@ -532,4 +532,25 @@ module.exports = app => {
     '/api/train/liveroom/update/:id',
     controller.liveroom.update
   );
+  // 培训视频
+  router.resources('trainvideo', '/api/train/trainvideo', controller.trainvideo); // index、create、show、destroy
+  router.post(
+    'trainvideo',
+    '/api/train/trainvideo/update/:id',
+    controller.trainvideo.update
+  );
+  // 答疑房间
+  router.resources('trainvideo', '/api/train/chatroom', controller.chatroom); // index、create、show、destroy
+  router.post(
+    'chatroom',
+    '/api/train/chatroom/update/:id',
+    controller.chatroom.update
+  );
+  // 答疑对话
+  router.resources('trainvideo', '/api/train/answerchat', controller.answerchat); // index、create、show、destroy
+  router.post(
+    'answerchat',
+    '/api/train/answerchat/update/:id',
+    controller.answerchat.update
+  );
 };

+ 41 - 0
app/service/answerchat.js

@@ -0,0 +1,41 @@
+'use strict';
+
+const assert = require('assert');
+const _ = require('lodash');
+const moment = require('moment');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class AnswerchatService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'answerchat');
+    this.model = this.ctx.model.Answerchat;
+  }
+
+  async create(data) {
+    const { sender_id, sender_name, receiver_id, receiver_name, room, content } = data;
+    assert(sender_id, '缺少发送人信息');
+    assert(sender_name, '缺少发送人信息');
+    assert(receiver_id, '缺少接收人信息');
+    assert(receiver_name, '缺少接受人信息');
+    assert(room, '缺少房间号');
+    assert(content, '缺少发送内容');
+    const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
+    const res = await this.model.create({ ...data, send_time });
+    const { mq } = this.ctx;
+    if (mq) {
+      const exchange = 'answerchat';
+      const parm = {
+        durable: true,
+        headers: {
+          userid: 1,
+        } };
+      await mq.fanout(exchange, room, JSON.stringify(res), parm);
+    }
+    return res;
+  }
+
+}
+
+module.exports = AnswerchatService;

+ 18 - 0
app/service/chatroom.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ChatroomService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'chatroom');
+    this.model = this.ctx.model.Chatroom;
+  }
+
+}
+
+module.exports = ChatroomService;

+ 1 - 1
app/service/liveroom.js

@@ -9,7 +9,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 
 class LiveroomService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'apply');
+    super(ctx, 'liveroom');
     this.model = this.ctx.model.Liveroom;
   }
   async create(data) {

+ 17 - 0
app/service/trainvideo.js

@@ -0,0 +1,17 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class TrainvideoService extends CrudService {
+  constructor(ctx) {
+    super(ctx, "trainvideo");
+    this.model = this.ctx.model.Trainvideo;
+  }
+}
+
+module.exports = TrainvideoService;

+ 23 - 23
config/config.default.js

@@ -70,36 +70,36 @@ module.exports = appInfo => {
   config.auth_code = 'vgWtywkwMJpN8QDL';
 
   // mq配置
-  config.amqp = {
-    client: {
-      hostname: '127.0.0.1',
-      username: 'visit',
-      password: 'visit',
-      vhost: 'train',
-    },
-    app: true,
-    agent: true,
-  };
+  // config.amqp = {
+  //   client: {
+  //     hostname: '127.0.0.1',
+  //     username: 'visit',
+  //     password: 'visit',
+  //     vhost: 'train',
+  //   },
+  //   app: true,
+  //   agent: true,
+  // };
 
   // redis config
-  config.redis = {
-    client: {
-      port: 6379, // Redis port
-      host: '127.0.0.1', // Redis host
-      password: 123456,
-      db: 0,
-    },
-  };
+  // config.redis = {
+  //   client: {
+  //     port: 6379, // Redis port
+  //     host: '127.0.0.1', // Redis host
+  //     password: 123456,
+  //     db: 0,
+  //   },
+  // };
 
   // mongoose config
   config.mongoose = {
     url: 'mongodb://127.0.0.1:27017/train',
     options: {
-      user: 'admin',
-      pass: 'admin',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
+      // user: 'admin',
+      // pass: 'admin',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
     },
   };
 

+ 24 - 24
config/config.local.js

@@ -23,36 +23,36 @@ module.exports = () => {
   config.authUrl = '/api/auth';
 
   // mq config
-  config.amqp = {
-    client: {
-      hostname: '127.0.0.1',
-      username: 'wy',
-      password: '1',
-      vhost: 'smart',
-    },
-    app: true,
-    agent: true,
-  };
+  // config.amqp = {
+  //   client: {
+  //     hostname: '127.0.0.1',
+  //     username: 'wy',
+  //     password: '1',
+  //     vhost: 'smart',
+  //   },
+  //   app: true,
+  //   agent: true,
+  // };
 
   // redis config
-  config.redis = {
-    client: {
-      port: 6379, // Redis port
-      host: '127.0.0.1', // Redis host
-      password: null,
-      db: 0,
-    },
-  };
+  // config.redis = {
+  //   client: {
+  //     port: 6379, // Redis port
+  //     host: '127.0.0.1', // Redis host
+  //     password: null,
+  //     db: 0,
+  //   },
+  // };
 
   config.mongoose = {
     url: 'mongodb://localhost:27017/train',
     options: {
-      user: 'demo',
-      pass: 'demo',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
-      useUnifiedTopology: true,
+      // user: 'demo',
+      // pass: 'demo',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+      // useUnifiedTopology: true,
     },
   };