Merge pull request #699 from detecti1/feat/show-log-with-channel-name
Feat: 日志查询增加渠道名称显示
This commit is contained in:
@@ -27,6 +27,7 @@ type Log struct {
|
|||||||
UseTime int `json:"use_time" gorm:"default:0"`
|
UseTime int `json:"use_time" gorm:"default:0"`
|
||||||
IsStream bool `json:"is_stream" gorm:"default:false"`
|
IsStream bool `json:"is_stream" gorm:"default:false"`
|
||||||
ChannelId int `json:"channel" gorm:"index"`
|
ChannelId int `json:"channel" gorm:"index"`
|
||||||
|
ChannelName string `json:"channel_name" gorm:"->"`
|
||||||
TokenId int `json:"token_id" gorm:"default:0;index"`
|
TokenId int `json:"token_id" gorm:"default:0;index"`
|
||||||
Group string `json:"group" gorm:"index"`
|
Group string `json:"group" gorm:"index"`
|
||||||
Other string `json:"other"`
|
Other string `json:"other"`
|
||||||
@@ -130,6 +131,10 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
|
|||||||
} else {
|
} else {
|
||||||
tx = LOG_DB.Where("type = ?", logType)
|
tx = LOG_DB.Where("type = ?", logType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx = tx.Joins("LEFT JOIN channels ON logs.channel_id = channels.id")
|
||||||
|
tx = tx.Select("logs.*, channels.name as channel_name")
|
||||||
|
|
||||||
if modelName != "" {
|
if modelName != "" {
|
||||||
tx = tx.Where("model_name like ?", modelName)
|
tx = tx.Where("model_name like ?", modelName)
|
||||||
}
|
}
|
||||||
@@ -169,6 +174,10 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
|
|||||||
} else {
|
} else {
|
||||||
tx = LOG_DB.Where("user_id = ? and type = ?", userId, logType)
|
tx = LOG_DB.Where("user_id = ? and type = ?", userId, logType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx = tx.Joins("LEFT JOIN channels ON logs.channel_id = channels.id")
|
||||||
|
tx = tx.Select("logs.*, channels.name as channel_name")
|
||||||
|
|
||||||
if modelName != "" {
|
if modelName != "" {
|
||||||
tx = tx.Where("model_name like ?", modelName)
|
tx = tx.Where("model_name like ?", modelName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,13 +157,15 @@ const LogsTable = () => {
|
|||||||
record.type === 0 || record.type === 2 ? (
|
record.type === 0 || record.type === 2 ? (
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
<Tag
|
<Tooltip content={record.channel_name || '[未知]'}>
|
||||||
color={colors[parseInt(text) % colors.length]}
|
<Tag
|
||||||
size='large'
|
color={colors[parseInt(text) % colors.length]}
|
||||||
>
|
size='large'
|
||||||
{' '}
|
>
|
||||||
{text}{' '}
|
{' '}
|
||||||
</Tag>
|
{text}{' '}
|
||||||
|
</Tag>
|
||||||
|
</Tooltip>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -234,7 +236,12 @@ const LogsTable = () => {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let other = JSON.parse(record.other);
|
let other = null;
|
||||||
|
try {
|
||||||
|
other = JSON.parse(record.other);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to parse record.other: "${record.other}".`, e);
|
||||||
|
}
|
||||||
if (other === null) {
|
if (other === null) {
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
@@ -543,6 +550,12 @@ const LogsTable = () => {
|
|||||||
// key: '渠道重试',
|
// key: '渠道重试',
|
||||||
// value: content,
|
// value: content,
|
||||||
// })
|
// })
|
||||||
|
}
|
||||||
|
if (isAdminUser && (logs[i].type === 0 || logs[i].type === 2)) {
|
||||||
|
expandDataLocal.push({
|
||||||
|
key: t('渠道信息'),
|
||||||
|
value: `${logs[i].channel} - ${logs[i].channel_name || '[未知]'}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (other?.ws || other?.audio) {
|
if (other?.ws || other?.audio) {
|
||||||
expandDataLocal.push({
|
expandDataLocal.push({
|
||||||
@@ -595,13 +608,12 @@ const LogsTable = () => {
|
|||||||
key: t('计费过程'),
|
key: t('计费过程'),
|
||||||
value: content,
|
value: content,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
expandDatesLocal[logs[i].key] = expandDataLocal;
|
expandDatesLocal[logs[i].key] = expandDataLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
setExpandData(expandDatesLocal);
|
setExpandData(expandDatesLocal);
|
||||||
|
|
||||||
setLogs(logs);
|
setLogs(logs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user