Ver Fonte

服务端更新

reloaded há 5 anos atrás
pai
commit
e6e77825cd

+ 49 - 0
app/controller/.bedroom.js

@@ -0,0 +1,49 @@
+module.exports = {
+  create: {
+    requestBody: [
+      'code',
+      'number',
+      'batch',
+      'gender',
+      'floor'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'code',
+      'number',
+      'batch',
+      'gender',
+      'floor'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        code: 'code',
+        number  :'number',
+        batch :'batch',
+        gender:'gender',
+        floor :'floor'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 43 - 0
app/controller/.class.js

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

+ 37 - 0
app/controller/.department.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      '!name'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name: 'name'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 58 - 0
app/controller/.headteacher.js

@@ -0,0 +1,58 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      '!phone',
+      'gender',
+      'openid',
+      'age',
+      'birthday',
+      'department',
+      'is_etiquette_teacher'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name',
+      'phone',
+      'gender',
+      'openid',
+      'age',
+      'birthday',
+      'department',
+      'is_etiquette_teacher'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name :'name',
+        phone:'phone',
+        gender :'gender',
+        openid :'openid',
+        age :'age',
+        birthday :'birthday',
+        department :'department',
+        is_etiquette_teacher :'is_etiquette_teacher'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 37 - 0
app/controller/.location.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name: 'name'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 97 - 0
app/controller/.student.js

@@ -0,0 +1,97 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      '!id_number',
+      '!phone',
+      'gender',
+      'nation',
+      'school_name',
+      'major',
+      'entry_year',
+      'finish_year',
+      'school_job',
+      'qq',
+      'email',
+      'openid',
+      'family_place',
+      'family_is_hard',
+      'have_grant',
+      'job',
+      'term',
+      'batch',
+      'class',
+      'is_fine'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name',
+      'id_number',
+      'phone',
+      'gender',
+      'nation',
+      'school_name',
+      'major',
+      'entry_year',
+      'finish_year',
+      'school_job',
+      'qq',
+      'email',
+      'openid',
+      'family_place',
+      'family_is_hard',
+      'have_grant',
+      'job',
+      'term',
+      'batch',
+      'class',
+      'is_fine'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name:'name',
+        id_number: 'id_number',
+        phone:'phone',
+        gender:'gender',
+        nation:'nation',
+        school_name:'school_name',
+        major:'major',
+        entry_year:'entry_year',
+        finish_year:'finish_year',
+        school_job :'school_job',
+        qq :'qq',
+        email:'email',
+        openid:'openid',
+        family_place :'family_place',
+        family_is_hard:'family_is_hard',
+        have_grant :'have_grant',
+        job:'job',
+        term :'term',
+        batch :'batch',
+        class :'class',
+        is_fine:'is_fine'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 2 - 2
app/controller/.subject.js

@@ -25,8 +25,8 @@ module.exports = {
   index: {
     parameters: {
       query: {
-        name: 'code',
-        mobile: 'name'
+        code: 'code',
+        name: 'name'
       }
     },
     service: 'query',

+ 19 - 0
app/controller/bedroom.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.bedroom.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class BedroomController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.bedroom;
+  }
+
+
+}
+
+module.exports = CrudController(BedroomController, meta);

+ 19 - 0
app/controller/class.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.class.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class ClassController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.class;
+  }
+
+
+}
+
+module.exports = CrudController(ClassController, meta);

+ 19 - 0
app/controller/department.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.department.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class DepartmentController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.department;
+  }
+
+
+}
+
+module.exports = CrudController(DepartmentController, meta);

+ 19 - 0
app/controller/headteacher.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.headteacher.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 班主任管理
+class HeadteacherController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.headteacher;
+  }
+
+
+}
+
+module.exports = CrudController(HeadteacherController, meta);

+ 19 - 0
app/controller/location.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.location.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class LocationController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.location;
+  }
+
+
+}
+
+module.exports = CrudController(LocationController, meta);

+ 53 - 0
app/controller/question.js

@@ -0,0 +1,53 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class QusetionController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.question;
+  }
+
+  // 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() {
+    const res = await this.service.show(this.ctx.params);
+    this.ctx.ok({ msg: 'queried', data: res });
+  }
+
+}
+
+module.exports = QusetionController;

