Browse Source

感知事件策略

develop
wangsixiang 11 months ago
parent
commit
6188c148e0
  1. 3
      zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java
  2. 44
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
  3. 3
      zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

3
zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java

@ -80,7 +80,8 @@ public interface DcWarningMapper
//查询预警配置信息
public List<DcWaringStrategy> selectDcWaringStrategyList(DcWaringStrategy dcWaringStrategy);
public List<DcWaringStrategy> selectDcWaringStrategyList();
public List<DcWaringStrategy> selectDcWaringStrategyList(@Param("warningSource")String warningSource,@Param
("warningType")String warningType,@Param("warningSubclass")String warningSubclass,@Param("strategy")Integer strategy);
//修改配置
public Integer updateOtherConfig(@Param("id")String id,@Param("otherConfig")String otherConfig);
}

44
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -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;
}

3
zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

@ -77,6 +77,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
warning.`warning_type`,warning.`warning_subclass`,warning.`warning_title`,
warning.`other_config` FROM dc_warning AS warning
LEFT JOIN dc_stake_mark AS mark ON mark.stake_mark=warning.stake_mark
where warning.warning_source !=6
</select>
<insert id="insertDcWarning" parameterType="DcWarning" useGeneratedKeys="true" keyProperty="id">
@ -208,6 +210,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="warningSource != null "> and warning_source = #{warningSource}</if>
<if test="warningType != null "> and warning_type = #{warningType}</if>
<if test="warningSubclass != null and warningSubclass != ''"> and warning_subclass = #{warningSubclass}</if>
<if test="strategy != null "> and strategy = #{strategy}</if>
</where>
</select>

Loading…
Cancel
Save