Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/article/article.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ArticleService {
const article = this.articleRepository.create({
...createArticleDto,
userId,
isActive: false, // 创建时默认为未激活状态
});
const savedArticle = await this.articleRepository.save(article);
return new ArticleResponseDto(savedArticle);
Expand All @@ -64,6 +65,7 @@ export class ArticleService {
articleAuthor,
startTime,
endTime,
showAll = false, // 默认只显示激活的文章
} = query;
const skip = (page - 1) * limit;

Expand Down Expand Up @@ -95,6 +97,14 @@ export class ArticleService {
);
}

// 如果不是显示所有,只显示激活的文章
if (!showAll) {
queryBuilder.andWhere('article.isActive = :isActive', { isActive: true })
.andWhere('(article.startTime IS NULL OR article.startTime <= :now)')
.andWhere('(article.endTime IS NULL OR article.endTime >= :now)')
.setParameter('now', new Date());
}

// 执行查询并获取结果
const [items, total] = await queryBuilder
.orderBy('article.createTime', 'DESC')
Expand Down Expand Up @@ -170,6 +180,23 @@ export class ArticleService {
throw new ForbiddenException('您没有权限修改这篇文章');
}

// 如果要修改文章状态、开始时间或结束时间,必须是管理员
if ((updateArticleDto.isActive !== undefined ||
updateArticleDto.startTime !== undefined ||
updateArticleDto.endTime !== undefined) &&
!isAdmin) {
throw new ForbiddenException('只有管理员可以修改文章状态和时间设置');
}

// 如果设置了开始和结束时间,验证时间范围
if (updateArticleDto.startTime && updateArticleDto.endTime) {
const startTime = new Date(updateArticleDto.startTime);
const endTime = new Date(updateArticleDto.endTime);
if (startTime >= endTime) {
throw new ForbiddenException('结束时间必须晚于开始时间');
}
}

const updatedArticle = await this.articleRepository.save({
...article,
...updateArticleDto,
Expand Down
10 changes: 10 additions & 0 deletions src/article/dto/query-article.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
IsInt,
IsString,
IsDateString,
IsBoolean,
Min,
Max,
} from 'class-validator';
Expand Down Expand Up @@ -37,4 +38,13 @@ export class QueryArticleDto {
@IsOptional()
@IsDateString({}, { message: '结束时间格式不正确,应为ISO格式的日期字符串' })
endTime?: string;

/**
* 是否显示所有文章,包括未激活的
* 只有管理员可以设置为true
*/
@IsOptional()
@IsBoolean({ message: '显示所有文章必须是布尔值' })
@Type(() => Boolean)
showAll?: boolean = false;
}
25 changes: 24 additions & 1 deletion src/article/dto/update-article.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateArticleDto } from './create-article.dto';
import { IsOptional, IsString, Length, MaxLength } from 'class-validator';
import { IsOptional, IsString, Length, MaxLength, IsBoolean, IsDateString } from 'class-validator';
import { Type } from 'class-transformer';

export class UpdateArticleDto extends PartialType(CreateArticleDto) {
@IsOptional()
Expand Down Expand Up @@ -29,4 +30,26 @@ export class UpdateArticleDto extends PartialType(CreateArticleDto) {
@IsOptional()
@IsString({ message: '文章内容必须是字符串' })
articleContent?: string;

/**
* 文章状态
*/
@IsOptional()
@IsBoolean({ message: '文章状态必须是布尔值' })
@Type(() => Boolean)
isActive?: boolean;

/**
* 开始时间
*/
@IsOptional()
@IsDateString({}, { message: '开始时间格式不正确,应为ISO格式的日期字符串' })
startTime?: Date;

/**
* 结束时间
*/
@IsOptional()
@IsDateString({}, { message: '结束时间格式不正确,应为ISO格式的日期字符串' })
endTime?: Date;
}
25 changes: 25 additions & 0 deletions src/article/entities/article.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ export class ArticleEntity {
})
articleContent: string;

// 开始时间
@Column({
type: 'datetime',
nullable: true,
name: 'start_time'
})
startTime: Date;

// 结束时间
@Column({
type: 'datetime',
nullable: true,
name: 'end_time'
})
endTime: Date;

// 状态。是否开始
@Column({
type: 'bool',
nullable: false,
name: 'is_active',
default: false
})
isActive: boolean

// 创建日期
@CreateDateColumn({
type: 'datetime',
Expand Down
7 changes: 7 additions & 0 deletions src/recruitment/dto/create-recruitment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ export class CreateRecruitmentDto {
@IsNotEmpty({ message: '简历文件地址不能为空' })
@IsOptional()
resumeFilePath?: string;

/**
* 投递者姓名
*/
@IsString({ message: '姓名必须是字符串' })
@IsNotEmpty({ message: '姓名不能为空' })
userName: string;
}
7 changes: 7 additions & 0 deletions src/recruitment/dto/query-recruitment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@ export class QueryRecruitmentDto {
@IsOptional()
@IsString({ message: '电话号码必须是字符串' })
phone?: string;

/**
* 投递者姓名(支持模糊查询)
*/
@IsOptional()
@IsString({ message: '姓名必须是字符串' })
userName?: string;
}
6 changes: 6 additions & 0 deletions src/recruitment/dto/recruitment-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export class RecruitmentResponseDto {
*/
phone: string;

/**
* 投递者姓名
*/
userName: string;

constructor(recruitment: RecruitmentEntity) {
this.officialResumeId = recruitment.officialResumeId;
this.userId = recruitment.userId;
Expand All @@ -81,6 +86,7 @@ export class RecruitmentResponseDto {
this.updateTime = recruitment.updateTime;
this.email = recruitment.email;
this.phone = recruitment.phone;
this.userName = recruitment.userName;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/recruitment/entities/recruiment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export class RecruitmentEntity {
})
userId: number;

// 投递者名字
@Column({
name: 'user_name',
nullable: false,
type: 'string'
})
userName: string;

// 求职类型
@Column({
name: 'recr_type',
Expand Down
8 changes: 8 additions & 0 deletions src/recruitment/recruitment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class RecruitmentService {
endTime,
email,
phone,
userName,
} = query;
const skip = (page - 1) * limit;

Expand Down Expand Up @@ -94,6 +95,13 @@ export class RecruitmentService {
});
}

// 根据投递者姓名过滤
if (userName) {
queryBuilder.andWhere('recruitment.userName LIKE :userName', {
userName: `%${userName}%`,
});
}

// 根据时间范围过滤
if (startTime && endTime) {
queryBuilder.andWhere(
Expand Down
Loading