Commit 1416f2a1 authored by xukaiqiang's avatar xukaiqiang

git

parent 3a29e559
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>YeeAmosIec104IntfRoot</artifactId> <artifactId>YeeAmosConnectRoot</artifactId>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<version>1.0.0</version> <version>1.0.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>YeeAmosConnectCommon</artifactId> <artifactId>YeeAmosConnectCommon</artifactId>
</project> </project>
\ No newline at end of file
package com.yeejoin.amos.connect.common.enums;
public enum RedisKeyEnum {
K001("K001", "AlarmParam");
/**
* 名称,描述
*/
private String key;
/**
* 编码
*/
private String desc;
public static String buildKey(String bizKey, RedisKeyEnum redisKeyEnum) {
return redisKeyEnum.getKey() + "_" + bizKey;
}
RedisKeyEnum(String key, String desc) {
this.key = key;
this.desc = desc;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>YeeAmosConnectStart</artifactId>
<name>YeeAmosConnectStart</name>
<parent> <parent>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnectRoot</artifactId> <artifactId>YeeAmosConnectRoot</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>YeeAmosConnectStart</artifactId>
<dependencies> <dependencies>
<!-- 业务模块jar --> <!-- 业务模块jar -->
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId> <artifactId>YeeAmosConnectCommon</artifactId>
<version>${iec104.version}</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosIec104IntfServer</artifactId> <artifactId>YeeAmosIec104IntfServer</artifactId>
<version>${iec104.version}</version> <version>${iec104.version}</version>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>com.yeejoin.amos</groupId> <!-- <groupId>com.yeejoin.amos</groupId>-->
<artifactId>YeeAmosUartServer</artifactId> <!-- <artifactId>YeeAmosUartServer</artifactId>-->
<version>${iec104.version}</version> <!-- <version>${iec104.version}</version>-->
</dependency> <!-- </dependency>-->
</dependencies> </dependencies>
<!-- maven打包时将lib提取到jar同目录,将配置文件提取到jar目录/config/下 --> <!-- maven打包时将lib提取到jar同目录,将配置文件提取到jar目录/config/下 -->
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnectRoot</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>YeeAmosIec104IntfServer</artifactId> <artifactId>YeeAmosIec104IntfServer</artifactId>
<name>YeeAmosIec104IntfServer</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<drools.version>6.5.0.Final</drools.version> <drools.version>6.5.0.Final</drools.version>
</properties> </properties>
<parent>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosIec104IntfRoot</artifactId>
<version>1.0.0</version>
</parent>
<dependencies> <dependencies>
<!-- 安全模块jar --> <!-- 安全模块jar -->
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId> <artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId> <artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
......
package com.yeejoin.amos.iec104.tcp.client.invoke; package com.yeejoin.amos.iec104.tcp.client.invoke;
import java.util.LinkedList; import com.alibaba.fastjson.JSONObject;
import java.util.concurrent.BlockingQueue; import com.yeejoin.amos.connect.common.enums.RedisKeyEnum;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.yeejoin.amos.connect.dao.entity.PointConfigVo; import com.yeejoin.amos.connect.dao.entity.PointConfigVo;
import org.apache.log4j.Logger;
import org.springframework.util.ObjectUtils;
import com.yeejoin.amos.iec104.business.constants.IEC104Constant; import com.yeejoin.amos.iec104.business.constants.IEC104Constant;
import com.yeejoin.amos.iec104.business.param.AlarmParam; import com.yeejoin.amos.iec104.business.param.AlarmParam;
import com.yeejoin.amos.iec104.business.service.intfc.IClientListenService; import com.yeejoin.amos.iec104.business.service.intfc.IClientListenService;
import com.yeejoin.amos.iec104.business.service.intfc.IConfService; import com.yeejoin.amos.iec104.business.service.intfc.IConfService;
import com.yeejoin.amos.iec104.business.service.intfc.IPointConfigService; import com.yeejoin.amos.iec104.business.service.intfc.IPointConfigService;
import com.yeejoin.amos.iec104.context.FireAutoIntfContext; import com.yeejoin.amos.iec104.context.FireAutoIntfContext;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.LinkedList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class GeneralDataQueue { public class GeneralDataQueue {
private static final BlockingQueue<AlarmParam> blockingQueue = new LinkedBlockingQueue<AlarmParam>(); private static final BlockingQueue<AlarmParam> blockingQueue = new LinkedBlockingQueue<AlarmParam>();
...@@ -26,19 +30,22 @@ public class GeneralDataQueue { ...@@ -26,19 +30,22 @@ public class GeneralDataQueue {
IConfService confService; IConfService confService;
private volatile static GeneralDataQueue instance = null; private volatile static GeneralDataQueue instance = null;
@Autowired
private RedisTemplate<String, String> redisTemplate;
private GeneralDataQueue() { private GeneralDataQueue() {
clientListenService = (IClientListenService) FireAutoIntfContext.getInstance().getBean(IClientListenService.class); clientListenService = (IClientListenService) FireAutoIntfContext.getInstance().getBean(IClientListenService.class);
confService = (IConfService) FireAutoIntfContext.getInstance().getBean(IConfService.class); confService = (IConfService) FireAutoIntfContext.getInstance().getBean(IConfService.class);
pointConfigService = (IPointConfigService) FireAutoIntfContext.getInstance().getBean(IPointConfigService.class); pointConfigService = (IPointConfigService) FireAutoIntfContext.getInstance().getBean(IPointConfigService.class);
} }
public static GeneralDataQueue getInstance(){ public static GeneralDataQueue getInstance() {
//先检查实例是否存在,如果不存在才进入下面的同步块 //先检查实例是否存在,如果不存在才进入下面的同步块
if(instance == null){ if (instance == null) {
//同步块,线程安全的创建实例 //同步块,线程安全的创建实例
synchronized(GeneralDataQueue.class){ synchronized (GeneralDataQueue.class) {
//再次检查实例是否存在,如果不存在才真的创建实例 //再次检查实例是否存在,如果不存在才真的创建实例
if(instance == null){ if (instance == null) {
instance = new GeneralDataQueue(); instance = new GeneralDataQueue();
} }
} }
...@@ -60,10 +67,31 @@ public class GeneralDataQueue { ...@@ -60,10 +67,31 @@ public class GeneralDataQueue {
} }
Runnable task_runnable = new Runnable() { Runnable task_runnable = new Runnable() {
private boolean alarmParamIsChange(AlarmParam alarmParam) {
String redisKey = RedisKeyEnum.buildKey(alarmParam.getPointCode(), RedisKeyEnum.K001);
String data = redisTemplate.opsForValue().get(redisKey);
if (StringUtils.isEmpty(data)) {
redisTemplate.opsForValue().set(redisKey, JSONObject.toJSONString(alarmParam));
return true;
} else {
AlarmParam oldAlarmParam = JSONObject.parseObject(data, AlarmParam.class);
if (oldAlarmParam.getState().equals(alarmParam.getState())) {
return false;
} else {
redisTemplate.opsForValue().set(redisKey, JSONObject.toJSONString(alarmParam));
return true;
}
}
}
public void run() { public void run() {
while(true) { while (true) {
try { try {
AlarmParam param1 = blockingQueue.take(); AlarmParam param1 = blockingQueue.take();
if (!alarmParamIsChange(param1)) {
return;
}
LinkedList<AlarmParam> datas = new LinkedList<AlarmParam>(); LinkedList<AlarmParam> datas = new LinkedList<AlarmParam>();
PointConfigVo vo = pointConfigService.findByServicesIdAndInfoAddress(param1.getServiceId(), Integer.valueOf(param1.getInformationAddress())); PointConfigVo vo = pointConfigService.findByServicesIdAndInfoAddress(param1.getServiceId(), Integer.valueOf(param1.getInformationAddress()));
param1.setPointCode(vo.getPointCode()); param1.setPointCode(vo.getPointCode());
...@@ -87,7 +115,7 @@ public class GeneralDataQueue { ...@@ -87,7 +115,7 @@ public class GeneralDataQueue {
} else { } else {
isEmpty = true; isEmpty = true;
} }
} while(!isEmpty); } while (!isEmpty);
try { try {
if (!ObjectUtils.isEmpty(datas)) { if (!ObjectUtils.isEmpty(datas)) {
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas); clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
...@@ -102,4 +130,6 @@ public class GeneralDataQueue { ...@@ -102,4 +130,6 @@ public class GeneralDataQueue {
} }
} }
}; };
} }
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId> <artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId> <artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment