Forráskód Böngészése

修改问卷表,加入快照功能

liuyu 5 éve
szülő
commit
8bac345922
3 módosított fájl, 30 hozzáadás és 14 törlés
  1. 17 1
      app/model/questionnaire.js
  2. 11 0
      app/service/class.js
  3. 2 13
      app/service/questionnaire.js

+ 17 - 1
app/model/questionnaire.js

@@ -3,17 +3,33 @@ const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
 
+// 选项详情
+const optionInfo = new Schema({
+  number: { type: String, required: false, maxLength: 200 }, // 序号
+  opname: { type: String, required: false, maxLength: 200 }, // 名称
+});
+
+// 问卷题
+const questionInfo = {
+  type: { type: String, required: true, maxLength: 200 }, // 类型,0-单选,1-多选,2-问答
+  topic: { type: String, required: true, maxLength: 500 }, // 题目
+  status: { type: String, required: false, maxLength: 200 }, // 状态,0-弃用,1-正常
+  option: { type: [ optionInfo ], select: true }, // 选项
+};
+
 // 问卷表
 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
+  status: { type: String, required: true, maxLength: 200, default: '0' }, // 状态,0-草稿,1-发布,2-禁用
+  question: { type: [ questionInfo ], required: false, select: true }, // 问卷
 };
 
 
 const schema = new Schema(QuestionnaireSchema, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
+schema.index({ type: 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 11 - 0
app/service/class.js

@@ -40,6 +40,8 @@ class ClassService extends CrudService {
       const beforestu = _.take(_students, stunum);
       // 将取出的数据调用更新学生的班级信息方法
       await this.studentup(_class.id, beforestu);
+      // 将班级自动分为组
+      await this.groupcreate(termid, _class.batchid, _class.id);
       // 取出的学生数据从原数据中删除
       _students = _.difference(_students, beforestu);
     }
@@ -57,6 +59,15 @@ class ClassService extends CrudService {
     }
   }
 
+  // 自动分组
+  async groupcreate(termid, batchid, classid) {
+    for (let i = 1; i < 8; i++) {
+      const name = i + '组';
+      const newdata = { name, termid, batchid, classid };
+      await this.gmodel.create(newdata);
+    }
+  }
+
   // 根据传入的学生列表和班级id更新学生信息
   async studentupclass({ id }, data) {
     assert(id, '班级id为必填项');

+ 2 - 13
app/service/questionnaire.js

@@ -50,7 +50,7 @@ class QuestionnaireService extends CrudService {
 
   // 查询
   async query({ skip, limit, ...num }) {
-    const total = await (await this.questionnairemodel.find(num)).length;
+    const total = await this.questionnairemodel.count(num);
     const data = await this.questionnairemodel.find(num).skip(Number(skip)).limit(Number(limit));
     const result = { total, data };
     return result;
@@ -59,18 +59,7 @@ class QuestionnaireService extends CrudService {
   // 查询详情
   async show({ id }) {
     const questionnaire = await this.questionnairemodel.findById(id);
-    const questions = await questionnaire.question;
-    const datas = [];
-    // 根据问卷中保存的问卷题目id查询题目详情
-    for (const code of questions) {
-      const question = await this.questionmodel.findById(code);
-      // 将查询出的题目放入一个数组中
-      datas.push(question);
-    }
-    questionnaire.question = datas;
-    // 将查询到的问卷id,名称,序号,查询到的问卷题目数组放到一个新的数据中
-    const newdata = { id, name: questionnaire.name, num: questionnaire.num, type: questionnaire.type, question: datas };
-    return newdata;
+    return questionnaire;
   }
 
 }