+ 53 - 0
app/controller/questionnaire.js

@@ -0,0 +1,53 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class QuestionnaireController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.questionnaire;
+  }
+
+  // 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() {
+    const res = await this.service.show(this.ctx.params);
+    this.ctx.ok({ msg: 'queried', data: res });
+  }
+
+}
+
+module.exports = QuestionnaireController;

+ 19 - 0
app/controller/student.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.student.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 学生管理
+class StudentController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.student;
+  }
+
+
+}
+
+module.exports = CrudController(StudentController, meta);

+ 2 - 0
app/controller/subject.js

@@ -12,6 +12,8 @@ class SubjectController extends Controller {
     super(ctx);
     this.service = this.ctx.service.subject;
   }
+
+
 }
 
 module.exports = CrudController(SubjectController, meta);

+ 52 - 0
app/controller/task.js

@@ -0,0 +1,52 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class TaskController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.task;
+  }
+
+  // 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() {
+    const res = await this.service.show(this.ctx.params);
+    this.ctx.ok({ msg: 'queried', data: res });
+  }
+
+}
+
+module.exports = TaskController;

+ 53 - 0
app/controller/teacher.js

@@ -0,0 +1,53 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class TeacherController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    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() {
+    const res = await this.service.fetchTeacher(this.ctx.params);
+    this.ctx.ok({ data: res });
+  }
+
+}
+
+module.exports = TeacherController;

+ 22 - 0
app/model/bedroom.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 寝室表
+const BedroomSchema = {
+  code: { type: String, required: true, maxLength: 200 }, // 寝室号
+  number: { type: String, required: true, maxLength: 200 }, // 人数
+  batch: { type: String, required: false, maxLength: 200 }, // 批次
+  gender: { type: String, required: false, maxLength: 200 }, // 男女限制
+  floor: { type: String, required: false, maxLength: 200 }, // 楼层
+};
+
+
+const schema = new Schema(BedroomSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Bedroom', schema, 'bedroom');
+};

+ 20 - 0
app/model/class.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 班级表
+const ClassSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 班级名称
+  number: { type: String, required: false, maxLength: 200 }, // 人数
+  batch: { type: String, required: false, maxLength: 200 }, // 批次
+};
+
+
+const schema = new Schema(ClassSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Class', schema, 'class');
+};

+ 18 - 0
app/model/department.js

@@ -0,0 +1,18 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 部门表
+const DepartmentSchema = {
+  name: { type: String, required: false, maxLength: 500 }, // 部门名称
+};
+
+
+const schema = new Schema(DepartmentSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Department', schema, 'department');
+};

+ 26 - 0
app/model/headteacher.js

@@ -0,0 +1,26 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+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
+  age: { type: String, required: false, maxLength: 200 }, // 年龄
+  birthday: { type: String, required: false, maxLength: 200 }, // 出生年月
+  department: { type: String, required: false, maxLength: 200 }, // 所在部门
+  is_etiquette_teacher: { type: String, required: false, maxLength: 200 }, // 是否可讲礼仪课,0-否,1-是
+}
+;
+
+const schema = new Schema(HeadteacherSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Headteacher', schema, 'headteacher');
+};

+ 18 - 0
app/model/location.js

@@ -0,0 +1,18 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 位置表
+const LocationSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 名称
+};
+
+
+const schema = new Schema(LocationSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Location', schema, 'location');
+};

+ 26 - 0
app/model/question.js

@@ -0,0 +1,26 @@
+'use strict';
+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 }, // 序号
+  option_name: { type: String, required: false, maxLength: 200 }, // 名称
+});
+
+// 问卷题库表
+const questionSchema = {
+  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 schema = new Schema(questionSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Question', schema, 'question');
+};

+ 25 - 0
app/model/questionnaire.js

@@ -0,0 +1,25 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 问题code表
+const questions = new Schema({
+  questionid: { type: String, required: false, maxLength: 200 }, // 序号
+});
+
+// 问卷表
+const QuestionnaireSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 问卷名称
+  num: { type: String, required: true, maxLength: 200 }, // 序号
+  question: { type: [ questions ], select: true }, // 问题code
+};
+
+
+const schema = new Schema(QuestionnaireSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Questionnaire', schema, 'questionnaire');
+};

