|
@@ -8,6 +8,7 @@ const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const moment = require('moment');
|
|
|
const XLSX = require('xlsx');
|
|
|
+const Excel = require('exceljs');
|
|
|
|
|
|
class SchoolService extends CrudService {
|
|
|
constructor(ctx) {
|
|
@@ -48,336 +49,319 @@ class SchoolService extends CrudService {
|
|
|
if (!plan) {
|
|
|
throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '计划信息不存在');
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const num_ = await this.getschnum(plan, type, schid, termid, batchid);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const schstu = await this.smodel.count({ schid, batchid });
|
|
|
- if (schstu && schstu > 0) throw new BusinessError(ErrorCode.BUSINESS, '该批次已经上传过学生,无需重复上传,若人员有变化,请联系中心负责人');
|
|
|
+ const term = plan.termnum.id(termid);
|
|
|
const planid = plan.id;
|
|
|
const planyearid = plan.planyearid;
|
|
|
-
|
|
|
- const _filepath = 'http://127.0.0.1' + filepath;
|
|
|
- const studatas = await this.getImportXLSXData(
|
|
|
- _filepath,
|
|
|
- termid,
|
|
|
- schid,
|
|
|
- planid,
|
|
|
- planyearid,
|
|
|
- type,
|
|
|
- batchid
|
|
|
- );
|
|
|
-
|
|
|
- const datacheck = await this.datacheck(studatas);
|
|
|
- if (datacheck.errorcode === '1') {
|
|
|
- return datacheck;
|
|
|
- }
|
|
|
- const school_ = await this.model.findOne({ code: schid });
|
|
|
- let schname = '';
|
|
|
- if (school_) {
|
|
|
- schname = school_.name;
|
|
|
+
|
|
|
+ let dbStuList = await this.ctx.model.Student.find({ termid, batchid, schid });
|
|
|
+ if (dbStuList.length > 0) {
|
|
|
+
|
|
|
+ const is_change = dbStuList.find(f => f.classid || f.bedroomid);
|
|
|
+ if (is_change) throw new BusinessError(ErrorCode.BUSINESS, '上报过的学生已经安排班级或寝室!若需要替换学生,让同性别的学生直接来和班主任说,修改信息即可.若还是有疑问,请和中心负责人联系(最好联系下)');
|
|
|
}
|
|
|
- const trem_ = await plan.termnum.id(termid);
|
|
|
- if (!trem_) {
|
|
|
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '期信息不存在');
|
|
|
+
|
|
|
+ let school_name;
|
|
|
+ const sch = await this.ctx.model.School.findOne({ code: schid });
|
|
|
+ if (sch) school_name = sch.name;
|
|
|
+ const fullUrl = 'http://127.0.0.1' + filepath;
|
|
|
+ let studentList = await this.getDataFromExcel(fullUrl);
|
|
|
+ const checkRes = await this.checkData(studentList);
|
|
|
+ const { errorcode } = checkRes;
|
|
|
+ if (errorcode === '1') {
|
|
|
+ return checkRes;
|
|
|
}
|
|
|
- const nowtime = moment().locale('zh-cn').format('YYYY-MM-DD HH:mm:ss');
|
|
|
- if (studatas.length > num_) {
|
|
|
- const jobdata = {
|
|
|
- code: schid,
|
|
|
- name: schname,
|
|
|
- planid: plan.id,
|
|
|
- termid,
|
|
|
- term: trem_.term,
|
|
|
- batchid,
|
|
|
- filepath,
|
|
|
- studs: JSON.stringify(studatas),
|
|
|
- plannum: num_,
|
|
|
- schnum: studatas.length,
|
|
|
- isstore: '0',
|
|
|
- createtime: nowtime,
|
|
|
- type,
|
|
|
- reason: '学校上传人数超过预期人数,请联系中心管理员',
|
|
|
- };
|
|
|
- await this.jmodel.create(jobdata);
|
|
|
- throw new BusinessError(
|
|
|
- ErrorCode.SERVICE_FAULT,
|
|
|
- '学校上传人数超过预期人数,请联系中心管理员'
|
|
|
- );
|
|
|
- } else if (studatas.length < num_) {
|
|
|
- const jobdata = {
|
|
|
- code: schid,
|
|
|
- name: schname,
|
|
|
- planid: plan.id,
|
|
|
- termid,
|
|
|
- term: trem_.term,
|
|
|
- batchid,
|
|
|
- filepath,
|
|
|
- studs: JSON.stringify(studatas),
|
|
|
- plannum: num_,
|
|
|
- schnum: studatas.length,
|
|
|
- isstore: '0',
|
|
|
- createtime: nowtime,
|
|
|
- type,
|
|
|
- reason: '学校上传人数少于预期人数,请联系中心管理员',
|
|
|
- };
|
|
|
- await this.jmodel.create(jobdata);
|
|
|
- throw new BusinessError(
|
|
|
- ErrorCode.SERVICE_FAULT,
|
|
|
- '学校上传人数少于预期人数,请联系中心管理员'
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- for (const stu of studatas) {
|
|
|
- const res = await this.smodel.create(stu);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ studentList = this.lastSetData(studentList, {
|
|
|
+ planyearid,
|
|
|
+ planid,
|
|
|
+ batchid,
|
|
|
+ termid,
|
|
|
+ type,
|
|
|
+ schid,
|
|
|
+ school_name,
|
|
|
+ });
|
|
|
+ const num = await this.getschnum(plan, schid, batchid);
|
|
|
+
|
|
|
+ if (studentList.length !== num) {
|
|
|
+ const res = await this.jmodel.findOne({ code: schid, batchid });
|
|
|
+ const reason = `学校上传人数${studentList.length > num ? '多于' : '少于'}预期人数,请联系中心管理员`;
|
|
|
+ if (res) {
|
|
|
+ res.reason = reason;
|
|
|
+ res.filepath = filepath;
|
|
|
+ await res.save();
|
|
|
+ } else {
|
|
|
+ const job = {
|
|
|
+ code: schid,
|
|
|
+ name: school_name,
|
|
|
+ planid,
|
|
|
+ termid,
|
|
|
+ term: term.term,
|
|
|
+ batchid,
|
|
|
+ filepath,
|
|
|
+ studs: JSON.stringify(studentList),
|
|
|
+ plannum: num,
|
|
|
+ schnum: studentList.length,
|
|
|
+ isstore: '0',
|
|
|
+ createtime: moment().format('YYYY-MM-DD HH:SS:mm'),
|
|
|
+ type,
|
|
|
+ };
|
|
|
+ job.reason = reason;
|
|
|
+ await this.jmodel.save(job);
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new BusinessError(ErrorCode.SERVICE_FAULT, reason);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ dbStuList = JSON.parse(JSON.stringify(dbStuList));
|
|
|
+ dbStuList = dbStuList.map(i => {
|
|
|
+ delete i.meta;
|
|
|
+ i.studentid = _.clone(i._id);
|
|
|
+ delete i.id;
|
|
|
+ delete i._id;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ await this.ctx.model.Dstudent.insertMany(dbStuList);
|
|
|
+ await this.smodel.deleteMany({ termid, batchid, schid });
|
|
|
+ await this.smodel.insertMany(studentList);
|
|
|
}
|
|
|
- return datacheck;
|
|
|
}
|
|
|
|
|
|
|
|
|
- async getschnum(plan, type, schid, termid, batchid) {
|
|
|
+ async getschnum(plan, schid, batchid) {
|
|
|
const schtime = await this.schmodel.findOne({ schid, planid: plan.id });
|
|
|
const { arrange } = schtime;
|
|
|
const r = arrange.find(f => f.batchid === batchid);
|
|
|
if (!r) { throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '没有找到该学校的计划'); }
|
|
|
const { number } = r;
|
|
|
return parseInt(number);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return obj_.number;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- async getImportXLSXData(
|
|
|
- filepath,
|
|
|
- termid,
|
|
|
- schid,
|
|
|
- planid,
|
|
|
- planyearid,
|
|
|
- type,
|
|
|
- batchid
|
|
|
- ) {
|
|
|
- const file = await this.ctx.curl(filepath);
|
|
|
- const workbook = XLSX.read(file.data);
|
|
|
-
|
|
|
- let exceldata = [];
|
|
|
- const sheetNames = workbook.SheetNames;
|
|
|
- const sheet = workbook.Sheets[sheetNames[0]];
|
|
|
-
|
|
|
-
|
|
|
- const theadRule = [];
|
|
|
- const range = XLSX.utils.decode_range(sheet['!ref']);
|
|
|
- const col_start = range.s.c;
|
|
|
- const col_end = range.e.c;
|
|
|
- for (let i = col_start; i <= col_end; i++) {
|
|
|
- const addr = XLSX.utils.encode_col(i) + XLSX.utils.encode_row(0);
|
|
|
- theadRule.push(sheet[addr].v);
|
|
|
+
|
|
|
+ async getDataFromExcel(url) {
|
|
|
+ const file = await this.ctx.curl(`http://127.0.0.1${url}`);
|
|
|
+ if (!(file && file.data)) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到上传的名单');
|
|
|
}
|
|
|
-
|
|
|
- const params = XLSX.utils.sheet_to_json(sheet);
|
|
|
-
|
|
|
- if (!params) return [];
|
|
|
- let i = 0;
|
|
|
- const length = params.length;
|
|
|
- const _datas = [];
|
|
|
- let data = {};
|
|
|
- for (i; i < length; i++) {
|
|
|
- data = params[i];
|
|
|
- const diy_ = [];
|
|
|
- if (theadRule.length > 18) {
|
|
|
- for (let j = 18; j < theadRule.length; j++) {
|
|
|
- const newdata = {
|
|
|
- itemname: theadRule[j],
|
|
|
- itemvalue: data[theadRule[j]],
|
|
|
- };
|
|
|
- diy_.push(newdata);
|
|
|
- }
|
|
|
- }
|
|
|
- _datas.push({
|
|
|
- name: _.trim(data[theadRule[1]]),
|
|
|
- gender: _.trim(data[theadRule[2]]),
|
|
|
- nation: _.trim(data[theadRule[3]]),
|
|
|
- id_number: _.trim(data[theadRule[4]]),
|
|
|
- school_name: _.trim(data[theadRule[5]]),
|
|
|
- faculty: _.trim(data[theadRule[6]]),
|
|
|
- major: _.trim(data[theadRule[7]]),
|
|
|
- entry_year: _.trim(data[theadRule[8]]),
|
|
|
- finish_year: _.trim(data[theadRule[9]]),
|
|
|
- school_job: _.trim(data[theadRule[10]]),
|
|
|
- phone: _.trim(data[theadRule[11]]),
|
|
|
- qq: _.trim(data[theadRule[12]]),
|
|
|
- family_place: _.trim(data[theadRule[13]]),
|
|
|
- family_is_hard: _.trim(data[theadRule[14]]),
|
|
|
- have_grant: _.trim(data[theadRule[15]]),
|
|
|
- edua_level: _.trim(data[theadRule[16]]),
|
|
|
- edua_system: _.trim(data[theadRule[17]]),
|
|
|
- diy: diy_,
|
|
|
- termid,
|
|
|
- batchid,
|
|
|
- schid,
|
|
|
- planid,
|
|
|
- planyearid,
|
|
|
- type,
|
|
|
- });
|
|
|
+ const workbook = new Excel.Workbook();
|
|
|
+ await workbook.xlsx.load(file);
|
|
|
+ const worksheet = workbook.getWorksheet(1);
|
|
|
+ if (!worksheet) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未发现excel中有工作表');
|
|
|
}
|
|
|
- exceldata = [ ...exceldata, ..._datas ];
|
|
|
+ const cols = this.getStucolumn();
|
|
|
+ const headRow = worksheet.getRow(1);
|
|
|
+ headRow.eachCell((cell, coli) => {
|
|
|
+ const r = cols.find(f => f.key === cell.value);
|
|
|
+ if (r) {
|
|
|
+ const ri = cols.findIndex(f => f.key === cell.value);
|
|
|
+ r.colIndex = coli;
|
|
|
+ cols[ri] = r;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const excelIsRigth = cols.find(f => f.colIndex);
|
|
|
+ if (!excelIsRigth) throw new BusinessError(ErrorCode.DATA_INVALID, 'Excel表格格式不正确,请使用系统提供的模板!');
|
|
|
+
|
|
|
+ worksheet.spliceRows(0, 1);
|
|
|
+ const stuList = [];
|
|
|
+
|
|
|
+ worksheet.eachRow(row => {
|
|
|
+ const stu = {};
|
|
|
+ for (let i = 0; i < cols.length; i++) {
|
|
|
+ const col = cols[i];
|
|
|
+ if (!col) break;
|
|
|
+ let val = _.trim(row.getCell(col.colIndex));
|
|
|
+ if (col.column === 'id_number') val = val.toUpperCase();
|
|
|
+ stu[col.column] = val;
|
|
|
+ }
|
|
|
+ stuList.push(stu);
|
|
|
+ });
|
|
|
+ return stuList;
|
|
|
|
|
|
- return exceldata;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- async datacheck(studatas) {
|
|
|
+
|
|
|
+ async checkData(stuList) {
|
|
|
+ const cols = this.getStucolumn();
|
|
|
let errorcode = '0';
|
|
|
const errormsg = [];
|
|
|
- for (const data of studatas) {
|
|
|
-
|
|
|
- if (!data.name) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '姓名不允许为空;';
|
|
|
- }
|
|
|
- if (!data.gender) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '性别不允许为空;';
|
|
|
- }
|
|
|
-
|
|
|
- if (data.gender.length !== 1) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg(data.msg || '') + '性别内容超出1个字.可能含有空格;';
|
|
|
- }
|
|
|
- if (!data.nation) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '民族不允许为空;';
|
|
|
- }
|
|
|
- if (!data.id_number) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '身份证号不允许为空;';
|
|
|
- } else {
|
|
|
- const res = await this.smodel.findOne({ id_number: data.id_number });
|
|
|
- if (res) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '学生已经存在请检查;';
|
|
|
- } else {
|
|
|
- const { pass, msg } = this.idCodeValid(data.id_number);
|
|
|
+ for (const stu of stuList) {
|
|
|
+ const { name } = stu;
|
|
|
+ let error = false;
|
|
|
+ let msg = '';
|
|
|
+
|
|
|
+ for (const col of cols) {
|
|
|
+ const { key, column } = col;
|
|
|
+ if (!column) throw new BusinessError(ErrorCode.SERVICE_FAULT, '未找到导出的字段名');
|
|
|
+ const val = _.get(stu, column);
|
|
|
+
|
|
|
+ if (!val || val === '') {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}"${key}"不能为空;`;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (column === 'gender') {
|
|
|
+ if (!(val.includes('男') || val.includes('女'))) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}性别错误;`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (column === 'id_number') {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const { pass, msg: idmsg } = this.ctx.service.school.idCodeValid(val);
|
|
|
if (!pass) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + `${msg},`;
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}${idmsg};`;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const have_same = stuList.filter(f => f.id_number === val && f.name !== name);
|
|
|
+ if (have_same.length > 0) {
|
|
|
+ error = true;
|
|
|
+ const h = _.head(have_same);
|
|
|
+ const num = have_same.length;
|
|
|
+ if (num === 1) {
|
|
|
+ msg = `${msg}身份证号与本次名单的"${h.name}"重复;`;
|
|
|
+ } else msg = `${msg}身份证号与本次名单中"${h.name}"等${num}人重复;`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- if (!data.school_name) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '学校名称不允许为空;';
|
|
|
- }
|
|
|
- if (!data.phone) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '手机号不允许为空;';
|
|
|
- }
|
|
|
- if (!data.faculty) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '院系不允许为空;';
|
|
|
- }
|
|
|
- if (!data.major) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '专业不允许为空;';
|
|
|
- } else {
|
|
|
-
|
|
|
- if (data.major.includes('专业')) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '专业列不能含有"专业"二字;';
|
|
|
+
|
|
|
+ if (column === 'phone') {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!/^\d{11}$/i.test(val)) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}手机号位数不正确;`;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const have_same = stuList.filter(f => f.phone === val && f.name !== name);
|
|
|
+ if (have_same.length > 0) {
|
|
|
+ error = true;
|
|
|
+ const h = _.head(have_same);
|
|
|
+ const num = have_same.length;
|
|
|
+ if (num === 1) {
|
|
|
+ msg = `${msg}手机号与本次名单的"${h.name}"重复;`;
|
|
|
+ } else msg = `${msg}手机号与本次名单中"${h.name}"等${num}人重复;`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (!data.entry_year) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '入学年份不允许为空;';
|
|
|
- } else {
|
|
|
- const m = /^\w{4}$/;
|
|
|
- if (!data.entry_year.match(m)) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '入学年份格式不正确,只填写4位数字即可;';
|
|
|
+
|
|
|
+ if (column === 'major') {
|
|
|
+ if (val.includes('专业')) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}专业列不能含有"专业"二字;`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (!data.finish_year) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '毕业年份不允许为空;';
|
|
|
- } else {
|
|
|
- const m = /^\w{4}$/;
|
|
|
- if (!data.finish_year.match(m)) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '毕业年份格式不正确,只填写4位数字即可;';
|
|
|
+
|
|
|
+ if (column === 'entry_year') {
|
|
|
+ const m = /^\w{4}$/;
|
|
|
+ if (!val.match(m)) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}入学年份格式不正确,只填写4位数字;`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (column === 'finish_year') {
|
|
|
+ const m = /^\w{4}$/;
|
|
|
+ if (!val.match(m)) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}毕业年份格式不正确,只填写4位数字;`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (column === 'family_is_hard') {
|
|
|
+ if (!(val.includes('是') || val.includes('否'))) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}家庭是否困难填写"是"或"否";`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (column === 'have_grant') {
|
|
|
+ if (!(val.includes('是') || val.includes('否'))) {
|
|
|
+ error = true;
|
|
|
+ msg = `${msg}是否获得过助学金填写"是"或"否";`;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
- if (!data.school_job) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '职务不允许为空;';
|
|
|
- }
|
|
|
- if (!data.qq) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + 'QQ号不允许为空;';
|
|
|
- }
|
|
|
- if (!data.family_place) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '家庭所在地不允许为空;';
|
|
|
- }
|
|
|
- if (!data.family_is_hard) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '家庭是否困难不允许为空;';
|
|
|
- }
|
|
|
- if (!data.have_grant) {
|
|
|
- errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '是否获得过助学金不允许为空;';
|
|
|
- }
|
|
|
- if (!/^\d{11}$/i.test(data.phone)) {
|
|
|
+ if (error) {
|
|
|
errorcode = '1';
|
|
|
- data.msg = (data.msg || '') + '手机号不正确;';
|
|
|
- }
|
|
|
- if (errorcode === '1') {
|
|
|
- errormsg.push(data);
|
|
|
+ stu.msg = msg;
|
|
|
+ errormsg.push(stu);
|
|
|
}
|
|
|
}
|
|
|
return { errorcode, errormsg };
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ lastSetData(stuList, data) {
|
|
|
+ const cols = this.getStucolumn();
|
|
|
+ const needChange = cols.filter(f => f.change);
|
|
|
+ stuList = stuList.map(i => {
|
|
|
+ const d = { ...i, ...data };
|
|
|
+ for (const col of needChange) {
|
|
|
+ const { column, change } = col;
|
|
|
+ if (!column && change && _.isArray(change)) continue;
|
|
|
+ const val = _.get(d, column);
|
|
|
+ if (!val) continue;
|
|
|
+ const r = change.find(f => f.key === val);
|
|
|
+ if (!r) continue;
|
|
|
+ const { value } = r;
|
|
|
+ d[column] = value;
|
|
|
+ }
|
|
|
+ return d;
|
|
|
+ });
|
|
|
+ return stuList;
|
|
|
+ }
|
|
|
+
|
|
|
+ getStucolumn() {
|
|
|
+ const arr = [
|
|
|
+ { key: '姓名', column: 'name' },
|
|
|
+ { key: '性别', column: 'gender' },
|
|
|
+ { key: '民族', column: 'nation' },
|
|
|
+ { key: '身份证号', column: 'id_number' },
|
|
|
+ { key: '学校名称', column: 'school_name' },
|
|
|
+ { key: '院(系)', column: 'faculty' },
|
|
|
+ { key: '专业', column: 'major' },
|
|
|
+ { key: '入学年份', column: 'entry_year' },
|
|
|
+ { key: '毕业年份', column: 'finish_year' },
|
|
|
+ { key: '在校曾担任何种职务', column: 'school_job' },
|
|
|
+ { key: '手机号', column: 'phone' },
|
|
|
+ { key: 'QQ号', column: 'qq' },
|
|
|
+ { key: '家庭所在地', column: 'family_place' },
|
|
|
+ {
|
|
|
+ key: '家庭是否困难',
|
|
|
+ column: 'family_is_hard',
|
|
|
+ change: [
|
|
|
+ { key: '否', value: '0' },
|
|
|
+ { key: '是', value: '1' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '是否获得过助学金',
|
|
|
+ column: 'have_grant',
|
|
|
+ change: [
|
|
|
+ { key: '否', value: '0' },
|
|
|
+ { key: '是', value: '1' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
async exportSchool({ trainplanId }) {
|
|
|
|
|
@@ -555,23 +539,6 @@ class SchoolService extends CrudService {
|
|
|
}
|
|
|
return row;
|
|
|
}
|
|
|
-
|
|
|
- outOfDate(plan, termid, batchid) {
|
|
|
- const term = plan.termnum.find(f => ObjectId(termid).equals(f._id));
|
|
|
- const { batchnum } = term;
|
|
|
- if (!batchnum) throw new BusinessError(ErrorCode.BUSINESS, '没有找到该期下的批次');
|
|
|
- const batch = batchnum.find(f => ObjectId(batchid).equals(f._id));
|
|
|
- if (!batch) throw new BusinessError(ErrorCode.BUSINESS, '没有找到该批次');
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const start = _.get(batch, 'startdate');
|
|
|
- if (!start) throw new BusinessError(ErrorCode.BUSINESS, '没有找到开始日期');
|
|
|
- const limit = moment(start).subtract(3, 'days').format('YYYY-MM-DD');
|
|
|
- const now = moment().format('YYYY-MM-DD');
|
|
|
- const res = moment(now).isBefore(limit);
|
|
|
- return res;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
module.exports = SchoolService;
|