lrf402788946 4 年之前
父節點
當前提交
5097ba020a
共有 2 個文件被更改,包括 27 次插入55 次删除
  1. 13 1
      app/service/experience.js
  2. 14 54
      app/service/util.js

+ 13 - 1
app/service/experience.js

@@ -14,8 +14,20 @@ class ExperienceService extends CrudService {
   }
 
   async query(data, { skip, limit }) {
-    const res = await this.model.find().populate({ path: 'studentid', select: 'name' }).skip(parseInt(skip))
+    let res = await this.model.find().populate({ path: 'studentid', select: 'name job' }).skip(parseInt(skip))
       .limit(parseInt(limit));
+    if (res.length > 0) {
+      res = JSON.parse(JSON.stringify(res));
+      res = res.map(i => {
+        const { studentid } = i;
+        if (studentid && _.isObject(studentid)) {
+          const { name, job } = studentid;
+          i.stuname = name;
+          i.stujob = job;
+        }
+        return i;
+      });
+    }
     return res;
   }
 

+ 14 - 54
app/service/util.js

@@ -70,58 +70,13 @@ class UtilService extends CrudService {
     }
     return res;
   }
-
   async findmodel({ modelname }) {
-    // TODO找到这个班级
-    // const tclass = { name: '1', term: '', batch: '' };
-    // 首先用名字找能不能对上,名字能对上直接把班级信息复制过来
-    // 名字对不上就根据当前班级的期找下本期的所有班,然后找到和他同批次的班级,查下它是第几位,按照这个位置去把模板的同位置班级信息复制过来
-
-    // 获取所有年度的期计划
-
-    // 处理学生入学年份超过4位的情况
-    // const list = await this.ctx.model.Student.find({ $where: 'this.entry_year.length>4' });
-    // const m = /^\w{4}/;
-    // for (const stu of list) {
-    //   const { entry_year } = stu;
-    //   const r = entry_year.match(m);
-    //   if (r) {
-    //     stu.entry_year = r[0];
-    //     stu.save();
-    //   }
-    // }
-    // 处理学生毕业年份超过4位的情况
-    // const list = await this.ctx.model.Student.find({ $where: 'this.finish_year.length>4' });
-    // const m = /^\w{4}/;
-    // for (const stu of list) {
-    //   const { finish_year } = stu;
-    //   const r = finish_year.match(m);
-    //   if (r) {
-    //     stu.finish_year = r[0];
-    //     stu.save();
-    //   }
-    // }
-    // 处理学生专业字段(major)带'专业'二字
-    // const stuList = await this.ctx.model.Student.find({ major: /专业/ });
-    // const m = /(\S+)(专业$)/;
-    // for (const stu of stuList) {
-    //   const { name, major } = stu;
-    //   const r = major.match(m);
-    //   let nm;
-    //   if (r) nm = r[1];
-    //   stu.major = nm;
-    //   stu.save();
-    // }
-    // 处理教师分数错误的初始化
-    // // 所有教师的分数都复制到beforescore上,xsscore需要重新计算
-    // const list = await this.ctx.model.Teacher.find();
-    // console.log(list.length);
-    // for (const tea of list) {
-    //   if (tea.xsscore) {
-    //     tea.beforescore = tea.xsscore;
-    //     await tea.save();
-    //   }
-    // }
+    const _model = _.capitalize(modelname);
+    const data = this.ctx.model[_model].prototype.schema.obj;
+    return data;
+  }
+  async utilMethod(data, body) {
+    console.log(data, body);
   }
 
   async toExcel(dataList, meta, fn = '导出结果') {
@@ -157,7 +112,14 @@ class UtilService extends CrudService {
    * @param {String} fn 文件名
    */
   async toDocx(data, fn = '培训心得') {
-    const { Document, Packer, Paragraph, TextRun, HeadingLevel, AlignmentType } = docx;
+    const {
+      Document,
+      Packer,
+      Paragraph,
+      TextRun,
+      HeadingLevel,
+      AlignmentType,
+    } = docx;
     const doc = new Document();
     const children = [];
     // 整理数据
@@ -212,11 +174,9 @@ class UtilService extends CrudService {
       fs.mkdirSync(path);
     }
     const num = new Date().getTime();
-    console.log(`filepath=>${path}${fn}-${num}.docx`);
     Packer.toBuffer(doc).then(buffer => {
       fs.writeFileSync(`${path}${fn}-${num}.docx`, buffer);
     });
-    console.log(`return path=>/files${rooturl}${fn}-${num}.docx`);
     return `/files${rooturl}${fn}-${num}.docx`;
   }
 }