lrf402788946 4 éve
szülő
commit
b79475e7a5

+ 28 - 12
app/controller/.headteacher.js

@@ -2,12 +2,21 @@ module.exports = {
   create: {
     requestBody: [
       "!name",
-      "!phone",
       "gender",
-      "openid",
-      "age",
-      "birthday",
+      "nation",
+      "!mobile",
+      "phone",
+      "idnumber",
+      "politics",
+      "jobaddress",
       "department",
+      "job",
+      "protitle",
+      "education",
+      "degree",
+      "qq",
+      "openid",
+      "eduexperience",
       "islyteacher",
     ],
   },
@@ -18,13 +27,22 @@ module.exports = {
   update: {
     params: ["!id"],
     requestBody: [
-      "name",
-      "phone",
+      "!name",
       "gender",
-      "openid",
-      "age",
-      "birthday",
+      "nation",
+      "!mobile",
+      "phone",
+      "idnumber",
+      "politics",
+      "jobaddress",
       "department",
+      "job",
+      "protitle",
+      "education",
+      "degree",
+      "qq",
+      "openid",
+      "eduexperience",
       "islyteacher",
     ],
   },
@@ -38,11 +56,9 @@ module.exports = {
     parameters: {
       query: {
         name: "name",
-        phone: "phone",
+        mobile: "mobile",
         gender: "gender",
         openid: "openid",
-        age: "age",
-        birthday: "birthday",
         department: "department",
         islyteacher: "islyteacher",
       },

+ 21 - 27
app/controller/.lesson.js

@@ -1,46 +1,40 @@
 module.exports = {
   create: {
-    requestBody: [
-      '!classid',
-      '!termid',
-      '!batchid',
-      'lessons'
-    ]
+    requestBody: ["!classid", "!termid", "!batchid", "lessons"],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete'
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
-    requestBody: [
-      'classid',
-      'termid',
-      'batchid',
-      'lessons'
-    ]
+    params: ["!id"],
+    requestBody: ["classid", "termid", "batchid", "lessons"],
   },
   show: {
     parameters: {
-      params: ['!id']
+      params: ["!id"],
     },
-    service: 'fetch'
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        classid:'classid',
-        termid:'termid',
-        batchid:'batchid',
-        lessons :'lessons'
-      }
+        classid: "classid",
+        termid: "termid",
+        batchid: "batchid",
+        lessons: "lessons",
+      },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
       desc: true,
-      count: true
-    }
+      count: true,
+    },
+  },
+  check: {
+    requestBody: ["ids"],
+    service: "check",
   },
 };

+ 36 - 0
app/controller/.liveroom.js

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

+ 18 - 0
app/controller/liveroom.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.liveroom.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 教师申请讲课表管理
+class LiveroomController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.liveroom;
+  }
+
+}
+
+module.exports = CrudController(LiveroomController, meta);

+ 17 - 5
app/model/headteacher.js

@@ -6,13 +6,25 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 班主任表
 const HeadteacherSchema = {
   name: { type: String, required: true, maxLength: 200 }, // 姓名
-  phone: { type: String, required: true, maxLength: 200 }, // 手机号
-  gender: { type: String, required: false, maxLength: 200 }, // 教师性别
-  openid: { type: String, required: false, maxLength: 200 }, // 微信openid
+  gender: { type: String, required: true, maxLength: 200 }, // 教师性别
+  department: { type: String, required: true, maxLength: 200 }, // 所在部门
+  mobile: { type: String, required: true, maxLength: 200 }, // 手机号
+  nation: { type: String, required: false, maxLength: 200 }, // 民族
+  phone: { type: String, required: false, maxLength: 200 }, // 固话
+  idnumber: { type: String, required: false, maxLength: 18 }, // 身份证
+  politics: { type: String, required: false, maxLength: 18 }, // 政治面貌
+  jobaddress: { type: String, required: false, maxLength: 18 }, // 工作单位
+  job: { type: String, required: false, maxLength: 200 }, // 职务
+  protitle: { type: String, required: false, maxLength: 200 }, // 职称
+  education: { type: String, required: false, maxLength: 200 }, // 最后学历
+  degree: { type: String, required: false, maxLength: 200 }, // 最后学位
+  qq: { type: String, required: false, maxLength: 200 }, // qq
   age: { type: String, required: false, maxLength: 200 }, // 年龄
-  birthday: { type: String, required: false, maxLength: 200 }, // 出生年月
-  department: { type: String, required: false, maxLength: 200 }, // 所在部门
+  eduexperience: { type: [ Object ], required: false, maxLength: 200 }, // 教育培训经历
   islyteacher: { type: String, required: false, maxLength: 200 }, // 是否可讲礼仪课,0-否,1-是
+  openid: { type: String, required: false, maxLength: 200 }, // 微信openid
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态:0,待审核;1,审核通过;2,审核拒绝
+  // birthday: { type: String, required: false, maxLength: 200 }, // 出生年月
 };
 
 

