feat: 航线任务与一键起飞任务
This commit is contained in:
+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>
|
||||
Reference in New Issue
Block a user