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));