浏览代码

验收修改

lrf 1 年之前
父节点
当前提交
815a46b53f
共有 5 个文件被更改,包括 284 次插入261 次删除
  1. 3 3
      app/model/student.js
  2. 28 2
      app/service/headteacher.js
  3. 205 226
      app/service/student.js
  4. 46 27
      app/service/teacher.js
  5. 2 3
      app/service/util.js

+ 3 - 3
app/model/student.js

@@ -30,13 +30,13 @@ const StudentSchema = {
   family_is_hard: { type: String, required: false, maxLength: 200, zh: '家庭是否困难' }, // 家庭是否困难,0-否,1-是
   family_is_hard: { type: String, required: false, maxLength: 200, zh: '家庭是否困难' }, // 家庭是否困难,0-否,1-是
   have_grant: { 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: '职务' }, // 职务
   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
+  schid: { type: String, required: false, maxLength: 200, zh: '学校' }, // 学校id
+  planyearid: { type: String, required: false, maxLength: 200 }, // 年度计划id
   planid: { type: String, required: false, maxLength: 200 }, // 计划id
   planid: { type: String, required: false, maxLength: 200 }, // 计划id
   termid: { type: String, required: false, maxLength: 200, zh: '期' }, // 期id
   termid: { type: String, required: false, maxLength: 200, zh: '期' }, // 期id
   batchid: { 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
   classid: { type: String, required: false, maxLength: 200, zh: '班级' }, // 班级id
-  bedroomid: { type: String, required: false, maxLength: 200, zh: '寝室id' }, // 寝室id
+  bedroomid: { type: String, required: false, maxLength: 200, zh: '寝室' }, // 寝室id
   openid: { type: String, required: false, maxLength: 200, zh: '微信openid' }, // 微信openid
   openid: { type: String, required: false, maxLength: 200, zh: '微信openid' }, // 微信openid
   diy: { type: { Object }, required: false, zh: '自定义' }, // 自定义
   diy: { type: { Object }, required: false, zh: '自定义' }, // 自定义
   type: { type: String, required: false, maxLength: 200, default: '0' }, // 类型:0-正常,1-特殊
   type: { type: String, required: false, maxLength: 200, default: '0' }, // 类型:0-正常,1-特殊

+ 28 - 2
app/service/headteacher.js

@@ -1,7 +1,7 @@
 'use strict';
 'use strict';
 
 
-
 const assert = require('assert');
 const assert = require('assert');
+const { trimData } = require('naf-core').Util;
 const _ = require('lodash');
 const _ = require('lodash');
 const { ObjectId } = require('mongoose').Types;
 const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
@@ -12,6 +12,33 @@ class HeadteacherService extends CrudService {
     super(ctx, 'headteacher');
     super(ctx, 'headteacher');
     this.model = this.ctx.model.Headteacher;
     this.model = this.ctx.model.Headteacher;
     this.umodel = this.ctx.model.User;
     this.umodel = this.ctx.model.User;
+    this.yjy = this.ctx.model.Yjyconnect;
+  }
+  async query(filter, { skip, limit, sort, desc, projection } = {}) {
+    // 处理排序
+    if (sort && _.isString(sort)) {
+      sort = { [sort]: desc ? -1 : 1 };
+    } else if (sort && _.isArray(sort)) {
+      sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
+    }
+
+    const rs = await this.model.find(trimData(filter), projection, { skip, limit, sort }).lean();
+    const ids = rs.map(i => ObjectId(i._id).toString());
+    const users = await this.umodel.find({ uid: ids }).lean();
+    const uids = users.map(i => ObjectId(i._id).toString());
+    const yjyUsers = await this.yjy.find({ suid: uids }).lean();
+    for (const i of rs) {
+      const { _id: did } = i;
+      const user = users.find(f => ObjectId(did).equals(f.uid));
+      if (!user) {
+        i.is_bind = false;
+        continue;
+      }
+      const yjyUser = yjyUsers.find(f => ObjectId(user._id).equals(f.suid));
+      if (yjyUser) i.is_bind = true;
+      else i.is_bind = false;
+    }
+    return rs;
   }
   }
 
 
   async create(data) {
   async create(data) {
@@ -52,7 +79,6 @@ class HeadteacherService extends CrudService {
     await this.umodel.deleteOne({ uid: id, type: '1' });
     await this.umodel.deleteOne({ uid: id, type: '1' });
     return 'deleted';
     return 'deleted';
   }
   }
-
 }
 }
 
 
 module.exports = HeadteacherService;
 module.exports = HeadteacherService;

