lrf402788946 4 lat temu
rodzic
commit
c9ccf53903

+ 4 - 1
app/controller/teacher.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 老师管理
 class TeacherController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.teacher;
@@ -31,6 +30,10 @@ class TeacherController extends Controller {
     this.ctx.ok({ msg: 'created', data: res });
   }
 
+  async export() {
+    const res = await this.service.toExport(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = CrudController(TeacherController, meta);

+ 26 - 25
app/model/teacher.js

@@ -38,46 +38,47 @@ const academicInfo = new Schema({
 
 // 教师表
 const TeacherSchema = {
-  name: { type: String, required: true, maxLength: 200 }, // 教师姓名
-  phone: { type: String, required: true, maxLength: 200 }, // 手机号
-  idnumber: { type: String, required: false, maxLength: 200 }, // 身份证号
-  gender: { type: String, required: false, maxLength: 200 }, // 教师性别
+  name: { type: String, required: true, maxLength: 200, zh: '姓名' }, // 教师姓名
+  phone: { type: String, required: true, maxLength: 200, zh: '手机号' }, // 手机号
+  gender: { type: String, required: false, maxLength: 200, zh: '性别' }, // 教师性别
+  idnumber: { type: String, required: false, maxLength: 200, zh: '身份证号' }, // 身份证号
+  secret: { type: String, required: false, maxLength: 200, zh: '密码' }, // 教师性别
   // zynumber: { type: String, required: false, maxLength: 200 }, // 职业资格证号
   zynumberfile: { type: [ zynumberfileInfo ], select: true }, // 职业资格证图片
   schid: { type: String, required: false, maxLength: 200 }, // 学校id
   schname: { type: String, required: false, maxLength: 200 }, // 学校名称
-  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  email: { type: String, required: false, maxLength: 200, zh: '邮箱' }, // 邮箱
   openid: { type: String, required: false, maxLength: 200 }, // 微信openid
-  age: { type: String, required: false, maxLength: 200 }, // 年龄
-  birthday: { type: String, required: false, maxLength: 200 }, // 出生年月
-  entrydate: { type: String, required: false, maxLength: 200 }, // 入职时间
-  politics: { type: String, required: false, maxLength: 200 }, // 政治面貌
-  department: { type: String, required: false, maxLength: 200 }, // 所在部门
-  job: { type: String, required: false, maxLength: 200 }, // 职务
-  protitle: { type: String, required: false, maxLength: 200 }, // 职称
-  education: { type: String, required: false, maxLength: 200 }, // 最后学历
-  degree: { type: String, required: false, maxLength: 200 }, // 最后学位
-  major: { type: String, required: false, maxLength: 200 }, // 教师所学专业
-  schlesson: { type: String, required: false, maxLength: 200 }, // 教师在校所教课程
+  age: { type: String, required: false, maxLength: 200, zh: '年龄' }, // 年龄
+  birthday: { type: String, required: false, maxLength: 200, zh: '出生年月' }, // 出生年月
+  entrydate: { type: String, required: false, maxLength: 200, zh: '入职时间' }, // 入职时间
+  politics: { type: String, required: false, maxLength: 200, zh: '政治面貌' }, // 政治面貌
+  department: { type: String, required: false, maxLength: 200, zh: '所在部门' }, // 所在部门
+  job: { type: String, required: false, maxLength: 200, zh: '职务' }, // 职务
+  protitle: { type: String, required: false, maxLength: 200, zh: '职称' }, // 职称
+  education: { type: String, required: false, maxLength: 200, zh: '最后学历' }, // 最后学历
+  degree: { type: String, required: false, maxLength: 200, zh: '最后学位' }, // 最后学位
+  major: { type: String, required: false, maxLength: 200, zh: '教师所学专业' }, // 教师所学专业
+  schlesson: { type: String, required: false, maxLength: 200, zh: '教师在校所教课程' }, // 教师在校所教课程
   experience: { type: [ experienceInfo ], select: true }, // 教育培训经历(从大学开始)
-  courses: { type: String, required: false, maxLength: 200 }, // 主讲课程
+  courses: { type: String, required: false, maxLength: 200, zh: '主讲课程' }, // 主讲课程
   academic: { type: [ academicInfo ], select: true }, // 主要学术成果及获奖情况
-  jobyear: { type: String, required: false, maxLength: 200 }, // 从事就业创业教学工作年限
-  jobaddress: { type: String, required: false, maxLength: 500 }, // 工作地点
+  jobyear: { type: String, required: false, maxLength: 200, zh: '从事就业创业教学工作年限' }, // 从事就业创业教学工作年限
+  jobaddress: { type: String, required: false, maxLength: 500, zh: '工作地点' }, // 工作地点
   subid: { type: String, required: false, maxLength: 200 }, // 科目id
   islyteacher: { type: String, required: false, maxLength: 200 }, // 是否可讲礼仪课,0-否,1-是
-  zlscore: { type: String, required: false, maxLength: 200 }, // 资料评分
-  msscore: { type: String, required: false, maxLength: 200 }, // 面试评分
-  xsscore: { type: String, required: false, maxLength: 200 }, // 学生评分
+  zlscore: { type: String, required: false, maxLength: 200, zh: '资料评分' }, // 资料评分
+  msscore: { type: String, required: false, maxLength: 200, zh: '面试评分' }, // 面试评分
+  xsscore: { type: String, required: false, maxLength: 200, zh: '学生评分' }, // 学生评分
   beforescore: { type: String, required: false, maxLength: 200 }, // 以前评分的平均分
   file: { type: [ FileInfo ], select: false }, // 资料,教案PPT视频等
   status: { type: String, required: false, maxLength: 200, default: '0' },
   withpersonal: { type: String, required: false }, // 与人合作
   career: { type: String, required: false }, // 职业探索
   training: { type: String, required: false }, // 面试训练
-  nation: { type: String, required: false, maxLength: 200 }, // 民族
-  qq: { type: String, required: false, maxLength: 200 }, // qq
-  mobile: { type: String, required: false, maxLength: 200 }, // 固定电话
+  nation: { type: String, required: false, maxLength: 200, zh: '民族' }, // 民族
+  qq: { type: String, required: false, maxLength: 200, zh: 'qq' }, // qq
+  mobile: { type: String, required: false, maxLength: 200, zh: '固定电话' }, // 固定电话
   course: { type: String, required: false, maxLength: 200 }, // 课程模块
   // 状态:0-注册,1-确认身份,2-资料评分,3-面试评分,4-确认入库
 };

+ 1 - 0
app/router.js

@@ -35,6 +35,7 @@ module.exports = app => {
   );
 
   // 教师表设置路由
+  router.post('teacher', '/api/train/teacher/export', controller.teacher.export);
   router.get('teacher', '/api/train/teacher/show/:id', controller.teacher.show);
   router.resources('teacher', '/api/train/teacher', controller.teacher); // index、create、show、destroy
   router.post(

+ 2 - 2
app/service/bedroom.js

@@ -19,7 +19,7 @@ class BedroomService extends CrudService {
     this.nmodel = this.ctx.model.Notice;
   }
 
-  async query({ code, ...data }, { skip = 0, limit = 0 } = {}) {
+  async query({ code, ...data } = {}, { skip = 0, limit = 0 } = {}) {
     const query = { ...data };
     if (code) {
       query.code = { $regex: code };
@@ -27,7 +27,7 @@ class BedroomService extends CrudService {
     const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
     return res;
   }
-  async count({ code, ...data }) {
+  async count({ code, ...data } = {}) {
     const query = { ...data };
     if (code) {
       query.code = { $regex: code };

+ 0 - 5
app/service/questionnaire.js

@@ -137,7 +137,6 @@ class QuestionnaireService extends CrudService {
         throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到问卷信息');
       }
       this.ctx.service.util.updateProcess(missionid, '25');
-      console.log('问卷导出=>25%');
       questionnaire = JSON.parse(JSON.stringify(questionnaire));
       // 修改条件,termid变成数组了,需要一个一个查出来
       const { planid, termid, batchid, classid } = range;
@@ -156,7 +155,6 @@ class QuestionnaireService extends CrudService {
         if (qaList) questAnswerList.push(...qaList);
       }
       this.ctx.service.util.updateProcess(missionid, '50');
-      console.log('问卷导出=>50%');
       // fn,根据范围+问卷 得出文件名
       const fn = await this.toSetFileName(questionnaire.name, range);
 
@@ -180,7 +178,6 @@ class QuestionnaireService extends CrudService {
         );
       }
       this.ctx.service.util.updateProcess(missionid, '75');
-      console.log('学生导出=>75%');
       if (excelData) {
         const { head, data } = excelData;
         const res = await this.ctx.service.util.toExcel(data, head, fn);
@@ -193,8 +190,6 @@ class QuestionnaireService extends CrudService {
         this.ctx.service.util.updateProcess(missionid, '100', '2', {
           uri: res,
         });
-        this.ctx.service.util.updateProcess(missionid, '100');
-        console.log('问卷导出=>100%');
       }
     } catch (error) {
       this.ctx.service.util.updateProcess(missionid, undefined, '3');

+ 1 - 1
app/service/school.js

@@ -60,7 +60,7 @@ class SchoolService extends CrudService {
     return res;
   }
 
-  async count({ name, ...data }) {
+  async count({ name, ...data } = {}) {
     const query = { ...data };
     if (name) {
       query.name = { $regex: name };

+ 2 - 2
app/service/student.js

@@ -70,7 +70,7 @@ class StudentService extends CrudService {
   }
 
   // 查询
-  async query({ name, ...info }, { skip = 0, limit = 0 } = {}) {
+  async query({ name, ...info } = {}, { skip = 0, limit = 0 } = {}) {
     const query = { ...info };
     if (name) {
       query.name = { $regex: name };
@@ -122,7 +122,7 @@ class StudentService extends CrudService {
     return data;
   }
 
-  async count({ name, ...info }) {
+  async count({ name, ...info } = {}) {
     const query = { ...info };
     if (name) {
       query.name = { $regex: name };

+ 70 - 2
app/service/teacher.js

@@ -3,6 +3,7 @@
 
 const assert = require('assert');
 const _ = require('lodash');
+const moment = require('moment');
 const XLSX = require('xlsx');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
@@ -14,9 +15,11 @@ class TeacherService extends CrudService {
     super(ctx, 'teacher');
     this.model = this.ctx.model.Teacher;
     this.umodel = this.ctx.model.User;
+    const { baseUrl } = _.get(this.ctx.app.config, 'mission');
+    if (baseUrl) this.missionBase = baseUrl;
   }
 
-  async query({ name, ...info }, { skip = 0, limit = 0 } = {}) {
+  async query({ name, ...info } = {}, { skip = 0, limit = 0 } = {}) {
     const query = { ...info };
     if (name) {
       query.name = { $regex: name };
@@ -36,7 +39,7 @@ class TeacherService extends CrudService {
     }
     return res;
   }
-  async count({ name, ...info }) {
+  async count({ name, ...info } = {}) {
     const query = { ...info };
     if (name) {
       query.name = { $regex: name };
@@ -203,6 +206,71 @@ class TeacherService extends CrudService {
     }
     return { errorcode, errormsg };
   }
+
+  // 建立任务
+  async toExport(body) {
+    const fn = `教师导出 ${moment().format('YYYY-MM-DD HH:SS:mm')}`;
+    const data = {
+      title: fn,
+      params: {
+        project: 'center',
+        service: 'teacher',
+        method: 'export',
+        body,
+      },
+    };
+    if (this.missionBase) {
+      const url = `${this.missionBase}/api/mission`;
+      const res = await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        data,
+        dataType: 'json',
+      });
+      if (res.status !== 200 || res.data.errcode !== 0) {
+        throw new BusinessError(ErrorCode.SERVICE_FAULT, '创建任务失败');
+      }
+    } else {
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '未找到任务项目设置');
+    }
+  }
+
+  // 导出
+  async export({ missionid, model }) {
+    assert(missionid, '缺少任务信息,无法执行任务');
+    try {
+      const head = model.map(i => {
+        const { zh, model } = i;
+        const headObj = { header: zh };
+        if (model) headObj.key = model;
+        headObj.width = 20;
+        return headObj;
+      });
+      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}导出失败`);
+      }
+      this.ctx.service.util.updateProcess(missionid, '100', '2', {
+        uri: res,
+      });
+    } catch (error) {
+      console.log('in function:error');
+      this.ctx.service.util.updateProcess(missionid, undefined, '3');
+    }
+  }
 }
 
 module.exports = TeacherService;

+ 1 - 1
app/service/user.js

@@ -16,7 +16,7 @@ class UserService extends CrudService {
     this.schModel = this.ctx.model.School;
     this.hModel = this.ctx.model.Headteacher;
   }
-  async query({ name, ...info }, options) {
+  async query({ name, ...info } = {}, options) {
     const newoptions = await this.ctx.service.util.getQueryOptions(options);
     const query = { ...info };
     if (name) {

+ 7 - 1
app/service/util.js

@@ -77,7 +77,13 @@ class UtilService extends CrudService {
   async findmodel({ modelname }) {
     const _model = _.capitalize(modelname);
     const data = this.ctx.model[_model].prototype.schema.obj;
-    return data;
+    const keys = Object.keys(data);
+    const res = {};
+    for (const k of keys) {
+      const obj = data[k];
+      if (_.get(obj, 'zh')) res[k] = obj;
+    }
+    return res;
   }
   async utilMethod(query, body) {
     // const ch = await this.ctx.amqp.conn.createChannel();