|
|
@ -12,10 +12,12 @@ import com.zc.business.domain.DcWaringStrategy; |
|
|
|
import com.zc.business.domain.DcWarning; |
|
|
|
import com.zc.business.domain.DcWarningBatchConvert; |
|
|
|
import com.zc.business.enums.ValueConverter; |
|
|
|
import com.zc.business.enums.WarningSubclassEnum; |
|
|
|
import com.zc.business.mapper.DcEventMapper; |
|
|
|
import com.zc.business.mapper.DcWarningMapper; |
|
|
|
import com.zc.business.service.IDcEventService; |
|
|
|
import com.zc.business.service.IDcWarningService; |
|
|
|
import com.zc.common.core.websocket.WebSocketService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -47,7 +49,9 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
private IDcEventService dcEventService; |
|
|
|
@Resource |
|
|
|
private RedisCache redisCache; |
|
|
|
|
|
|
|
private final String HAPPEN = "发生"; |
|
|
|
private final String EVENT = "事件"; |
|
|
|
private final String SUBEVENT = "1"; |
|
|
|
private static final String WARNINGSTRATEGY = "warningStrategy";//redis策略缓存的key
|
|
|
|
private static final String WARNINGDATA = "warningData:";//redis事件缓存的key
|
|
|
|
private static String JUDGE = "1"; //自定义判断参数,1为满足0为不满足
|
|
|
@ -123,6 +127,10 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
dcWarning.setEndTime(DateUtils.getObtainDateAfter(Integer.parseInt(strategyTime)));//注入过期时间
|
|
|
|
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的缓存过期时间以及数据库过期时间
|
|
|
|
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
|
|
|
|
//事件推送至 Websocket
|
|
|
|
extracted(dcWarning); |
|
|
|
|
|
|
|
|
|
|
|
if (insertDcWarning==0){ |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -136,6 +144,8 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
redisCache.deleteObject(WARNINGDATA+key); |
|
|
|
String id = dcWarning.getId(); |
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); |
|
|
|
//事件推送至 Websocket
|
|
|
|
extracted(dcWarning); |
|
|
|
return dcWarningMapper.insertDcWarning(dcWarning); |
|
|
|
} |
|
|
|
String otherConfig=""; |
|
|
@ -164,9 +174,33 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间
|
|
|
|
return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString(),dcWarning.getEndTime());//修改数据库配置
|
|
|
|
} |
|
|
|
//事件推送至 Websocket
|
|
|
|
extracted(dcWarning); |
|
|
|
return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库;
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 事件推送至 Websocket |
|
|
|
* @param dcWarning |
|
|
|
*/ |
|
|
|
private void extracted(DcWarning dcWarning) { |
|
|
|
String direction = "";// 方向
|
|
|
|
String EventSubclass = "";// 事件类型
|
|
|
|
if (dcWarning.getDirection().equals("1")) { |
|
|
|
direction="菏泽方向"; |
|
|
|
}else { |
|
|
|
direction="济南方向"; |
|
|
|
} |
|
|
|
for (WarningSubclassEnum eventSubclass : WarningSubclassEnum.values()) { |
|
|
|
if (eventSubclass.getCode().equals(dcWarning.getWarningSubclass())) { |
|
|
|
EventSubclass=eventSubclass.getInfo(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
String content= direction+" " + dcWarning.getStakeMark()+" "+HAPPEN+EventSubclass+EVENT ; |
|
|
|
WebSocketService.broadcast(SUBEVENT, content); //推送事件消息 0不是感知事件
|
|
|
|
} |
|
|
|
|
|
|
|
//优先级策略(还差优先级策略需要配置)
|
|
|
|
// public int priority(DcWarning dcWarning){
|
|
|
|
// dcWarning.setCreateTime(DateUtils.getNowDate());
|
|
|
|