Преглед изворни кода

新建教师在线表,聊天房间表,聊天记录表

reloaded пре 5 година
родитељ
комит
ca9289274f

+ 40 - 0
app/controller/.online.js

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

+ 49 - 0
app/controller/.record.js

@@ -0,0 +1,49 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!roomid',
+      '!sendid',
+      '!receiveid',
+      '!type',
+      'content'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'roomid',
+      'sendid',
+      'receiveid',
+      'type',
+      'content'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        roomid :'roomid',
+        sendid:'sendid',
+        receiveid :'receiveid',
+        type:'type',
+        content :'content'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 43 - 0
app/controller/.room.js

@@ -0,0 +1,43 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!teaid',
+      '!stuid',
+      'status'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'teaid',
+      'stuid',
+      'status'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        teaid :'teaid',
+        stuid:'stuid',
+        status :'status'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 19 - 0
app/controller/online.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.online.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 教师在线表管理
+class OnlineController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.online;
+  }
+
+
+}
+
+module.exports = CrudController(OnlineController, meta);

+ 19 - 0
app/controller/record.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.record.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 聊天记录表管理
+class RecordController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.record;
+  }
+
+
+}
+
+module.exports = CrudController(RecordController, meta);

+ 19 - 0
app/controller/room.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.room.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 聊天房间表管理
+class RoomController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.room;
+  }
+
+
+}
+
+module.exports = CrudController(RoomController, meta);

+ 1 - 1
app/model/leave.js

@@ -8,7 +8,7 @@ const LeaveSchema = {
   starttime: { type: String, required: true, maxLength: 200 }, // 开始时间
   endtime: { type: String, required: true, maxLength: 500 }, // 结束时间
   reason: { type: String, required: false, maxLength: 2000 }, // 请假理由
-  status: { type: String, required: false, maxLength: 200 }, // 状态,0-审核中,1-通过,2-未通过
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-审核中,1-通过,2-未通过
   refcause: { type: String, required: false, maxLength: 2000 }, // 拒绝原因
 };
 

+ 19 - 0
app/model/online.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 教师在线表
+const OnlineSchema = {
+  teaid: { type: String, required: true, maxLength: 200 }, // 教师id
+  status: { type: String, required: false, maxLength: 500 }, // 状态,0-下线,1-在线
+};
+
+
+const schema = new Schema(OnlineSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Online', schema, 'online');
+};

+ 22 - 0
app/model/record.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 聊天记录表
+const RecordSchema = {
+  roomid: { type: String, required: true, maxLength: 200 }, // 房间id
+  sendid: { type: String, required: true, maxLength: 200 }, // 发送者id
+  receiveid: { type: String, required: true, maxLength: 200 }, // 接收者id
+  type: { type: String, required: true, maxLength: 500 }, // 类型,0-学生向教师发送的信息,1-教师向学生发送的信息
+  content: { type: String, required: false, maxLength: 2000 }, // 内容
+};
+
+
+const schema = new Schema(RecordSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Record', schema, 'record');
+};

+ 20 - 0
app/model/room.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 聊天房间表
+const RoomSchema = {
+  teaid: { type: String, required: true, maxLength: 200 }, // 教师id
+  stuid: { type: String, required: true, maxLength: 200 }, // 学生id
+  status: { type: String, required: false, maxLength: 500 }, // 状态,0-开始,1-结束
+};
+
+
+const schema = new Schema(RoomSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Room', schema, 'room');
+};

+ 1 - 1
app/model/teacher.js

@@ -33,7 +33,7 @@ const TeacherSchema = {
   msscore: { type: String, required: false, maxLength: 200 }, // 面试评分
   xsscore: { type: String, required: false, maxLength: 200 }, // 学生评分
   file: { type: [ FileInfo ], select: false }, // 资料,教案PPT视频等
-  status: { type: String, required: false, maxLength: 200 },
+  status: { type: String, required: false, maxLength: 200, default: '0' },
   // 状态:0-注册,1-确认身份,2-资料评分,3-面试评分,4-确认入库
 }
 ;

+ 1 - 1
app/model/user.js

@@ -12,7 +12,7 @@ const UserSchema = {
   remark: { type: String, required: false }, // 备注
   type: { type: String, required: false, maxLength: 200 }, // 身份,0、中心管理元1、班主任用户2、学校用户3、教师4、学生
   uid: { type: String, required: false, maxLength: 200 }, // 关联用户信息id
-  status: { type: String, required: false, default: 0 }, // 注册状态
+  status: { type: String, required: false, default: '0' }, // 注册状态
 };
 
 

+ 12 - 0
app/router.js

@@ -158,4 +158,16 @@ module.exports = app => {
   // 资料评分表设置路由
   router.resources('materialscore', '/api/train/materialscore', controller.materialscore); // index、create、show、destroy
   router.post('materialscore', '/api/train/materialscore/update/:id', controller.materialscore.update);
+
+  // 教师在线表设置路由
+  router.resources('online', '/api/train/online', controller.online); // index、create、show、destroy
+  router.post('online', '/api/train/online/update/:id', controller.online.update);
+
+  // 聊天房间表设置路由
+  router.resources('room', '/api/train/room', controller.room); // index、create、show、destroy
+  router.post('room', '/api/train/room/update/:id', controller.room.update);
+
+  // 聊天记录表设置路由
+  router.resources('record', '/api/train/record', controller.record); // index、create、show、destroy
+  router.post('record', '/api/train/record/update/:id', controller.record.update);
 };

+ 18 - 0
app/service/online.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 OnlineService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'online');
+    this.model = this.ctx.model.Online;
+  }
+
+}
+
+module.exports = OnlineService;

+ 18 - 0
app/service/record.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 RecordService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'record');
+    this.model = this.ctx.model.Record;
+  }
+
+}
+
+module.exports = RecordService;

+ 18 - 0
app/service/room.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 RoomService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'room');
+    this.model = this.ctx.model.Room;
+  }
+
+}
+
+module.exports = RoomService;