Parcourir la source

班主任设置班长、学委后向他们发送消息;学生请假通过通知班长;寝室表新怎字段;科目表新增字段

reloaded il y a 5 ans
Parent
commit
d28d39f49f

+ 6 - 3
app/controller/.bedroom.js

@@ -5,7 +5,8 @@ module.exports = {
       'number',
       'batch',
       'gender',
-      'floor'
+      'floor',
+      'status'
     ]
   },
   destroy: {
@@ -19,7 +20,8 @@ module.exports = {
       'number',
       'batch',
       'gender',
-      'floor'
+      'floor',
+      'status'
     ]
   },
   show: {
@@ -35,7 +37,8 @@ module.exports = {
         number  :'number',
         batch :'batch',
         gender:'gender',
-        floor :'floor'
+        floor :'floor',
+        status : 'status'
       }
     },
     service: 'query',

+ 8 - 5
app/controller/.leave.js

@@ -2,11 +2,12 @@ module.exports = {
   create: {
     requestBody: [
       '!studentid',
-      '!starttime',
-      '!endtime',
+      'starttime',
+      'endtime',
       'reason',
       'status',
-      'refcause'
+      'refcause',
+      'type'
     ]
   },
   destroy: {
@@ -21,7 +22,8 @@ module.exports = {
       'endtime',
       'reason',
       'status',
-      'refcause'
+      'refcause',
+      'type'
     ]
   },
   show: {
@@ -38,7 +40,8 @@ module.exports = {
         endtime :'endtime',
         reason :'reason',
         status :'status',
-        refcause :'refcause'
+        refcause :'refcause',
+        type:'type'
       }
     },
     service: 'query',

+ 6 - 3
app/controller/.subject.js

@@ -2,7 +2,8 @@ module.exports = {
   create: {
     requestBody: [
       'code',
-      '!name'
+      '!name',
+      'type'
     ]
   },
   destroy: {
@@ -13,7 +14,8 @@ module.exports = {
     params: ['!id'],
     requestBody: [
       'code',
-      '!name'
+      '!name',
+      'type'
     ]
   },
   show: {
@@ -26,7 +28,8 @@ module.exports = {
     parameters: {
       query: {
         code: 'code',
-        name: 'name'
+        name: 'name',
+        type:'type'
       }
     },
     service: 'query',

+ 24 - 24
app/controller/.teacher.js

@@ -4,30 +4,30 @@ module.exports = {
       '!name',
       '!phone',
       '!idnumber',
-      'gender',
-      'zynumber',
-      'zynumberfile',
-      'schid',
-      'schname',
-      'email',
-      'openid',
-      'age',
-      'birthday',
-      'entrydate',
-      'politics',
-      'department',
-      'job',
-      'protitle',
-      'education',
-      'degree',
-      'major',
-      'schlesson',
-      'experience',
-      'courses',
-      'academic',
-      'jobyear',
-      'subid',
-      'islyteacher',
+      '!gender',
+      '!zynumber',
+      '!zynumberfile',
+      '!schid',
+      '!schname',
+      '!email',
+      '!openid',
+      '!age',
+      '!birthday',
+      '!entrydate',
+      '!politics',
+      '!department',
+      '!job',
+      '!protitle',
+      '!education',
+      '!degree',
+      '!major',
+      '!schlesson',
+      '!experience',
+      '!courses',
+      '!academic',
+      '!jobyear',
+      '!subid',
+      '!islyteacher',
       'zlscore',
       'msscore',
       'xsscore',

+ 5 - 0
app/controller/student.js

@@ -26,6 +26,11 @@ class StudentController extends Controller {
     this.ctx.ok({ data });
   }
 
+  async upjob() {
+    const data = await this.service.upjob(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
+
 }
 
 module.exports = CrudController(StudentController, meta);

+ 1 - 0
app/model/bedroom.js

@@ -9,6 +9,7 @@ const BedroomSchema = {
   batch: { type: String, required: false, maxLength: 200 }, // 批次
   gender: { type: String, required: false, maxLength: 200 }, // 男女限制
   floor: { type: String, required: false, maxLength: 200 }, // 楼层
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态:0-启用,1-停用
 };
 
 

+ 3 - 2
app/model/leave.js

@@ -5,11 +5,12 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 请假表
 const LeaveSchema = {
   studentid: { type: String, required: true, maxLength: 200 }, // 学生id
-  starttime: { type: String, required: true, maxLength: 200 }, // 开始时间
-  endtime: { type: String, required: true, maxLength: 500 }, // 结束时间
+  starttime: { type: String, required: false, maxLength: 200 }, // 开始时间
+  endtime: { type: String, required: false, maxLength: 500 }, // 结束时间
   reason: { type: String, required: false, maxLength: 2000 }, // 请假理由
   status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-审核中,1-通过,2-未通过
   refcause: { type: String, required: false, maxLength: 2000 }, // 拒绝原因
+  type: { type: String, required: false, maxLength: 200 }, // 类型,0-请假,1-退出
 };
 
 

+ 9 - 9
app/model/lesson.js

@@ -3,21 +3,21 @@ const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
 // 课程信息表
-const lessonInfo = new Schema({
-  teaname: { type: String, required: false, maxLength: 500 }, // 教师名称
-  teaid: { type: String, required: false, maxLength: 500 }, // 教师id
-  subname: { type: String, required: false, maxLength: 200 }, // 科目名称
-  subid: { type: String, required: false, maxLength: 200 }, // 科目id
-  date: { type: String, required: false, maxLength: 500 }, // 日期
-  day: { type: String, required: false, maxLength: 500 }, // 课程天数,半天或一天
-});
+// const lessonInfo = new Schema({
+//   teaname: { type: String, required: false, maxLength: 500 }, // 教师名称
+//   teaid: { type: String, required: false, maxLength: 500 }, // 教师id
+//   subname: { type: String, required: false, maxLength: 200 }, // 科目名称
+//   subid: { type: String, required: false, maxLength: 200 }, // 科目id
+//   date: { type: String, required: false, maxLength: 500 }, // 日期
+//   day: { type: String, required: false, maxLength: 500 }, // 课程天数,半天或一天
+// });
 
 // 课程表
 const LessonSchema = {
   classid: { type: String, required: true, maxLength: 500 }, // 班级id
   termid: { type: String, required: true, maxLength: 500 }, // 期id
   batchid: { type: String, required: true, maxLength: 500 }, // 批次id
-  lessons: { type: [ lessonInfo ], select: true }, // 课程信息
+  lessons: { type: String, required: false }, // 课程信息
 };
 
 const schema = new Schema(LessonSchema, { toJSON: { virtuals: true } });

+ 1 - 1
app/model/student.js

@@ -22,7 +22,7 @@ const StudentSchema = {
   family_place: { type: String, required: false, maxLength: 200 }, // 家庭所在地
   family_is_hard: { type: String, required: false, maxLength: 200 }, // 家庭是否困难,0-否,1-是
   have_grant: { type: String, required: false, maxLength: 200 }, // 是否获得过助学金,0-否,1-是
-  job: { type: String, required: false, maxLength: 200 }, // 职务
+  job: { type: String, required: false, maxLength: 200, default: '普通学生' }, // 职务
   termid: { type: String, required: false, maxLength: 200 }, // 期id
   batchid: { type: String, required: false, maxLength: 200 }, // 批次id
   classid: { type: String, required: false, maxLength: 200 }, // 班级id

+ 1 - 0
app/model/subject.js

@@ -6,6 +6,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const SubjectSchema = {
   code: { type: String, required: false, maxLength: 200 }, // 科目代码
   name: { type: String, required: false, maxLength: 500 }, // 科目名称
+  type: { type: String, required: false, maxLength: 500 }, // 类型,0-普通班,1-特殊班
 };
 
 

+ 1 - 0
app/router.js

@@ -37,6 +37,7 @@ module.exports = app => {
   router.get('sutdent', '/api/train/student/seek', controller.student.seek);
   router.resources('student', '/api/train/student', controller.student); // index、create、show、destroy
   router.post('student', '/api/train/student/update/:id', controller.student.update);
+  router.post('student', '/api/train/student/upjob', controller.student.upjob);
 
   // 班主任表设置路由
   router.resources('headteacher', '/api/train/headteacher', controller.headteacher); // index、create、show、destroy

+ 19 - 7
app/service/leave.js

@@ -49,28 +49,40 @@ class LeaveService extends CrudService {
     }
     if (status) {
       leave.status = status;
-      const student = await this.smodel.findById(studentid);
+      const student = await this.smodel.findById(leave.studentid);
       const remark = '感谢您的使用';
-      const stuuser = await this.umodel.findOne({ uid: studentid, type: '4' });
+      const stuuser = await this.umodel.findOne({ uid: leave.studentid, type: '4' });
       if (status === '1') {
+        // 通知中心管理员学生请假通过
         let detail = student.name + '的请假申请已通过,请及时查收!';
         const users = await this.umodel.find({ type: '0' });
         for (const user of users) {
           const openid = user.openid;
           const date = await this.ctx.service.util.updatedate();
-          await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+          this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
         }
         const _class = await this.cmodel.findById(student.classid);
+        // 通知班主任学生请假通过
         const headteacherid = _class.headteacherid;
         const headuser = await this.umodel.findOne({ uid: headteacherid, type: '1' });
         if (headuser) {
           const openid = headuser.openid;
           const date = await this.ctx.service.util.updatedate();
-          await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
-          const stuopenid = stuuser.openid;
-          detail = '您的请假申请已通过,请及时查收!';
-          await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, stuopenid, '您有一个新的通知', detail, date, remark);
+          this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
         }
+        const leadstu = await this.smodel.findOne({ classid: student.classid, job: '班长' });
+        console.log(leadstu);
+        const leaduser = await await this.umodel.findOne({ uid: leadstu.id, type: '4' });
+        if (leaduser) {
+          const openid = leaduser.openid;
+          const date = await this.ctx.service.util.updatedate();
+          this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+        }
+        const stuopenid = stuuser.openid;
+        detail = '您的请假申请已通过,请及时查收!';
+        const date = await this.ctx.service.util.updatedate();
+        await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, stuopenid, '您有一个新的通知', detail, date, remark);
+
       }
       if (status === '2') {
         const detail = '您的请假申请已被拒绝,拒绝原因为:' + refcause;

+ 18 - 0
app/service/student.js

@@ -11,6 +11,7 @@ class StudentService extends CrudService {
   constructor(ctx) {
     super(ctx, 'student');
     this.model = this.ctx.model.Student;
+    this.umodel = this.ctx.model.User;
   }
 
   // 查询
@@ -71,6 +72,23 @@ class StudentService extends CrudService {
     return result;
   }
 
+  async upjob(data) {
+    const { stuid, job } = data;
+    const student = await this.model.findById(stuid);
+    student.job = job;
+    if (job === '班长' || job === '学委') {
+      const user = await this.umodel.findOne({ uid: stuid, type: '4' });
+      const date = await this.ctx.service.util.updatedate();
+      const openid = user.openid;
+      const detail = '你已被班主任设置为' + job + ',请及时登录查看';
+      const remark = '感谢您的使用';
+      if (openid) {
+        this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+      }
+    }
+    return await student.save();
+  }
+
 }
 
 module.exports = StudentService;

+ 1 - 3
app/service/teacher.js

@@ -49,9 +49,7 @@ class TeacherService extends CrudService {
       } else if (status === '4') {
         detail = '您已通过审核被正式录入教师库';
       }
-      const moment = require('moment');
-      let date = new Date();
-      date = moment(date).format('YYYY-MM-DD HH:mm:ss');
+      const date = await this.ctx.service.util.updatedate();
       const user = await this.umodel.findOne({ uid: teacher.id, type: '3' });
       if (user && user.openid) {
         await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, teacher.openid, '您有一个新的通知', detail, date, remark);

+ 2 - 6
app/service/trainplan.js

@@ -62,9 +62,7 @@ class TrainplanService extends CrudService {
         const _teacher = await this.umodel.findOne({ uid: teacherid, type: '3' });
         const openid = _teacher.openid;
         const detail = trainplan.title + '已发布,请注意查收!';
-        const moment = require('moment');
-        let date = new Date();
-        date = moment(date).format('YYYY-MM-DD HH:mm:ss');
+        const date = await this.ctx.service.util.updatedate();
         const remark = '感谢您的使用';
         if (openid) {
           this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
@@ -75,9 +73,7 @@ class TrainplanService extends CrudService {
       for (const school of schools) {
         const openid = school.openid;
         const detail = trainplan.title + '已发布,请注意查收!';
-        const moment = require('moment');
-        let date = new Date();
-        date = moment(date).format('YYYY-MM-DD HH:mm:ss');
+        const date = await this.ctx.service.util.updatedate();
         const remark = '感谢您的使用';
         if (openid) {
           this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);