🔖 chore: logs list displays channel name.
This commit is contained in:
parent
5ae57435ba
commit
be874c330f
20
model/log.go
20
model/log.go
@ -20,8 +20,10 @@ type Log struct {
|
|||||||
Quota int `json:"quota" gorm:"default:0"`
|
Quota int `json:"quota" gorm:"default:0"`
|
||||||
PromptTokens int `json:"prompt_tokens" gorm:"default:0"`
|
PromptTokens int `json:"prompt_tokens" gorm:"default:0"`
|
||||||
CompletionTokens int `json:"completion_tokens" gorm:"default:0"`
|
CompletionTokens int `json:"completion_tokens" gorm:"default:0"`
|
||||||
ChannelId int `json:"channel" gorm:"index"`
|
ChannelId int `json:"channel_id" gorm:"index"`
|
||||||
RequestTime int `json:"request_time" gorm:"default:0"`
|
RequestTime int `json:"request_time" gorm:"default:0"`
|
||||||
|
|
||||||
|
Channel *Channel `json:"channel" gorm:"foreignKey:Id;references:ChannelId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -82,7 +84,7 @@ type LogsListParams struct {
|
|||||||
ModelName string `form:"model_name"`
|
ModelName string `form:"model_name"`
|
||||||
Username string `form:"username"`
|
Username string `form:"username"`
|
||||||
TokenName string `form:"token_name"`
|
TokenName string `form:"token_name"`
|
||||||
Channel int `form:"channel"`
|
ChannelId int `form:"channel_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var allowedLogsOrderFields = map[string]bool{
|
var allowedLogsOrderFields = map[string]bool{
|
||||||
@ -98,10 +100,12 @@ func GetLogsList(params *LogsListParams) (*DataResult[Log], error) {
|
|||||||
var tx *gorm.DB
|
var tx *gorm.DB
|
||||||
var logs []*Log
|
var logs []*Log
|
||||||
|
|
||||||
if params.LogType == LogTypeUnknown {
|
tx = DB.Preload("Channel", func(db *gorm.DB) *gorm.DB {
|
||||||
tx = DB
|
return db.Select("id, name")
|
||||||
} else {
|
})
|
||||||
tx = DB.Where("type = ?", params.LogType)
|
|
||||||
|
if params.LogType != LogTypeUnknown {
|
||||||
|
tx = tx.Where("type = ?", params.LogType)
|
||||||
}
|
}
|
||||||
if params.ModelName != "" {
|
if params.ModelName != "" {
|
||||||
tx = tx.Where("model_name = ?", params.ModelName)
|
tx = tx.Where("model_name = ?", params.ModelName)
|
||||||
@ -118,8 +122,8 @@ func GetLogsList(params *LogsListParams) (*DataResult[Log], error) {
|
|||||||
if params.EndTimestamp != 0 {
|
if params.EndTimestamp != 0 {
|
||||||
tx = tx.Where("created_at <= ?", params.EndTimestamp)
|
tx = tx.Where("created_at <= ?", params.EndTimestamp)
|
||||||
}
|
}
|
||||||
if params.Channel != 0 {
|
if params.ChannelId != 0 {
|
||||||
tx = tx.Where("channel_id = ?", params.Channel)
|
tx = tx.Where("channel_id = ?", params.ChannelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return PaginateAndOrder[Log](tx, ¶ms.PaginationParams, &logs, allowedLogsOrderFields)
|
return PaginateAndOrder[Log](tx, ¶ms.PaginationParams, &logs, allowedLogsOrderFields)
|
||||||
|
@ -70,7 +70,7 @@ export default function LogTableRow({ item, userIsAdmin }) {
|
|||||||
<TableRow tabIndex={item.id}>
|
<TableRow tabIndex={item.id}>
|
||||||
<TableCell>{timestamp2string(item.created_at)}</TableCell>
|
<TableCell>{timestamp2string(item.created_at)}</TableCell>
|
||||||
|
|
||||||
{userIsAdmin && <TableCell>{item.channel || ''}</TableCell>}
|
{userIsAdmin && <TableCell>{(item.channel_id || '') + '(' + (item.channel?.name || '未知') + ')'}</TableCell>}
|
||||||
{userIsAdmin && (
|
{userIsAdmin && (
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Label color="default" variant="outlined">
|
<Label color="default" variant="outlined">
|
||||||
|
@ -133,15 +133,15 @@ export default function TableToolBar({ filterName, handleFilterName, userIsAdmin
|
|||||||
{userIsAdmin && (
|
{userIsAdmin && (
|
||||||
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={{ xs: 3, sm: 2, md: 4 }} padding={'24px'}>
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={{ xs: 3, sm: 2, md: 4 }} padding={'24px'}>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<InputLabel htmlFor="channel-channel-label">渠道ID</InputLabel>
|
<InputLabel htmlFor="channel-channel_id-label">渠道ID</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
id="channel"
|
id="channel_id"
|
||||||
name="channel"
|
name="channel_id"
|
||||||
sx={{
|
sx={{
|
||||||
minWidth: '100%'
|
minWidth: '100%'
|
||||||
}}
|
}}
|
||||||
label="渠道ID"
|
label="渠道ID"
|
||||||
value={filterName.channel}
|
value={filterName.channel_id}
|
||||||
onChange={handleFilterName}
|
onChange={handleFilterName}
|
||||||
placeholder="渠道ID"
|
placeholder="渠道ID"
|
||||||
startAdornment={
|
startAdornment={
|
||||||
|
@ -29,7 +29,7 @@ export default function Log() {
|
|||||||
start_timestamp: 0,
|
start_timestamp: 0,
|
||||||
end_timestamp: dayjs().unix() + 3600,
|
end_timestamp: dayjs().unix() + 3600,
|
||||||
log_type: 0,
|
log_type: 0,
|
||||||
channel: ''
|
channel_id: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
@ -82,7 +82,7 @@ export default function Log() {
|
|||||||
const url = userIsAdmin ? '/api/log/' : '/api/log/self/';
|
const url = userIsAdmin ? '/api/log/' : '/api/log/self/';
|
||||||
if (!userIsAdmin) {
|
if (!userIsAdmin) {
|
||||||
delete keyword.username;
|
delete keyword.username;
|
||||||
delete keyword.channel;
|
delete keyword.channel_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await API.get(url, {
|
const res = await API.get(url, {
|
||||||
|
Loading…
Reference in New Issue
Block a user