From df5e94886a8842e8700f4ad14978242798d24500 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Wed, 10 Sep 2025 09:13:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(=E8=AE=A2=E5=8D=95=E4=B8=AD=E5=BF=83)?= =?UTF-8?q?=EF=BC=9A=E4=B8=80=E9=94=AE=E6=88=90=E7=89=87=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=85=BC=E5=AE=B9=E7=B4=A0=E6=9D=90?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E4=B8=BA4=E4=B8=AA=E7=9A=84=E8=AE=A2?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third-party-aerial-photography-flow.md | 74 +++++++++++++++++++ .../order/service/impl/MediaServiceImpl.java | 29 +++++--- 2 files changed, 93 insertions(+), 10 deletions(-) diff --git a/third-party-aerial-photography-flow.md b/third-party-aerial-photography-flow.md index b8c5e71c..65cb1c2e 100644 --- a/third-party-aerial-photography-flow.md +++ b/third-party-aerial-photography-flow.md @@ -137,6 +137,80 @@ stateDiagram-v2 ### 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 **接口地址:** `POST /api-device/execute/task` diff --git a/zlt-business/order-center/src/main/java/com/central/order/service/impl/MediaServiceImpl.java b/zlt-business/order-center/src/main/java/com/central/order/service/impl/MediaServiceImpl.java index fb4b50ca..393c3e9d 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/service/impl/MediaServiceImpl.java +++ b/zlt-business/order-center/src/main/java/com/central/order/service/impl/MediaServiceImpl.java @@ -131,7 +131,7 @@ public class MediaServiceImpl implements IMediaService { // 3. 获取视频文件 // List videoFiles = orderFileService.getOrderVideoFiles(orderNo); - if (orderFiles == null || orderFiles.size() < 7) { + if (orderFiles == null || orderFiles.size() < qrCode.getMaterialCount()) { throw new BusinessException("订单视频文件数量不足,至少需要2个视频文件"); } @@ -188,16 +188,17 @@ public class MediaServiceImpl implements IMediaService { List videoFiles = taskData.getVideoFiles(); //@TODO 后期需要通过模板参数进行动态设置clips参数 - clips.put("1", fileCenterService.getViewUrlByPath(videoFiles.get(4).getFilePath())); - clips.put("2", fileCenterService.getViewUrlByPath(videoFiles.get(5).getFilePath())); - clips.put("3", fileCenterService.getViewUrlByPath(videoFiles.get(6).getFilePath())); - clips.put("4", fileCenterService.getViewUrlByPath(videoFiles.get(0).getFilePath())); - clips.put("5", fileCenterService.getViewUrlByPath(videoFiles.get(1).getFilePath())); - clips.put("6", fileCenterService.getViewUrlByPath(videoFiles.get(2).getFilePath())); - clips.put("7", fileCenterService.getViewUrlByPath(videoFiles.get(3).getFilePath())); + // 保持既有模板顺序;当索引越界或无素材时返回空URL + clips.put("1", getUrlBySafeIndex(videoFiles, 4)); + clips.put("2", getUrlBySafeIndex(videoFiles, 5)); + clips.put("3", getUrlBySafeIndex(videoFiles, 6)); + clips.put("4", getUrlBySafeIndex(videoFiles, 0)); + clips.put("5", getUrlBySafeIndex(videoFiles, 1)); + clips.put("6", getUrlBySafeIndex(videoFiles, 2)); + clips.put("7", getUrlBySafeIndex(videoFiles, 3)); - if (taskData.getVideoFiles().size() > 7) { - clips.put("8", fileCenterService.getViewUrlByPath(videoFiles.get(7).getFilePath())); + if (videoFiles != null && videoFiles.size() > 7) { + clips.put("8", getUrlBySafeIndex(videoFiles, 7)); } return JSON.toJSONString(clips); @@ -206,6 +207,14 @@ public class MediaServiceImpl implements IMediaService { } } + private String getUrlBySafeIndex(List 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()); + } + /** * 构建输出配置 */ From 9ca13415ee06ae0121da87c714300ac9dffb9071 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Sat, 27 Sep 2025 12:03:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(=E8=AE=BE=E5=A4=87=E4=B8=AD=E5=BF=83)?= =?UTF-8?q?=EF=BC=9A=E5=A2=9E=E5=8A=A0=E8=AE=BE=E5=A4=87=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3=E5=B9=82=E7=AD=89=E6=80=A7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/central/device/controller/ApiDeviceController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java b/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java index 8e7d1d70..d668e9c6 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java +++ b/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java @@ -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.JsonObject; import com.central.common.model.Result; +import com.central.common.lock.Lock; import com.central.device.feign.OrderCenterService; import com.central.device.message.ControlEnum; import com.central.device.message.ControlMessageConstant; @@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * 设备操作controller @@ -76,6 +78,8 @@ public class ApiDeviceController { */ @Operation(summary = "设备属性设置") @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 param, @PathVariable("deviceId") String deviceId) { log.info("开始设置设备属性: deviceId={}, param={}", deviceId, param); try {