|
|
@ -47,6 +47,10 @@ import java.text.DecimalFormat; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.Future; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -62,7 +66,10 @@ public class DcDeviceController extends BaseController { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private IDcDeviceService dcDeviceService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private VideoController videoController; |
|
|
|
private static final int THREAD_POOL_SIZE = 100; // 线程池大小
|
|
|
|
private ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE); |
|
|
|
/* |
|
|
|
@Value("${iot.address}") |
|
|
|
private String iotAddress; |
|
|
@ -858,10 +865,43 @@ public class DcDeviceController extends BaseController { |
|
|
|
@PostMapping("/batchFunctions") |
|
|
|
@OperationLog(operUrl = "/business/device/batchFunctions") |
|
|
|
//public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props,int operType) throws HttpException, IOException, InterruptedException { todo
|
|
|
|
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException { |
|
|
|
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException, ExecutionException { |
|
|
|
ArrayList<JSONObject> devices = (ArrayList<JSONObject>) props.get("devices"); |
|
|
|
ArrayList<JSONObject> functions = (ArrayList<JSONObject>) props.get("functions"); |
|
|
|
JSONArray resultArray = new JSONArray(); |
|
|
|
|
|
|
|
JSONObject videoCamera = (JSONObject) JSON.toJSON(functions.get(0)); |
|
|
|
String videoCameraID = videoCamera.getString("functionId"); |
|
|
|
|
|
|
|
if (videoCameraID.equals("videoCamera")) { |
|
|
|
String cmdType = videoCamera.getString("cmdType"); |
|
|
|
|
|
|
|
List<Future<JSONObject>> futures = new ArrayList<>(); |
|
|
|
for (Object dev : devices) { |
|
|
|
JSONObject device = (JSONObject) JSON.toJSON(dev); |
|
|
|
String iotDeviceId = device.getString("iotDeviceId"); |
|
|
|
|
|
|
|
Future<JSONObject> future = executorService.submit(() -> { |
|
|
|
try { |
|
|
|
JSONObject responseJson = videoController.PTZControl(iotDeviceId, cmdType, "1"); |
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
result.put("device", device.getString("id")); |
|
|
|
result.put("deviceType", device.getInteger("deviceType")); |
|
|
|
result.put("functionId", cmdType); |
|
|
|
result.put("result", responseJson); |
|
|
|
return result; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
}); |
|
|
|
futures.add(future); |
|
|
|
} |
|
|
|
for (Future<JSONObject> future : futures) { |
|
|
|
JSONObject result = future.get(); // 获取结果,可能会抛出异常
|
|
|
|
resultArray.add(result); |
|
|
|
} |
|
|
|
return AjaxResult.success(resultArray); |
|
|
|
} |
|
|
|
for (Object dev : devices) { |
|
|
|
// 将Object转换为JSONObject
|
|
|
|
JSONObject device = (JSONObject) JSON.toJSON(dev); |
|
|
@ -1181,7 +1221,7 @@ public class DcDeviceController extends BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
@OperationLog(operUrl = "/business/device/batchFunctions") |
|
|
|
public AjaxResult batchInvokedFunction(Object object) throws HttpException, IOException, InterruptedException { |
|
|
|
public AjaxResult batchInvokedFunction(Object object) throws HttpException, IOException, InterruptedException, ExecutionException { |
|
|
|
//public AjaxResult batchInvokedFunction(Object object,int operType) throws HttpException, IOException, InterruptedException { todo
|
|
|
|
Map<String, Object> map = new ObjectMapper().convertValue(object, Map.class); |
|
|
|
return batchInvokedFunction(map); |
|
|
|