|
@@ -10,7 +10,6 @@ import com.zd.forward.config.AlgorithmYml;
|
|
|
import com.zd.forward.domain.VideoRequestData;
|
|
import com.zd.forward.domain.VideoRequestData;
|
|
|
import com.zd.forward.properties.FireProperties;
|
|
import com.zd.forward.properties.FireProperties;
|
|
|
import com.zd.system.api.domain.Algorithm;
|
|
import com.zd.system.api.domain.Algorithm;
|
|
|
-import com.zd.system.api.domain.ParamVo;
|
|
|
|
|
import com.zd.system.api.domain.PlayVo;
|
|
import com.zd.system.api.domain.PlayVo;
|
|
|
import com.zd.system.api.speak.RemoteSpeakService;
|
|
import com.zd.system.api.speak.RemoteSpeakService;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -28,6 +27,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import static com.zd.common.core.constant.Constants.MAP_INIT_SIZE;
|
|
import static com.zd.common.core.constant.Constants.MAP_INIT_SIZE;
|
|
@@ -44,6 +44,15 @@ public class SendSginAccessLogService {
|
|
|
|
|
|
|
|
private final RemoteSpeakService remoteSpeakService;
|
|
private final RemoteSpeakService remoteSpeakService;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 报警次数记录
|
|
|
|
|
+ */
|
|
|
|
|
+ static Map<String, Integer> alarmMap = new ConcurrentHashMap<>();
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 超时时间设置MAP
|
|
|
|
|
+ */
|
|
|
|
|
+ static Map<String, Long> expiryMap = new ConcurrentHashMap<>();
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
public SendSginAccessLogService(RestTemplate restTemplateLocal, RedisTemplate<Object, Object> redisTemplate, LoginService loginLab, AlgorithmYml algorithmYml, RemoteSpeakService remoteSpeakService) {
|
|
public SendSginAccessLogService(RestTemplate restTemplateLocal, RedisTemplate<Object, Object> redisTemplate, LoginService loginLab, AlgorithmYml algorithmYml, RemoteSpeakService remoteSpeakService) {
|
|
|
this.restTemplateLocal = restTemplateLocal;
|
|
this.restTemplateLocal = restTemplateLocal;
|
|
@@ -102,24 +111,37 @@ public class SendSginAccessLogService {
|
|
|
|
|
|
|
|
public void saveAlarm(FireProperties properties) {
|
|
public void saveAlarm(FireProperties properties) {
|
|
|
String hardwareNum = properties.getHardwareNum();
|
|
String hardwareNum = properties.getHardwareNum();
|
|
|
- if (Boolean.TRUE.equals(redisTemplate.hasKey(hardwareNum))) {
|
|
|
|
|
- Integer count = (Integer) redisTemplate.opsForValue().get(hardwareNum);
|
|
|
|
|
|
|
+ long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
+ if (expiryMap.containsKey(hardwareNum)) {
|
|
|
|
|
+ Long expiryTime = expiryMap.get(hardwareNum);
|
|
|
|
|
+ if (currentTimeMillis > expiryTime) {
|
|
|
|
|
+ expiryMap.remove(hardwareNum);
|
|
|
|
|
+ alarmMap.remove(hardwareNum);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ send(properties, hardwareNum);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alarmMap.put(hardwareNum, 1);
|
|
|
|
|
+ expiryMap.put(hardwareNum, currentTimeMillis + 30 * 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void send(FireProperties properties, String hardwareNum) {
|
|
|
|
|
+ if (alarmMap.containsKey(hardwareNum)) {
|
|
|
|
|
+ Integer count = alarmMap.get(hardwareNum);
|
|
|
if (count == null) {
|
|
if (count == null) {
|
|
|
count = 0;
|
|
count = 0;
|
|
|
}
|
|
}
|
|
|
- redisTemplate.opsForValue().set(hardwareNum, count + 1, 30, TimeUnit.SECONDS);
|
|
|
|
|
|
|
+ alarmMap.put(hardwareNum, count + 1);
|
|
|
R<Object> r = send(properties);
|
|
R<Object> r = send(properties);
|
|
|
if (r.getCode() != HttpStatus.SUCCESS) {
|
|
if (r.getCode() != HttpStatus.SUCCESS) {
|
|
|
logger.error("火焰警报失败原因:{}", r.getMsg());
|
|
logger.error("火焰警报失败原因:{}", r.getMsg());
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- redisTemplate.opsForValue().set(hardwareNum, 1, 30, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void playMp3() {
|
|
public void playMp3() {
|
|
|
- if (!algorithmYml.isLoudspeakerSwitch()){
|
|
|
|
|
|
|
+ if (!algorithmYml.isLoudspeakerSwitch()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
String loudspeakerIp1 = algorithmYml.getLoudspeakerIp1();
|
|
String loudspeakerIp1 = algorithmYml.getLoudspeakerIp1();
|
|
@@ -133,7 +155,7 @@ public class SendSginAccessLogService {
|
|
|
playVo.setSn(map.get("deviceSn") + "");
|
|
playVo.setSn(map.get("deviceSn") + "");
|
|
|
playVo.setPort(Integer.parseInt(map.get("port") + ""));
|
|
playVo.setPort(Integer.parseInt(map.get("port") + ""));
|
|
|
sendText(loudspeakerIp1, playVo);
|
|
sendText(loudspeakerIp1, playVo);
|
|
|
- sendText(loudspeakerIp2 , playVo);
|
|
|
|
|
|
|
+ sendText(loudspeakerIp2, playVo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -142,10 +164,10 @@ public class SendSginAccessLogService {
|
|
|
private void sendText(String ip, PlayVo playVo) {
|
|
private void sendText(String ip, PlayVo playVo) {
|
|
|
String url = algorithmYml.getTargetUrl() + "/zd-speaker/speaker/textPlayMusic?ip={ip}&texts={texts}";
|
|
String url = algorithmYml.getTargetUrl() + "/zd-speaker/speaker/textPlayMusic?ip={ip}&texts={texts}";
|
|
|
HttpEntity<PlayVo> requestEntity = getMapHttpEntity(playVo);
|
|
HttpEntity<PlayVo> requestEntity = getMapHttpEntity(playVo);
|
|
|
- if (StringUtils.isNotEmpty(ip)){
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(ip)) {
|
|
|
List<String> texts = new ArrayList<>();
|
|
List<String> texts = new ArrayList<>();
|
|
|
texts.add("当前环境监测到无人值守");
|
|
texts.add("当前环境监测到无人值守");
|
|
|
- ResponseEntity<AjaxResult> response = restTemplateLocal.postForEntity(url, requestEntity, AjaxResult.class, ip,texts);
|
|
|
|
|
|
|
+ ResponseEntity<AjaxResult> response = restTemplateLocal.postForEntity(url, requestEntity, AjaxResult.class, ip, texts);
|
|
|
logger.info("响应码:{},响应结果:{}", response.getStatusCode(), response.getBody());
|
|
logger.info("响应码:{},响应结果:{}", response.getStatusCode(), response.getBody());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -176,15 +198,12 @@ public class SendSginAccessLogService {
|
|
|
List<Map<String, Object>> maps = new ArrayList<>();
|
|
List<Map<String, Object>> maps = new ArrayList<>();
|
|
|
Integer aid = properties.getAlgoId();
|
|
Integer aid = properties.getAlgoId();
|
|
|
Map<Integer, AlgorithmYml.AlarmConfig> alarmConfigMap = algorithmYml.getAlarmConfigMap();
|
|
Map<Integer, AlgorithmYml.AlarmConfig> alarmConfigMap = algorithmYml.getAlarmConfigMap();
|
|
|
- if (alarmConfigMap.containsKey(aid)) {
|
|
|
|
|
- AlgorithmYml.AlarmConfig alarmConfig = alarmConfigMap.get(aid);
|
|
|
|
|
- Map<String, Object> params = new HashMap<>(MAP_INIT_SIZE);
|
|
|
|
|
- params.put("hardwareNum", properties.getHardwareNum());
|
|
|
|
|
- params.put("subId", properties.getLabId());
|
|
|
|
|
- params.put("val", 1);
|
|
|
|
|
- return getParams(requestMap, maps, alarmConfig, params);
|
|
|
|
|
- }
|
|
|
|
|
- return R.fail("未找到算法");
|
|
|
|
|
|
|
+ AlgorithmYml.AlarmConfig alarmConfig = alarmConfigMap.get(aid);
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>(MAP_INIT_SIZE);
|
|
|
|
|
+ params.put("hardwareNum", properties.getHardwareNum());
|
|
|
|
|
+ params.put("subId", properties.getLabId());
|
|
|
|
|
+ params.put("val", 1);
|
|
|
|
|
+ return getParams(requestMap, maps, alarmConfig, params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private R<Object> getParams(Map<String, Object> requestMap, List<Map<String, Object>> maps, AlgorithmYml.AlarmConfig alarmConfig, Map<String, Object> params) {
|
|
private R<Object> getParams(Map<String, Object> requestMap, List<Map<String, Object>> maps, AlgorithmYml.AlarmConfig alarmConfig, Map<String, Object> params) {
|