|
@@ -38,6 +38,11 @@ class SchoolService extends CrudService {
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
+ async delete({ id }) {
|
|
|
+ const res = await this.model.findByIdAndDelete(id);
|
|
|
+ await this.umodel.deleteOne({ uid: id, type: '2' });
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
async query({ name, ...data }, { skip, limit }) {
|
|
|
const query = { ...data };
|
|
@@ -47,10 +52,10 @@ class SchoolService extends CrudService {
|
|
|
let res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
if (res && res.length > 0) {
|
|
|
res = JSON.parse(JSON.stringify(res));
|
|
|
- const ids = res.map(i => i._id);
|
|
|
+ const ids = res.map((i) => i._id);
|
|
|
const users = await this.umodel.find({ uid: { $in: ids } }, '+passwd');
|
|
|
for (const tea of res) {
|
|
|
- const r = users.find(f => f.uid === tea._id);
|
|
|
+ const r = users.find((f) => f.uid === tea._id);
|
|
|
if (r) {
|
|
|
const passwd = _.get(r.passwd, 'secret');
|
|
|
if (passwd) tea.passwd = passwd;
|
|
@@ -85,8 +90,12 @@ class SchoolService extends CrudService {
|
|
|
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 is_change = dbStuList.find((f) => f.classid || f.bedroomid);
|
|
|
+ if (is_change)
|
|
|
+ throw new BusinessError(
|
|
|
+ ErrorCode.BUSINESS,
|
|
|
+ '上报过的学生已经安排班级或寝室!若需要替换学生,让同性别的学生直接来和班主任说,修改信息即可.若还是有疑问,请和中心负责人联系(最好联系下)'
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
const countOpenid = await this.ctx.model.Student.count({ termid, batchid, schid, openid: { $exists: true } });
|
|
@@ -154,7 +163,7 @@ class SchoolService extends CrudService {
|
|
|
|
|
|
if (dbStuList.length > 0) {
|
|
|
dbStuList = JSON.parse(JSON.stringify(dbStuList));
|
|
|
- dbStuList = dbStuList.map(i => {
|
|
|
+ dbStuList = dbStuList.map((i) => {
|
|
|
delete i.meta;
|
|
|
i.studentid = _.clone(i._id);
|
|
|
delete i.id;
|
|
@@ -201,8 +210,10 @@ class SchoolService extends CrudService {
|
|
|
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 r = arrange.find((f) => f.batchid === batchid);
|
|
|
+ if (!r) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '没有找到该学校的计划');
|
|
|
+ }
|
|
|
const { number } = r;
|
|
|
return parseInt(number);
|
|
|
}
|
|
@@ -228,9 +239,9 @@ class SchoolService extends CrudService {
|
|
|
headRow.eachCell((cell, coli) => {
|
|
|
console.log(cell.value);
|
|
|
if (cell.value !== '序号') {
|
|
|
- const r = cols.find(f => f.key === cell.value);
|
|
|
+ const r = cols.find((f) => f.key === cell.value);
|
|
|
if (r) {
|
|
|
- const ri = cols.findIndex(f => f.key === cell.value);
|
|
|
+ const ri = cols.findIndex((f) => f.key === cell.value);
|
|
|
|
|
|
r.colIndex = coli;
|
|
|
cols[ri] = r;
|
|
@@ -240,14 +251,14 @@ class SchoolService extends CrudService {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- const excelIsRigth = cols.every(f => f.colIndex);
|
|
|
+ const excelIsRigth = cols.every((f) => f.colIndex);
|
|
|
if (!excelIsRigth) throw new BusinessError(ErrorCode.DATA_INVALID, 'Excel表格格式不正确,请使用系统提供的模板,或重新下载模板!');
|
|
|
|
|
|
worksheet.spliceRows(0, 1);
|
|
|
const stuList = [];
|
|
|
- const noWhite = str => str.replace(/\s*/g, '');
|
|
|
+ const noWhite = (str) => str.replace(/\s*/g, '');
|
|
|
|
|
|
- worksheet.eachRow(row => {
|
|
|
+ worksheet.eachRow((row) => {
|
|
|
const stu = {};
|
|
|
for (let i = 0; i < cols.length; i++) {
|
|
|
const col = cols[i];
|
|
@@ -260,7 +271,6 @@ class SchoolService extends CrudService {
|
|
|
stuList.push(stu);
|
|
|
});
|
|
|
return stuList;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
async checkData(stuList) {
|
|
@@ -304,7 +314,7 @@ class SchoolService extends CrudService {
|
|
|
|
|
|
|
|
|
|
|
|
- const have_same = stuList.filter(f => f.id_number === val && f.name !== name);
|
|
|
+ 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);
|
|
@@ -328,7 +338,7 @@ class SchoolService extends CrudService {
|
|
|
|
|
|
|
|
|
|
|
|
- const have_same = stuList.filter(f => f.phone === val && f.name !== name);
|
|
|
+ const have_same = stuList.filter((f) => f.phone === val && f.name !== name);
|
|
|
if (have_same.length > 0) {
|
|
|
error = true;
|
|
|
const h = _.head(have_same);
|
|
@@ -393,15 +403,15 @@ class SchoolService extends CrudService {
|
|
|
|
|
|
lastSetData(stuList, data) {
|
|
|
const cols = this.getStucolumn();
|
|
|
- const needChange = cols.filter(f => f.change);
|
|
|
- stuList = stuList.map(i => {
|
|
|
+ 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);
|
|
|
+ const r = change.find((f) => f.key === val);
|
|
|
if (!r) continue;
|
|
|
const { value } = r;
|
|
|
d[column] = value;
|
|
@@ -448,8 +458,7 @@ class SchoolService extends CrudService {
|
|
|
return arr;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
async exportSchool({ trainplanId }) {
|
|
|
|
|
|
const trainplan = await this.tmodel.find({ _id: trainplanId });
|
|
@@ -458,30 +467,13 @@ class SchoolService extends CrudService {
|
|
|
const _data = trainplan;
|
|
|
const headers = _headers
|
|
|
.map(({ title }) => title)
|
|
|
- .map((v, i) =>
|
|
|
- Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 })
|
|
|
- )
|
|
|
- .reduce(
|
|
|
- (prev, next) =>
|
|
|
- Object.assign({}, prev, { [next.position]: { v: next.v } }),
|
|
|
- {}
|
|
|
- );
|
|
|
+ .map((v, i) => Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 }))
|
|
|
+ .reduce((prev, next) => Object.assign({}, prev, { [next.position]: { v: next.v } }), {});
|
|
|
|
|
|
const data = _data
|
|
|
- .map((v, i) =>
|
|
|
- _headers.map(({ key }, j) =>
|
|
|
- Object.assign(
|
|
|
- {},
|
|
|
- { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) }
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
+ .map((v, i) => _headers.map(({ key }, j) => Object.assign({}, { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) })))
|
|
|
.reduce((prev, next) => prev.concat(next))
|
|
|
- .reduce(
|
|
|
- (prev, next) =>
|
|
|
- Object.assign({}, prev, { [next.position]: { v: next.v } }),
|
|
|
- {}
|
|
|
- );
|
|
|
+ .reduce((prev, next) => Object.assign({}, prev, { [next.position]: { v: next.v } }), {});
|
|
|
|
|
|
|
|
|
const output = Object.assign({}, headers, data);
|
|
@@ -494,12 +486,11 @@ class SchoolService extends CrudService {
|
|
|
|
|
|
|
|
|
const nowDate = new Date().getTime();
|
|
|
- const path =
|
|
|
- 'D:\\wwwroot\\service\\service-file\\upload\\train\\' + nowDate + '.xlsx';
|
|
|
- const respath =
|
|
|
- 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
|
|
|
+
|
|
|
+ const path = 'D:\\wwwroot\\service\\service-file\\upload\\train\\' + nowDate + '.xlsx';
|
|
|
+ const respath = 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
|
|
|
const wb = {
|
|
|
- SheetNames: [ 'sheet0' ],
|
|
|
+ SheetNames: ['sheet0'],
|
|
|
Sheets: { sheet0: Object.assign({}, output, { '!ref': ref }) },
|
|
|
};
|
|
|
|
|
@@ -584,12 +575,7 @@ class SchoolService extends CrudService {
|
|
|
pass: true,
|
|
|
msg: '验证成功',
|
|
|
};
|
|
|
- if (
|
|
|
- !code ||
|
|
|
- !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/.test(
|
|
|
- code
|
|
|
- )
|
|
|
- ) {
|
|
|
+ if (!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/.test(code)) {
|
|
|
row = {
|
|
|
pass: false,
|
|
|
msg: '身份证号格式错误',
|
|
@@ -601,13 +587,13 @@ class SchoolService extends CrudService {
|
|
|
};
|
|
|
} else {
|
|
|
|
|
|
- if (code.length == 18) {
|
|
|
+ if (code.length === 18) {
|
|
|
code = code.split('');
|
|
|
|
|
|
|
|
|
- const factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
|
|
|
+ const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
|
|
|
|
- const parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
|
|
|
+ const parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
|
|
|
let sum = 0;
|
|
|
let ai = 0;
|
|
|
let wi = 0;
|
|
@@ -616,7 +602,7 @@ class SchoolService extends CrudService {
|
|
|
wi = factor[i];
|
|
|
sum += ai * wi;
|
|
|
}
|
|
|
- if (parity[sum % 11] != code[17].toUpperCase()) {
|
|
|
+ if (parity[sum % 11] !== code[17].toUpperCase()) {
|
|
|
row = {
|
|
|
pass: false,
|
|
|
msg: '身份证号校验位错误',
|