docs:重构文档结构并添加新内容

- 新增工具箱分类,移动相关文档
- 添加 GKD(搞快点)软件推荐文章
- 更新工作日志和常用代码示例
-优化网站配置和样式
This commit is contained in:
LiuMangMang 2025-07-25 13:50:48 +08:00
parent 704bef9502
commit 375218728e
21 changed files with 535 additions and 243 deletions

View File

@ -1,15 +1,20 @@
import {navbar} from "vuepress-theme-hope";
import { navbar } from "vuepress-theme-hope";
//VuePress Theme Hope主题的博客
export default navbar([
"/",
{
text: '编程',
text: "编程",
icon: "mdi:laptop",
link: '/programming/'
link: "/programming/",
},
{
text: '工作',
text: "工作",
icon: "mdi:laptop",
link: '/work/'
link: "/work/",
},
{
text: "工具箱",
icon: "mdi:tools", // 你可以换成任何支持的 mdi 图标
link: "/tools/",
},
]);

View File

@ -1,5 +1,5 @@
import { sidebar } from "vuepress-theme-hope";
//VuePress Theme Hope主题的博客
export default sidebar({
"/programming/": [
{
@ -71,5 +71,13 @@ export default sidebar({
icon: "mdi:briefcase-variant", // 更通用的文件图标
link: "/work/常用.md",
}
],
"/tools/": [
{
text: "工具箱",
icon: "mdi:toolbox",
collapsible: true,
children: "structure",
},
]
});

View File

@ -2,237 +2,115 @@ import {hopeTheme} from "vuepress-theme-hope";
import navbar from "./navbar.js";
import sidebar from "./sidebar.js";
//VuePress Theme Hope主题的博客
export default hopeTheme(
{
hostname: "http://10.6.212.39:8080",
author: {
name: "LiuMangMang",
},
license: "CC 4.0",
// 导航栏
navbar,
// 侧边栏
sidebar,
logo: "logo/transparentLogo.png",
logoDark: "logo/transparentLogo.png",
repo: "vuepress-theme-hope/vuepress-theme-hope",
docsDir: "src",
// 页脚
footer: "Powered by VuePress | Theme by Hope",
displayFooter: true,
lastUpdated: false,
darkmode: "toggle",
// 博客相关
blog: {
description: "一个后端开发者",
intro: "/intro.html"
/* medias: {
Baidu: "https://example.com",
BiliBili: "https://example.com",
Bitbucket: "https://example.com",
Dingding: "https://example.com",
Discord: "https://example.com",
Dribbble: "https://example.com",
Email: "mailto:info@example.com",
Evernote: "https://example.com",
Facebook: "https://example.com",
Flipboard: "https://example.com",
Gitee: "https://example.com",
GitHub: "https://example.com",
Gitlab: "https://example.com",
Gmail: "mailto:info@example.com",
Instagram: "https://example.com",
Lark: "https://example.com",
Lines: "https://example.com",
Linkedin: "https://example.com",
Pinterest: "https://example.com",
Pocket: "https://example.com",
QQ: "https://example.com",
Qzone: "https://example.com",
Reddit: "https://example.com",
Rss: "https://example.com",
Steam: "https://example.com",
Twitter: "https://example.com",
Wechat: "https://example.com",
Weibo: "https://example.com",
Whatsapp: "https://example.com",
Youtube: "https://example.com",
Zhihu: "https://example.com",
VuePressThemeHope: {
icon: "https://theme-hope-assets.vuejs.press/logo.svg",
link: "https://theme-hope.vuejs.press",
},
},*/
},
// 网站域名配置用于SEO和RSS等功能
hostname: "http://10.6.212.88:8080",
// 加密配置
encrypt: {
config: {
"/demo/encrypt.html": {
hint: "Password: 1234",
password: "1234",
},
// 作者信息
author: {
name: "LiuMangMang",
},
},
// 多语言配置
metaLocales: {
editLink: "在 GitHub 上编辑此页",
},
// 网站许可证
license: "CC 4.0",
// 如果想要实时查看任何改变,启用它。注: 这对更新性能有很大负面影响
// hotReload: true,
// 导航栏配置(从 navbar.js 文件导入)
navbar,
// 此处开启了很多功能用于演示,你应仅保留用到的功能。
markdown: {
align: true,
attrs: true,
codeTabs: true,
component: true,
demo: true,
figure: true,
gfm: true,
imgLazyload: true,
imgSize: true,
include: true,
mark: true,
plantuml: true,
spoiler: true,
stylize: [
{
matcher: "Recommended",
replacer: ({tag}) => {
if (tag === "em")
return {
tag: "Badge",
attrs: {type: "tip"},
content: "Recommended",
};
// 侧边栏配置(从 sidebar.js 文件导入)
sidebar,
// 网站logo设置
logo: "logo/transparentLogo.png", // 亮色模式下的logo
logoDark: "logo/transparentLogo.png", // 暗色模式下的logo
// 支持简写仓库名称,会解析到 GitHub 上,同时也可以是一个完整的 URL
repo: "http://43.138.173.153:8804/mangmang/blog",
// 默认从 `repo` 内容中推断为以下之一:
// "GitHub" / "GitLab" / "Gitee" / "Bitbucket" / "Source"
repoLabel: "Gitea",
repoDisplay: true,
// 是否显示编辑链接
editLink: true,
// 文档源码目录
docsDir: "src",
// 页脚配置
footer: "Powered by VuePress | Theme by Hope",
displayFooter: true,
// 是否显示最后更新时间
lastUpdated: false,
// 深色模式配置toggle表示用户可以切换
darkmode: "toggle",
// 博客相关配置
blog: {
description: "一个后端开发者",
intro: "/intro.html"
},
// Markdown增强功能配置
markdown: {
align: true, // 启用文本对齐
attrs: true, // 启用属性支持
codeTabs: true, // 启用代码选项卡
component: true, // 启用组件支持
demo: true, // 启用演示支持
figure: true, // 启用图片描述
gfm: true, // 启用GitHub风格的Markdown
imgLazyload: true, // 启用图片懒加载
imgSize: true, // 启用图片尺寸设置
include: true, // 启用文件包含
mark: true, // 启用标记高亮
plantuml: true, // 启用PlantUML图表
spoiler: true, // 启用剧透标记
// 文本样式化配置
stylize: [
{
matcher: "Recommended",
replacer: ({tag}) => {
if (tag === "em")
return {
tag: "Badge",
attrs: {type: "tip"},
content: "Recommended",
};
},
},
],
sub: true, // 启用下标
sup: true, // 启用上标
tabs: true, // 启用选项卡
tasklist: true, // 启用任务列表
vPre: true, // 启用v-pre支持
},
// 插件配置
plugins: {
// 启用博客功能
blog: true,
// 组件配置
components: {
components: ["Badge", "VPCard"],
},
],
sub: true,
sup: true,
tabs: true,
tasklist: true,
vPre: true,
// 取消注释它们如果你需要 TeX 支持
// math: {
// // 启用前安装 katex
// type: "katex",
// // 或者安装 mathjax-full
// type: "mathjax",
// },
// 如果你需要幻灯片,安装 @vuepress/plugin-revealjs 并取消下方注释
// revealjs: {
// plugins: ["highlight", "math", "search", "notes", "zoom"],
// },
// 在启用之前安装 chart.js
// chartjs: true,
// insert component easily
// 在启用之前安装 echarts
// echarts: true,
// 在启用之前安装 flowchart.ts
// flowchart: true,
// 在启用之前安装 mermaid
// mermaid: true,
// playground: {
// presets: ["ts", "vue"],
// },
// 在启用之前安装 @vue/repl
// vuePlayground: true,
// 在启用之前安装 sandpack-vue3
// sandpack: true,
},
// 在这里配置主题提供的插件
plugins: {
blog: true,
// 启用之前需安装 @waline/client
// 警告: 这是一个仅供演示的测试服务,在生产环境中请自行部署并使用自己的服务!
// comment: {
// provider: "Waline",
// serverURL: "https://waline-comment.vuejs.press",
// },
components: {
components: ["Badge", "VPCard"],
// 图标配置
icon: {
prefix: "fa6-solid:",
},
},
icon: {
prefix: "fa6-solid:",
},
// 如果你需要 PWA。安装 @vuepress/plugin-pwa 并取消下方注释
// pwa: {
// favicon: "/favicon.ico",
// cacheHTML: true,
// cacheImage: true,
// appendBase: true,
// apple: {
// icon: "/assets/icon/apple-icon-152.png",
// statusBarColor: "black",
// },
// msTile: {
// image: "/assets/icon/ms-icon-144.png",
// color: "#ffffff",
// },
// manifest: {
// icons: [
// {
// src: "/assets/icon/chrome-mask-512.png",
// sizes: "512x512",
// purpose: "maskable",
// type: "image/png",
// },
// {
// src: "/assets/icon/chrome-mask-192.png",
// sizes: "192x192",
// purpose: "maskable",
// type: "image/png",
// },
// {
// src: "/assets/icon/chrome-512.png",
// sizes: "512x512",
// type: "image/png",
// },
// {
// src: "/assets/icon/chrome-192.png",
// sizes: "192x192",
// type: "image/png",
// },
// ],
// shortcuts: [
// {
// name: "Demo",
// short_name: "Demo",
// url: "/demo/",
// icons: [
// {
// src: "/assets/icon/guide-maskable.png",
// sizes: "192x192",
// purpose: "maskable",
// type: "image/png",
// },
// ],
// },
// ],
// },
// },
},
},
{
custom: true // ✅ 添加这一行
});
// 自定义主题配置
custom: true
}
);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

45
src/tools/README.md Normal file
View File

@ -0,0 +1,45 @@
---
title: 导航页
icon: toolbox
index: true
order: 1
category:
- 实用工具
tag:
- 工具
- 效率
---
# 🧰 工具箱
这里收集了开发和工作中常用的工具配置、使用技巧和实用指南,涵盖远程工具、构建工具、开发环境、浏览器相关等。
## 📚 工具文档列表
- [Gitee SSH 配置](./gitee-ssh.md)
- [Maven 安装与配置](./Maven.md)
- [MobaXterm 远程终端](./MobaXterm.md)
- [RustDesk 自建远程桌面服务器](./RustDesk自建远程桌面服务器.md)
- [Scoop 包管理器](./Scoop.md)
- [Spring Boot JAR 瘦身与加密](./Spring%20Boot%20JAR%20瘦身与加密.md)
- [WebSocket 和 HTTP 关系](./WebSocket和HTTP关系.md)
- [WSL2 使用指南](./WSL2.md)
- [XJar 加密工具](./XJar.md)
- [浏览器常用技巧](./浏览器.md)
## 🧭 快速导航
```card
title: 推荐工具
icon: rocket
desc: 常用开发运维工具的配置与技巧
items:
- text: Gitee SSH
icon: link
link: ./gitee-ssh.md
- text: RustDesk 自建
icon: desktop
link: ./RustDesk自建远程桌面服务器.md
- text: Scoop 包管理器
icon: download
link: ./Scoop.md

View File

@ -1,6 +1,6 @@
---
icon: tabler:device-desktop-analytics
date: 2025-07.md-04
date: 2025-07-04
category:
- 实用工具
tag:

View File

@ -94,7 +94,7 @@ WebSocket与HTTP是相辅相成的关系而非替代关系。WebSocket通过H
## 5. 案例(服务端)
### 5.1 项目结构
![1746684922168.png](assert/1746684922168.png)
![1746684922168.png](./assets/1746684922168.png)
### 5.2 依赖配置
```xml

View File

@ -83,7 +83,7 @@ ssh-ed25519 AAAA***5B Gitee SSH Key
5. 输入Gitee账户密码进行验证
6. 点击「添加」按钮完成操作
![添加账户SSH公钥](./assert/sshkeys_create-8409f453e6780ca1a8db3ce33c74240b.png "添加用户SSH公钥")
![添加账户SSH公钥](./assets/sshkeys_create-8409f453e6780ca1a8db3ce33c74240b.png "添加用户SSH公钥")
### 4. 验证SSH连接
@ -109,9 +109,9 @@ Hi USERNAME! You've successfully authenticated, but GITEE.COM does not provide s
2. 查看公钥详情:点击具体的公钥可以查看其详细信息
3. 删除公钥当某个SSH公钥不再需要时可以直接删除它
![浏览SSH Key](./assert/sshkeys_list-bff1a324894abbdc3ab8f61c49bb63d5.png "浏览SSH Key")
![浏览SSH Key](./assets/sshkeys_list-bff1a324894abbdc3ab8f61c49bb63d5.png "浏览SSH Key")
![查看/删除SSH Key](./assert/sshkeys_show-a14cdfb89475debed237bfded2bd9848.png "查看/删除SSH Key")
![查看/删除SSH Key](./assets/sshkeys_show-a14cdfb89475debed237bfded2bd9848.png "查看/删除SSH Key")
## 账户SSH公钥vs仓库SSH公钥

95
src/tools/gkd.md Normal file
View File

@ -0,0 +1,95 @@
---
title: 跳过开屏广告神器GKD搞快点
icon: lightbulb
category:
- 软件推荐
tag:
- Android
- 广告拦截
- GKD
---
::: center
![GKD Logo](./assets/v2-751a78a5288f3230e3ba1ed114c97646_1440w-1753415770993-3.jpg)
:::
## 为什么推荐 GKD
- **痛点解决**:自动跳过开屏广告、摇一摇跳转广告、应用内弹窗广告
- **开源免费**GitHub 25.7K⭐GPL-3.0 协议,社区持续维护
- **非侵入式**:模拟点击跳过广告,无需 Root不修改应用代码
## 核心功能
| 功能 | 说明 |
|---|---|
| 开屏广告秒杀 | 自动点击“跳过”,成功率 >90% |
| 应用内广告清除 | 支持知乎、贴吧、微信等主流 APP |
| 扩展自动化 | 微信登录确认、红包领取等 |
## 快速上手3 步搞定)
### 1. 下载安装
::: tip 推荐下载
- **官网**[gkd.li/guide/](https://gkd.li/guide/)
- **GitHub 稳定版**[Releases](https://github.com/gkd-kit/gkd/releases)
:::
### 2. 开启权限
```bash
设置 → 无障碍 → 授权 GKD
```
### 3. 添加规则
1. 打开规则列表:[GitHub Topics](https://github.com/topics/gkd-subscription)
2. 复制订阅链接 → GKD 内粘贴 → 启用规则
## 用户口碑
> “运行稳如老狗,无需反复开权限,比李跳跳还香!”
> —— 知乎用户
- **GitHub 25.7K⭐** 开发者认可
- **零差评稳定**:不卡顿、不耗电、无隐私风险
## 横向对比
| 工具 | 优势 | 局限 |
|---|---|---|
| **GKD** | 开源、无需 Root、规则丰富 | 需无障碍权限 |
| AdGuard | 网络层拦截,省流量 | 无法处理原生广告 |
| Tasker | 高度自定义 | 配置复杂,学习成本高 |
## 未来展望
- ✅ 支持更多 APP 自定义规则
- ✅ 优化低端机性能
- ✅ 扩展自动化任务(签到、填表)
## 立即体验
::: info
- [GKD 官网下载](https://gkd.li/guide/)
- [GitHub 仓库](https://github.com/gkd-kit/gkd)
:::
---
::: note
整理自 [知乎专栏](https://zhuanlan.zhihu.com/p/1891142892980003672)作者chal1ce
:::
---
### 使用提示VuePress Theme Hope 专属)
1. 将上述内容保存为 `docs/gkd.md`
2. 在 `docs/.vuepress/config.ts``sidebar` 中添加:
```ts
"/gkd/": ["gkd"]
```
3. 本地预览:`pnpm docs:dev`
主题会自动生成标题锚点、代码高亮、提示框和图标,无需额外配置。

View File

@ -10,8 +10,12 @@ title: 202507日志
## TODO
1. 判断ue文件是否存在调整目录
1. 改掉平台代码redis *的匹配
1. rtdbBasicService的keys方法删除
## 2025-06-30 至 2025-07-04
## 2025-06-30 至 2025-07-06
### **PRS-7950 巡视系统**
@ -33,7 +37,7 @@ title: 202507日志
## 2025-07-07至2025-07-14
## 2025-07-07至2025-07-13
### **PRS-7950 巡视系统**
@ -53,13 +57,19 @@ title: 202507日志
## 2025-07-14至2025-07-20
### **PRS-7950 巡视系统 (2025-07-14至2025-07-20)**
1. 为巡视历史任务、首页通知、数据分析等模块新增了任务类型、点位状态、电站ID等关键字段丰富了数据维度。
2. 新增了联动信号去重功能通过同步控制和逻辑优化避免5秒内重复任务的产生。
3. 重构并优化了联动任务的执行逻辑与摄像头巡检数据的更新流程,提升了代码的可读性与执行效率。
4. 修复了巡检数据解析时因数组索引错误导致的异常,并解决了红外测温规则更新不生效的问题。
5. 优化了分析结果的描述逻辑,当存在多个检测结果时,能更准确地合并和展示描述信息。
### **PRS-7050 场站智慧管控 (2025-07-14至2025-07-20)**
1. 本周进行了大规模代码同步全面集成了主站业务逻辑、告警与工业集控同步、四遥信号支持、国际化等新功能并包含了对任务调度、数据处理、设备在线率计算、XML解析及大量B接口联调问题的深度优化与修复。

View File

@ -37,7 +37,7 @@ svn merge -c 241108 https://10.1.0.101/svn/houtai/001_后台软件/PRS-7950在
```bash
svn merge -c 240928 http://10.6.220.216:8080/svn/houtai/001_后台软件/PRS-7950在线巡视/01_开发库/V2.00/src_java/platapp
svn merge -c 241091 https://10.1.0.101/svn/houtai/001_后台软件/PRS-7950在线巡视/01_开发库/V2.00/src_java/platapp
svn merge -c 238665 https://10.1.0.101/svn/houtai/001_后台软件/PRS-7950在线巡视/01_开发库/V2.00/src_java/platapp
svn merge -c 237503 http://10.6.220.216:8080/svn/houtai/001_后台软件/PRS-7950在线巡视/01_开发库/V2.00/src_java/platform
```
@ -172,6 +172,22 @@ export file:/home/sunri/PRS7950/binary/java/jar/x64/dist/
\end{document}
```
## 杀死win10进程
```powershell
Stop-Process -Id 5668 -Force
```
### 权限图
![权限图](./assets/image-20240513143908211.png)
@ -205,5 +221,240 @@ echo "所有非 Main 的 Java 进程已被杀掉。"
多光谱测试代码:
```java
//测试用
@Override
public void run(String... args) throws Exception {
//查询数据
List<PatrolCameraDevice> cameraDeviceList = cameraDeviceMapper.queryByCameraUsage(3);
List<Integer> belongDeviceIDList = cameraDeviceList.stream().map(PatrolCameraDevice::getBelongDeviceId).distinct().collect(Collectors.toList());
List<PatrolCameraDevice> collect = cameraDeviceList
.stream()
.filter(item -> DeviceProtocol.VideoProtocol.VIDEO_PROTOCOL_MOLE_WEI_WEI_SHI.equals(item.getDeviceProtocol())).collect(Collectors.toList());
List<AlarmDto> alarmDtoList = Collections.emptyList();
if (!collect.isEmpty()) {
alarmDtoList = collect.stream().map(item -> {
AlarmDto alarmDto = new AlarmDto();
alarmDto.setBelongDeviceID(item.getBelongDeviceId());
alarmDto.setDeviceID(item.getId());
alarmDto.setDeviceName(item.getDeviceName());
return alarmDto;
}).collect(Collectors.toList());
}
scheduler = Executors.newScheduledThreadPool(1);
deviceIDList = belongDeviceIDList;
alarmDto = alarmDtoList;
startScheduledTask();
}
private ScheduledExecutorService scheduler;
private List<Integer> deviceIDList;
private List<AlarmDto> alarmDto;
/**
* 启动定时任务
*/
public void startScheduledTask() {
System.out.println("定时任务已启动每5秒随机执行一个方法...");
scheduler.scheduleAtFixedRate(() -> {
try {
// 随机选择执行哪个方法 (0或1)
int randomChoice = (int) (Math.random() * 2);
if (randomChoice == 0) {
// 执行 generateRandomDeviceData
String deviceData = generateRandomDeviceData(deviceIDList);
System.out.println(" 结果: " + JSONUtil.toJsonStr(deviceData));
mqBusService.sendCygCommonMessage(
JSONUtil.toJsonStr(deviceData),
StateTopicEnum.RUN.getIndex(),
"/patrolsys/webfront/notify",
MqBusClientInitConfig.appName,
"multispectral");
} else {
// 执行 generateRandomAlarm
AlarmDto alarm = AlarmGenerator.generateRandomAlarm(alarmDto);
System.out.println(" 结果: " + JSONUtil.toJsonStr(alarm));
mqBusService.sendCygCommonMessage(
JSONUtil.toJsonStr(alarm),
StateTopicEnum.RUN.getIndex(),
"/patrolsys/webfront/notify",
MqBusClientInitConfig.appName,
"multispectral");
}
System.out.println("----------------------------------------");
} catch (Exception e) {
System.err.println("定时任务执行出错: " + e.getMessage());
}
}, 0, 5, TimeUnit.SECONDS); // 立即开始每5秒执行一次
}
/**
* 从设备ID列表中随机选择一个设备ID并生成随机曲线数据
*
* @param belongDeviceIDList 设备ID列表
* @return JSON格式的设备数据对象
*/
public static String generateRandomDeviceData(List<Integer> belongDeviceIDList) {
if (belongDeviceIDList == null || belongDeviceIDList.isEmpty()) {
throw new IllegalArgumentException("设备ID列表不能为空");
}
// 使用Math.random()随机选择一个设备ID
int randomIndex = (int) (Math.random() * belongDeviceIDList.size());
int belongDeviceID = belongDeviceIDList.get(randomIndex);
// 生成1-1000范围内的随机曲线数据
int curveData = (int) (Math.random() * 1000) + 1;
// 使用JSONUtil生成更安全的JSON自动处理特殊字符
JSONObject json = new JSONObject();
json.set("belongDeviceID", belongDeviceID);
json.set("curveData", curveData);
json.set("msgType", "real-time-curve");
return json.toString();
}
// 使用示例
public static void main(String[] args) {
List<Integer> deviceIds = Arrays.asList(101, 102, 103, 104, 105);
String result = generateRandomDeviceData(deviceIds);
System.out.println(result);
// 输出示例: {"belongDeviceID":103,"curveData":756}
}
/**
* 告警数据传输对象
*/
@Data
static class AlarmDto {
private int belongDeviceID; // 所属设备id
private int deviceID; // 紫外设备id
private String deviceName; // 紫外设备名称
private int alarmTimestamp; // 告警时间戳s
private String alarmMessage; // 告警信息
private String msgType;
// 构造函数
public AlarmDto() {
}
public AlarmDto(int belongDeviceID, int deviceID, String deviceName) {
this.belongDeviceID = belongDeviceID;
this.deviceID = deviceID;
this.deviceName = deviceName;
}
public AlarmDto(int belongDeviceID, int deviceID, String deviceName,
int alarmTimestamp, String alarmMessage) {
this.belongDeviceID = belongDeviceID;
this.deviceID = deviceID;
this.deviceName = deviceName;
this.alarmTimestamp = alarmTimestamp;
this.alarmMessage = alarmMessage;
}
@Override
public String toString() {
return String.format("AlarmDto{belongDeviceID=%d, deviceID=%d, deviceName='%s', " +
"alarmTimestamp=%d, alarmMessage='%s'}",
belongDeviceID, deviceID, deviceName, alarmTimestamp, alarmMessage);
}
}
/**
* 告警数据生成器
*/
static class AlarmGenerator {
// 预定义的中文告警信息
private static final String[] ALARM_MESSAGES = {
"设备温度过高,请检查散热系统",
"紫外灯管老化,建议更换",
"设备电压异常,请检查供电线路",
"传感器读数异常,需要校准",
"设备运行时间过长,建议停机检修",
"紫外强度不足,检查灯管状态",
"设备过载保护触发",
"通信连接中断,请检查网络",
"设备内部湿度过高",
"风扇转速异常,请检查风扇",
"电流过大,触发保护机制",
"设备门未关闭,请检查安全门",
"滤网堵塞,需要清洁维护",
"设备震动异常,请检查固定",
"控制板故障,需要技术支持"
};
/**
* 从AlarmDto列表中随机选择一个设置当前时间戳和随机告警信息
*
* @param alarmDtoList 包含基础信息的AlarmDto列表
* @return 完整的AlarmDto对象
*/
public static AlarmDto generateRandomAlarm(List<AlarmDto> alarmDtoList) {
if (alarmDtoList == null || alarmDtoList.isEmpty()) {
throw new IllegalArgumentException("AlarmDto列表不能为空");
}
// 随机选择一个AlarmDto
int randomIndex = (int) (Math.random() * alarmDtoList.size());
AlarmDto selectedAlarm = alarmDtoList.get(randomIndex);
// 创建新的AlarmDto对象复制基础信息
AlarmDto result = new AlarmDto(
selectedAlarm.getBelongDeviceID(),
selectedAlarm.getDeviceID(),
selectedAlarm.getDeviceName()
);
result.setMsgType("alarm-message");
// 设置当前时间戳(秒)
result.setAlarmTimestamp((int) (System.currentTimeMillis() / 1000));
// 随机选择告警信息
int messageIndex = (int) (Math.random() * ALARM_MESSAGES.length);
result.setAlarmMessage(ALARM_MESSAGES[messageIndex]);
return result;
}
// 使用示例
public static void main(String[] args) {
// 创建测试数据
List<AlarmDto> alarmList = Arrays.asList(
new AlarmDto(1001, 2001, "紫外消毒设备A"),
new AlarmDto(1002, 2002, "紫外消毒设备B"),
new AlarmDto(1003, 2003, "紫外消毒设备C"),
new AlarmDto(1004, 2004, "紫外消毒设备D")
);
// 生成随机告警
AlarmDto randomAlarm = generateRandomAlarm(alarmList);
System.out.println("生成的随机告警:");
System.out.println(randomAlarm);
// 多次生成示例
System.out.println("\n连续生成3个随机告警:");
for (int i = 0; i < 3; i++) {
AlarmDto alarm = generateRandomAlarm(alarmList);
System.out.println((i + 1) + ". " + alarm);
}
}
}
```