|
|
@@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import com.xunmei.common.core.domain.iot.domain.*;
|
|
|
import com.xunmei.common.core.utils.IDHelper;
|
|
|
-import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.host.iot.dto.IotDeviceDiagnoseMissionReq;
|
|
|
import com.xunmei.host.iot.dto.IotDeviceDiagnoseThresholdReq;
|
|
|
import com.xunmei.host.iot.mapper.IotDeviceDiagnoseMissionChMapper;
|
|
|
@@ -27,9 +27,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.StringJoiner;
|
|
|
|
|
|
@Service
|
|
|
@@ -72,6 +74,7 @@ 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();
|
|
|
@@ -82,24 +85,41 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
final List<IotDeviceDiagnoseMissionReq> missions = JSON.parseArray(jsb.getString("missions"),IotDeviceDiagnoseMissionReq.class);
|
|
|
final List<IotDeviceDiagnoseThresholdReq> thresholds = JSON.parseArray(jsb.getString("thresholds"),IotDeviceDiagnoseThresholdReq.class);
|
|
|
|
|
|
+ for(IotDeviceDiagnoseMissionReq missionReq: missions){
|
|
|
+ String missionId = missionReq.getMissionId();
|
|
|
+ if(!missionId.equals("5ed19826-dd47-421e-a632-b00ba9271c45")){//非-系统默认任务
|
|
|
+
|
|
|
+ QueryWrapper<IotDeviceDiagnoseMission> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("mission_id", missionId);
|
|
|
+ wrapper.last(limitOne);
|
|
|
+ IotDeviceDiagnoseMission bean = missionMapper.selectOne(wrapper);
|
|
|
+
|
|
|
+ if(bean != null){//匹配到missionId
|
|
|
+ missionMapper.updateById(missionReq);
|
|
|
+ }else{//未匹配到missionId
|
|
|
+ wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.and(on -> on.eq("begin_time", missionReq.getBeginTime()).eq("end_time", missionReq.getEndTime()).eq("cycle",missionReq.getCycle())
|
|
|
+ .or().eq("name",missionReq.getName()));
|
|
|
+ wrapper.last(limitOne);
|
|
|
+
|
|
|
+ IotDeviceDiagnoseMission similarBean = missionMapper.selectOne(wrapper);
|
|
|
+ //名称或者规则一样,治理该主机的诊断任务(不执行插入更新操作,但添加下发该主机IotToken同步)
|
|
|
+ if(similarBean != null){
|
|
|
+ missionId = similarBean.getMissionId();
|
|
|
+ //todo:
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("治理的主机missionId={}",missionReq.getMissionId());
|
|
|
+ iotCodes.add(iotToken);
|
|
|
+ }else{//未匹配到missionId,且名称或规则不一样
|
|
|
+ missionId = IDHelper.id().toString();
|
|
|
+ missionReq.setMissionId(missionId);
|
|
|
+ missionMapper.insert(missionReq);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for(IotDeviceDiagnoseMissionReq mission: missions){
|
|
|
- //入库任务
|
|
|
- QueryWrapper<IotDeviceDiagnoseMission> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("mission_id", mission.getMissionId());
|
|
|
- if(StringUtils.isNotEmpty(mission.getIotToken())) {
|
|
|
- wrapper.eq("iot_token", mission.getIotToken());
|
|
|
- }
|
|
|
- wrapper.last(limitOne);
|
|
|
- IotDeviceDiagnoseMission bean = missionMapper.selectOne(wrapper);
|
|
|
- if (bean == null) {
|
|
|
- missionMapper.insert(mission);
|
|
|
- }else if(bean.getMissionId().equals("5ed19826-dd47-421e-a632-b00ba9271c45")){//系统默认任务
|
|
|
- }else{
|
|
|
- missionMapper.updateById(mission);
|
|
|
}
|
|
|
|
|
|
- List<IotDeviceDiagnoseMissionCh> chns = mission.getChns();
|
|
|
+
|
|
|
+ List<IotDeviceDiagnoseMissionCh> chns = missionReq.getChns();
|
|
|
if(chns != null && !chns.isEmpty()){
|
|
|
for(IotDeviceDiagnoseMissionCh missionCh:chns){
|
|
|
QueryWrapper<IotDeviceDiagnoseMissionCh> wrapperCh = new QueryWrapper<>();
|
|
|
@@ -109,6 +129,9 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
wrapperCh.eq("channel", missionCh.getChannel());
|
|
|
wrapperCh.last(limitOne);
|
|
|
IotDeviceDiagnoseMissionCh beanCh = missionChMapper.selectOne(wrapperCh);
|
|
|
+
|
|
|
+ missionCh.setMissionId(missionId);
|
|
|
+
|
|
|
if(beanCh == null){
|
|
|
missionCh.setIotToken(iotToken);
|
|
|
missionChMapper.insert(missionCh);
|
|
|
@@ -119,27 +142,37 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for(IotDeviceDiagnoseThresholdReq threshold: thresholds){
|
|
|
- //入库状态app附表
|
|
|
- QueryWrapper<IotDeviceDiagnoseThreshold> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("threshold_code", threshold.getThresholdCode());
|
|
|
- if(StringUtils.isNotEmpty(threshold.getIotToken())) {
|
|
|
- wrapper.eq("iot_token", threshold.getIotToken());
|
|
|
- }
|
|
|
- wrapper.last(limitOne);
|
|
|
- IotDeviceDiagnoseThreshold bean = thresholdMapper.selectOne(wrapper);
|
|
|
- if (bean == null) {
|
|
|
- //新增时,使用平台生成的id,然后下发到主机统一治理
|
|
|
- threshold.setThresholdId(IDHelper.id());
|
|
|
- threshold.setDiagnoseNumber(0);
|
|
|
- thresholdMapper.insert(threshold);
|
|
|
- }else if(bean.getThresholdId()==1){//系统默认阈值
|
|
|
- }else{
|
|
|
- threshold.setThresholdId(bean.getThresholdId());
|
|
|
- thresholdMapper.updateById(threshold);
|
|
|
+ for(IotDeviceDiagnoseThresholdReq thresholdReq: thresholds){
|
|
|
+ Long thresholdId = thresholdReq.getThresholdId();
|
|
|
+ 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,然后下发到主机统一治理
|
|
|
+ thresholdId = IDHelper.id();
|
|
|
+ thresholdReq.setThresholdId(thresholdId);
|
|
|
+ thresholdReq.setDiagnoseNumber(0);
|
|
|
+ thresholdMapper.insert(thresholdReq);
|
|
|
+ }else{
|
|
|
+ thresholdId = bean.getThresholdId();
|
|
|
+ thresholdReq.setThresholdId(thresholdId);
|
|
|
+ if(!thresholdReq.getThresholdName().equals(bean.getThresholdName())){//规则一样,但名称不一样,治理该主机的诊断阈值(添加下发该主机IotToken同步)
|
|
|
+ thresholdReq.setThresholdName(bean.getThresholdName());
|
|
|
+ //todo:
|
|
|
+ LogUtils.STATUS_INFO_STATUS_SENSOR.info("治理的主机thresholdCode={}",thresholdReq.getThresholdCode());
|
|
|
+ iotCodes.add(iotToken);
|
|
|
+ }
|
|
|
+ thresholdMapper.updateById(thresholdReq);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- List<IotDeviceDiagnoseThresholdCh> chns = threshold.getChns();
|
|
|
+
|
|
|
+ List<IotDeviceDiagnoseThresholdCh> chns = thresholdReq.getChns();
|
|
|
if(chns != null && !chns.isEmpty()){
|
|
|
for(IotDeviceDiagnoseThresholdCh thresholdCh:chns){
|
|
|
QueryWrapper<IotDeviceDiagnoseThresholdCh> wrapperCh = new QueryWrapper<>();
|
|
|
@@ -158,10 +191,12 @@ public class IotCameraMissionRuleServiceImpl implements IotCameraMissionRuleServ
|
|
|
}
|
|
|
}
|
|
|
//更新绑定通道数量
|
|
|
- missionChMapper.updateDiagnoseNumber(threshold.getThresholdCode());
|
|
|
+ missionChMapper.updateDiagnoseNumber(thresholdReq.getThresholdCode());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ if(iotCodes != null && !iotCodes.isEmpty()){
|
|
|
+ this.syncDiagnoseToHost(new ArrayList<>(iotCodes));
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
LogUtils.STATUS_INFO_STATUS_SENSOR.info("诊断绑定摄像机: 处理出现异常{}", e);
|
|
|
throw new RuntimeException(e);
|