|
@@ -2,18 +2,17 @@ package com.gyee.alarm.service;
|
|
|
|
|
|
import com.gyee.alarm.init.CacheContext;
|
|
|
import com.gyee.alarm.model.auto.*;
|
|
|
-import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
|
|
|
-import com.gyee.alarm.model.vo.AlarmTag;
|
|
|
-import com.gyee.alarm.model.vo.AlarmVo;
|
|
|
-import com.gyee.alarm.model.vo.DeviceTypeValue;
|
|
|
+import com.gyee.alarm.model.vo.*;
|
|
|
import com.gyee.alarm.service.auto.IAlarmTsService;
|
|
|
import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
|
|
|
+import com.gyee.alarm.util.DateUtils;
|
|
|
import com.gyee.alarm.util.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
@@ -68,6 +67,7 @@ public class AlarmWtService {
|
|
|
po.setTagId(vo.getTagid());
|
|
|
po.setOval(po.getVal());
|
|
|
po.setRank(vo.getRank());
|
|
|
+ po.setTimeLong(0.0);
|
|
|
po.setTs(new Date().getTime());
|
|
|
alarmTags.add(po);
|
|
|
}
|
|
@@ -94,19 +94,20 @@ public class AlarmWtService {
|
|
|
|
|
|
if (!alarmls.isEmpty()) {
|
|
|
for (ProEconAlarmConfiguration alarm : alarmls) {
|
|
|
- if (pointMap.containsKey(alarm.getUniformCode())) {
|
|
|
- ProBasicEquipmentPoint equipmentPoint = pointMap.get(alarm.getUniformCode());
|
|
|
-
|
|
|
- if(StringUtils.notEmp(initialcode) &&
|
|
|
- StringUtils.notEmp(equipmentPoint.getNemCode()) &&
|
|
|
- !equipmentPoint.getNemCode().equals(initialcode))
|
|
|
- {
|
|
|
+// if (pointMap.containsKey(alarm.getUniformCode())) {
|
|
|
+// ProBasicEquipmentPoint equipmentPoint = pointMap.get(alarm.getUniformCode());
|
|
|
+//
|
|
|
+// if(StringUtils.notEmp(initialcode) &&
|
|
|
+// StringUtils.notEmp(equipmentPoint.getNemCode()) &&
|
|
|
+// !equipmentPoint.getNemCode().equals(initialcode))
|
|
|
+// {
|
|
|
AlarmVo vo=new AlarmVo();
|
|
|
StringBuilder tbName = new StringBuilder();
|
|
|
tbName.append(wt.getId()).append("_").append(alarm.getId());
|
|
|
vo.setTbName(String.valueOf(tbName));
|
|
|
vo.setAlarmid(alarm.getId());
|
|
|
- vo.setTagid(equipmentPoint.getNemCode());
|
|
|
+// vo.setTagid(equipmentPoint.getNemCode());
|
|
|
+ vo.setTagid(alarm.getTagId());
|
|
|
vo.setAlarmtype(alarm.getAlarmType());
|
|
|
vo.setCharacteristic(alarm.getCharacteristic());
|
|
|
vo.setComponents(alarm.getComponents());
|
|
@@ -142,9 +143,9 @@ public class AlarmWtService {
|
|
|
vo.setUniformcode(alarm.getUniformCode());
|
|
|
vo.setSuperTableName(AlarmSuperTalbeType.WT.getCode());
|
|
|
alarmVoList.add(vo);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -187,24 +188,20 @@ public class AlarmWtService {
|
|
|
public synchronized void saveAlarms(List<AlarmTag> ls)
|
|
|
{
|
|
|
|
|
|
- if(StringUtils.notEmp(ls) && !ls.isEmpty())
|
|
|
- {
|
|
|
+ if(StringUtils.notEmp(ls) && !ls.isEmpty()) {
|
|
|
|
|
|
alarmTsService.insertList(ls);
|
|
|
|
|
|
|
|
|
- if(StringUtils.notEmp(ls) && !ls.isEmpty())
|
|
|
- {
|
|
|
+ if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
|
|
|
|
|
|
- List<ProEconAlarmInfo> valuels=new ArrayList<>();
|
|
|
- for(AlarmTag alarm:ls)
|
|
|
- {
|
|
|
- if(CacheContext.alarmWtMap.containsKey(alarm.getId()))
|
|
|
- {
|
|
|
- AlarmVo vo=CacheContext.alarmWtMap.get(alarm.getId());
|
|
|
- ProEconAlarmInfo po=new ProEconAlarmInfo();
|
|
|
+ List<ProEconAlarmInfo> valuels = new ArrayList<>();
|
|
|
+ for (AlarmTag alarm : ls) {
|
|
|
+ if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
|
|
|
+ AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
|
|
|
+ ProEconAlarmInfo po = new ProEconAlarmInfo();
|
|
|
po.setTbname(vo.getTbName());
|
|
|
- po.setTs(alarm.getTs());
|
|
|
+ po.setLastUpdateTime(new Date(alarm.getTs()));
|
|
|
po.setTagId(alarm.getTagId());
|
|
|
po.setTriggerType(alarm.getTriggerType());
|
|
|
po.setAlarmId(vo.getAlarmid());
|
|
@@ -230,76 +227,129 @@ public class AlarmWtService {
|
|
|
po.setLineidName(vo.getLinename());
|
|
|
po.setDeviceName(vo.getDevicename());
|
|
|
po.setOval(alarm.getOval().intValue());
|
|
|
- if(alarm.getVal()==1)
|
|
|
- {
|
|
|
- po.setIsOpen(1);
|
|
|
- }else if(alarm.getVal()==0)
|
|
|
- {
|
|
|
- po.setIsOpen(0);
|
|
|
- }
|
|
|
-
|
|
|
+ po.setIsOpen(1);
|
|
|
valuels.add(po);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// List<ProEconAlarmInfo> templs=new ArrayList<>();
|
|
|
-// for(ProEconAlarmInfo vo:valuels)
|
|
|
-// {
|
|
|
-// templs.add(vo);
|
|
|
-// if(templs.size()==200)
|
|
|
-// {
|
|
|
-// proEconAlarmInfoService.saveOrUpdateBatch(templs);
|
|
|
-// templs=new ArrayList<>();
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(!templs.isEmpty())
|
|
|
-// {
|
|
|
-// proEconAlarmInfoService.saveOrUpdateBatch(templs);
|
|
|
-// }
|
|
|
+ List<String> idls = new ArrayList<>();
|
|
|
+ for (ProEconAlarmInfo vo : valuels) {
|
|
|
+ idls.add(vo.getTbname());
|
|
|
+ }
|
|
|
+ if (!idls.isEmpty()) {
|
|
|
+
|
|
|
+ proEconAlarmInfoService.removeByIds(idls);
|
|
|
+ }
|
|
|
|
|
|
-//分类,相同的报警放在一个map中的list中
|
|
|
- Map<String, List<ProEconAlarmInfo>> tempmap = new HashMap<>();
|
|
|
+
|
|
|
+ List<ProEconAlarmInfo> templs = new ArrayList<>();
|
|
|
for (ProEconAlarmInfo vo : valuels) {
|
|
|
- if (tempmap.containsKey(vo.getTbname())) {
|
|
|
- List<ProEconAlarmInfo> templs = tempmap.get(vo.getTbname());
|
|
|
- templs.add(vo);
|
|
|
- } else {
|
|
|
- List<ProEconAlarmInfo> templs = new ArrayList<>();
|
|
|
- templs.add(vo);
|
|
|
- tempmap.put(vo.getTbname(), templs);
|
|
|
+ templs.add(vo);
|
|
|
+ if (templs.size() == 100) {
|
|
|
+ proEconAlarmInfoService.saveBatch(templs);
|
|
|
+ templs = new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
-//删除,相同的报警
|
|
|
- List<String> idls = new ArrayList<>();
|
|
|
- for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
|
|
|
- idls.add(entry.getKey());
|
|
|
+
|
|
|
+ if (!templs.isEmpty()) {
|
|
|
+ proEconAlarmInfoService.saveBatch(templs);
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (!idls.isEmpty()) {
|
|
|
|
|
|
- proEconAlarmInfoService.removeByIds(idls);
|
|
|
+ public synchronized void updateAlarms(List<AlarmTag> ls) {
|
|
|
+
|
|
|
+ if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
|
|
|
+
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ Map<String, AlarmSimpleVo> map=new HashMap<>();
|
|
|
+ for (AlarmTag alarm : ls) {
|
|
|
+ sb.append("'").append(alarm.getId()).append("',");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String ids=sb.substring(0,sb.length()-1);
|
|
|
+
|
|
|
+ List<AlarmSimpleVo> alarmls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.WT.getCode(),ids);
|
|
|
+ if(!alarmls.isEmpty())
|
|
|
+ {
|
|
|
+ for(AlarmSimpleVo vo:alarmls)
|
|
|
+ {
|
|
|
+ map.put(vo.getTbName(),vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (AlarmTag alarm : ls) {
|
|
|
+ if(map.containsKey(alarm.getId()))
|
|
|
+ {
|
|
|
+ AlarmSimpleVo tag=map.get(alarm.getId());
|
|
|
+ tag.setTs(new Timestamp(alarm.getTs()));
|
|
|
+
|
|
|
+ Date begin = new Date(alarm.getEndts());
|
|
|
+ Date end = new Date(alarm.getTs());
|
|
|
+
|
|
|
+ double value= DateUtils.hoursDiff(begin,end);
|
|
|
+ tag.setTimelong(value);
|
|
|
}
|
|
|
|
|
|
- List<ProEconAlarmInfo> pols = new ArrayList<>();
|
|
|
-//保存,取项目集合中的最后一个记录进行保存
|
|
|
- for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
|
|
|
- List<ProEconAlarmInfo> resultls = entry.getValue();
|
|
|
- if(!resultls.isEmpty())
|
|
|
- {
|
|
|
- Collections.sort(resultls, new Comparator<ProEconAlarmInfo>() {
|
|
|
- public int compare(ProEconAlarmInfo arg0, ProEconAlarmInfo arg1) {
|
|
|
- return arg0.getTs().compareTo(arg1.getTs());
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- pols.add(resultls.get(resultls.size() - 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ alarmTsService.insertList(ls);
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
|
|
|
+
|
|
|
+ List<ProEconAlarmInfo> valuels = new ArrayList<>();
|
|
|
+ for (AlarmTag alarm : ls) {
|
|
|
+ if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
|
|
|
+ AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
|
|
|
+ ProEconAlarmInfo po = new ProEconAlarmInfo();
|
|
|
+ po.setTbname(vo.getTbName());
|
|
|
+ po.setLastUpdateTime(new Date(alarm.getEndts()));
|
|
|
+ po.setTagId(alarm.getTagId());
|
|
|
+ po.setTriggerType(alarm.getTriggerType());
|
|
|
+ po.setAlarmId(vo.getAlarmid());
|
|
|
+ po.setDeviceId(vo.getDeviceid());
|
|
|
+ po.setSubcomponents(vo.getSuffix());
|
|
|
+ po.setRank(vo.getRank());
|
|
|
+ po.setConfirmed(false);
|
|
|
+ po.setUniformCode(vo.getUniformcode());
|
|
|
+ po.setAlarmType(vo.getAlarmtype());
|
|
|
+ po.setDeviceType(vo.getDevicetype());
|
|
|
+ po.setConfirmed(vo.getConfirmed());
|
|
|
+ po.setSubcomponents(vo.getSubcomponents());
|
|
|
+ po.setDescription(vo.getDescription());
|
|
|
+ po.setModelId(vo.getModelId());
|
|
|
+ po.setResetTable(vo.getResettable());
|
|
|
+ po.setEnable(vo.getEnabled());
|
|
|
+ po.setCharacteristic(vo.getCharacteristic());
|
|
|
+ po.setStationId(vo.getStationid());
|
|
|
+ po.setProjectId(vo.getProjectid());
|
|
|
+ po.setLineId(vo.getLineid());
|
|
|
+ po.setStationName(vo.getStationname());
|
|
|
+ po.setProjectiName(vo.getProjectname());
|
|
|
+ po.setLineidName(vo.getLinename());
|
|
|
+ po.setDeviceName(vo.getDevicename());
|
|
|
+ po.setOval(alarm.getOval().intValue());
|
|
|
+ po.setCloseTime(new Date(alarm.getEndts()));
|
|
|
+ po.setIsOpen(0);
|
|
|
+ valuels.add(po);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ List<String> idls = new ArrayList<>();
|
|
|
+ for (ProEconAlarmInfo vo : valuels) {
|
|
|
+ idls.add(vo.getTbname());
|
|
|
+ }
|
|
|
+ if (!idls.isEmpty()) {
|
|
|
+
|
|
|
+ proEconAlarmInfoService.removeByIds(idls);
|
|
|
}
|
|
|
|
|
|
List<ProEconAlarmInfo> templs = new ArrayList<>();
|
|
|
- for (ProEconAlarmInfo vo : pols) {
|
|
|
+ for (ProEconAlarmInfo vo : valuels) {
|
|
|
templs.add(vo);
|
|
|
if (templs.size() == 100) {
|
|
|
proEconAlarmInfoService.saveBatch(templs);
|
|
@@ -315,5 +365,4 @@ public class AlarmWtService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|