feat: 短信服务
This commit is contained in:
@@ -72,7 +72,9 @@
|
||||
"Bash(do if [ -f \"$file\" ])",
|
||||
"Bash(else echo \"✗ $file NOT FOUND\")",
|
||||
"Bash(fi)",
|
||||
"Bash(done)"
|
||||
"Bash(done)",
|
||||
"Bash(tasklist:*)",
|
||||
"Bash(test:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
FROM openjdk:8u292
|
||||
|
||||
LABEL MAINTAINER=Andy
|
||||
WORKDIR /apps
|
||||
ADD target/msg-center.jar /apps/
|
||||
CMD ["java","-jar","msg-center.jar"]
|
||||
# docker run --name msg-center \
|
||||
# -e spring_cloud_nacos_server_addr=10.0.0.12:8848 \
|
||||
# -e zlt_datasource_ip=10.0.0.12 \
|
||||
# -e zlt_datasource_username=root \
|
||||
# -e zlt_datasource_password=redhat \
|
||||
# -e spring_redis_host=10.0.0.12 \
|
||||
# -d msg-center:6.0.0
|
||||
@@ -0,0 +1,563 @@
|
||||
# 消息中心 (msg-center)
|
||||
|
||||
消息中心是一个独立的微服务模块,提供短信、邮件、推送等消息发送功能。
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 已实现功能
|
||||
- ✅ 腾讯云短信发送
|
||||
- ✅ 阿里云短信发送
|
||||
- ✅ **阿里云和腾讯云独立API接口(可分别调用)**
|
||||
- ✅ 多服务商切换(支持动态配置)
|
||||
- ✅ 短信发送记录保存到数据库
|
||||
- ✅ 验证码短信发送
|
||||
- ✅ RESTful API接口
|
||||
- ✅ 短信发送记录查询
|
||||
|
||||
### 计划功能
|
||||
- 📋 邮件发送
|
||||
- 📋 站内消息
|
||||
- 📋 APP推送通知
|
||||
- 📋 短信发送统计
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 数据库初始化
|
||||
|
||||
执行数据库初始化脚本创建短信发送记录表:
|
||||
|
||||
```bash
|
||||
mysql -u root -p your_database < db/init.sql
|
||||
```
|
||||
|
||||
或手动执行 `db/init.sql` 中的SQL语句。
|
||||
|
||||
### 2. 配置短信服务商
|
||||
|
||||
支持两种短信服务商:**腾讯云** 和 **阿里云**。
|
||||
|
||||
**重要更新:** 现在支持**同时配置两个服务商**,并通过不同的API接口分别调用,无需切换配置!
|
||||
|
||||
#### 同时配置腾讯云和阿里云
|
||||
|
||||
在 `application.yml` 中配置:
|
||||
|
||||
```yaml
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://${zlt.datasource.ip}/msg-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
sms:
|
||||
# 默认服务商(用于通用接口 /sms/send)
|
||||
provider: TENCENT
|
||||
|
||||
# 腾讯云短信配置
|
||||
tencent:
|
||||
app-id: 1400xxxxxx # 在腾讯云短信控制台获取
|
||||
secret-id: AKIDxxxxxxxx # 在腾讯云控制台获取
|
||||
secret-key: xxxxxxxx # 在腾讯云控制台获取
|
||||
sign-name: 您的签名 # 在腾讯云短信控制台配置
|
||||
verify-code-template-id: 1234567 # 腾讯云验证码模板ID
|
||||
|
||||
# 阿里云短信配置
|
||||
aliyun:
|
||||
access-key-id: LTAIxxxxxxxx # 在阿里云控制台获取
|
||||
access-key-secret: xxxxxxxx # 在阿里云控制台获取
|
||||
sign-name: 您的签名 # 在阿里云短信控制台配置
|
||||
verify-code-template-id: SMS_123456789 # 阿里云验证码模板CODE
|
||||
|
||||
# 是否保存短信发送记录到数据库
|
||||
save-log: true
|
||||
```
|
||||
|
||||
**环境变量配置(推荐):**
|
||||
|
||||
```bash
|
||||
# 数据库配置
|
||||
export zlt.datasource.ip=localhost:3306
|
||||
export zlt.datasource.username=root
|
||||
export zlt.datasource.password=yourpassword
|
||||
|
||||
# 默认服务商
|
||||
export SMS_PROVIDER=TENCENT
|
||||
|
||||
# 腾讯云配置
|
||||
export SMS_TENCENT_APP_ID=1400xxxxxx
|
||||
export SMS_TENCENT_SECRET_ID=AKIDxxxxxxxxxxxxxxxx
|
||||
export SMS_TENCENT_SECRET_KEY=xxxxxxxxxxxxxxxx
|
||||
export SMS_TENCENT_SIGN_NAME=您的签名
|
||||
export SMS_TENCENT_VERIFY_CODE_TEMPLATE_ID=1234567
|
||||
|
||||
# 阿里云配置
|
||||
export SMS_ALIYUN_ACCESS_KEY_ID=LTAIxxxxxxxx
|
||||
export SMS_ALIYUN_ACCESS_KEY_SECRET=xxxxxxxxxxxxxxxx
|
||||
export SMS_ALIYUN_SIGN_NAME=您的签名
|
||||
export SMS_ALIYUN_VERIFY_CODE_TEMPLATE_ID=SMS_123456789
|
||||
```
|
||||
|
||||
### 3. 获取配置参数
|
||||
|
||||
#### 腾讯云短信配置参数获取
|
||||
|
||||
1. 登录 [腾讯云短信控制台](https://console.cloud.tencent.com/smsv2)
|
||||
2. 创建短信应用,获取 `app-id`
|
||||
3. 前往 [API密钥管理](https://console.cloud.tencent.com/cam/capi) 获取 `secret-id` 和 `secret-key`
|
||||
4. 在短信控制台配置短信签名,获取 `sign-name`
|
||||
5. 创建短信模板,获取 `template-id`
|
||||
|
||||
#### 阿里云短信配置参数获取
|
||||
|
||||
1. 登录 [阿里云短信控制台](https://dysms.console.aliyun.com/)
|
||||
2. 前往 [AccessKey管理](https://ram.console.aliyun.com/manage/ak) 创建AccessKey,获取 `access-key-id` 和 `access-key-secret`
|
||||
3. 在短信控制台申请短信签名,获取 `sign-name`
|
||||
4. 创建短信模板,获取模板CODE(即 `template-id`,如:SMS_123456789)
|
||||
|
||||
### 4. 启动服务
|
||||
|
||||
```bash
|
||||
cd zlt-business/msg-center
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
## API接口文档
|
||||
|
||||
服务启动后,访问 Swagger 文档:
|
||||
```
|
||||
http://localhost:8080/doc.html
|
||||
```
|
||||
|
||||
### 主要接口
|
||||
|
||||
#### 1. 发送短信(使用默认服务商)
|
||||
|
||||
**接口地址:** `POST /sms/send`
|
||||
|
||||
**说明:** 使用配置文件中 `sms.provider` 指定的默认服务商发送短信
|
||||
|
||||
**请求参数:**
|
||||
```json
|
||||
{
|
||||
"phone": "13800138000",
|
||||
"templateId": "1234567",
|
||||
"params": {
|
||||
"code": "123456",
|
||||
"time": "5"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "success",
|
||||
"datas": {
|
||||
"success": true,
|
||||
"message": "短信发送成功"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. 发送阿里云短信
|
||||
|
||||
**接口地址:** `POST /sms/aliyun/send`
|
||||
|
||||
**说明:** 强制使用阿里云发送短信,不受默认配置影响
|
||||
|
||||
**请求参数:**
|
||||
```json
|
||||
{
|
||||
"phone": "13800138000",
|
||||
"templateId": "SMS_123456789",
|
||||
"params": {
|
||||
"code": "123456",
|
||||
"time": "5"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "success",
|
||||
"datas": {
|
||||
"success": true,
|
||||
"message": "阿里云短信发送成功"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 3. 发送腾讯云短信
|
||||
|
||||
**接口地址:** `POST /sms/tencent/send`
|
||||
|
||||
**说明:** 强制使用腾讯云发送短信,不受默认配置影响
|
||||
|
||||
**请求参数:**
|
||||
```json
|
||||
{
|
||||
"phone": "13800138000",
|
||||
"templateId": "1234567",
|
||||
"params": {
|
||||
"code": "123456",
|
||||
"time": "5"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "success",
|
||||
"datas": {
|
||||
"success": true,
|
||||
"message": "腾讯云短信发送成功"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 4. 发送验证码(使用默认服务商)
|
||||
|
||||
**接口地址:** `POST /sms/send-verify-code`
|
||||
|
||||
**请求参数:**
|
||||
- `phone`: 手机号(必填)
|
||||
- `code`: 验证码(必填)
|
||||
|
||||
**示例:**
|
||||
```
|
||||
POST /sms/send-verify-code?phone=13800138000&code=123456
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "success",
|
||||
"datas": {
|
||||
"success": true,
|
||||
"message": "验证码发送成功"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 5. 发送阿里云验证码
|
||||
|
||||
**接口地址:** `POST /sms/aliyun/send-verify-code`
|
||||
|
||||
**说明:** 强制使用阿里云发送验证码,使用阿里云配置的验证码模板
|
||||
|
||||
**请求参数:**
|
||||
- `phone`: 手机号(必填)
|
||||
- `code`: 验证码(必填)
|
||||
|
||||
**示例:**
|
||||
```
|
||||
POST /sms/aliyun/send-verify-code?phone=13800138000&code=123456
|
||||
```
|
||||
|
||||
#### 6. 发送腾讯云验证码
|
||||
|
||||
**接口地址:** `POST /sms/tencent/send-verify-code`
|
||||
|
||||
**说明:** 强制使用腾讯云发送验证码,使用腾讯云配置的验证码模板
|
||||
|
||||
**请求参数:**
|
||||
- `phone`: 手机号(必填)
|
||||
- `code`: 验证码(必填)
|
||||
|
||||
**示例:**
|
||||
```
|
||||
POST /sms/tencent/send-verify-code?phone=13800138000&code=123456
|
||||
```
|
||||
|
||||
#### 7. 查询短信发送记录
|
||||
|
||||
**接口地址:** `GET /sms/logs`
|
||||
|
||||
**请求参数:**
|
||||
- `page`: 当前页(默认1)
|
||||
- `size`: 每页大小(默认10)
|
||||
- `phone`: 手机号(可选,模糊查询)
|
||||
- `status`: 状态(可选,0-失败, 1-成功, 2-发送中)
|
||||
|
||||
**示例:**
|
||||
```
|
||||
GET /sms/logs?page=1&size=10&phone=138&status=1
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "success",
|
||||
"datas": {
|
||||
"records": [...],
|
||||
"total": 100,
|
||||
"size": 10,
|
||||
"current": 1,
|
||||
"pages": 10
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 短信模板参数说明
|
||||
|
||||
### 腾讯云模板示例
|
||||
|
||||
**模板内容:**
|
||||
```
|
||||
{1}为您的登录验证码,请于{2}分钟内填写。如非本人操作,请忽略本短信。
|
||||
```
|
||||
|
||||
**对应参数:**
|
||||
```json
|
||||
{
|
||||
"params": {
|
||||
"code": "123456", // {1} 验证码
|
||||
"time": "5" // {2} 有效期(分钟)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 阿里云模板示例
|
||||
|
||||
**模板内容:**
|
||||
```
|
||||
验证码${code},您正在进行身份验证,打死不告诉别人哦!有效期${time}分钟。
|
||||
```
|
||||
|
||||
**对应参数:**
|
||||
```json
|
||||
{
|
||||
"params": {
|
||||
"code": "123456", // ${code} 验证码
|
||||
"time": "5" // ${time} 有效期(分钟)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**注意事项:**
|
||||
- 腾讯云使用 `{1}`, `{2}` 这样的占位符,参数按顺序传入
|
||||
- 阿里云使用 `${变量名}` 这样的占位符,参数需要使用JSON格式的key-value对
|
||||
|
||||
## 数据库表结构
|
||||
|
||||
### sms_send_log - 短信发送记录表
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | bigint | 主键ID |
|
||||
| phone | varchar(20) | 手机号 |
|
||||
| template_id | varchar(50) | 短信模板ID |
|
||||
| template_params | varchar(500) | 模板参数(JSON格式) |
|
||||
| content | varchar(500) | 短信内容 |
|
||||
| status | tinyint | 发送状态: 0-失败, 1-成功, 2-发送中 |
|
||||
| provider | varchar(20) | 服务商: TENCENT, ALIYUN |
|
||||
| request_id | varchar(100) | 服务商返回的请求ID |
|
||||
| response_code | varchar(50) | 服务商返回的状态码 |
|
||||
| response_message | varchar(200) | 服务商返回的消息 |
|
||||
| error_message | varchar(500) | 错误信息 |
|
||||
| tenant_id | varchar(32) | 租户ID |
|
||||
| create_time | datetime | 创建时间 |
|
||||
| update_time | datetime | 更新时间 |
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
msg-center/
|
||||
├── db/
|
||||
│ └── init.sql # 数据库初始化脚本
|
||||
├── src/
|
||||
│ └── main/
|
||||
│ ├── java/com/central/
|
||||
│ │ ├── MsgCenterApp.java # 启动类
|
||||
│ │ └── msg/
|
||||
│ │ ├── config/
|
||||
│ │ │ └── SmsConfig.java
|
||||
│ │ ├── controller/
|
||||
│ │ │ └── SmsController.java
|
||||
│ │ ├── mapper/
|
||||
│ │ │ └── SmsSendLogMapper.java
|
||||
│ │ ├── model/
|
||||
│ │ │ ├── dto/
|
||||
│ │ │ │ ├── SmsRequest.java
|
||||
│ │ │ │ └── SmsResponse.java
|
||||
│ │ │ └── entity/
|
||||
│ │ │ └── SmsSendLog.java
|
||||
│ │ └── service/
|
||||
│ │ ├── MsgSmsService.java
|
||||
│ │ └── impl/
|
||||
│ │ └── MsgSmsServiceImpl.java
|
||||
│ └── resources/
|
||||
│ ├── application.yml # 配置文件
|
||||
│ ├── bootstrap.yml # 服务名称配置
|
||||
│ └── mapper/
|
||||
│ └── SmsSendLogMapper.xml
|
||||
├── Dockerfile # Docker镜像构建文件
|
||||
├── pom.xml # Maven配置
|
||||
└── README.md # 本文档
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 1. 短信发送失败
|
||||
|
||||
**可能原因:**
|
||||
- 配置参数错误(检查各项配置是否正确)
|
||||
- 签名未审核通过
|
||||
- 模板未审核通过
|
||||
- 账户余额不足
|
||||
- 手机号格式错误
|
||||
- 发送频率过高(部分运营商有限制)
|
||||
|
||||
**解决方法:**
|
||||
- 查看日志中的详细错误信息
|
||||
- 登录服务商控制台检查签名和模板审核状态
|
||||
- 确认账户余额充足
|
||||
- 检查手机号格式是否正确
|
||||
- 调整发送频率
|
||||
|
||||
### 2. 数据库连接失败
|
||||
|
||||
确保在 `application.yml` 或 Nacos 配置中心配置了正确的数据库连接信息。
|
||||
|
||||
### 3. 如何在运行时切换短信服务商
|
||||
|
||||
**新版本:无需切换!**
|
||||
|
||||
现在你可以**同时使用阿里云和腾讯云**,只需调用不同的API接口即可:
|
||||
|
||||
- **阿里云短信:** `POST /sms/aliyun/send` 或 `POST /sms/aliyun/send-verify-code`
|
||||
- **腾讯云短信:** `POST /sms/tencent/send` 或 `POST /sms/tencent/send-verify-code`
|
||||
- **默认服务商:** `POST /sms/send` 或 `POST /sms/send-verify-code`(使用配置文件中的 `sms.provider`)
|
||||
|
||||
**使用场景示例:**
|
||||
|
||||
```bash
|
||||
# 某个服务需要使用阿里云发送营销短信
|
||||
curl -X POST http://localhost:8080/sms/aliyun/send \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"phone": "13800138000",
|
||||
"templateId": "SMS_123456789",
|
||||
"params": {"code": "123456", "time": "5"}
|
||||
}'
|
||||
|
||||
# 另一个服务需要使用腾讯云发送验证码
|
||||
curl -X POST http://localhost:8080/sms/tencent/send-verify-code \
|
||||
-d "phone=13900139000&code=654321"
|
||||
```
|
||||
|
||||
**旧方法(仍然支持):**
|
||||
|
||||
如果你只想使用一个服务商,可以通过修改配置切换:
|
||||
|
||||
**方法一:修改配置文件**
|
||||
```yaml
|
||||
sms:
|
||||
provider: ALIYUN # 将 TENCENT 改为 ALIYUN
|
||||
```
|
||||
|
||||
**方法二:使用环境变量(推荐)**
|
||||
```bash
|
||||
export SMS_PROVIDER=ALIYUN
|
||||
```
|
||||
|
||||
重启服务后生效。
|
||||
|
||||
### 4. 腾讯云和阿里云的区别
|
||||
|
||||
| 特性 | 腾讯云 | 阿里云 |
|
||||
|------|--------|--------|
|
||||
| 模板格式 | {1}, {2}, {3}... | ${变量名} |
|
||||
| 参数格式 | 数组形式,按顺序 | JSON键值对 |
|
||||
| 手机号格式 | 需要+86前缀 | 直接手机号 |
|
||||
| SDK包名 | tencentcloud-sdk-java | aliyun-java-sdk-dysmsapi |
|
||||
|
||||
### 5. 如何同时配置两个服务商并分别调用
|
||||
|
||||
**现在已经默认支持!** 无需任何特殊配置。
|
||||
|
||||
只需在配置文件中同时配置腾讯云和阿里云的参数:
|
||||
|
||||
```yaml
|
||||
sms:
|
||||
provider: TENCENT # 默认服务商(用于 /sms/send 接口)
|
||||
|
||||
tencent:
|
||||
app-id: xxx
|
||||
secret-id: xxx
|
||||
secret-key: xxx
|
||||
sign-name: xxx
|
||||
verify-code-template-id: xxx
|
||||
|
||||
aliyun:
|
||||
access-key-id: xxx
|
||||
access-key-secret: xxx
|
||||
sign-name: xxx
|
||||
verify-code-template-id: xxx
|
||||
```
|
||||
|
||||
**然后直接调用对应的API接口:**
|
||||
|
||||
```bash
|
||||
# 使用阿里云发送
|
||||
POST /sms/aliyun/send
|
||||
|
||||
# 使用腾讯云发送
|
||||
POST /sms/tencent/send
|
||||
|
||||
# 使用默认服务商(TENCENT)发送
|
||||
POST /sms/send
|
||||
```
|
||||
|
||||
**优势:**
|
||||
- ✅ 不同服务可以选择不同的短信服务商
|
||||
- ✅ 无需重启服务即可使用不同的服务商
|
||||
- ✅ 可以根据成本、到达率等因素灵活选择
|
||||
- ✅ 支持灾备切换(一个服务商故障时使用另一个)
|
||||
|
||||
**实际应用场景:**
|
||||
|
||||
```java
|
||||
// 服务A:使用阿里云发送营销短信
|
||||
POST /sms/aliyun/send
|
||||
|
||||
// 服务B:使用腾讯云发送验证码
|
||||
POST /sms/tencent/send-verify-code
|
||||
|
||||
// 服务C:使用默认配置发送通知短信
|
||||
POST /sms/send
|
||||
```
|
||||
|
||||
## 开发计划
|
||||
|
||||
- [ ] 添加短信发送频率限制(防刷)
|
||||
- [ ] 添加短信发送统计报表
|
||||
- [ ] 支持批量发送短信
|
||||
- [ ] 添加短信发送队列(异步发送)
|
||||
- [ ] 支持更多短信服务商(华为云、七牛云等)
|
||||
- [ ] 添加邮件发送功能
|
||||
- [ ] 添加消息模板管理
|
||||
- [ ] 添加短信发送失败重试机制
|
||||
|
||||
## 技术栈
|
||||
|
||||
- Spring Boot 3.1.6
|
||||
- Spring Cloud
|
||||
- MyBatis Plus 3.5.4
|
||||
- 腾讯云短信 SDK 3.1.1040
|
||||
- 阿里云短信 SDK 2.1.0
|
||||
- MySQL 8.0
|
||||
- Redis 7.0
|
||||
- Nacos (服务注册与配置中心)
|
||||
|
||||
## 联系方式
|
||||
|
||||
如有问题,请提交 Issue 或联系开发团队。
|
||||
@@ -0,0 +1,26 @@
|
||||
-- =============================================
|
||||
-- 消息中心 - 短信发送记录表
|
||||
-- =============================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sms_send_log` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`phone` varchar(20) NOT NULL COMMENT '手机号',
|
||||
`template_id` varchar(50) NOT NULL COMMENT '短信模板ID',
|
||||
`template_params` varchar(500) DEFAULT NULL COMMENT '模板参数(JSON格式)',
|
||||
`content` varchar(500) DEFAULT NULL COMMENT '短信内容',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '2' COMMENT '发送状态: 0-失败, 1-成功, 2-发送中',
|
||||
`provider` varchar(20) NOT NULL DEFAULT 'TENCENT' COMMENT '服务商: TENCENT, ALIYUN',
|
||||
`request_id` varchar(100) DEFAULT NULL COMMENT '服务商返回的请求ID',
|
||||
`response_code` varchar(50) DEFAULT NULL COMMENT '服务商返回的状态码',
|
||||
`response_message` varchar(200) DEFAULT NULL COMMENT '服务商返回的消息',
|
||||
`error_message` varchar(500) DEFAULT NULL COMMENT '错误信息',
|
||||
`tenant_id` varchar(32) DEFAULT NULL COMMENT '租户ID',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_phone` (`phone`),
|
||||
KEY `idx_template_id` (`template_id`),
|
||||
KEY `idx_create_time` (`create_time`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_tenant_id` (`tenant_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='短信发送记录表';
|
||||
@@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-business</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</parent>
|
||||
<artifactId>msg-center</artifactId>
|
||||
<description>消息中心</description>
|
||||
<dependencies>
|
||||
<!-- 公共实体类模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-redis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 短信服务 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-sms-spring-boot-starter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||
<imageTags>
|
||||
<imageTag>${project.version}</imageTag>
|
||||
<imageTag>latest</imageTag>
|
||||
</imageTags>
|
||||
<forceTags>true</forceTags>
|
||||
<baseImage>${docker.baseImage}</baseImage>
|
||||
<volumes>${docker.volumes}</volumes>
|
||||
<env>
|
||||
<JAVA_OPTS>${docker.java.opts}</JAVA_OPTS>
|
||||
</env>
|
||||
<entryPoint>["sh","-c","java $JAVA_OPTS ${docker.java.security.egd} -jar /${project.build.finalName}.jar"]</entryPoint>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.central;
|
||||
|
||||
import com.central.common.lb.annotation.EnableFeignInterceptor;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* 消息中心启动类
|
||||
* @author system
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableTransactionManagement
|
||||
@EnableFeignInterceptor
|
||||
@SpringBootApplication
|
||||
public class MsgCenterApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MsgCenterApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.central.msg.config;
|
||||
|
||||
import com.central.sms.config.SmsProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 短信配置类
|
||||
* @author system
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(SmsProperties.class)
|
||||
public class SmsConfig {
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package com.central.msg.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.msg.model.dto.SmsRequest;
|
||||
import com.central.msg.model.dto.SmsResponse;
|
||||
import com.central.msg.model.entity.SmsSendLog;
|
||||
import com.central.msg.service.MsgSmsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 短信发送Controller
|
||||
* @author system
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sms")
|
||||
@Tag(name = "短信服务", description = "短信发送相关接口")
|
||||
public class SmsController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SmsController.class);
|
||||
|
||||
@Autowired
|
||||
private MsgSmsService msgSmsService;
|
||||
|
||||
/**
|
||||
* 发送短信(使用默认服务商)
|
||||
*/
|
||||
@PostMapping("/send")
|
||||
@Operation(summary = "发送短信", description = "使用默认服务商发送模板短信")
|
||||
public Result<SmsResponse> sendSms(@Valid @RequestBody SmsRequest request) {
|
||||
logger.info("收到短信发送请求: {}", request);
|
||||
|
||||
try {
|
||||
boolean success = msgSmsService.sendSms(
|
||||
request.getPhone(),
|
||||
request.getTemplateId(),
|
||||
request.getParams()
|
||||
);
|
||||
|
||||
if (success) {
|
||||
SmsResponse response = new SmsResponse(true, "短信发送成功");
|
||||
return Result.succeed(response);
|
||||
} else {
|
||||
SmsResponse response = new SmsResponse(false, "短信发送失败");
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("短信发送异常: {}", e.getMessage(), e);
|
||||
SmsResponse response = new SmsResponse(false, "短信发送异常: " + e.getMessage());
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送阿里云短信
|
||||
*/
|
||||
@PostMapping("/aliyun/send")
|
||||
@Operation(summary = "发送阿里云短信", description = "使用阿里云发送模板短信")
|
||||
public Result<SmsResponse> sendAliyunSms(@Valid @RequestBody SmsRequest request) {
|
||||
logger.info("收到阿里云短信发送请求: {}", request);
|
||||
|
||||
try {
|
||||
boolean success = msgSmsService.sendAliyunSms(
|
||||
request.getPhone(),
|
||||
request.getTemplateId(),
|
||||
request.getParams()
|
||||
);
|
||||
|
||||
if (success) {
|
||||
SmsResponse response = new SmsResponse(true, "阿里云短信发送成功");
|
||||
return Result.succeed(response);
|
||||
} else {
|
||||
SmsResponse response = new SmsResponse(false, "阿里云短信发送失败");
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("阿里云短信发送异常: {}", e.getMessage(), e);
|
||||
SmsResponse response = new SmsResponse(false, "阿里云短信发送异常: " + e.getMessage());
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送腾讯云短信
|
||||
*/
|
||||
@PostMapping("/tencent/send")
|
||||
@Operation(summary = "发送腾讯云短信", description = "使用腾讯云发送模板短信")
|
||||
public Result<SmsResponse> sendTencentSms(@Valid @RequestBody SmsRequest request) {
|
||||
logger.info("收到腾讯云短信发送请求: {}", request);
|
||||
|
||||
try {
|
||||
boolean success = msgSmsService.sendTencentSms(
|
||||
request.getPhone(),
|
||||
request.getTemplateId(),
|
||||
request.getParams()
|
||||
);
|
||||
|
||||
if (success) {
|
||||
SmsResponse response = new SmsResponse(true, "腾讯云短信发送成功");
|
||||
return Result.succeed(response);
|
||||
} else {
|
||||
SmsResponse response = new SmsResponse(false, "腾讯云短信发送失败");
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("腾讯云短信发送异常: {}", e.getMessage(), e);
|
||||
SmsResponse response = new SmsResponse(false, "腾讯云短信发送异常: " + e.getMessage());
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码(使用默认服务商)
|
||||
*/
|
||||
@PostMapping("/send-verify-code")
|
||||
@Operation(summary = "发送验证码", description = "使用默认服务商发送验证码短信")
|
||||
public Result<SmsResponse> sendVerifyCode(
|
||||
@Parameter(description = "手机号", required = true) @RequestParam("phone") String phone,
|
||||
@Parameter(description = "验证码", required = true) @RequestParam("code") String code) {
|
||||
logger.info("收到验证码发送请求: phone={}, code={}", phone, code);
|
||||
|
||||
try {
|
||||
boolean success = msgSmsService.sendVerifyCode(phone, code);
|
||||
|
||||
if (success) {
|
||||
SmsResponse response = new SmsResponse(true, "验证码发送成功");
|
||||
return Result.succeed(response);
|
||||
} else {
|
||||
SmsResponse response = new SmsResponse(false, "验证码发送失败");
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("验证码发送异常: {}", e.getMessage(), e);
|
||||
SmsResponse response = new SmsResponse(false, "验证码发送异常: " + e.getMessage());
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送阿里云验证码
|
||||
*/
|
||||
@PostMapping("/aliyun/send-verify-code")
|
||||
@Operation(summary = "发送阿里云验证码", description = "使用阿里云发送验证码短信")
|
||||
public Result<SmsResponse> sendAliyunVerifyCode(
|
||||
@Parameter(description = "手机号", required = true) @RequestParam("phone") String phone,
|
||||
@Parameter(description = "验证码", required = true) @RequestParam("code") String code) {
|
||||
logger.info("收到阿里云验证码发送请求: phone={}, code={}", phone, code);
|
||||
|
||||
try {
|
||||
boolean success = msgSmsService.sendAliyunVerifyCode(phone, code);
|
||||
|
||||
if (success) {
|
||||
SmsResponse response = new SmsResponse(true, "阿里云验证码发送成功");
|
||||
return Result.succeed(response);
|
||||
} else {
|
||||
SmsResponse response = new SmsResponse(false, "阿里云验证码发送失败");
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("阿里云验证码发送异常: {}", e.getMessage(), e);
|
||||
SmsResponse response = new SmsResponse(false, "阿里云验证码发送异常: " + e.getMessage());
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送腾讯云验证码
|
||||
*/
|
||||
@PostMapping("/tencent/send-verify-code")
|
||||
@Operation(summary = "发送腾讯云验证码", description = "使用腾讯云发送验证码短信")
|
||||
public Result<SmsResponse> sendTencentVerifyCode(
|
||||
@Parameter(description = "手机号", required = true) @RequestParam("phone") String phone,
|
||||
@Parameter(description = "验证码", required = true) @RequestParam("code") String code) {
|
||||
logger.info("收到腾讯云验证码发送请求: phone={}, code={}", phone, code);
|
||||
|
||||
try {
|
||||
boolean success = msgSmsService.sendTencentVerifyCode(phone, code);
|
||||
|
||||
if (success) {
|
||||
SmsResponse response = new SmsResponse(true, "腾讯云验证码发送成功");
|
||||
return Result.succeed(response);
|
||||
} else {
|
||||
SmsResponse response = new SmsResponse(false, "腾讯云验证码发送失败");
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("腾讯云验证码发送异常: {}", e.getMessage(), e);
|
||||
SmsResponse response = new SmsResponse(false, "腾讯云验证码发送异常: " + e.getMessage());
|
||||
return Result.failed(response,"短信发送失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询短信发送记录
|
||||
*/
|
||||
@GetMapping("/logs")
|
||||
@Operation(summary = "查询短信发送记录", description = "分页查询短信发送记录")
|
||||
public Result<Page<SmsSendLog>> querySmsSendLog(
|
||||
@Parameter(description = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1") int page,
|
||||
@Parameter(description = "每页大小", required = true) @RequestParam(value = "size", defaultValue = "10") int size,
|
||||
@Parameter(description = "手机号") @RequestParam(value = "phone", required = false) String phone,
|
||||
@Parameter(description = "状态: 0-失败, 1-成功, 2-发送中") @RequestParam(value = "status", required = false) Integer status) {
|
||||
logger.info("查询短信发送记录: page={}, size={}, phone={}, status={}", page, size, phone, status);
|
||||
|
||||
try {
|
||||
Page<SmsSendLog> result = msgSmsService.querySmsSendLog(page, size, phone, status);
|
||||
return Result.succeed(result);
|
||||
} catch (Exception e) {
|
||||
logger.error("查询短信发送记录异常: {}", e.getMessage(), e);
|
||||
return Result.failed("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.central.msg.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.msg.model.entity.SmsSendLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 短信发送记录Mapper
|
||||
* @author system
|
||||
*/
|
||||
@Mapper
|
||||
public interface SmsSendLogMapper extends BaseMapper<SmsSendLog> {
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.central.msg.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信发送请求DTO
|
||||
* @author system
|
||||
*/
|
||||
@Schema(description = "短信发送请求")
|
||||
public class SmsRequest {
|
||||
|
||||
@Schema(description = "手机号", required = true, example = "13800138000")
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "短信模板ID", required = true, example = "123456")
|
||||
@NotBlank(message = "模板ID不能为空")
|
||||
private String templateId;
|
||||
|
||||
@Schema(description = "模板参数", example = "{\"code\":\"1234\",\"time\":\"5\"}")
|
||||
private Map<String, String> params;
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public void setTemplateId(String templateId) {
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
public Map<String, String> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SmsRequest{" +
|
||||
"phone='" + phone + '\'' +
|
||||
", templateId='" + templateId + '\'' +
|
||||
", params=" + params +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.central.msg.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 短信发送响应DTO
|
||||
* @author system
|
||||
*/
|
||||
@Schema(description = "短信发送响应")
|
||||
public class SmsResponse {
|
||||
|
||||
@Schema(description = "是否成功")
|
||||
private boolean success;
|
||||
|
||||
@Schema(description = "消息")
|
||||
private String message;
|
||||
|
||||
@Schema(description = "请求ID")
|
||||
private String requestId;
|
||||
|
||||
public SmsResponse() {
|
||||
}
|
||||
|
||||
public SmsResponse(boolean success, String message) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SmsResponse(boolean success, String message, String requestId) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
this.requestId = requestId;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getRequestId() {
|
||||
return requestId;
|
||||
}
|
||||
|
||||
public void setRequestId(String requestId) {
|
||||
this.requestId = requestId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SmsResponse{" +
|
||||
"success=" + success +
|
||||
", message='" + message + '\'' +
|
||||
", requestId='" + requestId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.central.msg.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 短信发送记录实体
|
||||
* @author system
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_send_log")
|
||||
public class SmsSendLog implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 短信模板ID
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板参数(JSON格式)
|
||||
*/
|
||||
private String templateParams;
|
||||
|
||||
/**
|
||||
* 短信内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 发送状态: 0-失败, 1-成功, 2-发送中
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 服务商: TENCENT, ALIYUN
|
||||
*/
|
||||
private String provider;
|
||||
|
||||
/**
|
||||
* 服务商返回的请求ID
|
||||
*/
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 服务商返回的状态码
|
||||
*/
|
||||
private String responseCode;
|
||||
|
||||
/**
|
||||
* 服务商返回的消息
|
||||
*/
|
||||
private String responseMessage;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.central.msg.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.msg.model.entity.SmsSendLog;
|
||||
import com.central.sms.enums.SmsProviderType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息中心短信服务接口
|
||||
* @author system
|
||||
*/
|
||||
public interface MsgSmsService {
|
||||
|
||||
/**
|
||||
* 发送短信(使用默认服务商)
|
||||
* @param phone 手机号
|
||||
* @param templateId 模板ID
|
||||
* @param params 模板参数
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendSms(String phone, String templateId, Map<String, String> params);
|
||||
|
||||
/**
|
||||
* 发送短信(指定服务商)
|
||||
* @param phone 手机号
|
||||
* @param templateId 模板ID
|
||||
* @param params 模板参数
|
||||
* @param provider 服务商类型
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendSms(String phone, String templateId, Map<String, String> params, SmsProviderType provider);
|
||||
|
||||
/**
|
||||
* 发送阿里云短信
|
||||
* @param phone 手机号
|
||||
* @param templateId 模板ID
|
||||
* @param params 模板参数
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendAliyunSms(String phone, String templateId, Map<String, String> params);
|
||||
|
||||
/**
|
||||
* 发送腾讯云短信
|
||||
* @param phone 手机号
|
||||
* @param templateId 模板ID
|
||||
* @param params 模板参数
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendTencentSms(String phone, String templateId, Map<String, String> params);
|
||||
|
||||
/**
|
||||
* 发送验证码短信(使用默认服务商)
|
||||
* @param phone 手机号
|
||||
* @param code 验证码
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendVerifyCode(String phone, String code);
|
||||
|
||||
/**
|
||||
* 发送验证码短信(指定服务商)
|
||||
* @param phone 手机号
|
||||
* @param code 验证码
|
||||
* @param provider 服务商类型
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendVerifyCode(String phone, String code, SmsProviderType provider);
|
||||
|
||||
/**
|
||||
* 发送阿里云验证码
|
||||
* @param phone 手机号
|
||||
* @param code 验证码
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendAliyunVerifyCode(String phone, String code);
|
||||
|
||||
/**
|
||||
* 发送腾讯云验证码
|
||||
* @param phone 手机号
|
||||
* @param code 验证码
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
boolean sendTencentVerifyCode(String phone, String code);
|
||||
|
||||
/**
|
||||
* 分页查询短信发送记录
|
||||
* @param page 当前页
|
||||
* @param size 每页大小
|
||||
* @param phone 手机号(可选)
|
||||
* @param status 状态(可选)
|
||||
* @return 分页数据
|
||||
*/
|
||||
Page<SmsSendLog> querySmsSendLog(int page, int size, String phone, Integer status);
|
||||
}
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package com.central.msg.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.msg.mapper.SmsSendLogMapper;
|
||||
import com.central.msg.model.entity.SmsSendLog;
|
||||
import com.central.msg.service.MsgSmsService;
|
||||
import com.central.sms.config.SmsProperties;
|
||||
import com.central.sms.enums.SmsProviderType;
|
||||
import com.central.sms.service.ISmsService;
|
||||
import com.central.sms.service.impl.AliyunSmsService;
|
||||
import com.central.sms.service.impl.TencentSmsService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息中心短信服务实现类
|
||||
* @author system
|
||||
*/
|
||||
@Service
|
||||
public class MsgSmsServiceImpl implements MsgSmsService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MsgSmsServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private AliyunSmsService aliyunSmsService;
|
||||
|
||||
@Autowired
|
||||
private TencentSmsService tencentSmsService;
|
||||
|
||||
@Autowired
|
||||
private SmsSendLogMapper smsSendLogMapper;
|
||||
|
||||
@Autowired
|
||||
private SmsProperties smsProperties;
|
||||
|
||||
@Value("${sms.save-log:true}")
|
||||
private boolean saveLog;
|
||||
|
||||
@Override
|
||||
public boolean sendSms(String phone, String templateId, Map<String, String> params) {
|
||||
return sendSms(phone, templateId, params, smsProperties.getProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendSms(String phone, String templateId, Map<String, String> params, SmsProviderType provider) {
|
||||
SmsSendLog log = new SmsSendLog();
|
||||
log.setPhone(phone);
|
||||
log.setTemplateId(templateId);
|
||||
log.setTemplateParams(params != null ? JSON.toJSONString(params) : null);
|
||||
log.setProvider(provider.name());
|
||||
log.setCreateTime(new Date());
|
||||
log.setUpdateTime(new Date());
|
||||
|
||||
try {
|
||||
logger.info("开始发送短信: phone={}, templateId={}, params={}, provider={}",
|
||||
phone, templateId, params, provider);
|
||||
log.setStatus(2); // 发送中
|
||||
|
||||
ISmsService smsService = getSmsService(provider);
|
||||
boolean result = smsService.sendSms(phone, templateId, params);
|
||||
|
||||
if (result) {
|
||||
logger.info("短信发送成功: phone={}, templateId={}, provider={}", phone, templateId, provider);
|
||||
log.setStatus(1); // 成功
|
||||
log.setResponseCode("Ok");
|
||||
log.setResponseMessage("发送成功");
|
||||
} else {
|
||||
logger.warn("短信发送失败: phone={}, templateId={}, provider={}", phone, templateId, provider);
|
||||
log.setStatus(0); // 失败
|
||||
log.setResponseCode("Failed");
|
||||
log.setResponseMessage("发送失败");
|
||||
}
|
||||
|
||||
// 保存发送记录
|
||||
if (saveLog) {
|
||||
saveSendLog(log);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("短信发送异常: phone={}, templateId={}, provider={}, error={}",
|
||||
phone, templateId, provider, e.getMessage(), e);
|
||||
log.setStatus(0); // 失败
|
||||
log.setErrorMessage(e.getMessage());
|
||||
log.setResponseMessage("发送异常: " + e.getMessage());
|
||||
|
||||
// 保存发送记录
|
||||
if (saveLog) {
|
||||
saveSendLog(log);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendAliyunSms(String phone, String templateId, Map<String, String> params) {
|
||||
return sendSms(phone, templateId, params, SmsProviderType.ALIYUN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendTencentSms(String phone, String templateId, Map<String, String> params) {
|
||||
return sendSms(phone, templateId, params, SmsProviderType.TENCENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendVerifyCode(String phone, String code) {
|
||||
return sendVerifyCode(phone, code, smsProperties.getProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendVerifyCode(String phone, String code, SmsProviderType provider) {
|
||||
String templateId = getVerifyCodeTemplateId(provider);
|
||||
if (templateId == null || templateId.isEmpty()) {
|
||||
logger.error("{}验证码模板ID未配置,无法发送验证码短信", provider.name());
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("code", code);
|
||||
params.put("time", "5"); // 默认5分钟有效期
|
||||
|
||||
return sendSms(phone, templateId, params, provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendAliyunVerifyCode(String phone, String code) {
|
||||
return sendVerifyCode(phone, code, SmsProviderType.ALIYUN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendTencentVerifyCode(String phone, String code) {
|
||||
return sendVerifyCode(phone, code, SmsProviderType.TENCENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SmsSendLog> querySmsSendLog(int page, int size, String phone, Integer status) {
|
||||
Page<SmsSendLog> pageParam = new Page<>(page, size);
|
||||
|
||||
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SmsSendLog> wrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
||||
|
||||
// 手机号模糊查询
|
||||
if (phone != null && !phone.isEmpty()) {
|
||||
wrapper.like(SmsSendLog::getPhone, phone);
|
||||
}
|
||||
|
||||
// 状态查询
|
||||
if (status != null) {
|
||||
wrapper.eq(SmsSendLog::getStatus, status);
|
||||
}
|
||||
|
||||
// 按创建时间倒序
|
||||
wrapper.orderByDesc(SmsSendLog::getCreateTime);
|
||||
|
||||
return smsSendLogMapper.selectPage(pageParam, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据服务商类型获取短信服务实例
|
||||
*/
|
||||
private ISmsService getSmsService(SmsProviderType provider) {
|
||||
switch (provider) {
|
||||
case ALIYUN:
|
||||
return aliyunSmsService;
|
||||
case TENCENT:
|
||||
default:
|
||||
return tencentSmsService;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码模板ID
|
||||
*/
|
||||
private String getVerifyCodeTemplateId(SmsProviderType provider) {
|
||||
switch (provider) {
|
||||
case ALIYUN:
|
||||
return smsProperties.getAliyun().getVerifyCodeTemplateId();
|
||||
case TENCENT:
|
||||
return smsProperties.getTencent().getVerifyCodeTemplateId();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存短信发送记录
|
||||
*/
|
||||
private void saveSendLog(SmsSendLog log) {
|
||||
try {
|
||||
smsSendLogMapper.insert(log);
|
||||
} catch (Exception e) {
|
||||
logger.error("保存短信发送记录失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
# 消息中心配置文件
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://${zlt.datasource.ip}/msg-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
type-aliases-package: com.central.msg.model.entity
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
|
||||
springdoc:
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: com.central.msg.controller
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
swagger-model-name: 消息中心接口文档
|
||||
|
||||
# 短信服务配置
|
||||
sms:
|
||||
# 短信服务提供商: TENCENT(腾讯云) 或 ALIYUN(阿里云)
|
||||
# 默认提供商,用于未指定提供商的接口
|
||||
provider: ${SMS_PROVIDER:TENCENT}
|
||||
|
||||
# 腾讯云短信配置
|
||||
tencent:
|
||||
# 腾讯云短信应用ID (在腾讯云短信控制台获取)
|
||||
app-id: ${SMS_TENCENT_APP_ID:}
|
||||
# 腾讯云SecretId (在腾讯云控制台获取)
|
||||
secret-id: ${SMS_TENCENT_SECRET_ID:}
|
||||
# 腾讯云SecretKey (在腾讯云控制台获取)
|
||||
secret-key: ${SMS_TENCENT_SECRET_KEY:}
|
||||
# 短信签名 (在腾讯云短信控制台配置)
|
||||
sign-name: ${SMS_TENCENT_SIGN_NAME:}
|
||||
# 验证码模板ID
|
||||
verify-code-template-id: ${SMS_TENCENT_VERIFY_CODE_TEMPLATE_ID:}
|
||||
|
||||
# 阿里云短信配置
|
||||
aliyun:
|
||||
# 阿里云AccessKeyId (在阿里云控制台获取)
|
||||
access-key-id: ${SMS_ALIYUN_ACCESS_KEY_ID:}
|
||||
# 阿里云AccessKeySecret (在阿里云控制台获取)
|
||||
access-key-secret: ${SMS_ALIYUN_ACCESS_KEY_SECRET:}
|
||||
# 短信签名 (在阿里云短信控制台配置)
|
||||
sign-name: ${SMS_ALIYUN_SIGN_NAME:}
|
||||
# 验证码模板ID
|
||||
verify-code-template-id: ${SMS_ALIYUN_VERIFY_CODE_TEMPLATE_ID:}
|
||||
|
||||
# 是否保存短信发送记录到数据库
|
||||
save-log: ${SMS_SAVE_LOG:true}
|
||||
|
||||
# 多租户配置
|
||||
zlt:
|
||||
tenant:
|
||||
enable: true
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
application:
|
||||
name: msg-center
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.central.msg.mapper.SmsSendLogMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.central.msg.model.entity.SmsSendLog">
|
||||
<id column="id" property="id"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="template_id" property="templateId"/>
|
||||
<result column="template_params" property="templateParams"/>
|
||||
<result column="content" property="content"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="provider" property="provider"/>
|
||||
<result column="request_id" property="requestId"/>
|
||||
<result column="response_code" property="responseCode"/>
|
||||
<result column="response_message" property="responseMessage"/>
|
||||
<result column="error_message" property="errorMessage"/>
|
||||
<result column="tenant_id" property="tenantId"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
@@ -22,5 +22,7 @@
|
||||
<module>order-center</module>
|
||||
<!-- 优惠券中心 -->
|
||||
<module>coupon-center</module>
|
||||
<!-- 消息中心 -->
|
||||
<module>msg-center</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
+12
@@ -21,6 +21,8 @@ public class SmsProperties {
|
||||
private String secretId;
|
||||
private String secretKey;
|
||||
private String signName;
|
||||
private String verifyCodeTemplateId;
|
||||
|
||||
public String getAppId() { return appId; }
|
||||
public void setAppId(String appId) { this.appId = appId; }
|
||||
public String getSecretId() { return secretId; }
|
||||
@@ -29,17 +31,27 @@ public class SmsProperties {
|
||||
public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
|
||||
public String getSignName() { return signName; }
|
||||
public void setSignName(String signName) { this.signName = signName; }
|
||||
public String getVerifyCodeTemplateId() { return verifyCodeTemplateId; }
|
||||
public void setVerifyCodeTemplateId(String verifyCodeTemplateId) {
|
||||
this.verifyCodeTemplateId = verifyCodeTemplateId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AliyunConfig {
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String signName;
|
||||
private String verifyCodeTemplateId;
|
||||
|
||||
public String getAccessKeyId() { return accessKeyId; }
|
||||
public void setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; }
|
||||
public String getAccessKeySecret() { return accessKeySecret; }
|
||||
public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret = accessKeySecret; }
|
||||
public String getSignName() { return signName; }
|
||||
public void setSignName(String signName) { this.signName = signName; }
|
||||
public String getVerifyCodeTemplateId() { return verifyCodeTemplateId; }
|
||||
public void setVerifyCodeTemplateId(String verifyCodeTemplateId) {
|
||||
this.verifyCodeTemplateId = verifyCodeTemplateId;
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
-20
@@ -1,5 +1,6 @@
|
||||
package com.central.sms.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
||||
@@ -16,6 +17,10 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 阿里云短信服务实现
|
||||
* @author system
|
||||
*/
|
||||
@Service
|
||||
public class AliyunSmsService implements ISmsService {
|
||||
|
||||
@@ -26,30 +31,45 @@ public class AliyunSmsService implements ISmsService {
|
||||
|
||||
@Override
|
||||
public boolean sendSms(String phone, String templateId, Map<String, String> params) {
|
||||
SmsProperties.AliyunConfig config = smsProperties.getAliyun();
|
||||
DefaultProfile profile = DefaultProfile.getProfile(
|
||||
"cn-hangzhou", // 地域ID
|
||||
config.getAccessKeyId(),
|
||||
config.getAccessKeySecret()
|
||||
);
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
request.setPhoneNumbers(phone);
|
||||
request.setSignName(config.getSignName());
|
||||
request.setTemplateCode(templateId);
|
||||
// 阿里云短信模板参数为JSON字符串
|
||||
if (params != null && !params.isEmpty()) {
|
||||
request.setTemplateParam(com.alibaba.fastjson.JSON.toJSONString(params));
|
||||
}
|
||||
|
||||
try {
|
||||
logger.info("[阿里云短信] 发送请求: 手机号={}, 模板={}, 参数={}", phone, templateId, params);
|
||||
SmsProperties.AliyunConfig config = smsProperties.getAliyun();
|
||||
logger.info("[短信发送][服务商:ALIYUN] 手机号={}, 模板ID={}, 参数={}", phone, templateId, params);
|
||||
|
||||
// 创建DefaultAcsClient实例并初始化
|
||||
DefaultProfile profile = DefaultProfile.getProfile(
|
||||
"cn-hangzhou", // 地域ID,固定值
|
||||
config.getAccessKeyId(),
|
||||
config.getAccessKeySecret()
|
||||
);
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
|
||||
// 组装请求对象
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
request.setPhoneNumbers(phone);
|
||||
request.setSignName(config.getSignName());
|
||||
request.setTemplateCode(templateId);
|
||||
|
||||
// 阿里云短信模板参数为JSON字符串
|
||||
if (params != null && !params.isEmpty()) {
|
||||
String templateParam = JSON.toJSONString(params);
|
||||
request.setTemplateParam(templateParam);
|
||||
logger.debug("[短信发送][服务商:ALIYUN] 模板参数JSON: {}", templateParam);
|
||||
}
|
||||
|
||||
// 发送短信
|
||||
SendSmsResponse response = client.getAcsResponse(request);
|
||||
logger.info("[阿里云短信] 发送结果: {}", response.getMessage());
|
||||
|
||||
logger.info("[短信发送][服务商:ALIYUN] 响应: code={}, message={}, requestId={}, bizId={}",
|
||||
response.getCode(), response.getMessage(), response.getRequestId(), response.getBizId());
|
||||
|
||||
return "OK".equalsIgnoreCase(response.getCode());
|
||||
} catch (ClientException e) {
|
||||
logger.error("[阿里云短信] 发送失败,手机号:{},模板:{},参数:{},异常:{}", phone, templateId, params, e.getMessage(), e);
|
||||
logger.error("[短信发送][服务商:ALIYUN] SDK异常,手机号:{},模板ID:{},参数:{},错误码:{},异常:{}",
|
||||
phone, templateId, params, e.getErrCode(), e.getMessage(), e);
|
||||
throw new SmsSendException("阿里云短信发送失败: " + e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
logger.error("[短信发送][服务商:ALIYUN] 失败,手机号:{},模板ID:{},参数:{},异常:{}",
|
||||
phone, templateId, params, e.getMessage(), e);
|
||||
throw new SmsSendException("阿里云短信发送失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
+42
-7
@@ -4,8 +4,13 @@ import com.central.sms.config.SmsProperties;
|
||||
import com.central.sms.exception.SmsSendException;
|
||||
import com.central.sms.service.ISmsService;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,26 +31,56 @@ public class TencentSmsService implements ISmsService {
|
||||
try {
|
||||
SmsProperties.TencentConfig config = smsProperties.getTencent();
|
||||
logger.info("[短信发送][服务商:TENCENT] 手机号={}, 模板ID={}, 参数={}", phone, templateId, params);
|
||||
|
||||
// 实例化认证对象
|
||||
Credential cred = new Credential(config.getSecretId(), config.getSecretKey());
|
||||
|
||||
// 实例化http配置
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
// 实例化客户端配置
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
/*SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
||||
|
||||
// 实例化SMS客户端
|
||||
SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
||||
|
||||
// 实例化请求对象
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
req.setSmsSdkAppId(config.getAppId());
|
||||
req.setSignName(config.getSignName());
|
||||
req.setTemplateId(templateId);
|
||||
req.setPhoneNumberSet(new String[]{phone});
|
||||
req.setTemplateParamSet(params.values().toArray(new String[0]));
|
||||
|
||||
// 设置手机号(需要加+86前缀)
|
||||
String[] phoneNumbers = new String[]{"+86" + phone};
|
||||
req.setPhoneNumberSet(phoneNumbers);
|
||||
|
||||
// 设置模板参数
|
||||
if (params != null && !params.isEmpty()) {
|
||||
req.setTemplateParamSet(params.values().toArray(new String[0]));
|
||||
}
|
||||
|
||||
// 发送短信
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
logger.info("[短信发送][服务商:TENCENT] 响应: code={}, message={}", resp.getSendStatusSet()[0].getCode(), resp.getSendStatusSet()[0].getMessage());
|
||||
return "Ok".equalsIgnoreCase(resp.getSendStatusSet()[0].getCode());*/
|
||||
return true;
|
||||
SendStatus[] statusSet = resp.getSendStatusSet();
|
||||
|
||||
if (statusSet != null && statusSet.length > 0) {
|
||||
SendStatus status = statusSet[0];
|
||||
logger.info("[短信发送][服务商:TENCENT] 响应: code={}, message={}, requestId={}",
|
||||
status.getCode(), status.getMessage(), resp.getRequestId());
|
||||
return "Ok".equalsIgnoreCase(status.getCode());
|
||||
}
|
||||
|
||||
logger.warn("[短信发送][服务商:TENCENT] 响应状态集为空");
|
||||
return false;
|
||||
} catch (TencentCloudSDKException e) {
|
||||
logger.error("[短信发送][服务商:TENCENT] SDK异常,手机号:{},模板ID:{},参数:{},错误码:{},异常:{}",
|
||||
phone, templateId, params, e.getErrorCode(), e.getMessage(), e);
|
||||
throw new SmsSendException("腾讯云短信发送失败: " + e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
logger.error("[短信发送][服务商:TENCENT] 失败,手机号:{},模板ID:{},参数:{},异常:{}", phone, templateId, params, e.getMessage(), e);
|
||||
logger.error("[短信发送][服务商:TENCENT] 失败,手机号:{},模板ID:{},参数:{},异常:{}",
|
||||
phone, templateId, params, e.getMessage(), e);
|
||||
throw new SmsSendException("腾讯云短信发送失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ export default [
|
||||
path: '/',
|
||||
component: '@/layouts/BlankLayout',
|
||||
routes: [
|
||||
// 默认跳转海事大屏
|
||||
// 默认跳转智慧城市大屏
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/maritime',
|
||||
redirect: '/dashboard',
|
||||
},
|
||||
// 通用监控大屏首页
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -57,12 +57,21 @@ body {
|
||||
/* Ant Design 覆盖 */
|
||||
.ant-layout {
|
||||
background: var(--bg-primary) !important;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ant-layout-header {
|
||||
flex: 0 0 auto;
|
||||
background: var(--bg-secondary) !important;
|
||||
}
|
||||
|
||||
.ant-layout-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ant-card {
|
||||
background: var(--bg-card) !important;
|
||||
border-color: var(--border-color) !important;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
.blank-layout {
|
||||
min-height: 100vh;
|
||||
height: 100vh;
|
||||
height: 100dvh;
|
||||
max-height: 100vh;
|
||||
max-height: 100dvh;
|
||||
overflow: hidden;
|
||||
background: var(--bg-primary);
|
||||
/* Dashboard 高度自适应:同一份变量同时驱动 Header 与 Content,避免“减去固定像素”导致不同屏幕被遮挡 */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
/* Dashboard 高度自适应:同一份变量同时驱动 Header 与 Content,避免"减去固定像素"导致不同屏幕被遮挡 */
|
||||
--dashboard-header-h: 80px;
|
||||
}
|
||||
|
||||
@@ -18,6 +24,7 @@
|
||||
}
|
||||
|
||||
.blank-header {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
@@ -27,8 +34,7 @@
|
||||
background: linear-gradient(180deg, rgba(19, 26, 61, 0.98) 0%, rgba(10, 14, 39, 0.95) 100%) !important;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
position: relative;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
@@ -100,18 +106,16 @@
|
||||
}
|
||||
|
||||
.blank-content {
|
||||
height: calc(100vh - 56px);
|
||||
height: calc(100dvh - 56px);
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
background: var(--bg-primary);
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.blank-content--dashboard {
|
||||
height: calc(100vh - var(--dashboard-header-h));
|
||||
height: calc(100dvh - var(--dashboard-header-h));
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -209,6 +213,7 @@
|
||||
}
|
||||
|
||||
.blank-header--dashboard {
|
||||
flex: 0 0 var(--dashboard-header-h);
|
||||
height: var(--dashboard-header-h);
|
||||
line-height: var(--dashboard-header-h);
|
||||
padding: 0 22px;
|
||||
@@ -218,7 +223,7 @@
|
||||
box-shadow:
|
||||
0 2px 12px rgba(0, 0, 0, 0.28),
|
||||
inset 0 -1px 0 rgba(0, 212, 255, 0.18);
|
||||
position: sticky;
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
@@ -597,12 +602,23 @@
|
||||
|
||||
.blank-content--maritime {
|
||||
height: calc(100vh - 88px);
|
||||
height: calc(100dvh - 88px);
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: linear-gradient(180deg,
|
||||
#020c1b 0%,
|
||||
#071a2f 30%,
|
||||
#0c2340 60%,
|
||||
#0f2847 100%);
|
||||
|
||||
> * {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes maritimeSweep {
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import React from 'react';
|
||||
import { Card, Tabs } from 'antd';
|
||||
import { RadarChartOutlined } from '@ant-design/icons';
|
||||
import { Radar, Line, Heatmap } from '@ant-design/plots';
|
||||
|
||||
interface CityVitalCardProps {
|
||||
radarConfig: any;
|
||||
envLineConfig: any;
|
||||
trafficHeatmapConfig: any;
|
||||
}
|
||||
|
||||
const CityVitalCard: React.FC<CityVitalCardProps> = ({
|
||||
radarConfig,
|
||||
envLineConfig,
|
||||
trafficHeatmapConfig,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span style={{ color: 'rgba(255,255,255,0.92)', display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<RadarChartOutlined style={{ color: 'rgba(0,212,255,0.95)' }} /> 城市运行体征
|
||||
</span>
|
||||
}
|
||||
style={{
|
||||
height: '100%',
|
||||
background: 'rgba(19, 26, 61, 0.7)',
|
||||
border: '1px solid rgba(0, 212, 255, 0.15)',
|
||||
borderRadius: 8,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
styles={{
|
||||
header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' },
|
||||
body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 },
|
||||
}}
|
||||
size="small"
|
||||
>
|
||||
<Tabs
|
||||
size="small"
|
||||
style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
|
||||
items={[
|
||||
{
|
||||
key: 'grid',
|
||||
label: '网格治理',
|
||||
children: (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||
<div style={{ fontSize: 12, color: 'rgba(255,255,255,0.55)', marginBottom: 8 }}>覆盖、发现、处置、复核一体化评分</div>
|
||||
<div style={{ flex: 1, minHeight: 0 }}>
|
||||
<Radar {...radarConfig} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'env',
|
||||
label: '环境感知',
|
||||
children: (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||
<div style={{ fontSize: 12, color: 'rgba(255,255,255,0.55)', marginBottom: 8 }}>空地协同采集 · 24 小时滚动</div>
|
||||
<div style={{ flex: 1, minHeight: 0 }}>
|
||||
<Line {...envLineConfig} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'traffic',
|
||||
label: '交通热力',
|
||||
children: (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||
<div style={{ fontSize: 12, color: 'rgba(255,255,255,0.55)', marginBottom: 8 }}>重点片区热度分布(网格化)</div>
|
||||
<div style={{ flex: 1, minHeight: 0 }}>
|
||||
<Heatmap {...trafficHeatmapConfig} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default CityVitalCard;
|
||||
@@ -0,0 +1,149 @@
|
||||
import React from 'react';
|
||||
import { Card, Space, Segmented, DatePicker } from 'antd';
|
||||
import { RocketOutlined } from '@ant-design/icons';
|
||||
import { Line } from '@ant-design/plots';
|
||||
import dayjs from 'dayjs';
|
||||
import './card.less';
|
||||
|
||||
interface TaskStats {
|
||||
pending: number;
|
||||
running: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
successRate: number;
|
||||
}
|
||||
|
||||
interface TrendItem {
|
||||
date: string;
|
||||
type: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface DispatchCardProps {
|
||||
taskStats: TaskStats | null;
|
||||
taskTrendData: TrendItem[];
|
||||
taskStatType: 'day' | 'month' | 'year';
|
||||
taskStatDate: dayjs.Dayjs;
|
||||
onStatTypeChange: (type: 'day' | 'month' | 'year') => void;
|
||||
onDateChange: (date: dayjs.Dayjs) => void;
|
||||
}
|
||||
|
||||
const DispatchCard: React.FC<DispatchCardProps> = ({
|
||||
taskStats,
|
||||
taskTrendData,
|
||||
taskStatType,
|
||||
taskStatDate,
|
||||
onStatTypeChange,
|
||||
onDateChange,
|
||||
}) => {
|
||||
const taskPeriodText = React.useMemo(() => {
|
||||
if (taskStatType === 'day') return '当日';
|
||||
if (taskStatType === 'month') return '当月';
|
||||
return '当年';
|
||||
}, [taskStatType]);
|
||||
|
||||
const datePickerFormat = React.useMemo(() => {
|
||||
if (taskStatType === 'day') return 'YYYY-MM-DD';
|
||||
if (taskStatType === 'month') return 'YYYY-MM';
|
||||
return 'YYYY';
|
||||
}, [taskStatType]);
|
||||
|
||||
const dispatchTrendConfig: any = React.useMemo(() => {
|
||||
return {
|
||||
data: taskTrendData,
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
appendPadding: [2, 6, 6, 4],
|
||||
smooth: true,
|
||||
color: ['#00d4ff', '#00ff88', '#ffb800'],
|
||||
xAxis: {
|
||||
label: { style: { fill: 'rgba(255,255,255,0.62)', fontSize: 10 } },
|
||||
grid: null,
|
||||
},
|
||||
yAxis: {
|
||||
label: { style: { fill: 'rgba(255,255,255,0.62)', fontSize: 10 } },
|
||||
grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } },
|
||||
},
|
||||
legend: {
|
||||
position: 'top-right',
|
||||
itemName: { style: { fill: 'rgba(255,255,255,0.72)', fontSize: 10 } },
|
||||
itemSpacing: 8,
|
||||
marker: { symbol: 'circle', style: { r: 4 } },
|
||||
},
|
||||
tooltip: { showMarkers: true },
|
||||
autoFit: true,
|
||||
};
|
||||
}, [taskTrendData]);
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span className="panel-title">
|
||||
<RocketOutlined /> {taskPeriodText}运行调度
|
||||
</span>
|
||||
}
|
||||
className="dashboard-card glass-panel"
|
||||
size="small"
|
||||
style={{ height: '100%', minHeight: 0, maxHeight: '100%' }}
|
||||
styles={{
|
||||
header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' },
|
||||
body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 },
|
||||
}}
|
||||
extra={
|
||||
<Space size={8} className="task-filter">
|
||||
<Segmented
|
||||
size="small"
|
||||
options={[
|
||||
{ label: '日', value: 'day' },
|
||||
{ label: '月', value: 'month' },
|
||||
{ label: '年', value: 'year' },
|
||||
]}
|
||||
value={taskStatType}
|
||||
onChange={(v) => onStatTypeChange(v as any)}
|
||||
/>
|
||||
<DatePicker
|
||||
size="small"
|
||||
value={taskStatDate}
|
||||
onChange={(v) => v && onDateChange(v)}
|
||||
picker={taskStatType === 'day' ? 'date' : taskStatType}
|
||||
allowClear={false}
|
||||
format={datePickerFormat}
|
||||
disabledDate={(d) => !!d && d.isAfter(dayjs(), 'day')}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<div className="dispatch-grid">
|
||||
<div className="dispatch-stat">
|
||||
<div className="dispatch-stat__val dispatch-stat__val--pending">{taskStats?.pending || 0}</div>
|
||||
<div className="dispatch-stat__lbl">待执行</div>
|
||||
</div>
|
||||
<div className="dispatch-stat">
|
||||
<div className="dispatch-stat__val dispatch-stat__val--running">{taskStats?.running || 0}</div>
|
||||
<div className="dispatch-stat__lbl">执行中</div>
|
||||
</div>
|
||||
<div className="dispatch-stat">
|
||||
<div className="dispatch-stat__val dispatch-stat__val--done">{taskStats?.completed || 0}</div>
|
||||
<div className="dispatch-stat__lbl">已完成</div>
|
||||
</div>
|
||||
<div className="dispatch-stat">
|
||||
<div className="dispatch-stat__val dispatch-stat__val--fail">{taskStats?.failed || 0}</div>
|
||||
<div className="dispatch-stat__lbl">异常</div>
|
||||
</div>
|
||||
<div className="dispatch-highlight">
|
||||
<div className="dispatch-highlight__val">{taskStats?.successRate || 0}%</div>
|
||||
<div className="dispatch-highlight__lbl">成功率</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="dispatch-trend">
|
||||
<div className="dispatch-trend__title">近 7 日任务趋势</div>
|
||||
<div className="chart-wrapper">
|
||||
<Line {...dispatchTrendConfig} />
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default DispatchCard;
|
||||
@@ -0,0 +1,303 @@
|
||||
import React from 'react';
|
||||
import { Card, Tabs, Carousel, Empty, Tag, Progress } from 'antd';
|
||||
import { AlertOutlined } from '@ant-design/icons';
|
||||
import { Pie } from '@ant-design/plots';
|
||||
import './card.less';
|
||||
|
||||
interface AiSnapshot {
|
||||
id: string;
|
||||
tag: string;
|
||||
timeText: string;
|
||||
title: string;
|
||||
location: string;
|
||||
confidence: number;
|
||||
severity: string;
|
||||
}
|
||||
|
||||
interface RegionCoverage {
|
||||
id: string;
|
||||
name: string;
|
||||
coverage: number;
|
||||
pending: number;
|
||||
risk: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
interface DroneInsightCardProps {
|
||||
aiSnapshots: AiSnapshot[];
|
||||
fleet: {
|
||||
avgBattery: number;
|
||||
lowBatteryAlerts: number;
|
||||
flightHoursToday: number;
|
||||
flightMileageToday: number;
|
||||
dockOnline: number;
|
||||
dockTotal: number;
|
||||
droneInFlight: number;
|
||||
droneStandby: number;
|
||||
droneMaintenance: number;
|
||||
droneOnline: number;
|
||||
droneTotal: number;
|
||||
};
|
||||
airspace: {
|
||||
complianceIndex: number;
|
||||
safetyIndex: number;
|
||||
geofenceTriggers: number;
|
||||
noFlyWarnings: number;
|
||||
approvalsToday: number;
|
||||
approvalsPassRate: number;
|
||||
};
|
||||
regionCoverage: RegionCoverage[];
|
||||
compactLevel: 0 | 1 | 2;
|
||||
snapshotsPerPage: number;
|
||||
airspaceGaugeSize: number;
|
||||
}
|
||||
|
||||
const regionRiskColor = (risk: string) => {
|
||||
if (risk === 'critical') return '#ff4757';
|
||||
if (risk === 'warning') return '#ffb800';
|
||||
return '#00ff88';
|
||||
};
|
||||
|
||||
const DroneInsightCard: React.FC<DroneInsightCardProps> = ({
|
||||
aiSnapshots,
|
||||
fleet,
|
||||
airspace,
|
||||
regionCoverage,
|
||||
compactLevel,
|
||||
snapshotsPerPage,
|
||||
airspaceGaugeSize,
|
||||
}) => {
|
||||
const droneStatusPieConfig: any = React.useMemo(() => {
|
||||
const total = fleet.droneInFlight + fleet.droneStandby + fleet.droneMaintenance;
|
||||
if (!total) return {};
|
||||
return {
|
||||
data: [
|
||||
{ type: '在飞', value: fleet.droneInFlight },
|
||||
{ type: '待命', value: fleet.droneStandby },
|
||||
{ type: '维护', value: fleet.droneMaintenance },
|
||||
],
|
||||
angleField: 'value',
|
||||
colorField: 'type',
|
||||
radius: 0.92,
|
||||
innerRadius: 0.62,
|
||||
color: ['rgba(157, 78, 221, 0.95)', 'rgba(0, 212, 255, 0.9)', 'rgba(255, 184, 0, 0.92)'],
|
||||
legend: false,
|
||||
label: false,
|
||||
statistic: {
|
||||
title: false,
|
||||
content: {
|
||||
style: { color: 'rgba(255,255,255,0.88)', fontSize: 18, fontWeight: 700, whiteSpace: 'pre-line' },
|
||||
content: `${fleet.droneOnline}/${fleet.droneTotal}\n在线`,
|
||||
},
|
||||
},
|
||||
autoFit: true,
|
||||
};
|
||||
}, [fleet]);
|
||||
|
||||
const visibleRegionCoverage = React.useMemo(() => {
|
||||
const max = compactLevel === 2 ? 2 : compactLevel === 1 ? 4 : 6;
|
||||
return regionCoverage.slice(0, max);
|
||||
}, [regionCoverage, compactLevel]);
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span className="panel-title">
|
||||
<AlertOutlined /> 无人机态势与AI洞察
|
||||
</span>
|
||||
}
|
||||
className="dashboard-card glass-panel"
|
||||
size="small"
|
||||
style={{ height: '100%', minHeight: 0, maxHeight: '100%' }}
|
||||
styles={{
|
||||
header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' },
|
||||
body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 },
|
||||
}}
|
||||
>
|
||||
<Tabs
|
||||
size="small"
|
||||
className="dash-tabs"
|
||||
defaultActiveKey="fleet"
|
||||
items={[
|
||||
{
|
||||
key: 'fleet',
|
||||
label: '机队态势',
|
||||
children: (
|
||||
<div className="tab-pane fleet-pane">
|
||||
<div className="fleet-metrics">
|
||||
<div className="fleet-metric">
|
||||
<div className="fleet-metric__label">平均电量</div>
|
||||
<div className="fleet-metric__value">{fleet.avgBattery}%</div>
|
||||
<div className="fleet-metric__sub">低电 {fleet.lowBatteryAlerts} 起</div>
|
||||
</div>
|
||||
<div className="fleet-metric">
|
||||
<div className="fleet-metric__label">飞行时长</div>
|
||||
<div className="fleet-metric__value">{fleet.flightHoursToday}h</div>
|
||||
<div className="fleet-metric__sub">今日累计</div>
|
||||
</div>
|
||||
<div className="fleet-metric">
|
||||
<div className="fleet-metric__label">飞行里程</div>
|
||||
<div className="fleet-metric__value">{fleet.flightMileageToday}km</div>
|
||||
<div className="fleet-metric__sub">含航线复飞</div>
|
||||
</div>
|
||||
<div className="fleet-metric">
|
||||
<div className="fleet-metric__label">可用机库</div>
|
||||
<div className="fleet-metric__value">
|
||||
{fleet.dockOnline}/{fleet.dockTotal}
|
||||
</div>
|
||||
<div className="fleet-metric__sub">在线/总量</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="fleet-split">
|
||||
<div className="fleet-split__left">
|
||||
<div className="panel-subtitle">机队状态占比</div>
|
||||
<div className="chart-wrapper">
|
||||
{Object.keys(droneStatusPieConfig).length ? (
|
||||
<Pie {...droneStatusPieConfig} />
|
||||
) : (
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无无人机数据" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="fleet-split__right">
|
||||
<div className="panel-subtitle">重点区域覆盖</div>
|
||||
<div className="region-list">
|
||||
{visibleRegionCoverage.map((r) => (
|
||||
<div key={r.id} className="region-item">
|
||||
<div className="region-item__head">
|
||||
<span className="region-item__name">{r.name}</span>
|
||||
<span className="region-item__meta">
|
||||
<Tag className="region-item__tag" color={regionRiskColor(r.risk)}>
|
||||
{r.risk === 'critical' ? '高风险' : r.risk === 'warning' ? '关注' : '正常'}
|
||||
</Tag>
|
||||
<span className="region-item__time">{r.updatedAt}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="region-item__bar">
|
||||
<Progress
|
||||
percent={r.coverage}
|
||||
size="small"
|
||||
showInfo={false}
|
||||
strokeColor={regionRiskColor(r.risk)}
|
||||
trailColor="rgba(255,255,255,0.08)"
|
||||
/>
|
||||
<span className="region-item__pct">{r.coverage}%</span>
|
||||
<span className="region-item__pending">待处置 {r.pending}</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'snap',
|
||||
label: 'AI快照',
|
||||
children: (
|
||||
<div className="tab-pane">
|
||||
<Carousel autoplay autoplaySpeed={5500} dots className="snapshot-carousel">
|
||||
{new Array(Math.max(1, Math.ceil(aiSnapshots.length / snapshotsPerPage)))
|
||||
.fill(0)
|
||||
.map((_, pageIdx) => {
|
||||
const start = pageIdx * snapshotsPerPage;
|
||||
const page = aiSnapshots.slice(start, start + snapshotsPerPage);
|
||||
return (
|
||||
<div key={`page-${pageIdx}`} className="snapshot-page">
|
||||
<div className="snapshot-grid">
|
||||
{page.map((s) => (
|
||||
<div key={s.id} className={`snapshot-card snapshot-card--${s.severity}`}>
|
||||
<div className="snapshot-card__head">
|
||||
<span className="snapshot-card__tag">{s.tag}</span>
|
||||
<span className="snapshot-card__time">{s.timeText}</span>
|
||||
</div>
|
||||
<div className="snapshot-card__title">{s.title}</div>
|
||||
<div className="snapshot-card__meta">
|
||||
<span className="snapshot-card__loc">{s.location}</span>
|
||||
<span className="snapshot-card__conf">置信度 {s.confidence}%</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</Carousel>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'airspace',
|
||||
label: '空域合规',
|
||||
children: (
|
||||
<div className="tab-pane airspace-pane">
|
||||
<div className="airspace-top">
|
||||
<div className="airspace-score">
|
||||
<Progress
|
||||
type="dashboard"
|
||||
percent={airspace.complianceIndex}
|
||||
strokeColor={{
|
||||
'0%': 'rgba(255, 71, 87, 0.95)',
|
||||
'55%': 'rgba(255, 184, 0, 0.95)',
|
||||
'100%': 'rgba(0, 255, 136, 0.95)',
|
||||
}}
|
||||
trailColor="rgba(255,255,255,0.08)"
|
||||
size={airspaceGaugeSize}
|
||||
/>
|
||||
<div className="airspace-score__meta">
|
||||
<div className="airspace-score__title">合规指数</div>
|
||||
<div className="airspace-score__sub">围栏/禁飞/审批综合</div>
|
||||
<div className="airspace-score__sub">城市安全指数 {airspace.safetyIndex}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="airspace-metrics">
|
||||
<div className="airspace-metric">
|
||||
<div className="airspace-metric__val">{airspace.geofenceTriggers}</div>
|
||||
<div className="airspace-metric__lbl">围栏触发</div>
|
||||
</div>
|
||||
<div className="airspace-metric">
|
||||
<div className="airspace-metric__val">{airspace.noFlyWarnings}</div>
|
||||
<div className="airspace-metric__lbl">禁飞预警</div>
|
||||
</div>
|
||||
<div className="airspace-metric">
|
||||
<div className="airspace-metric__val">{airspace.approvalsToday}</div>
|
||||
<div className="airspace-metric__lbl">今日审批</div>
|
||||
</div>
|
||||
<div className="airspace-metric">
|
||||
<div className="airspace-metric__val">{airspace.approvalsPassRate}%</div>
|
||||
<div className="airspace-metric__lbl">通过率</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="airspace-notes">
|
||||
<div className="airspace-note">
|
||||
<span className="airspace-note__dot" />
|
||||
<span className="airspace-note__text">重点区域启用"低空走廊",优先保障应急任务快速通行。</span>
|
||||
</div>
|
||||
{compactLevel === 2 ? null : (
|
||||
<>
|
||||
<div className="airspace-note">
|
||||
<span className="airspace-note__dot airspace-note__dot--warn" />
|
||||
<span className="airspace-note__text">围栏触发或禁飞预警上升时,建议自动降级为"复核模式"。</span>
|
||||
</div>
|
||||
<div className="airspace-note">
|
||||
<span className="airspace-note__dot airspace-note__dot--ok" />
|
||||
<span className="airspace-note__text">审批通过率稳定后,可扩大夜航与多机协同策略的投放比例。</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default DroneInsightCard;
|
||||
@@ -0,0 +1,260 @@
|
||||
import React from 'react';
|
||||
import { Card, Tabs, Empty } from 'antd';
|
||||
import { EnvironmentOutlined } from '@ant-design/icons';
|
||||
import { Funnel, RadialBar, Pie, Column, Rose, Line } from '@ant-design/plots';
|
||||
import './card.less';
|
||||
|
||||
interface EventInsightCardProps {
|
||||
eventFunnelData: any[];
|
||||
eventTypeData: any[];
|
||||
terminalPieData: any[];
|
||||
taskTypeData: any[];
|
||||
failureAnalysisData: any[];
|
||||
annualData: any[];
|
||||
}
|
||||
|
||||
const EventInsightCard: React.FC<EventInsightCardProps> = ({
|
||||
eventFunnelData,
|
||||
eventTypeData,
|
||||
terminalPieData,
|
||||
taskTypeData,
|
||||
failureAnalysisData,
|
||||
annualData,
|
||||
}) => {
|
||||
const funnelConfig: any = React.useMemo(() => {
|
||||
return {
|
||||
data: eventFunnelData,
|
||||
xField: 'stage',
|
||||
yField: 'value',
|
||||
legend: false,
|
||||
conversionTag: false,
|
||||
tooltip: {
|
||||
formatter: (d: any) => ({ name: d?.stage ?? d?.name ?? '阶段', value: d?.value ?? 0 }),
|
||||
},
|
||||
label: {
|
||||
formatter: (d: any) => {
|
||||
const stage = d?.stage ?? d?.name ?? d?.type ?? '阶段';
|
||||
const value = d?.value ?? d?.count ?? 0;
|
||||
return `${stage} ${value}`;
|
||||
},
|
||||
content: (d: any) => {
|
||||
const stage = d?.stage ?? d?.name ?? d?.type ?? '阶段';
|
||||
const value = d?.value ?? d?.count ?? 0;
|
||||
return `${stage} ${value}`;
|
||||
},
|
||||
style: { fill: 'rgba(255,255,255,0.78)', fontSize: 12 },
|
||||
},
|
||||
color: ['#00d4ff', '#00ff88', '#ffb800', '#9d4edd', '#00d4ff'],
|
||||
autoFit: true,
|
||||
};
|
||||
}, [eventFunnelData]);
|
||||
|
||||
const eventRadialConfig: any = React.useMemo(() => {
|
||||
return {
|
||||
data: eventTypeData,
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
radius: 0.88,
|
||||
innerRadius: 0.25,
|
||||
colorField: 'type',
|
||||
color: ['#00d4ff', '#00ff88', '#ffb800', '#9d4edd', '#ff4757', '#13c2c2'],
|
||||
legend: false,
|
||||
label: { style: { fill: 'rgba(255,255,255,0.72)' } },
|
||||
autoFit: true,
|
||||
};
|
||||
}, [eventTypeData]);
|
||||
|
||||
const terminalPieConfig: any = React.useMemo(() => {
|
||||
const data = terminalPieData || [];
|
||||
return {
|
||||
data,
|
||||
angleField: 'count',
|
||||
colorField: 'name',
|
||||
radius: 0.8,
|
||||
innerRadius: 0.58,
|
||||
label: {
|
||||
text: (datum: any) => {
|
||||
const total = data.reduce((sum, d) => sum + (d.count || 0), 0);
|
||||
const count = datum?.count ?? 0;
|
||||
const percent = total > 0 ? ((count / total) * 100).toFixed(0) : '0';
|
||||
return `${datum?.name || ''} ${percent}%`;
|
||||
},
|
||||
style: { fill: 'rgba(255,255,255,0.7)' },
|
||||
},
|
||||
legend: false,
|
||||
autoFit: true,
|
||||
};
|
||||
}, [terminalPieData]);
|
||||
|
||||
const taskTypeColumnConfig: any = React.useMemo(() => {
|
||||
return {
|
||||
data: taskTypeData,
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
columnWidthRatio: 0.55,
|
||||
color: ['#00d4ff'],
|
||||
label: { style: { fill: 'rgba(255,255,255,0.85)' } },
|
||||
xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } } },
|
||||
yAxis: {
|
||||
label: { style: { fill: 'rgba(255,255,255,0.62)' } },
|
||||
grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } },
|
||||
},
|
||||
legend: false,
|
||||
autoFit: true,
|
||||
};
|
||||
}, [taskTypeData]);
|
||||
|
||||
const riskRoseConfig: any = React.useMemo(() => {
|
||||
return {
|
||||
data: failureAnalysisData,
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
radius: 0.85,
|
||||
innerRadius: 0.25,
|
||||
colorField: 'type',
|
||||
color: ['#ffb800', '#00d4ff', '#00ff88', '#9d4edd', '#ff4757', '#13c2c2'],
|
||||
label: {
|
||||
content: (d: any) => `${d.type}\n${d.value}`,
|
||||
style: { fill: 'rgba(255,255,255,0.72)' },
|
||||
},
|
||||
legend: false,
|
||||
autoFit: true,
|
||||
};
|
||||
}, [failureAnalysisData]);
|
||||
|
||||
const annualLineConfig: any = React.useMemo(() => {
|
||||
return {
|
||||
data: annualData,
|
||||
xField: 'month',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
smooth: true,
|
||||
color: ['#00d4ff', '#00ff88'],
|
||||
areaStyle: { fillOpacity: 0.12 },
|
||||
xAxis: { label: { style: { fill: 'rgba(255,255,255,0.62)' } } },
|
||||
yAxis: {
|
||||
label: { style: { fill: 'rgba(255,255,255,0.62)' } },
|
||||
grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } },
|
||||
},
|
||||
legend: { position: 'top', itemName: { style: { fill: 'rgba(255,255,255,0.72)' } } },
|
||||
autoFit: true,
|
||||
};
|
||||
}, [annualData]);
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span className="panel-title">
|
||||
<EnvironmentOutlined /> 事件处置与洞察
|
||||
</span>
|
||||
}
|
||||
className="dashboard-card glass-panel"
|
||||
size="small"
|
||||
style={{ height: '100%', minHeight: 0, maxHeight: '100%' }}
|
||||
styles={{
|
||||
header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' },
|
||||
body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 },
|
||||
}}
|
||||
>
|
||||
<Tabs
|
||||
size="small"
|
||||
className="dash-tabs"
|
||||
items={[
|
||||
{
|
||||
key: 'funnel',
|
||||
label: '处置闭环',
|
||||
children: (
|
||||
<div className="tab-pane">
|
||||
<div className="chart-wrapper">
|
||||
<Funnel {...funnelConfig} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'types',
|
||||
label: '类型分布',
|
||||
children: (
|
||||
<div className="tab-pane">
|
||||
<div className="chart-wrapper">
|
||||
<RadialBar {...eventRadialConfig} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'asset',
|
||||
label: '资产构成',
|
||||
children: terminalPieData?.length ? (
|
||||
<div className="tab-pane">
|
||||
<div className="chart-wrapper">
|
||||
<Pie {...terminalPieConfig} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="tab-pane">
|
||||
<div className="empty-holder">
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无资产数据" />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'capacity',
|
||||
label: '作业结构',
|
||||
children: taskTypeData?.length ? (
|
||||
<div className="tab-pane">
|
||||
<div className="chart-wrapper">
|
||||
<Column {...taskTypeColumnConfig} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="tab-pane">
|
||||
<div className="empty-holder">
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无结构数据" />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'risk',
|
||||
label: '风险画像',
|
||||
children: failureAnalysisData?.length ? (
|
||||
<div className="tab-pane">
|
||||
<div className="chart-wrapper">
|
||||
<Rose {...riskRoseConfig} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="tab-pane">
|
||||
<div className="empty-holder">
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无风险数据" />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'year',
|
||||
label: '年度趋势',
|
||||
children: annualData?.length ? (
|
||||
<div className="tab-pane">
|
||||
<div className="chart-wrapper">
|
||||
<Line {...annualLineConfig} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="tab-pane">
|
||||
<div className="empty-holder">
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无年度数据" />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default EventInsightCard;
|
||||
@@ -0,0 +1,93 @@
|
||||
import React from 'react';
|
||||
import { Card, List, Tag, Empty } from 'antd';
|
||||
import { AlertOutlined } from '@ant-design/icons';
|
||||
|
||||
interface EventItem {
|
||||
id: string;
|
||||
title: string;
|
||||
timeText: string;
|
||||
location: string;
|
||||
status: string;
|
||||
source: string;
|
||||
desc: string;
|
||||
severity: string;
|
||||
}
|
||||
|
||||
interface EventStreamCardProps {
|
||||
events: EventItem[];
|
||||
}
|
||||
|
||||
const severityColor = (severity: string) => {
|
||||
if (severity === 'critical') return '#ff4757';
|
||||
if (severity === 'warning') return '#ffb800';
|
||||
return '#00d4ff';
|
||||
};
|
||||
|
||||
const statusTagColor = (status: string) => {
|
||||
if (status === '已闭环') return '#00ff88';
|
||||
if (status === '处理中') return '#9d4edd';
|
||||
if (status === '已派单') return '#00d4ff';
|
||||
return 'rgba(255,255,255,0.25)';
|
||||
};
|
||||
|
||||
const EventStreamCard: React.FC<EventStreamCardProps> = ({ events }) => {
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span style={{ color: 'rgba(255,255,255,0.92)', display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<AlertOutlined style={{ color: 'rgba(0,212,255,0.95)' }} /> 城市事件流
|
||||
</span>
|
||||
}
|
||||
extra={<Tag color="cyan">实时</Tag>}
|
||||
style={{
|
||||
height: '100%',
|
||||
background: 'rgba(19, 26, 61, 0.7)',
|
||||
border: '1px solid rgba(0, 212, 255, 0.15)',
|
||||
borderRadius: 8,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
styles={{
|
||||
header: { flex: '0 0 auto', minHeight: 40, padding: '0 12px', borderBottom: '1px solid rgba(0, 212, 255, 0.1)' },
|
||||
body: { flex: 1, padding: 12, overflow: 'hidden', display: 'flex', flexDirection: 'column', minHeight: 0 },
|
||||
}}
|
||||
size="small"
|
||||
>
|
||||
<div style={{ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden' }}>
|
||||
<List
|
||||
dataSource={events}
|
||||
split={false}
|
||||
locale={{ emptyText: <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无事件" /> }}
|
||||
renderItem={(item) => (
|
||||
<List.Item style={{ padding: '10px 0', borderBottom: '1px solid rgba(255,255,255,0.06)' }}>
|
||||
<div style={{ display: 'flex', gap: 10, alignItems: 'flex-start', width: '100%' }}>
|
||||
<div style={{
|
||||
width: 8,
|
||||
height: 8,
|
||||
borderRadius: '50%',
|
||||
marginTop: 6,
|
||||
background: severityColor(item.severity),
|
||||
flexShrink: 0,
|
||||
}} />
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 10, marginBottom: 4 }}>
|
||||
<span style={{ fontSize: 13, fontWeight: 600, color: 'rgba(255,255,255,0.92)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{item.title}</span>
|
||||
<span style={{ fontSize: 12, color: 'rgba(255,255,255,0.55)', fontFamily: 'monospace' }}>{item.timeText}</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center', marginBottom: 4 }}>
|
||||
<span style={{ fontSize: 12, color: 'rgba(255,255,255,0.65)' }}>{item.location}</span>
|
||||
<Tag color={statusTagColor(item.status)} style={{ marginRight: 0 }}>{item.status}</Tag>
|
||||
<Tag color="rgba(0,212,255,0.18)" style={{ marginRight: 0 }}>{item.source}</Tag>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: 'rgba(255,255,255,0.56)', lineHeight: 1.3 }}>{item.desc}</div>
|
||||
</div>
|
||||
</div>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default EventStreamCard;
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from 'react';
|
||||
import './card.less';
|
||||
|
||||
interface KpiItem {
|
||||
key: string;
|
||||
label: string;
|
||||
value: string | number;
|
||||
unit?: string;
|
||||
sub?: string;
|
||||
accent?: string;
|
||||
}
|
||||
|
||||
interface KpiStripProps {
|
||||
kpis: KpiItem[];
|
||||
}
|
||||
|
||||
const KpiStrip: React.FC<KpiStripProps> = ({ kpis }) => {
|
||||
return (
|
||||
<div className="kpi-strip">
|
||||
{kpis.map((kpi) => (
|
||||
<div key={kpi.key} className={`kpi-tile kpi-tile--${kpi.accent || 'blue'}`}>
|
||||
<div className="kpi-tile__head">
|
||||
<span className="kpi-tile__label">{kpi.label}</span>
|
||||
<span className="kpi-tile__dot" />
|
||||
</div>
|
||||
<div className="kpi-tile__value">
|
||||
<span className="kpi-tile__num">{kpi.value}</span>
|
||||
{kpi.unit ? <span className="kpi-tile__unit">{kpi.unit}</span> : null}
|
||||
</div>
|
||||
{kpi.sub ? <div className="kpi-tile__sub">{kpi.sub}</div> : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default KpiStrip;
|
||||
@@ -0,0 +1,99 @@
|
||||
import React from 'react';
|
||||
import { Button, Tag } from 'antd';
|
||||
import { SafetyCertificateOutlined, AimOutlined, EnvironmentOutlined } from '@ant-design/icons';
|
||||
import { history } from 'umi';
|
||||
import './card.less';
|
||||
|
||||
interface TwinPortalProps {
|
||||
fleet: {
|
||||
droneOnline: number;
|
||||
droneInFlight: number;
|
||||
dockOnline: number;
|
||||
};
|
||||
airspace: {
|
||||
complianceIndex: number;
|
||||
};
|
||||
compactLevel: 0 | 1 | 2;
|
||||
}
|
||||
|
||||
const TwinPortal: React.FC<TwinPortalProps> = ({ fleet, airspace, compactLevel }) => {
|
||||
const goTo3D = () => {
|
||||
history.push('/map3d?from=dashboard');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="twin-portal">
|
||||
<div className="twin-portal__grid" />
|
||||
<div className="twin-portal__sweep" />
|
||||
<div className="twin-portal__overlay">
|
||||
<div className="twin-portal__top">
|
||||
{compactLevel === 2 ? (
|
||||
<div className="twin-portal__tags">
|
||||
<Tag color="cyan">事件点位</Tag>
|
||||
<Tag color="green">AI识别</Tag>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="twin-portal__tags">
|
||||
<Tag color="cyan">事件点位</Tag>
|
||||
<Tag color="geekblue">航线叠加</Tag>
|
||||
<Tag color="purple">电子围栏</Tag>
|
||||
<Tag color="green">AI识别</Tag>
|
||||
</div>
|
||||
<div className="twin-portal__chips">
|
||||
<span className="chip">
|
||||
<SafetyCertificateOutlined /> 安全态势
|
||||
</span>
|
||||
<span className="chip">
|
||||
<AimOutlined /> 空域管理
|
||||
</span>
|
||||
<span className="chip">
|
||||
<EnvironmentOutlined /> 数字孪生
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="twin-portal__center">
|
||||
<div className="twin-portal__title">全域数字孪生中枢</div>
|
||||
<div className="twin-portal__desc">空地协同巡检 · 城市事件识别 · 应急快速响应</div>
|
||||
<Button type="primary" shape="round" size="large" onClick={goTo3D} className="twin-portal__btn">
|
||||
进入 3D 监控视图
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="twin-portal__bottom">
|
||||
<div className="mini-metric">
|
||||
<span className="mini-metric__label">在线无人机</span>
|
||||
<span className="mini-metric__value">{fleet.droneOnline}</span>
|
||||
</div>
|
||||
<div className="mini-metric">
|
||||
<span className="mini-metric__label">在飞架次</span>
|
||||
<span className="mini-metric__value">{fleet.droneInFlight}</span>
|
||||
</div>
|
||||
{compactLevel === 2 ? null : (
|
||||
<>
|
||||
<div className="mini-metric">
|
||||
<span className="mini-metric__label">可用机库</span>
|
||||
<span className="mini-metric__value">{fleet.dockOnline}</span>
|
||||
</div>
|
||||
<div className="mini-metric">
|
||||
<span className="mini-metric__label">合规指数</span>
|
||||
<span
|
||||
className={`mini-metric__value${
|
||||
airspace.complianceIndex < 85 ? ' mini-metric__value--warn' : ''
|
||||
}`}
|
||||
>
|
||||
{airspace.complianceIndex}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TwinPortal;
|
||||
@@ -0,0 +1,733 @@
|
||||
/* 组件级样式 - 每个卡片独立管理高度 */
|
||||
|
||||
.dashboard-card {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
max-height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: transparent !important;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
|
||||
&.glass-panel {
|
||||
position: relative;
|
||||
background: rgba(19, 26, 61, 0.7) !important;
|
||||
border: 1px solid rgba(0, 212, 255, 0.15) !important;
|
||||
backdrop-filter: blur(8px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
background:
|
||||
linear-gradient(90deg, rgba(0, 212, 255, 0.6), transparent 60px) top left / 60px 2px no-repeat,
|
||||
linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 60px) top left / 2px 60px no-repeat,
|
||||
linear-gradient(270deg, rgba(0, 212, 255, 0.6), transparent 60px) top right / 60px 2px no-repeat,
|
||||
linear-gradient(180deg, rgba(0, 212, 255, 0.6), transparent 60px) top right / 2px 60px no-repeat,
|
||||
linear-gradient(90deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom left / 60px 2px no-repeat,
|
||||
linear-gradient(0deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom left / 2px 60px no-repeat,
|
||||
linear-gradient(270deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom right / 60px 2px no-repeat,
|
||||
linear-gradient(0deg, rgba(0, 212, 255, 0.6), transparent 60px) bottom right / 2px 60px no-repeat;
|
||||
opacity: 0.35;
|
||||
}
|
||||
}
|
||||
|
||||
:global(.ant-card-head) {
|
||||
min-height: 40px;
|
||||
padding: 0 12px;
|
||||
border-bottom: 1px solid rgba(0, 212, 255, 0.1);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
:global(.ant-card-body) {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 事件列表滚动容器 */
|
||||
.event-list-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 212, 255, 0.22);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
:global(.ant-list) {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
:global(.ant-spin-nested-loading),
|
||||
:global(.ant-spin-container) {
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* 通用样式复用 */
|
||||
.panel-title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
|
||||
:global(.anticon) {
|
||||
color: rgba(0, 212, 255, 0.95);
|
||||
}
|
||||
}
|
||||
|
||||
.panel-subtitle {
|
||||
margin: -2px 0 8px;
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
|
||||
> div {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
:global(canvas) {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tabs 样式 */
|
||||
.dash-tabs {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
|
||||
:global(.ant-tabs-nav) {
|
||||
margin: 0 0 8px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
:global(.ant-tabs-nav::before) {
|
||||
border-bottom-color: rgba(0, 212, 255, 0.12);
|
||||
}
|
||||
|
||||
:global(.ant-tabs-tab) {
|
||||
color: rgba(255, 255, 255, 0.62);
|
||||
}
|
||||
|
||||
:global(.ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn) {
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
}
|
||||
|
||||
:global(.ant-tabs-ink-bar) {
|
||||
background: rgba(0, 212, 255, 0.9);
|
||||
}
|
||||
|
||||
:global(.ant-tabs-content-holder) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
:global(.ant-tabs-content) {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
:global(.ant-tabs-tabpane) {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.tab-pane {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.empty-holder {
|
||||
height: 100%;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
/* 事件列表项样式 */
|
||||
.event-item {
|
||||
padding: 10px 0 !important;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
|
||||
}
|
||||
|
||||
.event-item__row {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.event-item__badge {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
margin-top: 6px;
|
||||
box-shadow: 0 0 12px rgba(0, 0, 0, 0.22);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.event-item__content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.event-item__head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.event-item__title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.event-item__time {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.event-item__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.event-item__loc {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
}
|
||||
|
||||
.event-item__tag {
|
||||
margin-inline-end: 0 !important;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12) !important;
|
||||
color: rgba(255, 255, 255, 0.82) !important;
|
||||
}
|
||||
|
||||
.event-item__desc {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.56);
|
||||
line-height: 1.3;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 任务筛选器样式 */
|
||||
.task-filter {
|
||||
:global(.ant-segmented) {
|
||||
background: rgba(0, 212, 255, 0.06);
|
||||
border: 1px solid rgba(0, 212, 255, 0.18);
|
||||
}
|
||||
|
||||
:global(.ant-segmented-item-label) {
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
:global(.ant-segmented-item-selected) {
|
||||
background: rgba(0, 212, 255, 0.22) !important;
|
||||
}
|
||||
|
||||
:global(.ant-picker) {
|
||||
background: rgba(0, 212, 255, 0.06);
|
||||
border: 1px solid rgba(0, 212, 255, 0.18);
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
|
||||
:global(.ant-picker-input > input) {
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
:global(.ant-picker-suffix) {
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dispatch 样式 */
|
||||
.dispatch-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.dispatch-stat {
|
||||
padding: 8px 10px;
|
||||
border-radius: 10px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.dispatch-stat__val {
|
||||
font-size: 18px;
|
||||
font-weight: 800;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.dispatch-stat__lbl {
|
||||
margin-top: 2px;
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.dispatch-stat__val--pending { color: rgba(255, 184, 0, 0.92); }
|
||||
.dispatch-stat__val--running { color: rgba(0, 212, 255, 0.92); }
|
||||
.dispatch-stat__val--done { color: rgba(0, 255, 136, 0.92); }
|
||||
.dispatch-stat__val--fail { color: rgba(255, 71, 87, 0.92); }
|
||||
|
||||
.dispatch-highlight {
|
||||
grid-column: 1 / -1;
|
||||
padding: 8px 12px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(0, 255, 136, 0.18);
|
||||
background:
|
||||
radial-gradient(circle at 20% 20%, rgba(0, 255, 136, 0.12), transparent 55%),
|
||||
linear-gradient(180deg, rgba(19, 26, 61, 0.78), rgba(10, 14, 39, 0.62));
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.dispatch-highlight__val {
|
||||
font-size: clamp(20px, 3vh, 28px);
|
||||
font-weight: 900;
|
||||
color: rgba(0, 255, 136, 0.92);
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.dispatch-highlight__lbl {
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.60);
|
||||
}
|
||||
|
||||
.dispatch-trend {
|
||||
margin-top: 8px;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dispatch-trend .chart-wrapper {
|
||||
flex: 1;
|
||||
min-height: 80px;
|
||||
padding: 0 4px 4px;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dispatch-trend__title {
|
||||
margin-bottom: 4px;
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.56);
|
||||
}
|
||||
|
||||
/* 机队态势样式 */
|
||||
.fleet-pane {
|
||||
gap: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.fleet-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.fleet-metric {
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
background:
|
||||
radial-gradient(circle at 25% 20%, rgba(0, 212, 255, 0.14), transparent 55%),
|
||||
linear-gradient(180deg, rgba(19, 26, 61, 0.74), rgba(10, 14, 39, 0.62));
|
||||
}
|
||||
|
||||
.fleet-metric__label {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.58);
|
||||
}
|
||||
|
||||
.fleet-metric__value {
|
||||
margin-top: 6px;
|
||||
font-size: 22px;
|
||||
font-weight: 800;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.fleet-metric__sub {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.52);
|
||||
}
|
||||
|
||||
.fleet-split {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.fleet-split__left,
|
||||
.fleet-split__right {
|
||||
min-height: 0;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
padding: 10px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.region-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
padding-right: 2px;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 212, 255, 0.18);
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.region-item {
|
||||
padding: 8px 10px 6px;
|
||||
border-radius: 10px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.region-item__head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.region-item__name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.region-item__meta {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.region-item__tag {
|
||||
margin-inline-end: 0 !important;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12) !important;
|
||||
color: rgba(255, 255, 255, 0.86) !important;
|
||||
}
|
||||
|
||||
.region-item__time {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.region-item__bar {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto auto;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
:global(.ant-progress) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.region-item__pct {
|
||||
width: 48px;
|
||||
text-align: right;
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.region-item__pending {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.52);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 空域合规样式 */
|
||||
.airspace-pane {
|
||||
gap: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.airspace-top {
|
||||
display: grid;
|
||||
grid-template-columns: 1.1fr 1fr;
|
||||
gap: 12px;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.airspace-score {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
background:
|
||||
radial-gradient(circle at 18% 24%, rgba(0, 255, 136, 0.10), transparent 55%),
|
||||
linear-gradient(180deg, rgba(19, 26, 61, 0.72), rgba(10, 14, 39, 0.62));
|
||||
|
||||
:global(.ant-progress) {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
.airspace-score__meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.airspace-score__title {
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.airspace-score__sub {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.airspace-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.airspace-metric {
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
|
||||
.airspace-metric__val {
|
||||
font-size: 22px;
|
||||
font-weight: 800;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.airspace-metric__lbl {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.airspace-notes {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.airspace-note {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.airspace-note__dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
margin-top: 6px;
|
||||
background: rgba(0, 212, 255, 0.9);
|
||||
box-shadow: 0 0 10px rgba(0, 212, 255, 0.25);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.airspace-note__dot--warn {
|
||||
background: rgba(255, 184, 0, 0.92);
|
||||
box-shadow: 0 0 10px rgba(255, 184, 0, 0.25);
|
||||
}
|
||||
|
||||
.airspace-note__dot--ok {
|
||||
background: rgba(0, 255, 136, 0.92);
|
||||
box-shadow: 0 0 10px rgba(0, 255, 136, 0.25);
|
||||
}
|
||||
|
||||
.airspace-note__text {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.62);
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
/* AI快照样式 */
|
||||
.snapshot-carousel {
|
||||
height: 100%;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
:global(.slick-dots) {
|
||||
bottom: -2px;
|
||||
}
|
||||
|
||||
:global(.slick-dots li button) {
|
||||
background: rgba(255, 255, 255, 0.25) !important;
|
||||
}
|
||||
|
||||
:global(.slick-dots li.slick-active button) {
|
||||
background: rgba(0, 212, 255, 0.85) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.snapshot-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.snapshot-card {
|
||||
border-radius: 12px;
|
||||
padding: 12px 12px 10px;
|
||||
border: 1px solid rgba(0, 212, 255, 0.16);
|
||||
background:
|
||||
radial-gradient(circle at 20% 10%, rgba(0, 212, 255, 0.16), transparent 55%),
|
||||
linear-gradient(180deg, rgba(19, 26, 61, 0.78), rgba(10, 14, 39, 0.62));
|
||||
box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
|
||||
transition: transform 0.18s ease, border-color 0.18s ease;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: rgba(0, 212, 255, 0.28);
|
||||
}
|
||||
}
|
||||
|
||||
.snapshot-card__head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.snapshot-card__tag {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
background: rgba(0, 212, 255, 0.10);
|
||||
border: 1px solid rgba(0, 212, 255, 0.18);
|
||||
}
|
||||
|
||||
.snapshot-card__time {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.snapshot-card__title {
|
||||
font-size: clamp(13px, 1.8vh, 16px);
|
||||
font-weight: 700;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.snapshot-card__meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.62);
|
||||
}
|
||||
|
||||
.snapshot-card--critical { border-color: rgba(255, 71, 87, 0.26); }
|
||||
.snapshot-card--warning { border-color: rgba(255, 184, 0, 0.24); }
|
||||
.snapshot-card--normal { border-color: rgba(0, 212, 255, 0.16); }
|
||||
|
||||
@media (max-width: 1440px) {
|
||||
.fleet-metrics {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.fleet-split {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.airspace-top {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export { default as CityVitalCard } from './CityVitalCard';
|
||||
export { default as EventStreamCard } from './EventStreamCard';
|
||||
export { default as KpiStrip } from './KpiStrip';
|
||||
export { default as TwinPortal } from './TwinPortal';
|
||||
export { default as DroneInsightCard } from './DroneInsightCard';
|
||||
export { default as DispatchCard } from './DispatchCard';
|
||||
export { default as EventInsightCard } from './EventInsightCard';
|
||||
@@ -0,0 +1,507 @@
|
||||
// 旧版通用监控大屏(留档备查)
|
||||
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import { Card, Button, List, Tag, Spin, message, DatePicker, Segmented, Space } from 'antd';
|
||||
import {
|
||||
DesktopOutlined,
|
||||
WarningOutlined,
|
||||
RocketOutlined,
|
||||
EnvironmentOutlined,
|
||||
PieChartOutlined,
|
||||
FieldTimeOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { Line, Pie, Column, Area, Rose } from '@ant-design/plots';
|
||||
import { history } from 'umi';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
getDeviceStats,
|
||||
getTaskStats,
|
||||
getTrendData,
|
||||
getMockAlerts,
|
||||
DeviceStats,
|
||||
TaskStats,
|
||||
TrendItem,
|
||||
AlertItem,
|
||||
} from '@/services/dashboard';
|
||||
import './index.less';
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [deviceStats, setDeviceStats] = useState<DeviceStats | null>(null);
|
||||
const [taskStats, setTaskStats] = useState<TaskStats | null>(null);
|
||||
const [taskTrend, setTaskTrend] = useState<TrendItem[]>([]);
|
||||
const [alerts, setAlerts] = useState<AlertItem[]>([]);
|
||||
const [annualData, setAnnualData] = useState<any[]>([]);
|
||||
const [failureAnalysisData, setFailureAnalysisData] = useState<any[]>([]);
|
||||
const [taskTypeData, setTaskTypeData] = useState<any[]>([]);
|
||||
const [taskStatType, setTaskStatType] = useState<'day' | 'month' | 'year'>('day');
|
||||
const [taskStatDate, setTaskStatDate] = useState(dayjs());
|
||||
const [tenantId, setTenantId] = useState<string | undefined>();
|
||||
const [includeChildren, setIncludeChildren] = useState<boolean>(true);
|
||||
|
||||
useEffect(() => {
|
||||
// 模拟年度数据
|
||||
const mockAnnual: any[] = [];
|
||||
for (let i = 1; i <= 12; i++) {
|
||||
mockAnnual.push({
|
||||
month: `${i}月`,
|
||||
value: Math.floor(Math.random() * 500) + 100,
|
||||
type: '任务总数',
|
||||
});
|
||||
mockAnnual.push({
|
||||
month: `${i}月`,
|
||||
value: Math.floor(Math.random() * 450) + 80,
|
||||
type: '成功任务',
|
||||
});
|
||||
}
|
||||
setAnnualData(mockAnnual);
|
||||
|
||||
// 模拟失败原因数据
|
||||
setFailureAnalysisData([
|
||||
{ type: '信号丢失', value: 27 },
|
||||
{ type: '电池不足', value: 25 },
|
||||
{ type: '天气原因', value: 18 },
|
||||
{ type: '机械故障', value: 15 },
|
||||
{ type: '人为取消', value: 10 },
|
||||
{ type: '其他', value: 5 },
|
||||
]);
|
||||
|
||||
// 任务类型分布数据
|
||||
setTaskTypeData([
|
||||
{ type: '航线任务', value: 156 },
|
||||
{ type: '一键起飞', value: 89 },
|
||||
{ type: '手动控制', value: 45 },
|
||||
]);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (e: any) => {
|
||||
const nextTenantId = e?.detail?.tenantId as string | undefined;
|
||||
const nextIncludeChildren = !!e?.detail?.includeChildren;
|
||||
setTenantId(nextTenantId);
|
||||
setIncludeChildren(nextIncludeChildren);
|
||||
};
|
||||
window.addEventListener('tenant-change', handler as any);
|
||||
return () => window.removeEventListener('tenant-change', handler as any);
|
||||
}, []);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [deviceRes, taskRes, trendRes] = await Promise.all([
|
||||
getDeviceStats({ tenantId, includeChildren }),
|
||||
getTaskStats({
|
||||
tenantId,
|
||||
includeChildren,
|
||||
statType: taskStatType,
|
||||
date:
|
||||
taskStatType === 'day'
|
||||
? taskStatDate.format('YYYY-MM-DD')
|
||||
: taskStatType === 'month'
|
||||
? taskStatDate.format('YYYY-MM')
|
||||
: taskStatDate.format('YYYY'),
|
||||
}),
|
||||
getTrendData(7),
|
||||
]);
|
||||
setDeviceStats(deviceRes);
|
||||
setTaskStats(taskRes);
|
||||
setTaskTrend(trendRes.taskTrend);
|
||||
setAlerts(getMockAlerts());
|
||||
} catch (error) {
|
||||
console.error('获取数据失败:', error);
|
||||
message.error('数据加载异常');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [includeChildren, taskStatDate, taskStatType, tenantId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!tenantId) return;
|
||||
fetchData();
|
||||
}, [fetchData]);
|
||||
|
||||
// 定时刷新和时间更新
|
||||
useEffect(() => {
|
||||
const dataTimer = setInterval(fetchData, 30000);
|
||||
return () => {
|
||||
clearInterval(dataTimer);
|
||||
};
|
||||
}, [fetchData]);
|
||||
|
||||
const goTo3D = () => {
|
||||
// 传递来源页面,以便从map3d返回时能回到正确的大屏
|
||||
history.push('/map3d?from=dashboard');
|
||||
};
|
||||
|
||||
// --- 图表配置 ---
|
||||
|
||||
const taskTrendSeriesData = useMemo(() => {
|
||||
return taskTrend.flatMap((t) => [
|
||||
{ date: t.date, type: '创建', value: t.created || 0 },
|
||||
{ date: t.date, type: '完成', value: t.completed || 0 },
|
||||
{ date: t.date, type: '失败', value: t.failed || 0 },
|
||||
]);
|
||||
}, [taskTrend]);
|
||||
|
||||
// 近7日任务完成数趋势数据
|
||||
const taskCompleteTrendData = useMemo(() => {
|
||||
return taskTrend.map((t) => ({
|
||||
date: t.date,
|
||||
value: t.completed || 0,
|
||||
}));
|
||||
}, [taskTrend]);
|
||||
|
||||
const taskTrendConfig: any = {
|
||||
data: taskTrendSeriesData,
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
smooth: true,
|
||||
color: ['#00d4ff', '#00ff88', '#ffb800'],
|
||||
areaStyle: {
|
||||
fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff',
|
||||
fillOpacity: 0.1,
|
||||
},
|
||||
xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: null },
|
||||
yAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(255,255,255,0.1)' } } } },
|
||||
tooltip: { showMarkers: true },
|
||||
height: 180,
|
||||
};
|
||||
|
||||
const pieConfig: any = {
|
||||
data: deviceStats?.byType || [],
|
||||
angleField: 'count',
|
||||
colorField: 'name',
|
||||
radius: 0.7,
|
||||
innerRadius: 0.5,
|
||||
label: {
|
||||
text: (datum: any) => {
|
||||
const name = datum?.name || '';
|
||||
const count = datum?.count ?? 0;
|
||||
const data = (deviceStats?.byType || []) as { name: string; count: number }[];
|
||||
const total = data.reduce((sum, d) => sum + (d.count || 0), 0);
|
||||
const percent = total > 0 ? ((count / total) * 100).toFixed(1) : 0;
|
||||
return `${name} ${percent}%`;
|
||||
},
|
||||
style: { fill: 'rgba(255,255,255,0.65)' },
|
||||
},
|
||||
legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(255,255,255,0.65)' } }, itemName: { style: { fill: 'rgba(255,255,255,0.65)' } } },
|
||||
height: 200,
|
||||
};
|
||||
|
||||
const columnConfig: any = {
|
||||
data: taskTypeData,
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
color: ({ type }: any) => {
|
||||
if(type === '航线任务') return '#00d4ff';
|
||||
if(type === '一键起飞') return '#00ff88';
|
||||
return '#ffb800';
|
||||
},
|
||||
label: {
|
||||
text: (datum: any) => datum?.value?.toString() || '0',
|
||||
style: { fill: '#fff' },
|
||||
},
|
||||
xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } } },
|
||||
yAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(255,255,255,0.1)' } } } },
|
||||
legend: false,
|
||||
height: 180,
|
||||
};
|
||||
|
||||
const taskCompleteTrendConfig: any = {
|
||||
data: taskCompleteTrendData,
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
smooth: true,
|
||||
color: '#00ff88',
|
||||
areaStyle: { fillOpacity: 0.15 },
|
||||
xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: null },
|
||||
yAxis: {
|
||||
label: { style: { fill: 'rgba(255,255,255,0.65)' } },
|
||||
grid: { line: { style: { stroke: 'rgba(255,255,255,0.08)' } } },
|
||||
},
|
||||
tooltip: { showMarkers: true },
|
||||
height: 160,
|
||||
};
|
||||
|
||||
const areaConfig: any = {
|
||||
data: annualData,
|
||||
xField: 'month',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
color: ['#00d4ff', '#00ff88'],
|
||||
areaStyle: { fillOpacity: 0.3 },
|
||||
xAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } } },
|
||||
yAxis: { label: { style: { fill: 'rgba(255,255,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(255,255,255,0.1)' } } } },
|
||||
legend: { position: 'top-right', itemName: { style: { fill: '#fff' } } },
|
||||
smooth: true,
|
||||
height: 220,
|
||||
};
|
||||
|
||||
const roseConfig: any = {
|
||||
data: failureAnalysisData,
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
radius: 0.9,
|
||||
label: {
|
||||
text: (datum: any) => datum?.type || '',
|
||||
style: { fill: '#fff' },
|
||||
},
|
||||
legend: { position: 'bottom', itemName: { style: { fill: 'rgba(255,255,255,0.65)' } } },
|
||||
height: 200,
|
||||
};
|
||||
|
||||
const taskStatusPieConfig: any = {
|
||||
data: [
|
||||
{ name: '待执行', value: taskStats?.pending || 0 },
|
||||
{ name: '执行中', value: taskStats?.running || 0 },
|
||||
{ name: '已完成', value: taskStats?.completed || 0 },
|
||||
{ name: '已失败', value: taskStats?.failed || 0 },
|
||||
],
|
||||
angleField: 'value',
|
||||
colorField: 'name',
|
||||
radius: 0.85,
|
||||
innerRadius: 0.55,
|
||||
label: {
|
||||
text: (datum: any) => {
|
||||
const name = datum?.name || '';
|
||||
const value = datum?.value ?? 0;
|
||||
const total = (taskStats?.pending || 0) + (taskStats?.running || 0) + (taskStats?.completed || 0) + (taskStats?.failed || 0);
|
||||
const percent = total > 0 ? ((value / total) * 100).toFixed(1) : 0;
|
||||
return `${name} ${percent}%`;
|
||||
},
|
||||
style: { fill: 'rgba(255,255,255,0.65)' },
|
||||
},
|
||||
legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(255,255,255,0.65)' } }, itemName: { style: { fill: 'rgba(255,255,255,0.65)' } } },
|
||||
height: 190,
|
||||
};
|
||||
|
||||
const getAlertColor = (level: string) => {
|
||||
switch (level) {
|
||||
case 'critical': return 'red';
|
||||
case 'error': return 'orange';
|
||||
case 'warning': return 'gold';
|
||||
default: return 'blue';
|
||||
}
|
||||
};
|
||||
|
||||
const taskPeriodText = useMemo(() => {
|
||||
if (taskStatType === 'day') return '当日';
|
||||
if (taskStatType === 'month') return '当月';
|
||||
return '当年';
|
||||
}, [taskStatType]);
|
||||
|
||||
const taskNewLabel = useMemo(() => {
|
||||
if (taskStatType === 'day') return '当日任务';
|
||||
if (taskStatType === 'month') return '当月任务';
|
||||
return '当年任务';
|
||||
}, [taskStatType]);
|
||||
|
||||
const datePickerFormat = useMemo(() => {
|
||||
if (taskStatType === 'day') return 'YYYY-MM-DD';
|
||||
if (taskStatType === 'month') return 'YYYY-MM';
|
||||
return 'YYYY';
|
||||
}, [taskStatType]);
|
||||
|
||||
return (
|
||||
<div className="dashboard-page">
|
||||
<div className="dashboard-bg-animation"></div>
|
||||
|
||||
<Spin spinning={loading} wrapperClassName="dashboard-spin">
|
||||
<div className="dashboard-content">
|
||||
<div className="dashboard-grid">
|
||||
|
||||
{/* 左侧栏:设备态势 */}
|
||||
<div className="grid-col left-col">
|
||||
<Card title="设备类型分布" className="panel-card glass-panel" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Pie {...pieConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card title="任务类型统计" className="panel-card glass-panel" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Column {...columnConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card title="近7日任务完成趋势" className="panel-card glass-panel" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Area {...taskCompleteTrendConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title={<span><WarningOutlined className="icon-warning" /> 实时告警</span>}
|
||||
className="panel-card glass-panel flex-grow"
|
||||
size="small"
|
||||
extra={<Tag color="#f50">Live</Tag>}
|
||||
>
|
||||
<div className="alert-list-container">
|
||||
<List
|
||||
dataSource={alerts}
|
||||
split={false}
|
||||
renderItem={(item) => (
|
||||
<List.Item className="alert-item">
|
||||
<div className="alert-row">
|
||||
<div className="alert-badge">
|
||||
<Tag color={getAlertColor(item.level)}>{item.level.toUpperCase().slice(0,1)}</Tag>
|
||||
</div>
|
||||
<div className="alert-content">
|
||||
<div className="alert-head">
|
||||
<span className="alert-name">{item.deviceName || item.taskName}</span>
|
||||
<span className="alert-time">{dayjs(item.timestamp).format('HH:mm')}</span>
|
||||
</div>
|
||||
<div className="alert-msg">{item.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* 中间栏:核心监控 */}
|
||||
<div className="grid-col center-col">
|
||||
{/* 顶部KPI */}
|
||||
<div className="kpi-row">
|
||||
<div className="kpi-card">
|
||||
<div className="kpi-icon blue"><DesktopOutlined /></div>
|
||||
<div className="kpi-info">
|
||||
<div className="label">设备总数</div>
|
||||
<div className="value">{deviceStats?.total || 0}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="kpi-card">
|
||||
<div className="kpi-icon green"><EnvironmentOutlined /></div>
|
||||
<div className="kpi-info">
|
||||
<div className="label">景区总数</div>
|
||||
<div className="value">{deviceStats?.tourismCount || 0}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="kpi-card">
|
||||
<div className="kpi-icon yellow"><RocketOutlined /></div>
|
||||
<div className="kpi-info">
|
||||
<div className="label">{taskNewLabel}</div>
|
||||
<div className="value">{taskStats?.todayNew || 0}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="kpi-card">
|
||||
<div className="kpi-icon purple"><PieChartOutlined /></div>
|
||||
<div className="kpi-info">
|
||||
<div className="label">执行成功率</div>
|
||||
<div className="value">{taskStats?.successRate || 0}<small>%</small></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 地图/3D入口 */}
|
||||
<div className="map-portal-wrapper">
|
||||
<div className="map-bg-grid"></div>
|
||||
<div className="radar-sweep"></div>
|
||||
<div className="map-content">
|
||||
<div className="portal-center">
|
||||
<EnvironmentOutlined style={{ fontSize: 56, color: '#00d4ff', marginBottom: 20 }} />
|
||||
<h2 className="portal-title">全域数字孪生监控中心</h2>
|
||||
<Button type="primary" shape="round" size="large" onClick={goTo3D} className="portal-btn">
|
||||
立即进入监控视图
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 底部年度统计 */}
|
||||
<Card title="年度任务执行趋势分析" className="panel-card glass-panel fill-bottom" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Area {...areaConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* 右侧栏:任务与运维 */}
|
||||
<div className="grid-col right-col">
|
||||
<Card
|
||||
title={`${taskPeriodText}任务统计`}
|
||||
className="panel-card glass-panel"
|
||||
size="small"
|
||||
extra={
|
||||
<Space size={8} className="task-filter">
|
||||
<Segmented
|
||||
size="small"
|
||||
options={[
|
||||
{ label: '日', value: 'day' },
|
||||
{ label: '月', value: 'month' },
|
||||
{ label: '年', value: 'year' },
|
||||
]}
|
||||
value={taskStatType}
|
||||
onChange={(v) => setTaskStatType(v as any)}
|
||||
/>
|
||||
<DatePicker
|
||||
size="small"
|
||||
value={taskStatDate}
|
||||
onChange={(v) => v && setTaskStatDate(v)}
|
||||
picker={taskStatType === 'day' ? 'date' : taskStatType}
|
||||
allowClear={false}
|
||||
format={datePickerFormat}
|
||||
disabledDate={(d) => !!d && d.isAfter(dayjs(), 'day')}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<div className="task-overview-grid">
|
||||
<div className="task-stat-box">
|
||||
<div className="val pending">{taskStats?.pending || 0}</div>
|
||||
<div className="lbl">待执行</div>
|
||||
</div>
|
||||
<div className="task-stat-box">
|
||||
<div className="val running">{taskStats?.running || 0}</div>
|
||||
<div className="lbl">执行中</div>
|
||||
</div>
|
||||
<div className="task-stat-box">
|
||||
<div className="val completed">{taskStats?.completed || 0}</div>
|
||||
<div className="lbl">已完成</div>
|
||||
</div>
|
||||
<div className="task-stat-box">
|
||||
<div className="val failed">{taskStats?.failed || 0}</div>
|
||||
<div className="lbl">已失败</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: 16, textAlign: 'center' }}>
|
||||
<div style={{ fontSize: '32px', fontWeight: 'bold', color: '#00ff88' }}>
|
||||
{taskStats?.successRate || 0}%
|
||||
</div>
|
||||
<div style={{ fontSize: '14px', color: '#fff', marginTop: 4 }}>
|
||||
{taskPeriodText}成功率
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card title="任务状态占比" className="panel-card glass-panel" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Pie {...taskStatusPieConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card title="近7日任务趋势" className="panel-card glass-panel" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Line {...taskTrendConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card title="异常原因分析" className="panel-card glass-panel flex-grow" size="small">
|
||||
<div className="chart-wrapper">
|
||||
<Rose {...roseConfig} />
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,401 @@
|
||||
import dayjs from 'dayjs';
|
||||
import type { AlertItem, DeviceStats, TaskStats, TrendItem } from '@/services/dashboard';
|
||||
|
||||
type Severity = 'normal' | 'warning' | 'critical';
|
||||
|
||||
export interface SmartCityKpiItem {
|
||||
key: string;
|
||||
label: string;
|
||||
value: number | string;
|
||||
unit?: string;
|
||||
accent?: 'blue' | 'green' | 'yellow' | 'red' | 'purple';
|
||||
sub?: string;
|
||||
}
|
||||
|
||||
export interface SmartCityEventItem {
|
||||
id: string;
|
||||
title: string;
|
||||
location: string;
|
||||
source: '无人机' | '摄像头' | '机库' | '多源融合';
|
||||
severity: Severity;
|
||||
status: '待确认' | '已派单' | '处理中' | '已闭环';
|
||||
timeText: string;
|
||||
desc: string;
|
||||
}
|
||||
|
||||
export interface SmartCityModels {
|
||||
kpis: SmartCityKpiItem[];
|
||||
fleet: {
|
||||
droneTotal: number;
|
||||
droneOnline: number;
|
||||
droneInFlight: number;
|
||||
droneStandby: number;
|
||||
droneMaintenance: number;
|
||||
dockTotal: number;
|
||||
dockOnline: number;
|
||||
cameraTotal: number;
|
||||
cameraOnline: number;
|
||||
lowBatteryAlerts: number;
|
||||
avgBattery: number;
|
||||
flightHoursToday: number;
|
||||
flightMileageToday: number;
|
||||
};
|
||||
airspace: {
|
||||
safetyIndex: number;
|
||||
complianceIndex: number;
|
||||
geofenceTriggers: number;
|
||||
noFlyWarnings: number;
|
||||
approvalsToday: number;
|
||||
approvalsPassRate: number;
|
||||
};
|
||||
regionCoverage: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
coverage: number;
|
||||
pending: number;
|
||||
risk: Severity;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
terminalPieData: { name: string; count: number }[];
|
||||
onlineRate: number;
|
||||
liquidRate: number;
|
||||
gridRadarData: { item: string; score: number; type: '当前' }[];
|
||||
envTrendData: { time: string; type: string; value: number }[];
|
||||
trafficHeatmapData: { x: string; y: string; value: number }[];
|
||||
eventTypeData: { type: string; value: number }[];
|
||||
eventFunnelData: { stage: string; value: number }[];
|
||||
eventList: SmartCityEventItem[];
|
||||
aiSnapshots: Array<{
|
||||
id: string;
|
||||
title: string;
|
||||
location: string;
|
||||
tag: string;
|
||||
confidence: number;
|
||||
timeText: string;
|
||||
severity: Severity;
|
||||
}>;
|
||||
}
|
||||
|
||||
function hashStringToSeed(text: string): number {
|
||||
let hash = 2166136261;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
hash ^= text.charCodeAt(i);
|
||||
hash = Math.imul(hash, 16777619);
|
||||
}
|
||||
return hash >>> 0;
|
||||
}
|
||||
|
||||
function createRng(seedText: string) {
|
||||
let seed = hashStringToSeed(seedText) || 1;
|
||||
return () => {
|
||||
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
|
||||
return seed / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
function clampNumber(value: number, min: number, max: number) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
function pickOne<T>(rng: () => number, items: T[]): T {
|
||||
return items[Math.floor(rng() * items.length)];
|
||||
}
|
||||
|
||||
function mapAlertToEvent(alert: AlertItem): Omit<SmartCityEventItem, 'location' | 'source' | 'status'> & {
|
||||
severity: Severity;
|
||||
title: string;
|
||||
} {
|
||||
const severity: Severity =
|
||||
alert.level === 'critical' ? 'critical' : alert.level === 'error' ? 'warning' : 'normal';
|
||||
|
||||
if (alert.type === 'device_offline') {
|
||||
return {
|
||||
id: alert.id,
|
||||
title: '关键点位离线预警',
|
||||
severity,
|
||||
timeText: dayjs(alert.timestamp).format('HH:mm'),
|
||||
desc: alert.message,
|
||||
};
|
||||
}
|
||||
if (alert.type === 'low_battery') {
|
||||
return {
|
||||
id: alert.id,
|
||||
title: '保障能力风险提示',
|
||||
severity: severity === 'normal' ? 'warning' : severity,
|
||||
timeText: dayjs(alert.timestamp).format('HH:mm'),
|
||||
desc: alert.message,
|
||||
};
|
||||
}
|
||||
if (alert.type === 'task_failed') {
|
||||
return {
|
||||
id: alert.id,
|
||||
title: '巡检任务异常',
|
||||
severity,
|
||||
timeText: dayjs(alert.timestamp).format('HH:mm'),
|
||||
desc: alert.message,
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: alert.id,
|
||||
title: '终端运行异常',
|
||||
severity: severity === 'normal' ? 'warning' : severity,
|
||||
timeText: dayjs(alert.timestamp).format('HH:mm'),
|
||||
desc: alert.message,
|
||||
};
|
||||
}
|
||||
|
||||
function calcSafetyIndex(params: {
|
||||
deviceStats?: DeviceStats | null;
|
||||
taskStats?: TaskStats | null;
|
||||
alerts?: AlertItem[];
|
||||
baseSeed: string;
|
||||
}) {
|
||||
const rng = createRng(`${params.baseSeed}:safety`);
|
||||
const onlineRate = params.deviceStats?.onlineRate ?? 0;
|
||||
const successRate = params.taskStats?.successRate ?? 0;
|
||||
const alerts = params.alerts || [];
|
||||
|
||||
const critical = alerts.filter((a) => a.level === 'critical').length;
|
||||
const error = alerts.filter((a) => a.level === 'error').length;
|
||||
const warning = alerts.filter((a) => a.level === 'warning').length;
|
||||
|
||||
const baseline = 90 + Math.round(rng() * 4);
|
||||
const penalty = critical * 6 + error * 4 + warning * 2 + Math.round((100 - onlineRate) * 0.18);
|
||||
const bonus = Math.round((successRate - 80) * 0.15);
|
||||
|
||||
return clampNumber(baseline - penalty + bonus, 60, 99);
|
||||
}
|
||||
|
||||
export function buildSmartCityModels(params: {
|
||||
tenantId?: string;
|
||||
deviceStats?: DeviceStats | null;
|
||||
taskStats?: TaskStats | null;
|
||||
taskTrend?: TrendItem[];
|
||||
alerts?: AlertItem[];
|
||||
}): SmartCityModels {
|
||||
const todayKey = dayjs().format('YYYY-MM-DD');
|
||||
const baseSeed = `${params.tenantId || 'default'}:${todayKey}`;
|
||||
const rng = createRng(baseSeed);
|
||||
|
||||
const deviceStats = params.deviceStats;
|
||||
const taskStats = params.taskStats;
|
||||
const taskTrend = params.taskTrend || [];
|
||||
const alerts = params.alerts || [];
|
||||
|
||||
const onlineRate = deviceStats?.onlineRate ?? 0;
|
||||
const safetyIndex = calcSafetyIndex({ deviceStats, taskStats, alerts, baseSeed });
|
||||
|
||||
const eventCount = alerts.length + 6 + Math.floor(rng() * 6);
|
||||
const avgResponse = clampNumber(8 + Math.round((1 - (taskStats?.successRate ?? 0) / 100) * 12) + Math.round(rng() * 4), 6, 28);
|
||||
const closedLoopRate = clampNumber(
|
||||
taskStats?.total ? Math.round(((taskStats.completed || 0) / taskStats.total) * 100) : 70 + Math.round(rng() * 18),
|
||||
40,
|
||||
99,
|
||||
);
|
||||
|
||||
const byType = deviceStats?.byType || [];
|
||||
const droneTotal = byType.find((d) => d.type === 'drone')?.count || 0;
|
||||
const dockTotal = byType.find((d) => d.type === 'dock')?.count || 0;
|
||||
const cameraTotal = byType.find((d) => d.type === 'camera')?.count || 0;
|
||||
|
||||
const ratio = clampNumber((onlineRate || 0) / 100, 0, 1);
|
||||
const droneOnline = clampNumber(Math.round(droneTotal * ratio * (0.94 + rng() * 0.12)), 0, droneTotal);
|
||||
const dockOnline = clampNumber(Math.round(dockTotal * ratio * (0.92 + rng() * 0.14)), 0, dockTotal);
|
||||
const cameraOnline = clampNumber(Math.round(cameraTotal * ratio * (0.90 + rng() * 0.16)), 0, cameraTotal);
|
||||
|
||||
const runningTasks = taskStats?.running || 0;
|
||||
const droneInFlight = clampNumber(Math.min(droneOnline, Math.max(0, runningTasks) + Math.round(rng() * 2)), 0, droneOnline);
|
||||
const droneMaintenance = clampNumber(Math.round(droneTotal * (0.06 + rng() * 0.09)), 0, droneTotal);
|
||||
const droneStandby = clampNumber(droneOnline - droneInFlight - Math.min(droneMaintenance, droneOnline), 0, droneOnline);
|
||||
|
||||
const lowBatteryAlerts = alerts.filter((a) => a.type === 'low_battery').length;
|
||||
const avgBattery = clampNumber(62 + Math.round(rng() * 28) - lowBatteryAlerts * 3, 18, 98);
|
||||
const flightHoursToday = clampNumber(6 + Math.round((taskStats?.total || 0) * 0.55) + Math.round(rng() * 4), 0, 78);
|
||||
const flightMileageToday = clampNumber(28 + Math.round((taskStats?.total || 0) * 2.2) + Math.round(rng() * 12), 0, 420);
|
||||
|
||||
const critical = alerts.filter((a) => a.level === 'critical').length;
|
||||
const error = alerts.filter((a) => a.level === 'error').length;
|
||||
const warning = alerts.filter((a) => a.level === 'warning').length;
|
||||
|
||||
const complianceIndex = clampNumber(95 - critical * 6 - error * 3 - warning * 1 - Math.round((100 - onlineRate) * 0.12) + Math.round(rng() * 2), 60, 99);
|
||||
const geofenceTriggers = clampNumber(Math.round(rng() * 5) + critical + Math.floor(error / 2), 0, 12);
|
||||
const noFlyWarnings = clampNumber(Math.round(rng() * 3) + Math.floor(warning / 2), 0, 10);
|
||||
const approvalsToday = clampNumber(18 + Math.round(rng() * 28), 0, 120);
|
||||
const approvalsPassRate = clampNumber(92 - critical * 2 - error + Math.round(rng() * 4), 70, 99);
|
||||
|
||||
const fleet = {
|
||||
droneTotal,
|
||||
droneOnline,
|
||||
droneInFlight,
|
||||
droneStandby,
|
||||
droneMaintenance,
|
||||
dockTotal,
|
||||
dockOnline,
|
||||
cameraTotal,
|
||||
cameraOnline,
|
||||
lowBatteryAlerts,
|
||||
avgBattery,
|
||||
flightHoursToday,
|
||||
flightMileageToday,
|
||||
};
|
||||
|
||||
const airspace = {
|
||||
safetyIndex,
|
||||
complianceIndex,
|
||||
geofenceTriggers,
|
||||
noFlyWarnings,
|
||||
approvalsToday,
|
||||
approvalsPassRate,
|
||||
};
|
||||
|
||||
const kpis: SmartCityKpiItem[] = [
|
||||
{ key: 'air', label: '空域合规指数', value: complianceIndex, unit: '', accent: complianceIndex >= 92 ? 'green' : complianceIndex >= 82 ? 'yellow' : 'red', sub: '围栏/禁飞/链路综合' },
|
||||
{ key: 'flight', label: '在飞无人机', value: droneInFlight, unit: '架', accent: 'purple', sub: `在线 ${droneOnline}/${droneTotal}` },
|
||||
{ key: 'sortie', label: '今日出动任务', value: taskStats?.todayNew ?? 0, unit: '次', accent: 'blue', sub: '巡检/应急/处置' },
|
||||
{ key: 'closed', label: '问题闭环率', value: closedLoopRate, unit: '%', accent: closedLoopRate >= 85 ? 'green' : 'yellow', sub: '发现→处置→复核' },
|
||||
{ key: 'online', label: '终端在线率', value: onlineRate, unit: '%', accent: onlineRate >= 90 ? 'green' : onlineRate >= 75 ? 'yellow' : 'red', sub: `低电 ${lowBatteryAlerts} 起` },
|
||||
];
|
||||
|
||||
const terminalPieData = (deviceStats?.byType || []).map((d) => ({ name: d.name, count: d.count }));
|
||||
|
||||
const regionCoverage = (() => {
|
||||
const regions = ['政务中心片区', '滨河公园带', '高新大道走廊', '老城商圈', '西站枢纽', '南湖片区', '工业园北区', '东门立交'];
|
||||
const picked = regions.slice(0, 6);
|
||||
return picked.map((name, idx) => {
|
||||
const coverage = clampNumber(72 + Math.round(rng() * 26) - idx * 2, 45, 99);
|
||||
const pending = clampNumber(Math.round(rng() * 8) + (idx % 2 === 0 ? 1 : 0), 0, 18);
|
||||
const risk: Severity = coverage >= 88 ? 'normal' : coverage >= 76 ? 'warning' : 'critical';
|
||||
const updatedAt = dayjs().subtract(5 + Math.round(rng() * 55), 'minute').format('HH:mm');
|
||||
return { id: `region-${idx}`, name, coverage, pending, risk, updatedAt };
|
||||
});
|
||||
})();
|
||||
|
||||
const gridRadarData = [
|
||||
{ item: '巡检覆盖', score: clampNumber(70 + Math.round(rng() * 24), 55, 98), type: '当前' as const },
|
||||
{ item: '问题发现', score: clampNumber(62 + Math.round(rng() * 30), 50, 98), type: '当前' as const },
|
||||
{ item: '处置效率', score: clampNumber(68 + Math.round(rng() * 22), 50, 98), type: '当前' as const },
|
||||
{ item: '复核通过', score: clampNumber(72 + Math.round(rng() * 18), 55, 99), type: '当前' as const },
|
||||
{ item: '重点关注', score: clampNumber(58 + Math.round(rng() * 34), 45, 98), type: '当前' as const },
|
||||
];
|
||||
|
||||
const envTrendData: { time: string; type: string; value: number }[] = [];
|
||||
const startHour = dayjs().startOf('day');
|
||||
const pmBase = clampNumber(22 + Math.round(rng() * 26), 15, 60);
|
||||
const noiseBase = clampNumber(52 + Math.round(rng() * 10), 45, 70);
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const time = startHour.add(i, 'hour').format('HH:00');
|
||||
const wave = Math.sin((i / 24) * Math.PI * 2);
|
||||
const pm = clampNumber(pmBase + wave * 10 + (rng() - 0.5) * 6, 8, 85);
|
||||
const noise = clampNumber(noiseBase + Math.abs(wave) * 9 + (rng() - 0.5) * 4, 35, 85);
|
||||
envTrendData.push({ time, type: 'PM2.5', value: Number(pm.toFixed(1)) });
|
||||
envTrendData.push({ time, type: '噪声(dB)', value: Number(noise.toFixed(1)) });
|
||||
}
|
||||
|
||||
const trafficHeatmapData: { x: string; y: string; value: number }[] = [];
|
||||
const cols = 10;
|
||||
const rows = 6;
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const centerBias = 1 - Math.abs(x - (cols - 1) / 2) / cols;
|
||||
const value = clampNumber(12 + centerBias * 36 + rng() * 18 + (y % 2 === 0 ? 2 : -2), 0, 100);
|
||||
trafficHeatmapData.push({ x: `${x + 1}`, y: `${rows - y}`, value: Math.round(value) });
|
||||
}
|
||||
}
|
||||
|
||||
const locations = ['政务中心', '滨河公园', '高新大道', '老城商圈', '西站枢纽', '南湖片区', '工业园北区', '东门立交'];
|
||||
const sources: SmartCityEventItem['source'][] = ['无人机', '摄像头', '机库', '多源融合'];
|
||||
const statuses: SmartCityEventItem['status'][] = ['待确认', '已派单', '处理中', '已闭环'];
|
||||
|
||||
const eventListFromAlerts: SmartCityEventItem[] = alerts.slice(0, 8).map((a, idx) => {
|
||||
const base = mapAlertToEvent(a);
|
||||
const status = idx === 0 ? '处理中' : idx === 1 ? '待确认' : pickOne(rng, statuses);
|
||||
const source = idx % 2 === 0 ? '无人机' : '机库';
|
||||
return {
|
||||
...base,
|
||||
location: pickOne(rng, locations),
|
||||
source,
|
||||
status,
|
||||
};
|
||||
});
|
||||
|
||||
const aiEventTypes = ['违停抓拍', '烟火识别', '占道经营', '河道漂浮物', '工地未戴帽', '夜间聚集'];
|
||||
const aiSnapshots = new Array(10).fill(0).map((_, i) => {
|
||||
const type = aiEventTypes[i % aiEventTypes.length];
|
||||
const confidence = clampNumber(78 + Math.round(rng() * 20), 60, 99);
|
||||
const severity: Severity = confidence >= 92 ? 'critical' : confidence >= 84 ? 'warning' : 'normal';
|
||||
const timeText = dayjs().subtract(Math.round(rng() * 65), 'minute').format('HH:mm');
|
||||
return {
|
||||
id: `snap-${todayKey}-${i}`,
|
||||
title: type,
|
||||
location: pickOne(rng, locations),
|
||||
tag: pickOne(rng, ['AI识别', '多源融合', '重点区域', '高频点位']),
|
||||
confidence,
|
||||
timeText,
|
||||
severity,
|
||||
};
|
||||
});
|
||||
|
||||
const eventListGenerated: SmartCityEventItem[] = aiSnapshots.slice(0, 6).map((s, idx) => {
|
||||
const severity: Severity = s.severity;
|
||||
const status = idx < 2 ? '待确认' : idx < 4 ? '已派单' : pickOne(rng, statuses);
|
||||
const source = idx % 3 === 0 ? '无人机' : idx % 3 === 1 ? '摄像头' : '多源融合';
|
||||
return {
|
||||
id: `evt-${s.id}`,
|
||||
title: s.title,
|
||||
location: s.location,
|
||||
source,
|
||||
severity,
|
||||
status,
|
||||
timeText: s.timeText,
|
||||
desc: `疑似${s.title}(置信度 ${s.confidence}%)`,
|
||||
};
|
||||
});
|
||||
|
||||
const eventList = [...eventListGenerated, ...eventListFromAlerts].slice(0, 12);
|
||||
|
||||
const eventTypeCounts: Record<string, number> = {};
|
||||
eventList.forEach((e) => {
|
||||
const key = e.title;
|
||||
eventTypeCounts[key] = (eventTypeCounts[key] || 0) + 1;
|
||||
});
|
||||
const eventTypeData = Object.entries(eventTypeCounts)
|
||||
.map(([type, value]) => ({ type, value }))
|
||||
.sort((a, b) => b.value - a.value)
|
||||
.slice(0, 6);
|
||||
|
||||
const eventFunnelData = (() => {
|
||||
const total = eventCount;
|
||||
const confirmed = clampNumber(Math.round(total * (0.78 + rng() * 0.08)), 0, total);
|
||||
const assigned = clampNumber(Math.round(confirmed * (0.75 + rng() * 0.1)), 0, confirmed);
|
||||
const processing = clampNumber(Math.round(assigned * (0.72 + rng() * 0.12)), 0, assigned);
|
||||
const closed = clampNumber(Math.round(processing * (0.78 + rng() * 0.12)), 0, processing);
|
||||
return [
|
||||
{ stage: '识别', value: total },
|
||||
{ stage: '确认', value: confirmed },
|
||||
{ stage: '派单', value: assigned },
|
||||
{ stage: '处置', value: processing },
|
||||
{ stage: '闭环', value: closed },
|
||||
];
|
||||
})();
|
||||
|
||||
const liquidRate = clampNumber((onlineRate || 0) / 100, 0, 1);
|
||||
|
||||
void taskTrend;
|
||||
|
||||
return {
|
||||
kpis,
|
||||
fleet,
|
||||
airspace,
|
||||
regionCoverage,
|
||||
terminalPieData,
|
||||
onlineRate,
|
||||
liquidRate,
|
||||
gridRadarData,
|
||||
envTrendData,
|
||||
trafficHeatmapData,
|
||||
eventTypeData,
|
||||
eventFunnelData,
|
||||
eventList,
|
||||
aiSnapshots,
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,19 @@
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
font-size: clamp(12px, 1.1vh, 14px);
|
||||
--mar-pad-x: clamp(12px, 1.4vw, 18px);
|
||||
--mar-pad-y: clamp(10px, 1.2vh, 16px);
|
||||
--mar-gap: clamp(10px, 1.2vh, 14px);
|
||||
--mar-kpi-h: clamp(70px, 9vh, 85px);
|
||||
--mar-card-head-h: clamp(36px, 4.4vh, 42px);
|
||||
--mar-card-body-pad: clamp(8px, 1.1vh, 12px);
|
||||
--mar-frame-h: clamp(18px, 2.6vh, 28px);
|
||||
--mar-frame-gap: clamp(6px, 0.9vh, 12px);
|
||||
--mar-map-min: clamp(240px, 33vh, 360px);
|
||||
background: linear-gradient(180deg,
|
||||
#020c1b 0%,
|
||||
#051525 25%,
|
||||
@@ -107,40 +120,115 @@
|
||||
}
|
||||
}
|
||||
|
||||
.maritime-dashboard--compact-1 {
|
||||
--mar-pad-x: clamp(10px, 1.1vw, 16px);
|
||||
--mar-pad-y: clamp(8px, 1.0vh, 12px);
|
||||
--mar-gap: clamp(8px, 1.0vh, 12px);
|
||||
--mar-kpi-h: clamp(64px, 8vh, 78px);
|
||||
--mar-card-head-h: clamp(34px, 4.0vh, 40px);
|
||||
--mar-card-body-pad: clamp(6px, 0.9vh, 10px);
|
||||
--mar-frame-h: clamp(16px, 2.2vh, 24px);
|
||||
--mar-frame-gap: clamp(4px, 0.7vh, 10px);
|
||||
--mar-map-min: clamp(220px, 30vh, 320px);
|
||||
}
|
||||
|
||||
.maritime-dashboard--compact-2 {
|
||||
--mar-pad-x: clamp(8px, 1.0vw, 14px);
|
||||
--mar-pad-y: clamp(6px, 0.8vh, 10px);
|
||||
--mar-gap: clamp(6px, 0.9vh, 10px);
|
||||
--mar-kpi-h: clamp(58px, 7vh, 70px);
|
||||
--mar-card-head-h: clamp(32px, 3.6vh, 38px);
|
||||
--mar-card-body-pad: clamp(6px, 0.8vh, 9px);
|
||||
--mar-frame-h: clamp(14px, 2.0vh, 22px);
|
||||
--mar-frame-gap: clamp(4px, 0.6vh, 8px);
|
||||
--mar-map-min: clamp(200px, 28vh, 300px);
|
||||
}
|
||||
|
||||
/* 主内容区域 */
|
||||
.maritime-spin {
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
:global(.ant-spin-container) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.maritime-content {
|
||||
flex: 1;
|
||||
padding: 16px 18px;
|
||||
padding: var(--mar-pad-y) var(--mar-pad-x);
|
||||
padding-bottom: calc(var(--mar-pad-y) + var(--mar-frame-h) + var(--mar-frame-gap));
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.maritime-bottom-frame {
|
||||
position: absolute;
|
||||
left: clamp(12px, 1.6vw, 26px);
|
||||
right: clamp(12px, 1.6vw, 26px);
|
||||
bottom: clamp(6px, 0.8vh, 12px);
|
||||
height: var(--mar-frame-h);
|
||||
border-radius: 12px;
|
||||
z-index: 2;
|
||||
pointer-events: none;
|
||||
background:
|
||||
linear-gradient(
|
||||
90deg,
|
||||
rgba(0, 120, 180, 0.08),
|
||||
rgba(0, 180, 230, 0.7) 34%,
|
||||
rgba(0, 229, 160, 0.45) 50%,
|
||||
rgba(0, 180, 230, 0.7) 66%,
|
||||
rgba(0, 120, 180, 0.08)
|
||||
) bottom/100% 2px no-repeat,
|
||||
linear-gradient(90deg, rgba(0, 220, 255, 0.85), transparent 90px) bottom left/90px 2px no-repeat,
|
||||
linear-gradient(270deg, rgba(0, 220, 255, 0.85), transparent 90px) bottom right/90px 2px no-repeat,
|
||||
linear-gradient(180deg, rgba(0, 180, 230, 0.6), transparent 80%) bottom left/2px 100% no-repeat,
|
||||
linear-gradient(180deg, rgba(0, 180, 230, 0.6), transparent 80%) bottom right/2px 100% no-repeat;
|
||||
box-shadow: 0 -6px 18px rgba(0, 120, 180, 0.3);
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: 6px;
|
||||
width: clamp(120px, 18vw, 220px);
|
||||
height: 6px;
|
||||
transform: translateX(-50%);
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(90deg, transparent, rgba(0, 220, 255, 0.85), transparent);
|
||||
box-shadow: 0 0 12px rgba(0, 180, 230, 0.4);
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
.maritime-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 25% 50% 25%;
|
||||
grid-template-rows: 100%;
|
||||
gap: 14px;
|
||||
grid-template-columns: minmax(0, 25%) minmax(0, 50%) minmax(0, 25%);
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
gap: var(--mar-gap);
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.grid-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
gap: var(--mar-gap);
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* 海事风格玻璃面板 */
|
||||
@@ -180,7 +268,7 @@
|
||||
}
|
||||
|
||||
:global(.ant-card-head) {
|
||||
min-height: 42px;
|
||||
min-height: var(--mar-card-head-h);
|
||||
padding: 0 14px;
|
||||
border-bottom: 1px solid rgba(0, 180, 230, 0.15);
|
||||
background: linear-gradient(90deg, rgba(0, 100, 150, 0.2), transparent);
|
||||
@@ -195,7 +283,7 @@
|
||||
|
||||
:global(.ant-card-body) {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
padding: var(--mar-card-body-pad);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
display: flex;
|
||||
@@ -222,8 +310,8 @@
|
||||
.kpi-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12px;
|
||||
height: 85px;
|
||||
gap: var(--mar-gap);
|
||||
height: var(--mar-kpi-h);
|
||||
}
|
||||
|
||||
.kpi-card {
|
||||
@@ -281,6 +369,7 @@
|
||||
/* 中央海图监控区域 */
|
||||
.map-portal-wrapper {
|
||||
flex: 2;
|
||||
min-height: var(--mar-map-min);
|
||||
position: relative;
|
||||
background: linear-gradient(180deg, rgba(0, 40, 80, 0.5) 0%, rgba(0, 60, 100, 0.3) 100%);
|
||||
border: 1px solid rgba(0, 180, 230, 0.35);
|
||||
|
||||
@@ -42,6 +42,18 @@ const MaritimeDashboard: React.FC = () => {
|
||||
const [taskStatDate, setTaskStatDate] = useState(dayjs());
|
||||
const [tenantId, setTenantId] = useState<string | undefined>();
|
||||
const [includeChildren, setIncludeChildren] = useState<boolean>(true);
|
||||
const [compactLevel, setCompactLevel] = useState<0 | 1 | 2>(0);
|
||||
|
||||
useEffect(() => {
|
||||
const calc = () => {
|
||||
const height = window?.innerHeight || 0;
|
||||
const next: 0 | 1 | 2 = height <= 760 ? 2 : height <= 900 ? 1 : 0;
|
||||
setCompactLevel(next);
|
||||
};
|
||||
calc();
|
||||
window.addEventListener('resize', calc);
|
||||
return () => window.removeEventListener('resize', calc);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// 模拟年度数据
|
||||
@@ -167,6 +179,40 @@ const MaritimeDashboard: React.FC = () => {
|
||||
}));
|
||||
}, [taskTrend]);
|
||||
|
||||
const chartHeights = useMemo(() => {
|
||||
if (compactLevel === 2) {
|
||||
return {
|
||||
taskTrend: 140,
|
||||
pie: 160,
|
||||
column: 140,
|
||||
taskComplete: 120,
|
||||
area: 170,
|
||||
rose: 160,
|
||||
taskStatus: 150,
|
||||
};
|
||||
}
|
||||
if (compactLevel === 1) {
|
||||
return {
|
||||
taskTrend: 160,
|
||||
pie: 180,
|
||||
column: 160,
|
||||
taskComplete: 140,
|
||||
area: 190,
|
||||
rose: 180,
|
||||
taskStatus: 170,
|
||||
};
|
||||
}
|
||||
return {
|
||||
taskTrend: 180,
|
||||
pie: 200,
|
||||
column: 180,
|
||||
taskComplete: 160,
|
||||
area: 220,
|
||||
rose: 200,
|
||||
taskStatus: 190,
|
||||
};
|
||||
}, [compactLevel]);
|
||||
|
||||
const taskTrendConfig: any = {
|
||||
data: taskTrendSeriesData,
|
||||
xField: 'date',
|
||||
@@ -181,7 +227,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: null },
|
||||
yAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } } },
|
||||
tooltip: { showMarkers: true },
|
||||
height: 180,
|
||||
height: chartHeights.taskTrend,
|
||||
};
|
||||
|
||||
// 设备类型分布 - 模拟数据
|
||||
@@ -213,7 +259,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
style: { fill: 'rgba(200,230,255,0.65)' },
|
||||
},
|
||||
legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(200,230,255,0.65)' } }, itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } },
|
||||
height: 200,
|
||||
height: chartHeights.pie,
|
||||
};
|
||||
|
||||
const columnConfig: any = {
|
||||
@@ -233,7 +279,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
xAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } } },
|
||||
yAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } } },
|
||||
legend: false,
|
||||
height: 180,
|
||||
height: chartHeights.column,
|
||||
};
|
||||
|
||||
const taskCompleteTrendConfig: any = {
|
||||
@@ -249,7 +295,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
grid: { line: { style: { stroke: 'rgba(0,150,200,0.08)' } } },
|
||||
},
|
||||
tooltip: { showMarkers: true },
|
||||
height: 160,
|
||||
height: chartHeights.taskComplete,
|
||||
};
|
||||
|
||||
const areaConfig: any = {
|
||||
@@ -263,7 +309,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
yAxis: { label: { style: { fill: 'rgba(200,230,255,0.65)' } }, grid: { line: { style: { stroke: 'rgba(0,150,200,0.1)' } } } },
|
||||
legend: { position: 'top-right', itemName: { style: { fill: 'rgba(200,230,255,0.8)' } } },
|
||||
smooth: true,
|
||||
height: 220,
|
||||
height: chartHeights.area,
|
||||
};
|
||||
|
||||
const roseConfig: any = {
|
||||
@@ -278,7 +324,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
style: { fill: '#fff', fontSize: 10 },
|
||||
},
|
||||
legend: { position: 'bottom', itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } },
|
||||
height: 200,
|
||||
height: chartHeights.rose,
|
||||
};
|
||||
|
||||
const taskStatusPieConfig: any = {
|
||||
@@ -304,7 +350,7 @@ const MaritimeDashboard: React.FC = () => {
|
||||
style: { fill: 'rgba(200,230,255,0.65)' },
|
||||
},
|
||||
legend: { position: 'bottom', itemValue: { style: { fill: 'rgba(200,230,255,0.65)' } }, itemName: { style: { fill: 'rgba(200,230,255,0.65)' } } },
|
||||
height: 190,
|
||||
height: chartHeights.taskStatus,
|
||||
};
|
||||
|
||||
const getAlertColor = (level: string) => {
|
||||
@@ -335,11 +381,12 @@ const MaritimeDashboard: React.FC = () => {
|
||||
}, [taskStatType]);
|
||||
|
||||
return (
|
||||
<div className="maritime-dashboard">
|
||||
<div className={`maritime-dashboard maritime-dashboard--compact-${compactLevel}`}>
|
||||
<div className="wave-bg-animation"></div>
|
||||
<div className="wave-layer"></div>
|
||||
<div className="wave-layer-2"></div>
|
||||
<div className="wave-layer-3"></div>
|
||||
<div className="maritime-bottom-frame" aria-hidden="true" />
|
||||
|
||||
<Spin spinning={loading} wrapperClassName="maritime-spin">
|
||||
<div className="maritime-content">
|
||||
|
||||
Reference in New Issue
Block a user