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 26939ca5..acc2eb02 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 @@ -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 props,int operType) throws HttpException, IOException, InterruptedException { todo - public AjaxResult batchInvokedFunction(@RequestBody Map props) throws HttpException, IOException, InterruptedException { + public AjaxResult batchInvokedFunction(@RequestBody Map props) throws HttpException, IOException, InterruptedException, ExecutionException { ArrayList devices = (ArrayList) props.get("devices"); ArrayList functions = (ArrayList) 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> futures = new ArrayList<>(); + for (Object dev : devices) { + JSONObject device = (JSONObject) JSON.toJSON(dev); + String iotDeviceId = device.getString("iotDeviceId"); + + Future 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 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 map = new ObjectMapper().convertValue(object, Map.class); return batchInvokedFunction(map); diff --git a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java index 503c56ed..e277dfcc 100644 --- a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java +++ b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java @@ -446,6 +446,16 @@ public class OperationLogAspect { } } + }else if (Objects.equals(deviceType, UniversalEnum.ONE.getValue())) { + JSONObject videoCamera = (JSONObject) JSON.toJSON(functions.get(0)); + String cmdType = videoCamera.getString("cmdType"); + if (cmdType.equals("48")) { + remark.append("雨刷关闭"); + } + if (cmdType.equals("49")) { + remark.append("雨刷开启"); + } + } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java index 3a52d5e0..f61a255a 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java @@ -498,11 +498,16 @@ public class DcDeviceServiceImpl extends ServiceImpl i List startStakeMarks = castList(parameter.get("startStakeMark"), String.class); List endStakeMarks = castList(parameter.get("endStakeMark"), String.class); String deviceType = String.valueOf(parameter.get("deviceType")); + String childType = String.valueOf(parameter.get("childType")); String deviceState = String.valueOf(parameter.get("deviceState")); String direction = String.valueOf(parameter.get("direction")); String useState = String.valueOf(parameter.get("useState")); + String facilitiesType = String.valueOf(parameter.get("facilitiesType")); DcDevice device = new DcDevice(); + if (!Objects.equals(facilitiesType, UniversalEnum.NULL.getValue())) { + device.setFacilitiesType(facilitiesType); + } if (!Objects.equals(useState, UniversalEnum.NULL.getValue())) { device.setUseState(Integer.parseInt(useState)); } diff --git a/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java b/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java index 445df902..aef7ff3c 100644 --- a/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java +++ b/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java @@ -11,6 +11,7 @@ import org.quartz.SchedulerException; import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.concurrent.ExecutionException; /** * 定时任务调度测试 @@ -19,7 +20,7 @@ import java.io.IOException; public class ScheduledTaskSchedulingTask { - public void invokeTarget(DcBatchFunctionsJob dcBatchFunctionsJob) throws HttpException, IOException, InterruptedException, SchedulerException { + public void invokeTarget(DcBatchFunctionsJob dcBatchFunctionsJob) throws HttpException, IOException, InterruptedException, SchedulerException, ExecutionException { DcBatchFunctionsJobServiceImpl dcBatchFunctionsJobService = SpringUtils.getBean(DcBatchFunctionsJobServiceImpl.class); DcDeviceController deviceController = SpringUtils.getBean(DcDeviceController.class);