|
|
@@ -1,4 +1,4 @@
|
|
|
-import { DataSource, Repository } from 'typeorm';
|
|
|
+import { DataSource, Repository, In, Not, Like, MoreThan, Raw, Brackets } from 'typeorm';
|
|
|
import { PolicyNews } from '../silver-users/policy-news.entity';
|
|
|
import { Job } from '../silver-jobs/job.entity';
|
|
|
import { SilverKnowledge } from '../silver-users/silver-knowledge.entity';
|
|
|
@@ -120,24 +120,43 @@ export class HomeService {
|
|
|
});
|
|
|
const viewedJobIds = viewedJobs.map(v => v.jobId);
|
|
|
|
|
|
- let query = this.jobRepo
|
|
|
- .createQueryBuilder('job')
|
|
|
- .leftJoinAndSelect('job.company', 'company')
|
|
|
- .where('job.status = :status', { status: 1 });
|
|
|
+ // 构建查询条件
|
|
|
+ const whereConditions: any = {
|
|
|
+ status: 1
|
|
|
+ };
|
|
|
|
|
|
if (viewedJobIds.length > 0) {
|
|
|
- query = query.andWhere('job.id NOT IN (:...viewedJobIds)', { viewedJobIds });
|
|
|
+ whereConditions.id = Not(In(viewedJobIds));
|
|
|
}
|
|
|
|
|
|
// 基于用户专业背景匹配
|
|
|
+ const queryBuilder = this.jobRepo
|
|
|
+ .createQueryBuilder('job')
|
|
|
+ .leftJoinAndSelect('job.company', 'company')
|
|
|
+ .where(whereConditions);
|
|
|
+
|
|
|
if (userProfile?.personalSkills) {
|
|
|
- const skills = userProfile.personalSkills.split(',').map((s: string) => s.trim());
|
|
|
- for (let i = 0; i < skills.length; i++) {
|
|
|
- query = query.orWhere(`job.requirements LIKE :skill${i}`, { [`skill${i}`]: `%${skills[i]}%` });
|
|
|
+ const skills = userProfile.personalSkills.split(',').map((s: string) => s.trim()).filter(s => s);
|
|
|
+ if (skills.length > 0) {
|
|
|
+ const orConditions = skills.map(skill => ({
|
|
|
+ requirements: Like(`%${skill}%`)
|
|
|
+ }));
|
|
|
+
|
|
|
+ queryBuilder.andWhere(
|
|
|
+ new Brackets(qb => {
|
|
|
+ orConditions.forEach((condition, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ qb.where(condition);
|
|
|
+ } else {
|
|
|
+ qb.orWhere(condition);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return await query
|
|
|
+ return await queryBuilder
|
|
|
.orderBy('job.createdAt', 'DESC')
|
|
|
.limit(limit)
|
|
|
.getMany();
|
|
|
@@ -165,33 +184,38 @@ export class HomeService {
|
|
|
});
|
|
|
const viewedKnowledgeIds = userInteractions.map(i => i.knowledgeId);
|
|
|
|
|
|
- // 获取用户浏览过的知识分类,进行相似推荐
|
|
|
- let categoryQuery = this.knowledgeRepo
|
|
|
+ // 获取用户浏览过的知识分类
|
|
|
+ const userCategories = await this.knowledgeRepo
|
|
|
.createQueryBuilder('knowledge')
|
|
|
- .select('DISTINCT knowledge.categoryId', 'categoryId')
|
|
|
- .where('knowledge.id IN (:...viewedKnowledgeIds)', { viewedKnowledgeIds });
|
|
|
-
|
|
|
- const userCategories = await categoryQuery.getRawMany();
|
|
|
+ .select('knowledge.categoryId')
|
|
|
+ .distinct(true)
|
|
|
+ .where({ id: In(viewedKnowledgeIds) })
|
|
|
+ .getRawMany();
|
|
|
+
|
|
|
const preferredCategories = userCategories.map((c: any) => c.categoryId);
|
|
|
|
|
|
- let query = this.knowledgeRepo
|
|
|
- .createQueryBuilder('knowledge')
|
|
|
- .leftJoinAndSelect('knowledge.category', 'category')
|
|
|
- .where('knowledge.status = :status', { status: 1 });
|
|
|
+ // 构建查询条件
|
|
|
+ const whereConditions: any = {
|
|
|
+ status: 1
|
|
|
+ };
|
|
|
|
|
|
if (viewedKnowledgeIds.length > 0) {
|
|
|
- query = query.andWhere('knowledge.id NOT IN (:...viewedKnowledgeIds)', { viewedKnowledgeIds });
|
|
|
+ whereConditions.id = Not(In(viewedKnowledgeIds));
|
|
|
}
|
|
|
|
|
|
if (preferredCategories.length > 0) {
|
|
|
- query = query.andWhere('knowledge.categoryId IN (:...preferredCategories)', { preferredCategories });
|
|
|
+ whereConditions.categoryId = In(preferredCategories);
|
|
|
}
|
|
|
|
|
|
- return await query
|
|
|
- .orderBy('knowledge.viewCount', 'DESC')
|
|
|
- .addOrderBy('knowledge.createdAt', 'DESC')
|
|
|
- .limit(limit)
|
|
|
- .getMany();
|
|
|
+ return await this.knowledgeRepo.find({
|
|
|
+ where: whereConditions,
|
|
|
+ relations: ['category'],
|
|
|
+ order: {
|
|
|
+ viewCount: 'DESC',
|
|
|
+ createdAt: 'DESC'
|
|
|
+ },
|
|
|
+ take: limit
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -256,13 +280,20 @@ export class HomeService {
|
|
|
companies: []
|
|
|
};
|
|
|
|
|
|
+ const searchKeyword = `%${keyword}%`;
|
|
|
+
|
|
|
if (type === 'jobs' || type === 'all') {
|
|
|
results.jobs = await this.jobRepo
|
|
|
.createQueryBuilder('job')
|
|
|
.leftJoinAndSelect('job.company', 'company')
|
|
|
.where('job.status = :status', { status: 1 })
|
|
|
- .andWhere('(job.title LIKE :keyword OR job.description LIKE :keyword OR company.name LIKE :keyword)')
|
|
|
- .setParameter('keyword', `%${keyword}%`)
|
|
|
+ .andWhere(
|
|
|
+ new Brackets(qb => {
|
|
|
+ qb.where('job.title LIKE :keyword', { keyword: searchKeyword })
|
|
|
+ .orWhere('job.description LIKE :keyword', { keyword: searchKeyword })
|
|
|
+ .orWhere('company.name LIKE :keyword', { keyword: searchKeyword });
|
|
|
+ })
|
|
|
+ )
|
|
|
.limit(limit)
|
|
|
.getMany();
|
|
|
}
|
|
|
@@ -272,8 +303,12 @@ export class HomeService {
|
|
|
.createQueryBuilder('knowledge')
|
|
|
.leftJoinAndSelect('knowledge.category', 'category')
|
|
|
.where('knowledge.status = :status', { status: 1 })
|
|
|
- .andWhere('(knowledge.title LIKE :keyword OR knowledge.content LIKE :keyword)')
|
|
|
- .setParameter('keyword', `%${keyword}%`)
|
|
|
+ .andWhere(
|
|
|
+ new Brackets(qb => {
|
|
|
+ qb.where('knowledge.title LIKE :keyword', { keyword: searchKeyword })
|
|
|
+ .orWhere('knowledge.content LIKE :keyword', { keyword: searchKeyword });
|
|
|
+ })
|
|
|
+ )
|
|
|
.limit(limit)
|
|
|
.getMany();
|
|
|
}
|
|
|
@@ -282,9 +317,13 @@ export class HomeService {
|
|
|
const Company = this.jobRepo.manager.getRepository('Company');
|
|
|
results.companies = await Company
|
|
|
.createQueryBuilder('company')
|
|
|
- .where('company.status = 1')
|
|
|
- .andWhere('(company.name LIKE :keyword OR company.description LIKE :keyword)')
|
|
|
- .setParameter('keyword', `%${keyword}%`)
|
|
|
+ .where('company.status = :status', { status: 1 })
|
|
|
+ .andWhere(
|
|
|
+ new Brackets(qb => {
|
|
|
+ qb.where('company.name LIKE :keyword', { keyword: searchKeyword })
|
|
|
+ .orWhere('company.description LIKE :keyword', { keyword: searchKeyword });
|
|
|
+ })
|
|
|
+ )
|
|
|
.limit(limit)
|
|
|
.getMany();
|
|
|
}
|