|
@@ -6,6 +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');
|
|
|
const XLSX = require('xlsx');
|
|
|
|
|
|
class SchoolService extends CrudService {
|
|
@@ -15,6 +16,7 @@ class SchoolService extends CrudService {
|
|
|
this.smodel = this.ctx.model.Student;
|
|
|
this.umodel = this.ctx.model.User;
|
|
|
this.tmodel = this.ctx.model.Trainplan;
|
|
|
+ this.jmodel = this.ctx.model.Job;
|
|
|
}
|
|
|
|
|
|
async stuimport(data) {
|
|
@@ -40,14 +42,26 @@ class SchoolService extends CrudService {
|
|
|
console.log(_filepath);
|
|
|
const studatas = await this.getImportXLSXData(_filepath, termid, schid, planid, planyearid);
|
|
|
console.log(studatas);
|
|
|
- if (studatas.length > Number(num_)) {
|
|
|
- throw new BusinessError(ErrorCode.SERVICE_FAULT, '学校上传人数超过预期人数');
|
|
|
- }
|
|
|
// 将得到的数据校验
|
|
|
const datacheck = await this.datacheck(studatas);
|
|
|
if (datacheck.errorcode === '1') {
|
|
|
return datacheck;
|
|
|
}
|
|
|
+ const school_ = await this.smodel.findOne({ code: schid });
|
|
|
+ const trem_ = await plan.termnum.id(termid);
|
|
|
+ if (!trem_) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '期信息不存在');
|
|
|
+ }
|
|
|
+ const nowtime = moment().locale('zh-cn').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ if (studatas.length > Number(num_)) {
|
|
|
+ const jobdata = { code: schid, name: school_.name, planid: plan.id, termid, term: trem_.term, filepath, studs: JSON.stringify(studatas), plannum: num_, schnum: studatas.length, isstore: '0', createtime: nowtime };
|
|
|
+ await this.jmodel.create(jobdata);
|
|
|
+ throw new BusinessError(ErrorCode.SERVICE_FAULT, '学校上传人数超过预期人数');
|
|
|
+ } else if (studatas.length < Number(num_)) {
|
|
|
+ const jobdata = { code: schid, name: school_.name, planid: plan.id, termid, term: trem_.term, filepath, studs: JSON.stringify(studatas), plannum: num_, schnum: studatas.length, isstore: '0', createtime: nowtime };
|
|
|
+ await this.jmodel.create(jobdata);
|
|
|
+ throw new BusinessError(ErrorCode.SERVICE_FAULT, '学校上传人数少于预期人数');
|
|
|
+ }
|
|
|
// 将数据存入数据库中
|
|
|
for (const stu of studatas) {
|
|
|
const res = await this.smodel.create(stu);
|