+ 1 - 0
app/model/lesson.js

@@ -20,6 +20,7 @@ const LessonSchema = {
   termid: { type: String, required: true, maxLength: 500 }, // 期id
   batchid: { type: String, required: true, maxLength: 500 }, // 批次id
   lessons: { type: [ lessonInfo ], required: false, select: true }, // 课程信息
+  status: { type: String, required: false, maxLength: 500, default: '0' }, // 状态:0,未审核;1已通过;改成1的时候需要发送通知
 };
 
 const schema = new Schema(LessonSchema, { toJSON: { virtuals: true } });

+ 22 - 0
app/model/liveroom.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 教师直播房间
+const LiveroomSchema = {
+  number: { type: String, required: true, maxLength: 200 }, // 房间号
+  subid: { type: String, required: true, maxLength: 200 }, // 科目id
+  teacherid: { type: String, required: true, maxLength: 200 }, // 教师id
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态:0=>未审核;1=>通过;2=>拒绝
+  reason: { type: String, required: false, maxLength: 2000 }, // 申请原因
+};
+
+
+const schema = new Schema(LiveroomSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Liveroom', schema, 'liveroom');
+};

+ 48 - 9
app/router.js

@@ -198,16 +198,43 @@ module.exports = app => {
 
   // 培训计划表设置路由
   router.resources('trainplan', '/api/train/trainplan', controller.trainplan); // index、create、show、destroy
-  router.post('trainplan','/api/train/trainplan/update/:id',controller.trainplan.update);
-  router.post('/api/train/trainplan/exportExcel', controller.trainplan.exportExcel); // 导出
-  router.post('/api/train/trainplan/exportSchool', controller.trainplan.exportSchool); // 导出计划学校
-  router.post('/api/train/trainplan/exportPlan', controller.trainplan.exportPlan); // 导出计划日历
-  router.post('/api/train/trainplan/updateclass', controller.trainplan.updateclass);
-  router.post('/api/train/trainplan/updatereteacher', controller.trainplan.updatereteacher);
+  router.post(
+    'trainplan',
+    '/api/train/trainplan/update/:id',
+    controller.trainplan.update
+  );
+  router.post(
+    '/api/train/trainplan/exportExcel',
+    controller.trainplan.exportExcel
+  ); // 导出
+  router.post(
+    '/api/train/trainplan/exportSchool',
+    controller.trainplan.exportSchool
+  ); // 导出计划学校
+  router.post(
+    '/api/train/trainplan/exportPlan',
+    controller.trainplan.exportPlan
+  ); // 导出计划日历
+  router.post(
+    '/api/train/trainplan/updateclass',
+    controller.trainplan.updateclass
+  );
+  router.post(
+    '/api/train/trainplan/updatereteacher',
+    controller.trainplan.updatereteacher
+  );
 
   // 培训计划年度批次表设置路由
-  router.resources('trainplanyear', '/api/train/trainplanyear', controller.trainplanyear); // index、create、show、destroy
-  router.post('trainplanyear', '/api/train/trainplanyear/update/:id', controller.trainplanyear.update);
+  router.resources(
+    'trainplanyear',
+    '/api/train/trainplanyear',
+    controller.trainplanyear
+  ); // index、create、show、destroy
+  router.post(
+    'trainplanyear',
+    '/api/train/trainplanyear/update/:id',
+    controller.trainplanyear.update
+  );
 
   // 节假日表设置路由
   router.resources('festival', '/api/train/festival', controller.festival); // index、create、show、destroy
@@ -236,6 +263,7 @@ module.exports = app => {
     '/api/train/lesson/autolesson/:id',
     controller.lesson.autolesson
   ); // 自动排课
+  router.post('lesson', '/api/train/lesson/check', controller.lesson.check); // 确定(锁死)课表
 
   // 培训计划学校上报时间表设置路由
   router.resources('schtime', '/api/train/schtime', controller.schtime); // index、create、show、destroy
@@ -492,5 +520,16 @@ module.exports = app => {
 
   // 消息表设置路由
   router.resources('message', '/api/train/message', controller.message); // index、create、show、destroy
-  router.post('message', '/api/train/message/update/:id', controller.message.update);
+  router.post(
+    'message',
+    '/api/train/message/update/:id',
+    controller.message.update
+  );
+  // 直播房间
+  router.resources('liveroom', '/api/train/liveroom', controller.liveroom); // index、create、show、destroy
+  router.post(
+    'liveroom',
+    '/api/train/liveroom/update/:id',
+    controller.liveroom.update
+  );
 };

+ 9 - 7
app/service/headteacher.js

@@ -15,26 +15,28 @@ class HeadteacherService extends CrudService {
   }
 
   async create(data) {
-    const { name, phone } = data;
-    const user = await this.umodel.findOne({ mobile: phone });
+    const { name, mobile } = data;
+    const user = await this.umodel.findOne({ mobile });
     if (user) {
       throw new BusinessError(ErrorCode.DATA_EXIST, '电话已经存在');
     }
-    console.log(data);
     const res = await this.model.create(data);
-    const newdata = { name, mobile: phone, type: '1', uid: res.id };
+    const newdata = { name, mobile, type: '1', uid: res.id };
     newdata.passwd = { secret: '12345678' };
     await this.umodel.create(newdata);
   }
 
   async update({ id }, data) {
-    const { name, phone, openid } = data;
-    const user = await this.umodel.findOne({ mobile: phone });
+    const { name, mobile, openid } = data;
+    // 修改后的手机号查找是否已存在
+    console.log(mobile);
+    const have_mobile = await this.umodel.count({ mobile, uid: { $ne: id } });
+    if (have_mobile > 0) throw new BusinessError(ErrorCode.DATA_EXIST, '电话已经存在');
     const res = await this.model.update({ _id: ObjectId(id) }, data);
     if (res) {
       const _user = await this.umodel.findOne({ uid: id, type: '1' });
       if (_user) {
-        _user.mobile = phone;
+        _user.mobile = mobile;
         _user.name = name;
         if (openid) {
           _user.openid = openid;

+ 88 - 3
app/service/lesson.js

@@ -18,7 +18,8 @@ class LessonService extends CrudService {
     this.teamodel = this.ctx.model.Teacher;
     this.stumodel = this.ctx.model.Student;
     this.schmodel = this.ctx.model.School;
-
+    this.headteamodel = this.ctx.model.Headteacher;
+    this.umodel = this.ctx.model.User;
   }
 
   // 自动排课私有方法
@@ -53,7 +54,10 @@ class LessonService extends CrudService {
           if (!lessonmode_) {
             lessonmode_ = _lessonmode[0];
             if (!lessonmode_) {
-              throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '课程模板信息不存在');
+              throw new BusinessError(
+                ErrorCode.DATA_NOT_EXIST,
+                '课程模板信息不存在'
+              );
             }
           }
           // 取得模板内容并转化成json
@@ -117,7 +121,9 @@ class LessonService extends CrudService {
   // 自动排教师,按照分数的综合成绩排序,上报时间,安排教师
   async autoteacher(subid, teachids) {
     // 按照上报时间取得所有老师,进行正序排列
-    const teachers = await this.teamodel.find({ subid, status: '4' }).sort({ zlscore: '-1', msscore: '-1', xsscore: '-1' });
+    const teachers = await this.teamodel
+      .find({ subid, status: '4' })
+      .sort({ zlscore: '-1', msscore: '-1', xsscore: '-1' });
     for (const teaid of teachids) {
       _.remove(teachers, item => item.id === teaid);
     }
@@ -276,6 +282,85 @@ class LessonService extends CrudService {
       await this.model.findByIdAndUpdate(_data.id, _data);
     }
   }
+  /**
+   * 修改课表的状态,并发送信息
+   * @param {Array} ids 要修改的课表
+   */
+  async check({ ids }) {
+    // 1,修改课表状态; TODO 2,拿到所有的班级,获取所有人员;3,然后发送信息
+    const list = await this.model.find({ _id: { $in: ids } });
+    const res = await this.model.updateMany({ _id: { $in: ids } }, { status: '1' });
+    // 循环课表
+    for (const lessonInfo of list) {
+      // 获取期数
+      const { termid, classid, lessons } = lessonInfo;
+      const planRes = await this.tmodel.findOne({ termnum: { $elemMatch: { _id: termid } } });
+      if (!planRes) continue;
+      const term = planRes.termnum.find(f => ObjectId(termid).equals(f._id));
+      if (!term) continue;
+      const { term: termnum } = term;
+      const classInfo = await this.clamodel.findById(classid);
+      const { headteacherid, lyteacherid } = classInfo;
+      const headteacher = await this.headteamodel.findById(headteacherid);
+      if (headteacher) await this.toSendMsg(headteacher, 'headteacher', termnum);
+      // 礼仪教师和班主任不是一个人时查礼仪教师是班主任还是任课教师,然后发消息
+      if (lyteacherid !== headteacherid) {
+        let lyTeacher = await this.headteamodel.findById(lyteacherid);
+        if (lyTeacher) await this.toSendMsg(lyTeacher, 'headteacher', termnum);
+        else {
+          lyTeacher = await this.teamodel.findById(lyteacherid);
+          if (lyTeacher) await this.toSendMsg(lyTeacher, 'teacher', termnum);
+        }
+      }
+      // 获取所有任课教师ids
+      const teacherList = _.compact(_.uniq(lessons.map(i => i.teaid)));
+      if (teacherList) {
+        for (const tea of teacherList) {
+          await this.toSendMsg(tea, 'teacher', termnum);
+        }
+      }
+    }
+  }
+
+  async toSendMsg(teacherInfo, type, term) {
+    if (teacherInfo) {
+      let email;
+      if (type === 'headteacher') {
+        const { qq } = teacherInfo;
+        if (qq) email = `${qq}@qq.com`;
+      } else {
+        email = teacherInfo.email;
+      }
+      // 发邮件
+      if (email) {
+        const subject = '吉林省高等学校毕业生就业指导中心通知';
+        const text = teacherInfo.name + `您好!\n欢迎参加由吉林省高等学校毕业生就业指导中心举办的“双困生培训会”第${term}期,请您尽快登陆双困生培训系统查看您的安排`;
+        this.ctx.service.util.sendMail(email, subject, text);
+      }
+
+
+      // 获取openid,推送
+      console.log(teacherInfo);
+      const teacherUser = await this.umodel.findOne({ uid: teacherInfo._id });
+      console.log(teacherUser);
+      if (teacherUser) {
+        const { openid } = teacherUser;
+        if (openid) {
+          // TODO 推送
+          await this.ctx.service.weixin.sendTemplateDesign(
+            this.ctx.app.config.REVIEW_TEMPLATE_ID,
+            openid,
+            '您有一个新的通知',
+            '您有新的安排',
+            'null',
+            '感谢您的使用',
+            'http://www.baidu.com'
+          );
+        }
+      }
+    }
+  }
+
 }
 
 module.exports = LessonService;

+ 32 - 0
app/service/liveroom.js

@@ -0,0 +1,32 @@
+'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 LiveroomService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'apply');
+    this.model = this.ctx.model.Liveroom;
+  }
+  async create(data) {
+    const { subid, teacherid } = data;
+    assert(subid, '缺少科目信息');
+    assert(teacherid, '缺少教师信息');
+    const list = await this.model.find();
+    const last = _.last(list);
+    let number = '000001';
+    if (last) {
+      number = last.number * 1 + 1;
+    }
+    data.number = number;
+    const res = await this.model.create(data);
+    return res;
+  }
+
+}
+
+module.exports = LiveroomService;

+ 20 - 19
app/service/trainplan.js

@@ -21,25 +21,26 @@ class TrainplanService extends CrudService {
     this.schmodel = this.ctx.model.Schtime;
   }
 
-  //   async create(data) {
-  //     const terminfo = await data.termnum;
-  //     console.log(terminfo);
-  //     const { batchnum: { type, name, number }, term } = terminfo;
-  //     console.log(type);
-  //     if (type === 1) {
-  //       const classdata = { name, number, term, type };
-  //       await this.clamodel.create(classdata);
-  //     }
-  //     if (type === 0) {
-  //       for (let i = 0; i < class; i++) {
-  //         const name = '第' + term + '期' + batch + '批次' + i + '班';
-  //         const classdate = { name, number, term, type, newbatch };
-  //         await this.clamodel.create(classdate);
-  //       }
-  //     }
-  //     return this.tpmodel.create(data);
-  //   }
-  // }
+  async create(data) {
+    const { planyearid, year, title } = data;
+    assert(planyearid, '缺少大批次信息');
+    assert(year, '缺少年度');
+    assert(title, '缺少标题');
+    const res = await this.model.create(data);
+    console.log(res);
+    let planid = '';
+    if (res) planid = res._id;
+    const schoolList = await this.smodel.find();
+    const schtimeArr = [];
+    for (const sch of schoolList) {
+      const { code } = sch;
+      const obj = { schid: code, year, planid };
+      const schtimeres = await this.schmodel.create(obj);
+      if (schtimeres) schtimeArr.push(schtimeres);
+    }
+    if (!schtimeArr.every(e => e)) throw new BusinessError(ErrorCode.DATA_INVALID, '学校计划生成失败');
+    else return res;
+  }
 
   async update({ id }, data) {
     const trainplan = await this.model.findById(id);