From 2ccc3823b79a0639944e428dc9dec35a79b2ca92 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Tue, 2 Apr 2024 18:26:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=93=8D=E4=BD=9C=E5=8A=9F=E8=83=BD=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 452e8407..1cee37f7 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -447,27 +447,31 @@ public class DcDeviceController extends BaseController { @ApiOperation("批量设备功能调用") @PostMapping("/batchFunctions") public AjaxResult batchInvokedFunction(@RequestBody Map props) throws HttpException, IOException, InterruptedException { - List devices = (List) props.get("devices"); - JSONArray functions = (JSONArray) props.get("functions"); + ArrayList devices = (ArrayList) props.get("devices"); + ArrayList functions = (ArrayList) props.get("functions"); JSONArray resultArray = new JSONArray(); - for (DcDevice device : devices) { - String iotDeviceId = device.getIotDeviceId(); + for (Object dev : devices) { + // 将Object转换为JSONObject + JSONObject device = (JSONObject) JSON.toJSON(dev); + //JSONObject device = (JSONObject) JSON.toJSON(dev.toString()); + String iotDeviceId = device.getString("iotDeviceId"); for (Object function : functions) { - JSONObject functionJSONObject = JSONObject.parseObject(String.valueOf(function)); + JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); + //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; String functionId = functionJSONObject.getString("functionId"); - JSONObject jsonObject = functionJSONObject.getJSONObject("params"); + JSONObject jsonObject = functionJSONObject.getJSONObject("params") == null?functionJSONObject.getJSONObject("params"):new JSONObject(); resultArray.add(getResult(device, iotDeviceId, functionId, jsonObject)); } } return AjaxResult.success(resultArray); } - private JSONObject getResult(DcDevice device, String iotDeviceId, String functionId, JSONObject jsonObject) throws HttpException, IOException { + private JSONObject getResult(JSONObject device, String iotDeviceId, String functionId, JSONObject jsonObject) throws HttpException, IOException { HashMap params = jsonObject.toJavaObject(new TypeReference>() { }); JSONObject result = new JSONObject(); - result.put("device", device.getId()); - if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { + result.put("device", device.getString("id")); + if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { result.put("result", broadcastController.nearCamListDistance(jsonObject)); } else { result.put("result", invokedFunction(iotDeviceId, functionId, params));