Compare commits

...

3 Commits

Author SHA1 Message Date
fff309f56b 修bug 2025-10-25 15:42:19 +08:00
d3700c8835 实现通知记录界面 2025-10-25 15:34:28 +08:00
ea44c9caea 增加新接口定义 2025-10-25 15:27:27 +08:00
7 changed files with 550 additions and 5 deletions

View File

@@ -970,6 +970,149 @@
}
}
},
"/api/v1/monitor/notifications": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "根据提供的过滤条件,分页获取通知列表",
"produces": [
"application/json"
],
"tags": [
"数据监控"
],
"summary": "批量查询通知",
"parameters": [
{
"type": "string",
"name": "end_time",
"in": "query"
},
{
"enum": [
7,
-1,
0,
1,
2,
3,
4,
5,
-1,
5,
6
],
"type": "integer",
"format": "int32",
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
"ErrorLevel",
"DPanicLevel",
"PanicLevel",
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel"
],
"name": "level",
"in": "query"
},
{
"enum": [
"邮件",
"企业微信",
"飞书",
"日志"
],
"type": "string",
"x-enum-varnames": [
"NotifierTypeSMTP",
"NotifierTypeWeChat",
"NotifierTypeLark",
"NotifierTypeLog"
],
"name": "notifier_type",
"in": "query"
},
{
"type": "string",
"name": "order_by",
"in": "query"
},
{
"type": "integer",
"name": "page",
"in": "query"
},
{
"type": "integer",
"name": "pageSize",
"in": "query"
},
{
"type": "string",
"name": "start_time",
"in": "query"
},
{
"enum": [
"发送成功",
"发送失败",
"已跳过"
],
"type": "string",
"x-enum-comments": {
"NotificationStatusFailed": "通知发送失败",
"NotificationStatusSkipped": "通知因某些原因被跳过(例如:用户未配置联系方式)",
"NotificationStatusSuccess": "通知已成功发送"
},
"x-enum-descriptions": [
"通知已成功发送",
"通知发送失败",
"通知因某些原因被跳过(例如:用户未配置联系方式)"
],
"x-enum-varnames": [
"NotificationStatusSuccess",
"NotificationStatusFailed",
"NotificationStatusSkipped"
],
"name": "status",
"in": "query"
},
{
"type": "integer",
"name": "user_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/dto.ListNotificationResponse"
}
}
}
]
}
}
}
}
},
"/api/v1/monitor/pending-collections": {
"get": {
"security": [
@@ -3918,6 +4061,64 @@
}
}
}
},
"/api/v1/users/{id}/notifications/test": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "为指定用户发送一条特定渠道的测试消息,以验证其配置是否正确。",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户管理"
],
"summary": "发送测试通知",
"parameters": [
{
"type": "integer",
"description": "用户ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "请求体",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.SendTestNotificationRequest"
}
}
],
"responses": {
"200": {
"description": "成功响应",
"schema": {
"allOf": [
{
"$ref": "#/definitions/controller.Response"
},
{
"type": "object",
"properties": {
"data": {
"type": "string"
}
}
}
]
}
}
}
}
}
},
"definitions": {
@@ -4426,6 +4627,20 @@
}
}
},
"dto.ListNotificationResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.NotificationDTO"
}
},
"pagination": {
"$ref": "#/definitions/dto.PaginationDTO"
}
}
},
"dto.ListPendingCollectionResponse": {
"type": "object",
"properties": {
@@ -4734,6 +4949,47 @@
}
}
},
"dto.NotificationDTO": {
"type": "object",
"properties": {
"alarm_timestamp": {
"type": "string"
},
"created_at": {
"type": "string"
},
"error_message": {
"type": "string"
},
"id": {
"type": "integer"
},
"level": {
"$ref": "#/definitions/zapcore.Level"
},
"message": {
"type": "string"
},
"notifier_type": {
"$ref": "#/definitions/notify.NotifierType"
},
"status": {
"$ref": "#/definitions/models.NotificationStatus"
},
"title": {
"type": "string"
},
"to_address": {
"type": "string"
},
"updated_at": {
"type": "string"
},
"user_id": {
"type": "integer"
}
}
},
"dto.PaginationDTO": {
"type": "object",
"properties": {
@@ -5586,6 +5842,22 @@
}
}
},
"dto.SendTestNotificationRequest": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"description": "Type 指定要测试的通知渠道",
"allOf": [
{
"$ref": "#/definitions/notify.NotifierType"
}
]
}
}
},
"dto.SensorDataDTO": {
"type": "object",
"properties": {
@@ -6196,6 +6468,29 @@
"ReasonTypeHealthCare"
]
},
"models.NotificationStatus": {
"type": "string",
"enum": [
"发送成功",
"发送失败",
"已跳过"
],
"x-enum-comments": {
"NotificationStatusFailed": "通知发送失败",
"NotificationStatusSkipped": "通知因某些原因被跳过(例如:用户未配置联系方式)",
"NotificationStatusSuccess": "通知已成功发送"
},
"x-enum-descriptions": [
"通知已成功发送",
"通知发送失败",
"通知因某些原因被跳过(例如:用户未配置联系方式)"
],
"x-enum-varnames": [
"NotificationStatusSuccess",
"NotificationStatusFailed",
"NotificationStatusSkipped"
]
},
"models.PenStatus": {
"type": "string",
"enum": [
@@ -6525,6 +6820,51 @@
"$ref": "#/definitions/models.SensorType"
}
}
},
"notify.NotifierType": {
"type": "string",
"enum": [
"邮件",
"企业微信",
"飞书",
"日志"
],
"x-enum-varnames": [
"NotifierTypeSMTP",
"NotifierTypeWeChat",
"NotifierTypeLark",
"NotifierTypeLog"
]
},
"zapcore.Level": {
"type": "integer",
"format": "int32",
"enum": [
7,
-1,
0,
1,
2,
3,
4,
5,
-1,
5,
6
],
"x-enum-varnames": [
"_numLevels",
"DebugLevel",
"InfoLevel",
"WarnLevel",
"ErrorLevel",
"DPanicLevel",
"PanicLevel",
"FatalLevel",
"_minLevel",
"_maxLevel",
"InvalidLevel"
]
}
},
"securityDefinitions": {

View File

@@ -121,6 +121,49 @@ import http from '../utils/http';
* @property {number} [operator_id]
*/
/**
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
*/
/**
* @typedef {('发送成功'|'发送失败'|'已跳过')} NotificationStatus
*/
/**
* @typedef {object} NotificationDTO
* @property {number} id
* @property {number} user_id
* @property {NotifierType} notifier_type
* @property {string} to_address
* @property {string} title
* @property {string} message
* @property {number} level - 日志级别, 见 ZapcoreLevel 枚举
* @property {string} alarm_timestamp
* @property {NotificationStatus} status
* @property {string} error_message
* @property {string} created_at
* @property {string} updated_at
*/
/**
* @typedef {object} ListNotificationResponse
* @property {Array<NotificationDTO>} list
* @property {PaginationDTO} pagination
*/
/**
* @typedef {object} NotificationsParams
* @property {number} [page]
* @property {number} [pageSize]
* @property {string} [order_by]
* @property {string} [start_time]
* @property {string} [end_time]
* @property {number} [level] - 日志级别, 见 ZapcoreLevel 枚举
* @property {NotifierType} [notifier_type]
* @property {NotificationStatus} [status]
* @property {number} [user_id]
*/
/**
* @typedef {('等待中'|'已完成'|'已超时')} PendingCollectionStatus
*/
@@ -606,6 +649,22 @@ import http from '../utils/http';
* @property {number} [operator_id]
*/
// --- Enums ---
/**
* 日志级别, 对应后端的 zapcore.Level
* @enum {number}
*/
export const ZapcoreLevel = {
Debug: -1,
Info: 0,
Warn: 1,
Error: 2,
DPanic: 3,
Panic: 4,
Fatal: 5,
Invalid: 6,
};
// --- Functions ---
@@ -647,6 +706,16 @@ export const getMedicationLogs = async (params) => {
return processResponse(responseData);
};
/**
* 批量查询通知
* @param {NotificationsParams} params - 查询参数
* @returns {Promise<{list: Array<NotificationDTO>, total: number}>}
*/
export const getNotifications = async (params) => {
const responseData = await http.get('/api/v1/monitor/notifications', { params });
return processResponse(responseData);
};
/**
* 获取待采集请求列表
* @param {PendingCollectionsParams} params - 查询参数

View File

@@ -71,6 +71,15 @@ import http from '../utils/http';
* @property {string} [username]
*/
/**
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
*/
/**
* @typedef {object} SendTestNotificationRequest
* @property {NotifierType} type - Type 指定要测试的通知渠道
*/
/**
* 创建一个新用户
* @param {CreateUserRequest} userData - 用户信息
@@ -99,8 +108,19 @@ const getUserHistory = (id, params) => {
return http.get(`/api/v1/users/${id}/history`, { params });
};
/**
* 发送测试通知
* @param {number} id - 用户ID
* @param {SendTestNotificationRequest} data - 请求体
* @returns {Promise<string>}
*/
const sendTestNotification = (id, data) => {
return http.post(`/api/v1/users/${id}/notifications/test`, data);
};
export const UserApi = {
createUser,
login,
getUserHistory,
sendTestNotification,
};

View File

@@ -77,6 +77,10 @@
<el-icon><FirstAidKit /></el-icon>
<template #title>用药记录</template>
</el-menu-item>
<el-menu-item index="/monitor/notifications">
<el-icon><Bell /></el-icon>
<template #title>通知记录</template>
</el-menu-item>
<el-menu-item index="/monitor/pending-collections">
<el-icon><Clock /></el-icon>
<template #title>待采集请求</template>
@@ -183,14 +187,14 @@ import { ref, computed, onMounted, onUnmounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import {
House, Monitor, Calendar, ArrowDown, Menu, Fold, Expand, Setting, Tickets, DataAnalysis, Document, Food,
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management, Bell
} from '@element-plus/icons-vue';
export default {
name: 'MainLayout',
components: {
House, Monitor, Calendar, ArrowDown, Menu, Fold, Expand, Setting, Tickets, DataAnalysis, Document, Food,
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management, Bell
},
setup() {
const route = useRoute();
@@ -233,6 +237,7 @@ export default {
'/monitor/device-command-logs': '设备命令日志',
'/monitor/feed-usage-records': '饲料使用记录',
'/monitor/medication-logs': '用药记录',
'/monitor/notifications': '通知记录',
'/monitor/pending-collections': '待采集请求',
'/monitor/pig-batch-logs': '猪批次日志',
'/monitor/pig-purchases': '猪只采购记录',

View File

@@ -17,6 +17,7 @@ import PigBatchManagementView from './views/pms/PigBatchManagementView.vue'; //
import DeviceCommandLogView from './views/monitor/DeviceCommandLogView.vue';
import FeedUsageRecordsView from './views/monitor/FeedUsageRecordsView.vue';
import MedicationLogsView from './views/monitor/MedicationLogsView.vue';
import NotificationLogView from './views/monitor/NotificationLogView.vue';
import PendingCollectionsView from './views/monitor/PendingCollectionsView.vue';
import PigBatchLogsView from './views/monitor/PigBatchLogsView.vue';
import PigPurchasesView from './views/monitor/PigPurchasesView.vue';
@@ -50,6 +51,7 @@ const routes = [
{path: '/monitor/device-command-logs', component: DeviceCommandLogView, meta: {requiresAuth: true}},
{path: '/monitor/feed-usage-records', component: FeedUsageRecordsView, meta: {requiresAuth: true}},
{path: '/monitor/medication-logs', component: MedicationLogsView, meta: {requiresAuth: true}},
{path: '/monitor/notifications', component: NotificationLogView, meta: {requiresAuth: true}},
{path: '/monitor/pending-collections', component: PendingCollectionsView, meta: {requiresAuth: true}},
{path: '/monitor/pig-batch-logs', component: PigBatchLogsView, meta: {requiresAuth: true}},
{path: '/monitor/pig-purchases', component: PigPurchasesView, meta: {requiresAuth: true}},

View File

@@ -53,9 +53,7 @@ http.interceptors.response.use(
if (error.response.status === 401) {
// 清除token并重定向到登录页
localStorage.removeItem('jwt_token');
// 这里需要访问router但http.js是纯工具文件不应直接依赖Vue Router实例
// 可以在main.js的全局错误处理或组件中处理401错误
// 例如window.location.href = '/login';
window.location.href = '/login';
}
} else if (error.request) {
// 请求发出但没有收到响应

View File

@@ -0,0 +1,111 @@
<template>
<div class="notification-log-view">
<GenericMonitorList
:fetchData="fetchNotifications"
:columnsConfig="notificationLogColumns"
/>
</div>
</template>
<script setup>
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getNotifications, ZapcoreLevel } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';
// 适配通用组件的 fetchData prop
const fetchNotifications = async (params) => {
return await getNotifications(params);
};
// 定义表格的列
const notificationLogColumns = [
{
title: '用户ID',
dataIndex: 'user_id',
key: 'user_id',
sorter: true,
filterType: 'number',
minWidth: 100,
},
{
title: '通知渠道',
dataIndex: 'notifier_type',
key: 'notifier_type',
filterType: 'select',
filterOptions: [
{ value: '邮件', text: '邮件' },
{ value: '企业微信', text: '企业微信' },
{ value: '飞书', text: '飞书' },
{ value: '日志', text: '日志' },
],
minWidth: 120,
},
{
title: '目标地址',
dataIndex: 'to_address',
key: 'to_address',
minWidth: 200,
},
{
title: '标题',
dataIndex: 'title',
key: 'title',
minWidth: 200,
},
{
title: '消息',
dataIndex: 'message',
key: 'message',
minWidth: 300,
},
{
title: '日志级别',
dataIndex: 'level',
key: 'level',
sorter: true,
filterType: 'select',
filterOptions: Object.entries(ZapcoreLevel).map(([text, value]) => ({ value, text })),
minWidth: 110,
},
{
title: '告警时间',
dataIndex: 'alarm_timestamp',
key: 'alarm_timestamp',
sorter: true,
formatter: (row, column, cellValue) => formatRFC3339(cellValue),
minWidth: 180,
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
filterType: 'select',
filterOptions: [
{ value: '发送成功', text: '发送成功' },
{ value: '发送失败', text: '发送失败' },
{ value: '已跳过', text: '已跳过' },
],
minWidth: 120,
},
{
title: '错误信息',
dataIndex: 'error_message',
key: 'error_message',
minWidth: 200,
},
{
title: '创建时间',
dataIndex: 'created_at',
key: 'created_at',
sorter: true,
formatter: (row, column, cellValue) => formatRFC3339(cellValue),
minWidth: 180,
},
];
</script>
<style scoped>
.notification-log-view {
/* 视图容器样式 */
}
</style>