|
|
@@ -15,6 +15,7 @@ import com.xunmei.common.core.domain.iot.domain.IotAlarmSubsystemLog;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotDevice;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.MediatorCategory;
|
|
|
import com.xunmei.common.core.enums.CategoryDataEnum;
|
|
|
+import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
import com.xunmei.common.core.util.BeanHelper;
|
|
|
import com.xunmei.common.core.utils.IDHelper;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
@@ -22,6 +23,7 @@ import com.xunmei.mediator.api.mapper.IotAlarmDefenceAreaMapper;
|
|
|
import com.xunmei.mediator.api.mapper.IotAlarmSubsystemMapper;
|
|
|
import com.xunmei.mediator.api.mapper.ProtectionLogMapper;
|
|
|
import com.xunmei.mediator.api.service.*;
|
|
|
+import com.xunmei.mediator.util.CheckDataUtil;
|
|
|
import com.xunmei.mediator.util.RedisCheckRepeatDataUtil;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
@@ -38,13 +40,18 @@ import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@@ -73,16 +80,18 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
private IotAlarmDefenceAreaService defenceAreService;
|
|
|
@Resource
|
|
|
private NorthErrorService northErrorService;
|
|
|
- @Resource
|
|
|
- IotAlarmDefenceAreaMapper defenceAreaMapper;
|
|
|
- @Resource
|
|
|
- private IotAlarmSubsystemMapper subsystemMapper;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.MEDIATOR_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
|
|
|
@Override
|
|
|
public IotAlarmSubsystem findByCodeAndOrgId(String defenceAreaCode, Long orgId) {
|
|
|
return lambdaQuery()
|
|
|
+ .eq(IotAlarmSubsystem::getDeleted, 0)
|
|
|
.eq(IotAlarmSubsystem::getCode, defenceAreaCode)
|
|
|
- .eq(IotAlarmSubsystem::getOrgId, orgId).last(Constants.LIMIT1).one()
|
|
|
+ .eq(IotAlarmSubsystem::getOrgId, orgId)
|
|
|
+ .last(Constants.LIMIT1)
|
|
|
+ .one()
|
|
|
;
|
|
|
}
|
|
|
|
|
|
@@ -129,8 +138,7 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
|
|
|
SysOrg org = orgService.findByCode(organizationGuid, SecurityConstants.INNER);
|
|
|
if (org == null) {
|
|
|
- NorthError error = new NorthError(msgId, "/status/defencearea"
|
|
|
- , protectionEditDto, "orgGUID:" + organizationGuid + "不正确");
|
|
|
+ NorthError error = new NorthError(msgId, "/status/defencearea", protectionEditDto, "orgGUID:" + organizationGuid + "不正确");
|
|
|
northErrorService.saveError(error);
|
|
|
return result;
|
|
|
}
|
|
|
@@ -143,24 +151,23 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
result.setErrorMsg("参数非法:updateTime不正确");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- IotAlarmSubsystem protection = new IotAlarmSubsystem();
|
|
|
- protection.setCode(protectionEditDto.getDefenceareaCode());
|
|
|
-
|
|
|
- IotAlarmSubsystem old = this.findByCodeAndOrgId(protectionEditDto.getDefenceareaCode(), org.getId());
|
|
|
- if (old != null) {
|
|
|
- if (old.getUpdateTime().isAfter(updateTime)) {
|
|
|
- result.setSuccess(true);
|
|
|
- result.setErrorMsg("历史更新时间大于当前消息,无需更新!");
|
|
|
- return result;
|
|
|
- }
|
|
|
- protection = old;
|
|
|
- } else {
|
|
|
- protection.setId(IdWorker.getId());
|
|
|
- protection.setCreateTime(LocalDateTime.now());
|
|
|
+ IotDevice device = iotDeviceService.findByHostCode(protectionEditDto.getAlarmHostCode(), org.getId());
|
|
|
+ if (device == null) {
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setErrorMsg("参数非法:没有找到报警主机");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ IotAlarmSubsystem protection = this.findByCodeAndOrgId(protectionEditDto.getDefenceareaCode(), org.getId());
|
|
|
+ if (protection == null) {
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setErrorMsg("参数非法:没有找到子系统");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (protection.getUpdateTime().isAfter(updateTime)) {
|
|
|
+ result.setSuccess(true);
|
|
|
+ result.setErrorMsg("历史更新时间大于当前消息,无需更新!");
|
|
|
+ return result;
|
|
|
}
|
|
|
-
|
|
|
protection.setName(protectionEditDto.getDefenceareaName());
|
|
|
protection.setUpdateTime(updateTime);
|
|
|
protection.setStatusUpdateTime(LocalDateTime.now());
|
|
|
@@ -179,55 +186,15 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
result.setErrorMsg("参数非法:defenceStatus不正确");
|
|
|
return result;
|
|
|
}
|
|
|
- IotDevice device = iotDeviceService.findByHostCode(protectionEditDto.getAlarmHostCode(), org.getId());
|
|
|
- if (device == null) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:没有找到报警主机");
|
|
|
- return result;
|
|
|
- }
|
|
|
- IotAlarmSubsystem po = this.findByCodeAndOrgId(protectionEditDto.getDefenceareaCode(), org.getId());
|
|
|
- if (po == null) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:没有找到子系统");
|
|
|
- return result;
|
|
|
- } else {
|
|
|
- if (!po.getAlarmHostCode().equals(protectionEditDto.getAlarmHostCode())) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:该报警主机没有此子系统");
|
|
|
- return result;
|
|
|
- }
|
|
|
- }
|
|
|
protection.setOrgId(org.getId());
|
|
|
protection.setOrgName(org.getShortName());
|
|
|
protection.setOrgPath(org.getPath());
|
|
|
protection.setAlarmHostCode(protectionEditDto.getAlarmHostCode());
|
|
|
protection.setStatusUpdatorId(null);
|
|
|
protection.setStatusUpdatorName(null);
|
|
|
- this.saveOrUpdate(protection);
|
|
|
+ this.updateById(protection);
|
|
|
this.northStatisticsSyncService.saveOrUpdateBusinessCountByDateAndDataType(DateUtil.today(), DataType.protectionStatusCount.getIndex(), 1L);
|
|
|
this.saveProtectionLog(protection);
|
|
|
- //this.writeValue(device, protection);
|
|
|
-
|
|
|
-/*
|
|
|
- //动环告警处理
|
|
|
- List<MediatorAlarmRuleSource> alarmRuleSourceList = alarmRuleSourceService.selectByCode(protection.getCode(), protection.getOrgId());
|
|
|
- if (ObjectUtil.isNotEmpty(alarmRuleSourceList)) {
|
|
|
- for (MediatorAlarmRuleSource alarmRuleSource : alarmRuleSourceList) {
|
|
|
- final List<MediatorAlarmRuleExpress> appAlarmRuleExpressList = alarmRuleExpressService.selectRuleExpressByRuleIdAndType(alarmRuleSource.getRuleId(), alarmRuleSource.getSourceType());
|
|
|
- if (ObjectUtil.isEmpty(appAlarmRuleExpressList)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (MediatorAlarmRuleExpress alarmRuleExpress : appAlarmRuleExpressList) {
|
|
|
- Integer timeTemplateId = alarmRuleExpress.getTimeTemplateId();
|
|
|
- //全时段
|
|
|
- if (timeTemplateId != null && 0 == alarmRuleExpress.getIsUseWorkTemplate()) {
|
|
|
- dealAlarmDataByAllTimeTemplate(alarmRuleExpress, protection);
|
|
|
- } else {
|
|
|
- dealAlarmDataByWorkTimeTemplate(alarmRuleExpress, protection, alarmRuleSource);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -242,38 +209,12 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
protectionLogMapper.insert(protectionLog);
|
|
|
}
|
|
|
|
|
|
- /* public void writeValue(final IotDevice device, final IotAlarmSubsystem protection) {
|
|
|
- Map data = null;
|
|
|
-
|
|
|
- try {
|
|
|
- data = JSON.parseObject(String.valueOf(protection), Map.class);
|
|
|
- } catch (Exception var5) {
|
|
|
- log.error("转换对象异常:{}", var5);
|
|
|
- }
|
|
|
-
|
|
|
- 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";
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ReceiveErrorDto defenceAreaList(DataPageDto<DefenceAreaDto> request, String msgId) {
|
|
|
- String packageGuid = request.getPackageGuid();
|
|
|
- if (StringUtils.isEmpty(packageGuid)) {
|
|
|
- return ReceiveErrorDto.error("packageGuid参数非法");
|
|
|
- }
|
|
|
- Long totalPage = request.getTotalPage();
|
|
|
- if (totalPage == null) {
|
|
|
- return ReceiveErrorDto.error("totalPage参数非法");
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(request.getData())) {
|
|
|
- return ReceiveErrorDto.error("报警主机子系统及防区信息为空");
|
|
|
+ final ReceiveErrorDto errorDto = CheckDataUtil.checkObjFieldIsNull(request);
|
|
|
+ if (!errorDto.getSuccess()) {
|
|
|
+ return errorDto;
|
|
|
}
|
|
|
final List<DefenceAreaDto> defenceareaList = RedisCheckRepeatDataUtil.isCompleted(request, DefenceAreaDto.class);
|
|
|
LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", defenceareaList.size() > 0);
|
|
|
@@ -282,25 +223,20 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
}
|
|
|
LogUtils.BASE_INFO_DEFENCEAREA.info("获取全部的报警主机子系统及防区信息,开始数据处理界面!");
|
|
|
this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), false);
|
|
|
- new Thread(() -> {
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
this.saveAndUpdate(defenceareaList, msgId);
|
|
|
- }).start();
|
|
|
+ }, threadPoolTaskExecutor);
|
|
|
return ReceiveErrorDto.success();
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
|
|
public void saveAndUpdate(List<DefenceAreaDto> defenceareaList, String msgId) {
|
|
|
- if (CollectionUtils.isEmpty(defenceareaList)) {
|
|
|
- ReceiveErrorDto.error("报警主机子系统及防区信息为空");
|
|
|
- return;
|
|
|
- }
|
|
|
//查询报警主机主机设备列表
|
|
|
List<IotDevice> devices = iotDeviceService.findByCategory(CategoryDataEnum.ALARM_HOST_DEVICE.getId());
|
|
|
checkParam(defenceareaList, msgId, devices);
|
|
|
}
|
|
|
|
|
|
private void checkParam(List<DefenceAreaDto> defenceareaList, String msgId, List<IotDevice> devices) {
|
|
|
- //获取category列表
|
|
|
- List<MediatorCategory> categorys = categoryService.list();
|
|
|
final List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
List<NorthError> errors = new ArrayList<>();
|
|
|
List<IotAlarmDefenceArea> sensorList = new ArrayList<>();
|
|
|
@@ -371,17 +307,14 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
if (StringUtils.isEmpty(sensorDto.getSensorTypeName())) {
|
|
|
error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:未传SensorTypeName");
|
|
|
errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<MediatorCategory> categorysa = categorys.stream().filter(r -> r.getName().equals(sensorDto.getSensorTypeName())).collect(Collectors.toList());//categoryDao.getOne(qw);
|
|
|
- if (categorysa.size() == 0) {
|
|
|
- error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:没有找到设备类型,默认归到其他类型中");
|
|
|
- errors.add(error);
|
|
|
}
|
|
|
}
|
|
|
- // }
|
|
|
- List<IotDevice> devicesa = devices.stream().filter(r -> r.getEquipmentCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(org.getId())).collect(Collectors.toList());
|
|
|
- if (devicesa.size() == 0) {
|
|
|
+ final Optional<IotDevice> iotDeviceOptional = devices.stream()
|
|
|
+ .filter(r -> r.getEquipmentCode().equals(dto.getAlarmHostCode()))
|
|
|
+ .filter(r -> r.getOrgId().equals(org.getId()))
|
|
|
+ .filter(r -> r.getDeleted() == 0)
|
|
|
+ .findAny();
|
|
|
+ if (!iotDeviceOptional.isPresent()) {
|
|
|
error = new NorthError(msgId, "/api/data/defenceareaList", dto, "参数非法:没有找到报警主机");
|
|
|
errors.add(error);
|
|
|
continue;
|
|
|
@@ -410,25 +343,22 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
|
|
|
}
|
|
|
|
|
|
- private void updateAllDelete(List<Long> orgIdLIst){
|
|
|
- LambdaUpdateWrapper<IotAlarmSubsystem> updateWrapper=new LambdaUpdateWrapper<IotAlarmSubsystem>();
|
|
|
- updateWrapper.in(IotAlarmSubsystem::getOrgId,orgIdLIst);
|
|
|
- updateWrapper.set(IotAlarmSubsystem::getDeleted,1);
|
|
|
+ private void updateAllDelete(List<Long> orgIdLIst) {
|
|
|
+ LambdaUpdateWrapper<IotAlarmSubsystem> updateWrapper = new LambdaUpdateWrapper<IotAlarmSubsystem>();
|
|
|
+ updateWrapper.in(IotAlarmSubsystem::getOrgId, orgIdLIst);
|
|
|
+ updateWrapper.set(IotAlarmSubsystem::getDeleted, 1);
|
|
|
this.update(updateWrapper);
|
|
|
|
|
|
- LambdaUpdateWrapper<IotAlarmDefenceArea> defenceAreaLambdaUpdateWrapper=new LambdaUpdateWrapper<IotAlarmDefenceArea>();
|
|
|
- defenceAreaLambdaUpdateWrapper.in(IotAlarmDefenceArea::getOrgId,orgIdLIst);
|
|
|
- defenceAreaLambdaUpdateWrapper.set(IotAlarmDefenceArea::getDeleted,1);
|
|
|
+ LambdaUpdateWrapper<IotAlarmDefenceArea> defenceAreaLambdaUpdateWrapper = new LambdaUpdateWrapper<IotAlarmDefenceArea>();
|
|
|
+ defenceAreaLambdaUpdateWrapper.in(IotAlarmDefenceArea::getOrgId, orgIdLIst);
|
|
|
+ defenceAreaLambdaUpdateWrapper.set(IotAlarmDefenceArea::getDeleted, 1);
|
|
|
defenceAreService.update(defenceAreaLambdaUpdateWrapper);
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> protectionBuild(DefenceAreaDto dto, SysOrgVO org) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- IotAlarmSubsystem protection = null;
|
|
|
- IotAlarmSubsystem old = this.findByCodeAndOrgId(dto.getDefenceareaCode(), org.getId());
|
|
|
- if (old != null) {
|
|
|
- protection = old;
|
|
|
- } else {
|
|
|
+ IotAlarmSubsystem protection = this.findByCodeAndOrgId(dto.getDefenceareaCode(), org.getId());
|
|
|
+ if (protection == null) {
|
|
|
protection = new IotAlarmSubsystem();
|
|
|
protection.setId(IDHelper.id());
|
|
|
protection.setCreateTime(LocalDateTime.now());
|
|
|
@@ -445,12 +375,11 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
protection.setOrgPath(org.getPath());
|
|
|
map.put("protection", protection);
|
|
|
saveProtectionLog(protection);
|
|
|
-
|
|
|
if (ObjectUtil.isEmpty(dto.getSensorArray())) {
|
|
|
return map;
|
|
|
}
|
|
|
List<IotAlarmDefenceArea> list = new ArrayList<>();
|
|
|
- List<IotAlarmDefenceArea> sensorList = defenceAreService.findBySubSystemCode(dto.getDefenceareaCode());
|
|
|
+ List<IotAlarmDefenceArea> sensorList = defenceAreService.findBySubSystemCode(dto.getDefenceareaCode(), org.getId());
|
|
|
for (SensorDto sensorDto : dto.getSensorArray()) {
|
|
|
IotAlarmDefenceArea sensor = new IotAlarmDefenceArea();
|
|
|
sensor.setAlarmHostCode(dto.getAlarmHostCode());
|
|
|
@@ -462,7 +391,6 @@ public class IotAlarmSubSystemServiceImpl extends ServiceImpl<IotAlarmSubsystemM
|
|
|
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.setDeleted(0);
|