123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package com.hb.proj.gather.process;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import com.hb.proj.gather.model.AlarmLogVO;
- import com.hb.proj.gather.model.SingleCombPO;
- import com.hb.proj.gather.model.SingleInsertPO;
- import com.hb.proj.gather.model.WellParamVO;
- import com.hb.proj.gather.rep.GatherDataRepService;
- import com.hb.proj.gather.rep.RedisRepComponent;
- import com.hb.proj.utils.JacksonUtils;
- import com.hb.xframework.util.ApplicationContextUtils;
- /**
- * 单值采集数据 数据转换任务
- * @author cwen
- *
- */
- public class DataTransRepSingleTask implements Runnable{
-
- private final static Logger logger = LoggerFactory.getLogger(DataTransRepSingleTask.class);
- private SingleCombPO singleCombPO;
-
- public DataTransRepSingleTask(SingleCombPO singleCombPO) {
- this.singleCombPO=singleCombPO;
- }
-
-
- @Override
- public void run() {
- try {
- logger.info("开始单值数据转换处理{}",singleCombPO.getDevSerial());
- Map<String,Float> gatherDatas=singleCombPO.getGatherDatas();
- WellParamVO paramConfig=null;
- SingleInsertPO insPOItm=null;
-
- Map<String,Object> redisDatas=new HashMap<>(gatherDatas.size()); //进入redis的数据
- Map<String,SingleInsertPO> mappingDatas=new HashMap<>(gatherDatas.size()); //入库及报警判断用数据
-
- for(String pcode : gatherDatas.keySet()) {
- paramConfig=DataTransConfig.get(singleCombPO.getDevSerial()+"_"+pcode);
- if(paramConfig==null) {
- logger.warn("未找到参数配置{}_{}",singleCombPO.getDevSerial(),pcode);
- continue;
- }
- insPOItm=new SingleInsertPO(pcode,paramConfig.getParamId(),gatherDatas.get(pcode),singleCombPO.getGatherTime());
- DataTransUtils.transSingle(insPOItm, paramConfig);
-
- redisDatas.put(insPOItm.getParamCode(), insPOItm.getDataVal());
- mappingDatas.put(insPOItm.getWellParam(), insPOItm);
-
-
- }
-
- if(paramConfig==null) {
- logger.warn("设备{}未关联任何井,取消后续操",singleCombPO.getDevSerial());
- return;
- }
-
- List<AlarmLogVO> almlogs=DataAlarmDetector.detect(paramConfig.getWellId(), mappingDatas);
-
- RedisRepComponent repRedis=ApplicationContextUtils.getBean("redisRepComponent", RedisRepComponent.class);
- redisDatas.put("time", singleCombPO.getGatherTime());
- repRedis.put(paramConfig.getWellId(), redisDatas);
-
- 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()); //入库
- repService.saveAlarm(almlogs);
-
- logger.info("单值数据转换、报警、入库完成:{}",singleCombPO.getDevSerial());
- }
- catch(Exception e) {
- e.printStackTrace();
- logger.error("单值转换、入库任务执行出现异常:{}",e.getMessage());
- }
-
- }
-
-
- private Map<String,String> buildRedisAlarm(List<AlarmLogVO> almlogs){
- if(almlogs==null||almlogs.size()==0) {
- return null;
- }
- Map<String,String> rtn=new HashMap<String,String>();
-
- for(AlarmLogVO almlog : almlogs) {
- rtn.put(almlog.getParamCode(), JacksonUtils.getJSON(almlog));
- }
-
- return rtn;
- }
- }
|