|
@@ -46,10 +46,7 @@ class StudentService extends CrudService {
|
|
|
|
|
|
async delete({ id }) {
|
|
|
|
|
|
- await this.gmodel.update(
|
|
|
- { 'students.stuid': id },
|
|
|
- { $pull: { students: { stuid: id } } }
|
|
|
- );
|
|
|
+ await this.gmodel.update({ 'students.stuid': id }, { $pull: { students: { stuid: id } } });
|
|
|
await this.upmodel.deleteMany({ studentid: id });
|
|
|
await this.uqmodel.deleteMany({ studentid: id });
|
|
|
await this.scoremodel.deleteMany({ stuid: id });
|
|
@@ -62,10 +59,7 @@ class StudentService extends CrudService {
|
|
|
if (student) {
|
|
|
const { phone, name } = data;
|
|
|
if (phone && name) {
|
|
|
- await this.umodel.findOneAndUpdate(
|
|
|
- { uid: id },
|
|
|
- { mobile: phone, name }
|
|
|
- );
|
|
|
+ await this.umodel.findOneAndUpdate({ uid: id }, { mobile: phone, name });
|
|
|
}
|
|
|
}
|
|
|
return student;
|
|
@@ -77,22 +71,22 @@ class StudentService extends CrudService {
|
|
|
if (name) {
|
|
|
query.name = { $regex: name };
|
|
|
}
|
|
|
- let data = await this.model
|
|
|
- .find(query)
|
|
|
- .skip(parseInt(skip))
|
|
|
- .limit(parseInt(limit));
|
|
|
- const planids = _.uniq(data.map(i => ObjectId(i.planid)));
|
|
|
+ let data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
+ const planids = _.uniq(data.map((i) => ObjectId(i.planid)));
|
|
|
const plan = await this.ctx.model.Trainplan.find({ _id: planids });
|
|
|
data = JSON.parse(JSON.stringify(data));
|
|
|
for (const i of data) {
|
|
|
- if (i.classid) { i.classid = await this.clamodel.findById(i.classid).lean(); }
|
|
|
+ if (i.classid) {
|
|
|
+ const d = await this.clamodel.findById(i.classid).exec();
|
|
|
+ if (d) i.classid = JSON.parse(JSON.stringify(d));
|
|
|
+ }
|
|
|
}
|
|
|
- data = data.map(i => {
|
|
|
+ data = data.map((i) => {
|
|
|
if (i.classid && _.isObject(i.classid)) {
|
|
|
i.classname = _.get(i.classid, 'name');
|
|
|
i.classid = _.get(i.classid, '_id');
|
|
|
}
|
|
|
- const p = plan.find(f => ObjectId(f._id).equals(i.planid));
|
|
|
+ const p = plan.find((f) => ObjectId(f._id).equals(i.planid));
|
|
|
if (p) {
|
|
|
const { termnum, title } = p;
|
|
|
i.plantitle = title;
|
|
@@ -203,14 +197,7 @@ class StudentService extends CrudService {
|
|
|
const detail = '你已被班主任设置为' + job + ',请及时登录查看';
|
|
|
const remark = '感谢您的使用';
|
|
|
if (openid) {
|
|
|
- this.ctx.service.weixin.sendTemplateMsg(
|
|
|
- this.ctx.app.config.REVIEW_TEMPLATE_ID,
|
|
|
- openid,
|
|
|
- '您有一个新的通知',
|
|
|
- detail,
|
|
|
- date,
|
|
|
- remark
|
|
|
- );
|
|
|
+ this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
|
|
|
}
|
|
|
}
|
|
|
return await student.save();
|
|
@@ -231,17 +218,12 @@ class StudentService extends CrudService {
|
|
|
async findscore({ skip, limit, ...info }) {
|
|
|
const { classid } = info;
|
|
|
const total = await this.model.count(info);
|
|
|
- const students = await this.model
|
|
|
- .find(info)
|
|
|
- .skip(Number(skip))
|
|
|
- .limit(Number(limit));
|
|
|
+ const students = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
|
|
|
const data = [];
|
|
|
const groups = await this.gmodel.find({ classid });
|
|
|
for (const student of students) {
|
|
|
const _student = JSON.parse(JSON.stringify(student));
|
|
|
- const group = groups.find(item =>
|
|
|
- item.students.find(stuinfo => stuinfo.stuid === _student.id)
|
|
|
- );
|
|
|
+ const group = groups.find((item) => item.students.find((stuinfo) => stuinfo.stuid === _student.id));
|
|
|
if (group) {
|
|
|
_student.groupscore = group.score;
|
|
|
}
|
|
@@ -299,19 +281,15 @@ class StudentService extends CrudService {
|
|
|
|
|
|
let studentList = await this.model.find({ classid });
|
|
|
|
|
|
- studentList = studentList.map(i => {
|
|
|
+ studentList = studentList.map((i) => {
|
|
|
if (i.job.includes('普通')) i.is_fine = '0';
|
|
|
else i.is_fine = '1';
|
|
|
return i;
|
|
|
});
|
|
|
|
|
|
- const reverseList = studentList.filter(
|
|
|
- f => !(f.is_fine !== '2' && f.job.includes('普通'))
|
|
|
- );
|
|
|
+ const reverseList = studentList.filter((f) => !(f.is_fine !== '2' && f.job.includes('普通')));
|
|
|
|
|
|
- studentList = studentList.filter(
|
|
|
- f => f.is_fine !== '2' && f.job.includes('普通')
|
|
|
- );
|
|
|
+ studentList = studentList.filter((f) => f.is_fine !== '2' && f.job.includes('普通'));
|
|
|
|
|
|
let dailyScoreList = await this.psmodel.find({ classid });
|
|
|
|
|
@@ -324,21 +302,12 @@ class StudentService extends CrudService {
|
|
|
|
|
|
const groupList = await this.gmodel.find({ classid });
|
|
|
const groupScoreList = await this.gsmodel.find({ classid });
|
|
|
- studentList = this.dealGroupScoreList(
|
|
|
- groupList,
|
|
|
- groupScoreList,
|
|
|
- studentList
|
|
|
- );
|
|
|
- studentList = studentList.map(i => {
|
|
|
- i.score = _.round(
|
|
|
- (i.daily || 0) + (i.task || 0) + (i.groupscore || 0),
|
|
|
- 2
|
|
|
- );
|
|
|
+ studentList = this.dealGroupScoreList(groupList, groupScoreList, studentList);
|
|
|
+ studentList = studentList.map((i) => {
|
|
|
+ i.score = _.round((i.daily || 0) + (i.task || 0) + (i.groupscore || 0), 2);
|
|
|
return i;
|
|
|
});
|
|
|
- studentList = studentList.sort(
|
|
|
- (a, b) => (b.score * 1 || 0) - (a.score * 1 || 0)
|
|
|
- );
|
|
|
+ studentList = studentList.sort((a, b) => (b.score * 1 || 0) - (a.score * 1 || 0));
|
|
|
|
|
|
|
|
|
let num = 0;
|
|
@@ -353,15 +322,11 @@ class StudentService extends CrudService {
|
|
|
let plus = 1;
|
|
|
|
|
|
student.is_fine = '1';
|
|
|
- const rlist = studentList.filter(
|
|
|
- f => f.score === score && !ObjectId(f._id).equals(_id)
|
|
|
- );
|
|
|
+ const rlist = studentList.filter((f) => f.score === score && !ObjectId(f._id).equals(_id));
|
|
|
|
|
|
for (const stud of rlist) {
|
|
|
stud.is_fine = '1';
|
|
|
- const sindex = studentList.findIndex(f =>
|
|
|
- ObjectId(stud._id).equals(f._id)
|
|
|
- );
|
|
|
+ const sindex = studentList.findIndex((f) => ObjectId(stud._id).equals(f._id));
|
|
|
if (sindex >= 0) {
|
|
|
studentList[sindex] = stud;
|
|
|
plus++;
|
|
@@ -371,14 +336,11 @@ class StudentService extends CrudService {
|
|
|
num = num + plus;
|
|
|
}
|
|
|
|
|
|
- const lastList = [ ...studentList, ...reverseList ];
|
|
|
+ const lastList = [...studentList, ...reverseList];
|
|
|
for (const student of lastList) {
|
|
|
|
|
|
|
|
|
- const r = await this.model.findByIdAndUpdate(
|
|
|
- { _id: ObjectId(student._id) },
|
|
|
- { score: student.score, is_fine: student.is_fine }
|
|
|
- );
|
|
|
+ const r = await this.model.findByIdAndUpdate({ _id: ObjectId(student._id) }, { score: student.score, is_fine: student.is_fine });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -416,7 +378,7 @@ class StudentService extends CrudService {
|
|
|
dealGroupScoreList(groupList, scoreList, studentList) {
|
|
|
scoreList = _.groupBy(scoreList, 'groupid');
|
|
|
|
|
|
- groupList = groupList.map(i => {
|
|
|
+ groupList = groupList.map((i) => {
|
|
|
const { students } = i;
|
|
|
if (students.length > 0) {
|
|
|
const slist = scoreList[i._id];
|
|
@@ -429,10 +391,8 @@ class StudentService extends CrudService {
|
|
|
return i;
|
|
|
});
|
|
|
|
|
|
- studentList = studentList.map(i => {
|
|
|
- const r = groupList.find(f =>
|
|
|
- f.students.find(sf => ObjectId(sf.stuid).equals(i._id))
|
|
|
- );
|
|
|
+ studentList = studentList.map((i) => {
|
|
|
+ const r = groupList.find((f) => f.students.find((sf) => ObjectId(sf.stuid).equals(i._id)));
|
|
|
if (r) {
|
|
|
|
|
|
i.groupscore = r.score * 1 || 0;
|
|
@@ -520,10 +480,10 @@ class StudentService extends CrudService {
|
|
|
assert(missionid, '缺少任务信息,无法执行任务');
|
|
|
try {
|
|
|
|
|
|
- const head = model.map(i => i.zh);
|
|
|
+ const head = model.map((i) => i.zh);
|
|
|
let fn = await this.toGetFn(data, missionid);
|
|
|
let dp = null;
|
|
|
- const { downloadPath, fn: nfn } = await this.ctx.service.util.toAsyncExcel([ head ], fn, dp);
|
|
|
+ const { downloadPath, fn: nfn } = await this.ctx.service.util.toAsyncExcel([head], fn, dp);
|
|
|
dp = downloadPath;
|
|
|
fn = nfn;
|
|
|
|
|
@@ -535,7 +495,7 @@ class StudentService extends CrudService {
|
|
|
else if (termid.length > 0) query.termid = termid;
|
|
|
else if (planid) query.planid = planid;
|
|
|
if (isComming === '0') query.isComming = '0';
|
|
|
- else if (isComming !== '0')query.isComming = { $ne: '0' };
|
|
|
+ else if (isComming !== '0') query.isComming = { $ne: '0' };
|
|
|
const total = await this.exportToGetTotal(query);
|
|
|
const times = Math.ceil(total / limit);
|
|
|
for (let i = 0; i < times; i++) {
|
|
@@ -543,7 +503,7 @@ class StudentService extends CrudService {
|
|
|
if (data.length <= 0) break;
|
|
|
skip = skip + limit;
|
|
|
data = await this.exportDealData(data);
|
|
|
- const dataList = data.map(i => {
|
|
|
+ const dataList = data.map((i) => {
|
|
|
const obj = [];
|
|
|
for (const m of model) {
|
|
|
obj.push(i[m.model]);
|
|
@@ -619,27 +579,27 @@ class StudentService extends CrudService {
|
|
|
{
|
|
|
model: 'schid',
|
|
|
type: 'get',
|
|
|
- format: i => i.school_name,
|
|
|
+ format: (i) => i.school_name,
|
|
|
},
|
|
|
{
|
|
|
model: 'termid',
|
|
|
type: 'get',
|
|
|
- format: i => i.termname,
|
|
|
+ format: (i) => i.termname,
|
|
|
},
|
|
|
{
|
|
|
model: 'batchid',
|
|
|
type: 'get',
|
|
|
- format: i => i.batchname,
|
|
|
+ format: (i) => i.batchname,
|
|
|
},
|
|
|
{
|
|
|
model: 'classid',
|
|
|
type: 'get',
|
|
|
- format: i => i.classname,
|
|
|
+ format: (i) => i.classname,
|
|
|
},
|
|
|
{
|
|
|
model: 'bedroomid',
|
|
|
type: 'get',
|
|
|
- format: i => i.bedroom,
|
|
|
+ format: (i) => i.bedroom,
|
|
|
},
|
|
|
];
|
|
|
|
|
@@ -657,7 +617,7 @@ class StudentService extends CrudService {
|
|
|
const option = _.head(options);
|
|
|
i[model] = option.to;
|
|
|
} else {
|
|
|
- const option = options.find(f => f.value === v);
|
|
|
+ const option = options.find((f) => f.value === v);
|
|
|
if (option) i[model] = option.to;
|
|
|
else {
|
|
|
|
|
@@ -666,7 +626,6 @@ class StudentService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
return data;
|
|
@@ -729,20 +688,13 @@ class StudentService extends CrudService {
|
|
|
|
|
|
|
|
|
async printCert({ ids }) {
|
|
|
- const res = await this.model.updateMany(
|
|
|
- { _id: { $in: ids.map(i => ObjectId(i)) } },
|
|
|
- { cert: '1' }
|
|
|
- );
|
|
|
+ const res = await this.model.updateMany({ _id: { $in: ids.map((i) => ObjectId(i)) } }, { cert: '1' });
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
|
|
|
async getSchoolStudent({ planid }) {
|
|
|
- const res = await this.model.aggregate([
|
|
|
- { $match: { planid } },
|
|
|
- { $group: { _id: '$schid', sum: { $sum: 1 } } },
|
|
|
- { $project: { _id: 0, schid: '$_id', schnum: '$sum' } },
|
|
|
- ]);
|
|
|
+ const res = await this.model.aggregate([{ $match: { planid } }, { $group: { _id: '$schid', sum: { $sum: 1 } } }, { $project: { _id: 0, schid: '$_id', schnum: '$sum' } }]);
|
|
|
return res;
|
|
|
}
|
|
|
}
|