lrf402788946 4 vuotta sitten
vanhempi
commit
ebe0821694
2 muutettua tiedostoa jossa 48 lisäystä ja 56 poistoa
  1. 7 7
      app/model/student.js
  2. 41 49
      app/service/student.js

+ 7 - 7
app/model/student.js

@@ -12,7 +12,7 @@ const StudentSchema = {
   nation: { type: String, required: false, maxLength: 200, zh: '民族' }, // 民族
   insurance: { type: String, required: false, maxLength: 200, zh: '拓训时间' }, // 拓训时间
   school_name: { type: String, required: false, maxLength: 200, zh: '学校名称' }, // 学校名称
-  schid: { type: String, required: false, maxLength: 200, zh: '学校id' }, // 学校id
+  isComming: { type: String, default: '0', zh: '是否参培' }, // 是否签到0否,1是
   faculty: { type: String, required: false, maxLength: 200, zh: '院系' }, // 院系
   major: { type: String, required: false, maxLength: 200, zh: '专业' }, // 专业
   edua_level: { type: String, required: false, maxLength: 200, zh: '学历层次' }, // 学历层次
@@ -20,25 +20,25 @@ const StudentSchema = {
   entry_year: { type: String, required: false, maxLength: 200, zh: '入学年份' }, // 入学年份
   finish_year: { type: String, required: false, maxLength: 200, zh: '毕业年份' }, // 毕业年份
   school_job: { type: String, required: false, maxLength: 200, zh: '在校担任何种职务' }, // 在校担任何种职务
+  bedroom: { type: String, required: false, maxLength: 200, zh: '寝室号' }, // 寝室号
+  is_fine: { type: String, required: false, maxLength: 200, default: '0', zh: '是否优秀' }, // 是否优秀,0-否,1-是,2-无资格
+  selfscore: { type: String, required: false, maxLength: 200, zh: '个人分' }, // 个人分
+  score: { type: String, required: false, maxLength: 200, zh: '总分' }, // 总分
   qq: { type: String, required: false, maxLength: 200, zh: 'QQ号' }, // QQ号
   email: { type: String, required: false, maxLength: 200, zh: '邮箱' }, // 邮箱
-  openid: { type: String, required: false, maxLength: 200, zh: '微信openid' }, // 微信openid
   family_place: { type: String, required: false, maxLength: 200, zh: '家庭所在地' }, // 家庭所在地
   family_is_hard: { type: String, required: false, maxLength: 200, zh: '家庭是否困难' }, // 家庭是否困难,0-否,1-是
   have_grant: { type: String, required: false, maxLength: 200, zh: '是否获得过助学金' }, // 是否获得过助学金,0-否,1-是
   job: { type: String, required: false, maxLength: 200, default: '普通学生', zh: '职务' }, // 职务
+  schid: { type: String, required: false, maxLength: 200, zh: '学校id' }, // 学校id
   planyearid: { type: String, required: false, maxLength: 200, zh: '大批次id' }, // 大批次id
   planid: { type: String, required: false, maxLength: 200 }, // 计划id
   termid: { type: String, required: false, maxLength: 200, zh: '期' }, // 期id
   batchid: { type: String, required: false, maxLength: 200, zh: '批次' }, // 批次id
   classid: { type: String, required: false, maxLength: 200, zh: '班级' }, // 班级id
   bedroomid: { type: String, required: false, maxLength: 200, zh: '寝室id' }, // 寝室id
-  bedroom: { type: String, required: false, maxLength: 200, zh: '寝室号' }, // 寝室号
-  is_fine: { type: String, required: false, maxLength: 200, default: '0', zh: '是否优秀' }, // 是否优秀,0-否,1-是,2-无资格
-  selfscore: { type: String, required: false, maxLength: 200, zh: '个人分' }, // 个人分
-  score: { type: String, required: false, maxLength: 200, zh: '总分' }, // 总分
+  openid: { type: String, required: false, maxLength: 200, zh: '微信openid' }, // 微信openid
   diy: { type: { Object }, required: false, zh: '自定义' }, // 自定义
-  isComming: { type: String, default: '0', zh: '签到' }, // 是否签到0否,1是
   type: { type: String, required: false, maxLength: 200, default: '0' }, // 类型:0-正常,1-特殊
   status: { type: String, required: false, maxLength: 200, default: '1' }, // 0:待确定。1:确定,2:失败
   cert: { type: String, required: false, default: '0' }, // 证书状态,0=>未打印;1=已打印

+ 41 - 49
app/service/student.js

@@ -487,50 +487,19 @@ class StudentService extends CrudService {
       }
     });
     model = _.compact(model);
