瀏覽代碼

增加学生计划id字段

liuyu 5 年之前
父節點
當前提交
9b01bce842
共有 3 個文件被更改,包括 14 次插入2 次删除
  1. 3 0
      app/controller/.student.js
  2. 1 0
      app/model/student.js
  3. 10 2
      app/service/school.js

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

@@ -20,6 +20,7 @@ module.exports = {
       'family_is_hard',
       'have_grant',
       'job',
+      'planid',
       'termid',
       'batchid',
       'classid',
@@ -55,6 +56,7 @@ module.exports = {
       'family_is_hard',
       'have_grant',
       'job',
+      'planid',
       'termid',
       'batchid',
       'classid',
@@ -92,6 +94,7 @@ module.exports = {
         family_is_hard:'family_is_hard',
         have_grant :'have_grant',
         job:'job',
+        planid:'planid',
         termid:'termid',
         batchid:'batchid',
         classid:'classid',

+ 1 - 0
app/model/student.js

@@ -23,6 +23,7 @@ const StudentSchema = {
   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, default: '普通学生' }, // 职务
+  planid: { type: String, required: false, maxLength: 200 }, // 计划id
   termid: { type: String, required: false, maxLength: 200 }, // 期id
   batchid: { type: String, required: false, maxLength: 200 }, // 批次id
   classid: { type: String, required: false, maxLength: 200 }, // 班级id

+ 10 - 2
app/service/school.js

@@ -14,6 +14,7 @@ class SchoolService extends CrudService {
     this.model = this.ctx.model.School;
     this.smodel = this.ctx.model.Student;
     this.umodel = this.ctx.model.User;
+    this.tmodel = this.ctx.model.Trainplan;
   }
 
   async stuimport(data) {
@@ -21,10 +22,16 @@ class SchoolService extends CrudService {
     assert(filepath, 'filepath不能为空');
     assert(termid, 'termid不能为空');
     assert(schid, 'schid不能为空');
+    // 根据termid取得计划信息
+    const plan = await this.tmodel.findOne({ 'termnum._id': ObjectId(termid) });
+    if (!plan) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '计划信息不存在');
+    }
+    const planid = plan.id;
     // 取得excle中数据
     const _filepath = this.ctx.app.config.baseUrl + filepath;
     console.log(_filepath);
-    const studatas = await this.getImportXLSXData(_filepath, termid, schid);
+    const studatas = await this.getImportXLSXData(_filepath, termid, schid, planid);
     console.log(studatas);
     // 将得到的数据校验
     const datacheck = await this.datacheck(studatas);
@@ -44,7 +51,7 @@ class SchoolService extends CrudService {
   }
 
   // 获取导入的XLSX文件中的数据
-  async getImportXLSXData(filepath, termid, schid) {
+  async getImportXLSXData(filepath, termid, schid, planid) {
     console.log(filepath);
     const file = await this.ctx.curl(filepath);
     const workbook = XLSX.read(file.data);
@@ -80,6 +87,7 @@ class SchoolService extends CrudService {
         have_grant: data[theadRule[15]],
         termid,
         schid,
+        planid,
       });
     }
     exceldata = [ ...exceldata, ..._datas ];