|
@@ -9,6 +9,8 @@ import { Match } from '../entity/platform/match.entity';
|
|
|
import { Expert } from '../entity/users/expert.entity';
|
|
|
import { Company } from '../entity/users/company.entity';
|
|
|
import { Project } from '../entity/platform/project.entity';
|
|
|
+import { News } from '../entity/platform/news.entity';
|
|
|
+import { Unit } from '../entity/users/unit.entity';
|
|
|
@Provide()
|
|
|
export class ToolService {
|
|
|
@Inject()
|
|
@@ -28,12 +30,74 @@ export class ToolService {
|
|
|
@InjectEntityModel(Match)
|
|
|
mModel: ReturnModelType<typeof Match>;
|
|
|
|
|
|
+ @InjectEntityModel(News)
|
|
|
+ nModel: ReturnModelType<typeof News>;
|
|
|
+
|
|
|
+ @InjectEntityModel(Unit)
|
|
|
+ uModel: ReturnModelType<typeof Unit>;
|
|
|
+
|
|
|
@InjectEntityModel(Expert)
|
|
|
eModel: ReturnModelType<typeof Expert>;
|
|
|
|
|
|
@InjectEntityModel(Company)
|
|
|
companyModel: ReturnModelType<typeof Company>;
|
|
|
|
|
|
+ // 搜索总数
|
|
|
+ async getTotal(filter) {
|
|
|
+ const { searchValue, ...condition } = filter;
|
|
|
+ const actList = [
|
|
|
+ { label: '成果', value: 'achievement' },
|
|
|
+ { label: '需求', value: 'demand' },
|
|
|
+ { label: '项目', value: 'project' },
|
|
|
+ { label: '赛事', value: 'match' },
|
|
|
+ { label: '资讯', value: 'news' },
|
|
|
+ { label: '单位', value: 'unit' },
|
|
|
+ { label: '企业', value: 'company' },
|
|
|
+ { label: '专家', value: 'expert' },
|
|
|
+ ];
|
|
|
+ for (const val of actList) {
|
|
|
+ let model;
|
|
|
+ const query = { ...condition };
|
|
|
+ if (searchValue) {
|
|
|
+ if (val.value === 'news') query.title = { $regex: searchValue };
|
|
|
+ else query.name = { $regex: searchValue };
|
|
|
+ }
|
|
|
+ if (val.value === 'achievement') model = this.aModel;
|
|
|
+ if (val.value === 'demand') model = this.dModel;
|
|
|
+ if (val.value === 'project') model = this.pModel;
|
|
|
+ if (val.value === 'match') model = this.mModel;
|
|
|
+ if (val.value === 'news') model = this.nModel;
|
|
|
+ if (val.value === 'unit') model = this.uModel;
|
|
|
+ if (val.value === 'company') model = this.companyModel;
|
|
|
+ if (val.value === 'expert') model = this.eModel;
|
|
|
+ const total = await model.count(query).lean();
|
|
|
+ val.label = val.label + `(${total})`;
|
|
|
+ }
|
|
|
+ return actList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 搜索
|
|
|
+ async query(filter) {
|
|
|
+ const { skip = 0, limit = 0, type, searchValue, ...condition } = filter;
|
|
|
+ let model;
|
|
|
+ const query = { ...condition };
|
|
|
+ if (searchValue) {
|
|
|
+ if (type === 'news') query.title = { $regex: searchValue };
|
|
|
+ else query.name = { $regex: searchValue };
|
|
|
+ }
|
|
|
+ if (type === 'achievement') model = this.aModel;
|
|
|
+ if (type === 'demand') model = this.dModel;
|
|
|
+ if (type === 'project') model = this.pModel;
|
|
|
+ if (type === 'match') model = this.mModel;
|
|
|
+ if (type === 'news') model = this.nModel;
|
|
|
+ if (type === 'unit') model = this.uModel;
|
|
|
+ if (type === 'company') model = this.companyModel;
|
|
|
+ if (type === 'expert') model = this.eModel;
|
|
|
+ const data = await model.find(query).skip(skip).limit(limit).lean();
|
|
|
+ const total = await model.count(query).lean();
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
+
|
|
|
// 收藏总数
|
|
|
async getCollectionTotal() {
|
|
|
const user = this.ctx.user;
|