Browse Source

同步于master分支(单值采集,存储报警wellId处理)

chenwen 1 year ago
parent
commit
46d6f94a05

+ 4 - 1
src/main/java/com/hb/proj/gather/process/DataTransRepSingleTask.java

@@ -69,7 +69,10 @@ public class DataTransRepSingleTask implements Runnable{
 			redisDatas.put("time", singleCombPO.getGatherTime());
 			repRedis.put(paramConfig.getWellId(), redisDatas);
 			
-			repRedis.put("alarm_"+paramConfig.getWellId(), buildRedisAlarm(almlogs),true);
+			repRedis.put("alarm_"+paramConfig.getWellId(), buildRedisAlarm(almlogs),true); //覆盖方式,同步于采集数据,不会一直缓存
+			
+			//有报警时,缓存wellId,便于展示系统通过wellId获取报警,否则移除
+			repRedis.updateAlarmWell(paramConfig.getWellId(),almlogs!=null&&almlogs.size()>0);
 			
 			GatherDataRepService repService=ApplicationContextUtils.getBean("gatherDataRepService", GatherDataRepService.class);
 			repService.save(mappingDatas.values());  //入库

+ 21 - 0
src/main/java/com/hb/proj/gather/rep/RedisRepComponent.java

@@ -17,6 +17,11 @@ public class RedisRepComponent {
 	@Autowired
 	private RedisTemplate<String,Object> redisTemplate;
 	
+	/**
+	 * 需要报警的wellId集合
+	 */
+	public static final String ALARM_WELL_KEY="alarm_well_set";
+	
 	
 	public void put(String key,String hashKey,Object val) {
 		redisTemplate.opsForHash().put(key, hashKey, val);
@@ -58,4 +63,20 @@ public class RedisRepComponent {
 	public void delete(String key) {
 		redisTemplate.delete(key);
 	}
+	
+	
+	
+	/**
+	 * 更新缓存(缓存报警的wellId)
+	 * @param wellId
+	 * @param addIf  true 增加缓存,false 移除
+	 */
+	public void updateAlarmWell(Object wellId,boolean addIf) {
+		if(addIf) {
+			redisTemplate.opsForSet().add(ALARM_WELL_KEY, wellId);
+		}
+		else {
+			redisTemplate.opsForSet().remove(ALARM_WELL_KEY, wellId);
+		}
+	}
 }