소스 검색

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

liuyu 4 년 전
부모
커밋
c463bedd7e
6개의 변경된 파일98개의 추가작업 그리고 30개의 파일을 삭제
  1. 33 29
      app/controller/.uploadquestion.js
  2. 5 1
      app/controller/notice.js
  3. 5 0
      app/controller/uploadquestion.js
  4. 1 0
      app/model/uploadquestion.js
  5. 41 0
      app/service/notice.js
  6. 13 0
      app/service/uploadquestion.js

+ 33 - 29
app/controller/.uploadquestion.js

@@ -1,50 +1,54 @@
 module.exports = {
   create: {
     requestBody: [
-      '!termid',
-      '!batchid',
-      '!classid',
-      '!studentid',
-      '!questionnaireid',
-      'answers'
-    ]
+      "planid",
+      "!termid",
+      "!batchid",
+      "!classid",
+      "!studentid",
+      "!questionnaireid",
+      "answers",
+    ],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete'
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
+    params: ["!id"],
     requestBody: [
-      'termid',
-      'batchid',
-      'classid',
-      'studentid',
-      'questionnaireid',
-      'answers'
-    ]
+      "planid",
+      "termid",
+      "batchid",
+      "classid",
+      "studentid",
+      "questionnaireid",
+      "answers",
+    ],
   },
   show: {
     parameters: {
-      params: ['!id']
+      params: ["!id"],
     },
-    service: 'fetch'
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        termid : 'termid',
-        batchid: 'batchid',
-        classid : 'classid',
-        studentid : 'studentid'
-      }
+        planid: "planid",
+        termid: "termid",
+        batchid: "batchid",
+        classid: "classid",
+        studentid: "studentid",
+        questionnaireid:"questionnaireid"
+      },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
       desc: true,
-      count: true
-    }
+      count: true,
+    },
   },
 };

+ 5 - 1
app/controller/notice.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 通知管理
 class NoticeController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.notice;
@@ -17,6 +16,11 @@ class NoticeController extends Controller {
     const res = await this.service.look(this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
+
+  async index() {
+    const data = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...data });
+  }
 }
 
 module.exports = CrudController(NoticeController, meta);

+ 5 - 0
app/controller/uploadquestion.js

@@ -19,6 +19,11 @@ class UploadquestionController extends Controller {
     this.ctx.ok({ ...res });
   }
 
+  async index() {
+    const res = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+
 }
 
 module.exports = CrudController(UploadquestionController, meta);

+ 1 - 0
app/model/uploadquestion.js

@@ -10,6 +10,7 @@ const answerInfo = new Schema({
 
 // 学生上传问卷表
 const UploadquestionSchema = {
+  planid: { type: String, required: true, maxLength: 200 }, // 计划id
   termid: { type: String, required: true, maxLength: 200 }, // 期id
   batchid: { type: String, required: true, maxLength: 200 }, // 批次id
   classid: { type: String, required: true, maxLength: 200 }, // 班级id

+ 41 - 0
app/service/notice.js

@@ -13,6 +13,10 @@ class NoticeService extends CrudService {
     super(ctx, 'notice');
     this.model = this.ctx.model.Notice;
     this.umodel = this.ctx.model.User;
+    this.stumodel = this.ctx.model.Student;
+    this.schmodel = this.ctx.model.School;
+    this.heamodel = this.ctx.model.Headteacher;
+    this.teamodel = this.ctx.model.Teacher;
   }
 
   async create(data) {
@@ -52,6 +56,43 @@ class NoticeService extends CrudService {
     }
   }
 
+  async query({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const notices = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const res = [];
+    for (const _notice of notices) {
+      const notice = _.cloneDeep(JSON.parse(JSON.stringify(_notice)));
+      const { noticeid, content, notified, meta } = notice;
+      const elm = [];
+      for (const notified of notice.notified) {
+        const _notified = _.cloneDeep(JSON.parse(JSON.stringify(notified)));
+        const user = await this.umodel.findOne({ uid: _notified.notifiedid });
+        const userinfo = await this.findUserInfo(user);
+        console.log({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
+        elm.push({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
+      }
+      res.push({ noticeid, content, meta, notified: elm });
+    }
+    return { data: res, total };
+  }
+
+  async findUserInfo(user) {
+    let userinfo;
+    if (user.type === '1') {
+      userinfo = await this.heamodel.findById(user.uid);
+    } else if (user.type === '2') {
+      userinfo = await this.schmodel.findById(user.uid);
+    } else if (user.type === '3') {
+      userinfo = await this.teamodel.findById(user.uid);
+      if (userinfo) {
+        delete userinfo.status;
+      }
+    } else if (user.type === '4') {
+      userinfo = await this.stumodel.findById(user.uid);
+    }
+    return userinfo;
+  }
+
 }
 
 module.exports = NoticeService;

+ 13 - 0
app/service/uploadquestion.js

@@ -85,6 +85,19 @@ class UploadquestionService extends CrudService {
     return newdata;
   }
 
+  async query({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const data = [];
+    for (const _res of res) {
+      const elm = _.cloneDeep(JSON.parse(JSON.stringify(_res)));
+      const stu = await this.smodel.findById(elm.studentid);
+      elm.studentname = stu.name;
+      data.push(elm);
+    }
+    return { data, total };
+  }
+
 }
 
 module.exports = UploadquestionService;