Merge pull request 'test' (#8) from test into prod
Reviewed-on: http://220.205.16.27:18081/goflytec/GoFly-platform-services/pulls/8
This commit is contained in:
@@ -60,7 +60,10 @@
|
||||
"Bash(del:*)",
|
||||
"Bash(cmd /c del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\controller\\CdnProxyController.java\")",
|
||||
"Bash(cmd /c del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\websocket\\config\\DeviceControlWebSocketConfig.java\")",
|
||||
"Bash(cmd /c del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\websocket\\handler\\DeviceControlWebSocketHandler.java\")"
|
||||
"Bash(cmd /c del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\websocket\\handler\\DeviceControlWebSocketHandler.java\")",
|
||||
"Bash(tree:*)",
|
||||
"Bash(move \"F:\\\\project\\\\go-fly-platform-services\\\\zlt-business\\\\order-center\\\\src\\\\main\\\\resources\\\\mapper\\\\mission\\\\MissionMapper.xml\" \"F:\\\\project\\\\go-fly-platform-services\\\\zlt-business\\\\order-center\\\\src\\\\main\\\\resources\\\\mapper\\\\MissionMapper.xml\")",
|
||||
"Bash(cmd /c move:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
+171
@@ -1,17 +1,40 @@
|
||||
package com.central.device.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.JsonElement;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.entity.WaylineRoute;
|
||||
import com.central.device.feign.FileCenterService;
|
||||
import com.central.device.message.ControlMessageConstant;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.model.LineFile;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
import com.central.device.service.ILineFileService;
|
||||
import com.central.device.service.IWaylineRouteService;
|
||||
import com.central.device.service.LiveStreamService;
|
||||
import com.central.device.util.IotRequestResult;
|
||||
import com.central.device.util.RequestUtils;
|
||||
import com.central.device.util.TencentLiveUtil;
|
||||
import com.central.device.websocket.manager.DeviceCommandManager;
|
||||
import com.central.device.websocket.model.CommandStatus;
|
||||
import com.central.device.websocket.model.DeviceCommand;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 设备命令控制器
|
||||
* 提供HTTP接口接收前端命令请求,发送命令到设备
|
||||
@@ -25,9 +48,29 @@ import org.springframework.web.bind.annotation.*;
|
||||
@Tag(name = "设备命令控制")
|
||||
public class DeviceCommandController {
|
||||
|
||||
@Value("${jetlinks.server.baseUrl}")
|
||||
private String baseUrl;
|
||||
|
||||
@Autowired
|
||||
private DeviceCommandManager commandManager;
|
||||
|
||||
@Autowired
|
||||
private ILineFileService lineFileService;
|
||||
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
|
||||
@Autowired
|
||||
private IWaylineRouteService iWaylineRouteService;
|
||||
|
||||
@Autowired
|
||||
private RequestUtils requestUtils;
|
||||
|
||||
@Resource
|
||||
private IAgeDeviceService iAgeDeviceService;
|
||||
|
||||
private final ControlMessageConstant controlMessageConstant = new ControlMessageConstant();
|
||||
|
||||
/**
|
||||
* 发送设备命令
|
||||
*/
|
||||
@@ -388,6 +431,134 @@ public class DeviceCommandController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行航线任务
|
||||
* 参考writeProperties逻辑,用于航线任务执行(不包含订单业务逻辑和幂等性检查)
|
||||
*/
|
||||
@Operation(summary = "执行航线任务")
|
||||
@PostMapping("/wayline/execute")
|
||||
public Result<String> executeWayline(@RequestParam("deviceSn") String deviceSn,
|
||||
@RequestParam("waylineId") String waylineId,
|
||||
@RequestParam("missionCode") String missionCode) {
|
||||
log.info("开始执行航线任务: deviceSn={}, waylineId={}, missionCode={}", deviceSn, waylineId, missionCode);
|
||||
try {
|
||||
// 1. 参数校验
|
||||
if (deviceSn == null || deviceSn.isEmpty()) {
|
||||
return Result.failed("设备SN不能为空");
|
||||
}
|
||||
if (waylineId == null || waylineId.isEmpty()) {
|
||||
return Result.failed("航线ID不能为空");
|
||||
}
|
||||
if (missionCode == null || missionCode.isEmpty()) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
//根据routeid去获取航迹文件
|
||||
WaylineRoute route = iWaylineRouteService.getByRouteId(waylineId);
|
||||
if(route==null){
|
||||
return Result.failed("航线文件不存在");
|
||||
}
|
||||
// 2. 获取航线文件信息
|
||||
LineFile lineFile = lineFileService.findLineFileByWaylineId(route.getFileWaylineId());
|
||||
if (lineFile == null) {
|
||||
log.error("航线文件不存在: waylineId={}", waylineId);
|
||||
return Result.failed("航线文件不存在");
|
||||
}
|
||||
|
||||
// 3. 构建控制消息
|
||||
JsonObject controlMessage = buildWaylineControlMessage(deviceSn, waylineId, missionCode, lineFile);
|
||||
if (controlMessage == null) {
|
||||
return Result.failed("构建航线控制消息失败");
|
||||
}
|
||||
// 4. 发送设备控制请求到IoT平台
|
||||
String url = baseUrl + "/device/instance/" + deviceSn + "/property";
|
||||
log.info("发送航线任务到IoT平台: url={}, message={}", url, controlMessage);
|
||||
java.util.Map<String, String> result = requestUtils.getPostRequestResultMap(url, controlMessage.toString());
|
||||
// 5. 处理响应结果
|
||||
return handleWaylineResponse(result, missionCode, deviceSn);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("执行航线任务异常: deviceSn={}, waylineId={}, missionCode={}, error={}",
|
||||
deviceSn, waylineId, missionCode, e.getMessage(), e);
|
||||
return Result.failed("执行航线任务异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建航线控制消息
|
||||
*/
|
||||
private JsonObject buildWaylineControlMessage(String deviceSn, String waylineId, String missionCode, LineFile lineFile) {
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
// 使用 flighttask_prepare 命令模板
|
||||
JsonObject jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get("flighttask_prepare"), JsonObject.class);
|
||||
JsonObject data = jsonObject.getAsJsonObject("data");
|
||||
|
||||
// 设置任务编码(代替订单号)
|
||||
data.addProperty("order_no", missionCode);
|
||||
|
||||
// 设置航线文件路径(从objectKey获取完整URL)
|
||||
String waylineFilePath = fileCenterService.getFileViewUrl(lineFile.getWaylineId());
|
||||
data.addProperty("wayline_link_url", waylineFilePath);
|
||||
// 设置航线文件MD5签名
|
||||
data.addProperty("file_md5", lineFile.getSign());
|
||||
// 设置设备视频流地址
|
||||
try {
|
||||
data.add("stream_urls", gson.fromJson(getStreamUrls(deviceSn).toJSONString(), JsonElement.class));
|
||||
} catch (Exception e) {
|
||||
log.error("生成设备推流/拉流地址异常: deviceSn={}, error={}", deviceSn, e.getMessage(), e);
|
||||
data.addProperty("stream_urls", "{}");
|
||||
}
|
||||
log.info("构建航线控制消息完成: deviceSn={}, waylineId={}, missionCode={}", deviceSn, waylineId, missionCode);
|
||||
return jsonObject;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("构建航线控制消息失败: deviceSn={}, waylineId={}, error={}", deviceSn, waylineId, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理航线任务响应结果
|
||||
*/
|
||||
private Result<String> handleWaylineResponse(java.util.Map<String, String> result, String missionCode, String deviceSn) throws JsonProcessingException {
|
||||
com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(result.get(""));
|
||||
if (object == null) {
|
||||
log.error("请求IoT平台异常,返回结果为空: missionCode={}", missionCode);
|
||||
return Result.failed("请求IoT平台异常");
|
||||
}
|
||||
IotRequestResult requestResult = IotRequestResult.getInstance(object);
|
||||
log.info("航线任务IoT响应: missionCode={}, status={}, message={}", missionCode, requestResult.getStatus(), requestResult.getMessage());
|
||||
|
||||
if (requestResult.getStatus() == 200) {
|
||||
log.info("航线任务下发成功: missionCode={}, deviceSn={}", missionCode, deviceSn);
|
||||
return Result.succeed(missionCode, "航线任务执行成功");
|
||||
} else if (requestResult.getStatus() == 500) {
|
||||
if ("Device is offline".equals(requestResult.getMessage())) {
|
||||
log.warn("设备离线,无法执行航线任务: missionCode={}, deviceSn={}", missionCode, deviceSn);
|
||||
return Result.failed("设备已离线,无法执行航线任务");
|
||||
}
|
||||
log.error("航线任务执行失败: missionCode={}, message={}", missionCode, requestResult.getMessage());
|
||||
return Result.failed("航线任务执行失败: " + requestResult.getMessage());
|
||||
}
|
||||
|
||||
return Result.failed("航线任务执行失败,请重试");
|
||||
}
|
||||
|
||||
|
||||
public JSONObject getStreamUrls(String deviceId) {
|
||||
JSONObject result = new JSONObject();
|
||||
AgeDevice device = iAgeDeviceService.getByDeviceSn(deviceId);
|
||||
if(Objects.nonNull(device)){
|
||||
result.put("pushUrl", device.getVideoStreamUrl());
|
||||
}
|
||||
result.put("playRtmpUrl", "");
|
||||
result.put("playFlvUrl", "");
|
||||
result.put("playM3u8Url", "");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取状态描述
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.central.file.mapper.FileMapper;
|
||||
import com.central.file.service.IFileService;
|
||||
import com.central.file.service.StorageHealthCheckService;
|
||||
import com.central.file.service.TimeWindowStorageService;
|
||||
import com.central.file.service.impl.S3Service;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
@@ -74,6 +76,12 @@ public class FileController {
|
||||
return fileService.upload(file);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/files-S3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public FileInfo uploadForS3(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
return fileService.uploadForS3(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传并返回智能路由后的访问地址
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.util.Map;
|
||||
public interface IFileService extends IService<FileInfo> {
|
||||
FileInfo upload(MultipartFile file ) throws Exception;
|
||||
|
||||
FileInfo uploadForS3(MultipartFile file ) throws Exception;
|
||||
|
||||
FileInfo upload(String name, InputStream inputStream) throws Exception;
|
||||
|
||||
PageResult<FileInfo> findList(Map<String, Object> params);
|
||||
|
||||
+48
@@ -8,8 +8,11 @@ import com.central.file.mapper.FileMapper;
|
||||
import com.central.file.service.IFileService;
|
||||
import com.central.file.utils.FileUtil;
|
||||
import com.central.oss.model.ObjectInfo;
|
||||
import com.central.oss.template.S3Template;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -27,6 +30,15 @@ import java.util.Map;
|
||||
public abstract class AbstractIFileService extends ServiceImpl<FileMapper, FileInfo> implements IFileService {
|
||||
private static final String FILE_SPLIT = ".";
|
||||
|
||||
@Autowired(required = false)
|
||||
private S3Template s3Template;
|
||||
|
||||
@Value("${cdn.s3.domain:minicdn.goflytec.com}")
|
||||
private String cdnDomain;
|
||||
|
||||
@Value("${cdn.s3.enabled:true}")
|
||||
private boolean cdnEnabled;
|
||||
|
||||
@Override
|
||||
public FileInfo upload(MultipartFile file) {
|
||||
FileInfo fileInfo = FileUtil.getFileInfo(file);
|
||||
@@ -44,6 +56,42 @@ public abstract class AbstractIFileService extends ServiceImpl<FileMapper, FileI
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FileInfo uploadForS3(MultipartFile file) {
|
||||
if (s3Template == null) {
|
||||
throw new RuntimeException("S3服务未配置,无法使用S3上传");
|
||||
}
|
||||
FileInfo fileInfo = FileUtil.getFileInfo(file);
|
||||
if (!fileInfo.getName().contains(FILE_SPLIT)) {
|
||||
throw new IllegalArgumentException("缺少后缀名");
|
||||
}
|
||||
// 直接使用S3Template上传,确保是S3存储
|
||||
ObjectInfo objectInfo = s3Template.upload(file);
|
||||
fileInfo.setPath(objectInfo.getObjectPath());
|
||||
// 设置CDN URL
|
||||
fileInfo.setUrl(buildCdnUrl(objectInfo.getObjectPath()));
|
||||
// 设置文件来源为S3
|
||||
fileInfo.setSource("s3");
|
||||
// 将文件信息保存到数据库
|
||||
baseMapper.insert(fileInfo);
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建CDN URL
|
||||
* @param objectPath 对象路径 (格式: bucket/objectKey)
|
||||
* @return CDN URL
|
||||
*/
|
||||
protected String buildCdnUrl(String objectPath) {
|
||||
if (cdnEnabled && cdnDomain != null && !cdnDomain.isEmpty()) {
|
||||
return "https://" + cdnDomain + "/" + objectPath;
|
||||
}
|
||||
// CDN未启用时返回原始路径
|
||||
return objectPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo upload(String name, InputStream inputStream) throws IOException {
|
||||
FileInfo fileInfo = FileUtil.getFileInfo(name, inputStream);
|
||||
|
||||
@@ -0,0 +1,904 @@
|
||||
# Mission(任务)功能设计文档
|
||||
|
||||
## 1. 功能概述
|
||||
|
||||
### 1.1 业务背景
|
||||
在3D任务管理页面,用户可以创建和管理机库执行任务(Mission)。与订单任务不同,Mission是由管理员在3D界面手动创建并下发给机库执行的航线任务。
|
||||
|
||||
### 1.2 业务流程
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Mission 任务执行流程 │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ 1. 选择航线 │
|
||||
│ ↓ │
|
||||
│ 2. 检查机库状态 (订阅消息中 model_code) │
|
||||
│ ├── model_code != 0 → 机库忙碌,禁止创建任务 │
|
||||
│ └── model_code == 0 → 机库空闲,可创建任务 │
|
||||
│ ↓ │
|
||||
│ 3. 调用后端接口创建 Mission │
|
||||
│ ↓ │
|
||||
│ 4. 调用设备执行方法下发任务命令给机库 │
|
||||
│ ↓ │
|
||||
│ 5. 机库执行航线任务 │
|
||||
│ ↓ │
|
||||
│ 6. 机库上传任务图片 │
|
||||
│ ↓ │
|
||||
│ 7. 保存任务图片到 mission_images 表 │
|
||||
│ ↓ │
|
||||
│ 8. 任务完成 │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 1.3 关键设计要点
|
||||
|
||||
1. **任务编码规则**:任务编码需要在编码前添加 `J` 前缀
|
||||
- 原因:下发设备执行任务的命令参数与订单执行任务的参数结构相同,需要通过 `J` 前缀区分
|
||||
- 示例:`J20251222001`(J + 日期 + 序号)
|
||||
- **唯一性要求**:任务编码必须全局唯一,数据库表设置唯一索引 `uk_mission_code`
|
||||
|
||||
2. **任务类型**:区分不同类型的任务,下发设备的指令逻辑不同
|
||||
- `1` - **航线任务(WAYLINE)**:选择航线后创建,下发航线执行指令
|
||||
- `2` - **一键起飞任务(TAKEOFF)**:一键起飞创建,下发起飞指令
|
||||
|
||||
3. **机库状态检查**:通过WebSocket/SSE订阅消息中的 `mode_code` 字段判断
|
||||
- `mode_code == 0`:机库空闲(待机状态),可创建任务
|
||||
- `mode_code != 0`(如 `mode_code == 1`):机库正在执行任务,创建按钮禁用
|
||||
- **已有实现参考**:`RightPanel.tsx` 中已订阅机库状态(第107行、117行)
|
||||
|
||||
---
|
||||
|
||||
## 2. 数据库设计
|
||||
|
||||
### 2.1 Mission 任务表
|
||||
|
||||
```sql
|
||||
-- =====================================================
|
||||
-- 表名: missions
|
||||
-- 描述: 任务主表,存储3D页面创建的航线任务信息
|
||||
-- =====================================================
|
||||
CREATE TABLE `missions` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`mission_code` VARCHAR(64) NOT NULL COMMENT '任务编码(J前缀+日期+序号,如J20251222001)',
|
||||
`mission_name` VARCHAR(128) DEFAULT NULL COMMENT '任务名称',
|
||||
`mission_type` TINYINT NOT NULL DEFAULT 1 COMMENT '任务类型(1:航线任务, 2:一键起飞任务)',
|
||||
`device_sn` VARCHAR(64) NOT NULL COMMENT '设备序列号(机库SN)',
|
||||
`wayline_id` VARCHAR(64) DEFAULT NULL COMMENT '航线ID(航线任务必填)',
|
||||
`wayline_name` VARCHAR(128) DEFAULT NULL COMMENT '航线名称',
|
||||
`workspace_id` VARCHAR(64) DEFAULT NULL COMMENT '工作区ID',
|
||||
`tourism_id` BIGINT DEFAULT NULL COMMENT '景区ID',
|
||||
`mission_status` TINYINT NOT NULL DEFAULT 1 COMMENT '任务状态(1:待执行, 2:已取消, 3:执行完成, 4:执行中, 5:图片上传中, 6:图片上传完成)',
|
||||
`target_latitude` DECIMAL(10,7) DEFAULT NULL COMMENT '目标纬度(一键起飞任务)',
|
||||
`target_longitude` DECIMAL(10,7) DEFAULT NULL COMMENT '目标经度(一键起飞任务)',
|
||||
`target_height` DECIMAL(10,2) DEFAULT NULL COMMENT '目标高度(一键起飞任务,米)',
|
||||
`start_time` DATETIME DEFAULT NULL COMMENT '任务开始时间',
|
||||
`end_time` DATETIME DEFAULT NULL COMMENT '任务结束时间',
|
||||
`creator_id` BIGINT DEFAULT NULL COMMENT '创建人ID',
|
||||
`creator_name` VARCHAR(64) DEFAULT NULL COMMENT '创建人姓名',
|
||||
`remark` VARCHAR(512) DEFAULT NULL COMMENT '备注',
|
||||
`tenant_id` VARCHAR(32) DEFAULT 'webApp' COMMENT '租户ID',
|
||||
`is_del` TINYINT NOT NULL DEFAULT 0 COMMENT '删除标记(0:正常, 1:已删除)',
|
||||
`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`),
|
||||
UNIQUE KEY `uk_mission_code` (`mission_code`),
|
||||
KEY `idx_device_sn` (`device_sn`),
|
||||
KEY `idx_wayline_id` (`wayline_id`),
|
||||
KEY `idx_tourism_id` (`tourism_id`),
|
||||
KEY `idx_mission_type` (`mission_type`),
|
||||
KEY `idx_mission_status` (`mission_status`),
|
||||
KEY `idx_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='任务表';
|
||||
```
|
||||
|
||||
### 2.2 Mission Images 任务图片表
|
||||
|
||||
```sql
|
||||
-- =====================================================
|
||||
-- 表名: mission_images
|
||||
-- 描述: 任务图片表,存储机库执行任务后上传的图片
|
||||
-- =====================================================
|
||||
CREATE TABLE `mission_images` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`mission_code` VARCHAR(64) NOT NULL COMMENT '任务编码',
|
||||
`file_id` VARCHAR(64) DEFAULT NULL COMMENT '文件ID(file-center生成)',
|
||||
`file_path` VARCHAR(512) NOT NULL COMMENT '文件路径(不含bucket)',
|
||||
`file_name` VARCHAR(256) DEFAULT NULL COMMENT '文件名',
|
||||
`file_type` VARCHAR(64) DEFAULT NULL COMMENT '文件MIME类型',
|
||||
`file_size` BIGINT DEFAULT NULL COMMENT '文件大小(字节)',
|
||||
`file_tag` VARCHAR(32) DEFAULT NULL COMMENT '文件标签(如:raw_image, processed_image)',
|
||||
`tourism_id` BIGINT DEFAULT NULL COMMENT '景区ID',
|
||||
`device_sn` VARCHAR(64) DEFAULT NULL COMMENT '设备序列号',
|
||||
`capture_time` DATETIME DEFAULT NULL COMMENT '拍摄时间',
|
||||
`latitude` DECIMAL(10,7) DEFAULT NULL COMMENT '拍摄纬度',
|
||||
`longitude` DECIMAL(10,7) DEFAULT NULL COMMENT '拍摄经度',
|
||||
`altitude` DECIMAL(10,2) DEFAULT NULL COMMENT '拍摄高度(米)',
|
||||
`tenant_id` VARCHAR(32) DEFAULT 'webApp' COMMENT '租户ID',
|
||||
`is_del` TINYINT NOT NULL DEFAULT 0 COMMENT '删除标记(0:正常, 1:已删除)',
|
||||
`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_mission_code` (`mission_code`),
|
||||
KEY `idx_file_id` (`file_id`),
|
||||
KEY `idx_tourism_id` (`tourism_id`),
|
||||
KEY `idx_device_sn` (`device_sn`),
|
||||
KEY `idx_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='任务图片表';
|
||||
```
|
||||
|
||||
### 2.3 任务状态枚举
|
||||
|
||||
> **说明**:任务状态数值与订单状态 `OrderStatus` 保持一致,便于复用设备端逻辑。去掉支付和退款相关状态。
|
||||
|
||||
| 状态值 | 状态名称 | 对应订单状态 | 描述 |
|
||||
|-------|---------|-------------|------|
|
||||
| 1 | PENDING | PAID(1) | 待执行 - 任务已创建,等待下发执行 |
|
||||
| 2 | CANCELED | CANCELED(2) | 已取消 - 任务被取消 |
|
||||
| 3 | COMPLETE | COMPLETE(3) | 执行完成 - 设备执行完成 |
|
||||
| 4 | DOING | DOING(4) | 执行中 - 任务已下发,机库正在执行 |
|
||||
| 5 | UPLOADING | UPLOADING(5) | 图片上传中 - 机库正在上传图片 |
|
||||
| 6 | UPLOADED | UPLOADED(6) | 图片上传完成 - 任务完成 |
|
||||
|
||||
### 2.4 任务类型枚举
|
||||
|
||||
| 类型值 | 类型名称 | 说明 | 下发指令 |
|
||||
|-------|---------|------|---------|
|
||||
| 1 | WAYLINE | 航线任务 | 调用航线执行接口,需要 waylineId |
|
||||
| 2 | TAKEOFF | 一键起飞任务 | 调用起飞接口,需要目标坐标和高度 |
|
||||
|
||||
**不同任务类型的必填字段:**
|
||||
|
||||
| 字段 | 航线任务(1) | 一键起飞任务(2) |
|
||||
|-----|-----------|---------------|
|
||||
| wayline_id | 必填 | 不需要 |
|
||||
| wayline_name | 选填 | 不需要 |
|
||||
| target_latitude | 不需要 | 必填 |
|
||||
| target_longitude | 不需要 | 必填 |
|
||||
| target_height | 不需要 | 必填 |
|
||||
|
||||
---
|
||||
|
||||
## 3. 后端接口设计
|
||||
|
||||
### 3.1 代码目录结构
|
||||
|
||||
```
|
||||
order-center/src/main/java/com/central/order/
|
||||
├── mission/ # Mission模块目录
|
||||
│ ├── controller/
|
||||
│ │ ├── MissionController.java # 任务管理接口
|
||||
│ │ └── MissionImageController.java # 任务图片管理接口
|
||||
│ ├── model/
|
||||
│ │ ├── Mission.java # 任务实体类
|
||||
│ │ ├── MissionImage.java # 任务图片实体类
|
||||
│ │ ├── dto/
|
||||
│ │ │ ├── CreateMissionRequest.java # 创建任务请求DTO
|
||||
│ │ │ └── MissionStatusRequest.java # 状态更新请求DTO
|
||||
│ │ └── vo/
|
||||
│ │ ├── MissionVO.java # 任务视图对象
|
||||
│ │ └── MissionImageVO.java # 任务图片视图对象
|
||||
│ ├── mapper/
|
||||
│ │ ├── MissionMapper.java # 任务Mapper
|
||||
│ │ └── MissionImageMapper.java # 任务图片Mapper
|
||||
│ ├── service/
|
||||
│ │ ├── IMissionService.java # 任务服务接口
|
||||
│ │ ├── IMissionImageService.java # 任务图片服务接口
|
||||
│ │ └── impl/
|
||||
│ │ ├── MissionServiceImpl.java # 任务服务实现
|
||||
│ │ └── MissionImageServiceImpl.java # 任务图片服务实现
|
||||
│ └── enums/
|
||||
│ └── MissionStatus.java # 任务状态枚举
|
||||
└── resources/
|
||||
└── mapper/
|
||||
├── MissionMapper.xml # 任务Mapper XML
|
||||
└── MissionImageMapper.xml # 任务图片Mapper XML
|
||||
```
|
||||
|
||||
### 3.2 核心接口列表
|
||||
|
||||
#### 3.2.1 任务管理接口 (MissionController)
|
||||
|
||||
| 接口 | 方法 | 路径 | 描述 |
|
||||
|-----|------|------|------|
|
||||
| 创建任务 | POST | `/mission/saveMission` | 创建新的航线任务 |
|
||||
| 任务列表 | POST | `/mission/listMission` | 分页查询任务列表 |
|
||||
| 任务详情 | POST | `/mission/getMission` | 获取任务详情 |
|
||||
| 更新任务状态 | POST | `/mission/updateMissionStatus` | 更新任务状态(设备回调) |
|
||||
| 取消任务 | POST | `/mission/cancelMission` | 取消任务 |
|
||||
| 删除任务 | POST | `/mission/deleteMission` | 删除任务(逻辑删除) |
|
||||
| 完成任务 | POST | `/mission/completeMission` | 机库回调任务完成 |
|
||||
|
||||
#### 3.2.2 任务图片接口 (MissionImageController)
|
||||
|
||||
| 接口 | 方法 | 路径 | 描述 |
|
||||
|-----|------|------|------|
|
||||
| 上传图片记录 | POST | `/mission/image/saveMissionImage` | 机库回传图片路径创建记录 |
|
||||
| 图片列表 | POST | `/mission/image/listMissionImage` | 获取任务的所有图片 |
|
||||
| 图片详情 | POST | `/mission/image/getMissionImage` | 获取图片详情 |
|
||||
| 删除图片 | POST | `/mission/image/deleteMissionImage` | 删除图片记录 |
|
||||
|
||||
### 3.3 接口详细设计
|
||||
|
||||
#### 3.3.1 创建任务 (POST /mission/saveMission)
|
||||
|
||||
**请求参数(航线任务 missionType=1):**
|
||||
```json
|
||||
{
|
||||
"missionType": 1,
|
||||
"deviceSn": "机库设备序列号",
|
||||
"waylineId": "航线ID",
|
||||
"waylineName": "航线名称",
|
||||
"tourismId": 1,
|
||||
"missionName": "任务名称(可选)",
|
||||
"remark": "备注(可选)"
|
||||
}
|
||||
```
|
||||
|
||||
**请求参数(一键起飞任务 missionType=2):**
|
||||
```json
|
||||
{
|
||||
"missionType": 2,
|
||||
"deviceSn": "机库设备序列号",
|
||||
"tourismId": 1,
|
||||
"targetLatitude": 30.123456,
|
||||
"targetLongitude": 120.123456,
|
||||
"targetHeight": 50.0,
|
||||
"missionName": "一键起飞任务(可选)",
|
||||
"remark": "备注(可选)"
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "任务创建成功",
|
||||
"datas": {
|
||||
"id": 1,
|
||||
"missionCode": "J20251222001",
|
||||
"missionType": 1,
|
||||
"missionName": "航线巡检任务",
|
||||
"deviceSn": "DOCK-001",
|
||||
"waylineId": "wayline-123",
|
||||
"waylineName": "景区A号航线",
|
||||
"missionStatus": 1,
|
||||
"createTime": "2025-12-22 10:00:00"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**业务逻辑:**
|
||||
1. 生成任务编码(J + yyyyMMdd + 3位序号)
|
||||
2. 根据 `missionType` 校验必填参数:
|
||||
- 航线任务(1):校验 waylineId 必填
|
||||
- 一键起飞任务(2):校验 targetLatitude、targetLongitude、targetHeight 必填
|
||||
3. 保存任务记录到数据库,状态为 `PENDING(1)`
|
||||
4. 根据任务类型调用不同的设备接口:
|
||||
- 航线任务(1):调用航线执行接口
|
||||
- 一键起飞任务(2):调用起飞接口
|
||||
5. 任务下发成功后更新状态为 `DOING(4)`
|
||||
|
||||
#### 3.3.2 更新任务状态 (POST /mission/updateMissionStatus)
|
||||
|
||||
**请求参数:**
|
||||
```json
|
||||
{
|
||||
"missionCode": "J20251222001",
|
||||
"status": 3,
|
||||
"remark": "任务执行完成"
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "状态更新成功"
|
||||
}
|
||||
```
|
||||
|
||||
**状态流转规则:**
|
||||
```
|
||||
PENDING(1) → DOING(4) :任务开始执行
|
||||
PENDING(1) → CANCELED(2) :取消待执行任务
|
||||
DOING(4) → UPLOADING(5) :机库开始上传图片
|
||||
DOING(4) → COMPLETE(3) :任务执行完成(无图片上传)
|
||||
UPLOADING(5) → UPLOADED(6) :图片上传完成
|
||||
UPLOADED(6) → COMPLETE(3) :任务最终完成
|
||||
```
|
||||
|
||||
#### 3.3.3 机库回传图片 (POST /mission/image/saveMissionImage)
|
||||
|
||||
**请求参数:**
|
||||
```json
|
||||
{
|
||||
"missionCode": "J20251222001",
|
||||
"filePath": "mission/2025/12/22/image001.jpg",
|
||||
"fileName": "image001.jpg",
|
||||
"captureTime": "2025-12-22 10:30:00",
|
||||
"latitude": 30.123456,
|
||||
"longitude": 120.123456,
|
||||
"altitude": 100.5
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "图片记录创建成功",
|
||||
"datas": {
|
||||
"id": 1,
|
||||
"missionCode": "J20251222001",
|
||||
"fileId": "file-uuid-123",
|
||||
"filePath": "mission/2025/12/22/image001.jpg",
|
||||
"viewUrl": "https://cdn.example.com/mission/2025/12/22/image001.jpg"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**业务逻辑(参考订单素材上传):**
|
||||
1. 校验任务是否存在
|
||||
2. 校验图片路径是否已存在(避免重复创建)
|
||||
3. 调用 file-center 创建文件信息
|
||||
4. 保存图片记录到 `mission_images` 表
|
||||
5. 如果任务状态为 `PENDING(1)` 或 `DOING(4)`,更新为 `UPLOADING(5)`
|
||||
|
||||
#### 3.3.4 完成任务 (POST /mission/completeMission)
|
||||
|
||||
**请求参数:**
|
||||
```json
|
||||
{
|
||||
"missionCode": "J20251222001",
|
||||
"remark": "任务执行完成"
|
||||
}
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{
|
||||
"resp_code": 0,
|
||||
"resp_msg": "任务完成"
|
||||
}
|
||||
```
|
||||
|
||||
**业务逻辑(参考订单完成):**
|
||||
1. 校验任务是否存在
|
||||
2. 校验任务状态是否为 `DOING(4)`、`UPLOADING(5)` 或 `UPLOADED(6)`
|
||||
3. 更新任务状态为 `COMPLETE(3)`
|
||||
4. 记录任务结束时间
|
||||
|
||||
---
|
||||
|
||||
## 4. 实体类设计
|
||||
|
||||
### 4.1 Mission.java
|
||||
|
||||
```java
|
||||
package com.central.order.mission.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("missions")
|
||||
public class Mission extends SuperEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 任务编码(J前缀) */
|
||||
private String missionCode;
|
||||
|
||||
/** 任务名称 */
|
||||
private String missionName;
|
||||
|
||||
/** 任务类型(1:航线任务, 2:一键起飞任务) */
|
||||
private Integer missionType;
|
||||
|
||||
/** 设备序列号(机库SN) */
|
||||
private String deviceSn;
|
||||
|
||||
/** 航线ID(航线任务必填) */
|
||||
private String waylineId;
|
||||
|
||||
/** 航线名称 */
|
||||
private String waylineName;
|
||||
|
||||
/** 工作区ID */
|
||||
private String workspaceId;
|
||||
|
||||
/** 景区ID */
|
||||
private Long tourismId;
|
||||
|
||||
/** 任务状态 */
|
||||
private Integer missionStatus;
|
||||
|
||||
/** 目标纬度(一键起飞任务) */
|
||||
private BigDecimal targetLatitude;
|
||||
|
||||
/** 目标经度(一键起飞任务) */
|
||||
private BigDecimal targetLongitude;
|
||||
|
||||
/** 目标高度(一键起飞任务,米) */
|
||||
private BigDecimal targetHeight;
|
||||
|
||||
/** 任务开始时间 */
|
||||
private Date startTime;
|
||||
|
||||
/** 任务结束时间 */
|
||||
private Date endTime;
|
||||
|
||||
/** 创建人ID */
|
||||
private Long creatorId;
|
||||
|
||||
/** 创建人姓名 */
|
||||
private String creatorName;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
/** 租户ID */
|
||||
private String tenantId;
|
||||
|
||||
/** 删除标记 */
|
||||
private Integer isDel;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
// ========== 临时字段 ==========
|
||||
/** 景区名称(联表查询) */
|
||||
@TableField(exist = false)
|
||||
private transient String tourismName;
|
||||
|
||||
/** 任务图片数量 */
|
||||
@TableField(exist = false)
|
||||
private transient Integer imageCount;
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 MissionImage.java
|
||||
|
||||
```java
|
||||
package com.central.order.mission.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mission_images")
|
||||
public class MissionImage extends SuperEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 任务编码 */
|
||||
private String missionCode;
|
||||
|
||||
/** 文件ID(file-center生成) */
|
||||
private String fileId;
|
||||
|
||||
/** 文件路径(不含bucket) */
|
||||
private String filePath;
|
||||
|
||||
/** 文件名 */
|
||||
private String fileName;
|
||||
|
||||
/** 文件MIME类型 */
|
||||
private String fileType;
|
||||
|
||||
/** 文件大小(字节) */
|
||||
private Long fileSize;
|
||||
|
||||
/** 文件标签 */
|
||||
private String fileTag;
|
||||
|
||||
/** 景区ID */
|
||||
private Long tourismId;
|
||||
|
||||
/** 设备序列号 */
|
||||
private String deviceSn;
|
||||
|
||||
/** 拍摄时间 */
|
||||
private Date captureTime;
|
||||
|
||||
/** 拍摄纬度 */
|
||||
private BigDecimal latitude;
|
||||
|
||||
/** 拍摄经度 */
|
||||
private BigDecimal longitude;
|
||||
|
||||
/** 拍摄高度(米) */
|
||||
private BigDecimal altitude;
|
||||
|
||||
/** 租户ID */
|
||||
private String tenantId;
|
||||
|
||||
/** 删除标记 */
|
||||
private Integer isDel;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
// ========== 临时字段 ==========
|
||||
/** 图片访问URL */
|
||||
@TableField(exist = false)
|
||||
private transient String viewUrl;
|
||||
|
||||
/** 缩略图URL */
|
||||
@TableField(exist = false)
|
||||
private transient String thumbnailUrl;
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 MissionStatus.java
|
||||
|
||||
```java
|
||||
package com.central.order.mission.enums;
|
||||
|
||||
import com.central.common.enums.ZltEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务状态枚举
|
||||
* 状态值与 OrderStatus 保持一致,便于复用设备端逻辑
|
||||
* 去掉支付相关(0-UNPAID)和退款相关(7-10)状态
|
||||
*/
|
||||
@Getter
|
||||
public enum MissionStatus implements ZltEnum {
|
||||
// 对应 OrderStatus.PAID(1)
|
||||
PENDING(1, "待执行"),
|
||||
// 对应 OrderStatus.CANCELED(2)
|
||||
CANCELED(2, "已取消"),
|
||||
// 对应 OrderStatus.COMPLETE(3)
|
||||
COMPLETE(3, "执行完成"),
|
||||
// 对应 OrderStatus.DOING(4)
|
||||
DOING(4, "执行中"),
|
||||
// 对应 OrderStatus.UPLOADING(5)
|
||||
UPLOADING(5, "图片上传中"),
|
||||
// 对应 OrderStatus.UPLOADED(6)
|
||||
UPLOADED(6, "图片上传完成");
|
||||
|
||||
MissionStatus(Integer id, String content) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
private final Integer id;
|
||||
private final String content;
|
||||
|
||||
public static MissionStatus fromId(Integer id) {
|
||||
if (id == null) return null;
|
||||
for (MissionStatus status : values()) {
|
||||
if (status.getId().equals(id)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDesc(Integer id) {
|
||||
MissionStatus status = fromId(id);
|
||||
return status != null ? status.getContent() : "未知状态";
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为最终状态
|
||||
*/
|
||||
public static boolean isFinalStatus(Integer status) {
|
||||
return status != null && (
|
||||
status.equals(COMPLETE.getId()) ||
|
||||
status.equals(CANCELED.getId()) ||
|
||||
status.equals(UPLOADED.getId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可取消(只有待执行状态可取消)
|
||||
*/
|
||||
public static boolean canCancel(Integer status) {
|
||||
return status != null && status.equals(PENDING.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效的编辑状态(执行完成后可查看)
|
||||
*/
|
||||
public static boolean isValidForView(Integer status) {
|
||||
return status != null && (
|
||||
status.equals(COMPLETE.getId()) ||
|
||||
status.equals(UPLOADED.getId())
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4 MissionType.java
|
||||
|
||||
```java
|
||||
package com.central.order.mission.enums;
|
||||
|
||||
import com.central.common.enums.ZltEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务类型枚举
|
||||
*/
|
||||
@Getter
|
||||
public enum MissionType implements ZltEnum {
|
||||
WAYLINE(1, "航线任务"),
|
||||
TAKEOFF(2, "一键起飞任务");
|
||||
|
||||
MissionType(Integer id, String content) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
private final Integer id;
|
||||
private final String content;
|
||||
|
||||
public static MissionType fromId(Integer id) {
|
||||
if (id == null) return null;
|
||||
for (MissionType type : values()) {
|
||||
if (type.getId().equals(id)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDesc(Integer id) {
|
||||
MissionType type = fromId(id);
|
||||
return type != null ? type.getContent() : "未知类型";
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为航线任务
|
||||
*/
|
||||
public static boolean isWaylineTask(Integer type) {
|
||||
return type != null && type.equals(WAYLINE.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为一键起飞任务
|
||||
*/
|
||||
public static boolean isTakeoffTask(Integer type) {
|
||||
return type != null && type.equals(TAKEOFF.getId());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 前端设计
|
||||
|
||||
### 5.1 3D任务管理页面功能
|
||||
|
||||
#### 5.1.1 已有机库状态订阅(RightPanel.tsx)
|
||||
|
||||
> **文件路径**:`zlt-web/react-web-next/src/pages/device/mapDashboard/components/MapContainer/3d/BottomPanel/RightPanel.tsx`
|
||||
|
||||
已有实现可直接复用:
|
||||
```typescript
|
||||
// 第47行:使用SSE订阅设备实时数据
|
||||
const { realtimeData, sseConnected, connectSSE, disconnectSSE } = useDeviceSSE();
|
||||
|
||||
// 第107行:获取机库数据
|
||||
const dockData = realtimeData?.rawData?.dockData;
|
||||
|
||||
// 第117行:检查机库状态
|
||||
if (dockData?.mode_code !== 0) {
|
||||
message.warning('机库正在执行任务,无法起飞');
|
||||
return;
|
||||
}
|
||||
|
||||
// 第264行:按钮禁用逻辑
|
||||
disabled={takeoffLoading || dockData?.mode_code === 1 || dockData?.drone_in_dock === 0}
|
||||
|
||||
// 第281行:状态显示
|
||||
{renderItem('运行模式', dockData?.mode_code === 1 ? '工作' : '待机', '', dockData?.mode_code === 1 ? 'warning' : 'success')}
|
||||
```
|
||||
|
||||
#### 5.1.2 任务创建流程
|
||||
```
|
||||
1. 用户在3D界面选择航线
|
||||
2. 复用 RightPanel.tsx 中的 useDeviceSSE 订阅,获取 dockData.mode_code
|
||||
3. 判断机库状态:
|
||||
- mode_code !== 0 → 创建按钮禁用,显示"机库忙碌中"提示
|
||||
- mode_code === 0 → 创建按钮可用
|
||||
4. 用户点击"创建任务"按钮
|
||||
5. 调用 POST /mission/saveMission 接口创建任务
|
||||
6. 创建成功后刷新任务列表
|
||||
```
|
||||
|
||||
#### 5.1.3 任务列表展示
|
||||
| 字段 | 描述 |
|
||||
|-----|------|
|
||||
| 任务编码 | J20251222001 |
|
||||
| 任务类型 | 航线任务 / 一键起飞 (带类型标签) |
|
||||
| 任务名称 | 航线巡检任务 |
|
||||
| 航线名称 | 景区A号航线 |
|
||||
| 设备SN | DOCK-001 |
|
||||
| 任务状态 | 执行中 (带状态标签颜色) |
|
||||
| 图片数量 | 10 (可点击查看) |
|
||||
| 创建时间 | 2025-12-22 10:00:00 |
|
||||
| 操作 | 查看详情 / 查看图片 / 取消 |
|
||||
|
||||
#### 5.1.4 任务图片展示
|
||||
- 图片预览模式:缩略图网格展示
|
||||
- 支持图片大图预览
|
||||
- 显示拍摄信息:时间、经纬度、高度
|
||||
- 支持下载单张/批量下载
|
||||
|
||||
### 5.2 状态标签颜色设计
|
||||
| 状态值 | 状态 | 颜色 | Tag类型 |
|
||||
|-------|-----|------|---------|
|
||||
| 1 | 待执行 | 蓝色 | processing |
|
||||
| 2 | 已取消 | 灰色 | default |
|
||||
| 3 | 执行完成 | 绿色 | success |
|
||||
| 4 | 执行中 | 橙色 | warning |
|
||||
| 5 | 图片上传中 | 青色 | cyan |
|
||||
| 6 | 图片上传完成 | 绿色 | success |
|
||||
|
||||
### 5.3 任务类型标签颜色设计
|
||||
| 类型值 | 类型 | 颜色 | Tag类型 |
|
||||
|-------|-----|------|---------|
|
||||
| 1 | 航线任务 | 蓝色 | blue |
|
||||
| 2 | 一键起飞 | 紫色 | purple |
|
||||
|
||||
---
|
||||
|
||||
## 6. 与订单模块的对比
|
||||
|
||||
| 对比项 | Order(订单) | Mission(任务) |
|
||||
|-------|-------------|----------------|
|
||||
| 编码前缀 | 无前缀或其他前缀 | J前缀 |
|
||||
| 创建方式 | 用户扫码支付创建 | 管理员3D页面手动创建 |
|
||||
| 支付功能 | 需要支付 | 无需支付 |
|
||||
| 执行触发 | 排队等待执行 | 创建后立即下发执行 |
|
||||
| 任务类型 | 单一类型 | 航线任务(1) / 一键起飞(2) |
|
||||
| 素材类型 | 图片+视频 | 主要是图片 |
|
||||
| 状态数量 | 11个状态(0-10) | 6个状态(1-6),与订单对应 |
|
||||
| 一键成片 | 支持 | 暂不支持 |
|
||||
| 退款功能 | 支持(7-10) | 不支持 |
|
||||
|
||||
### 6.1 状态对照表
|
||||
|
||||
| 状态值 | Order状态 | Mission状态 | 说明 |
|
||||
|-------|----------|-------------|------|
|
||||
| 0 | UNPAID(待支付) | - | 任务无需支付 |
|
||||
| 1 | PAID(已支付排队中) | PENDING(待执行) | 等待执行 |
|
||||
| 2 | CANCELED(已取消) | CANCELED(已取消) | 相同 |
|
||||
| 3 | COMPLETE(设备执行完成) | COMPLETE(执行完成) | 相同 |
|
||||
| 4 | DOING(正在服务中) | DOING(执行中) | 相同 |
|
||||
| 5 | UPLOADING(素材上传中) | UPLOADING(图片上传中) | 相同 |
|
||||
| 6 | UPLOADED(素材上传完成) | UPLOADED(图片上传完成) | 相同 |
|
||||
| 7-10 | 退款相关状态 | - | 任务不支持退款 |
|
||||
|
||||
---
|
||||
|
||||
## 7. 开发任务清单
|
||||
|
||||
### 7.1 后端开发任务
|
||||
|
||||
- [ ] **数据库**
|
||||
- [ ] 创建 `missions` 表
|
||||
- [ ] 创建 `mission_images` 表
|
||||
- [ ] 添加必要的索引
|
||||
|
||||
- [ ] **实体类**
|
||||
- [ ] 创建 `Mission.java`
|
||||
- [ ] 创建 `MissionImage.java`
|
||||
- [ ] 创建 `MissionStatus.java` 枚举
|
||||
- [ ] 创建 `MissionType.java` 枚举
|
||||
|
||||
- [ ] **Mapper层**
|
||||
- [ ] 创建 `MissionMapper.java`
|
||||
- [ ] 创建 `MissionImageMapper.java`
|
||||
- [ ] 创建 `MissionMapper.xml`
|
||||
- [ ] 创建 `MissionImageMapper.xml`
|
||||
|
||||
- [ ] **Service层**
|
||||
- [ ] 创建 `IMissionService.java`
|
||||
- [ ] 创建 `IMissionImageService.java`
|
||||
- [ ] 创建 `MissionServiceImpl.java`
|
||||
- [ ] 创建 `MissionImageServiceImpl.java`
|
||||
|
||||
- [ ] **Controller层**
|
||||
- [ ] 创建 `MissionController.java`
|
||||
- [ ] 创建 `MissionImageController.java`
|
||||
|
||||
- [ ] **任务编码生成**
|
||||
- [ ] 实现 J + yyyyMMdd + 序号 的编码生成逻辑
|
||||
- [ ] 使用数据库唯一索引 + 乐观锁确保并发安全
|
||||
- [ ] 编码生成失败时自动重试
|
||||
|
||||
- [ ] **设备中心调用**
|
||||
- [ ] 复用现有 Feign 接口下发任务命令
|
||||
|
||||
### 7.2 前端开发任务
|
||||
|
||||
- [ ] **任务管理组件**
|
||||
- [ ] 任务创建表单(航线选择、任务名称)
|
||||
- [ ] 任务列表表格
|
||||
- [ ] 任务状态标签组件
|
||||
- [x] 机库状态检查逻辑(已有:RightPanel.tsx useDeviceSSE)
|
||||
|
||||
- [ ] **任务图片组件**
|
||||
- [ ] 图片网格展示
|
||||
- [ ] 图片大图预览
|
||||
- [ ] 图片信息展示(经纬度、高度)
|
||||
- [ ] 图片下载功能
|
||||
|
||||
- [ ] **状态管理**
|
||||
- [ ] 任务列表状态管理
|
||||
- [x] SSE 机库状态订阅(已有:useDeviceSSE hook)
|
||||
|
||||
### 7.3 接口联调任务
|
||||
|
||||
- [ ] 创建任务接口联调
|
||||
- [ ] 任务列表查询联调
|
||||
- [ ] 任务状态更新联调
|
||||
- [ ] 图片上传回调联调
|
||||
- [ ] 图片列表查询联调
|
||||
|
||||
---
|
||||
|
||||
## 8. 注意事项
|
||||
|
||||
1. **任务编码唯一性**:
|
||||
- J前缀确保与订单编码区分,便于设备端识别任务类型
|
||||
- 数据库设置唯一索引 `uk_mission_code` 确保全局唯一
|
||||
- 编码生成建议使用:`J` + `yyyyMMdd` + `3位自增序号`(如 J20251222001)
|
||||
- 并发场景下使用乐观锁或分布式锁避免编码冲突
|
||||
|
||||
2. **并发处理**:多个任务同时创建时,编码生成需要考虑并发安全
|
||||
|
||||
3. **状态同步**:任务状态需要通过设备回调及时更新
|
||||
|
||||
4. **图片存储**:复用现有的 file-center 文件存储服务
|
||||
|
||||
5. **权限控制**:任务管理功能需要特定角色权限
|
||||
|
||||
6. **错误处理**:设备执行失败时需要正确记录失败原因
|
||||
|
||||
7. **前端复用**:机库状态订阅已在 `RightPanel.tsx` 中实现(useDeviceSSE),可直接复用
|
||||
|
||||
---
|
||||
|
||||
## 9. 参考代码
|
||||
|
||||
### 9.1 后端参考
|
||||
- 订单创建:`OrderController.java`
|
||||
- 订单状态更新:`OrderController.updateOrderStatusDoing()`
|
||||
- 素材上传:`OrderFileController.createOrderFileForPath()`
|
||||
- 状态枚举:`OrderStatus.java`
|
||||
- 设备调用:`DeviceCenterService.java`
|
||||
|
||||
### 9.2 前端参考
|
||||
- 机库状态订阅:`RightPanel.tsx:47` - useDeviceSSE hook
|
||||
- 机库数据获取:`RightPanel.tsx:107` - realtimeData?.rawData?.dockData
|
||||
- 状态检查逻辑:`RightPanel.tsx:117` - dockData?.mode_code !== 0
|
||||
- 按钮禁用逻辑:`RightPanel.tsx:264` - dockData?.mode_code === 1
|
||||
|
||||
---
|
||||
|
||||
**文档版本**: v1.0
|
||||
**创建时间**: 2025-12-22
|
||||
**作者**: dzc
|
||||
@@ -0,0 +1,74 @@
|
||||
-- =====================================================
|
||||
-- Mission 任务功能数据库脚本
|
||||
-- 创建时间: 2025-12-22
|
||||
-- 作者: dzc
|
||||
-- =====================================================
|
||||
|
||||
-- =====================================================
|
||||
-- 表名: missions
|
||||
-- 描述: 任务主表,存储3D页面创建的航线任务信息
|
||||
-- =====================================================
|
||||
CREATE TABLE IF NOT EXISTS `missions` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`mission_code` VARCHAR(64) NOT NULL COMMENT '任务编码(J前缀+日期+序号,如J20251222001)',
|
||||
`mission_name` VARCHAR(128) DEFAULT NULL COMMENT '任务名称',
|
||||
`mission_type` TINYINT NOT NULL DEFAULT 1 COMMENT '任务类型(1:航线任务, 2:一键起飞任务)',
|
||||
`device_sn` VARCHAR(64) NOT NULL COMMENT '设备序列号(机库SN)',
|
||||
`wayline_id` VARCHAR(64) DEFAULT NULL COMMENT '航线ID(航线任务必填)',
|
||||
`wayline_name` VARCHAR(128) DEFAULT NULL COMMENT '航线名称',
|
||||
`workspace_id` VARCHAR(64) DEFAULT NULL COMMENT '工作区ID',
|
||||
`tourism_id` BIGINT DEFAULT NULL COMMENT '景区ID',
|
||||
`mission_status` TINYINT NOT NULL DEFAULT 1 COMMENT '任务状态(1:待执行, 2:已取消, 3:执行完成, 4:执行中, 5:图片上传中, 6:图片上传完成)',
|
||||
`target_latitude` DECIMAL(10,7) DEFAULT NULL COMMENT '目标纬度(一键起飞任务)',
|
||||
`target_longitude` DECIMAL(10,7) DEFAULT NULL COMMENT '目标经度(一键起飞任务)',
|
||||
`target_height` DECIMAL(10,2) DEFAULT NULL COMMENT '目标高度(一键起飞任务,米)',
|
||||
`start_time` DATETIME DEFAULT NULL COMMENT '任务开始时间',
|
||||
`end_time` DATETIME DEFAULT NULL COMMENT '任务结束时间',
|
||||
`creator_id` BIGINT DEFAULT NULL COMMENT '创建人ID',
|
||||
`creator_name` VARCHAR(64) DEFAULT NULL COMMENT '创建人姓名',
|
||||
`remark` VARCHAR(512) DEFAULT NULL COMMENT '备注',
|
||||
`tenant_id` VARCHAR(32) DEFAULT 'webApp' COMMENT '租户ID',
|
||||
`is_del` TINYINT NOT NULL DEFAULT 0 COMMENT '删除标记(0:正常, 1:已删除)',
|
||||
`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`),
|
||||
UNIQUE KEY `uk_mission_code` (`mission_code`),
|
||||
KEY `idx_device_sn` (`device_sn`),
|
||||
KEY `idx_wayline_id` (`wayline_id`),
|
||||
KEY `idx_tourism_id` (`tourism_id`),
|
||||
KEY `idx_mission_type` (`mission_type`),
|
||||
KEY `idx_mission_status` (`mission_status`),
|
||||
KEY `idx_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='任务表';
|
||||
|
||||
-- =====================================================
|
||||
-- 表名: mission_images
|
||||
-- 描述: 任务图片表,存储机库执行任务后上传的图片
|
||||
-- =====================================================
|
||||
CREATE TABLE IF NOT EXISTS `mission_images` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`mission_code` VARCHAR(64) NOT NULL COMMENT '任务编码',
|
||||
`file_id` VARCHAR(64) DEFAULT NULL COMMENT '文件ID(file-center生成)',
|
||||
`file_path` VARCHAR(512) NOT NULL COMMENT '文件路径(不含bucket)',
|
||||
`file_name` VARCHAR(256) DEFAULT NULL COMMENT '文件名',
|
||||
`file_type` VARCHAR(64) DEFAULT NULL COMMENT '文件MIME类型',
|
||||
`file_size` BIGINT DEFAULT NULL COMMENT '文件大小(字节)',
|
||||
`file_tag` VARCHAR(32) DEFAULT NULL COMMENT '文件标签(如:raw_image, processed_image)',
|
||||
`tourism_id` BIGINT DEFAULT NULL COMMENT '景区ID',
|
||||
`device_sn` VARCHAR(64) DEFAULT NULL COMMENT '设备序列号',
|
||||
`capture_time` DATETIME DEFAULT NULL COMMENT '拍摄时间',
|
||||
`latitude` DECIMAL(10,7) DEFAULT NULL COMMENT '拍摄纬度',
|
||||
`longitude` DECIMAL(10,7) DEFAULT NULL COMMENT '拍摄经度',
|
||||
`altitude` DECIMAL(10,2) DEFAULT NULL COMMENT '拍摄高度(米)',
|
||||
`tenant_id` VARCHAR(32) DEFAULT 'webApp' COMMENT '租户ID',
|
||||
`is_del` TINYINT NOT NULL DEFAULT 0 COMMENT '删除标记(0:正常, 1:已删除)',
|
||||
`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_mission_code` (`mission_code`),
|
||||
KEY `idx_file_id` (`file_id`),
|
||||
KEY `idx_file_path` (`file_path`(255)),
|
||||
KEY `idx_tourism_id` (`tourism_id`),
|
||||
KEY `idx_device_sn` (`device_sn`),
|
||||
KEY `idx_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='任务图片表';
|
||||
+22
-3
@@ -2,11 +2,12 @@ package com.central.order.feign;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.fallback.DeviceCenterServiceFallbackFactory;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* device-center模块远程调用
|
||||
@@ -30,4 +31,22 @@ public interface DeviceCenterService {
|
||||
|
||||
@GetMapping("/live/stream-urls")
|
||||
JSONObject getStreamUrls(@RequestParam("deviceId") String deviceId) ;
|
||||
|
||||
@Operation(summary = "无人机一键起飞")
|
||||
@PostMapping("/device/command/takeoff")
|
||||
Result<String> takeoff(@RequestBody TakeoffRequestVO request);
|
||||
|
||||
/**
|
||||
* 执行航线任务
|
||||
*
|
||||
* @param deviceSn 设备SN
|
||||
* @param waylineId 航线ID
|
||||
* @param missionCode 任务编码
|
||||
* @return 执行结果
|
||||
*/
|
||||
@Operation(summary = "执行航线任务")
|
||||
@PostMapping("/device/command/wayline/execute")
|
||||
Result<String> executeWayline(@RequestParam("deviceSn") String deviceSn,
|
||||
@RequestParam("waylineId") String waylineId,
|
||||
@RequestParam("missionCode") String missionCode);
|
||||
}
|
||||
|
||||
+15
@@ -1,7 +1,9 @@
|
||||
package com.central.order.feign.fallback;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -31,6 +33,19 @@ public class DeviceCenterServiceFallbackFactory implements FallbackFactory<Devic
|
||||
public JSONObject getStreamUrls(String deviceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> takeoff(TakeoffRequestVO request) {
|
||||
log.error("调用设备中心takeoff失败: {}", cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> executeWayline(String deviceSn, String waylineId, String missionCode) {
|
||||
log.error("调用设备中心executeWayline失败: deviceSn={}, waylineId={}, missionCode={}, error={}",
|
||||
deviceSn, waylineId, missionCode, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.central.order.mission.VO;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TakeoffRequestVO {
|
||||
/** 设备SN */
|
||||
private String deviceSn;
|
||||
/** 目标点纬度 */
|
||||
private Double targetLatitude;
|
||||
/** 目标点经度 */
|
||||
private Double targetLongitude;
|
||||
/** 目标点高度(椭球高),使用 WGS84 模型 */
|
||||
private Float targetHeight;
|
||||
/** 安全起飞高度,相对起飞点的高度 */
|
||||
private Float securityTakeoffHeight;
|
||||
/** 返航模式:0=智能高度,1=设定高度 */
|
||||
private Integer rthMode;
|
||||
/** 返航高度,相对起飞点的高度 */
|
||||
private Integer rthAltitude;
|
||||
/** 遥控器失控动作:0=悬停,1=降落,2=返航 */
|
||||
private Integer rcLostAction;
|
||||
/** 指点飞行失控动作:0=继续执行,1=退出任务 */
|
||||
private Integer commanderModeLostAction;
|
||||
/** 指点飞行模式:0=智能高度飞行,1=设定高度飞行 */
|
||||
private Integer commanderFlightMode;
|
||||
/** 指点飞行高度,相对起飞点的高度 */
|
||||
private Float commanderFlightHeight;
|
||||
/** 一键起飞任务UUID */
|
||||
private String flightId;
|
||||
/** 最大飞行速度(m/s),范围1-15 */
|
||||
private Integer maxSpeed;
|
||||
/** 飞行安全预检查:0=关闭,1=开启 */
|
||||
private Integer flightSafetyAdvanceCheck;
|
||||
}
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
package com.central.order.mission.controller;
|
||||
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.mission.enums.MissionStatus;
|
||||
import com.central.order.mission.enums.MissionType;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.service.IMissionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务管理接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "任务管理")
|
||||
@RequestMapping("/mission")
|
||||
@RequiredArgsConstructor
|
||||
public class MissionController {
|
||||
|
||||
private final IMissionService missionService;
|
||||
|
||||
/**
|
||||
* 创建任务
|
||||
* 航线任务:创建后不自动执行,需要调用executeMission接口确认执行
|
||||
* 一键起飞任务:创建后自动执行
|
||||
*/
|
||||
@Operation(summary = "创建任务")
|
||||
@PostMapping("/saveMission")
|
||||
public Result<Mission> saveMission(@RequestBody Mission mission) {
|
||||
try {
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(mission.getDeviceSn())) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
|
||||
Integer missionType = mission.getMissionType();
|
||||
if (missionType == null) {
|
||||
missionType = MissionType.WAYLINE.getId(); // 默认为航线任务
|
||||
mission.setMissionType(missionType);
|
||||
}
|
||||
|
||||
// 根据任务类型校验必填参数
|
||||
if (MissionType.isWaylineTask(missionType)) {
|
||||
if (!StringUtils.hasText(mission.getWaylineId())) {
|
||||
return Result.failed("航线ID不能为空");
|
||||
}
|
||||
} else if (MissionType.isTakeoffTask(missionType)) {
|
||||
if (mission.getTargetLatitude() == null ||
|
||||
mission.getTargetLongitude() == null ||
|
||||
mission.getTargetHeight() == null) {
|
||||
return Result.failed("一键起飞任务必须指定目标坐标和高度");
|
||||
}
|
||||
} else {
|
||||
return Result.failed("无效的任务类型");
|
||||
}
|
||||
|
||||
// 设置创建人信息
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
if (user != null) {
|
||||
mission.setCreatorId(user.getId());
|
||||
mission.setCreatorName(user.getUsername());
|
||||
}
|
||||
|
||||
// 创建任务
|
||||
boolean created = missionService.createMission(mission);
|
||||
if (!created) {
|
||||
return Result.failed("任务创建失败");
|
||||
}
|
||||
|
||||
// 一键起飞任务:创建后自动执行
|
||||
if (MissionType.isTakeoffTask(missionType)) {
|
||||
boolean dispatched = missionService.dispatchMissionToDevice(mission);
|
||||
if (!dispatched) {
|
||||
log.warn("一键起飞任务创建成功但下发失败: {}", mission.getMissionCode());
|
||||
return Result.failed("任务创建成功但执行失败,请重试");
|
||||
}
|
||||
return Result.succeed(mission, "一键起飞任务已执行");
|
||||
}
|
||||
// 航线任务:只创建,不自动执行
|
||||
return Result.succeed(mission, "任务创建成功,请确认执行");
|
||||
} catch (Exception e) {
|
||||
log.error("创建任务异常", e);
|
||||
return Result.failed("创建任务异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务(下发到设备)
|
||||
* 用于航线任务创建后,用户确认执行
|
||||
*/
|
||||
@Operation(summary = "执行任务")
|
||||
@PostMapping("/executeMission")
|
||||
public Result<String> executeMission(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
Mission mission = missionService.getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
return Result.failed("任务不存在");
|
||||
}
|
||||
|
||||
// 只有待执行状态的任务可以执行
|
||||
if (!MissionStatus.PENDING.getId().equals(mission.getMissionStatus())) {
|
||||
return Result.failed("只有待执行状态的任务可以执行");
|
||||
}
|
||||
|
||||
// 下发任务到设备
|
||||
boolean dispatched = missionService.dispatchMissionToDevice(mission);
|
||||
if (dispatched) {
|
||||
return Result.succeed("任务已下发执行");
|
||||
} else {
|
||||
return Result.failed("任务执行失败,请检查设备状态");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("执行任务异常", e);
|
||||
return Result.failed("执行任务异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务列表
|
||||
*/
|
||||
@Operation(summary = "查询任务列表")
|
||||
@PostMapping("/listMission")
|
||||
public PageResult<Mission> listMission(@RequestBody Map<String, Object> params) {
|
||||
return missionService.findList(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务详情
|
||||
*/
|
||||
@Operation(summary = "获取任务详情")
|
||||
@PostMapping("/getMission")
|
||||
public Result<Mission> getMission(@RequestBody Map<String, Object> params) {
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
Mission mission = missionService.getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
return Result.failed("任务不存在");
|
||||
}
|
||||
|
||||
return Result.succeed(mission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
*/
|
||||
@Operation(summary = "更新任务状态")
|
||||
@PostMapping("/updateMissionStatus")
|
||||
public Result<String> updateMissionStatus(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
Integer status = (Integer) params.get("status");
|
||||
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
if (status == null) {
|
||||
return Result.failed("状态不能为空");
|
||||
}
|
||||
|
||||
// 校验状态值
|
||||
if (MissionStatus.fromId(status) == null) {
|
||||
return Result.failed("无效的状态值");
|
||||
}
|
||||
|
||||
boolean updated = missionService.updateMissionStatus(missionCode, status);
|
||||
if (updated) {
|
||||
return Result.succeed("状态更新成功");
|
||||
} else {
|
||||
return Result.failed("状态更新失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新任务状态异常", e);
|
||||
return Result.failed("更新任务状态异常: " + e.getMessage());
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消任务
|
||||
*/
|
||||
@Operation(summary = "取消任务")
|
||||
@PostMapping("/cancelMission")
|
||||
public Result<String> cancelMission(@RequestBody Map<String, Object> params) {
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
boolean canceled = missionService.cancelMission(missionCode);
|
||||
if (canceled) {
|
||||
return Result.succeed("任务取消成功");
|
||||
} else {
|
||||
return Result.failed("任务取消失败,请检查任务状态");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成任务
|
||||
*/
|
||||
@Operation(summary = "完成任务")
|
||||
@PostMapping("/completeMission")
|
||||
public Result<String> completeMission(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
boolean completed = missionService.completeMission(missionCode);
|
||||
if (completed) {
|
||||
return Result.succeed("任务完成");
|
||||
} else {
|
||||
return Result.failed("任务完成失败,请检查任务状态");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("完成任务异常", e);
|
||||
return Result.failed("完成任务异常: " + e.getMessage());
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务
|
||||
*/
|
||||
@Operation(summary = "删除任务")
|
||||
@PostMapping("/deleteMission")
|
||||
public Result<String> deleteMission(@RequestBody Map<String, Object> params) {
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
boolean deleted = missionService.deleteMission(missionCode);
|
||||
if (deleted) {
|
||||
return Result.succeed("任务删除成功");
|
||||
} else {
|
||||
return Result.failed("任务删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
package com.central.order.mission.controller;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.model.MissionImage;
|
||||
import com.central.order.mission.service.IMissionImageService;
|
||||
import com.central.order.mission.service.IMissionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务图片管理接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "任务图片管理")
|
||||
@RequestMapping("/mission/image")
|
||||
@RequiredArgsConstructor
|
||||
public class MissionImageController {
|
||||
|
||||
private final IMissionImageService missionImageService;
|
||||
private final IMissionService missionService;
|
||||
private final FileCenterService fileCenterService;
|
||||
|
||||
@Value("${file.style:}")
|
||||
private String fileStyle;
|
||||
|
||||
/**
|
||||
* 机库回传图片路径创建记录
|
||||
*/
|
||||
@Operation(summary = "机库回传图片路径创建记录")
|
||||
@PostMapping("/saveMissionImage")
|
||||
public Result<MissionImage> saveMissionImage(@RequestBody MissionImage missionImage) {
|
||||
try {
|
||||
// TenantContextHolder.setTenant("webApp");
|
||||
|
||||
// 参数校验
|
||||
if (!StringUtils.hasText(missionImage.getMissionCode())) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
if (!StringUtils.hasText(missionImage.getFilePath())) {
|
||||
return Result.failed("文件路径不能为空");
|
||||
}
|
||||
|
||||
// 校验任务是否存在
|
||||
Mission mission = missionService.getByMissionCode(missionImage.getMissionCode());
|
||||
if (mission == null) {
|
||||
return Result.failed("任务不存在");
|
||||
}
|
||||
|
||||
// 校验文件路径是否已存在(避免重复创建)
|
||||
MissionImage existingImage = missionImageService.getByFilePath(missionImage.getFilePath());
|
||||
if (existingImage != null) {
|
||||
log.info("图片记录已存在: missionCode={}, filePath={}",
|
||||
missionImage.getMissionCode(), missionImage.getFilePath());
|
||||
return Result.succeed(existingImage, "记录已存在,无需重复创建");
|
||||
}
|
||||
|
||||
// 设置任务相关信息
|
||||
missionImage.setTourismId(mission.getTourismId());
|
||||
missionImage.setDeviceSn(mission.getDeviceSn());
|
||||
|
||||
// 创建文件信息
|
||||
FileInfo fileInfo = fileCenterService.creatFileInfo(missionImage.getFilePath());
|
||||
if (fileInfo != null) {
|
||||
missionImage.setFileId(fileInfo.getId());
|
||||
missionImage.setFilePath(fileInfo.getPath());
|
||||
missionImage.setFileType(fileInfo.getContentType());
|
||||
}
|
||||
|
||||
// 保存记录
|
||||
boolean saved = missionImageService.createMissionImage(missionImage);
|
||||
if (saved) {
|
||||
log.info("图片记录创建成功: missionCode={}, fileId={}",
|
||||
missionImage.getMissionCode(), missionImage.getFileId());
|
||||
return Result.succeed(missionImage, "创建成功");
|
||||
} else {
|
||||
return Result.failed("图片记录保存失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("创建图片记录异常", e);
|
||||
return Result.failed("创建图片记录异常: " + e.getMessage());
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务图片列表
|
||||
*/
|
||||
@Operation(summary = "查询任务图片列表")
|
||||
@PostMapping("/listMissionImage")
|
||||
public Result<List<MissionImage>> listMissionImage(@RequestBody Map<String, Object> params) {
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
List<MissionImage> images = missionImageService.getByMissionCode(missionCode);
|
||||
|
||||
// 设置图片访问URL
|
||||
for (MissionImage image : images) {
|
||||
if (StringUtils.hasText(image.getFileId())) {
|
||||
String viewUrl = fileCenterService.getFileViewUrl(image.getFileId());
|
||||
image.setViewUrl(viewUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return Result.succeed(images);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询任务图片列表
|
||||
*/
|
||||
@Operation(summary = "分页查询任务图片列表")
|
||||
@PostMapping("/pageMissionImage")
|
||||
public PageResult<MissionImage> pageMissionImage(@RequestBody Map<String, Object> params) {
|
||||
PageResult<MissionImage> result = missionImageService.findList(params);
|
||||
|
||||
// 设置图片访问URL
|
||||
for (MissionImage image : result.getData()) {
|
||||
if (StringUtils.hasText(image.getFileId())) {
|
||||
String viewUrl = fileCenterService.getFileViewUrl(image.getFileId());
|
||||
image.setViewUrl(viewUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片详情
|
||||
*/
|
||||
@Operation(summary = "获取图片详情")
|
||||
@PostMapping("/getMissionImage")
|
||||
public Result<MissionImage> getMissionImage(@RequestBody Map<String, Object> params) {
|
||||
Long id = null;
|
||||
Object idObj = params.get("id");
|
||||
if (idObj instanceof Number) {
|
||||
id = ((Number) idObj).longValue();
|
||||
} else if (idObj instanceof String) {
|
||||
id = Long.parseLong((String) idObj);
|
||||
}
|
||||
|
||||
if (id == null) {
|
||||
return Result.failed("图片ID不能为空");
|
||||
}
|
||||
|
||||
MissionImage image = missionImageService.getById(id);
|
||||
if (image == null) {
|
||||
return Result.failed("图片不存在");
|
||||
}
|
||||
|
||||
// 设置图片访问URL
|
||||
if (StringUtils.hasText(image.getFileId())) {
|
||||
String viewUrl = fileCenterService.getFileViewUrl(image.getFileId());
|
||||
image.setViewUrl(viewUrl);
|
||||
}
|
||||
|
||||
return Result.succeed(image);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片记录
|
||||
*/
|
||||
@Operation(summary = "删除图片记录")
|
||||
@PostMapping("/deleteMissionImage")
|
||||
public Result<String> deleteMissionImage(@RequestBody Map<String, Object> params) {
|
||||
Long id = null;
|
||||
Object idObj = params.get("id");
|
||||
if (idObj instanceof Number) {
|
||||
id = ((Number) idObj).longValue();
|
||||
} else if (idObj instanceof String) {
|
||||
id = Long.parseLong((String) idObj);
|
||||
}
|
||||
|
||||
if (id == null) {
|
||||
return Result.failed("图片ID不能为空");
|
||||
}
|
||||
|
||||
boolean deleted = missionImageService.deleteMissionImage(id);
|
||||
if (deleted) {
|
||||
return Result.succeed("删除成功");
|
||||
} else {
|
||||
return Result.failed("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计任务图片数量
|
||||
*/
|
||||
@Operation(summary = "统计任务图片数量")
|
||||
@PostMapping("/countMissionImage")
|
||||
public Result<Long> countMissionImage(@RequestBody Map<String, Object> params) {
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
Long count = missionImageService.countByMissionCode(missionCode);
|
||||
return Result.succeed(count);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.central.order.mission.enums;
|
||||
|
||||
import com.central.common.enums.ZltEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务状态枚举
|
||||
* 状态值与 OrderStatus 保持一致,便于复用设备端逻辑
|
||||
* 去掉支付相关(0-UNPAID)和退款相关(7-10)状态
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Getter
|
||||
public enum MissionStatus implements ZltEnum {
|
||||
// 对应 OrderStatus.PAID(1)
|
||||
PENDING(1, "待执行"),
|
||||
// 对应 OrderStatus.CANCELED(2)
|
||||
CANCELED(2, "已取消"),
|
||||
// 对应 OrderStatus.COMPLETE(3)
|
||||
COMPLETE(3, "执行完成"),
|
||||
// 对应 OrderStatus.DOING(4)
|
||||
DOING(4, "执行中"),
|
||||
// 对应 OrderStatus.UPLOADING(5)
|
||||
UPLOADING(5, "图片上传中"),
|
||||
// 对应 OrderStatus.UPLOADED(6)
|
||||
UPLOADED(6, "图片上传完成");
|
||||
|
||||
MissionStatus(Integer id, String content) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
private final Integer id;
|
||||
private final String content;
|
||||
|
||||
public static MissionStatus fromId(Integer id) {
|
||||
if (id == null) return null;
|
||||
for (MissionStatus status : values()) {
|
||||
if (status.getId().equals(id)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDesc(Integer id) {
|
||||
MissionStatus status = fromId(id);
|
||||
return status != null ? status.getContent() : "未知状态";
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为最终状态
|
||||
*/
|
||||
public static boolean isFinalStatus(Integer status) {
|
||||
return status != null && (
|
||||
status.equals(COMPLETE.getId()) ||
|
||||
status.equals(CANCELED.getId()) ||
|
||||
status.equals(UPLOADED.getId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可取消(只有待执行状态可取消)
|
||||
*/
|
||||
public static boolean canCancel(Integer status) {
|
||||
return status != null && status.equals(PENDING.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效的查看状态(执行完成后可查看图片)
|
||||
*/
|
||||
public static boolean isValidForView(Integer status) {
|
||||
return status != null && (
|
||||
status.equals(COMPLETE.getId()) ||
|
||||
status.equals(UPLOADED.getId())
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.central.order.mission.enums;
|
||||
|
||||
import com.central.common.enums.ZltEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务类型枚举
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Getter
|
||||
public enum MissionType implements ZltEnum {
|
||||
WAYLINE(1, "航线任务"),
|
||||
TAKEOFF(2, "一键起飞任务");
|
||||
|
||||
MissionType(Integer id, String content) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
private final Integer id;
|
||||
private final String content;
|
||||
|
||||
public static MissionType fromId(Integer id) {
|
||||
if (id == null) return null;
|
||||
for (MissionType type : values()) {
|
||||
if (type.getId().equals(id)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDesc(Integer id) {
|
||||
MissionType type = fromId(id);
|
||||
return type != null ? type.getContent() : "未知类型";
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为航线任务
|
||||
*/
|
||||
public static boolean isWaylineTask(Integer type) {
|
||||
return type != null && type.equals(WAYLINE.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为一键起飞任务
|
||||
*/
|
||||
public static boolean isTakeoffTask(Integer type) {
|
||||
return type != null && type.equals(TAKEOFF.getId());
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.central.order.mission.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.order.mission.model.MissionImage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务图片Mapper接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface MissionImageMapper extends BaseMapper<MissionImage> {
|
||||
|
||||
/**
|
||||
* 分页查询任务图片列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param params 查询参数
|
||||
* @return 图片列表
|
||||
*/
|
||||
Page<MissionImage> findList(Page<MissionImage> page, @Param("p") Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据任务编码查询图片列表
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 图片列表
|
||||
*/
|
||||
List<MissionImage> getByMissionCode(@Param("missionCode") String missionCode);
|
||||
|
||||
/**
|
||||
* 根据文件路径查询图片
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 图片信息
|
||||
*/
|
||||
MissionImage getByFilePath(@Param("filePath") String filePath);
|
||||
|
||||
/**
|
||||
* 统计任务图片数量
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 图片数量
|
||||
*/
|
||||
Long countByMissionCode(@Param("missionCode") String missionCode);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.central.order.mission.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务Mapper接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface MissionMapper extends BaseMapper<Mission> {
|
||||
|
||||
/**
|
||||
* 分页查询任务列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param params 查询参数
|
||||
* @return 任务列表
|
||||
*/
|
||||
Page<Mission> findList(Page<Mission> page, @Param("p") Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据任务编码查询任务
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 任务信息
|
||||
*/
|
||||
Mission getByMissionCode(@Param("missionCode") String missionCode);
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
*
|
||||
* @param missionId 任务ID
|
||||
* @param newStatus 新状态
|
||||
* @return 影响行数
|
||||
*/
|
||||
int updateMissionStatus(@Param("missionId") Long missionId, @Param("newStatus") Integer newStatus);
|
||||
|
||||
/**
|
||||
* 获取当天最大任务序号
|
||||
*
|
||||
* @param datePrefix 日期前缀(如:J20251222)
|
||||
* @return 最大序号
|
||||
*/
|
||||
Integer getMaxSequenceByDate(@Param("datePrefix") String datePrefix);
|
||||
|
||||
/**
|
||||
* 统计任务图片数量
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 图片数量
|
||||
*/
|
||||
Integer countImagesByMissionCode(@Param("missionCode") String missionCode);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.central.order.mission.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 任务实体类
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("missions")
|
||||
@Schema(description = "任务实体")
|
||||
public class Mission extends SuperEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "任务编码(J前缀)")
|
||||
private String missionCode;
|
||||
|
||||
@Schema(description = "任务名称")
|
||||
private String missionName;
|
||||
|
||||
@Schema(description = "任务类型(1:航线任务, 2:一键起飞任务)")
|
||||
private Integer missionType;
|
||||
|
||||
@Schema(description = "设备序列号(机库SN)")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "航线ID(航线任务必填)")
|
||||
private String waylineId;
|
||||
|
||||
@Schema(description = "航线名称")
|
||||
private String waylineName;
|
||||
|
||||
@Schema(description = "工作区ID")
|
||||
private String workspaceId;
|
||||
|
||||
@Schema(description = "景区ID")
|
||||
private Long tourismId;
|
||||
|
||||
@Schema(description = "任务状态(1:待执行, 2:已取消, 3:执行完成, 4:执行中, 5:图片上传中, 6:图片上传完成)")
|
||||
private Integer missionStatus;
|
||||
|
||||
@Schema(description = "目标纬度(一键起飞任务)")
|
||||
private BigDecimal targetLatitude;
|
||||
|
||||
@Schema(description = "目标经度(一键起飞任务)")
|
||||
private BigDecimal targetLongitude;
|
||||
|
||||
@Schema(description = "目标高度(一键起飞任务,米)")
|
||||
private BigDecimal targetHeight;
|
||||
|
||||
@Schema(description = "任务开始时间")
|
||||
private Date startTime;
|
||||
|
||||
@Schema(description = "任务结束时间")
|
||||
private Date endTime;
|
||||
|
||||
@Schema(description = "创建人ID")
|
||||
private Long creatorId;
|
||||
|
||||
@Schema(description = "创建人姓名")
|
||||
private String creatorName;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "租户ID")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "删除标记(0:正常, 1:已删除)")
|
||||
private Integer isDel;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
// ========== 临时字段 ==========
|
||||
|
||||
@Schema(description = "景区名称(联表查询)")
|
||||
@TableField(exist = false)
|
||||
private transient String tourismName;
|
||||
|
||||
@Schema(description = "任务图片数量")
|
||||
@TableField(exist = false)
|
||||
private transient Integer imageCount;
|
||||
|
||||
@Schema(description = "任务类型描述")
|
||||
@TableField(exist = false)
|
||||
private transient String missionTypeDesc;
|
||||
|
||||
@Schema(description = "任务状态描述")
|
||||
@TableField(exist = false)
|
||||
private transient String missionStatusDesc;
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.central.order.mission.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 任务图片实体类
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mission_images")
|
||||
@Schema(description = "任务图片实体")
|
||||
public class MissionImage extends SuperEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "任务编码")
|
||||
private String missionCode;
|
||||
|
||||
@Schema(description = "文件ID(file-center生成)")
|
||||
private String fileId;
|
||||
|
||||
@Schema(description = "文件路径(不含bucket)")
|
||||
private String filePath;
|
||||
|
||||
@Schema(description = "文件名")
|
||||
private String fileName;
|
||||
|
||||
@Schema(description = "文件MIME类型")
|
||||
private String fileType;
|
||||
|
||||
@Schema(description = "文件大小(字节)")
|
||||
private Long fileSize;
|
||||
|
||||
@Schema(description = "文件标签(如:raw_image, processed_image)")
|
||||
private String fileTag;
|
||||
|
||||
@Schema(description = "景区ID")
|
||||
private Long tourismId;
|
||||
|
||||
@Schema(description = "设备序列号")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "拍摄时间")
|
||||
private Date captureTime;
|
||||
|
||||
@Schema(description = "拍摄纬度")
|
||||
private BigDecimal latitude;
|
||||
|
||||
@Schema(description = "拍摄经度")
|
||||
private BigDecimal longitude;
|
||||
|
||||
@Schema(description = "拍摄高度(米)")
|
||||
private BigDecimal altitude;
|
||||
|
||||
@Schema(description = "租户ID")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "删除标记(0:正常, 1:已删除)")
|
||||
private Integer isDel;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
// ========== 临时字段 ==========
|
||||
|
||||
@Schema(description = "图片访问URL")
|
||||
@TableField(exist = false)
|
||||
private transient String viewUrl;
|
||||
|
||||
@Schema(description = "缩略图URL")
|
||||
@TableField(exist = false)
|
||||
private transient String thumbnailUrl;
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.central.order.mission.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.mission.model.MissionImage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务图片服务接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
public interface IMissionImageService extends IService<MissionImage> {
|
||||
|
||||
/**
|
||||
* 分页查询任务图片列表
|
||||
*
|
||||
* @param params 查询参数
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<MissionImage> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据任务编码查询图片列表
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 图片列表
|
||||
*/
|
||||
List<MissionImage> getByMissionCode(String missionCode);
|
||||
|
||||
/**
|
||||
* 根据文件路径查询图片
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 图片信息
|
||||
*/
|
||||
MissionImage getByFilePath(String filePath);
|
||||
|
||||
/**
|
||||
* 创建图片记录
|
||||
*
|
||||
* @param missionImage 图片信息
|
||||
* @return 创建成功返回true
|
||||
*/
|
||||
boolean createMissionImage(MissionImage missionImage);
|
||||
|
||||
/**
|
||||
* 删除图片记录(逻辑删除)
|
||||
*
|
||||
* @param id 图片ID
|
||||
* @return 删除成功返回true
|
||||
*/
|
||||
boolean deleteMissionImage(Long id);
|
||||
|
||||
/**
|
||||
* 统计任务图片数量
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 图片数量
|
||||
*/
|
||||
Long countByMissionCode(String missionCode);
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.central.order.mission.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.mission.model.Mission;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务服务接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
public interface IMissionService extends IService<Mission> {
|
||||
|
||||
/**
|
||||
* 分页查询任务列表
|
||||
*
|
||||
* @param params 查询参数
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<Mission> findList(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据任务编码查询任务
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 任务信息
|
||||
*/
|
||||
Mission getByMissionCode(String missionCode);
|
||||
|
||||
/**
|
||||
* 创建任务
|
||||
*
|
||||
* @param mission 任务信息
|
||||
* @return 创建成功返回true
|
||||
*/
|
||||
boolean createMission(Mission mission);
|
||||
|
||||
/**
|
||||
* 更新任务
|
||||
*
|
||||
* @param mission 任务信息
|
||||
* @return 更新成功返回true
|
||||
*/
|
||||
boolean updateMission(Mission mission);
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @param newStatus 新状态
|
||||
* @return 更新成功返回true
|
||||
*/
|
||||
boolean updateMissionStatus(String missionCode, Integer newStatus);
|
||||
|
||||
/**
|
||||
* 取消任务
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 取消成功返回true
|
||||
*/
|
||||
boolean cancelMission(String missionCode);
|
||||
|
||||
/**
|
||||
* 完成任务
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 完成成功返回true
|
||||
*/
|
||||
boolean completeMission(String missionCode);
|
||||
|
||||
/**
|
||||
* 删除任务(逻辑删除)
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @return 删除成功返回true
|
||||
*/
|
||||
boolean deleteMission(String missionCode);
|
||||
|
||||
/**
|
||||
* 生成任务编码
|
||||
*
|
||||
* @param deviceSn 设备序列号
|
||||
* @return 任务编码(J + 设备SN后4位 + yyyyMMdd + 3位序号)
|
||||
*/
|
||||
String generateMissionCode(String deviceSn);
|
||||
|
||||
/**
|
||||
* 下发任务到设备
|
||||
*
|
||||
* @param mission 任务信息
|
||||
* @return 下发成功返回true
|
||||
*/
|
||||
boolean dispatchMissionToDevice(Mission mission);
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package com.central.order.mission.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.mission.enums.MissionStatus;
|
||||
import com.central.order.mission.mapper.MissionImageMapper;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.model.MissionImage;
|
||||
import com.central.order.mission.service.IMissionImageService;
|
||||
import com.central.order.mission.service.IMissionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务图片服务实现类
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MissionImageServiceImpl extends ServiceImpl<MissionImageMapper, MissionImage> implements IMissionImageService {
|
||||
|
||||
@Lazy
|
||||
private final IMissionService missionService;
|
||||
|
||||
@Override
|
||||
public PageResult<MissionImage> findList(Map<String, Object> params) {
|
||||
Page<MissionImage> page = new Page<>();
|
||||
if (params.containsKey("page")) {
|
||||
page.setCurrent(Long.parseLong(params.get("page").toString()));
|
||||
}
|
||||
if (params.containsKey("limit")) {
|
||||
page.setSize(Long.parseLong(params.get("limit").toString()));
|
||||
}
|
||||
|
||||
Page<MissionImage> result = baseMapper.findList(page, params);
|
||||
|
||||
return PageResult.<MissionImage>builder()
|
||||
.data(result.getRecords())
|
||||
.count(result.getTotal())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MissionImage> getByMissionCode(String missionCode) {
|
||||
return baseMapper.getByMissionCode(missionCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MissionImage getByFilePath(String filePath) {
|
||||
return baseMapper.getByFilePath(filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createMissionImage(MissionImage missionImage) {
|
||||
// 设置默认值
|
||||
missionImage.setIsDel(0);
|
||||
if (missionImage.getTenantId() == null || missionImage.getTenantId().isEmpty()) {
|
||||
missionImage.setTenantId("webApp");
|
||||
}
|
||||
|
||||
boolean saved = save(missionImage);
|
||||
|
||||
if (saved) {
|
||||
// 检查并更新任务状态
|
||||
updateMissionStatusOnImageUpload(missionImage.getMissionCode());
|
||||
}
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片上传时更新任务状态
|
||||
*/
|
||||
private void updateMissionStatusOnImageUpload(String missionCode) {
|
||||
Mission mission = missionService.getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
log.warn("任务不存在: {}", missionCode);
|
||||
return;
|
||||
}
|
||||
|
||||
Integer currentStatus = mission.getMissionStatus();
|
||||
// 如果任务状态为待执行或执行中,更新为图片上传中
|
||||
if (currentStatus.equals(MissionStatus.PENDING.getId()) ||
|
||||
currentStatus.equals(MissionStatus.DOING.getId())) {
|
||||
missionService.updateMissionStatus(missionCode, MissionStatus.UPLOADING.getId());
|
||||
log.info("任务状态已更新为图片上传中: missionCode={}", missionCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteMissionImage(Long id) {
|
||||
MissionImage missionImage = getById(id);
|
||||
if (missionImage == null) {
|
||||
log.warn("图片不存在: {}", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
missionImage.setIsDel(1);
|
||||
return updateById(missionImage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByMissionCode(String missionCode) {
|
||||
return baseMapper.countByMissionCode(missionCode);
|
||||
}
|
||||
}
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
package com.central.order.mission.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import com.central.order.mission.enums.MissionStatus;
|
||||
import com.central.order.mission.enums.MissionType;
|
||||
import com.central.order.mission.mapper.MissionMapper;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.service.IMissionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务服务实现类
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MissionServiceImpl extends ServiceImpl<MissionMapper, Mission> implements IMissionService {
|
||||
|
||||
@Resource
|
||||
DeviceCenterService deviceCenterService;
|
||||
|
||||
@Override
|
||||
public PageResult<Mission> findList(Map<String, Object> params) {
|
||||
Page<Mission> page = new Page<>();
|
||||
if (params.containsKey("page")) {
|
||||
page.setCurrent(Long.parseLong(params.get("page").toString()));
|
||||
}
|
||||
if (params.containsKey("limit")) {
|
||||
page.setSize(Long.parseLong(params.get("limit").toString()));
|
||||
}
|
||||
|
||||
Page<Mission> result = baseMapper.findList(page, params);
|
||||
|
||||
// 设置类型和状态描述
|
||||
result.getRecords().forEach(mission -> {
|
||||
mission.setMissionTypeDesc(MissionType.getDesc(mission.getMissionType()));
|
||||
mission.setMissionStatusDesc(MissionStatus.getDesc(mission.getMissionStatus()));
|
||||
});
|
||||
|
||||
return PageResult.<Mission>builder()
|
||||
.data(result.getRecords())
|
||||
.count(result.getTotal())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mission getByMissionCode(String missionCode) {
|
||||
Mission mission = baseMapper.getByMissionCode(missionCode);
|
||||
if (mission != null) {
|
||||
mission.setMissionTypeDesc(MissionType.getDesc(mission.getMissionType()));
|
||||
mission.setMissionStatusDesc(MissionStatus.getDesc(mission.getMissionStatus()));
|
||||
}
|
||||
return mission;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createMission(Mission mission) {
|
||||
// 生成任务编码(包含设备SN)
|
||||
if (mission.getMissionCode() == null || mission.getMissionCode().isEmpty()) {
|
||||
mission.setMissionCode(generateMissionCode(mission.getDeviceSn()));
|
||||
}
|
||||
|
||||
// 如果没有任务名称,使用航线名称或默认名称
|
||||
if (mission.getMissionName() == null || mission.getMissionName().isEmpty()) {
|
||||
if (mission.getWaylineName() != null && !mission.getWaylineName().isEmpty()) {
|
||||
mission.setMissionName(mission.getWaylineName());
|
||||
} else {
|
||||
mission.setMissionName("任务-" + mission.getMissionCode());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置初始状态为待执行
|
||||
mission.setMissionStatus(MissionStatus.PENDING.getId());
|
||||
mission.setIsDel(0);
|
||||
|
||||
// 设置默认租户
|
||||
if (mission.getTenantId() == null || mission.getTenantId().isEmpty()) {
|
||||
mission.setTenantId("webApp");
|
||||
}
|
||||
|
||||
return save(mission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateMission(Mission mission) {
|
||||
return updateById(mission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateMissionStatus(String missionCode, Integer newStatus) {
|
||||
Mission mission = getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
log.warn("任务不存在: {}", missionCode);
|
||||
return false;
|
||||
}
|
||||
// 先更新内存中的状态,避免 updateById 覆盖
|
||||
mission.setMissionStatus(newStatus);
|
||||
// 如果是开始执行,记录开始时间
|
||||
if (newStatus.equals(MissionStatus.DOING.getId())) {
|
||||
mission.setStartTime(new Date());
|
||||
}
|
||||
// 如果是完成状态,记录结束时间
|
||||
if (newStatus.equals(MissionStatus.COMPLETE.getId()) ||
|
||||
newStatus.equals(MissionStatus.UPLOADED.getId())) {
|
||||
mission.setEndTime(new Date());
|
||||
}
|
||||
|
||||
// 统一更新一次
|
||||
return updateById(mission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean cancelMission(String missionCode) {
|
||||
Mission mission = getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
log.warn("任务不存在: {}", missionCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 只有待执行状态可以取消
|
||||
if (!MissionStatus.canCancel(mission.getMissionStatus())) {
|
||||
log.warn("任务状态不允许取消: {}, status={}", missionCode, mission.getMissionStatus());
|
||||
return false;
|
||||
}
|
||||
|
||||
return updateMissionStatus(missionCode, MissionStatus.CANCELED.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean completeMission(String missionCode) {
|
||||
Mission mission = getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
log.warn("任务不存在: {}", missionCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
Integer currentStatus = mission.getMissionStatus();
|
||||
// 只有执行中、上传中、上传完成状态可以完成
|
||||
if (!currentStatus.equals(MissionStatus.DOING.getId()) &&
|
||||
!currentStatus.equals(MissionStatus.UPLOADING.getId()) &&
|
||||
!currentStatus.equals(MissionStatus.UPLOADED.getId())) {
|
||||
log.warn("任务状态不允许完成: {}, status={}", missionCode, currentStatus);
|
||||
return false;
|
||||
}
|
||||
|
||||
mission.setMissionStatus(MissionStatus.COMPLETE.getId());
|
||||
mission.setEndTime(new Date());
|
||||
return updateById(mission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteMission(String missionCode) {
|
||||
Mission mission = getByMissionCode(missionCode);
|
||||
if (mission == null) {
|
||||
log.warn("任务不存在: {}", missionCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
mission.setIsDel(1);
|
||||
return updateById(mission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String generateMissionCode(String deviceSn) {
|
||||
// 格式: J + 设备SN后4位 + yyyyMMdd + 3位序号
|
||||
// 例如: J1234202512220001
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
String dateStr = sdf.format(new Date());
|
||||
|
||||
// 获取设备SN后4位
|
||||
String snSuffix = "0000";
|
||||
if (deviceSn != null && deviceSn.length() >= 4) {
|
||||
snSuffix = deviceSn.substring(deviceSn.length() - 4);
|
||||
} else if (deviceSn != null) {
|
||||
snSuffix = String.format("%4s", deviceSn).replace(' ', '0');
|
||||
}
|
||||
|
||||
String prefix = "J" + snSuffix + dateStr;
|
||||
|
||||
// 获取当天该设备最大序号
|
||||
Integer maxSeq = baseMapper.getMaxSequenceByDate(prefix);
|
||||
int nextSeq = (maxSeq == null ? 0 : maxSeq) + 1;
|
||||
|
||||
// 格式化为4位数字
|
||||
return String.format("%s%04d", prefix, nextSeq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchMissionToDevice(Mission mission) {
|
||||
try {
|
||||
Integer missionType = mission.getMissionType();
|
||||
|
||||
if (MissionType.isWaylineTask(missionType)) {
|
||||
// 航线任务:调用航线执行接口
|
||||
log.info("下发航线任务到设备: missionCode={}, deviceSn={}, waylineId={}",
|
||||
mission.getMissionCode(), mission.getDeviceSn(), mission.getWaylineId());
|
||||
// 调用设备中心的航线执行接口
|
||||
Result<String> result = deviceCenterService.executeWayline(
|
||||
mission.getDeviceSn(),
|
||||
mission.getWaylineId(),
|
||||
mission.getMissionCode()
|
||||
);
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
// 更新任务状态为执行中
|
||||
updateMissionStatus(mission.getMissionCode(), MissionStatus.DOING.getId());
|
||||
log.info("航线任务下发成功: missionCode={}", mission.getMissionCode());
|
||||
return true;
|
||||
} else {
|
||||
String errorMsg = result != null ? result.getResp_msg() : "设备中心服务调用失败";
|
||||
log.error("航线任务下发失败: missionCode={}, error={}", mission.getMissionCode(), errorMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
} else if (MissionType.isTakeoffTask(missionType)) {
|
||||
// 一键起飞任务:调用起飞接口
|
||||
log.info("下发一键起飞任务到设备: missionCode={}, deviceSn={}, target=({}, {}, {})",
|
||||
mission.getMissionCode(), mission.getDeviceSn(),
|
||||
mission.getTargetLatitude(), mission.getTargetLongitude(), mission.getTargetHeight());
|
||||
// 调用设备中心的起飞接口
|
||||
TakeoffRequestVO takeoffRequestVO = new TakeoffRequestVO();
|
||||
takeoffRequestVO.setTargetHeight(mission.getTargetHeight().floatValue());
|
||||
takeoffRequestVO.setDeviceSn(mission.getDeviceSn());
|
||||
takeoffRequestVO.setFlightId(mission.getMissionCode());
|
||||
takeoffRequestVO.setTargetLatitude(mission.getTargetLatitude().doubleValue());
|
||||
takeoffRequestVO.setTargetLongitude(mission.getTargetLongitude().doubleValue());
|
||||
Result<String> result = deviceCenterService.takeoff(takeoffRequestVO);
|
||||
if(result!=null && result.getResp_code()==0){
|
||||
// 更新任务状态为执行中
|
||||
updateMissionStatus(mission.getMissionCode(), MissionStatus.DOING.getId());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
log.error("未知的任务类型: {}", missionType);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("下发任务到设备失败: missionCode={}", mission.getMissionCode(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
-8
@@ -12,20 +12,17 @@ import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.event.OrderStatusChangeEvent;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.mapper.OrderFileMapper;
|
||||
import com.central.order.mapper.OrderMapper;
|
||||
import com.central.order.mapper.TourismFileMapper;
|
||||
import com.central.order.mapper.TourismMapper;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.OrderFile;
|
||||
import com.central.order.model.OrderRanking;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.mapper.*;
|
||||
import com.central.order.model.*;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.util.DateUtils;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.feign.WechatConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -79,6 +76,13 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
|
||||
@Autowired
|
||||
private QrCodeMapper qrCodeMapper;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private WechatConfigService wechatConfigService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
@@ -118,6 +122,13 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
if(Objects.nonNull(user)){
|
||||
order.setMobile(user.getMobile());
|
||||
}
|
||||
QrCode qrCode = qrCodeMapper.getByCodeId(order.getCodeId());
|
||||
if(qrCode!=null){
|
||||
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",qrCode.getTenantId());
|
||||
if(wechatConfig!=null){
|
||||
order.setCompany(wechatConfig.getSubMchName());
|
||||
}
|
||||
}
|
||||
order.setTourismName(tourismMapper.selectById(order.getTourismId()).getTourismName());
|
||||
}
|
||||
return PageResult.<Order>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?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.order.mission.mapper.MissionImageMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.mission.model.MissionImage">
|
||||
<id column="id" property="id"/>
|
||||
<result column="mission_code" property="missionCode"/>
|
||||
<result column="file_id" property="fileId"/>
|
||||
<result column="file_path" property="filePath"/>
|
||||
<result column="file_name" property="fileName"/>
|
||||
<result column="file_type" property="fileType"/>
|
||||
<result column="file_size" property="fileSize"/>
|
||||
<result column="file_tag" property="fileTag"/>
|
||||
<result column="tourism_id" property="tourismId"/>
|
||||
<result column="device_sn" property="deviceSn"/>
|
||||
<result column="capture_time" property="captureTime"/>
|
||||
<result column="latitude" property="latitude"/>
|
||||
<result column="longitude" property="longitude"/>
|
||||
<result column="altitude" property="altitude"/>
|
||||
<result column="tenant_id" property="tenantId"/>
|
||||
<result column="is_del" property="isDel"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, mission_code, file_id, file_path, file_name, file_type, file_size,
|
||||
file_tag, tourism_id, device_sn, capture_time, latitude, longitude, altitude,
|
||||
tenant_id, is_del, create_time, update_time
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询任务图片列表 -->
|
||||
<select id="findList" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM mission_images
|
||||
<where>
|
||||
is_del = 0
|
||||
<if test="p.missionCode != null and p.missionCode != ''">
|
||||
AND mission_code = #{p.missionCode}
|
||||
</if>
|
||||
<if test="p.tourismId != null">
|
||||
AND tourism_id = #{p.tourismId}
|
||||
</if>
|
||||
<if test="p.deviceSn != null and p.deviceSn != ''">
|
||||
AND device_sn = #{p.deviceSn}
|
||||
</if>
|
||||
<if test="p.fileType != null and p.fileType != ''">
|
||||
AND file_type LIKE CONCAT('%', #{p.fileType}, '%')
|
||||
</if>
|
||||
<if test="p.fileTag != null and p.fileTag != ''">
|
||||
AND file_tag = #{p.fileTag}
|
||||
</if>
|
||||
<if test="p.tenantId != null and p.tenantId != ''">
|
||||
AND tenant_id = #{p.tenantId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据任务编码查询图片列表 -->
|
||||
<select id="getByMissionCode" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM mission_images
|
||||
WHERE mission_code = #{missionCode}
|
||||
AND is_del = 0
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据文件路径查询图片 -->
|
||||
<select id="getByFilePath" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM mission_images
|
||||
WHERE file_path = #{filePath}
|
||||
AND is_del = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 统计任务图片数量 -->
|
||||
<select id="countByMissionCode" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM mission_images
|
||||
WHERE mission_code = #{missionCode}
|
||||
AND is_del = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,121 @@
|
||||
<?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.order.mission.mapper.MissionMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.central.order.mission.model.Mission">
|
||||
<id column="id" property="id"/>
|
||||
<result column="mission_code" property="missionCode"/>
|
||||
<result column="mission_name" property="missionName"/>
|
||||
<result column="mission_type" property="missionType"/>
|
||||
<result column="device_sn" property="deviceSn"/>
|
||||
<result column="wayline_id" property="waylineId"/>
|
||||
<result column="wayline_name" property="waylineName"/>
|
||||
<result column="workspace_id" property="workspaceId"/>
|
||||
<result column="tourism_id" property="tourismId"/>
|
||||
<result column="mission_status" property="missionStatus"/>
|
||||
<result column="target_latitude" property="targetLatitude"/>
|
||||
<result column="target_longitude" property="targetLongitude"/>
|
||||
<result column="target_height" property="targetHeight"/>
|
||||
<result column="start_time" property="startTime"/>
|
||||
<result column="end_time" property="endTime"/>
|
||||
<result column="creator_id" property="creatorId"/>
|
||||
<result column="creator_name" property="creatorName"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<result column="tenant_id" property="tenantId"/>
|
||||
<result column="is_del" property="isDel"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<!-- 临时字段 -->
|
||||
<result column="tourism_name" property="tourismName"/>
|
||||
<result column="image_count" property="imageCount"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础列 -->
|
||||
<sql id="Base_Column_List">
|
||||
m.id, m.mission_code, m.mission_name, m.mission_type, m.device_sn,
|
||||
m.wayline_id, m.wayline_name, m.workspace_id, m.tourism_id, m.mission_status,
|
||||
m.target_latitude, m.target_longitude, m.target_height,
|
||||
m.start_time, m.end_time, m.creator_id, m.creator_name, m.remark,
|
||||
m.tenant_id, m.is_del, m.create_time, m.update_time
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询任务列表 -->
|
||||
<select id="findList" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>,
|
||||
t.tourism_name,
|
||||
(SELECT COUNT(*) FROM mission_images mi WHERE mi.mission_code = m.mission_code AND mi.is_del = 0) AS image_count
|
||||
FROM missions m
|
||||
LEFT JOIN tourisms t ON m.tourism_id = t.id
|
||||
<where>
|
||||
m.is_del = 0
|
||||
<if test="p.missionCode != null and p.missionCode != ''">
|
||||
AND m.mission_code LIKE CONCAT('%', #{p.missionCode}, '%')
|
||||
</if>
|
||||
<if test="p.missionName != null and p.missionName != ''">
|
||||
AND m.mission_name LIKE CONCAT('%', #{p.missionName}, '%')
|
||||
</if>
|
||||
<if test="p.missionType != null">
|
||||
AND m.mission_type = #{p.missionType}
|
||||
</if>
|
||||
<if test="p.deviceSn != null and p.deviceSn != ''">
|
||||
AND m.device_sn = #{p.deviceSn}
|
||||
</if>
|
||||
<if test="p.tourismId != null">
|
||||
AND m.tourism_id = #{p.tourismId}
|
||||
</if>
|
||||
<if test="p.missionStatus != null">
|
||||
AND m.mission_status = #{p.missionStatus}
|
||||
</if>
|
||||
<if test="p.tenantId != null and p.tenantId != ''">
|
||||
AND m.tenant_id = #{p.tenantId}
|
||||
</if>
|
||||
<if test="p.startDate != null and p.startDate != ''">
|
||||
AND m.create_time >= #{p.startDate}
|
||||
</if>
|
||||
<if test="p.endDate != null and p.endDate != ''">
|
||||
AND m.create_time <= #{p.endDate}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY m.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据任务编码查询任务 -->
|
||||
<select id="getByMissionCode" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>,
|
||||
t.tourism_name,
|
||||
(SELECT COUNT(*) FROM mission_images mi WHERE mi.mission_code = m.mission_code AND mi.is_del = 0) AS image_count
|
||||
FROM missions m
|
||||
LEFT JOIN tourisms t ON m.tourism_id = t.id
|
||||
WHERE m.mission_code = #{missionCode}
|
||||
AND m.is_del = 0
|
||||
</select>
|
||||
|
||||
<!-- 更新任务状态 -->
|
||||
<update id="updateMissionStatus">
|
||||
UPDATE missions
|
||||
SET mission_status = #{newStatus},
|
||||
update_time = NOW()
|
||||
WHERE id = #{missionId}
|
||||
</update>
|
||||
|
||||
<!-- 获取当天该设备最大任务序号 -->
|
||||
<!-- 任务编码格式: J + 设备SN后4位 + yyyyMMdd + 4位序号 (共17位) -->
|
||||
<!-- 例如: J1234202512220001, 序号从第14位开始 -->
|
||||
<select id="getMaxSequenceByDate" resultType="java.lang.Integer">
|
||||
SELECT MAX(CAST(SUBSTRING(mission_code, 14) AS UNSIGNED))
|
||||
FROM missions
|
||||
WHERE mission_code LIKE CONCAT(#{datePrefix}, '%')
|
||||
</select>
|
||||
|
||||
<!-- 统计任务图片数量 -->
|
||||
<select id="countImagesByMissionCode" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM mission_images
|
||||
WHERE mission_code = #{missionCode}
|
||||
AND is_del = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -3,7 +3,7 @@
|
||||
* - 统一网关转发:仅代理 /api- 前缀到网关(/api-user、/api-uaa 等)
|
||||
* - 生产环境由网关/容器转发,此文件不生效
|
||||
*/
|
||||
const GATEWAY = process.env.GATEWAY_ORIGIN || 'http://192.168.2.214:9900';
|
||||
const GATEWAY = process.env.GATEWAY_ORIGIN || 'http://localhost:9900';
|
||||
// SRS流媒体服务器地址
|
||||
const SRS_SERVER = process.env.SRS_SERVER || 'http://220.205.16.27:8024';
|
||||
|
||||
|
||||
Binary file not shown.
@@ -15,8 +15,8 @@
|
||||
"prebuild:test:mgnt": "npm run copy:cesium",
|
||||
"prebuild:pre:mgnt": "npm run copy:cesium",
|
||||
"prebuild:prod:mgnt": "npm run copy:cesium",
|
||||
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://192.168.2.124:9900 umi dev",
|
||||
"start:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://192.168.2.124:9900 umi dev",
|
||||
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://localhost:9900 umi dev",
|
||||
"start:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://localhost:9900 umi dev",
|
||||
"start:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test GATEWAY_ORIGIN=https://test.goflytec.com umi dev",
|
||||
"start:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre GATEWAY_ORIGIN=http://119.45.169.13:9900 umi dev",
|
||||
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider umi build",
|
||||
|
||||
+11
-18
@@ -19,7 +19,7 @@ import {
|
||||
import { message, Modal, Tooltip, Spin } from 'antd';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { deviceControlWs } from '@/services/deviceControlWs';
|
||||
import { useDroneSSE } from '../hooks/useDroneSSE';
|
||||
import { DroneData } from '../hooks/useDroneSSE';
|
||||
import WhepPlayer from './WhepPlayer';
|
||||
import styles from './LeftControlPanel.less';
|
||||
|
||||
@@ -29,6 +29,7 @@ interface LeftControlPanelProps {
|
||||
device: any;
|
||||
realtimeData: any;
|
||||
videoStreamUrl?: string;
|
||||
droneData?: DroneData | null; // 从父组件接收无人机数据(SSE已在CesiumContainer中订阅)
|
||||
}
|
||||
|
||||
const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
@@ -37,13 +38,12 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
device,
|
||||
realtimeData,
|
||||
videoStreamUrl,
|
||||
droneData, // 从父组件接收,无需自己订阅SSE
|
||||
}) => {
|
||||
const dockData = realtimeData?.rawData?.dockData;
|
||||
const rawDroneData = realtimeData?.rawData?.droneData;
|
||||
const deviceSn = device?.deviceSn;
|
||||
|
||||
const { droneData, connectDroneSSE, disconnectDroneSSE, resetDroneData } = useDroneSSE();
|
||||
|
||||
const flightData = useMemo(() => {
|
||||
const data = droneData || rawDroneData;
|
||||
let gimbal: any = {};
|
||||
@@ -126,8 +126,8 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
const [position, setPosition] = useState({ x: 0, y: 0 });
|
||||
const draggingRef = useRef(false);
|
||||
const lastPosRef = useRef({ x: 0, y: 0 });
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const panelRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && deviceSn) {
|
||||
@@ -137,12 +137,10 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
if(!c) { setDrcMode(false); drcModeRef.current = false; }
|
||||
});
|
||||
deviceControlWs.connect(deviceSn);
|
||||
connectDroneSSE(deviceSn);
|
||||
// 注意:无人机SSE已在CesiumContainer中统一订阅,这里不再重复订阅
|
||||
return () => {
|
||||
sub();
|
||||
deviceControlWs.disconnect();
|
||||
disconnectDroneSSE(deviceSn);
|
||||
resetDroneData();
|
||||
};
|
||||
} else {
|
||||
setPosition({ x: 0, y: 0 });
|
||||
@@ -525,20 +523,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
||||
}
|
||||
}, [handleMouseMove]);
|
||||
|
||||
// 关闭面板时,主动断开所有连接
|
||||
// 关闭面板时,断开设备控制连接
|
||||
const handleClose = () => {
|
||||
// 1. 断开设备控制服务
|
||||
// 1. 断开设备控制WebSocket服务
|
||||
deviceControlWs.disconnect();
|
||||
// 2. 断开无人机SSE连接(会调用后端接口取消订阅)
|
||||
if (deviceSn) {
|
||||
disconnectDroneSSE(deviceSn);
|
||||
}
|
||||
// 3. 重置无人机数据
|
||||
resetDroneData();
|
||||
// 4. 退出DRC模式
|
||||
// 2. 退出DRC模式
|
||||
setDrcMode(false);
|
||||
drcModeRef.current = false;
|
||||
// 5. 调用父组件的关闭回调
|
||||
// 3. 调用父组件的关闭回调
|
||||
// 注意:无人机SSE由CesiumContainer统一管理,这里不处理
|
||||
onClose();
|
||||
};
|
||||
|
||||
|
||||
+23
-15
@@ -15,6 +15,7 @@ import {
|
||||
} from '@ant-design/icons';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { saveMission, MissionType } from '@/services/mission';
|
||||
import useDeviceSSE from '../hooks/useDeviceSSE';
|
||||
import styles from './RightPanel.less';
|
||||
|
||||
@@ -25,7 +26,7 @@ interface RightPanelProps {
|
||||
tourism: any;
|
||||
onClose: () => void;
|
||||
onControlClick: (device: any, realtimeData: any) => void;
|
||||
onTaskPanelOpen?: (device: any) => void; // 打开任务管理面板回调
|
||||
onTaskPanelOpen?: (device: any, dockData: any, tourismId?: number) => void; // 打开任务管理面板回调
|
||||
viewer?: any; // Cesium Viewer 实例
|
||||
Cesium?: any; // Cesium 库
|
||||
}
|
||||
@@ -62,7 +63,9 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
.map((res: any) => (res.data && res.data.length > 0 ? res.data[0] : null))
|
||||
.filter((device: any) => device !== null);
|
||||
setDeviceList(devices);
|
||||
if (devices.length > 0) setSelectedDeviceSn(devices[0].deviceSn || '');
|
||||
if (devices.length > 0) {
|
||||
setSelectedDeviceSn(devices[0].deviceSn || '');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('获取设备列表失败');
|
||||
@@ -86,7 +89,9 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
}, [visible]);
|
||||
|
||||
const handleDeviceSelect = (deviceSn: string) => {
|
||||
if (deviceSn !== selectedDeviceSn) setSelectedDeviceSn(deviceSn);
|
||||
if (deviceSn !== selectedDeviceSn) {
|
||||
setSelectedDeviceSn(deviceSn);
|
||||
}
|
||||
};
|
||||
|
||||
// 关闭面板时,主动断开SSE连接
|
||||
@@ -105,7 +110,7 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
|
||||
const formatValue = (val: any, unit: string = '') => (val !== undefined && val !== null ? `${val}${unit}` : '-');
|
||||
|
||||
// 一键起飞
|
||||
// 一键起飞 - 创建一键起飞任务(后端会自动执行)
|
||||
const handleTakeoff = () => {
|
||||
const dockData = realtimeData?.rawData?.dockData;
|
||||
|
||||
@@ -131,6 +136,8 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const targetHeight = dockHeight + 30;
|
||||
|
||||
// 弹窗确认
|
||||
Modal.confirm({
|
||||
title: '确认一键起飞',
|
||||
@@ -139,7 +146,7 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
<p>无人机将自动开机并起飞到指定位置</p>
|
||||
<p style={{ fontSize: 12, color: '#666' }}>
|
||||
目标坐标: {dockLatitude.toFixed(6)}, {dockLongitude.toFixed(6)}<br />
|
||||
目标高度: {(dockHeight + 30).toFixed(1)}m (机库高度+30m)
|
||||
目标高度: {targetHeight.toFixed(1)}m (机库高度+30m)
|
||||
</p>
|
||||
</div>
|
||||
),
|
||||
@@ -148,14 +155,15 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
onOk: async () => {
|
||||
setTakeoffLoading(true);
|
||||
try {
|
||||
const res = await deviceApi.takeoff({
|
||||
// 创建一键起飞任务(后端会自动执行起飞命令)
|
||||
const res = await saveMission({
|
||||
deviceSn: selectedDeviceSn,
|
||||
missionType: MissionType.TAKEOFF,
|
||||
missionName: '一键起飞任务',
|
||||
tourismId: tourism?.id,
|
||||
targetLatitude: dockLatitude,
|
||||
targetLongitude: dockLongitude,
|
||||
targetHeight: dockHeight + 30,
|
||||
securityTakeoffHeight: 50,
|
||||
rthAltitude: 50,
|
||||
maxSpeed: 5,
|
||||
targetHeight: targetHeight,
|
||||
});
|
||||
|
||||
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||
@@ -163,14 +171,14 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||
|
||||
if (code === 0) {
|
||||
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
||||
message.success('一键起飞任务已创建,无人机将自动开机并起飞');
|
||||
} else {
|
||||
message.error(msg || '起飞命令发送失败');
|
||||
message.error(msg || '一键起飞任务创建失败');
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('起飞命令发送失败:', error);
|
||||
console.error('一键起飞任务创建失败:', error);
|
||||
// 更详细的错误信息
|
||||
let errorMsg = '起飞命令发送失败';
|
||||
let errorMsg = '一键起飞任务创建失败';
|
||||
if (error.response) {
|
||||
const data = error.response.data;
|
||||
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||
@@ -304,7 +312,7 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
||||
<button className={styles.primary} onClick={() => onControlClick(selectedDevice, realtimeData)}>
|
||||
<VideoCameraOutlined /> 进入操控台
|
||||
</button>
|
||||
<button className={styles.task} onClick={() => onTaskPanelOpen?.(selectedDevice)}>
|
||||
<button className={styles.task} onClick={() => onTaskPanelOpen?.(selectedDevice, dockData, tourism?.id)}>
|
||||
<UnorderedListOutlined /> 任务管理
|
||||
</button>
|
||||
</div>
|
||||
|
||||
+55
@@ -214,6 +214,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
.dockStatus {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 10px;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 6px;
|
||||
|
||||
.modeCode {
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
font-family: 'Consolas', monospace;
|
||||
}
|
||||
}
|
||||
|
||||
.createBtn {
|
||||
background: linear-gradient(135deg, rgba(0, 240, 255, 0.2), rgba(0, 100, 255, 0.2)) !important;
|
||||
border: 1px solid rgba(0, 240, 255, 0.4) !important;
|
||||
@@ -276,6 +291,18 @@
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.taskHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 3px;
|
||||
|
||||
.taskCode {
|
||||
font-size: 11px;
|
||||
color: @cyan;
|
||||
font-family: 'Consolas', monospace;
|
||||
}
|
||||
}
|
||||
|
||||
.taskName {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
@@ -288,10 +315,16 @@
|
||||
|
||||
.taskMeta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
|
||||
.taskTime {
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 1px 5px;
|
||||
border-radius: 3px;
|
||||
@@ -340,6 +373,28 @@
|
||||
border-color: rgba(0, 240, 255, 0.3);
|
||||
color: @cyan;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.danger:hover {
|
||||
background: rgba(255, 77, 79, 0.1);
|
||||
border-color: rgba(255, 77, 79, 0.3);
|
||||
color: @neon-red;
|
||||
}
|
||||
|
||||
&.execute {
|
||||
background: rgba(0, 255, 136, 0.1);
|
||||
border-color: rgba(0, 255, 136, 0.3);
|
||||
color: @neon-green;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background: rgba(0, 255, 136, 0.2);
|
||||
border-color: @neon-green;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+383
-235
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
||||
import { Button, message, Tooltip, Empty, Image, Select, Tabs } from 'antd';
|
||||
import { Button, message, Tooltip, Empty, Image, Select, Tabs, Tag, Modal, Spin } from 'antd';
|
||||
import {
|
||||
CloseOutlined,
|
||||
PlusOutlined,
|
||||
@@ -11,9 +11,33 @@ import {
|
||||
SendOutlined,
|
||||
UnorderedListOutlined,
|
||||
AimOutlined,
|
||||
CheckCircleOutlined,
|
||||
CloseCircleOutlined,
|
||||
SyncOutlined,
|
||||
ClockCircleOutlined,
|
||||
UploadOutlined,
|
||||
DeleteOutlined,
|
||||
PlayCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { useDroneSSE } from '../hooks/useDroneSSE';
|
||||
import { DroneData } from '../hooks/useDroneSSE';
|
||||
import { waylineRouteApi, WaylineRouteListItemVO, WaypointVO } from '@/services/waylineRoute';
|
||||
import {
|
||||
Mission,
|
||||
MissionImage,
|
||||
MissionStatus,
|
||||
MissionType,
|
||||
MissionStatusMap,
|
||||
MissionTypeMap,
|
||||
MissionStatusColorMap,
|
||||
saveMission,
|
||||
executeMission,
|
||||
listMission,
|
||||
getMission,
|
||||
completeMission,
|
||||
cancelMission,
|
||||
deleteMission,
|
||||
listMissionImage,
|
||||
} from '@/services/mission';
|
||||
import styles from './TaskPanel.less';
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
@@ -24,20 +48,49 @@ interface TaskPanelProps {
|
||||
device: any;
|
||||
viewer?: any;
|
||||
Cesium?: any;
|
||||
droneData?: DroneData | null; // 从父组件接收无人机数据(SSE已在CesiumContainer中订阅)
|
||||
dockData?: any; // 机库数据,用于检查 mode_code
|
||||
tourismId?: number; // 景区ID
|
||||
}
|
||||
|
||||
// 任务数据结构(后端未实现,先定义好接口)
|
||||
interface TaskItem {
|
||||
taskId: string;
|
||||
taskName: string;
|
||||
routeId: string;
|
||||
routeName: string;
|
||||
deviceSn: string;
|
||||
status: number; // 0-待执行 1-执行中 2-已完成 3-失败
|
||||
statusDesc: string;
|
||||
createTime: string;
|
||||
images?: string[];
|
||||
}
|
||||
// 获取任务状态图标
|
||||
const getMissionStatusIcon = (status: number) => {
|
||||
switch (status) {
|
||||
case MissionStatus.PENDING:
|
||||
return <ClockCircleOutlined />;
|
||||
case MissionStatus.DOING:
|
||||
return <SyncOutlined spin />;
|
||||
case MissionStatus.COMPLETE:
|
||||
return <CheckCircleOutlined />;
|
||||
case MissionStatus.CANCELED:
|
||||
return <CloseCircleOutlined />;
|
||||
case MissionStatus.UPLOADING:
|
||||
return <UploadOutlined />;
|
||||
case MissionStatus.UPLOADED:
|
||||
return <CheckCircleOutlined />;
|
||||
default:
|
||||
return <ClockCircleOutlined />;
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化时间 - 将后端返回的时间格式化为更友好的显示
|
||||
const formatTime = (timeStr?: string): string => {
|
||||
if (!timeStr) return '--';
|
||||
try {
|
||||
// 处理可能的时间格式:2025-12-22T10:30:00 或 2025-12-22 10:30:00
|
||||
const date = new Date(timeStr.replace(' ', 'T'));
|
||||
if (isNaN(date.getTime())) return timeStr;
|
||||
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
|
||||
return `${month}-${day} ${hours}:${minutes}`;
|
||||
} catch {
|
||||
return timeStr;
|
||||
}
|
||||
};
|
||||
|
||||
const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
visible,
|
||||
@@ -45,12 +98,12 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
device,
|
||||
viewer,
|
||||
Cesium,
|
||||
droneData, // 从父组件接收,无需自己订阅SSE
|
||||
dockData, // 机库数据,包含 mode_code
|
||||
tourismId, // 景区ID
|
||||
}) => {
|
||||
const deviceSn = device?.deviceSn;
|
||||
|
||||
// SSE hook
|
||||
const { droneData, connectDroneSSE, disconnectDroneSSE, resetDroneData } = useDroneSSE();
|
||||
|
||||
// 航线相关状态
|
||||
const [routeList, setRouteList] = useState<WaylineRouteListItemVO[]>([]);
|
||||
const [selectedRouteId, setSelectedRouteId] = useState<string | null>(null);
|
||||
@@ -58,11 +111,13 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
const [routeLoading, setRouteLoading] = useState(false);
|
||||
|
||||
// 任务相关状态
|
||||
const [taskList, setTaskList] = useState<TaskItem[]>([]);
|
||||
const [selectedTaskId, setSelectedTaskId] = useState<string | null>(null);
|
||||
const [taskLoading, setTaskLoading] = useState(false);
|
||||
const [missionList, setMissionList] = useState<Mission[]>([]);
|
||||
const [selectedMissionCode, setSelectedMissionCode] = useState<string | null>(null);
|
||||
const [missionLoading, setMissionLoading] = useState(false);
|
||||
const [createLoading, setCreateLoading] = useState(false);
|
||||
const [imagePreviewVisible, setImagePreviewVisible] = useState(false);
|
||||
const [previewImages, setPreviewImages] = useState<string[]>([]);
|
||||
const [previewImages, setPreviewImages] = useState<MissionImage[]>([]);
|
||||
const [imageLoading, setImageLoading] = useState(false);
|
||||
|
||||
// Tab 状态
|
||||
const [activeTab, setActiveTab] = useState<string>('route');
|
||||
@@ -74,15 +129,9 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
const rafRef = useRef<number | null>(null);
|
||||
const pendingPosRef = useRef({ x: 0, y: 0 });
|
||||
|
||||
// 地图图层引用
|
||||
// 地图图层引用(仅航线相关)
|
||||
const waylineEntityRef = useRef<any>(null);
|
||||
const waypointEntitiesRef = useRef<any[]>([]);
|
||||
const droneEntityRef = useRef<any>(null);
|
||||
const flightTrackEntityRef = useRef<any>(null);
|
||||
const trackPositionsRef = useRef<any[]>([]);
|
||||
const hasFlownToDroneRef = useRef<boolean>(false); // 是否已经飞到过无人机位置
|
||||
const lastUpdateTimeRef = useRef<number>(0); // 上次更新时间
|
||||
const lastPositionRef = useRef<{ lon: number; lat: number; height: number } | null>(null); // 上次位置
|
||||
|
||||
// 实时位置 - 区分相对高度和海拔高度
|
||||
const realtimePosition = useMemo(() => {
|
||||
@@ -99,23 +148,18 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
};
|
||||
}, [droneData]);
|
||||
|
||||
// 初始化
|
||||
// 初始化 - 加载航线和任务列表
|
||||
useEffect(() => {
|
||||
if (visible && deviceSn) {
|
||||
connectDroneSSE(deviceSn);
|
||||
loadRoutesByDevice(deviceSn);
|
||||
loadTasksByDevice(deviceSn);
|
||||
loadMissionsByDevice(deviceSn);
|
||||
return () => {
|
||||
disconnectDroneSSE(deviceSn);
|
||||
resetDroneData();
|
||||
clearMapLayers();
|
||||
clearWaylineEntities();
|
||||
};
|
||||
} else {
|
||||
setPosition({ x: 0, y: 0 });
|
||||
trackPositionsRef.current = [];
|
||||
hasFlownToDroneRef.current = false;
|
||||
setSelectedRouteId(null);
|
||||
setSelectedTaskId(null);
|
||||
setSelectedMissionCode(null);
|
||||
}
|
||||
}, [visible, deviceSn]);
|
||||
|
||||
@@ -126,122 +170,9 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
hasViewer: !!viewer,
|
||||
hasCesium: !!Cesium,
|
||||
deviceSn,
|
||||
hasDroneData: !!droneData,
|
||||
});
|
||||
}, [visible, viewer, Cesium, deviceSn]);
|
||||
|
||||
// 实时位置更新 - 绘制无人机和航迹(节流:1秒更新一次,或位置变化时更新)
|
||||
useEffect(() => {
|
||||
if (!visible || !viewer || !Cesium || !realtimePosition) return;
|
||||
if (viewer.isDestroyed?.()) return;
|
||||
if (!realtimePosition.longitude || !realtimePosition.latitude) return;
|
||||
|
||||
const now = Date.now();
|
||||
const currentPos = {
|
||||
lon: realtimePosition.longitude,
|
||||
lat: realtimePosition.latitude,
|
||||
height: realtimePosition.height ?? 0,
|
||||
};
|
||||
|
||||
// 检查是否需要更新:1秒内且位置没变化则跳过
|
||||
const timeSinceLastUpdate = now - lastUpdateTimeRef.current;
|
||||
const lastPos = lastPositionRef.current;
|
||||
|
||||
if (lastPos && timeSinceLastUpdate < 1000) {
|
||||
// 检查位置是否有明显变化(经纬度变化超过0.00001度,约1米;高度变化超过0.5米)
|
||||
const posChanged =
|
||||
Math.abs(currentPos.lon - lastPos.lon) > 0.00001 ||
|
||||
Math.abs(currentPos.lat - lastPos.lat) > 0.00001 ||
|
||||
Math.abs(currentPos.height - lastPos.height) > 0.5;
|
||||
|
||||
if (!posChanged) {
|
||||
return; // 位置没变化且不到1秒,跳过更新
|
||||
}
|
||||
}
|
||||
|
||||
// 更新时间和位置记录
|
||||
lastUpdateTimeRef.current = now;
|
||||
lastPositionRef.current = currentPos;
|
||||
|
||||
const displayHeight = realtimePosition.height ?? 50;
|
||||
|
||||
try {
|
||||
const pos = Cesium.Cartesian3.fromDegrees(
|
||||
realtimePosition.longitude,
|
||||
realtimePosition.latitude,
|
||||
displayHeight
|
||||
);
|
||||
|
||||
const labelText = `无人机 H:${realtimePosition.height != null ? realtimePosition.height.toFixed(0) : '--'}m`;
|
||||
|
||||
// 更新或创建无人机entity
|
||||
if (droneEntityRef.current) {
|
||||
droneEntityRef.current.position = pos;
|
||||
if (droneEntityRef.current.label) {
|
||||
droneEntityRef.current.label.text = labelText;
|
||||
}
|
||||
} else {
|
||||
droneEntityRef.current = viewer.entities.add({
|
||||
name: '无人机实时位置',
|
||||
position: pos,
|
||||
point: {
|
||||
pixelSize: 16,
|
||||
color: Cesium.Color.RED,
|
||||
outlineColor: Cesium.Color.WHITE,
|
||||
outlineWidth: 3,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
label: {
|
||||
text: labelText,
|
||||
font: '14px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||
outlineWidth: 2,
|
||||
outlineColor: Cesium.Color.BLACK,
|
||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
pixelOffset: new Cesium.Cartesian2(0, -20),
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
console.log('[TaskPanel] 创建无人机entity');
|
||||
}
|
||||
|
||||
// 添加航迹点(只有位置变化才添加)
|
||||
trackPositionsRef.current.push(pos);
|
||||
|
||||
// 绘制飞行轨迹
|
||||
if (trackPositionsRef.current.length >= 2) {
|
||||
if (flightTrackEntityRef.current) {
|
||||
flightTrackEntityRef.current.polyline.positions = [...trackPositionsRef.current];
|
||||
} else {
|
||||
flightTrackEntityRef.current = viewer.entities.add({
|
||||
name: '飞行轨迹',
|
||||
polyline: {
|
||||
positions: [...trackPositionsRef.current],
|
||||
width: 4,
|
||||
material: new Cesium.PolylineGlowMaterialProperty({
|
||||
glowPower: 0.3,
|
||||
color: Cesium.Color.LIME,
|
||||
}),
|
||||
clampToGround: false,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
console.log('[TaskPanel] 创建飞行轨迹entity');
|
||||
}
|
||||
}
|
||||
|
||||
// 强制渲染
|
||||
viewer.scene.requestRender();
|
||||
|
||||
// 首次收到位置数据时,自动飞到无人机位置
|
||||
if (!hasFlownToDroneRef.current && trackPositionsRef.current.length === 1) {
|
||||
hasFlownToDroneRef.current = true;
|
||||
flyToDrone();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[TaskPanel] 更新无人机位置出错:', error);
|
||||
}
|
||||
}, [realtimePosition, visible, viewer, Cesium]);
|
||||
}, [visible, viewer, Cesium, deviceSn, droneData]);
|
||||
|
||||
// 飞到无人机位置
|
||||
const flyToDrone = useCallback(() => {
|
||||
@@ -287,20 +218,25 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 加载任务列表(后端未实现,使用模拟数据)
|
||||
const loadTasksByDevice = useCallback(async (sn: string) => {
|
||||
// 加载任务列表
|
||||
const loadMissionsByDevice = useCallback(async (sn: string) => {
|
||||
try {
|
||||
setTaskLoading(true);
|
||||
// TODO: 调用后端接口 - waylineRouteApi.getTaskListByDevice(sn)
|
||||
// 模拟数据
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
setTaskList([
|
||||
// 暂无任务,等后端实现
|
||||
]);
|
||||
setMissionLoading(true);
|
||||
const res = await listMission({
|
||||
deviceSn: sn,
|
||||
page: 1,
|
||||
limit: 20,
|
||||
});
|
||||
if (res.resp_code === 0) {
|
||||
setMissionList(res.data || []);
|
||||
} else {
|
||||
message.error(res.resp_msg || '加载任务列表失败');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载任务列表失败:', e);
|
||||
message.error('加载任务列表失败');
|
||||
} finally {
|
||||
setTaskLoading(false);
|
||||
setMissionLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -452,90 +388,210 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
waypointEntitiesRef.current = [];
|
||||
}, [viewer, isViewerValid]);
|
||||
|
||||
// 清除所有图层
|
||||
const clearMapLayers = useCallback(() => {
|
||||
if (!isViewerValid()) return;
|
||||
|
||||
clearWaylineEntities();
|
||||
|
||||
if (droneEntityRef.current) {
|
||||
try {
|
||||
viewer.entities.remove(droneEntityRef.current);
|
||||
} catch (e) {}
|
||||
droneEntityRef.current = null;
|
||||
}
|
||||
|
||||
if (flightTrackEntityRef.current) {
|
||||
try {
|
||||
viewer.entities.remove(flightTrackEntityRef.current);
|
||||
} catch (e) {}
|
||||
flightTrackEntityRef.current = null;
|
||||
}
|
||||
|
||||
trackPositionsRef.current = [];
|
||||
}, [viewer, isViewerValid, clearWaylineEntities]);
|
||||
|
||||
// 选择航线
|
||||
const handleSelectRoute = useCallback((routeId: string) => {
|
||||
setSelectedRouteId(routeId);
|
||||
loadWaypoints(routeId);
|
||||
}, [loadWaypoints]);
|
||||
|
||||
// 检查机库是否空闲
|
||||
const isDockIdle = useMemo(() => {
|
||||
return dockData?.mode_code === 0;
|
||||
}, [dockData]);
|
||||
|
||||
// 创建任务
|
||||
const handleCreateTask = useCallback(async () => {
|
||||
const handleCreateMission = useCallback(async () => {
|
||||
if (!selectedRouteId) {
|
||||
message.warning('请先选择一条航线');
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查机库状态
|
||||
if (!isDockIdle) {
|
||||
message.warning('机库正在执行任务,请等待当前任务完成');
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedRoute = routeList.find(r => r.routeId === selectedRouteId);
|
||||
if (!selectedRoute) return;
|
||||
|
||||
// TODO: 调用后端接口创建任务
|
||||
// await waylineRouteApi.createTask({
|
||||
// routeId: selectedRouteId,
|
||||
// routeName: selectedRoute.routeName,
|
||||
// deviceSn: deviceSn,
|
||||
// });
|
||||
try {
|
||||
setCreateLoading(true);
|
||||
const res = await saveMission({
|
||||
deviceSn: deviceSn!,
|
||||
missionType: MissionType.WAYLINE,
|
||||
tourismId: tourismId,
|
||||
waylineId: selectedRoute.routeId,
|
||||
waylineName: selectedRoute.routeName,
|
||||
});
|
||||
|
||||
message.info('创建任务功能待后端实现');
|
||||
}, [selectedRouteId, routeList, deviceSn]);
|
||||
if (res.resp_code === 0) {
|
||||
message.success('任务创建成功');
|
||||
// 刷新任务列表
|
||||
loadMissionsByDevice(deviceSn!);
|
||||
// 切换到任务 Tab
|
||||
setActiveTab('task');
|
||||
} else {
|
||||
message.error(res.resp_msg || '任务创建失败');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('创建任务失败:', e);
|
||||
message.error('创建任务失败');
|
||||
} finally {
|
||||
setCreateLoading(false);
|
||||
}
|
||||
}, [selectedRouteId, routeList, deviceSn, tourismId, isDockIdle, loadMissionsByDevice]);
|
||||
|
||||
// 查看任务图片
|
||||
const handleViewTaskImages = useCallback(async (task: TaskItem) => {
|
||||
// TODO: 调用后端接口获取任务图片
|
||||
// const res = await waylineRouteApi.getTaskImages(task.taskId);
|
||||
// setPreviewImages(res.data || []);
|
||||
const handleViewMissionImages = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
|
||||
// 模拟数据
|
||||
setPreviewImages([
|
||||
'https://via.placeholder.com/800x600?text=Task+Image+1',
|
||||
'https://via.placeholder.com/800x600?text=Task+Image+2',
|
||||
]);
|
||||
setImagePreviewVisible(true);
|
||||
try {
|
||||
setImageLoading(true);
|
||||
const res = await listMissionImage(mission.missionCode);
|
||||
if (res.resp_code === 0) {
|
||||
setPreviewImages(res.data || []);
|
||||
if (res.data && res.data.length > 0) {
|
||||
setImagePreviewVisible(true);
|
||||
} else {
|
||||
message.info('该任务暂无图片');
|
||||
}
|
||||
} else {
|
||||
message.error(res.resp_msg || '获取图片失败');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取任务图片失败:', e);
|
||||
message.error('获取任务图片失败');
|
||||
} finally {
|
||||
setImageLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 完成任务
|
||||
const handleCompleteMission = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
|
||||
Modal.confirm({
|
||||
title: '确认完成任务',
|
||||
content: `确定要完成任务 ${mission.missionCode} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
const res = await completeMission(mission.missionCode!);
|
||||
if (res.resp_code === 0) {
|
||||
message.success('任务已完成');
|
||||
loadMissionsByDevice(deviceSn!);
|
||||
} else {
|
||||
message.error(res.resp_msg || '操作失败');
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('操作失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
}, [deviceSn, loadMissionsByDevice]);
|
||||
|
||||
// 取消任务
|
||||
const handleCancelMission = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
|
||||
Modal.confirm({
|
||||
title: '确认取消任务',
|
||||
content: `确定要取消任务 ${mission.missionCode} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
const res = await cancelMission(mission.missionCode!);
|
||||
if (res.resp_code === 0) {
|
||||
message.success('任务已取消');
|
||||
loadMissionsByDevice(deviceSn!);
|
||||
} else {
|
||||
message.error(res.resp_msg || '操作失败');
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('操作失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
}, [deviceSn, loadMissionsByDevice]);
|
||||
|
||||
// 删除任务
|
||||
const handleDeleteMission = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
|
||||
Modal.confirm({
|
||||
title: '确认删除任务',
|
||||
content: `确定要删除任务 ${mission.missionCode} 吗?此操作不可恢复。`,
|
||||
okType: 'danger',
|
||||
onOk: async () => {
|
||||
try {
|
||||
const res = await deleteMission(mission.missionCode!);
|
||||
if (res.resp_code === 0) {
|
||||
message.success('任务已删除');
|
||||
loadMissionsByDevice(deviceSn!);
|
||||
} else {
|
||||
message.error(res.resp_msg || '删除失败');
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
}, [deviceSn, loadMissionsByDevice]);
|
||||
|
||||
// 执行任务(航线任务需要手动确认执行)
|
||||
const handleExecuteMission = useCallback(async (mission: Mission) => {
|
||||
if (!mission.missionCode) return;
|
||||
|
||||
// 检查机库状态
|
||||
if (!isDockIdle) {
|
||||
message.warning('机库正在执行任务,请等待当前任务完成');
|
||||
return;
|
||||
}
|
||||
|
||||
Modal.confirm({
|
||||
title: '确认执行任务',
|
||||
content: (
|
||||
<div>
|
||||
<p>确定要执行任务 <strong>{mission.missionCode}</strong> 吗?</p>
|
||||
{mission.waylineName && (
|
||||
<p style={{ fontSize: 12, color: '#666' }}>
|
||||
航线: {mission.waylineName}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
okText: '确认执行',
|
||||
onOk: async () => {
|
||||
try {
|
||||
const res = await executeMission(mission.missionCode!);
|
||||
if (res.resp_code === 0) {
|
||||
message.success('任务已下发执行');
|
||||
loadMissionsByDevice(deviceSn!);
|
||||
} else {
|
||||
message.error(res.resp_msg || '执行失败');
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('执行失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
}, [deviceSn, loadMissionsByDevice, isDockIdle]);
|
||||
|
||||
// 刷新
|
||||
const handleRefresh = useCallback(() => {
|
||||
if (deviceSn) {
|
||||
loadRoutesByDevice(deviceSn);
|
||||
loadTasksByDevice(deviceSn);
|
||||
loadMissionsByDevice(deviceSn);
|
||||
message.success('刷新成功');
|
||||
}
|
||||
}, [deviceSn, loadRoutesByDevice, loadTasksByDevice]);
|
||||
}, [deviceSn, loadRoutesByDevice, loadMissionsByDevice]);
|
||||
|
||||
// 关闭面板时,主动断开SSE连接
|
||||
// 关闭面板时清理航线图层
|
||||
const handleClose = useCallback(() => {
|
||||
// 1. 断开无人机SSE连接(会调用后端接口取消订阅)
|
||||
if (deviceSn) {
|
||||
disconnectDroneSSE(deviceSn);
|
||||
}
|
||||
// 2. 重置无人机数据
|
||||
resetDroneData();
|
||||
// 3. 清除地图图层
|
||||
clearMapLayers();
|
||||
// 4. 调用父组件的关闭回调
|
||||
// 清除航线图层
|
||||
clearWaylineEntities();
|
||||
// 调用父组件的关闭回调
|
||||
onClose();
|
||||
}, [deviceSn, disconnectDroneSSE, resetDroneData, clearMapLayers, onClose]);
|
||||
}, [clearWaylineEntities, onClose]);
|
||||
|
||||
// 拖拽
|
||||
const handleMouseDown = (e: React.MouseEvent) => {
|
||||
@@ -648,17 +704,33 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 机库状态 */}
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionTitle}>机库状态</div>
|
||||
<div className={styles.dockStatus}>
|
||||
<Tag color={isDockIdle ? 'success' : 'warning'}>
|
||||
{isDockIdle ? '空闲' : '忙碌'}
|
||||
</Tag>
|
||||
{dockData?.mode_code !== undefined && (
|
||||
<span className={styles.modeCode}>
|
||||
mode_code: {dockData.mode_code}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 创建任务按钮 */}
|
||||
<div className={styles.section}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
block
|
||||
onClick={handleCreateTask}
|
||||
disabled={!selectedRouteId}
|
||||
onClick={handleCreateMission}
|
||||
disabled={!selectedRouteId || !isDockIdle}
|
||||
loading={createLoading}
|
||||
className={styles.createBtn}
|
||||
>
|
||||
基于此航线创建任务
|
||||
{isDockIdle ? '基于此航线创建任务' : '机库忙碌中...'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -688,30 +760,44 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
<div className={styles.tabContent}>
|
||||
{/* 任务列表 */}
|
||||
<div className={styles.section}>
|
||||
<div className={styles.sectionTitle}>任务列表</div>
|
||||
<div className={styles.sectionTitle}>
|
||||
任务列表
|
||||
{missionLoading && <Spin size="small" style={{ marginLeft: 8 }} />}
|
||||
</div>
|
||||
<div className={styles.taskList}>
|
||||
{taskLoading ? (
|
||||
{missionLoading && missionList.length === 0 ? (
|
||||
<div className={styles.loading}>加载中...</div>
|
||||
) : taskList.length === 0 ? (
|
||||
) : missionList.length === 0 ? (
|
||||
<Empty
|
||||
description="暂无任务,请先创建"
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
className={styles.emptyState}
|
||||
/>
|
||||
) : (
|
||||
taskList.map(task => (
|
||||
missionList.map(mission => (
|
||||
<div
|
||||
key={task.taskId}
|
||||
className={`${styles.taskItem} ${selectedTaskId === task.taskId ? styles.selected : ''}`}
|
||||
onClick={() => setSelectedTaskId(task.taskId)}
|
||||
key={mission.missionCode}
|
||||
className={`${styles.taskItem} ${selectedMissionCode === mission.missionCode ? styles.selected : ''}`}
|
||||
onClick={() => setSelectedMissionCode(mission.missionCode || null)}
|
||||
>
|
||||
<div className={styles.taskInfo}>
|
||||
<div className={styles.taskName}>{task.taskName}</div>
|
||||
<div className={styles.taskHeader}>
|
||||
<span className={styles.taskCode}>{mission.missionCode}</span>
|
||||
</div>
|
||||
<div className={styles.taskName}>
|
||||
{mission.missionName || mission.waylineName || '未命名任务'}
|
||||
</div>
|
||||
<div className={styles.taskMeta}>
|
||||
<span className={`${styles.status} ${styles[`status${task.status}`]}`}>
|
||||
{task.statusDesc}
|
||||
</span>
|
||||
<span>{task.createTime}</span>
|
||||
<Tag color={mission.missionType === MissionType.TAKEOFF ? 'orange' : 'blue'}>
|
||||
{MissionTypeMap[mission.missionType || 1]}
|
||||
</Tag>
|
||||
<Tag
|
||||
icon={getMissionStatusIcon(mission.missionStatus || 1)}
|
||||
color={MissionStatusColorMap[mission.missionStatus || 1]}
|
||||
>
|
||||
{MissionStatusMap[mission.missionStatus || 1]}
|
||||
</Tag>
|
||||
<span className={styles.taskTime}>{formatTime(mission.createTime)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.taskActions}>
|
||||
@@ -720,12 +806,74 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
className={styles.actionBtn}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleViewTaskImages(task);
|
||||
handleViewMissionImages(mission);
|
||||
}}
|
||||
disabled={imageLoading}
|
||||
>
|
||||
<PictureOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/* 待执行的航线任务可以执行 */}
|
||||
{mission.missionStatus === MissionStatus.PENDING &&
|
||||
mission.missionType === MissionType.WAYLINE && (
|
||||
<Tooltip title={isDockIdle ? '执行任务' : '机库忙碌中'}>
|
||||
<button
|
||||
className={`${styles.actionBtn} ${styles.execute}`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleExecuteMission(mission);
|
||||
}}
|
||||
disabled={!isDockIdle}
|
||||
>
|
||||
<PlayCircleOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
{/* 只有执行中、上传中、上传完成状态可以手动完成 */}
|
||||
{(mission.missionStatus === MissionStatus.DOING ||
|
||||
mission.missionStatus === MissionStatus.UPLOADING ||
|
||||
mission.missionStatus === MissionStatus.UPLOADED) && (
|
||||
<Tooltip title="完成任务">
|
||||
<button
|
||||
className={styles.actionBtn}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleCompleteMission(mission);
|
||||
}}
|
||||
>
|
||||
<CheckCircleOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
{/* 只有待执行状态可以取消 */}
|
||||
{mission.missionStatus === MissionStatus.PENDING && (
|
||||
<Tooltip title="取消任务">
|
||||
<button
|
||||
className={styles.actionBtn}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleCancelMission(mission);
|
||||
}}
|
||||
>
|
||||
<CloseCircleOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
{/* 已完成或已取消的任务可以删除 */}
|
||||
{(mission.missionStatus === MissionStatus.COMPLETE ||
|
||||
mission.missionStatus === MissionStatus.CANCELED) && (
|
||||
<Tooltip title="删除任务">
|
||||
<button
|
||||
className={`${styles.actionBtn} ${styles.danger}`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleDeleteMission(mission);
|
||||
}}
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
@@ -766,8 +914,8 @@ const TaskPanel: React.FC<TaskPanelProps> = ({
|
||||
onVisibleChange: (vis) => setImagePreviewVisible(vis),
|
||||
}}
|
||||
>
|
||||
{previewImages.map((src, index) => (
|
||||
<Image key={index} src={src} style={{ display: 'none' }} />
|
||||
{previewImages.map((img, index) => (
|
||||
<Image key={img.id || index} src={img.viewUrl} style={{ display: 'none' }} />
|
||||
))}
|
||||
</Image.PreviewGroup>
|
||||
</div>
|
||||
|
||||
+288
-36
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
||||
import React, { useEffect, useRef, useState, useCallback, useMemo } from 'react';
|
||||
import { message, Button, Tooltip } from 'antd';
|
||||
import { AppstoreOutlined } from '@ant-design/icons';
|
||||
import RightPanel from './3d/BottomPanel/RightPanel';
|
||||
@@ -6,6 +6,7 @@ import LeftControlPanel from './3d/BottomPanel/LeftControlPanel';
|
||||
import TaskPanel from './3d/BottomPanel/TaskPanel';
|
||||
import TilesetPanel from './3d/TilesetPanel';
|
||||
import { useTilesetLoader, TilesetConfig } from './3d/hooks/useTilesetLoader';
|
||||
import { useDroneSSE } from './3d/hooks/useDroneSSE';
|
||||
import { getModelsByTourismId, convertToTilesetConfig } from '@/services/threeDModel';
|
||||
|
||||
// 动态导入Cesium
|
||||
@@ -36,6 +37,20 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 任务管理面板状态
|
||||
const [taskPanelVisible, setTaskPanelVisible] = useState(false);
|
||||
const [taskPanelDevice, setTaskPanelDevice] = useState<any>(null);
|
||||
const [taskPanelDockData, setTaskPanelDockData] = useState<any>(null);
|
||||
const [taskPanelTourismId, setTaskPanelTourismId] = useState<number | undefined>(undefined);
|
||||
|
||||
// 无人机SSE订阅(用于在3D地球上显示无人机位置)
|
||||
const [droneDeviceSn, setDroneDeviceSn] = useState<string>('');
|
||||
const { droneData, connectDroneSSE, disconnectDroneSSE, resetDroneData } = useDroneSSE();
|
||||
|
||||
// 无人机位置渲染相关引用
|
||||
const droneEntityRef = useRef<any>(null);
|
||||
const flightTrackEntityRef = useRef<any>(null);
|
||||
const trackPositionsRef = useRef<any[]>([]);
|
||||
const hasFlownToDroneRef = useRef<boolean>(false);
|
||||
const lastDroneUpdateTimeRef = useRef<number>(0);
|
||||
const lastDronePositionRef = useRef<{ lon: number; lat: number; height: number } | null>(null);
|
||||
|
||||
// 3D Tiles 模型管理
|
||||
const [tilesetPanelVisible, setTilesetPanelVisible] = useState(false);
|
||||
@@ -180,10 +195,11 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
|
||||
/**
|
||||
* 加载景区绑定的模型
|
||||
* 【优化】采用"先飞后加载"策略,用户点击后立即飞行,模型异步加载
|
||||
* 策略:
|
||||
* 1. 默认只加载第一个模型(通常是主模型)
|
||||
* 2. 其他模型存储在 currentTourismModels 中,可通过模型面板手动加载
|
||||
* 3. 如果模型数量较少(<=2个),自动加载所有模型
|
||||
* 1. 相机飞行已在 handleTourismSelect 中执行,此处专注于加载
|
||||
* 2. 高程和模型并行准备,减少等待时间
|
||||
* 3. 模型加载完成后,平滑调整到最佳观察视角
|
||||
*/
|
||||
const loadTourismModels = useCallback(async (tourismId: number): Promise<boolean> => {
|
||||
if (!viewerRef.current || !Cesium) {
|
||||
@@ -210,15 +226,14 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 保存所有模型配置(供模型面板使用)
|
||||
setCurrentTourismModels(configs);
|
||||
|
||||
// 【重要】加载模型前,先切换到高程地形
|
||||
// 从第一个模型的配置中获取地形类型(用于保持与高度标定时一致的地形)
|
||||
// 【优化】并行执行:高程加载和模型配置准备
|
||||
const firstModelTerrainType = configs[0]?.position?.terrainType;
|
||||
console.log('第一个模型的地形类型配置:', firstModelTerrainType);
|
||||
const loadedTerrainType = await switchToElevationTerrain(firstModelTerrainType);
|
||||
console.log('实际加载的地形类型:', loadedTerrainType);
|
||||
|
||||
// 启动高程加载(不阻塞,让用户先看到地形变化)
|
||||
const terrainPromise = switchToElevationTerrain(firstModelTerrainType);
|
||||
|
||||
// 确定要自动加载的模型数量
|
||||
// 策略:模型数量 <= 2 时全部加载,否则只加载第一个
|
||||
const autoLoadCount = configs.length <= 2 ? configs.length : 1;
|
||||
const configsToLoad = configs.slice(0, autoLoadCount);
|
||||
|
||||
@@ -226,6 +241,10 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
message.info(`景区共有 ${configs.length} 个模型,已自动加载第 1 个,其他可通过模型面板加载`);
|
||||
}
|
||||
|
||||
// 等待高程加载完成(通常很快,或者已缓存)
|
||||
const loadedTerrainType = await terrainPromise;
|
||||
console.log('实际加载的地形类型:', loadedTerrainType);
|
||||
|
||||
let loadedCount = 0;
|
||||
let firstTileset: any = null;
|
||||
|
||||
@@ -246,11 +265,12 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 飞到第一个加载成功的模型
|
||||
if (firstTileset) {
|
||||
// 【优化】模型加载完成后,平滑调整到最佳观察视角
|
||||
// 使用较短的动画时间,因为相机已经在景区附近了
|
||||
if (firstTileset && viewerRef.current && !viewerRef.current.isDestroyed?.()) {
|
||||
try {
|
||||
await viewerRef.current.flyTo(firstTileset, {
|
||||
duration: 2.0,
|
||||
viewerRef.current.flyTo(firstTileset, {
|
||||
duration: 1.0, // 缩短动画时间,因为已经在附近
|
||||
offset: new Cesium.HeadingPitchRange(
|
||||
Cesium.Math.toRadians(0),
|
||||
Cesium.Math.toRadians(-45),
|
||||
@@ -258,8 +278,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
),
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn('flyTo 失败,尝试 zoomTo:', e);
|
||||
await viewerRef.current.zoomTo(firstTileset);
|
||||
console.warn('微调视角失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,24 +297,21 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
}, [loadTileset, unloadAllTilesets, switchToElevationTerrain]);
|
||||
|
||||
// 处理景区点击
|
||||
// 优化策略:先飞行后加载,提升用户体验
|
||||
const handleTourismSelect = useCallback((tourism: any) => {
|
||||
setSelectedTourism(tourism);
|
||||
setRightPanelVisible(true);
|
||||
// 切换景区时,关闭左侧操控台
|
||||
setLeftPanelVisible(false);
|
||||
|
||||
// 查询并加载该景区绑定的3D模型
|
||||
// 如果有模型会自动飞到模型位置,没有模型才飞到景区位置
|
||||
// 【优化】立即飞到景区位置,不等待模型加载
|
||||
// 这样用户点击后立刻能看到视角变化,体验更流畅
|
||||
flyToTourism(tourism);
|
||||
|
||||
// 【优化】异步加载模型,不阻塞飞行动画
|
||||
// 模型加载完成后会自动调整到最佳视角
|
||||
if (tourism.id) {
|
||||
loadTourismModels(tourism.id).then((hasModel) => {
|
||||
// 异步回调时检查 viewer 是否还存在
|
||||
if (!viewerRef.current || viewerRef.current.isDestroyed?.()) return;
|
||||
if (!hasModel) {
|
||||
flyToTourism(tourism);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
flyToTourism(tourism);
|
||||
loadTourismModels(tourism.id);
|
||||
}
|
||||
}, [flyToTourism, loadTourismModels]);
|
||||
|
||||
@@ -306,19 +322,221 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
}
|
||||
}, [externalSelectedTourism, loading, handleTourismSelect]);
|
||||
|
||||
// 处理从右侧面板点击"操控"
|
||||
// 清除无人机图层
|
||||
const clearDroneLayers = useCallback(() => {
|
||||
if (!viewerRef.current || viewerRef.current.isDestroyed?.()) return;
|
||||
|
||||
if (droneEntityRef.current) {
|
||||
try {
|
||||
viewerRef.current.entities.remove(droneEntityRef.current);
|
||||
} catch (e) {}
|
||||
droneEntityRef.current = null;
|
||||
}
|
||||
|
||||
if (flightTrackEntityRef.current) {
|
||||
try {
|
||||
viewerRef.current.entities.remove(flightTrackEntityRef.current);
|
||||
} catch (e) {}
|
||||
flightTrackEntityRef.current = null;
|
||||
}
|
||||
|
||||
trackPositionsRef.current = [];
|
||||
hasFlownToDroneRef.current = false;
|
||||
lastDroneUpdateTimeRef.current = 0;
|
||||
lastDronePositionRef.current = null;
|
||||
}, []);
|
||||
|
||||
// 处理从右侧面板点击"操控" - 打开操控台并订阅无人机SSE
|
||||
const handleOpenControl = useCallback((device: any, realtimeData: any) => {
|
||||
setControlDevice(device);
|
||||
setControlRealtimeData(realtimeData);
|
||||
setLeftPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 打开操控台时开始订阅无人机SSE(msg_alarm)
|
||||
const deviceSn = device?.deviceSn;
|
||||
if (deviceSn && deviceSn !== droneDeviceSn) {
|
||||
// 断开旧的SSE连接
|
||||
if (droneDeviceSn) {
|
||||
disconnectDroneSSE(droneDeviceSn);
|
||||
}
|
||||
// 清除旧的无人机图层
|
||||
clearDroneLayers();
|
||||
// 开始新的SSE订阅
|
||||
setDroneDeviceSn(deviceSn);
|
||||
connectDroneSSE(deviceSn);
|
||||
}
|
||||
}, [droneDeviceSn, disconnectDroneSSE, connectDroneSSE, clearDroneLayers]);
|
||||
|
||||
// 关闭操控台 - 断开无人机SSE
|
||||
const handleCloseControl = useCallback(() => {
|
||||
setLeftPanelVisible(false);
|
||||
|
||||
// 关闭操控台时断开无人机SSE(取消msg_alarm订阅)
|
||||
if (droneDeviceSn) {
|
||||
disconnectDroneSSE(droneDeviceSn);
|
||||
setDroneDeviceSn('');
|
||||
}
|
||||
resetDroneData();
|
||||
clearDroneLayers();
|
||||
}, [droneDeviceSn, disconnectDroneSSE, resetDroneData, clearDroneLayers]);
|
||||
|
||||
// 处理从右侧面板点击"任务管理"
|
||||
const handleOpenTaskPanel = useCallback((device: any) => {
|
||||
const handleOpenTaskPanel = useCallback((device: any, dockData: any, tourismId?: number) => {
|
||||
setTaskPanelDevice(device);
|
||||
setTaskPanelDockData(dockData);
|
||||
setTaskPanelTourismId(tourismId);
|
||||
setTaskPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 计算无人机实时位置
|
||||
const realtimePosition = useMemo(() => {
|
||||
if (!droneData) return null;
|
||||
return {
|
||||
longitude: droneData.longitude,
|
||||
latitude: droneData.latitude,
|
||||
height: droneData.height, // 相对高度(相对于起飞点)
|
||||
elevation: droneData.elevation, // 海拔高度
|
||||
altitude: droneData.height, // 3D地图显示用
|
||||
heading: droneData.attitude_head,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}, [droneData]);
|
||||
|
||||
// 飞到无人机位置
|
||||
const flyToDrone = useCallback(() => {
|
||||
if (!viewerRef.current || !Cesium || !realtimePosition) return;
|
||||
if (!realtimePosition.longitude || !realtimePosition.latitude) return;
|
||||
|
||||
const droneHeight = realtimePosition.height ?? 50;
|
||||
|
||||
viewerRef.current.camera.flyTo({
|
||||
destination: Cesium.Cartesian3.fromDegrees(
|
||||
realtimePosition.longitude,
|
||||
realtimePosition.latitude,
|
||||
droneHeight + 100 // 视角高度比无人机高100米
|
||||
),
|
||||
orientation: {
|
||||
heading: 0,
|
||||
pitch: Cesium.Math.toRadians(-90), // 垂直俯视
|
||||
roll: 0,
|
||||
},
|
||||
duration: 1.5,
|
||||
});
|
||||
}, [realtimePosition]);
|
||||
|
||||
// 无人机位置渲染(当收到SSE数据时在地图上显示无人机位置)
|
||||
useEffect(() => {
|
||||
if (!viewerRef.current || !Cesium || !realtimePosition) return;
|
||||
if (viewerRef.current.isDestroyed?.()) return;
|
||||
if (!realtimePosition.longitude || !realtimePosition.latitude) return;
|
||||
|
||||
const now = Date.now();
|
||||
const currentPos = {
|
||||
lon: realtimePosition.longitude,
|
||||
lat: realtimePosition.latitude,
|
||||
height: realtimePosition.height ?? 0,
|
||||
};
|
||||
|
||||
// 节流:1秒内且位置没变化则跳过
|
||||
const timeSinceLastUpdate = now - lastDroneUpdateTimeRef.current;
|
||||
const lastPos = lastDronePositionRef.current;
|
||||
|
||||
if (lastPos && timeSinceLastUpdate < 1000) {
|
||||
const posChanged =
|
||||
Math.abs(currentPos.lon - lastPos.lon) > 0.00001 ||
|
||||
Math.abs(currentPos.lat - lastPos.lat) > 0.00001 ||
|
||||
Math.abs(currentPos.height - lastPos.height) > 0.5;
|
||||
|
||||
if (!posChanged) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新时间和位置记录
|
||||
lastDroneUpdateTimeRef.current = now;
|
||||
lastDronePositionRef.current = currentPos;
|
||||
|
||||
const displayHeight = realtimePosition.height ?? 50;
|
||||
|
||||
try {
|
||||
const pos = Cesium.Cartesian3.fromDegrees(
|
||||
realtimePosition.longitude,
|
||||
realtimePosition.latitude,
|
||||
displayHeight
|
||||
);
|
||||
|
||||
const labelText = `无人机 H:${realtimePosition.height != null ? realtimePosition.height.toFixed(0) : '--'}m`;
|
||||
|
||||
// 更新或创建无人机entity
|
||||
if (droneEntityRef.current) {
|
||||
droneEntityRef.current.position = pos;
|
||||
if (droneEntityRef.current.label) {
|
||||
droneEntityRef.current.label.text = labelText;
|
||||
}
|
||||
} else {
|
||||
droneEntityRef.current = viewerRef.current.entities.add({
|
||||
name: '无人机实时位置',
|
||||
position: pos,
|
||||
point: {
|
||||
pixelSize: 16,
|
||||
color: Cesium.Color.RED,
|
||||
outlineColor: Cesium.Color.WHITE,
|
||||
outlineWidth: 3,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
label: {
|
||||
text: labelText,
|
||||
font: '14px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||
outlineWidth: 2,
|
||||
outlineColor: Cesium.Color.BLACK,
|
||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
pixelOffset: new Cesium.Cartesian2(0, -20),
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
console.log('[CesiumContainer] 创建无人机entity');
|
||||
}
|
||||
|
||||
// 添加航迹点
|
||||
trackPositionsRef.current.push(pos);
|
||||
|
||||
// 绘制飞行轨迹
|
||||
if (trackPositionsRef.current.length >= 2) {
|
||||
if (flightTrackEntityRef.current) {
|
||||
flightTrackEntityRef.current.polyline.positions = [...trackPositionsRef.current];
|
||||
} else {
|
||||
flightTrackEntityRef.current = viewerRef.current.entities.add({
|
||||
name: '飞行轨迹',
|
||||
polyline: {
|
||||
positions: [...trackPositionsRef.current],
|
||||
width: 4,
|
||||
material: new Cesium.PolylineGlowMaterialProperty({
|
||||
glowPower: 0.3,
|
||||
color: Cesium.Color.LIME,
|
||||
}),
|
||||
clampToGround: false,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
console.log('[CesiumContainer] 创建飞行轨迹entity');
|
||||
}
|
||||
}
|
||||
|
||||
// 强制渲染
|
||||
viewerRef.current.scene.requestRender();
|
||||
|
||||
// 首次收到位置数据时,自动飞到无人机位置
|
||||
if (!hasFlownToDroneRef.current && trackPositionsRef.current.length === 1) {
|
||||
hasFlownToDroneRef.current = true;
|
||||
flyToDrone();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[CesiumContainer] 更新无人机位置出错:', error);
|
||||
}
|
||||
}, [realtimePosition, flyToDrone]);
|
||||
|
||||
// 获取设备的视频流地址(从设备数据中获取)
|
||||
const getVideoStreamUrl = useCallback((device: any): string | undefined => {
|
||||
// 从设备配置获取视频流地址
|
||||
@@ -331,6 +549,14 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
setSelectedTourism(null);
|
||||
setLeftPanelVisible(false); // 同时也关闭左侧
|
||||
|
||||
// 【修复】断开无人机SSE连接并清除图层
|
||||
if (droneDeviceSn) {
|
||||
disconnectDroneSSE(droneDeviceSn);
|
||||
setDroneDeviceSn('');
|
||||
}
|
||||
resetDroneData();
|
||||
clearDroneLayers();
|
||||
|
||||
// 【修复】卸载所有3D模型,避免返回地球时出现渲染问题(黑洞)
|
||||
if (viewerRef.current) {
|
||||
unloadAllTilesets(viewerRef.current);
|
||||
@@ -349,7 +575,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
onClearSelection?.();
|
||||
|
||||
flyToGlobal();
|
||||
}, [flyToGlobal, unloadAllTilesets, onClearSelection]);
|
||||
}, [flyToGlobal, unloadAllTilesets, onClearSelection, droneDeviceSn, disconnectDroneSSE, resetDroneData, clearDroneLayers]);
|
||||
|
||||
// ========== 3D Tiles 模型管理方法 ==========
|
||||
|
||||
@@ -623,7 +849,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 地形/模型加载中提示 */}
|
||||
{/* 地形/模型加载中提示 - 优化为不阻塞视觉的提示 */}
|
||||
{(terrainLoading || modelLoading) && (
|
||||
<div
|
||||
style={{
|
||||
@@ -633,13 +859,35 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
transform: 'translateX(-50%)',
|
||||
color: '#fff',
|
||||
fontSize: 14,
|
||||
background: 'rgba(0,0,0,0.7)',
|
||||
padding: '8px 16px',
|
||||
borderRadius: 4,
|
||||
background: 'linear-gradient(135deg, rgba(0,100,150,0.85) 0%, rgba(0,60,100,0.85) 100%)',
|
||||
padding: '10px 20px',
|
||||
borderRadius: 20,
|
||||
zIndex: 800,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 10,
|
||||
boxShadow: '0 4px 15px rgba(0,0,0,0.3)',
|
||||
border: '1px solid rgba(0,240,255,0.3)',
|
||||
}}
|
||||
>
|
||||
{terrainLoading ? '正在加载高程地形...' : '正在加载3D模型...'}
|
||||
<div
|
||||
style={{
|
||||
width: 16,
|
||||
height: 16,
|
||||
border: '2px solid rgba(255,255,255,0.3)',
|
||||
borderTopColor: '#00f0ff',
|
||||
borderRadius: '50%',
|
||||
animation: 'spin 1s linear infinite',
|
||||
}}
|
||||
/>
|
||||
<span>
|
||||
{terrainLoading ? '正在加载高程地形...' : '正在加载3D模型...'}
|
||||
</span>
|
||||
<style>{`
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -677,10 +925,11 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
{/* 左侧操控台 */}
|
||||
<LeftControlPanel
|
||||
visible={leftPanelVisible}
|
||||
onClose={() => setLeftPanelVisible(false)}
|
||||
onClose={handleCloseControl}
|
||||
device={controlDevice}
|
||||
realtimeData={controlRealtimeData}
|
||||
videoStreamUrl={getVideoStreamUrl(controlDevice)}
|
||||
droneData={droneData}
|
||||
/>
|
||||
|
||||
{/* 右侧数据面板 */}
|
||||
@@ -701,6 +950,9 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
device={taskPanelDevice}
|
||||
viewer={viewerRef.current}
|
||||
Cesium={Cesium}
|
||||
droneData={droneData}
|
||||
dockData={taskPanelDockData}
|
||||
tourismId={taskPanelTourismId}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
/**
|
||||
* 任务类型枚举
|
||||
*/
|
||||
export enum MissionType {
|
||||
WAYLINE = 1, // 航线任务
|
||||
TAKEOFF = 2, // 一键起飞任务
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务状态枚举
|
||||
*/
|
||||
export enum MissionStatus {
|
||||
PENDING = 1, // 待执行
|
||||
CANCELED = 2, // 已取消
|
||||
COMPLETE = 3, // 已完成
|
||||
DOING = 4, // 执行中
|
||||
UPLOADING = 5, // 图片上传中
|
||||
UPLOADED = 6, // 图片上传完成
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务类型描述映射
|
||||
*/
|
||||
export const MissionTypeMap: Record<number, string> = {
|
||||
[MissionType.WAYLINE]: '航线任务',
|
||||
[MissionType.TAKEOFF]: '一键起飞',
|
||||
};
|
||||
|
||||
/**
|
||||
* 任务状态描述映射
|
||||
*/
|
||||
export const MissionStatusMap: Record<number, string> = {
|
||||
[MissionStatus.PENDING]: '待执行',
|
||||
[MissionStatus.CANCELED]: '已取消',
|
||||
[MissionStatus.COMPLETE]: '已完成',
|
||||
[MissionStatus.DOING]: '执行中',
|
||||
[MissionStatus.UPLOADING]: '上传中',
|
||||
[MissionStatus.UPLOADED]: '上传完成',
|
||||
};
|
||||
|
||||
/**
|
||||
* 任务状态颜色映射
|
||||
*/
|
||||
export const MissionStatusColorMap: Record<number, string> = {
|
||||
[MissionStatus.PENDING]: 'default',
|
||||
[MissionStatus.CANCELED]: 'error',
|
||||
[MissionStatus.COMPLETE]: 'success',
|
||||
[MissionStatus.DOING]: 'processing',
|
||||
[MissionStatus.UPLOADING]: 'warning',
|
||||
[MissionStatus.UPLOADED]: 'success',
|
||||
};
|
||||
|
||||
/**
|
||||
* 任务实体接口
|
||||
*/
|
||||
export interface Mission {
|
||||
id?: number;
|
||||
missionCode?: string;
|
||||
missionName?: string;
|
||||
missionType?: number;
|
||||
missionTypeDesc?: string;
|
||||
tourismId?: number;
|
||||
deviceSn?: string;
|
||||
waylineId?: string;
|
||||
waylineName?: string;
|
||||
missionStatus?: number;
|
||||
missionStatusDesc?: string;
|
||||
targetLatitude?: number;
|
||||
targetLongitude?: number;
|
||||
targetHeight?: number;
|
||||
creatorId?: number;
|
||||
creatorName?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
remark?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务图片实体接口
|
||||
*/
|
||||
export interface MissionImage {
|
||||
id?: number;
|
||||
missionCode?: string;
|
||||
tourismId?: number;
|
||||
deviceSn?: string;
|
||||
fileId?: string;
|
||||
filePath?: string;
|
||||
fileType?: string;
|
||||
viewUrl?: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
altitude?: number;
|
||||
shootTime?: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务请求参数
|
||||
*/
|
||||
export interface CreateMissionParams {
|
||||
deviceSn: string;
|
||||
missionType?: number;
|
||||
missionName?: string;
|
||||
tourismId?: number;
|
||||
waylineId?: string;
|
||||
waylineName?: string;
|
||||
targetLatitude?: number;
|
||||
targetLongitude?: number;
|
||||
targetHeight?: number;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务列表请求参数
|
||||
*/
|
||||
export interface ListMissionParams {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
deviceSn?: string;
|
||||
missionStatus?: number;
|
||||
missionType?: number;
|
||||
tourismId?: number;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务
|
||||
*/
|
||||
export async function saveMission(params: CreateMissionParams) {
|
||||
return request<API.Result<Mission>>('/api-order/mission/saveMission', {
|
||||
method: 'POST',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务(下发到设备)
|
||||
* 用于航线任务创建后,用户确认执行
|
||||
*/
|
||||
export async function executeMission(missionCode: string) {
|
||||
return request<API.Result<string>>('/api-order/mission/executeMission', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务列表
|
||||
*/
|
||||
export async function listMission(params: ListMissionParams) {
|
||||
return request<API.PageResult<Mission>>('/api-order/mission/listMission', {
|
||||
method: 'POST',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务详情
|
||||
*/
|
||||
export async function getMission(missionCode: string) {
|
||||
return request<API.Result<Mission>>('/api-order/mission/getMission', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
*/
|
||||
export async function updateMissionStatus(missionCode: string, status: number) {
|
||||
return request<API.Result<string>>('/api-order/mission/updateMissionStatus', {
|
||||
method: 'POST',
|
||||
data: { missionCode, status },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消任务
|
||||
*/
|
||||
export async function cancelMission(missionCode: string) {
|
||||
return request<API.Result<string>>('/api-order/mission/cancelMission', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成任务
|
||||
*/
|
||||
export async function completeMission(missionCode: string) {
|
||||
return request<API.Result<string>>('/api-order/mission/completeMission', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务
|
||||
*/
|
||||
export async function deleteMission(missionCode: string) {
|
||||
return request<API.Result<string>>('/api-order/mission/deleteMission', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存任务图片记录
|
||||
*/
|
||||
export async function saveMissionImage(params: Partial<MissionImage>) {
|
||||
return request<API.Result<MissionImage>>('/api-order/mission/image/saveMissionImage', {
|
||||
method: 'POST',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务图片列表
|
||||
*/
|
||||
export async function listMissionImage(missionCode: string) {
|
||||
return request<API.Result<MissionImage[]>>('/api-order/mission/image/listMissionImage', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询任务图片列表
|
||||
*/
|
||||
export async function pageMissionImage(params: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
missionCode?: string;
|
||||
deviceSn?: string;
|
||||
}) {
|
||||
return request<API.PageResult<MissionImage>>('/api-order/mission/image/pageMissionImage', {
|
||||
method: 'POST',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片详情
|
||||
*/
|
||||
export async function getMissionImage(id: number) {
|
||||
return request<API.Result<MissionImage>>('/api-order/mission/image/getMissionImage', {
|
||||
method: 'POST',
|
||||
data: { id },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片记录
|
||||
*/
|
||||
export async function deleteMissionImage(id: number) {
|
||||
return request<API.Result<string>>('/api-order/mission/image/deleteMissionImage', {
|
||||
method: 'POST',
|
||||
data: { id },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计任务图片数量
|
||||
*/
|
||||
export async function countMissionImage(missionCode: string) {
|
||||
return request<API.Result<number>>('/api-order/mission/image/countMissionImage', {
|
||||
method: 'POST',
|
||||
data: { missionCode },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user