|
|
@@ -1,5 +1,6 @@
|
|
|
package com.yunfeiyun.agmp.iots.device.serviceImp;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.common.constant.ResConstants;
|
|
|
import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
|
|
|
@@ -7,6 +8,7 @@ import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
|
import com.yunfeiyun.agmp.common.framework.manager.ResManager;
|
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.uuid.UUID;
|
|
|
+
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.IotEnumOnlineStatus;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
@@ -29,11 +31,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.lang.reflect.Method;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@@ -64,7 +65,7 @@ public class IHikVisionEzvizDeviceImpl extends HttpDeviceAbstractImpl implements
|
|
|
CmdModel.Cmd cmdDistribution = cmdModel.getCmdDistribution();
|
|
|
// 获取执行的方法 ,方法可以通过反射获取执行,也可以临时case 匹配
|
|
|
String methodName = cmdDistribution.getFunc();
|
|
|
- Method method = this.getClass().getDeclaredMethod(methodName,JSONObject.class,IotDevice.class);
|
|
|
+ Method method = this.getClass().getDeclaredMethod(methodName,JSONObject.class, IotDevice.class);
|
|
|
Object result = method.invoke(this,cmdDistribution.getJsons(),cmdModel.getIotDevice());
|
|
|
JSONObject resultObject = JSONObject.from(result);
|
|
|
log.info("【海康萤石云平台监控】指令发送结果:{}",resultObject);
|
|
|
@@ -111,7 +112,6 @@ public class IHikVisionEzvizDeviceImpl extends HttpDeviceAbstractImpl implements
|
|
|
JSONObject dataObject = JSONObject.from(data);
|
|
|
String picUrl = dataObject.getString("picUrl");
|
|
|
String devCode = param.getString("deviceSerial")+"-"+param.getString("channelNo");
|
|
|
- iotDevice = iotDeviceService.selectDeviceByDeviceServiceNameAndDevCode(ServiceNameConst.SERVICE_EZVIZ_MINITOR,devCode);
|
|
|
IotMonitorCapture iotMonitorCapture = new IotMonitorCapture();
|
|
|
iotMonitorCapture.setDevBid(iotDevice.getDevBid());
|
|
|
iotMonitorCapture.setPicBid(iotMonitorCapture.getUUId());
|
|
|
@@ -139,26 +139,41 @@ public class IHikVisionEzvizDeviceImpl extends HttpDeviceAbstractImpl implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject refreshStatus(JSONObject param,IotDevice iotDevice){
|
|
|
- log.info("【海康萤石云平台监控】设备检测设备在线状态,devCode={}",iotDevice.getDevCode());
|
|
|
- param = new JSONObject();
|
|
|
- String[] devCodeArray = iotDevice.getDevCode().split("-");
|
|
|
- param.put("deviceSerial",devCodeArray[0]);
|
|
|
- param.put("channelNo",devCodeArray[1]);
|
|
|
- JSONObject refreshStatus = (JSONObject) ezvizHttpClient(iotDevice).getExchange(EzvizApi.STATUS,param,JSONObject.class);
|
|
|
- if(refreshStatus.get("status").equals(1)) {
|
|
|
- iotDevice.setDevStatus(IotEnumOnlineStatus.ONLINE.getStatus());
|
|
|
- iotDeviceService.updateIotDevice(iotDevice);
|
|
|
- log.info("【海康萤石云平台监控】检测设备在线状态,结果:在线,devCode={}",iotDevice.getDevCode());
|
|
|
- redisCacheManager.setCacheObject(RedisCacheKey.IOT_DEVICE_STATUS,iotDevice.getDevBid(),"1",1, TimeUnit.HOURS);
|
|
|
- return refreshStatus;
|
|
|
+ public JSONObject refreshStatus(IotDevice iotDevice,List<IotDevice> childDeviceList){
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("deviceSerial", iotDevice.getDevCode());
|
|
|
+ JSONObject refreshResult = (JSONObject) ezvizHttpClient(iotDevice).postExchange(EzvizApi.STATUS, param, JSONObject.class);
|
|
|
+ if (String.valueOf(HttpStatus.OK.value()).equals(refreshResult.get("code"))) {
|
|
|
+ JSONArray result = refreshResult.getJSONArray("data");
|
|
|
+ if (null != result) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ for (Object resultItemObj : result) {
|
|
|
+ JSONObject resultItem = JSONObject.from(resultItemObj);
|
|
|
+ String status = resultItem.getString("status");
|
|
|
+ String deviceSerial = resultItem.getString("deviceSerial");
|
|
|
+ String channelNo = resultItem.getString("channelNo");
|
|
|
+ map.put(deviceSerial + "-" + channelNo, status);
|
|
|
+ }
|
|
|
+ for (IotDevice childDevice : childDeviceList) {
|
|
|
+ String status = map.get(iotDevice.getDevCode());
|
|
|
+ if (null != status) {
|
|
|
+ log.info("【海康萤石云平台监控】更新设备状态,devCode = {},设备状态:{}",childDevice.getDevCode(), IotEnumOnlineStatus.messageOfCode(childDevice.getDevStatus()));
|
|
|
+ childDevice.setDevStatus(status);
|
|
|
+ } else {
|
|
|
+ log.info("【海康萤石云平台监控】更新设备状态,未查询到设备状态信息,视为设备离线 devCode = {}",childDevice.getDevCode());
|
|
|
+ childDevice.setDevStatus(IotEnumOnlineStatus.OFFLINE.getStatus());
|
|
|
+ }
|
|
|
+ if(IotEnumOnlineStatus.ONLINE.getStatus().equals(childDevice.getDevStatus())){
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_DEVICE_STATUS,childDevice.getDevBid(),"1",1, TimeUnit.HOURS);
|
|
|
+ }else {
|
|
|
+ redisCacheManager.deleteObject(RedisCacheKey.IOT_DEVICE_STATUS,childDevice.getDevBid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ iotDeviceService.updateIotDeviceBatch(childDeviceList);
|
|
|
+ return refreshResult;
|
|
|
+ }
|
|
|
}
|
|
|
- iotDevice.setDevStatus(IotEnumOnlineStatus.OFFLINE.getStatus());
|
|
|
- iotDevice.setDevOfflinedate(DateUtils.dateTimeNow());
|
|
|
- iotDeviceService.updateIotDevice(iotDevice);
|
|
|
- redisCacheManager.deleteObject(RedisCacheKey.IOT_DEVICE_STATUS,iotDevice.getDevBid());
|
|
|
- log.info("【海康萤石云平台监控】检测设备在线状态,结果:离线,devCode={}",iotDevice.getDevCode());
|
|
|
- return refreshStatus;
|
|
|
+ return refreshResult;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -166,11 +181,17 @@ public class IHikVisionEzvizDeviceImpl extends HttpDeviceAbstractImpl implements
|
|
|
try {
|
|
|
log.info("海康设备定时检测设备在线状态开始");
|
|
|
List<CompletableFuture<JSONObject>> completableFutureList = new LinkedList<>();
|
|
|
+ // 此处若后续数据较多时,可按租户分批处理
|
|
|
List<IotDevice> iotDeviceList = iotDeviceService.selectAllDeviceByDeviceServiceName(ServiceNameConst.SERVICE_EZVIZ_MINITOR);
|
|
|
- for(IotDevice iotDevice : iotDeviceList){
|
|
|
+ Map<String,List<IotDevice>> map = iotDeviceList.stream().collect(Collectors.groupingBy(item->item.getDevCode().split("-")[0]));
|
|
|
+ for(Map.Entry<String,List<IotDevice>> entry:map.entrySet()){
|
|
|
CompletableFuture<JSONObject> generateGraphics = CompletableFuture.supplyAsync(() -> {
|
|
|
try {
|
|
|
- return this.refreshStatus(null,iotDevice);
|
|
|
+ IotDevice iotDevice = new IotDevice();
|
|
|
+ iotDevice.setDevCode(entry.getKey());
|
|
|
+ iotDevice.setDevtypeBid(entry.getValue().get(0).getDevtypeBid());
|
|
|
+ iotDevice.setDevconnBid(entry.getValue().get(0).getDevconnBid());
|
|
|
+ return this.refreshStatus(iotDevice,entry.getValue());
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|