lrf402788946 4 years ago
parent
commit
d68f4dd3bb
1 changed files with 13 additions and 7 deletions
  1. 13 7
      app/service/school.js

+ 13 - 7
app/service/school.js

@@ -150,8 +150,8 @@ class SchoolService extends CrudService {
           delete i._id;
           return i;
         });
-        await this.ctx.model.Dstudent.insertMany(dbStuList);
         await this.smodel.deleteMany({ termid, batchid, schid });
+        await this.ctx.model.Dstudent.insertMany(dbStuList);
       }
 
       await this.smodel.insertMany(studentList);
@@ -174,7 +174,7 @@ class SchoolService extends CrudService {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到上传的名单');
     }
     const workbook = new Excel.Workbook();
-    await workbook.xlsx.load(file);
+    await workbook.xlsx.load(file.data);
     const worksheet = workbook.getWorksheet(1);
     if (!worksheet) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未发现excel中有工作表');
@@ -182,13 +182,19 @@ class SchoolService extends CrudService {
     const cols = this.getStucolumn();
     const headRow = worksheet.getRow(1);
     headRow.eachCell((cell, coli) => {
-      const r = cols.find(f => f.key === cell.value);
-      if (r) {
-        const ri = cols.findIndex(f => f.key === cell.value);
-        r.colIndex = coli;
-        cols[ri] = r;
+      if (cell.value !== '序号') {
+        const r = cols.find(f => f.key === cell.value);
+        if (r) {
+          const ri = cols.findIndex(f => f.key === cell.value);
+          r.colIndex = coli;
+          cols[ri] = r;
+        } else {
+          throw new BusinessError(`模板中"${cell.value}"列错误,请检查excel!`);
+        }
       }
+
     });
+    console.log(cols);
     const excelIsRigth = cols.find(f => f.colIndex);
     if (!excelIsRigth) throw new BusinessError(ErrorCode.DATA_INVALID, 'Excel表格格式不正确,请使用系统提供的模板!');
     // 删除掉第一行