ソースを参照

更新教师表

reloaded 5 年 前
コミット
bc6c898b4e

+ 103 - 0
app/controller/.teacher.js

@@ -0,0 +1,103 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      '!passwd',
+      '!phone',
+      '!idnumber',
+      'gender',
+      'zynumber',
+      'zynumberfile',
+      'schid',
+      'schname',
+      'email',
+      'openid',
+      'age',
+      'birthday',
+      'entrydate',
+      'job',
+      'major',
+      'subid',
+      'islyteacher',
+      'zlscore',
+      'msscore',
+      'xsscore',
+      'file',
+      'status'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name',
+      'passwd',
+      'phone',
+      'idnumber',
+      'gender',
+      'zynumber',
+      'zynumberfile',
+      'schid',
+      'schname',
+      'email',
+      'openid',
+      'age',
+      'birthday',
+      'entrydate',
+      'job',
+      'major',
+      'subid',
+      'islyteacher',
+      'zlscore',
+      'msscore',
+      'xsscore',
+      'file',
+      'status'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name :'name',
+        passwd :'passwd',
+        phone :'phone',
+        idnumber :'idnumber',
+        gender :'gender',
+        zynumber :'zynumber',
+        zynumberfile :'zynumberfile',
+        schid :'schid',
+        schname:'schname',
+        email :'email',
+        openid :'openid',
+        age:'age',
+        birthday:'birthday',
+        entrydate :'entrydate',
+        job :'job',
+        major:'major',
+        subid:'subid',
+        islyteacher :'islyteacher',
+        zlscore:'zlscore',
+        msscore :'msscore',
+        xsscore:'xsscore',
+        file  :'file',
+        status  :'status'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 2 - 30
app/controller/teacher.js

@@ -2,6 +2,7 @@
 
 const _ = require('lodash');
 const Controller = require('egg').Controller;
+const meta = require('./.teacher.js');
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 老师管理
@@ -12,35 +13,6 @@ class TeacherController extends Controller {
     this.service = this.ctx.service.teacher;
   }
 
