|
|
@@ -1,5 +1,6 @@
|
|
|
package com.xunmei.mediator.api.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -38,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -66,7 +68,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
@Resource
|
|
|
RemoteOrgService orgService;
|
|
|
@Resource
|
|
|
- RedisTemplate redisTemplate;
|
|
|
+ StringRedisTemplate stringRedisTemplate;
|
|
|
@Resource
|
|
|
NorthStatisticsSyncService northStatisticsSyncService;
|
|
|
@Resource
|
|
|
@@ -211,7 +213,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
this.saveOrUpdate(protection);
|
|
|
this.northStatisticsSyncService.saveOrUpdateBusinessCountByDateAndDataType(DateUtil.today(), DataType.protectionStatusCount.getIndex(), 1L);
|
|
|
this.saveProtectionLog(protection);
|
|
|
- this.writeValue(device, protection);
|
|
|
+ //this.writeValue(device, protection);
|
|
|
|
|
|
/*
|
|
|
//动环告警处理
|
|
|
@@ -247,7 +249,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
protectionLogMapper.insert(protectionLog);
|
|
|
}
|
|
|
|
|
|
- public void writeValue(final IotDevice device, final IotAlarmSubsystem protection) {
|
|
|
+ /* public void writeValue(final IotDevice device, final IotAlarmSubsystem protection) {
|
|
|
Map data = null;
|
|
|
|
|
|
try {
|
|
|
@@ -259,7 +261,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
String key = this.toKey(device.getOrgId(), Integer.parseInt(device.getDeviceType()));
|
|
|
this.redisTemplate.boundHashOps(key).put(device.getId(), data);
|
|
|
log.info("[ {} ][ {} ][ {} ] 数据 ==> [ {} ]", new Object[]{device.getOrgId(), device.getDeviceType(), device.getId(), data});
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
private String toKey(final Long orgId, Integer deviceType) {
|
|
|
return "device_" + orgId + "_" + deviceType + "_data_map";
|
|
|
@@ -385,22 +387,12 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
if (CollectionUtils.isEmpty(request.getData())) {
|
|
|
return ReceiveErrorDto.error("报警主机子系统及防区信息为空");
|
|
|
}
|
|
|
- boolean completed = this.isCompleted(request);
|
|
|
- LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", completed);
|
|
|
- if (!completed) {
|
|
|
+ final List<DefenceAreaDto> defenceareaList = this.isCompleted(request);
|
|
|
+ LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", defenceareaList.size() > 0);
|
|
|
+ if (ObjectUtil.isEmpty(defenceareaList)) {
|
|
|
return ReceiveErrorDto.error("尚未获取全部报警主机子系统及防区信息分页数据,暂不处理!");
|
|
|
}
|
|
|
LogUtils.BASE_INFO_DEFENCEAREA.info("获取全部的报警主机子系统及防区信息,开始数据处理界面!");
|
|
|
- List<DefenceAreaDto> defenceareaList = new ArrayList<>();
|
|
|
- for (int i = 1; i <= totalPage; i++) {
|
|
|
- String ak = packageGuid + "_" + i;
|
|
|
- Object obj = this.redisTemplate.opsForValue().get(ak);
|
|
|
- if (ObjectUtil.isNotEmpty(obj)){
|
|
|
- List<DefenceAreaDto> defenceareaDtos = JSON.parseArray((String) obj, DefenceAreaDto.class);
|
|
|
- defenceareaList.addAll(defenceareaDtos);
|
|
|
- redisTemplate.delete(ak);
|
|
|
- }
|
|
|
- }
|
|
|
this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), false);
|
|
|
new Thread(() -> {
|
|
|
this.saveAndUpdate(defenceareaList, branchId, msgId);
|
|
|
@@ -516,50 +508,26 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
}
|
|
|
}
|
|
|
SysOrgVO finalOrg = org;
|
|
|
- IotDevice device = null;
|
|
|
List<IotDevice> devicesa = devices.stream().filter(r -> r.getEquipmentCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(finalOrg.getId())).collect(Collectors.toList());
|
|
|
- if (devicesa == null || devicesa.size() == 0) {
|
|
|
+ if (devicesa.size() == 0) {
|
|
|
error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
, dto, "参数非法:没有找到报警主机");
|
|
|
errors.add(error);
|
|
|
continue;
|
|
|
}
|
|
|
Map<String, Object> map = this.protectionBuild(dto, org);
|
|
|
- if (map != null) {
|
|
|
- protectionList.add((IotAlarmSubsystem) map.get("protection"));
|
|
|
- List<IotAlarmDefenceArea> list = (List<IotAlarmDefenceArea>) map.get("sensorList");
|
|
|
- if (list != null && list.size() > 0) {
|
|
|
- sensorList.addAll(list);
|
|
|
- }
|
|
|
+ protectionList.add((IotAlarmSubsystem) map.get("protection"));
|
|
|
+ List<IotAlarmDefenceArea> list = (List<IotAlarmDefenceArea>) map.get("sensorList");
|
|
|
+ if (ObjectUtil.isNotEmpty(list)) {
|
|
|
+ sensorList.addAll(list);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- try {
|
|
|
- //删除传感器表中的数据
|
|
|
- defenceAreService.remove(new LambdaQueryWrapper<>());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("删除传感器表中的数据失败,失败原因:" + e.getMessage(), e);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (errors.size() > 0) {
|
|
|
- northErrorService.saveErrorData(errors);
|
|
|
- }
|
|
|
- try {
|
|
|
- baseMapper.updateAllDelete();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("修改子系统为逻辑删除失败,失败原因:" + e.getMessage(), e);
|
|
|
- }
|
|
|
- try {
|
|
|
- this.saveOrUpdateBatch(protectionList);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("更新子系统数据失败,失败原因:" + e.getMessage(), e);
|
|
|
- }
|
|
|
- try {
|
|
|
- defenceAreService.saveOrUpdateBatch(sensorList);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("更新t_sensor表传感器数据失败,失败原因:" + e.getMessage(), e);
|
|
|
- }
|
|
|
+ defenceAreService.remove(new LambdaQueryWrapper<>());
|
|
|
+ northErrorService.saveErrorData(errors);
|
|
|
+ baseMapper.updateAllDelete();
|
|
|
+ this.saveOrUpdateBatch(protectionList);
|
|
|
+ defenceAreService.saveOrUpdateBatch(sensorList);
|
|
|
this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
|
|
|
}
|
|
|
|
|
|
@@ -574,7 +542,9 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
protection.setId(IDHelper.id());
|
|
|
protection.setCreateTime(new Date());
|
|
|
protection.setStatus(2);
|
|
|
+ protection.setSource(1);
|
|
|
}
|
|
|
+ protection.setUpdateTime(new Date());
|
|
|
protection.setDeleted(0);
|
|
|
protection.setAlarmHostCode(dto.getAlarmHostCode());
|
|
|
protection.setCode(dto.getDefenceareaCode());
|
|
|
@@ -598,13 +568,13 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
sensor.setOrgId(org.getId());
|
|
|
sensor.setOrgName(org.getName());
|
|
|
sensor.setOrgPath(org.getPath());
|
|
|
+ sensor.setOrganizationGuid(dto.getOrganizationGuid());
|
|
|
sensor.setDefenceAreaIndex(sensorDto.getInputIndex());
|
|
|
sensor.setDefenceAreaName(sensorDto.getInputName());
|
|
|
//sensor.setModuleAddress(sensorDto.getModuleAddress());
|
|
|
sensor.setSensorType(sensorDto.getSensorType());
|
|
|
sensor.setSensorTypeName(sensorDto.getSensorTypeName());
|
|
|
- //sensor.setStrDeviceId(dto.getDefenceAreaCode() + sensorDto.getInputIndex());
|
|
|
- String strDeviceId = dto.getDefenceareaCode() + sensorDto.getInputIndex();
|
|
|
+ sensor.setDeleted(0);
|
|
|
final Optional<IotAlarmDefenceArea> optional = sensorList.stream()
|
|
|
.filter(r -> r.getOrgId().equals(org.getId()))
|
|
|
.filter(r -> r.getAlarmHostCode().equals(dto.getAlarmHostCode()))
|
|
|
@@ -614,11 +584,14 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
if (optional.isPresent()) {
|
|
|
final IotAlarmDefenceArea iotDefenceAre = optional.get();
|
|
|
BeanHelper.copyProperties(iotDefenceAre, sensor);
|
|
|
+ iotDefenceAre.setUpdateTime(LocalDateTime.now());
|
|
|
list.add(iotDefenceAre);
|
|
|
} else {
|
|
|
sensor.setId(IDHelper.id());
|
|
|
sensor.setState("unKnown");
|
|
|
sensor.setStateText("未知");
|
|
|
+ sensor.setCreateTime(LocalDateTime.now());
|
|
|
+ sensor.setDeleted(0);
|
|
|
list.add(sensor);
|
|
|
}
|
|
|
}
|
|
|
@@ -630,38 +603,43 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public boolean isCompleted(DefenceareaPageDto request) {
|
|
|
- String guid = request.getPackageGuid();
|
|
|
+ public List<DefenceAreaDto> isCompleted(DefenceareaPageDto request) {
|
|
|
+ String packageGuid = request.getPackageGuid();
|
|
|
Long currPage = request.getCurrPage();
|
|
|
Long totalPage = request.getTotalPage();
|
|
|
List<DefenceAreaDto> defenceareaList = request.getData();
|
|
|
|
|
|
- /**
|
|
|
- * 生成每一页的redis key值
|
|
|
- */
|
|
|
- String key = guid + "_" + currPage;
|
|
|
+ //生成当前页的redis key值,判断是否已经获取到该分页数据,
|
|
|
+ //若没有获取到,则存入当前页数据,获取到了则继续判断是否拿到所有的数据,
|
|
|
+ //如果拿到了所有的数据则开始处理数据
|
|
|
+ String currPageKey = packageGuid + "_" + currPage;
|
|
|
|
|
|
- /**
|
|
|
- * 判断是否已经获取到该分页数据,如果已获取到,则直接返回
|
|
|
- */
|
|
|
- Boolean isExist = redisTemplate.hasKey(key);
|
|
|
-
|
|
|
- if (!isExist) {
|
|
|
+ Boolean isExist = stringRedisTemplate.hasKey(currPageKey);
|
|
|
+ if (Boolean.FALSE.equals(isExist)) {
|
|
|
String data = JSON.toJSONString(defenceareaList);
|
|
|
- this.redisTemplate.opsForValue().set(key, data);
|
|
|
- this.redisTemplate.expire(key, 1, TimeUnit.DAYS);
|
|
|
+ this.stringRedisTemplate.opsForValue().set(currPageKey, data);
|
|
|
+ this.stringRedisTemplate.expire(currPageKey, 1, TimeUnit.DAYS);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //判断是否完整
|
|
|
+ List<String> allPageKeyList = new ArrayList<>();
|
|
|
for (int i = 1; i <= totalPage; i++) {
|
|
|
- String ak = guid + "_" + i;
|
|
|
- Boolean isOk = redisTemplate.hasKey(ak);
|
|
|
- if (!isOk) {
|
|
|
- return false;
|
|
|
+ String everyPageKey = packageGuid + "_" + i;
|
|
|
+ allPageKeyList.add(everyPageKey);
|
|
|
+ }
|
|
|
+ //判断是否拿到所有的数据
|
|
|
+ final List<Boolean> list = allPageKeyList.stream().map(key -> stringRedisTemplate.hasKey(key)).distinct().collect(Collectors.toList());
|
|
|
+ if (list.contains(Boolean.FALSE)) {
|
|
|
+ return ListUtil.empty();
|
|
|
+ }
|
|
|
+ return allPageKeyList.stream().map(k -> {
|
|
|
+ String obj = this.stringRedisTemplate.opsForValue().get(k);
|
|
|
+ if (ObjectUtil.isNotEmpty(obj)) {
|
|
|
+ final List<DefenceAreaDto> defenceAreaDtos = JSON.parseArray(obj, DefenceAreaDto.class);
|
|
|
+ this.stringRedisTemplate.delete(k);
|
|
|
+ return defenceAreaDtos;
|
|
|
}
|
|
|
- }
|
|
|
- return true;
|
|
|
+ return null;
|
|
|
+ }).filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|
|
|
|