|
@ -447,27 +447,31 @@ public class DcDeviceController extends BaseController { |
|
|
@ApiOperation("批量设备功能调用") |
|
|
@ApiOperation("批量设备功能调用") |
|
|
@PostMapping("/batchFunctions") |
|
|
@PostMapping("/batchFunctions") |
|
|
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException { |
|
|
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException { |
|
|
List<DcDevice> devices = (List<DcDevice>) props.get("devices"); |
|
|
ArrayList<JSONObject> devices = (ArrayList<JSONObject>) props.get("devices"); |
|
|
JSONArray functions = (JSONArray) props.get("functions"); |
|
|
ArrayList<JSONObject> functions = (ArrayList<JSONObject>) props.get("functions"); |
|
|
JSONArray resultArray = new JSONArray(); |
|
|
JSONArray resultArray = new JSONArray(); |
|
|
for (DcDevice device : devices) { |
|
|
for (Object dev : devices) { |
|
|
String iotDeviceId = device.getIotDeviceId(); |
|
|
// 将Object转换为JSONObject
|
|
|
|
|
|
JSONObject device = (JSONObject) JSON.toJSON(dev); |
|
|
|
|
|
//JSONObject device = (JSONObject) JSON.toJSON(dev.toString());
|
|
|
|
|
|
String iotDeviceId = device.getString("iotDeviceId"); |
|
|
for (Object function : functions) { |
|
|
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"); |
|
|
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)); |
|
|
resultArray.add(getResult(device, iotDeviceId, functionId, jsonObject)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return AjaxResult.success(resultArray); |
|
|
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<String, Object> params = jsonObject.toJavaObject(new TypeReference<HashMap<String, Object>>() { |
|
|
HashMap<String, Object> params = jsonObject.toJavaObject(new TypeReference<HashMap<String, Object>>() { |
|
|
}); |
|
|
}); |
|
|
JSONObject result = new JSONObject(); |
|
|
JSONObject result = new JSONObject(); |
|
|
result.put("device", device.getId()); |
|
|
result.put("device", device.getString("id")); |
|
|
if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { |
|
|
if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { |
|
|
result.put("result", broadcastController.nearCamListDistance(jsonObject)); |
|
|
result.put("result", broadcastController.nearCamListDistance(jsonObject)); |
|
|
} else { |
|
|
} else { |
|
|
result.put("result", invokedFunction(iotDeviceId, functionId, params)); |
|
|
result.put("result", invokedFunction(iotDeviceId, functionId, params)); |
|
|