瀏覽代碼

问卷表增加字段,分班时自动创建7个组

reloaded 5 年之前
父節點
當前提交
400ca2f592
共有 5 個文件被更改,包括 47 次插入37 次删除
  1. 1 0
      app/model/questionnaire.js
  2. 1 1
      app/model/teacher.js
  3. 11 7
      app/service/class.js
  4. 14 9
      app/service/questionnaire.js
  5. 20 20
      config/config.default.js

+ 1 - 0
app/model/questionnaire.js

@@ -7,6 +7,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const QuestionnaireSchema = {
   name: { type: String, required: true, maxLength: 200 }, // 问卷名称
   num: { type: String, required: true, maxLength: 200 }, // 序号
+  type: { type: String, required: true, maxLength: 200 }, // 类型,0-常用问卷,1-非常用问卷,2-教师问卷
   question: [ String ], // 问题code
 };
 

+ 1 - 1
app/model/teacher.js

@@ -13,7 +13,7 @@ const urlInfo = new Schema({
 const FileInfo = new Schema({
   url: { type: [ urlInfo ], select: true }, // 资料路径
   filename: { type: String, required: false, maxLength: 200 }, // 资料名称
-  type: { type: String, required: false, maxLength: 200 }, // 资料类别
+  type: { type: String, required: false, maxLength: 200 }, // 资料类别,教案(Word)、PPT、视频(Mp4)、其他(zip)
 });
 
 // 教师表

+ 11 - 7
app/service/class.js

@@ -15,17 +15,16 @@ class ClassService extends CrudService {
     this.lessmodel = this.ctx.model.Lesson;
     this.umodel = this.ctx.model.User;
     this.tmodel = this.ctx.model.Trainplan;
+    this.gmodel = this.ctx.model.Group;
   }
 
   async divide(data) {
-    const name = await data.classname;
-    const number = await data.students.length;
-    const type = await data.type;
-    const termid = await data.termid;
-    const batchid = await data.batchid;
-    const classdata = { name, batchid, termid, number, type };
+    const { classname, number, type, termid, batchid } = data;
+    const classdata = { name: classname, batchid, termid, number, type };
+    console.log(classdata);
     // 根据班级名称查询班级是否已存在
-    const newclass = await this.model.findOne({ name });
+    const newclass = await this.model.findOne({ name: classname });
+    console.log(newclass);
     // 如果已经存在
     if (newclass) {
       throw new BusinessError(ErrorCode.DATA_EXIST, '班级名称已存在');
@@ -56,6 +55,11 @@ class ClassService extends CrudService {
         student.termid = termid;
         await student.save();
       }
+      for (let i = 1; i <= 7; i++) {
+        const groupname = i + '组';
+        const groupdata = { termid, batchid, classid, name: groupname };
+        await this.gmodel.create(groupdata);
+      }
     }
 
   }

+ 14 - 9
app/service/questionnaire.js

@@ -16,9 +16,10 @@ class QuestionnaireService extends CrudService {
 
   // 插入问卷
   async create(data) {
-    const { name, num } = data;
+    const { name, num, type } = data;
     assert(name, '问卷名称不能为空');
     assert(num, '问卷序号不能为空');
+    assert(type, '问卷类型不能为空');
     return await this.questionnairemodel.create(data);
   }
 
@@ -30,16 +31,20 @@ class QuestionnaireService extends CrudService {
 
   // 根据id更新问卷信息
   async update({ id }, data) {
-    console.log(data);
+    const { name, num, type, question } = data;
     const questionnaire = await this.questionnairemodel.findById(id);
-    if (questionnaire.name) {
-      questionnaire.name = data.name;
+    if (name) {
+      questionnaire.name = name;
     }
-    if (questionnaire.num) {
-      questionnaire.num = data.num;
+    if (num) {
+      questionnaire.num = num;
+    }
+    if (type) {
+      questionnaire.type = type;
+    }
+    if (question) {
+      questionnaire.question = question;
     }
-    questionnaire.question = data.question;
-    console.log(questionnaire);
     return await questionnaire.save();
   }
 
@@ -64,7 +69,7 @@ class QuestionnaireService extends CrudService {
     }
     questionnaire.question = datas;
     // 将查询到的问卷id,名称,序号,查询到的问卷题目数组放到一个新的数据中
-    const newdata = { id, name: questionnaire.name, num: questionnaire.num, question: datas };
+    const newdata = { id, name: questionnaire.name, num: questionnaire.num, type: questionnaire.type, question: datas };
     return newdata;
   }
 

+ 20 - 20
config/config.default.js

@@ -59,27 +59,27 @@ module.exports = appInfo => {
   config.user_email = '1345526645@qq.com';
   config.auth_code = 'vnrzrxwserhyfeda';
 
-  // mq配置
-  config.amqp = {
-    client: {
-      hostname: '127.0.0.1',
-      username: 'visit',
-      password: 'visit',
-      vhost: 'train',
-    },
-    app: true,
-    agent: true,
-  };
+  // // mq配置
+  // 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,
-    },
-  };
+  // // redis config
+  // config.redis = {
+  //   client: {
+  //     port: 6379, // Redis port
+  //     host: '127.0.0.1', // Redis host
+  //     password: 123456,
+  //     db: 0,
+  //   },
+  // };
 
   // mongoose config
   config.mongoose = {