|
@@ -50,8 +50,7 @@ class SchoolService extends CrudService {
|
|
|
const planid = plan.id;
|
|
|
const planyearid = plan.planyearid;
|
|
|
// 取得excle中数据
|
|
|
- const _filepath = 'http://127.0.0.1' + filepath; // this.ctx.app.config.baseUrl
|
|
|
- console.warn(_filepath);
|
|
|
+ const _filepath = 'http://127.0.0.1:2001' + filepath; // this.ctx.app.config.baseUrl http://jytz.jilinjobs.cn
|
|
|
const studatas = await this.getImportXLSXData(
|
|
|
_filepath,
|
|
|
termid,
|
|
@@ -136,56 +135,51 @@ class SchoolService extends CrudService {
|
|
|
// 取得学校预计人数
|
|
|
async getschnum(plan, type, schid, termid, batchid) {
|
|
|
const schtime = await this.schmodel.findOne({ schid, planid: plan.id });
|
|
|
- let { arrange } = schtime;
|
|
|
- const { termnum } = plan;
|
|
|
- arrange = _.groupBy(arrange, 'termid');
|
|
|
- const keys = Object.keys(arrange);
|
|
|
- let arr = keys.map(key => {
|
|
|
- const rt = termnum.find(f => ObjectId(key).equals(f._id));
|
|
|
- let ar = arrange[key];
|
|
|
- ar = ar.map(a => {
|
|
|
- const rb = rt.batchnum.find(f => ObjectId(a.batchid).equals(f._id));
|
|
|
- console.log(rb);
|
|
|
- if (rb) {
|
|
|
- const bh = _.head(rb.class);
|
|
|
- const { type } = bh;
|
|
|
- a.type = type;
|
|
|
- return a;
|
|
|
- }
|
|
|
- });
|
|
|
- console.log(ar);
|
|
|
- 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 });
|
|
|
+ const { arrange } = schtime;
|
|
|
+ console.log(arrange);
|
|
|
+ const r = arrange.find(f => f.batchid === batchid);
|
|
|
+ if (!r) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '没有找到该学校的计划');
|
|
|
+ const { number } = r;
|
|
|
+ return parseInt(number);
|
|
|
+ // const { termnum } = plan;
|
|
|
+ // arrange = _.groupBy(arrange, 'termid');
|
|
|
+ // const keys = Object.keys(arrange);
|
|
|
+ // let arr = keys.map(key => {
|
|
|
+ // const rt = termnum.find(f => ObjectId(key).equals(f._id));
|
|
|
+ // let ar = arrange[key];
|
|
|
+ // ar = ar.map(a => {
|
|
|
+ // const rb = rt.batchnum.find(f => ObjectId(a.batchid).equals(f._id));
|
|
|
+ // 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;
|
|
|
}
|
|
|
|
|
|
// 获取导入的XLSX文件中的数据
|
|
|
async getImportXLSXData(filepath, termid, schid, planid, planyearid, type, batchid) {
|
|
|
- console.group('filepath');
|
|
|
- console.log(filepath);
|
|
|
const file = await this.ctx.curl(filepath);
|
|
|
- console.log(file);
|
|
|
- console.groupEnd();
|
|
|
const workbook = XLSX.read(file.data);
|
|
|
- console.log(workbook);
|
|
|
// 读取内容
|
|
|
let exceldata = [];
|
|
|
const sheetNames = workbook.SheetNames; // 获取表名
|
|
|
- console.log(sheetNames);
|
|
|
const sheet = workbook.Sheets[sheetNames[0]]; // 通过表名得到表对象
|
|
|
- console.log(sheet);
|
|
|
|
|
|
// 遍历26个字母
|
|
|
- console.log('in function:');
|
|
|
const theadRule = [];
|
|
|
const range = XLSX.utils.decode_range(sheet['!ref']);
|
|
|
const col_start = range.s.c;
|
|
@@ -194,11 +188,9 @@ class SchoolService extends CrudService {
|
|
|
const addr = XLSX.utils.encode_col(i) + XLSX.utils.encode_row(0);
|
|
|
theadRule.push(sheet[addr].v);
|
|
|
}
|
|
|
- console.log('in function2:');
|
|
|
// const theadRule = [ sheet.A1.v, sheet.B1.v, sheet.C1.v, sheet.D1.v, sheet.E1.v, sheet.F1.v, sheet.G1.v, sheet.H1.v, sheet.I1.v, sheet.J1.v, sheet.K1.v, sheet.L1.v, sheet.M1.v, sheet.N1.v, sheet.O1.v, sheet.P1.v, sheet.Q1.v, sheet.R1.v ];
|
|
|
const params = XLSX.utils.sheet_to_json(sheet); // 通过工具将表对象的数据读出来并转成json
|
|
|
// const theadRule = [ '序号', '姓名', '性别', '民族', '身份证号', '学校名称', '院系', '专业', '入学年份', '毕业年份', '在校曾担任何种职务', '手机号', 'QQ号', '家庭所在地', '家庭是否困难', '是否获得过助学金' ];
|
|
|
- console.log('in function3:');
|
|
|
if (!params) return [];
|
|
|
let i = 0;
|
|
|
const length = params.length;
|
|
@@ -243,9 +235,7 @@ class SchoolService extends CrudService {
|
|
|
type,
|
|
|
});
|
|
|
}
|
|
|
- console.log('in function4:');
|
|
|
exceldata = [ ...exceldata, ..._datas ];
|
|
|
- console.log(`exceldata=>${exceldata}`);
|
|
|
|
|
|
return exceldata;
|
|
|
}
|
|
@@ -336,7 +326,6 @@ class SchoolService extends CrudService {
|
|
|
async exportSchool({ trainplanId }) {
|
|
|
// 批次期次都在这里面
|
|
|
const trainplan = await this.tmodel.find({ _id: trainplanId });
|
|
|
- console.log(trainplan);
|
|
|
const _headers = [
|
|
|
{ key: 'title', title: '计划标题' },
|
|
|
];
|