|
@@ -17,6 +17,7 @@ class SchoolService extends CrudService {
|
|
|
this.umodel = this.ctx.model.User;
|
|
|
this.tmodel = this.ctx.model.Trainplan;
|
|
|
this.jmodel = this.ctx.model.Job;
|
|
|
+ this.schmodel = this.ctx.model.Schtime;
|
|
|
}
|
|
|
|
|
|
async stuimport(data) {
|
|
@@ -29,12 +30,8 @@ class SchoolService extends CrudService {
|
|
|
if (!plan) {
|
|
|
throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '计划信息不存在');
|
|
|
}
|
|
|
- const schs = await plan.school;
|
|
|
- const sch_ = _.find(schs, { code: schid });
|
|
|
- let num_ = '0';
|
|
|
- if (sch_) {
|
|
|
- num_ = sch_.num;
|
|
|
- }
|
|
|
+
|
|
|
+ const num_ = this.getschnum(plan, type, schid, termid);
|
|
|
const planid = plan.id;
|
|
|
const planyearid = plan.planyearid;
|
|
|
|
|
@@ -58,11 +55,11 @@ class SchoolService extends CrudService {
|
|
|
}
|
|
|
const nowtime = moment().locale('zh-cn').format('YYYY-MM-DD HH:mm:ss');
|
|
|
if (studatas.length > Number(num_)) {
|
|
|
- const jobdata = { code: schid, name: schname, planid: plan.id, termid, term: trem_.term, filepath, studs: JSON.stringify(studatas), plannum: num_, schnum: studatas.length, isstore: '0', createtime: nowtime };
|
|
|
+ const jobdata = { code: schid, name: schname, planid: plan.id, termid, term: trem_.term, 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 < Number(num_)) {
|
|
|
- const jobdata = { code: schid, name: schname, planid: plan.id, termid, term: trem_.term, filepath, studs: JSON.stringify(studatas), plannum: num_, schnum: studatas.length, isstore: '0', createtime: nowtime };
|
|
|
+ const jobdata = { code: schid, name: schname, planid: plan.id, termid, term: trem_.term, 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, '学校上传人数少于预期人数');
|
|
|
}
|
|
@@ -78,6 +75,39 @@ class SchoolService extends CrudService {
|
|
|
return datacheck;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ async getschnum(plan, type, schid, termid) {
|
|
|
+ const schtime = await this.schmodel.findOne({ schid, planid: plan.id });
|
|
|
+ let { arrange } = schtime;
|
|
|
+ const { termnum } = plan;
|
|
|
+ arrange = _.groupBy(arrange, 'term');
|
|
|
+ const keys = Object.keys(arrange);
|
|
|
+ let arr = keys.map(key => {
|
|
|
+ const rt = termnum.find(f => f.term === key);
|
|
|
+ let ar = arrange[key];
|
|
|
+ ar = ar.map(a => {
|
|
|
+ const rb = rt.batchnum.find(f => f.batch === a.batch);
|
|
|
+ if (rb) {
|
|
|
+ const bh = _.head(rb.class);
|
|
|
+ const { type } = bh;
|
|
|
+ a.type = type;
|
|
|
+ return a;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ let garr = _.groupBy(ar, 'type');
|
|
|
+ const gks = Object.keys(garr);
|
|
|
+ garr = gks.map(gk => {
|
|
|
+ const { term, termid } = _.head(garr[gk]);
|
|
|
+ const number = garr[gk].reduce((p, n) => p + n.number * 1, 0);
|
|
|
+ return { term, termid, number, type: gk };
|
|
|
+ });
|
|
|
+ return garr;
|
|
|
+ });
|
|
|
+ arr = arr.flat();
|
|
|
+ const obj_ = _.find(arr, { termid, type });
|
|
|
+ return obj_.number;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
async getImportXLSXData(filepath, termid, schid, planid, planyearid, type) {
|
|
|
console.log(filepath);
|