|
|
@@ -1,678 +0,0 @@
|
|
|
-package com.xunmei.mediator.api.service.impl;
|
|
|
-
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.xunmei.common.core.constant.CacheConstants;
|
|
|
-import com.xunmei.common.core.constant.Constants;
|
|
|
-import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
-import com.xunmei.common.core.domain.iot.domain.IotAlarmDefenceArea;
|
|
|
-import com.xunmei.common.core.domain.mediator.domain.*;
|
|
|
-import com.xunmei.common.core.domain.protect.domain.IotSubSystem;
|
|
|
-import com.xunmei.common.core.enums.CategoryDataEnum;
|
|
|
-import com.xunmei.common.core.util.BeanHelper;
|
|
|
-import com.xunmei.common.core.utils.DateUtils;
|
|
|
-import com.xunmei.common.core.utils.IDHelper;
|
|
|
-import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
-import com.xunmei.mediator.api.mapper.IotSubSystemMapper;
|
|
|
-import com.xunmei.mediator.api.mapper.MediatorTimeTemplateMapper;
|
|
|
-import com.xunmei.mediator.api.service.*;
|
|
|
-import com.xunmei.system.api.RemoteDeviceService;
|
|
|
-import com.xunmei.system.api.RemoteOrgService;
|
|
|
-import com.xunmei.system.api.domain.SysDevice;
|
|
|
-import com.xunmei.system.api.domain.SysOrg;
|
|
|
-import com.xunmei.system.api.domain.north.NorthError;
|
|
|
-import com.xunmei.system.api.dto.protection.*;
|
|
|
-import com.xunmei.system.api.enums.AlarmRuleExpressOperateEnum;
|
|
|
-import com.xunmei.system.api.enums.DataType;
|
|
|
-import com.xunmei.system.api.enums.ProtectionStatus;
|
|
|
-import com.xunmei.system.api.util.LogUtils;
|
|
|
-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.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneId;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 服务实现类
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author oygj
|
|
|
- * @since 2024-01-29
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class IotSubSystemServiceImpl extends ServiceImpl<IotSubSystemMapper, IotSubSystem> implements IIotSubSystemService {
|
|
|
- @Resource
|
|
|
- RemoteOrgService orgService;
|
|
|
- @Resource
|
|
|
- RedisTemplate redisTemplate;
|
|
|
- @Resource
|
|
|
- NorthStatisticsSyncService northStatisticsSyncService;
|
|
|
- @Resource
|
|
|
- IMediatorCategoryService categoryService;
|
|
|
- @Resource
|
|
|
- RemoteDeviceService deviceService;
|
|
|
- @Resource
|
|
|
- private IIotDefenceAreaService defenceAreService;
|
|
|
- @Resource
|
|
|
- private NorthErrorService northErrorService;
|
|
|
- @Resource
|
|
|
- private MediatorTimeTemplateMapper timeTemplateMapper;
|
|
|
- @Resource
|
|
|
- private IMediatorAlarmRuleSourceService alarmRuleSourceService;
|
|
|
- @Resource
|
|
|
- private IMediatorAlarmRuleExpressService alarmRuleExpressService;
|
|
|
- @Override
|
|
|
- public IotSubSystem findByCodeAndOrgId(String defenceAreaCode, Long orgId) {
|
|
|
- return lambdaQuery()
|
|
|
- .eq(IotSubSystem::getSubSystemCode, defenceAreaCode)
|
|
|
- .eq(IotSubSystem::getOrgId, orgId)
|
|
|
- .last(Constants.LIMIT1)
|
|
|
- .one();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ReceiveErrorDto saveData(ProtectionEditDto protectionEditDto, String msgId, String branchId) {
|
|
|
-
|
|
|
- ReceiveErrorDto result = new ReceiveErrorDto();
|
|
|
- String organizationGuid = protectionEditDto.getOrganizationGuid();
|
|
|
- if (StringUtils.isEmpty(organizationGuid)) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:未传organizationGuid");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(protectionEditDto.getDefenceareaCode())) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:未传defenceareaCode");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(protectionEditDto.getDefenceareaName())) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:未传defenceareaName");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (protectionEditDto.getDefenceStatus() == null) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:未传defenceStatus");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(protectionEditDto.getUpdateTime())) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:未传updateTime");
|
|
|
- return result;
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(protectionEditDto.getAlarmHostCode())) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:未传alarmHostCode");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- SysOrg org = orgService.findByCode(organizationGuid, SecurityConstants.INNER);
|
|
|
- if (org == null) {
|
|
|
- NorthError error = new NorthError(msgId, branchId, "/status/defencearea"
|
|
|
- , protectionEditDto, "orgGUID:" + organizationGuid + "不正确");
|
|
|
- northErrorService.saveError(error);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- LocalDateTime dateTime = null;
|
|
|
- try {
|
|
|
- dateTime = LocalDateTime.parse(protectionEditDto.getUpdateTime(), DateTimeFormatter.ISO_DATE_TIME);
|
|
|
- } catch (Exception e) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:updateTime不正确");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Date updateTime = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
- IotSubSystem protection = new IotSubSystem();
|
|
|
- protection.setSubSystemCode(protectionEditDto.getDefenceareaCode());
|
|
|
-
|
|
|
- IotSubSystem old = this.findByCodeAndOrgId(protectionEditDto.getDefenceareaCode(), org.getId());
|
|
|
- if (old != null) {
|
|
|
- Date oldUt = DateUtils.toDate(old.getUpdateTime());
|
|
|
- long ot = oldUt.getTime();
|
|
|
- long nt = updateTime.getTime();
|
|
|
- if (ot - nt > 0) {
|
|
|
- result.setSuccess(true);
|
|
|
- result.setErrorMsg("历史更新时间大于当前消息,无需更新!");
|
|
|
- return result;
|
|
|
- }
|
|
|
- protection = old;
|
|
|
- } else {
|
|
|
- protection.setId(IdWorker.getId());
|
|
|
- }
|
|
|
-
|
|
|
- protection.setSubSystemName(protectionEditDto.getDefenceareaName());
|
|
|
- protection.setUpdateTime(DateUtils.toLocalDateTime(updateTime));
|
|
|
- switch (protectionEditDto.getDefenceStatus()) {
|
|
|
- case 0:
|
|
|
- protection.setStatus(ProtectionStatus.REMOVAL.ordinal());
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- protection.setStatus(ProtectionStatus.PROTECTION.ordinal());
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- protection.setStatus(ProtectionStatus.UNKNOWN.ordinal());
|
|
|
- break;
|
|
|
- default:
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:defenceStatus不正确");
|
|
|
- return result;
|
|
|
- }
|
|
|
- SysDevice device = deviceService.findByHostCode(protectionEditDto.getAlarmHostCode(),SecurityConstants.INNER);
|
|
|
- if (device == null) {
|
|
|
- result.setSuccess(false);
|
|
|
- result.setErrorMsg("参数非法:没有找到报警主机");
|
|
|
- return result;
|
|
|
- }
|
|
|
- IotSubSystem 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.getName());
|
|
|
- protection.setOrgPath(org.getPath());
|
|
|
- protection.setAlarmHostCode(protectionEditDto.getAlarmHostCode());
|
|
|
- this.saveOrUpdate(protection);
|
|
|
- this.northStatisticsSyncService.saveOrUpdateBusinessCountByDateAndDataType(DateUtil.today(), DataType.protectionStatusCount.getIndex(), 1L);
|
|
|
- this.saveProtectionLog(protection);
|
|
|
- this.writeValue(device, protection);
|
|
|
-
|
|
|
-
|
|
|
- //动环告警处理
|
|
|
- List<MediatorAlarmRuleSource> alarmRuleSourceList = alarmRuleSourceService.selectByCode(protection.getSubSystemCode(), 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;
|
|
|
- }
|
|
|
- private void dealAlarmDataByWorkTimeTemplate(MediatorAlarmRuleExpress alarmRuleExpress, IotSubSystem protection, MediatorAlarmRuleSource alarmRuleSource) {
|
|
|
- //使用作息时间模板
|
|
|
- /* final Long orgId = protection.getOrgId();
|
|
|
- final int year = DateUtil.year(new Date());
|
|
|
- WorkTimeSet weekday = objectMapper.selectWorkTimeSet(orgId, year);
|
|
|
- if (weekday == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(DateUtil.offsetDay(new Date(), -1));
|
|
|
- calendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
- int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
- final List<Integer> weekDayList = getWeekDayList(weekday);
|
|
|
- //如果作息时间模板中 不包含今天即今天任何情况都不报警,则返回
|
|
|
- if (!weekDayList.contains(weekDay)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- boolean isAlarm = false;
|
|
|
- //获取告警表达式内容
|
|
|
- final String operator = alarmRuleExpress.getOperator();
|
|
|
- final String value = alarmRuleExpress.getValue();
|
|
|
- Date now = DateUtil.parse(DateUtil.format(new Date(), "HH:mm"), "HH:mm");
|
|
|
- Date workOffTime = DateUtil.parse(weekday.getWorkOffTime(), "HH:mm");
|
|
|
- //如果 作息中的下班时间早于当前时间,即当前时间 大于 作息中下班时间,即当前时间已经下班
|
|
|
- //此处认定 如果当前时间小于下班时间,那么都属于上班时间,使用上班告警规则
|
|
|
- final boolean isOffWork = workOffTime.before(now);
|
|
|
- MediatorAlarmRule alarmRule = objectMapper.selectAlarmRuleById(alarmRuleSource.getRuleId());
|
|
|
- if (isOffWork && ObjectUtil.equal("downinspection", alarmRule.getType())) {
|
|
|
- //如果已经下班,使用下班巡检告警规则
|
|
|
- //判断表达式的值 于当前布撤防状态值是否一致
|
|
|
- if (AlarmRuleExpressOperateEnum.EQUALS.getText().equals(operator)) {
|
|
|
- isAlarm = protection.getStatus() == Integer.parseInt(value);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isOffWork && ObjectUtil.equal("upinspection", alarmRule.getType())) {
|
|
|
- //如果还没下班,使用上班巡检告警规则
|
|
|
- //判断表达式的值 于当前布撤防状态值是否一致
|
|
|
- if (AlarmRuleExpressOperateEnum.EQUALS.getText().equals(operator)) {
|
|
|
- isAlarm = protection.getStatus() == Integer.parseInt(value);
|
|
|
- }
|
|
|
- }
|
|
|
- if (isAlarm) {
|
|
|
- DeviceAlarm deviceAlarm = new DeviceAlarm();
|
|
|
- deviceAlarm.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
- deviceAlarm.setContent(ProductTypeEnum.ALARM_ZONE + " 触发动环设备告警规则告警");
|
|
|
- deviceAlarm.setImageList(null);
|
|
|
- deviceAlarm.setDeviceId(protection.getDeviceId());
|
|
|
- deviceAlarm.setIsRestore(0);
|
|
|
- deviceAlarmDao.save(deviceAlarm);
|
|
|
- }*/
|
|
|
-
|
|
|
- }
|
|
|
- /*private List<Integer> getWeekDayList(WorkTimeSet weekday) {
|
|
|
- List<Integer> list = new ArrayList<>();
|
|
|
- if (weekday.getMonday()!=null&& weekday.getMonday() == 1) {
|
|
|
- list.add(1);
|
|
|
- }
|
|
|
- if (weekday.getTuesday()!=null&&weekday.getTuesday() == 1) {
|
|
|
- list.add(2);
|
|
|
- }
|
|
|
- if (weekday.getWednesday()!=null&&weekday.getWednesday() == 1) {
|
|
|
- list.add(3);
|
|
|
- }
|
|
|
- if (weekday.getThursday()!=null&&weekday.getThursday() == 1) {
|
|
|
- list.add(4);
|
|
|
- }
|
|
|
- if (weekday.getFriday()!=null&&weekday.getFriday() == 1) {
|
|
|
- list.add(5);
|
|
|
- }
|
|
|
- if (weekday.getSaturday()!=null&&weekday.getSaturday() == 1) {
|
|
|
- list.add(6);
|
|
|
- }
|
|
|
- if (weekday.getSunday()!=null&&weekday.getSunday() == 1) {
|
|
|
- list.add(7);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }*/
|
|
|
- private void dealAlarmDataByAllTimeTemplate(MediatorAlarmRuleExpress alarmRuleExpress, IotSubSystem protection) {
|
|
|
- //全时段
|
|
|
- MediatorTimeTemplate timeTemplate = timeTemplateMapper.selectById(alarmRuleExpress.getTimeTemplateId());
|
|
|
- final List<Map> listMap = JSON.parseArray(timeTemplate.getTemplatecontent(), Map.class);
|
|
|
- for (Map timeMap : listMap) {
|
|
|
-
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(DateUtil.offsetDay(new Date(), -1));
|
|
|
- calendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
- int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
-
|
|
|
- String startTime = (String) timeMap.get("startTime");
|
|
|
- String endTime = (String) timeMap.get("endTime");
|
|
|
- final Object weekday = timeMap.get("weekday");
|
|
|
-
|
|
|
- final String string = JSON.toJSONString(weekday);
|
|
|
-
|
|
|
-
|
|
|
- final List<Integer> list = JSON.parseArray(string, Integer.class);
|
|
|
- //如果时间模板中 不包含今天则返回
|
|
|
- if (!list.contains(weekDay)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- final Date sTime = DateUtil.parse(startTime, "HH:mm");
|
|
|
- final Date eTime = DateUtil.parse(endTime, "HH:mm");
|
|
|
- final Date now = DateUtil.parse(DateUtil.format(new Date(), "HH:mm"), "HH:mm");
|
|
|
-
|
|
|
- final boolean in = DateUtil.isIn(now, sTime, eTime);
|
|
|
- if (!in) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- boolean isAlarm = false;
|
|
|
- final String operator = alarmRuleExpress.getOperator();
|
|
|
- final String value = alarmRuleExpress.getValue();
|
|
|
- if (AlarmRuleExpressOperateEnum.EQUALS.getText().equals(operator)) {
|
|
|
- isAlarm = protection.getStatus() == Integer.parseInt(value);
|
|
|
- }
|
|
|
-
|
|
|
- if (isAlarm) {
|
|
|
- /* DeviceAlarm deviceAlarm = new DeviceAlarm();
|
|
|
- deviceAlarm.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
- deviceAlarm.setContent(ProductTypeEnum.ALARM_ZONE + " 触发动环设备告警规则告警");
|
|
|
- deviceAlarm.setImageList(null);
|
|
|
- deviceAlarm.setDeviceId(protection.getDeviceId());
|
|
|
- deviceAlarm.setIsRestore(0);
|
|
|
- deviceAlarmDao.save(deviceAlarm);*/
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void saveProtectionLog(IotSubSystem protection) {
|
|
|
- //todo 保存布撤防历史
|
|
|
- }
|
|
|
- public void writeValue(final SysDevice device, final IotSubSystem 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
|
|
|
- public ReceiveErrorDto defenceAreaList(DefenceareaPageDto request, String branchId, 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("报警主机子系统及防区信息为空");
|
|
|
- }
|
|
|
- boolean completed = this.isCompleted(request);
|
|
|
- LogUtils.BASE_INFO_DEFENCEAREA.info("判断是否获取全部报警主机子系统及防区信息分页数据:{}", completed);
|
|
|
- if (completed) {
|
|
|
- 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);
|
|
|
- List<DefenceAreaDto> defenceareaDtos = JSON.parseArray((String) obj, DefenceAreaDto.class);
|
|
|
- if (defenceareaDtos != null) {
|
|
|
- defenceareaList.addAll(defenceareaDtos);
|
|
|
- }
|
|
|
- }
|
|
|
- for (int i = 1; i <= totalPage; i++) {
|
|
|
- String ak = packageGuid + "_" + i;
|
|
|
- this.redisTemplate.delete(ak);
|
|
|
- }
|
|
|
- //protectionDao.updateAllDelete();
|
|
|
- this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), false);
|
|
|
- new Thread(() -> {
|
|
|
- this.saveAndUpdate(defenceareaList, branchId, msgId);
|
|
|
- }).start();
|
|
|
-
|
|
|
- }
|
|
|
- return ReceiveErrorDto.success();
|
|
|
- }
|
|
|
-
|
|
|
- public ReceiveErrorDto saveAndUpdate(List<DefenceAreaDto> defenceareaList, String branchId, String msgId) {
|
|
|
- if (CollectionUtils.isEmpty(defenceareaList)) {
|
|
|
- return ReceiveErrorDto.error("报警主机子系统及防区信息为空");
|
|
|
- }
|
|
|
- List<NorthError> errors = new ArrayList<>();
|
|
|
- List<IotSubSystem> protectionList = new ArrayList<>();
|
|
|
- List<IotAlarmDefenceArea> sensorList = new ArrayList<>();
|
|
|
- List<IotSubSystem> deviceList = new ArrayList<>();
|
|
|
- //获取机构列表
|
|
|
- final List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
- //获取category列表
|
|
|
- List<MediatorCategory> categorys = categoryService.list();
|
|
|
- //查询报警主机主机设备列表
|
|
|
- List<SysDevice> devices = deviceService.findAlarmHostDevice(3713671920926720L, SecurityConstants.INNER);
|
|
|
- checkParam(defenceareaList, branchId, msgId, errors, orgList, categorys, devices, deviceList, protectionList, sensorList);
|
|
|
- return ReceiveErrorDto.success();
|
|
|
- }
|
|
|
-
|
|
|
- private void checkParam(List<DefenceAreaDto> defenceareaList, String branchId, String msgId, List<NorthError> errors, List<SysOrgVO> orgList, List<MediatorCategory> categorys, List<SysDevice> devices, List<IotSubSystem> deviceList, List<IotSubSystem> protectionList, List<IotAlarmDefenceArea> sensorList) {
|
|
|
- NorthError error = null;
|
|
|
- for (DefenceAreaDto dto : defenceareaList) {
|
|
|
- SysOrgVO org = null;
|
|
|
- if (StringUtils.isEmpty(dto.getOrganizationGuid())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传organizationGuid");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- List<SysOrgVO> orgs = orgList.stream().filter(r -> r.getGuid().equals(dto.getOrganizationGuid())).collect(Collectors.toList()); //orgDao.findByGuid(dto.getOrganizationGuid());
|
|
|
- if (orgs.size() == 0) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "orgGUID:" + dto.getOrganizationGuid() + "不正确");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- org = orgs.get(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(dto.getDefenceAreaCode())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传defenceareaCode");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(dto.getDefenceAreaName())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传defenceareaName");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(dto.getAlarmHostCode())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传alarmHostCode");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (dto.getSensorArray() == null || dto.getSensorArray().size() == 0) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传sensorArray");
|
|
|
- errors.add(error);
|
|
|
- //continue;
|
|
|
- } else {
|
|
|
- List<SensorDto> sensorArray = dto.getSensorArray();
|
|
|
-
|
|
|
- for (SensorDto sensorDto : sensorArray) {
|
|
|
- if (StringUtils.isEmpty(sensorDto.getInputName())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传InputName");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (sensorDto.getInputIndex() == null) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传InputIndex");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(sensorDto.getModuleAddress())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传ModuleAddress");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(sensorDto.getSensorType())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传SensorType");
|
|
|
- errors.add(error);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(sensorDto.getSensorTypeName())) {
|
|
|
- error = new NorthError(msgId, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:未传SensorTypeName");
|
|
|
- errors.add(error);
|
|
|
- }
|
|
|
-
|
|
|
- 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, branchId, "/api/data/defenceareaList"
|
|
|
- , dto, "参数非法:没有找到设备类型,默认归到其他类型中");
|
|
|
- errors.add(error);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- SysOrgVO finalOrg = org;
|
|
|
- SysDevice device = null;
|
|
|
- List<SysDevice> devicesa = devices.stream().filter(r -> r.getHostCode().equals(dto.getAlarmHostCode()) && r.getOrgId().equals(finalOrg.getId())).collect(Collectors.toList());
|
|
|
- if (devicesa == null || 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((IotSubSystem) map.get("protection"));
|
|
|
- List<IotAlarmDefenceArea> list = (List<IotAlarmDefenceArea>) map.get("sensorList");
|
|
|
- if (list != null && list.size() > 0) {
|
|
|
- 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);
|
|
|
- }
|
|
|
- this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.protectionCount.getIndex(), defenceareaList.size(), true);
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Object> protectionBuild(DefenceAreaDto dto, SysOrgVO org) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- IotSubSystem protection = null;
|
|
|
- IotSubSystem old = this.findByCodeAndOrgId(dto.getDefenceAreaCode(), org.getId());
|
|
|
- if (old != null) {
|
|
|
- protection = old;
|
|
|
- } else {
|
|
|
- protection = new IotSubSystem();
|
|
|
- protection.setId(IDHelper.id());
|
|
|
- protection.setCreateTime(DateUtils.toLocalDateTime(new Date()));
|
|
|
- protection.setStatus(2);
|
|
|
- }
|
|
|
- protection.setDeleted(0);
|
|
|
- protection.setAlarmHostCode(dto.getAlarmHostCode());
|
|
|
- protection.setSubSystemCode(dto.getDefenceAreaCode());
|
|
|
- protection.setSubSystemName(dto.getDefenceAreaName());
|
|
|
- protection.setOrgId(org.getId());
|
|
|
- protection.setOrgName(org.getName());
|
|
|
- protection.setOrgPath(org.getPath());
|
|
|
- map.put("protection", protection);
|
|
|
-
|
|
|
-
|
|
|
- List<SensorDto> sensorArray = dto.getSensorArray();
|
|
|
- if (sensorArray != null && sensorArray.size() > 0) {
|
|
|
- List<IotAlarmDefenceArea> list = new ArrayList<>();
|
|
|
- List<IotAlarmDefenceArea> list1 = new ArrayList<>();
|
|
|
- List<IotAlarmDefenceArea> sensorList = defenceAreService.findBySubSystemCode(dto.getDefenceAreaCode());
|
|
|
- for (SensorDto sensorDto : sensorArray) {
|
|
|
- IotAlarmDefenceArea sensor = new IotAlarmDefenceArea();
|
|
|
- sensor.setAlarmHostCode(dto.getAlarmHostCode());
|
|
|
- sensor.setSubSystemCode(dto.getDefenceAreaCode());
|
|
|
- sensor.setDefenceAreaName(dto.getDefenceAreaName());
|
|
|
- sensor.setOrgId(org.getId());
|
|
|
- sensor.setOrgName(org.getName());
|
|
|
- sensor.setOrgPath(org.getPath());
|
|
|
- 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();
|
|
|
- final Optional<IotAlarmDefenceArea> optional = sensorList.stream()
|
|
|
- .filter(r -> r.getOrgId().equals(org.getId()))
|
|
|
- .filter(r -> r.getAlarmHostCode().equals(dto.getAlarmHostCode()))
|
|
|
- .filter(r -> r.getSubSystemCode().equals(dto.getDefenceAreaCode()))
|
|
|
- .filter(r -> r.getDefenceAreaIndex().equals(sensorDto.getInputIndex()))
|
|
|
- .max(Comparator.comparing(IotAlarmDefenceArea::getUpdateTime));
|
|
|
- if (optional.isPresent()) {
|
|
|
- final IotAlarmDefenceArea iotDefenceAre = optional.get();
|
|
|
- BeanHelper.copyProperties(iotDefenceAre, sensor);
|
|
|
- list.add(iotDefenceAre);
|
|
|
- } else {
|
|
|
- sensor.setId(IDHelper.id());
|
|
|
- sensor.setState("unKnown");
|
|
|
- sensor.setStateText("未知");
|
|
|
- list.add(sensor);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- map.put("sensorList", list);
|
|
|
- map.put("deviceList", list1);
|
|
|
- }
|
|
|
-
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isCompleted(DefenceareaPageDto request) {
|
|
|
- String guid = request.getPackageGuid();
|
|
|
- Long currPage = request.getCurrPage();
|
|
|
- Long totalPage = request.getTotalPage();
|
|
|
- List<DefenceAreaDto> defenceareaList = request.getData();
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成每一页的redis key值
|
|
|
- */
|
|
|
- String key = guid + "_" + currPage;
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断是否已经获取到该分页数据,如果已获取到,则直接返回
|
|
|
- */
|
|
|
- Boolean isExist = redisTemplate.hasKey(key);
|
|
|
-
|
|
|
- if (!isExist) {
|
|
|
- String data = JSON.toJSONString(defenceareaList);
|
|
|
- this.redisTemplate.opsForValue().set(key, data);
|
|
|
- this.redisTemplate.expire(key, 1, TimeUnit.DAYS);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //判断是否完整
|
|
|
- for (int i = 1; i <= totalPage; i++) {
|
|
|
- String ak = guid + "_" + i;
|
|
|
- Boolean isOk = redisTemplate.hasKey(ak);
|
|
|
- if (!isOk) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-}
|