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

Merge branch 'master' of http://git.cc-lotus.info/new_train/service-center

liuyu пре 5 година
родитељ
комит
c1564f2952

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

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

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

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

+ 4 - 0
app/controller/group.js

@@ -23,6 +23,10 @@ class GroupController extends Controller {
     this.ctx.ok({ msg: 'ok', data: res });
   }
 
+  async sethead() {
+    const res = await this.service.sethead(this.ctx.request.body);
+    this.ctx.ok({ msg: 'ok', data: res });
+  }
 
 }
 

+ 19 - 0
app/controller/lessonmode.js

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

+ 19 - 0
app/controller/notice.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.notice.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 通知管理
+class NoticeController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.notice;
+  }
+
+
+}
+
+module.exports = CrudController(NoticeController, meta);

+ 1 - 0
app/model/group.js

@@ -6,6 +6,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const stuInfo = new Schema({
   stuid: { type: String, required: false, maxLength: 500 }, // 学生id
   stuname: { type: String, required: false, maxLength: 500 }, // 学生姓名
+  type: { type: String, required: false, maxLength: 500, default: '0' }, // 类型,0-组员,1-组长
 });
 
 // 分组表

+ 19 - 0
app/model/lessonmode.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 课程模板表
+const LessonmodeSchema = {
+  title: { type: String, required: true, maxLength: 500 }, // 标题
+  type: { type: String, required: true, maxLength: 500 }, // 类型,0-普通班,1-特殊班
+  lessons: { type: String, required: false }, // 课程信息
+};
+
+const schema = new Schema(LessonmodeSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Lessonmode', schema, 'lessonmode');
+};

+ 28 - 0
app/model/notice.js

@@ -0,0 +1,28 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 被通知详情表
+const notifiedInfo = new Schema({
+  notifiedid: { type: String, required: false, maxLength: 200 }, // 被通知人id
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-未读,1-已读
+  readtime: { type: String, required: false, maxLength: 200 }, // 读取时间
+});
+
+// 通知表
+const NoticeSchema = {
+  noticeid: { type: String, required: true, maxLength: 200 }, // 通知人id
+  content: { type: String, required: true }, // 通知内容
+  notified: { type: [ notifiedInfo ], select: true }, // 被通知信息
+
+};
+
+
+const schema = new Schema(NoticeSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Notice', schema, 'notice');
+};

+ 9 - 0
app/router.js

@@ -97,6 +97,7 @@ module.exports = app => {
   router.post('group', '/api/train/group/update/:id', controller.group.update);
   router.post('group', '/api/train/group/insert', controller.group.insert);
   router.post('group', '/api/train/group/exit', controller.group.exit);
+  router.post('group', '/api/train/group/sethead', controller.group.sethead);
 
   // 职责说明表设置路由
   router.resources('duty', '/api/train/duty', controller.duty); // index、create、show、destroy
@@ -176,4 +177,12 @@ module.exports = app => {
   // 聊天记录表设置路由
   router.resources('record', '/api/train/record', controller.record); // index、create、show、destroy
   router.post('record', '/api/train/record/update/:id', controller.record.update);
+
+  // 通知表设置路由
+  router.resources('notice', '/api/train/notice', controller.notice); // index、create、show、destroy
+  router.post('notice', '/api/train/notice/update/:id', controller.notice.update);
+
+  // 课程模板表设置路由
+  router.resources('lessonmode', '/api/train/lessonmode', controller.lessonmode); // index、create、show、destroy
+  router.post('lessonmode', '/api/train/lessonmode/update/:id', controller.lessonmode.update);
 };

+ 22 - 0
app/service/group.js

@@ -11,6 +11,7 @@ class GroupService extends CrudService {
   constructor(ctx) {
     super(ctx, 'group');
     this.model = this.ctx.model.Group;
+    this.smodel = this.ctx.model.Student;
   }
 
   async insert(data) {
@@ -39,6 +40,27 @@ class GroupService extends CrudService {
     }
     await group.save();
   }
+
+  // 设置学生为组长或组员
+  async sethead(data) {
+    const { groupid, stuid, type } = data;
+    const group = await this.model.findById(groupid);
+    const students = group.students;
+    for (const student of students) {
+      if (student.stuid === stuid) {
+        student.type = type;
+      }
+    }
+    await group.save();
+    const student = await this.smodel.findById(stuid);
+    if (type === '1') {
+      student.jod = '组长';
+    }
+    if (type === '0') {
+      student.jod = '普通学生';
+    }
+    await student.save();
+  }
 }
 
 

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

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