feat(timezone): implement UTC and Beijing time conversion utilities and update bid handling
- Add functions to convert between UTC and Beijing time in timezone utility. - Update BidsService to return latest update and publish dates in Beijing time. - Modify BidCrawlerService to store publish dates in UTC format. - Change database timezone configuration to UTC for consistency.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
getDaysAgo,
|
||||
setStartOfDay,
|
||||
setEndOfDay,
|
||||
utcToBeijing,
|
||||
} from '../../common/utils/timezone.util';
|
||||
|
||||
interface FindAllQuery {
|
||||
@@ -23,7 +24,7 @@ interface SourceResult {
|
||||
export interface CrawlInfoAddStats {
|
||||
source: string;
|
||||
count: number;
|
||||
latestUpdate: Date | string;
|
||||
latestUpdate: Date | string | null;
|
||||
latestPublishDate: Date | string | null;
|
||||
error: string | null;
|
||||
}
|
||||
@@ -164,7 +165,7 @@ export class BidsService {
|
||||
count,
|
||||
latestPublishDate,
|
||||
error,
|
||||
strftime('%Y-%m-%d %H:%M:%S', createdAt, '+8 hours') as latestUpdate
|
||||
createdAt as latestUpdate
|
||||
FROM crawl_info_add
|
||||
WHERE (source, createdAt) IN (
|
||||
SELECT source, MAX(createdAt)
|
||||
@@ -177,16 +178,26 @@ export class BidsService {
|
||||
const results =
|
||||
await this.crawlInfoRepository.query<CrawlInfoAddRawResult[]>(query);
|
||||
|
||||
return results.map((item) => ({
|
||||
source: String(item.source),
|
||||
count: Number(item.count),
|
||||
latestUpdate: item.latestUpdate,
|
||||
latestPublishDate: item.latestPublishDate,
|
||||
// 确保 error 字段正确处理:null 或空字符串都转换为 null,非空字符串保留
|
||||
error:
|
||||
item.error && String(item.error).trim() !== ''
|
||||
? String(item.error)
|
||||
: null,
|
||||
}));
|
||||
return results.map((item) => {
|
||||
// 将UTC时间转换为北京时间显示
|
||||
const latestUpdateBeijing = item.latestUpdate
|
||||
? utcToBeijing(new Date(item.latestUpdate))
|
||||
: null;
|
||||
const latestPublishDateBeijing = item.latestPublishDate
|
||||
? utcToBeijing(new Date(item.latestPublishDate))
|
||||
: null;
|
||||
|
||||
return {
|
||||
source: String(item.source),
|
||||
count: Number(item.count),
|
||||
latestUpdate: latestUpdateBeijing,
|
||||
latestPublishDate: latestPublishDateBeijing,
|
||||
// 确保 error 字段正确处理:null 或空字符串都转换为 null,非空字符串保留
|
||||
error:
|
||||
item.error && String(item.error).trim() !== ''
|
||||
? String(item.error)
|
||||
: null,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user