|
|
@ -447,27 +447,31 @@ public class DcDeviceController extends BaseController { |
|
|
|
@ApiOperation("批量设备功能调用") |
|
|
|
@PostMapping("/batchFunctions") |
|
|
|
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException { |
|
|
|
List<DcDevice> devices = (List<DcDevice>) props.get("devices"); |
|
|
|
JSONArray functions = (JSONArray) props.get("functions"); |
|
|
|
ArrayList<JSONObject> devices = (ArrayList<JSONObject>) props.get("devices"); |
|
|
|
ArrayList<JSONObject> functions = (ArrayList<JSONObject>) 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<String, Object> params = jsonObject.toJavaObject(new TypeReference<HashMap<String, Object>>() { |
|
|
|
}); |
|
|
|
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)); |
|
|
|