Quellcode durchsuchen

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

liuyu vor 5 Jahren
Ursprung
Commit
6e71c17b65

+ 3 - 3
app/controller/.leave.js

@@ -5,7 +5,7 @@ module.exports = {
       '!starttime',
       '!endtime',
       'reason',
-      'ispass',
+      'status',
       'refcause'
     ]
   },
@@ -20,7 +20,7 @@ module.exports = {
       'starttime',
       'endtime',
       'reason',
-      'ispass',
+      'status',
       'refcause'
     ]
   },
@@ -37,7 +37,7 @@ module.exports = {
         starttime :'starttime',
         endtime :'endtime',
         reason :'reason',
-        ispass :'ispass',
+        status :'status',
         refcause :'refcause'
       }
     },

+ 40 - 0
app/controller/.nation.js

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

+ 40 - 0
app/controller/.region.js

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

+ 19 - 0
app/controller/nation.js

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

+ 19 - 0
app/controller/region.js

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

+ 6 - 1
app/controller/student.js

@@ -12,7 +12,12 @@ class StudentController extends Controller {
     super(ctx);
     this.service = this.ctx.service.student;
   }
-
+  // GET
+  // 查询
+  async seek() {
+    const res = await this.service.seek(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
 
 }
 

+ 1 - 1
app/model/leave.js

@@ -8,7 +8,7 @@ const LeaveSchema = {
   starttime: { type: String, required: true, maxLength: 200 }, // 开始时间
   endtime: { type: String, required: true, maxLength: 500 }, // 结束时间
   reason: { type: String, required: false, maxLength: 2000 }, // 请假理由
-  ispass: { type: String, required: false, maxLength: 200 }, // 是否通过,0-未通过,1-通过
+  status: { type: String, required: false, maxLength: 200 }, // 状态,0-审核中,1-通过,2-未通过
   refcause: { type: String, required: false, maxLength: 2000 }, // 拒绝原因
 };
 

+ 19 - 0
app/model/nation.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 民族表
+const NationSchema = {
+  code: { type: String, required: false, maxLength: 500 }, // 代码
+  name: { type: String, required: false, maxLength: 500 }, // 名称
+};
+
+
+const schema = new Schema(NationSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Nation', schema, 'nation');
+};

+ 19 - 0
app/model/region.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 行政区划表
+const RegionSchema = {
+  code: { type: String, required: false, maxLength: 500 }, // 代码
+  name: { type: String, required: false, maxLength: 500 }, // 名称
+};
+
+
+const schema = new Schema(RegionSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Region', schema, 'region');
+};

+ 9 - 0
app/router.js

@@ -40,6 +40,7 @@ module.exports = app => {
   router.get('questionnaire', '/api/train/questionnaire/show/:id', controller.questionnaire.show);
 
   // 学生表设置路由
+  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);
 
@@ -113,4 +114,12 @@ module.exports = app => {
   router.resources('school', '/api/train/school', controller.school); // index、create、show、destroy
   router.post('school', '/api/train/school/update/:id', controller.school.update);
   router.post('/api/train/school/import', controller.school.stuimport); // 名单上传
+
+  // 民族表设置路由
+  router.resources('nation', '/api/train/nation', controller.nation); // index、create、show、destroy
+  router.post('nation', '/api/train/nation/update/:id', controller.nation.update);
+
+  // 行政区划表设置路由
+  router.resources('region', '/api/train/region', controller.region); // index、create、show、destroy
+  router.post('region', '/api/train/region/update/:id', controller.region.update);
 };

+ 29 - 14
app/service/class.js

@@ -23,23 +23,38 @@ class ClassService extends CrudService {
     const classdata = { name, batchid, termid, number, type };
     // 根据班级名称查询班级是否已存在
     const newclass = await this.model.findOne({ name });
-    // 如果已经存在抛出异常
+    // 如果已经存在
     if (newclass) {
       throw new BusinessError(ErrorCode.DATA_EXIST, '班级名称已存在');
+      // const classid = newclass._id;
+      // const oldstudents = this.stumodel.find({ classid });
+      // for (const oldstudent of oldstudents) {
+      //   oldstudent.classid = null;
+      // }
+      // // 遍历学生id
+      // for (const studentid of data.students) {
+      //   // 根据学生id找到学生数据修改其中的class字段
+      //   const student = await this.stumodel.findById(studentid);
+      //   student.batchid = batchid;
+      //   student.classid = classid;
+      //   await student.save();
+      // }
+    } else {
+      // 如果班级不存在则创建班级
+      const newdata = await this.model.create(classdata);
+      // 查询班级id
+      const classid = newdata._id;
+      // 遍历学生id
+      for (const studentid of data.students) {
+        // 根据学生id找到学生数据修改其中的class字段
+        const student = await this.stumodel.findById(studentid);
+        student.classid = classid;
+        student.batchid = batchid;
+        student.termid = termid;
+        await student.save();
+      }
     }
-    // 如果班级不存在则创建班级
-    const newdata = await this.model.create(classdata);
-    // 查询班级id
-    const classid = newdata._id;
-    // 遍历学生id
-    for (const studentid of data.students) {
-      // 根据学生id找到学生数据修改其中的class字段
-      const student = await this.stumodel.findById(studentid);
-      student.classid = classid;
-      student.batchid = batchid;
-      student.termid = termid;
-      await student.save();
-    }
+
   }
 }
 

+ 18 - 0
app/service/nation.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 NationService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'nation');
+    this.model = this.ctx.model.Nation;
+  }
+
+}
+
+module.exports = NationService;

+ 18 - 0
app/service/region.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 RegionService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'region');
+    this.model = this.ctx.model.Region;
+  }
+
+}
+
+module.exports = RegionService;

+ 9 - 0
app/service/student.js

@@ -13,6 +13,15 @@ class StudentService extends CrudService {
     this.model = this.ctx.model.Student;
   }
 
+  // 查询
+  async seek({ termid, skip, limit }) {
+    const students = await this.model.find({ termid, classid: null });
+    const data = await this.model.find({ termid, classid: null }).skip(Number(skip)).limit(Number(limit));
+    const total = await students.length;
+    const result = { total, data };
+    return result;
+  }
+
 }
 
 module.exports = StudentService;