Browse Source

摄像机雨刷

develop
王兴琳 4 months ago
parent
commit
4ff2451f98
  1. 46
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 10
      zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java
  3. 5
      zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java
  4. 3
      zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java

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

10
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("雨刷开启");
}
}

5
zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java

@ -498,11 +498,16 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
List<String> startStakeMarks = castList(parameter.get("startStakeMark"), String.class);
List<String> 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));
}

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

Loading…
Cancel
Save