+ 205 - 226
app/service/student.js

@@ -79,18 +79,14 @@ class StudentService extends CrudService {
     }
     }
     let data = await this.model
     let data = await this.model
       .find(query)
       .find(query)
-      .populate([
-        {
-          path: 'classid',
-          model: 'Class',
-          select: 'name',
-        },
-      ])
       .skip(parseInt(skip))
       .skip(parseInt(skip))
       .limit(parseInt(limit));
       .limit(parseInt(limit));
     const planids = _.uniq(data.map(i => ObjectId(i.planid)));
     const planids = _.uniq(data.map(i => ObjectId(i.planid)));
     const plan = await this.ctx.model.Trainplan.find({ _id: planids });
     const plan = await this.ctx.model.Trainplan.find({ _id: planids });
     data = JSON.parse(JSON.stringify(data));
     data = JSON.parse(JSON.stringify(data));
+    for (const i of data) {
+      if (i.classid) { i.classid = await this.clamodel.findById(i.classid).lean(); }
+    }
     data = data.map(i => {
     data = data.map(i => {
       if (i.classid && _.isObject(i.classid)) {
       if (i.classid && _.isObject(i.classid)) {
         i.classname = _.get(i.classid, 'name');
         i.classname = _.get(i.classid, 'name');
@@ -98,13 +94,18 @@ class StudentService extends CrudService {
       }
       }
       const p = plan.find(f => ObjectId(f._id).equals(i.planid));
       const p = plan.find(f => ObjectId(f._id).equals(i.planid));
       if (p) {
       if (p) {
-        const { termnum } = p;
+        const { termnum, title } = p;
+        i.plantitle = title;
         const tr = termnum.id(i.termid);
         const tr = termnum.id(i.termid);
         if (tr) {
         if (tr) {
           i.termname = _.get(tr, 'term');
           i.termname = _.get(tr, 'term');
           const br = tr.batchnum.id(i.batchid);
           const br = tr.batchnum.id(i.batchid);
           if (br) {
           if (br) {
             i.batchname = _.get(br, 'batch');
             i.batchname = _.get(br, 'batch');
+            const startDate = _.get(br, 'startdate');
+            if (startDate) {
+              i.insurance = moment(startDate).add(1, 'd').format('YYYY-MM-DD');
+            }
           }
           }
         }
         }
       }
       }
@@ -485,55 +486,11 @@ class StudentService extends CrudService {
   }
   }
   // 建立导出学生名单的任务
   // 建立导出学生名单的任务
   async toExport(body) {
   async toExport(body) {
-    const { planid, termid, batchid, classid } = body;
-    const trainPlan = await this.ctx.model.Trainplan.findById(planid);
-    let fn = '学生名单';
-    if (termid && termid.length > 0) {
-      if (classid) {
-        const cla = await this.ctx.model.Class.findById(classid);
-        if (cla) {
-          const { name } = cla;
-          if (name) {
-            fn = `${name.includes('班') ? name : `${name}班`}${fn}`;
-          }
-        }
-      }
-      if (termid.length === 1) {
-        const tid = _.head(termid);
-        const { termnum } = trainPlan;
-        const t = termnum.id(tid);
-        if (t) {
-          const { term, batchnum } = t;
-          if (batchid) {
-            const b = batchnum.id(batchid);
-            if (b) {
-              const { batch } = b;
-              if (b) fn = `第${batch}批${fn}`;
-            }
-          }
-          if (term) fn = `第${term}期${fn}`;
-        }
-      } else if (termid.length > 1) {
-        const { termnum } = trainPlan;
-        let str = '第';
-        for (const tid of termid) {
-          const t = termnum.id(tid);
-          if (t) {
-            const { term } = t;
-            str = `${str}${term} `;
-          }
-        }
-        fn = `${str}期${fn}`;
-      }
-    } else {
-      const { title } = trainPlan;
-      fn = `${title}${fn}`;
-    }
+    const fn = await this.toGetFn(body);
     const data = {
     const data = {
       title: fn,
       title: fn,
       params: {
       params: {
         project: 'center',
         project: 'center',
-        // router: '/api/train/mission/student/export',
         service: 'student',
         service: 'student',
         method: 'exportStudent',
         method: 'exportStudent',
         body,
         body,
@@ -558,182 +515,216 @@ class StudentService extends CrudService {
   }
   }
   // 导出学生
   // 导出学生
   async exportStudent(body) {
   async exportStudent(body) {
-    let { missionid, model, ...data } = body;
+    const limit = 50;
+    const { missionid, model, ...data } = body;
     assert(missionid, '缺少任务信息,无法执行任务');
     assert(missionid, '缺少任务信息,无法执行任务');
     try {
     try {
-      // 整理model
-      model = model.map(i => {
-        const { zh, model } = i;
-        if (zh && model) {
-          const obj = {};
-          obj.header = zh;
-          if (model === 'termid') obj.key = 'termname';
-          else if (model === 'batchid') obj.key = 'batchname';
-          else if (model === 'classid') obj.key = 'classname';
-          else obj.key = model;
-          obj.width = 20;
+      // 整理表头+生成excel
+      const head = model.map(i => i.zh);
+      let fn = await this.toGetFn(data, missionid);
+      let dp = null;
+      const { downloadPath, fn: nfn } = await this.ctx.service.util.toAsyncExcel([ head ], fn, dp);
+      dp = downloadPath;
+      fn = nfn;
+      // 整理数据(分页循环)+写入excel
+      let skip = 0;
+      const { planid, termid = [], batchid = [], classid = [], isComming } = data;
+      const query = {};
+      if (classid.length > 0) query.classid = classid;
+      else if (batchid.length > 0) query.batchid = batchid;
+      else if (termid.length > 0) query.termid = termid;
+      else if (planid) query.planid = planid;
+      if (isComming === '0') query.isComming = '0';
+      else if (isComming !== '0')query.isComming = { $ne: '0' };
+      const total = await this.exportToGetTotal(query);
+      const times = Math.ceil(total / limit);
+      for (let i = 0; i < times; i++) {
+        let data = await this.query(query, { skip, limit });
+        if (data.length <= 0) break;
+        skip = skip + limit;
+        data = await this.exportDealData(data);
+        const dataList = data.map(i => {
+          const obj = [];
+          for (const m of model) {
+            obj.push(i[m.model]);
+          }
           return obj;
           return obj;
-        }
-      });
-      model = _.compact(model);
-      // 请求数据
-      // 修改条件,termid变成数组了,需要一个一个查出来
-      const { planid, termid, batchid, classid, isComming } = data;
-      const queryObject = {};
-      if (planid) queryObject.planid = planid;
-      if (batchid) queryObject.batchid = batchid;
-      if (classid) queryObject.classid = classid;
-      if (isComming) {
-        // 因为isComming有3种,0=>没来;1=>来了;2=>来了又退了.而已参培的类型应该是不为0,而不是单纯的1,只管来没来,不管走没走,毕竟吃饭了,得交钱
-        if (isComming !== '0') queryObject.isComming = { $ne: '0' };
-        else queryObject.isComming = isComming;
-      }
-      let studentList = [];
-      console.log(queryObject);
-      if (termid && termid.length > 0) {
-        for (const t of termid) {
-          queryObject.termid = t;
-          const stuList = await this.query(queryObject);
-          studentList.push(...stuList);
-        }
-      } else {
-        studentList = await this.query(queryObject);
+        });
+        await this.ctx.service.util.toAsyncExcel(dataList, fn, dp);
+        const per = Math.ceil(((i + 1) / times) * 100);
+        this.ctx.service.util.updateProcess(missionid, per);
       }
       }
-      console.log(studentList.length);
-      // 获取学生,4分之1
-      this.ctx.service.util.updateProcess(missionid, '25');
-      console.log('学生导出=>25%');
-      studentList = JSON.parse(JSON.stringify(studentList));
-      let ids = studentList.map(i => i.classid);
-      ids = _.uniq(ids);
-      ids = _.compact(ids);
-      ids = ids.map(i => ObjectId(i));
-      const classList = await this.ctx.model.Class.find({
-        _id: { $in: ids },
+      this.ctx.service.util.updateProcess(missionid, '100', '2', {
+        uri: dp,
       });
       });
-      for (const stu of studentList) {
-        // 转换是否参培
-        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 = '否';
-          else if (isComming === '1') stu.isComming = '是';
-          else if (isComming === '2') stu.isComming = '退出';
-        }
-      }
-      // 整理完数据,4分之2
-      this.ctx.service.util.updateProcess(missionid, '50');
-      console.log('学生导出=>50%');
-      let fn = '学生名单';
-      // 因为是递进下来, batchid和classid并列,并非递进
-      // 获取fn
-      if (classid) {
-        // 文件名称: 期, 班
-        // 班级名上面有直接拽来
-        const cla = classList.find(f => ObjectId(classid).equals(f._id));
-        if (cla) {
-          const { name, termid } = cla;
-          if (name) fn = `${name.includes('班') ? name : `${name}班`}${fn}`;
-          if (termid) {
-            const obj = await this.toGetFn(termid);
-            if (obj) {
-              const { term } = obj;
-              fn = `第${term}期${fn}`;
-            }
-          }
-        }
-      } else if (batchid) {
-        // 文件名称,期,批
-        const tid = _.head(termid);
-        const obj = await this.toGetFn(tid, batchid);
-        if (obj) {
-          const { term, batch } = obj;
-          if (batch) fn = `第${batch}批${fn}`;
-          if (term) fn = `第${term}期${fn}`;
-        }
-      } else if (termid) {
-        // 文件名称: 期
-        if (termid.length === 1) {
-          const obj = await this.toGetFn(_.head(termid));
-          if (obj) {
-            const { term } = obj;
-            if (term) fn = `第${term}期${fn}`;
-          }
+    } catch (error) {
+      console.log(error);
+      this.ctx.service.util.updateProcess(missionid, undefined, '3');
+    }
+  }
+  // 处理数据
+  async exportDealData(data) {
+    const changeList = [
+      {
+        model: 'is_fine',
+        options: [
+          { value: '0', to: '否' },
+          { value: '1', to: '是' },
+          { value: '2', to: '无资格' },
+        ],
+      },
+      {
+        model: 'isComming',
+        options: [
+          { value: '0', to: '未报到' },
+          { value: '1', to: '已报到' },
+        ],
+      },
+      {
+        model: 'family_is_hard',
+        options: [
+          { value: '0', to: '否' },
+          { value: '1', to: '是' },
+        ],
+      },
+      {
+        model: 'have_grant',
+        options: [
+          { value: '0', to: '否' },
+          { value: '1', to: '是' },
+        ],
+      },
+      {
+        model: 'type',
+        options: [
+          { value: '0', to: '正常' },
+          { value: '1', to: '特殊' },
+        ],
+      },
+      {
+        model: 'status',
+        options: [
+          { value: '0', to: '待确定' },
+          { value: '1', to: '确定' },
+          { value: '2', to: '失败' },
+        ],
+      },
+      {
+        model: 'cert',
+        options: [
+          { value: '0', to: '未打印' },
+          { value: '1', to: '已打印' },
+        ],
+      },
+      {
+        model: 'schid',
+        type: 'get',
+        format: i => i.school_name,
+      },
+      {
+        model: 'termid',
+        type: 'get',
+        format: i => i.termname,
+      },
+      {
+        model: 'batchid',
+        type: 'get',
+        format: i => i.batchname,
+      },
+      {
+        model: 'classid',
+        type: 'get',
+        format: i => i.classname,
+      },
+      {
+        model: 'bedroomid',
+        type: 'get',
+        format: i => i.bedroom,
+      },
+    ];
+    // 需要请求的数据, 学校数据
+    for (const i of data) {
+      for (const m of changeList) {
+        const { model, options, type, format } = m;
+        if (type === 'get') {
+          // 请求转换
+          i[model] = format(i);
         } else {
         } 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}期`;
-                }
-              }
+          // 字典转换
+          const v = _.get(i, model);
+          if (!v) {
+            // 没有默认第一个
+            const option = _.head(options);
+            i[model] = option.to;
+          } else {
+            const option = options.find(f => f.value === v);
+            if (option) i[model] = option.to;
+            else {
+              // 没有默认第一个
+              const option = _.head(options);
+              i[model] = option.to;
             }
             }
           }
           }
-          fn = `${tStr}${fn}`;
-        }
-      } else if (planid) {
-        // 文件名称:该计划标题
-        const trainPlan = await this.ctx.model.Trainplan.findById(planid);
-        if (trainPlan) {
-          const { title } = trainPlan;
-          if (title) fn = `${title}${fn}`;
         }
         }
+
       }
       }
-      // 获取文件名,60%
-      this.ctx.service.util.updateProcess(missionid, '60');
-      console.log('学生导出=>60%');
-      const res = await this.ctx.service.util.toExcel(studentList, model, fn);
-      if (!res) {
-        console.error(
-          `${moment().format('YYYY-MM-DD HH:SS:mm')} ${fn} 导出失败`
-        );
-        throw new BusinessError(ErrorCode.SERVICE_FAULT, `${fn}导出失败`);
-      }
-      this.ctx.service.util.updateProcess(missionid, '100', '2', {
-        uri: res,
-      });
-      console.log('学生导出=>100%');
-    } catch (error) {
-      this.ctx.service.util.updateProcess(missionid, undefined, '3');
     }
     }
+    return data;
   }
   }
+  // 导出,获取总数,分页处理
+  async exportToGetTotal(query) {
+    const total = await this.model.count(query);
+    // const { planid, termid = [], batchid = [], classid = [], isComming } = data;
+    // if (classid.length > 0) total = await this.model.count({ classid });
+    // else if (batchid.length > 0) total = await this.model.count({ batchid });
+    // else if (termid.length > 0) total = await this.model.count({ termid });
+    // else if (planid) total = await this.model.count({ planid });
 
 
-  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, '未找到年度计划信息');
-    }
-    const { termnum } = trainPlan;
-    if (!termnum) {
-      throw new BusinessError(
-        ErrorCode.DATA_NOT_EXIST,
-        '未找到年度计划的期信息'
-      );
-    }
-    const obj = {};
-    if (termid) {
-      const term = termnum.id(termid);
-      if (term) obj.term = term.term;
-      if (batchid) {
-        const { batchnum } = term;
-        const batch = batchnum.id(batchid);
-        if (batch) obj.batch = batch.batch;
+    return total;
+  }
+  // 导出,获取文件名
+  async toGetFn(data, missionid) {
+    const { planid, termid = [], batchid = [], classid = [] } = data;
+    let fn = '学生名单';
+    const fnList = [];
+    // 如果有班级id,直接用班级id查,然后拼接导出文件名;第x期-第x批-第x班;第x期-第x批-第x班...学生名单
+    if (classid.length > 0) {
+      for (const cid of classid) {
+        const cla = await this.ctx.service.class.fetch({ id: cid });
+        if (cla) fnList.push(`第${cla.term}期-第${cla.batch}批-${cla.name}班`);
+      }
+    } else {
+      // 如果没有年度计划id,那就是全库学生导出
+      if (!planid) return fn;
+      const trainPlan = await this.ctx.model.Trainplan.findById(planid);
+      if (!trainPlan) {
+        if (missionid) this.ctx.service.util.updateProcess(missionid, '0', '3');
+        throw new BusinessError(ErrorCode.SERVICE_FAULT, '学生导出,查询计划失败');
+      }
+      if (termid.length > 0) {
+        for (const tid of termid) {
+          const { termnum = [] } = trainPlan;
+          const term = termnum.id(tid);
+          if (!term) continue;
+          if (batchid.length > 0) {
+            // 先看批次: 第x期-第x批;第x期-第x批....学生名单
+            const { batchnum = [] } = term;
+            for (const bid of batchid) {
+              const batch = batchnum.id(bid);
+              if (batch) fnList.push(`第${term.term}期-第${batch.batch}批`);
+            }
+          } else {
+            // 只有期:第x期;第x期...学生名单
+            fnList.push(`第${term.term}期`);
+          }
+        }
+      } else {
+        // 只有计划id: xxx计划学生名单
+        fnList.push(trainPlan.title);
       }
       }
     }
     }
-    return obj;
+    fn = `${fnList.join(';')}${fn}`;
+    return fn;
   }
   }
 
 
   // 确认学生打印证书
   // 确认学生打印证书
@@ -754,18 +745,6 @@ class StudentService extends CrudService {
     ]);
     ]);
     return res;
     return res;
   }
   }
-
-  // excel导出表头设置
-  metaBx(type) {
-    const header = [
-      {
-        header: '姓名',
-        key: 'name',
-        width: 20,
-      },
-    ];
-    return header;
-  }
 }
 }
 
 
 module.exports = StudentService;
 module.exports = StudentService;

+ 46 - 27
app/service/teacher.js

@@ -16,6 +16,8 @@ class TeacherService extends CrudService {
     this.umodel = this.ctx.model.User;
     this.umodel = this.ctx.model.User;
     const { baseUrl } = _.get(this.ctx.app.config, 'mission');
     const { baseUrl } = _.get(this.ctx.app.config, 'mission');
     if (baseUrl) this.missionBase = baseUrl;
     if (baseUrl) this.missionBase = baseUrl;
+    this.yjy = this.ctx.model.Yjyconnect;
+    this.export_limit = 50;
   }
   }
 
 
   async query({ name, ...info } = {}, { skip = 0, limit = 0 } = {}) {
   async query({ name, ...info } = {}, { skip = 0, limit = 0 } = {}) {
@@ -23,17 +25,23 @@ class TeacherService extends CrudService {
     if (name) {
     if (name) {
       query.name = { $regex: name };
       query.name = { $regex: name };
     }
     }
-    let res = await this.model.find(query).skip(Number(skip)).limit(Number(limit));
-    res = JSON.parse(JSON.stringify(res));
-    for (const tea of res) {
-      const r = await this.umodel.findOne({ uid: tea._id }, '+passwd');
-      if (r) {
-        // const { passwd } = r;
-        // tea.secret = passwd.secret;
-        tea.openid = _.get(r, 'openid');
+    const rs = await this.model.find(query, null, { skip, limit }).lean();
+    const ids = rs.map(i => ObjectId(i._id).toString());
+    const users = await this.umodel.find({ uid: ids }).lean();
+    const uids = users.map(i => ObjectId(i._id).toString());
+    const yjyUsers = await this.yjy.find({ suid: uids }).lean();
+    for (const i of rs) {
+      const { _id: did } = i;
+      const user = users.find(f => ObjectId(did).equals(f.uid));
+      if (!user) {
+        i.is_bind = false;
+        continue;
       }
       }
+      const yjyUser = yjyUsers.find(f => ObjectId(user._id).equals(f.suid));
+      if (yjyUser) i.is_bind = true;
+      else i.is_bind = false;
     }
     }
-    return res;
+    return rs;
   }
   }
   async count({ name, ...info } = {}) {
   async count({ name, ...info } = {}) {
     const query = { ...info };
     const query = { ...info };
@@ -243,27 +251,38 @@ class TeacherService extends CrudService {
     assert(missionid, '缺少任务信息,无法执行任务');
     assert(missionid, '缺少任务信息,无法执行任务');
     try {
     try {
       const head = model.map(i => {
       const head = model.map(i => {
-        const { zh, model } = i;
-        const headObj = { header: zh };
-        if (model) headObj.key = model;
-        headObj.width = 20;
-        return headObj;
+        // const { zh, model } = i;
+        // const headObj = { header: zh };
+        // if (model) headObj.key = model;
+        // headObj.width = 20;
+        // return headObj;
+        return i.zh;
       });
       });
-      const fn = '教师导出';
-      const data = await this.query();
-      console.log(data.length);
-      if (data.length <= 0) {
-        throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教师信息');
-      }
-      this.ctx.service.util.updateProcess(missionid, '50');
-      const res = await this.ctx.service.util.toExcel(data, head, fn);
-      console.log(res);
-      if (!res) {
-        console.error(`${moment().format('YYYY-MM-DD HH:mm:ss')} ${fn} 导出失败`);
-        throw new BusinessError(ErrorCode.SERVICE_FAULT, `${fn}导出失败`);
+      let fn = '教师导出';
+      let skip = 0;
+      const total = await this.count({});
+      const times = Math.ceil(total / this.export_limit);
+      let dp = null;
+      const { downloadPath, fn: nfn } = await this.ctx.service.util.toAsyncExcel([ head ], fn, dp);
+      dp = downloadPath;
+      fn = nfn;
+      for (let i = 0; i < times; i++) {
+        const data = await this.query({}, { skip, limit: this.export_limit });
+        if (data.length <= 0) break;
+        const dataList = data.map(i => {
+          const obj = [];
+          for (const m of model) {
+            obj.push(i[m.model]);
+          }
+          return obj;
+        });
+        await this.ctx.service.util.toAsyncExcel(dataList, fn, dp);
+        skip = skip + this.export_limit;
+        const per = Math.ceil(((i + 1) / times) * 100);
+        this.ctx.service.util.updateProcess(missionid, per);
       }
       }
       this.ctx.service.util.updateProcess(missionid, '100', '2', {
       this.ctx.service.util.updateProcess(missionid, '100', '2', {
-        uri: res,
+        uri: dp,
       });
       });
     } catch (error) {
     } catch (error) {
       console.log('in function:error');
       console.log('in function:error');

+ 2 - 3
app/service/util.js

@@ -350,7 +350,7 @@ XQIDAQAB
     if (!path) {
     if (!path) {
       throw new BusinessError(ErrorCode.BUSINESS, '服务端没有设置存储路径');
       throw new BusinessError(ErrorCode.BUSINESS, '服务端没有设置存储路径');
     }
     }
-    if (process.env.NODE_ENV === 'development') path = 'E:\\exportFile\\excel\\';
+    if (process.env.NODE_ENV === 'development') path = 'D:\\temp\\upload\\excel\\';
     if (!fs.existsSync(path)) {
     if (!fs.existsSync(path)) {
       // 如果不存在文件夹,就创建
       // 如果不存在文件夹,就创建
       fs.mkdirSync(path);
       fs.mkdirSync(path);
@@ -362,8 +362,7 @@ XQIDAQAB
       fn = `${fn}-${nowDate}.xlsx`;
       fn = `${fn}-${nowDate}.xlsx`;
       sheet = workbook.addWorksheet('sheet');
       sheet = workbook.addWorksheet('sheet');
     } else {
     } else {
-      let domain = 'http://127.0.0.1';
-      if (process.env.NODE_ENV === 'development') domain = `${domain}:8000`;
+      const domain = 'http://127.0.0.1';
       const file = await this.ctx.curl(`${domain}${downloadPath}`);
       const file = await this.ctx.curl(`${domain}${downloadPath}`);
       if (!(file && file.data)) {
       if (!(file && file.data)) {
         throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找导出的excel');
         throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找导出的excel');