|
|
@@ -9,10 +9,7 @@ import com.xunmei.common.core.domain.iot.domain.*;
|
|
|
import com.xunmei.common.core.utils.IDHelper;
|
|
|
import com.xunmei.host.iot.dto.IotDeviceDiagnoseMissionReq;
|
|
|
import com.xunmei.host.iot.dto.IotDeviceDiagnoseThresholdReq;
|
|
|
-import com.xunmei.host.iot.mapper.IotDeviceDiagnoseMissionChMapper;
|
|
|
-import com.xunmei.host.iot.mapper.IotDeviceDiagnoseMissionMapper;
|
|
|
-import com.xunmei.host.iot.mapper.IotDeviceDiagnoseThresholdChMapper;
|
|
|
-import com.xunmei.host.iot.mapper.IotDeviceDiagnoseThresholdMapper;
|
|
|
+import com.xunmei.host.iot.mapper.*;
|
|
|
import com.xunmei.host.iot.service.IotCameraMissionRuleService;
|
|
|
import com.xunmei.host.north.service.IotWebsocketMsgService;
|
|
|
import com.xunmei.host.websocket.constant.WebSocketConstants;
|
|
|
@@ -22,6 +19,7 @@ import com.xunmei.host.websocket.enums.ProductEnums;
|
|
|
import com.xunmei.host.websocket.enums.TopicTypeEnums;
|
|
|
import com.xunmei.host.websocket.service.RouterService;
|
|
|
import com.xunmei.host.websocket.service.WebsocketService;
|
|
|
+import com.xunmei.system.api.domain.iot.IotDeviceInfo;
|
|
|
import com.xunmei.system.api.util.LogUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -45,6 +43,9 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
private IotDeviceDiagnoseThresholdMapper thresholdMapper;
|
|
|
@Autowired
|
|
|
private IotDeviceDiagnoseThresholdChMapper thresholdChMapper;
|
|
|
+ @Autowired
|
|
|
+ private IotDeviceInfoMapper iotDeviceInfoMapper;
|
|
|
+
|
|
|
//下发消息使用
|
|
|
@Resource
|
|
|
private WebsocketService websocketService;
|
|
|
@@ -74,16 +75,17 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
|
|
|
private JSONObject receiveAndUpdateMissionCamera(WebsocketExecuteReq req) {
|
|
|
try {
|
|
|
- Set<String> iotCodes = Sets.newHashSet();
|
|
|
- String limitOne = "limit 1";
|
|
|
-
|
|
|
- final Object data = req.getData();
|
|
|
final String iotToken = req.getServerInfo().getIotCode();
|
|
|
- final JSONObject jsb = JSON.parseObject(data.toString(), JSONObject.class);
|
|
|
+ final JSONObject param = JSON.parseObject(req.getData().toString(), JSONObject.class);
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:iotToken={}开始执行",iotToken);
|
|
|
|
|
|
+ Set<String> iotCodes = Sets.newHashSet();
|
|
|
+ String deviceProduct,dvs,channel;
|
|
|
+ QueryWrapper<IotDeviceInfo> equWrapper;
|
|
|
+ String limitOne = "limit 1";
|
|
|
|
|
|
- final List<IotDeviceDiagnoseMissionReq> missions = JSON.parseArray(jsb.getString("missions"),IotDeviceDiagnoseMissionReq.class);
|
|
|
- final List<IotDeviceDiagnoseThresholdReq> thresholds = JSON.parseArray(jsb.getString("thresholds"),IotDeviceDiagnoseThresholdReq.class);
|
|
|
+ final List<IotDeviceDiagnoseMissionReq> missions = JSON.parseArray(param.getString("missions"),IotDeviceDiagnoseMissionReq.class);
|
|
|
+ final List<IotDeviceDiagnoseThresholdReq> thresholds = JSON.parseArray(param.getString("thresholds"),IotDeviceDiagnoseThresholdReq.class);
|
|
|
|
|
|
for(IotDeviceDiagnoseMissionReq missionReq: missions){
|
|
|
String missionId = missionReq.getMissionId();
|
|
|
@@ -107,7 +109,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
if(similarBean != null){
|
|
|
missionId = similarBean.getMissionId();
|
|
|
//todo:
|
|
|
- LogUtils.STATUS_INFO_STATUS_SENSOR.info("治理的主机missionId={}",missionReq.getMissionId());
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:治理的主机iotToken={},missionId={}",iotToken,missionReq.getMissionId());
|
|
|
iotCodes.add(iotToken);
|
|
|
}else{//未匹配到missionId,且名称或规则不一样
|
|
|
missionId = IDHelper.id().toString();
|
|
|
@@ -122,11 +124,24 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
List<IotDeviceDiagnoseMissionCh> chns = missionReq.getChns();
|
|
|
if(chns != null && !chns.isEmpty()){
|
|
|
for(IotDeviceDiagnoseMissionCh missionCh:chns){
|
|
|
+ deviceProduct = missionCh.getDeviceProduct();
|
|
|
+ dvs = missionCh.getDvs();
|
|
|
+ channel = missionCh.getChannel();
|
|
|
+ //查询设备主键id
|
|
|
+ equWrapper = new QueryWrapper<>();
|
|
|
+ equWrapper.eq("iot_token",iotToken).eq("device_product",deviceProduct)
|
|
|
+ .eq("host_code",dvs).eq("device_code",channel).eq("deleted",0);
|
|
|
+ equWrapper.last(limitOne);
|
|
|
+ IotDeviceInfo camera=iotDeviceInfoMapper.selectOne(equWrapper);
|
|
|
+ if(camera == null){
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.error("主机上传诊断绑定:dvs={},channel={},未找到有效的摄像机基础信息(IotDeviceInfo)",dvs,channel);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long deviceId = camera.getId();
|
|
|
+
|
|
|
QueryWrapper<IotDeviceDiagnoseMissionCh> wrapperCh = new QueryWrapper<>();
|
|
|
- wrapperCh.eq("iot_token", iotToken);
|
|
|
- wrapperCh.eq("device_product", missionCh.getDeviceProduct());
|
|
|
- wrapperCh.eq("dvs", missionCh.getDvs());
|
|
|
- wrapperCh.eq("channel", missionCh.getChannel());
|
|
|
+ wrapperCh.eq("iot_token", iotToken).eq("device_product", deviceProduct)
|
|
|
+ .eq("dvs", dvs).eq("channel", channel);
|
|
|
wrapperCh.last(limitOne);
|
|
|
IotDeviceDiagnoseMissionCh beanCh = missionChMapper.selectOne(wrapperCh);
|
|
|
|
|
|
@@ -139,6 +154,11 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
missionChMapper.update(missionCh,wrapperCh);
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ //本主机无摄像机绑定,删除关联
|
|
|
+ QueryWrapper<IotDeviceDiagnoseMissionCh> wrapperCh = new QueryWrapper<>();
|
|
|
+ wrapperCh.eq("iot_token", iotToken);
|
|
|
+ missionChMapper.delete(wrapperCh);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -147,10 +167,8 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
if(thresholdId != 1){//非-系统默认阈值
|
|
|
QueryWrapper<IotDeviceDiagnoseThreshold> wrapper = new QueryWrapper<>();
|
|
|
wrapper.eq("threshold_code", thresholdReq.getThresholdCode());
|
|
|
-// if(StringUtils.isNotEmpty(thresholdReq.getIotToken())) {
|
|
|
-// wrapper.eq("iot_token", thresholdReq.getIotToken());
|
|
|
-// }
|
|
|
wrapper.last(limitOne);
|
|
|
+
|
|
|
IotDeviceDiagnoseThreshold bean = thresholdMapper.selectOne(wrapper);
|
|
|
if (bean == null) {
|
|
|
//新增时,使用平台生成的id,然后下发到主机统一治理
|
|
|
@@ -164,7 +182,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
if(!thresholdReq.getThresholdName().equals(bean.getThresholdName())){//规则一样,但名称不一样,治理该主机的诊断阈值(添加下发该主机IotToken同步)
|
|
|
thresholdReq.setThresholdName(bean.getThresholdName());
|
|
|
//todo:
|
|
|
- LogUtils.STATUS_INFO_STATUS_SENSOR.info("治理的主机thresholdCode={}",thresholdReq.getThresholdCode());
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定:治理的主机iotToken={},thresholdCode={}",iotToken,thresholdReq.getThresholdCode());
|
|
|
iotCodes.add(iotToken);
|
|
|
}
|
|
|
thresholdMapper.updateById(thresholdReq);
|
|
|
@@ -175,11 +193,24 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
List<IotDeviceDiagnoseThresholdCh> chns = thresholdReq.getChns();
|
|
|
if(chns != null && !chns.isEmpty()){
|
|
|
for(IotDeviceDiagnoseThresholdCh thresholdCh:chns){
|
|
|
+ deviceProduct = thresholdCh.getDeviceProduct();
|
|
|
+ dvs = thresholdCh.getDvs();
|
|
|
+ channel = thresholdCh.getChannel();
|
|
|
+ //查询设备主键id
|
|
|
+ equWrapper = new QueryWrapper<>();
|
|
|
+ equWrapper.eq("iot_token",iotToken).eq("device_product",deviceProduct)
|
|
|
+ .eq("host_code",dvs).eq("device_code",channel).eq("deleted",0);
|
|
|
+ equWrapper.last(limitOne);
|
|
|
+ IotDeviceInfo camera=iotDeviceInfoMapper.selectOne(equWrapper);
|
|
|
+ if(camera == null){
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.error("主机上传诊断绑定:dvs={},channel={},未找到有效的摄像机基础信息(IotDeviceInfo)",dvs,channel);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long deviceId = camera.getId();
|
|
|
+
|
|
|
QueryWrapper<IotDeviceDiagnoseThresholdCh> wrapperCh = new QueryWrapper<>();
|
|
|
- wrapperCh.eq("iot_token", iotToken);
|
|
|
- wrapperCh.eq("device_product", thresholdCh.getDeviceProduct());
|
|
|
- wrapperCh.eq("dvs", thresholdCh.getDvs());
|
|
|
- wrapperCh.eq("channel", thresholdCh.getChannel());
|
|
|
+ wrapperCh.eq("iot_token", iotToken).eq("device_product", deviceProduct)
|
|
|
+ .eq("dvs", dvs).eq("channel", channel).eq("threshold_code",thresholdCh.getThresholdCode());
|
|
|
wrapperCh.last(limitOne);
|
|
|
IotDeviceDiagnoseThresholdCh beanCh = thresholdChMapper.selectOne(wrapperCh);
|
|
|
if(beanCh == null){
|
|
|
@@ -189,6 +220,11 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
thresholdChMapper.update(thresholdCh,wrapperCh);
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ //本主机无摄像机绑定,删除关联
|
|
|
+ QueryWrapper<IotDeviceDiagnoseThresholdCh> wrapperCh = new QueryWrapper<>();
|
|
|
+ wrapperCh.eq("iot_token", iotToken);
|
|
|
+ thresholdChMapper.delete(wrapperCh);
|
|
|
}
|
|
|
//更新绑定通道数量
|
|
|
missionChMapper.updateDiagnoseNumber(thresholdReq.getThresholdCode());
|
|
|
@@ -198,7 +234,7 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
this.syncDiagnoseToHost(new ArrayList<>(iotCodes));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- LogUtils.STATUS_INFO_STATUS_SENSOR.info("诊断绑定摄像机: 处理出现异常{}", e);
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("主机上传诊断绑定: 处理出现异常{}", e);
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
return WebsocketResult.getSuccessPayload();
|
|
|
@@ -210,8 +246,19 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
List<IotDeviceDiagnoseMissionReq> missions = missionChMapper.selectMissions();
|
|
|
List<IotDeviceDiagnoseMissionCh> missionChns;
|
|
|
List<String> subIotCodes;
|
|
|
+ QueryWrapper<IotDeviceInfo> equWrapper;
|
|
|
|
|
|
for(String iotCode:iotCodes) {
|
|
|
+ equWrapper = new QueryWrapper<>();
|
|
|
+ equWrapper.eq("iot_token",iotCode).eq("deleted",0);
|
|
|
+ equWrapper.and(on -> on.eq("device_type", 2).or().eq("device_type",3));
|
|
|
+ long camera=iotDeviceInfoMapper.selectCount(equWrapper);
|
|
|
+
|
|
|
+ if(camera <= 0){
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("平台下发诊断绑定:iotToken={},未找到有效的摄像机基础信息(IotDeviceInfo)",iotCode);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
subIotCodes = Lists.newArrayList();
|
|
|
subIotCodes.add(iotCode);
|
|
|
for (IotDeviceDiagnoseMissionReq mission : missions) {
|
|
|
@@ -239,10 +286,16 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
|
|
|
final String topic = TopicTypeEnums.formatUrl(TopicTypeEnums.PRODUCT_SERVICE_INVOKE.getUrl(), ProductEnums.DETECTION_HOST.getProductName().get(0), ProductEnums.DETECTION_HOST.getProductName().get(1));
|
|
|
final WebsocketResult result = WebsocketResult.invokeHostServer(topic, new com.alibaba.fastjson.JSONObject(), WebSocketConstants.CAMERA_DIAGNOSE_TO_HOST, param);
|
|
|
-
|
|
|
-
|
|
|
- final IotWebsocketMsg saveMsg = websocketMsgService.proactiveSendAndSaveMsg(iotCode, result);
|
|
|
- websocketService.sendMsgByTokens(saveMsg, iotCode);
|
|
|
+ IotWebsocketMsg saveMsg = null;
|
|
|
+ try {
|
|
|
+ saveMsg = websocketMsgService.proactiveSendAndSaveMsg(iotCode, result);
|
|
|
+ }catch (Exception e){
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("平台下发诊断绑定: iotToken={},处理出现异常{}",iotCode, e);
|
|
|
+ }
|
|
|
+ if(saveMsg != null) {
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("平台下发诊断绑定: iotToken={}",iotCode);
|
|
|
+ websocketService.sendMsgByTokens(saveMsg, iotCode);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|