chroe: add send message caller ip

This commit is contained in:
engigu
2024-01-22 14:17:33 +08:00
parent ed292b09ed
commit 7040031253
4 changed files with 25 additions and 11 deletions
+6 -4
View File
@@ -6,10 +6,11 @@ import (
)
type SendTasksLogs struct {
ID int `gorm:"primary_key" json:"id" `
TaskID string `json:"task_id" gorm:"type:varchar(12) comment '任务id';default:'';index:task_id"`
Log string `json:"log" gorm:"type:text comment '日志';"`
Status int `json:"status" gorm:"type:int comment '状态';default:0;"`
ID int `gorm:"primary_key" json:"id" `
TaskID string `json:"task_id" gorm:"type:varchar(12) comment '任务id';default:'';index:task_id"`
Log string `json:"log" gorm:"type:text comment '日志';"`
Status int `json:"status" gorm:"type:int comment '状态';default:0;"`
CallerIp string `json:"caller_ip" gorm:"type:varchar(256) comment '发送者的ip';default:'';"`
CreatedOn util.Time `json:"created_on" gorm:"type:timestamp comment '创建时间';default:current_timestamp;"`
ModifiedOn util.Time `json:"modified_on" gorm:"type:timestamp comment '更新时间';"`
@@ -32,6 +33,7 @@ type LogsResult struct {
ModifiedOn util.Time `json:"modified_on"`
TaskName string `json:"task_name"`
Status int `json:"status"`
CallerIp string `json:"caller_ip"`
}
// GetSendLogs 获取所有日志记录
+1
View File
@@ -36,6 +36,7 @@ func DoSendMassage(c *gin.Context) {
Text: req.Text,
HTML: req.HTML,
MarkDown: req.MarkDown,
CallerIp: c.ClientIP(),
}
if req.Mode == "sync" {
// 同步发送
+5 -3
View File
@@ -32,6 +32,7 @@ type SendMessageService struct {
Text string
HTML string
MarkDown string
CallerIp string
Status int
LogOutput []string
@@ -190,9 +191,10 @@ func (sm *SendMessageService) RecordSendLog() {
return
}
log := models.SendTasksLogs{
Log: strings.Join(sm.LogOutput, "\n"),
TaskID: sm.TaskID,
Status: sm.Status,
Log: strings.Join(sm.LogOutput, "\n"),
TaskID: sm.TaskID,
Status: sm.Status,
CallerIp: sm.CallerIp,
}
err := log.Add()
if err != nil {
+13 -4
View File
@@ -22,7 +22,7 @@
<template #default="scope">
<el-tooltip enterable placement="top">
<template #content>
<div v-html="TransHtml(scope.row.log)"></div>
<div v-html="formatLogDisplayHtml(scope)"></div>
</template>
<span class="log-overflow">{{ scope.row.log }}</span>
</el-tooltip>
@@ -32,7 +32,7 @@
<el-table-column label="详情/状态" prop="status" width="120px" fixed="right">
<template #default="scope">
<el-button link size="small" style="margin-right: 10px;" type="primary"
@click="drawer = true; logText = scope.row.log">日志</el-button>
@click="drawer = true; logText = formatLogDisplayHtml(scope)">日志</el-button>
<el-tag v-if="scope.row.status == 0" type="danger">失败</el-tag>
<el-tag v-if="scope.row.status == 1" type="success">成功</el-tag>
</template>
@@ -41,7 +41,7 @@
</div>
<el-drawer v-model="drawer" :with-header="false">
<el-text v-html="TransHtml(logText)" size="small"></el-text>
<el-text v-html="logText" size="small"></el-text>
</el-drawer>
<div class="pagination-block">
@@ -97,6 +97,15 @@ export default {
return ''
}
const formatLogDisplayHtml = (scope) => {
let log = TransHtml(scope.row.log);
log += '<br />\n';
if (scope.row.caller_ip) {
log += `调用来源IP${scope.row.caller_ip}`;
};
return log;
}
const handPageChange = async (pageNum) => {
state.currPage = pageNum;
await queryListData(pageNum, state.pageSize);
@@ -145,7 +154,7 @@ export default {
return {
...toRefs(state), handleDelete, TransHtml, clickFreshSwitch,
rowStyle, handPageChange, filterFunc, copyToClipboard
rowStyle, handPageChange, filterFunc, copyToClipboard, formatLogDisplayHtml
};
}
}