|  | @@ -9,10 +9,12 @@ import com.xunmei.common.core.domain.iot.domain.IotDevice;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.iot.domain.IotDvrChannel;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.video.MediatorVideoDiagnosisRecord;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.IDHelper;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.utils.JacksonUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.alarm.service.IotAlarmDataService;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.host.mapper.MediatorCategoryMapper;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.host.service.IIotDeviceService;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.host.service.IIotDvrChannelService;
 | 
	
		
			
				|  |  | +import com.xunmei.mediator.api.server.service.IotServerInfoService;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.video.mapper.VideoDiagnosisRecordMapper;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.video.service.IVideoDiagnosisLogService;
 | 
	
		
			
				|  |  |  import com.xunmei.mediator.api.video.service.IVideoDiagnosisRecordService;
 | 
	
	
		
			
				|  | @@ -29,6 +31,7 @@ import com.xunmei.mediator.websocket.service.RouterService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.util.LogUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
	
		
			
				|  | @@ -65,6 +68,8 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IotAlarmDataService iotAlarmDataService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private IotServerInfoService iotServerInfoService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public ProductEnums product() {
 | 
	
	
		
			
				|  | @@ -82,13 +87,11 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public Object execute(WebsocketExecuteReq obj) {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              String jsonString = JSON.toJSONString(obj.getData());
 | 
	
		
			
				|  |  |              VideoDiagnosisReq req = JSON.parseObject(jsonString, VideoDiagnosisReq.class);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |              VideoDiagnosisDto dto = new VideoDiagnosisDto();
 | 
	
		
			
				|  |  |              dto.setEquipmentCode(req.getDvsCode());
 | 
	
		
			
				|  |  |              dto.setChannelCode(req.getIndex());
 | 
	
	
		
			
				|  | @@ -96,9 +99,11 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |              dto.setImgUrl(req.getImgUrl());
 | 
	
		
			
				|  |  |              dto.setAlarmTime(req.getAlarmTime());
 | 
	
		
			
				|  |  |              dto.setDetailInfo(req.getDetailInfo());
 | 
	
		
			
				|  |  | -            return saveData(dto, "");
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        } catch (IllegalAccessException | ParseException e) {
 | 
	
		
			
				|  |  | +            SysOrg sysOrg = iotServerInfoService.selectOrgByToken(obj.getToken());
 | 
	
		
			
				|  |  | +            dto.setOrganizationGuid(sysOrg.getCode());
 | 
	
		
			
				|  |  | +            return saveData(dto, obj.getId());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            LogUtils.STATUS_INFO_VIDEO_DIAGNOSIS.error(e.getMessage());
 | 
	
		
			
				|  |  |              throw new RuntimeException(e);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -120,7 +125,6 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |          if (error.getSuccess()) {
 | 
	
		
			
				|  |  |              SysOrg org = (SysOrg) map.get("org");
 | 
	
		
			
				|  |  |              IotDvrChannel device = (IotDvrChannel) map.get("device");
 | 
	
		
			
				|  |  | -           // MediatorCategory category = (MediatorCategory) map.get("category");
 | 
	
		
			
				|  |  |              Map<String, Object> objectMap = this.buildEntityDto(videoDiagnosisDto, org, device);
 | 
	
		
			
				|  |  |              this.saveDataInfo(objectMap, videoDiagnosisDto, device);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -129,7 +133,7 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private Map<String, Object> checkVideoDiagnosisDto(VideoDiagnosisDto videoDiagnosisDto) throws IllegalAccessException {
 | 
	
		
			
				|  |  | -        ReceiveErrorDto error = CheckDataUtil.checkObjFieldIsNull(videoDiagnosisDto, null);
 | 
	
		
			
				|  |  | +        ReceiveErrorDto error = CheckDataUtil.checkObjFieldIsNull(videoDiagnosisDto, Arrays.asList("channelName"));
 | 
	
		
			
				|  |  |          Map<String, Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |          if (error.getSuccess()) {
 | 
	
		
			
				|  |  |              if (checkDetailInfo(JSON.toJSONString(videoDiagnosisDto.getDetailInfo()))) {
 | 
	
	
		
			
				|  | @@ -160,29 +164,36 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |                  map.put("error", error);
 | 
	
		
			
				|  |  |                  return map;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            /*MediatorCategory category = categoryMapper.selectById(channel.getCategoryId());
 | 
	
		
			
				|  |  | -            if (ObjectUtil.isNull(category)) {
 | 
	
		
			
				|  |  | -                error.setSuccess(false);
 | 
	
		
			
				|  |  | -                error.setErrorMsg("设备类型不存在");
 | 
	
		
			
				|  |  | -                map.put("error", error);
 | 
	
		
			
				|  |  | -                return map;
 | 
	
		
			
				|  |  | -            }*/
 | 
	
		
			
				|  |  |              map.put("device", channel);
 | 
	
		
			
				|  |  |              map.put("org", org);
 | 
	
		
			
				|  |  | -           // map.put("category", category);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          map.put("error", error);
 | 
	
		
			
				|  |  |          return map;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private List<VideoDiagnosisDetailInfoVo> buildEntityByJson(String detailInfo) {
 | 
	
		
			
				|  |  | +        List<VideoDiagnosisDetailInfoVo> list = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<String> strings = JSON.parseArray(detailInfo, String.class);
 | 
	
		
			
				|  |  | +        for (String string : strings) {
 | 
	
		
			
				|  |  | +            VideoDiagnosisDetailInfoVo parsedObject = JSON.parseObject(string, VideoDiagnosisDetailInfoVo.class);
 | 
	
		
			
				|  |  | +            list.add(parsedObject);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return list;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String buildJson(String detailInfo) {
 | 
	
		
			
				|  |  | +        List<VideoDiagnosisDetailInfoVo> list = buildEntityByJson(detailInfo);
 | 
	
		
			
				|  |  | +        return JacksonUtils.toJSONString(list);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private Boolean checkDetailInfo(String detailInfo) {
 | 
	
		
			
				|  |  | +        List<VideoDiagnosisDetailInfoVo> list = buildEntityByJson(detailInfo);
 | 
	
		
			
				|  |  |          List<Integer> list1 = new ArrayList<>();
 | 
	
		
			
				|  |  |          Collections.addAll(list1, 0, 1, 2, 3, 4, 5, 6, 7);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          List<Integer> list2 = new ArrayList<>();
 | 
	
		
			
				|  |  |          Collections.addAll(list2, 0, 1);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        List<VideoDiagnosisDetailInfoVo> list = JSON.parseArray(detailInfo, VideoDiagnosisDetailInfoVo.class);
 | 
	
		
			
				|  |  |          final List<Integer> typeList = list.stream().map(VideoDiagnosisDetailInfoVo::getType).distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  |          final List<Integer> stateList = list.stream().map(VideoDiagnosisDetailInfoVo::getState).distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  |          final List<Integer> typeDifferentList = getDifferent(typeList, list1);
 | 
	
	
		
			
				|  | @@ -236,7 +247,7 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |          videoDiagnosis.setAlarmTime(videoDiagnosisDto.getAlarmTime());
 | 
	
		
			
				|  |  |          videoDiagnosis.setChannelCode(videoDiagnosisDto.getChannelCode());
 | 
	
		
			
				|  |  |          videoDiagnosis.setChannelName(videoDiagnosisDto.getChannelName());
 | 
	
		
			
				|  |  | -        videoDiagnosis.setDetailInfo(JSON.toJSONString(videoDiagnosisDto.getDetailInfo()));
 | 
	
		
			
				|  |  | +        videoDiagnosis.setDetailInfo(buildJson(JSON.toJSONString(videoDiagnosisDto.getDetailInfo())));
 | 
	
		
			
				|  |  |          videoDiagnosis.setEquipmentCode(videoDiagnosisDto.getEquipmentCode());
 | 
	
		
			
				|  |  |          switch (videoDiagnosisDto.getIsAlarm()) {
 | 
	
		
			
				|  |  |              case 0:
 | 
	
	
		
			
				|  | @@ -252,7 +263,7 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |          videoDiagnosis.setOrgName(org.getShortName());
 | 
	
		
			
				|  |  |          videoDiagnosis.setOrgPath(org.getPath());
 | 
	
		
			
				|  |  |          videoDiagnosis.setImgUrl(videoDiagnosisDto.getImgUrl());
 | 
	
		
			
				|  |  | -        IotDevice hostDevice = iIotDeviceService.findByHostCode(videoDiagnosis.getEquipmentCode(),org.getId());
 | 
	
		
			
				|  |  | +        IotDevice hostDevice = iIotDeviceService.findByHostCode(videoDiagnosis.getEquipmentCode(), org.getId());
 | 
	
		
			
				|  |  |          if (hostDevice != null) {
 | 
	
		
			
				|  |  |              videoDiagnosis.setEquipmentName(hostDevice.getEquipmentName());
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -262,10 +273,11 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |          objectMap.put("videoDiagnosis", videoDiagnosis);
 | 
	
		
			
				|  |  |          return objectMap;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    private void  dealDetailInfo(MediatorVideoDiagnosisRecord record){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void dealDetailInfo(MediatorVideoDiagnosisRecord record) {
 | 
	
		
			
				|  |  |          final String detailInfo = record.getDetailInfo();
 | 
	
		
			
				|  |  |          if (ObjectUtil.isNotNull(detailInfo)) {
 | 
	
		
			
				|  |  | -            final List<VideoDiagnosisDetailInfoVo> list = JSON.parseArray(detailInfo, VideoDiagnosisDetailInfoVo.class);
 | 
	
		
			
				|  |  | +            List<VideoDiagnosisDetailInfoVo> list = buildEntityByJson(detailInfo);
 | 
	
		
			
				|  |  |              if (ObjectUtil.isEmpty(list)) {
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -315,17 +327,9 @@ public class VideoDiagnosisRecordServiceImpl extends ServiceImpl<VideoDiagnosisR
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public void saveDataInfo(Map<String, Object> objectMap, VideoDiagnosisDto videoDiagnosisDto, IotDvrChannel device) {
 | 
	
		
			
				|  |  |          MediatorVideoDiagnosisRecord videoDiagnosis = (MediatorVideoDiagnosisRecord) objectMap.get("videoDiagnosis");
 | 
	
		
			
				|  |  | -       /* List<HostAlarmRecord> alarmRecordsInsert = (List<HostAlarmRecord>) objectMap.get("alarmRecordsInsert");
 | 
	
		
			
				|  |  | -        List<HostAlarmRecord> alarmRecordsUpdate = (List<HostAlarmRecord>) objectMap.get("alarmRecordsUpdate");*/
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              videoDiagnosisLogService.saveData(videoDiagnosis);
 | 
	
		
			
				|  |  |              this.saveOrUpdate(videoDiagnosis);
 | 
	
		
			
				|  |  | -            /*if(alarmRecordsInsert!=null&&alarmRecordsInsert.size()>0){
 | 
	
		
			
				|  |  | -                hostAlarmRecordDao.saveBatch(alarmRecordsInsert);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if(alarmRecordsUpdate!=null&&alarmRecordsUpdate.size()>0){
 | 
	
		
			
				|  |  | -                hostAlarmRecordDao.updateBatchById(alarmRecordsUpdate);
 | 
	
		
			
				|  |  | -            }*/
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  |              throw new RuntimeException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 |