feat: 添加项目置顶功能

在仪表盘中添加置顶项目功能,包括:
- 新增置顶项目展示区域
- 为AI推荐项目添加置顶/取消置顶操作
- 后端接口支持置顶状态管理
This commit is contained in:
dmy
2026-01-13 20:56:21 +08:00
parent 4f4355c1cd
commit 50bc930663
4 changed files with 173 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { Controller, Get, Query } from '@nestjs/common';
import { Controller, Get, Query, Patch, Param, Body } from '@nestjs/common';
import { BidsService } from '../services/bid.service';
@Controller('api/bids')
@@ -15,6 +15,11 @@ export class BidsController {
return this.bidsService.getRecentBids();
}
@Get('pinned')
getPinned() {
return this.bidsService.getPinnedBids();
}
@Get('sources')
getSources() {
return this.bidsService.getSources();
@@ -30,4 +35,9 @@ export class BidsController {
getCrawlInfoStats() {
return this.bidsService.getCrawlInfoAddStats();
}
@Patch(':title/pin')
updatePin(@Param('title') title: string, @Body() body: { pin: boolean }) {
return this.bidsService.updatePin(title, body.pin);
}
}

View File

@@ -17,6 +17,9 @@ export class BidItem {
@Column()
source: string;
@Column({ default: false })
pin: boolean;
@CreateDateColumn()
createdAt: Date;

View File

@@ -73,6 +73,14 @@ export class BidsService {
.getMany();
}
async getPinnedBids() {
return this.bidRepository
.createQueryBuilder('bid')
.where('bid.pin = :pin', { pin: true })
.orderBy('bid.publishDate', 'DESC')
.getMany();
}
async getBidsByDateRange(startDate?: string, endDate?: string, keywords?: string[]) {
const qb = this.bidRepository.createQueryBuilder('bid');
@@ -101,6 +109,15 @@ export class BidsService {
return qb.orderBy('bid.publishDate', 'DESC').getMany();
}
async updatePin(title: string, pin: boolean) {
const item = await this.bidRepository.findOne({ where: { title } });
if (!item) {
throw new Error('Bid not found');
}
item.pin = pin;
return this.bidRepository.save(item);
}
async getCrawlInfoAddStats() {
// 获取每个来源的最新一次爬虫记录(按 createdAt 降序)
const query = `