-  // POST
-  // 创建新的教师用户
-  async create() {
-    const res = await this.service.create(this.ctx.request.body);
-    this.ctx.ok({ msg: 'created', data: res });
-  }
-
-  // POST
-  // 根据id删除用户
-  async delete() {
-    const { id } = this.ctx.params;
-    await this.service.delete({ id });
-    this.ctx.ok({ msg: 'deleted' });
-  }
-
-  // POST
-  // 根据id更新信息
-  async update() {
-    await this.service.update(this.ctx.params, this.ctx.request.body);
-    this.ctx.ok({ msg: 'accepted' });
-  }
-
-  // GET
-  // 查询
-  async query() {
-    const res = await this.service.query(this.ctx.query);
-    this.ctx.ok({ msg: 'queried', data: res });
-  }
-
   // GET
   // 查询教师详情
   async show() {
@@ -55,4 +27,4 @@ class TeacherController extends Controller {
 
 }
 
-module.exports = TeacherController;
+module.exports = CrudController(TeacherController, meta);

+ 12 - 12
app/model/teacher.js

@@ -6,33 +6,33 @@ const { Secret } = require('naf-framework-mongoose/lib/model/schema');
 // 资料信息
 const FileInfo = new Schema({
   url: { type: String, required: false, maxLength: 200 }, // 资料地址
-  file_name: { type: String, required: false, maxLength: 200 }, // 资料名称
+  filename: { type: String, required: false, maxLength: 200 }, // 资料名称
   type: { type: String, required: false, maxLength: 200 }, // 资料类别
 });
 
 // 教师表
 const TeacherSchema = {
   name: { type: String, required: true, maxLength: 200 }, // 教师姓名
-  password: { type: Secret, required: true, select: false, maxLength: 200 }, // 密码
+  passwd: { type: Secret, required: true, select: false, maxLength: 200 }, // 密码
   phone: { type: String, required: true, maxLength: 200 }, // 手机号
-  id_number: { type: String, required: true, maxLength: 200 }, // 身份证号
+  idnumber: { type: String, required: true, maxLength: 200 }, // 身份证号
   gender: { type: String, required: false, maxLength: 200 }, // 教师性别
-  profession_number: { type: String, required: false, maxLength: 200 }, // 职业资格证号
-  profession_number_file: { type: String, required: false, maxLength: 200 }, // 职业资格证图片
-  school_code: { type: String, required: false, maxLength: 200 }, // 学校编码
-  school_name: { type: String, required: false, maxLength: 200 }, // 学校名称
+  zynumber: { type: String, required: false, maxLength: 200 }, // 职业资格证号
+  zynumberfile: { type: String, required: false, maxLength: 200 }, // 职业资格证图片
+  schid: { type: String, required: false, maxLength: 200 }, // 学校id
+  schname: { type: String, required: false, maxLength: 200 }, // 学校名称
   email: { type: String, required: false, maxLength: 200 }, // 邮箱
   openid: { type: String, required: false, maxLength: 200 }, // 微信openid
   age: { type: String, required: false, maxLength: 200 }, // 年龄
   birthday: { type: String, required: false, maxLength: 200 }, // 出生年月
-  entry_time: { type: String, required: false, maxLength: 200 }, // 入职时间
+  entrydate: { type: String, required: false, maxLength: 200 }, // 入职时间
   job: { type: String, required: false, maxLength: 200 }, // 职务
   major: { type: String, required: false, maxLength: 200 }, // 专业
   subid: { type: String, required: false, maxLength: 200 }, // 科目id
-  is_etiquette_teacher: { type: String, required: false, maxLength: 200 }, // 是否可讲礼仪课,0-否,1-是
-  file_score: { type: String, required: false, maxLength: 200 }, // 资料评分
-  interview_score: { type: String, required: false, maxLength: 200 }, // 面试评分
-  student_score: { type: String, required: false, maxLength: 200 }, // 学生评分
+  islyteacher: { type: String, required: false, maxLength: 200 }, // 是否可讲礼仪课,0-否,1-是
+  zlscore: { type: String, required: false, maxLength: 200 }, // 资料评分
+  msscore: { type: String, required: false, maxLength: 200 }, // 面试评分
+  xsscore: { type: String, required: false, maxLength: 200 }, // 学生评分
   file: { type: [ FileInfo ], select: false }, // 资料,教案PPT视频等
   status: { type: String, required: false, maxLength: 200 },
   // 状态:0-注册,1-确认身份,2-资料评分,3-面试评分,4-确认入库

+ 1 - 4
app/router.js

@@ -12,11 +12,8 @@ module.exports = app => {
   router.post('subject', '/api/train/subject/update/:id', controller.subject.update);
 
   // 教师表设置路由
-  router.post('teacher', '/api/train/teacher', controller.teacher.create);
-  router.delete('teacher', '/api/train/teacher/:id', controller.teacher.delete);
-  router.post('teacher', '/api/train/teacher/update/:id', controller.teacher.update);
-  router.get('teacher', '/api/train/teacher', controller.teacher.query);
   router.get('teacher', '/api/train/teacher/show/:id', controller.teacher.show);
+  router.resources('teacher', '/api/train/teacher', controller.teacher); // index、create、show、destroy
   router.post('teacher', '/api/train/teacher/status', controller.teacher.status);
 
   // 作业表配置路由

+ 1 - 1
app/service/department.js

@@ -9,7 +9,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 
 class DepartmentService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'subject');
+    super(ctx, 'department');
     this.model = this.ctx.model.Department;
   }
 

+ 16 - 1
app/service/leave.js

@@ -11,8 +11,23 @@ class LeaveService extends CrudService {
   constructor(ctx) {
     super(ctx, 'leave');
     this.model = this.ctx.model.Leave;
+    this.smodel = this.ctx.model.Student;
+    this.umodel = this.ctx.model.User;
+  }
+  async create(data) {
+    const newdata = { ...data, status: '0' };
+    const entity = await this.model.create(newdata);
+    const studentid = data.studentid;
+    const student = await this.smodel.findById(studentid);
+    const schoolid = student.schoolid;
+    const user = await this.umodel.findOne({ uid: schoolid });
+    const openid = user.openid;
+    const date = await this.ctx.service.util.updatedate();
+    const detail = student.name + '发起了请假请求,请及时处理';
+    const remark = '感谢您的使用';
+    await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+    return await this.fetch({ id: entity.id });
   }
-
 
 }
 

+ 1 - 78
app/service/teacher.js

@@ -14,88 +14,11 @@ class TeacherService extends CrudService {
     this.umodel = this.ctx.model.User;
   }
 
-  // 创建教师用户
-  async create(data) {
-    const { name, password, phone, id_number } = data;
-    assert(name, '姓名不能为空');
-    assert(password, '密码不能为空');
-    assert(phone, '手机号不能为空');
-    assert(id_number, '身份证号不能为空');
-
-
-    // 检查是否已经注册
-    const teacher = await this.model.findOne({ id_number });
-    if (teacher) {
-      throw new BusinessError(ErrorCode.DATA_EXIST, '已经注册,无需重复注册');
-    }
-
-    // 插入数据时默认状态为0
-    const newdata = { ...data, status: '0' };
-
-    newdata.password = { secret: password };
-
-    const entity = await this.model.create(newdata);
-    return await this.fetch({ id: entity.id });
-  }
-
-  // 根据id删除教师信息
-  async delete({ id }) {
-    await this.model.findByIdAndDelete(id);
-    return 'deleted';
-  }
-
   // 根据状态删除教师信息
   async deleteByStatus({ status }) {
-    const teacher = await this.model.findOne(status);
-    this.model.deleteOne(teacher);
+    await this.model.deleteMany({ status });
     return 'deleted';
   }
-
-  // 根据id更新信息
-  async update({ id }, data) {
-    const teacher = await this.model.findById(id);
-    if (data.name) {
-      teacher.name = data.name;
-    }
-    if (data.phone) {
-      teacher.phone = data.phone;
-    }
-    if (data.id_number) {
-      teacher.id_number = data.id_number;
-    }
-    if (data.password) {
-      teacher.password = { secret: data.password };
-    }
-    teacher.gender = data.gender;
-    teacher.profession_number = data.profession_number;
-    teacher.profession_number_file = data.profession_number_file;
-    teacher.school_code = data.school_code;
-    teacher.school_name = data.school_name;
-    teacher.email = data.email;
-    teacher.openid = data.openid;
-    teacher.age = data.age;
-    teacher.birthday = data.birthday;
-    teacher.entry_time = data.entry_time;
-    teacher.job = data.job;
-    teacher.major = data.major;
-    teacher.subid = data.subid;
-    teacher.status = data.status;
-    teacher.file_score = data.file_score;
-    teacher.is_etiquette_teacher = data.is_etiquette_teacher;
-    teacher.interview_score = data.interview_score;
-    teacher.student_score = data.student_score;
-
-    return await teacher.save();
-  }
-
-  // 根据参数查询信息
-  async query({ skip, limit, ...number }) {
-    const total = await this.model.find(number);
-    const teacher = await this.model.find(number).skip(Number(skip)).limit(Number(limit));
-    const result = { total, teacher };
-    return result;
-  }
-
   // 查询详情
   async fetchTeacher({ id }) {
     // 将文件拼到查询到的数据后

+ 21 - 0
app/service/util.js

@@ -0,0 +1,21 @@
+'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;
+const moment = require('moment');
+
+class UtilService extends CrudService {
+
+  async updatedate() {
+    let date = new Date();
+    date = moment(date).format('YYYY-MM-DD HH:mm:ss');
+    return date;
+  }
+
+}
+
+module.exports = UtilService;