|
@@ -74,6 +74,46 @@ class SchoolService extends CrudService {
|
|
return await this.model.count(query);
|
|
return await this.model.count(query);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 去重查询学校
|
|
|
|
+ async findSchool({ name, skip, limit, ...info }) {
|
|
|
|
+ let data = [];
|
|
|
|
+ const query = { ...info };
|
|
|
|
+ if (name) {
|
|
|
|
+ query.name = { $regex: name };
|
|
|
|
+ }
|
|
|
|
+ const AggregateInfo = [
|
|
|
|
+ // 这里可以添加其他查询条件,例如过滤特定字段等
|
|
|
|
+ { $match: query },
|
|
|
|
+ // 去除重复数据
|
|
|
|
+ { $group: { _id: '$code', uniqueData: { $first: '$$ROOT' } } },
|
|
|
|
+ { $replaceRoot: { newRoot: '$uniqueData' } },
|
|
|
|
+ { $addFields: { id: '$_id' } },
|
|
|
|
+ // 分页查询
|
|
|
|
+ { $skip: parseInt(skip) },
|
|
|
|
+ ];
|
|
|
|
+ if (limit) AggregateInfo.push({ $limit: parseInt(limit) });
|
|
|
|
+ const res = await this.model.aggregate(AggregateInfo);
|
|
|
|
+ if (res && res.length > 0) {
|
|
|
|
+ data = JSON.parse(JSON.stringify(res));
|
|
|
|
+ const ids = res.map(i => i._id);
|
|
|
|
+ const users = await this.umodel.find({ uid: { $in: ids } }, '+passwd').lean();
|
|
|
|
+ for (const tea of data) {
|
|
|
|
+ const r = users.find(f => f.uid === tea._id);
|
|
|
|
+ if (r) {
|
|
|
|
+ const passwd = _.get(r.passwd, 'secret');
|
|
|
|
+ if (passwd) tea.passwd = passwd;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ const count = await this.model.aggregate([
|
|
|
|
+ { $match: query },
|
|
|
|
+ { $group: { _id: '$code' } },
|
|
|
|
+ { $count: 'distinctCount' },
|
|
|
|
+ ]);
|
|
|
|
+ const total = _.get(count[0], 'distinctCount') || 0;
|
|
|
|
+ return { total, data };
|
|
|
|
+ }
|
|
|
|
+
|
|
async stuimport(data) {
|
|
async stuimport(data) {
|
|
const { filepath, termid, schid, type, batchid } = data;
|
|
const { filepath, termid, schid, type, batchid } = data;
|
|
assert(filepath, 'filepath不能为空');
|
|
assert(filepath, 'filepath不能为空');
|