-    const { planid, termid: tids, batchid, classid } = data;
-    if (tids && !_.isArray(tids)) throw new BusinessError(ErrorCode.DATA_INVALID, '期数据不正确');
-    const condition = {};
-    if (planid) condition.planid = planid;
-    if (batchid)condition.batchid = batchid;
-    if (classid)condition.classid = classid;
-    const res = [];
-    if (tids.length === 1) {
-      condition.termid = _.head(tids);
-      const r = await this.dataToExcel(condition, model);
-      if (r) res.push(r);
-    } else {
-      for (const tid of tids) {
-        condition.termid = tid;
-        const r = await this.dataToExcel(condition, model);
-        if (r) res.push(r);
-      }
-    }
-    console.log(res);
-    if (res.length === 1) return _.head(res);
-    else if (res.length > 1) {
-      let fn = '学生名单';
-      let tStr = '';
-      for (let i = 0; i < tids.length; i++) {
-        const tid = tids[i];
-        const obj = await this.toGetFn(tid);
-        if (obj) {
-          const { term } = obj;
-          if (term) {
-            if (i === 0) { tStr += `${term}期`; } else { tStr += `,${term}期`; }
-          }
-        }
-      }
-      fn = `${tStr}${fn}`;
-      return await this.ctx.service.util.toZip(res, fn);
-    }
-
-  }
-
-  // 准备数据
-  async dataToExcel(condition, model) {
-    const { planid, termid, batchid, classid } = condition;
     // 请求数据
-    let { data: studentList } = await this.query(condition);
+    // 修改条件,termid变成数组了,需要一个一个查出来
+    const { planid, termid, batchid, classid } = data;
+    const queryObject = { };
+    if (planid) queryObject.planid = planid;
+    if (batchid) queryObject.batchid = batchid;
+    if (classid) queryObject.classid = classid;
+    let studentList = [];
+    for (const t of termid) {
+      queryObject.termid = t;
+      const { data: stuList } = await this.query(queryObject);
+      studentList.push(...stuList);
+    }
     studentList = JSON.parse(JSON.stringify(studentList));
     let ids = studentList.map(i => i.classid);
     ids = _.uniq(ids);
@@ -538,13 +507,18 @@ class StudentService extends CrudService {
     ids = ids.map(i => ObjectId(i));
     const classList = await this.ctx.model.Class.find({ _id: { $in: ids } });
     for (const stu of studentList) {
-      const { classid } = stu;
+      // 转换是否参培
+      const { classid, isComming } = stu;
       if (!classid) continue;
       const cla = await this.ctx.service.class.fetch({ id: classid });
       if (!cla) continue;
       const { startdate } = cla;
       if (!startdate) continue;
       stu.insurance = moment(startdate).add(1, 'd').format('YYYY-MM-DD');
+      if (isComming) {
+        if (isComming === '0') stu.isComming = '否';
+        if (isComming === '1') stu.isComming = '是';
+      }
     }
     let fn = '学生名单';
     // 因为是递进下来, batchid和classid并列,并非递进
@@ -565,7 +539,8 @@ class StudentService extends CrudService {
       }
     } else if (batchid) {
       // 文件名称,期,批
-      const obj = await this.toGetFn(termid, batchid);
+      const tid = _.head(termid);
+      const obj = await this.toGetFn(tid, batchid);
       if (obj) {
         const { term, batch } = obj;
         if (batch) fn = `第${batch}批${fn}`;
@@ -573,10 +548,25 @@ class StudentService extends CrudService {
       }
     } else if (termid) {
       // 文件名称: 期
-      const obj = await this.toGetFn(termid);
-      if (obj) {
-        const { term } = obj;
-        if (term) fn = `第${term}期${fn}`;
+      if (termid.length === 1) {
+        const obj = await this.toGetFn(_.head(termid));
+        if (obj) {
+          const { term } = obj;
+          if (term) fn = `第${term}期${fn}`;
+        }
+      } else {
+        let tStr = '';
+        for (let i = 0; i < termid.length; i++) {
+          const tid = termid[i];
+          const obj = await this.toGetFn(tid);
+          if (obj) {
+            const { term } = obj;
+            if (term) {
+              if (i === 0) { tStr += `${term}期`; } else { tStr += `,${term}期`; }
+            }
+          }
+        }
+        fn = `${tStr}${fn}`;
       }
     } else if (planid) {
       // 文件名称:该计划标题
@@ -589,6 +579,8 @@ class StudentService extends CrudService {
     return await this.ctx.service.util.toExcel(studentList, model, fn);
   }
 
+ 
+
   async toGetFn(termid, batchid) {
     const trainPlan = await this.ctx.model.Trainplan.findOne({ 'termnum._id': ObjectId(termid) });
     if (!trainPlan) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到年度计划信息');