+ 38 - 0
app/model/student.js

@@ -0,0 +1,38 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 学生表
+const StudentSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 姓名
+  id_number: { type: String, required: true, maxLength: 200 }, // 身份证号
+  phone: { type: String, required: true, maxLength: 200 }, // 手机号
+  gender: { type: String, required: false, maxLength: 200 }, // 性别
+  nation: { type: String, required: false, maxLength: 200 }, // 民族
+  school_name: { type: String, required: false, maxLength: 200 }, // 学校名称
+  major: { type: String, required: false, maxLength: 200 }, // 专业
+  entry_year: { type: String, required: false, maxLength: 200 }, // 入学年份
+  finish_year: { type: String, required: false, maxLength: 200 }, // 毕业年份
+  school_job: { type: String, required: false, maxLength: 200 }, // 在校担任何种职务
+  qq: { type: String, required: false, maxLength: 200 }, // QQ号
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  openid: { type: String, required: false, maxLength: 200 }, // 微信openid
+  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 }, // 职务
+  term: { type: String, required: false, maxLength: 200 }, // 期
+  batch: { type: String, required: false, maxLength: 200 }, // 批次
+  class: { type: String, required: false, maxLength: 200 }, // 班级
+  is_fine: { type: String, required: false, maxLength: 200 }, // 是否优秀,0-否,1-是
+}
+  ;
+
+const schema = new Schema(StudentSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Student', schema, 'student');
+};

+ 35 - 0
app/model/task.js

@@ -0,0 +1,35 @@
+'use strict';
+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 }, // 序号
+  option_name: { type: String, required: false, maxLength: 200 }, // 名称
+});
+
+// 问题详情
+const questionInfo = new Schema({
+  type: { type: String, required: false, maxLength: 200 }, // 类型,0-单选,1-多选,2-问答
+  topic: { type: String, required: false, maxLength: 500 }, // 题目
+  answer: { type: String, required: false, maxLength: 500 }, // 答案
+  option: { type: [ optionInfo ], select: true }, // 选项
+});
+
+// 作业表
+const TaskSchema = {
+  code: { type: String, required: true, maxLength: 200 }, // 科目代码
+  name: { type: String, required: true, maxLength: 500 }, // 科目名称
+  title: { type: String, required: true, maxLength: 500 }, // 标题
+  status: { type: String, required: false, maxLength: 200 }, // 状态,0-弃用,1-正常
+  question: { type: [ questionInfo ], select: true }, // 问题
+};
+
+const schema = new Schema(TaskSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Task', schema, 'task');
+};

+ 48 - 0
app/model/teacher.js

@@ -0,0 +1,48 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+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 }, // 资料名称
+  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 }, // 密码
+  phone: { type: String, required: true, maxLength: 200 }, // 手机号
+  id_number: { 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 }, // 学校名称
+  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 }, // 入职时间
+  job: { type: String, required: false, maxLength: 200 }, // 职务
+  major: { type: String, required: false, maxLength: 200 }, // 专业
+  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 }, // 学生评分
+  file: { type: [ FileInfo ], select: false }, // 资料,教案PPT视频等
+  status: { type: String, required: false, maxLength: 200 },
+  // 状态:0-注册,1-确认身份,2-资料评分,3-面试评分,4-确认入库
+}
+;
+
+const schema = new Schema(TeacherSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Teacher', schema, 'teacher');
+};

+ 53 - 1
app/router.js

