!34 fix(设备中心):增加设备执行任务接口幂等性配置
Merge pull request !34 from Iamasoldier/feature_lsl
This commit is contained in:
@@ -137,6 +137,80 @@ stateDiagram-v2
|
|||||||
|
|
||||||
### 4. 关键接口设计
|
### 4. 关键接口设计
|
||||||
|
|
||||||
|
#### 4.0 获取访问Token(OAuth2)
|
||||||
|
|
||||||
|
**接口地址:** `POST /api-uaa/oauth/token`
|
||||||
|
|
||||||
|
**认证方式:** HTTP Basic(`Authorization: Basic base64(clientId:clientSecret)`)
|
||||||
|
|
||||||
|
**请求头:**
|
||||||
|
- `Authorization: Basic {base64(clientId:clientSecret)}`
|
||||||
|
- `Content-Type: application/x-www-form-urlencoded`
|
||||||
|
|
||||||
|
**授权模式与参数:**
|
||||||
|
- 密码验证码模式(推荐)
|
||||||
|
- `grant_type=password_code`
|
||||||
|
- `username` 用户名
|
||||||
|
- `password` 密码
|
||||||
|
- `validCode` 校验码(图形/短信)
|
||||||
|
- `deviceId` 设备ID(可用于风控)
|
||||||
|
- 密码模式
|
||||||
|
- `grant_type=password`
|
||||||
|
- `username`
|
||||||
|
- `password`
|
||||||
|
- 客户端模式(服务器到服务器)
|
||||||
|
- `grant_type=client_credentials`
|
||||||
|
- 刷新令牌
|
||||||
|
- `grant_type=refresh_token`
|
||||||
|
- `refresh_token` 刷新令牌
|
||||||
|
|
||||||
|
**响应示例:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "eyJraWQiOi...",
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"expires_in": 3600,
|
||||||
|
"refresh_token": "def50200...",
|
||||||
|
"scope": "all openid profile"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**调用示例:**
|
||||||
|
|
||||||
|
- 密码验证码模式
|
||||||
|
```bash
|
||||||
|
curl -X POST 'https://{gateway}/api-uaa/oauth/token' \
|
||||||
|
-H 'Authorization: Basic {base64(clientId:clientSecret)}' \
|
||||||
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
-d 'grant_type=password_code&username=admin&password=123456&validCode=abcd&deviceId=web'
|
||||||
|
```
|
||||||
|
|
||||||
|
- 密码模式
|
||||||
|
```bash
|
||||||
|
curl -X POST 'https://{gateway}/api-uaa/oauth/token' \
|
||||||
|
-H 'Authorization: Basic {base64(clientId:clientSecret)}' \
|
||||||
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
-d 'grant_type=password&username=admin&password=123456'
|
||||||
|
```
|
||||||
|
|
||||||
|
- 客户端模式
|
||||||
|
```bash
|
||||||
|
curl -X POST 'https://{gateway}/api-uaa/oauth/token' \
|
||||||
|
-H 'Authorization: Basic {base64(clientId:clientSecret)}' \
|
||||||
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
-d 'grant_type=client_credentials'
|
||||||
|
```
|
||||||
|
|
||||||
|
- 刷新令牌
|
||||||
|
```bash
|
||||||
|
curl -X POST 'https://{gateway}/api-uaa/oauth/token' \
|
||||||
|
-H 'Authorization: Basic {base64(clientId:clientSecret)}' \
|
||||||
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
-d 'grant_type=refresh_token&refresh_token={refresh_token}'
|
||||||
|
```
|
||||||
|
|
||||||
|
> 说明:可用客户端在 `oauth_client_details` 管理(如 `webApp`、`app`、`zlt` 等示例);令牌类型支持不透明令牌与JWT,网关域名与前缀以实际环境为准。
|
||||||
|
|
||||||
#### 4.1 设备执行任务API
|
#### 4.1 设备执行任务API
|
||||||
|
|
||||||
**接口地址:** `POST /api-device/execute/task`
|
**接口地址:** `POST /api-device/execute/task`
|
||||||
|
|||||||
+4
@@ -5,6 +5,7 @@ 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.JsonElement;
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
|
import com.central.common.lock.Lock;
|
||||||
import com.central.device.feign.OrderCenterService;
|
import com.central.device.feign.OrderCenterService;
|
||||||
import com.central.device.message.ControlEnum;
|
import com.central.device.message.ControlEnum;
|
||||||
import com.central.device.message.ControlMessageConstant;
|
import com.central.device.message.ControlMessageConstant;
|
||||||
@@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备操作controller
|
* 设备操作controller
|
||||||
@@ -76,6 +78,8 @@ public class ApiDeviceController {
|
|||||||
*/
|
*/
|
||||||
@Operation(summary = "设备属性设置")
|
@Operation(summary = "设备属性设置")
|
||||||
@PostMapping("/setting/{deviceId}/property")
|
@PostMapping("/setting/{deviceId}/property")
|
||||||
|
@Lock(key = "device:writeProperties:#deviceId:#param['order_no']:#param['control']",
|
||||||
|
waitTime = 3, leaseTime = 10, unit = TimeUnit.SECONDS)
|
||||||
public Result writeProperties(@RequestBody Map<String, Object> param, @PathVariable("deviceId") String deviceId) {
|
public Result writeProperties(@RequestBody Map<String, Object> param, @PathVariable("deviceId") String deviceId) {
|
||||||
log.info("开始设置设备属性: deviceId={}, param={}", deviceId, param);
|
log.info("开始设置设备属性: deviceId={}, param={}", deviceId, param);
|
||||||
try {
|
try {
|
||||||
|
|||||||
+19
-10
@@ -131,7 +131,7 @@ public class MediaServiceImpl implements IMediaService {
|
|||||||
|
|
||||||
// 3. 获取视频文件
|
// 3. 获取视频文件
|
||||||
// List<OrderFile> videoFiles = orderFileService.getOrderVideoFiles(orderNo);
|
// List<OrderFile> videoFiles = orderFileService.getOrderVideoFiles(orderNo);
|
||||||
if (orderFiles == null || orderFiles.size() < 7) {
|
if (orderFiles == null || orderFiles.size() < qrCode.getMaterialCount()) {
|
||||||
throw new BusinessException("订单视频文件数量不足,至少需要2个视频文件");
|
throw new BusinessException("订单视频文件数量不足,至少需要2个视频文件");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,16 +188,17 @@ public class MediaServiceImpl implements IMediaService {
|
|||||||
List<OrderFile> videoFiles = taskData.getVideoFiles();
|
List<OrderFile> videoFiles = taskData.getVideoFiles();
|
||||||
//@TODO 后期需要通过模板参数进行动态设置clips参数
|
//@TODO 后期需要通过模板参数进行动态设置clips参数
|
||||||
|
|
||||||
clips.put("1", fileCenterService.getViewUrlByPath(videoFiles.get(4).getFilePath()));
|
// 保持既有模板顺序;当索引越界或无素材时返回空URL
|
||||||
clips.put("2", fileCenterService.getViewUrlByPath(videoFiles.get(5).getFilePath()));
|
clips.put("1", getUrlBySafeIndex(videoFiles, 4));
|
||||||
clips.put("3", fileCenterService.getViewUrlByPath(videoFiles.get(6).getFilePath()));
|
clips.put("2", getUrlBySafeIndex(videoFiles, 5));
|
||||||
clips.put("4", fileCenterService.getViewUrlByPath(videoFiles.get(0).getFilePath()));
|
clips.put("3", getUrlBySafeIndex(videoFiles, 6));
|
||||||
clips.put("5", fileCenterService.getViewUrlByPath(videoFiles.get(1).getFilePath()));
|
clips.put("4", getUrlBySafeIndex(videoFiles, 0));
|
||||||
clips.put("6", fileCenterService.getViewUrlByPath(videoFiles.get(2).getFilePath()));
|
clips.put("5", getUrlBySafeIndex(videoFiles, 1));
|
||||||
clips.put("7", fileCenterService.getViewUrlByPath(videoFiles.get(3).getFilePath()));
|
clips.put("6", getUrlBySafeIndex(videoFiles, 2));
|
||||||
|
clips.put("7", getUrlBySafeIndex(videoFiles, 3));
|
||||||
|
|
||||||
if (taskData.getVideoFiles().size() > 7) {
|
if (videoFiles != null && videoFiles.size() > 7) {
|
||||||
clips.put("8", fileCenterService.getViewUrlByPath(videoFiles.get(7).getFilePath()));
|
clips.put("8", getUrlBySafeIndex(videoFiles, 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.toJSONString(clips);
|
return JSON.toJSONString(clips);
|
||||||
@@ -206,6 +207,14 @@ public class MediaServiceImpl implements IMediaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getUrlBySafeIndex(List<OrderFile> videoFiles, int index) {
|
||||||
|
int size = (videoFiles == null) ? 0 : videoFiles.size();
|
||||||
|
if (size == 0 || index < 0 || index >= size) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return fileCenterService.getViewUrlByPath(videoFiles.get(index).getFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建输出配置
|
* 构建输出配置
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user