|
|
@ -97,8 +97,12 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//优先级策略
|
|
|
|
//优先级策略(还差优先级策略需要配置)
|
|
|
|
public int priority(DcWarning dcWarning){ |
|
|
|
dcWarning.setCreateTime(DateUtils.getNowDate()); |
|
|
|
//设置事件Id UUID无下划线格式32
|
|
|
|
String uuid = IdUtils.fastSimpleUUID(); |
|
|
|
dcWarning.setId(uuid); |
|
|
|
if (StringUtils.isBlank(dcWarning.getStakeMark())||dcWarning.getWarningSource()==null||dcWarning.getWarningType()==null|| |
|
|
|
StringUtils.isBlank(dcWarning.getWarningSubclass())||StringUtils.isBlank(dcWarning.getDirection())){ |
|
|
|
return 0; |
|
|
@ -141,6 +145,13 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
} |
|
|
|
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间
|
|
|
|
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); |
|
|
|
if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis
|
|
|
|
redisCache.deleteObject(WARNINGDATA+key); |
|
|
|
dcWarningMapper.insertDcWarning(dcWarning); |
|
|
|
String id = dcWarning.getId(); |
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
String otherConfig=""; |
|
|
|
if (map.get("otherConfig")!=null){ |
|
|
|
otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息
|
|
|
@ -148,7 +159,8 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
|
|
|
|
JSONObject jsonObjectOne = new JSONObject(otherConfig); |
|
|
|
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); |
|
|
|
JSONObject jsonObject = new DcWarningServiceImpl().mergeJsonObjects(jsonObjectOne, jsonObjectTwo);//合成新的json
|
|
|
|
DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成新的json
|
|
|
|
JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo); |
|
|
|
Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置
|
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间
|
|
|
|
if (integer==0){ |
|
|
@ -159,16 +171,25 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
HashMap redisValueThree = redisWarningStrategy.get(redisKye+"3");//查看传入的事件类型是否配置策略3(时间窗口策略)
|
|
|
|
if (redisValueOne==null&&redisValueTwo==null&&redisValueThree!=null){ //执行策略3,执行到这里说明1不存在或者2不存在或者1未满足过滤条件
|
|
|
|
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间(30分钟)
|
|
|
|
int insertDcWarning = new DcWarningServiceImpl().insertDcWarning(dcWarning);//加入数据库
|
|
|
|
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
|
|
|
|
if (insertDcWarning==0){ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
String id = dcWarning.getId();//取出加入后的id作为value
|
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,id,30,TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟)
|
|
|
|
return 1;//结束
|
|
|
|
} |
|
|
|
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置
|
|
|
|
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); |
|
|
|
String otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
|
|
|
|
if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis
|
|
|
|
redisCache.deleteObject(WARNINGDATA+key); |
|
|
|
dcWarningMapper.insertDcWarning(dcWarning); |
|
|
|
String id = dcWarning.getId(); |
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,id,30,TimeUnit.MINUTES); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
String otherConfig=""; |
|
|
|
otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
|
|
|
|
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
|
|
|
|
JSONObject jsonObjectOne = new JSONObject(otherConfig); |
|
|
|
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); |
|
|
@ -182,22 +203,31 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
HashMap redisValueFour = redisWarningStrategy.get(redisKye+"4");//查看传入的事件类型是否配置策略3(自动结束策略)
|
|
|
|
if (redisValueOne==null&&redisValueTwo==null&&redisValueThree==null&&redisValueFour!=null){ //执行策略4,执行到这里说明1不存在或者2、3不存在或者1未满足过滤条件
|
|
|
|
if (dataId==null){//如果不存在直接加入数据库,加入缓存
|
|
|
|
int insertDcWarning = new DcWarningServiceImpl().insertDcWarning(dcWarning);//加入数据库
|
|
|
|
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
|
|
|
|
if (insertDcWarning==0){ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
String id = dcWarning.getId();//取出加入后的id作为value
|
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,id);//加入缓存????存在问题会数据累计
|
|
|
|
return 1;//结束
|
|
|
|
} |
|
|
|
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置
|
|
|
|
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); |
|
|
|
String otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
|
|
|
|
if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis
|
|
|
|
redisCache.deleteObject(WARNINGDATA+key); |
|
|
|
dcWarningMapper.insertDcWarning(dcWarning); |
|
|
|
String id = dcWarning.getId(); |
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,id); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
String otherConfig=""; |
|
|
|
otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
|
|
|
|
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
|
|
|
|
JSONObject jsonObjectOne = new JSONObject(otherConfig); |
|
|
|
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); |
|
|
|
JSONObject jsonObject = new DcWarningServiceImpl().mergeJsonObjects(jsonObjectOne, jsonObjectTwo);//合成新的json
|
|
|
|
Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置
|
|
|
|
redisCache.deleteObject(WARNINGDATA + key);//删除对应的合成事件
|
|
|
|
redisCache.deleteObject(WARNINGDATA + key);//删除redis存储的数据
|
|
|
|
if (integer==0){ |
|
|
|
return 0; |
|
|
|
} |
|
|
|