@@ -9,5 +9,57 @@ module.exports = app => {
 
   // 科目表设置路由
   router.resources('subject', '/api/subject', controller.subject); // index、create、show、destroy
-  router.post('subject', '/api/subject/:id', controller.subject.update);
+  router.post('subject', '/api/subject/update/:id', controller.subject.update);
+
+  // 教师表设置路由
+  router.post('teacher', '/api/teacher', controller.teacher.create);
+  router.delete('teacher', '/api/teacher/:id', controller.teacher.delete);
+  router.post('teacher', '/api/teacher/update/:id', controller.teacher.update);
+  router.get('teacher', '/api/teacher', controller.teacher.query);
+  router.get('teacher', '/api/teacher/show/:id', controller.teacher.show);
+
+  // 作业表配置路由
+  router.post('task', '/api/task', controller.task.create);
+  router.delete('task', '/api/task/:id', controller.task.delete);
+  router.post('task', '/api/task/update/:id', controller.task.update);
+  router.get('task', '/api/task', controller.task.query);
+  router.get('task', '/api/task/show/:id', controller.task.show);
+
+  // 问卷题库表配置路由
+  router.post('question', '/api/question', controller.question.create);
+  router.delete('question', '/api/question/:id', controller.question.delete);
+  router.post('question', '/api/question/update/:id', controller.question.update);
+  router.get('question', '/api/question', controller.question.query);
+  router.get('question', '/api/question/show/:id', controller.question.show);
+
+  // 问卷表配置路由
+  router.post('questionnaire', '/api/questionnaire', controller.questionnaire.create);
+  router.delete('questionnaire', '/api/questionnaire/:id', controller.questionnaire.delete);
+  router.post('questionnaire', '/api/questionnaire/update/:id', controller.questionnaire.update);
+  router.get('questionnaire', '/api/questionnaire', controller.questionnaire.query);
+  router.get('questionnaire', '/api/questionnaire/show/:id', controller.questionnaire.show);
+
+  // 学生表设置路由
+  router.resources('student', '/api/student', controller.student); // index、create、show、destroy
+  router.post('student', '/api/student/update/:id', controller.student.update);
+
+  // 班主任表设置路由
+  router.resources('headteacher', '/api/headteacher', controller.headteacher); // index、create、show、destroy
+  router.post('headteacher', '/api/headteacher/update/:id', controller.headteacher.update);
+
+  // 寝室表设置路由
+  router.resources('bedroom', '/api/bedroom', controller.bedroom); // index、create、show、destroy
+  router.post('bedroom', '/api/bedroom/update/:id', controller.bedroom.update);
+
+  // 班级表设置路由
+  router.resources('class', '/api/class', controller.class); // index、create、show、destroy
+  router.post('class', '/api/class/update/:id', controller.class.update);
+
+  // 部门表设置路由
+  router.resources('department', '/api/department', controller.department); // index、create、show、destroy
+  router.post('department', '/api/department/update/:id', controller.department.update);
+
+  // 位置表设置路由
+  router.resources('location', '/api/location', controller.location); // index、create、show、destroy
+  router.post('location', '/api/location/update/:id', controller.location.update);
 };

+ 17 - 0
app/service/bedroom.js

@@ -0,0 +1,17 @@
+'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 BedroomService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'bedroom');
+    this.model = this.ctx.model.Bedroom;
+  }
+}
+
+module.exports = BedroomService;

+ 17 - 0
app/service/class.js

@@ -0,0 +1,17 @@
+'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 ClassService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'class');
+    this.model = this.ctx.model.Class;
+  }
+}
+
+module.exports = ClassService;

+ 18 - 0
app/service/department.js

@@ -0,0 +1,18 @@
+'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 DepartmentService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'subject');
+    this.model = this.ctx.model.Department;
+  }
+
+}
+
+module.exports = DepartmentService;

+ 18 - 0
app/service/headteacher.js

@@ -0,0 +1,18 @@
+'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 HeadteacherService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'headteacher');
+    this.model = this.ctx.model.Headteacher;
+  }
+
+}
+
+module.exports = HeadteacherService;

+ 18 - 0
app/service/location.js

@@ -0,0 +1,18 @@
+'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 LocationService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'location');
+    this.model = this.ctx.model.Location;
+  }
+
+}
+
+module.exports = LocationService;

+ 61 - 0
app/service/question.js

