|
@@ -6,7 +6,7 @@ const _ = require('lodash');
|
|
|
const { ObjectId } = require('mongoose').Types;
|
|
|
const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
-
|
|
|
+const moment = require('moment');
|
|
|
class StudentService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'student');
|
|
@@ -394,7 +394,6 @@ class StudentService extends CrudService {
|
|
|
// 将学生排号
|
|
|
async arrangeNumber(classid) {
|
|
|
const studList = await this.model.find({ classid });
|
|
|
- console.log(`in function:arrangeNumber classid=>${classid}`);
|
|
|
let number = 1;
|
|
|
// 查每个学生的编号,如果没有,就给赋上值;有,就给number赋上值,然后继续下一位
|
|
|
for (const stu of studList) {
|
|
@@ -407,7 +406,95 @@ class StudentService extends CrudService {
|
|
|
}
|
|
|
number = number * 1 + 1;
|
|
|
}
|
|
|
- console.log(`last number => ${number}`);
|
|
|
+ // console.log(`last number => ${number}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 导出学生 目前:拓展训练保险用
|
|
|
+ async exportStudent(data) {
|
|
|
+ let { data: studentList } = await this.query(data);
|
|
|
+ studentList = JSON.parse(JSON.stringify(studentList));
|
|
|
+ let ids = studentList.map(i => i.classid);
|
|
|
+ ids = _.uniq(ids);
|
|
|
+ const classList = [];
|
|
|
+ for (const id of ids) {
|
|
|
+ const cla = await this.ctx.service.class.fetch({ id });
|
|
|
+ if (!cla) continue;
|
|
|
+ cla.date = moment(cla.date).add(1, 'd').format('YYYY-MM-DD');
|
|
|
+ classList.push(cla);
|
|
|
+ }
|
|
|
+ studentList = studentList.map(i => {
|
|
|
+ const c = classList.find(f => ObjectId(i.classid).equals(f._id));
|
|
|
+ if (c) i.date = c.date;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ const meta = this.metaBx();
|
|
|
+ return await this.ctx.service.util.toExcel(studentList, meta, '学生名单');
|
|
|
+ }
|
|
|
+
|
|
|
+ metaBx() {
|
|
|
+ const header = [
|
|
|
+ {
|
|
|
+ header: '姓名',
|
|
|
+ key: 'name',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '拓训日期',
|
|
|
+ key: 'date',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '性别',
|
|
|
+ key: 'gender',
|
|
|
+ width: 10,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '民族',
|
|
|
+ key: 'nation',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '身份证号',
|
|
|
+ key: 'id_number',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '期',
|
|
|
+ key: 'termname',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '批次',
|
|
|
+ key: 'batchname',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '班级',
|
|
|
+ key: 'classname',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '学校',
|
|
|
+ key: 'school_name',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '院系',
|
|
|
+ key: 'faculty',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '专业',
|
|
|
+ key: 'major',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ header: '手机号',
|
|
|
+ key: 'phone',
|
|
|
+ width: 20,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ return header;
|
|
|
}
|
|
|
}
|
|
|
|