Skip to content

Commit

Permalink
fix: 修复 日志存在重复的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Jun 27, 2024
1 parent 7bb0392 commit b8996b2
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CacheService } from './services/cache/cache.service'
import { SystemController } from './controllers/system/system.controller'
import { FeedService } from './services/feed/feed.service'
import { CategoryService } from './services/category/category.service'
import { DailyCountController } from './controllers/daily-count/daily-count.controller'

@Global()
@Module({
Expand Down Expand Up @@ -57,6 +58,7 @@ import { CategoryService } from './services/category/category.service'
ProxyConfigController,
CustomQueryController,
SystemController,
DailyCountController,
],
providers: [
AppService,
Expand Down
27 changes: 27 additions & 0 deletions src/controllers/daily-count/daily-count.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Controller } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { DailyCount, FindDailyCount } from '@/db/models/daily-count.entity'
import { AclCrud } from '@/decorators/acl-crud.decorator'
import { UseAdmin } from '@/decorators/use-admin.decorator'

@UseAdmin()
@AclCrud({
model: DailyCount,
config: {
option: {
title: '使用统计',
column: [],
},
},
routes: {
find: {
dto: FindDailyCount,
},
create: false,
update: false,
delete: false,
},
})
@ApiTags('daily-count')
@Controller('daily-count')
export class DailyCountController { }
5 changes: 5 additions & 0 deletions src/db/models/daily-count.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Length } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { Base } from './base.entity'
import { IsSafeNaturalNumber } from '@/decorators/is-safe-integer.decorator'
import { FindPlaceholderDto } from '@/models/find-placeholder.dto'

/**
* 每日计数:文章数/资源数/推送 webhook 数
Expand Down Expand Up @@ -45,3 +46,7 @@ export class DailyCount extends Base {
webhookLogCount: number
}

export class FindDailyCount extends FindPlaceholderDto<DailyCount> {
@ApiProperty({ type: () => [DailyCount] })
declare data: DailyCount[]
}
12 changes: 7 additions & 5 deletions src/services/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,13 @@ The content to be summarized is:`
}
const dailyCount = await this.dailyCountRepository.findOne({ where: { date } })
const fields = ['articleCount', 'resourceCount', 'webhookLogCount']
if (dailyCount && !isEqual(pickBy(newDailyCount, fields), pickBy(dailyCount, fields))) { // 如果存在且值不相等,则更新
await this.dailyCountRepository.save(this.dailyCountRepository.create({
...dailyCount,
...newDailyCount,
}))
if (dailyCount) { // 如果存在且值不相等,则更新
if (!isEqual(pickBy(newDailyCount, fields), pickBy(dailyCount, fields))) {
await this.dailyCountRepository.save(this.dailyCountRepository.create({
...dailyCount,
...newDailyCount,
}))
}
return null
}
return this.dailyCountRepository.save(this.dailyCountRepository.create(newDailyCount))
Expand Down
254 changes: 254 additions & 0 deletions test/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3948,6 +3948,181 @@
"system"
]
}
},
"/api/daily-count/config": {
"get": {
"operationId": "DailyCount_config",
"summary": "获取 config",
"parameters": [],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Config"
}
}
}
},
"201": {
"description": "创建成功"
},
"400": {
"description": "数据格式有误"
},
"401": {
"description": "没有权限访问"
},
"403": {
"description": "该用户没有权限访问"
},
"404": {
"description": "找不到要访问的接口"
},
"408": {
"description": "请求超时"
},
"409": {
"description": "请求时发生了冲突"
},
"429": {
"description": "请求次数超限"
},
"500": {
"description": "服务器内部错误"
},
"502": {
"description": "代理服务器错误"
}
},
"tags": [
"daily-count"
]
}
},
"/api/daily-count": {
"get": {
"operationId": "DailyCount_find",
"summary": "查找所有记录",
"parameters": [
{
"name": "query",
"required": false,
"in": "query",
"description": "Query options",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/FindDailyCount"
}
}
}
},
"201": {
"description": "创建成功"
},
"400": {
"description": "数据格式有误"
},
"401": {
"description": "没有权限访问"
},
"403": {
"description": "该用户没有权限访问"
},
"404": {
"description": "找不到要访问的接口"
},
"408": {
"description": "请求超时"
},
"409": {
"description": "请求时发生了冲突"
},
"429": {
"description": "请求次数超限"
},
"500": {
"description": "服务器内部错误"
},
"502": {
"description": "代理服务器错误"
}
},
"tags": [
"daily-count"
]
}
},
"/api/daily-count/{id}": {
"get": {
"operationId": "DailyCount_findOne",
"summary": "查找记录",
"parameters": [
{
"name": "id",
"required": true,
"in": "path",
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DailyCount"
}
}
}
},
"201": {
"description": "创建成功"
},
"400": {
"description": "数据格式有误"
},
"401": {
"description": "没有权限访问"
},
"403": {
"description": "该用户没有权限访问"
},
"404": {
"description": "找不到要访问的接口"
},
"408": {
"description": "请求超时"
},
"409": {
"description": "请求时发生了冲突"
},
"429": {
"description": "请求次数超限"
},
"500": {
"description": "服务器内部错误"
},
"502": {
"description": "代理服务器错误"
}
},
"tags": [
"daily-count"
]
}
}
},
"info": {
Expand Down Expand Up @@ -7363,6 +7538,85 @@
"osUptime",
"uptime"
]
},
"DailyCount": {
"type": "object",
"properties": {
"id": {
"type": "number",
"title": "ID",
"example": 1
},
"createdAt": {
"format": "date-time",
"type": "string",
"title": "创建时间",
"example": "2023-12-31T16:00:00.000Z"
},
"updatedAt": {
"format": "date-time",
"type": "string",
"title": "更新时间",
"example": "2023-12-31T16:00:00.000Z"
},
"date": {
"type": "string",
"minLength": 0,
"maxLength": 16,
"title": "日期",
"example": "2024-01-01"
},
"articleCount": {
"type": "number",
"title": "文章数量",
"example": 114
},
"resourceCount": {
"type": "number",
"title": "资源数量",
"example": 514
},
"webhookLogCount": {
"type": "number",
"title": "Webhook和通知日志数量",
"example": 233
}
},
"required": [
"id",
"createdAt",
"updatedAt",
"date",
"articleCount",
"resourceCount",
"webhookLogCount"
]
},
"FindDailyCount": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/DailyCount"
}
},
"total": {
"type": "number"
},
"lastPage": {
"type": "number"
},
"currentPage": {
"type": "number"
}
},
"required": [
"data",
"total",
"lastPage",
"currentPage"
]
}
}
}
Expand Down

0 comments on commit b8996b2

Please sign in to comment.