@@ -0,0 +1,61 @@
+'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 QuestionService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'question');
+    this.model = this.ctx.model.Question;
+  }
+
+  // 插入问卷题目
+  async create(data) {
+    const { type, topic } = data;
+    assert(type, '类型不能为空');
+    assert(topic, '题目不能为空');
+    // 插入数据时默认状态为1
+    const newdata = { ...data, status: '1' };
+    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';
+  }
+
+  // 根据id更新问卷题目
+  async upadate({ id }, data) {
+    const question = await this.model.findById(id);
+    if (question.type) {
+      question.code = data.code;
+    }
+    if (question.topic) {
+      question.name = data.name;
+    }
+    if (question.status) {
+      question.status = data.status;
+    }
+    question.option = data.option;
+    return await question.save();
+  }
+
+  // 查询
+  async query({ skip, limit, ...num }) {
+    return await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+  }
+
+  // 查询详情
+  async show({ id }) {
+    return await this.model.findById(id);
+  }
+
+}
+
+module.exports = QuestionService;

+ 68 - 0
app/service/questionnaire.js

@@ -0,0 +1,68 @@
+'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 QuestionnaireService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'qusetionnaire');
+    this.questionnairemodel = this.ctx.model.Questionnaire;
+    this.questionmodel = this.ctx.model.Question;
+  }
+
+  // 插入问卷
+  async create(data) {
+    const { name, num } = data;
+    assert(name, '问卷名称不能为空');
+    assert(num, '问卷序号不能为空');
+    return await this.questionnairemodel.create(data);
+  }
+
+  // 根据id删除问卷
+  async delete({ id }) {
+    await this.questionnairemodel.findByIdAndDelete(id);
+    return 'deleted';
+  }
+
+  // 根据id更新问卷信息
+  async update({ id }, data) {
+    const questionnaire = await this.questionnairemodel.findById(id);
+    if (questionnaire.name) {
+      questionnaire.name = data.name;
+    }
+    if (questionnaire.num) {
+      questionnaire.num = data.num;
+    }
+    questionnaire.question = data.question;
+    return await questionnaire.save();
+  }
+
+  // 查询
+  async query({ skip, limit, ...num }) {
+    return await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+  }
+
+  // 查询详情
+  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.questionid);
+      // 将查询出的题目放入一个数组中
+      datas.push(question);
+    }
+    questionnaire.question = datas;
+    // 将查询到的问卷id,名称,序号,查询到的问卷题目数组放到一个新的数据中
+    const newdata = { id, name: questionnaire.name, num: questionnaire.num, question: datas };
+    return newdata;
+  }
+
+}
+
+module.exports = QuestionnaireService;

+ 17 - 0
app/service/student.js

@@ -0,0 +1,17 @@
+'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 StudentService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'student');
+    this.model = this.ctx.model.Student;
+  }
+}
+
+module.exports = StudentService;

+ 65 - 0
app/service/task.js

@@ -0,0 +1,65 @@
+'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 TaskService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'task');
+    this.model = this.ctx.model.Task;
+  }
+
+  // 插入作业
+  async create(data) {
+    const { code, name, title } = data;
+    assert(code, '科目代码不能为空');
+    assert(name, '科目名称不能为空');
+    assert(title, '标题不能为空');
+    // 插入数据时默认状态为1
+    const newdata = { ...data, status: '1' };
+    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';
+  }
+
+  // 根据id更新作业信息
+  async upadate({ id }, data) {
+    const task = await this.model.findById(id);
+    if (task.code) {
+      task.code = data.code;
+    }
+    if (task.name) {
+      task.name = data.name;
+    }
+    if (task.title) {
+      task.title = data.title;
+    }
+    if (task.status) {
+      task.status = data.status;
+    }
+    task.question = data.question;
+    return await task.save();
+  }
+
+  // 查询
+  async query({ skip, limit, ...num }) {
+    return await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+  }
+
+  // 查询详情
+  async show({ id }) {
+    return await this.model.findById(id);
+  }
+
+}
+
+module.exports = TaskService;

+ 103 - 0
app/service/teacher.js

@@ -0,0 +1,103 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+
+class TeacherService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'teacher');
+    this.model = this.ctx.model.Teacher;
+  }
+
+  // 创建教师用户
+  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);
+    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.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 teacher = await this.model.find(number).skip(Number(skip)).limit(Number(limit));
+    return teacher;
+  }
+
+  // 查询详情
+  async fetchTeacher({ id }) {
+    // 将文件拼到查询到的数据后
+    return await this.model.findById(id, '+file');
+  }
+
+}
+
+module.exports = TeacherService;