Commit 1416f2a1 authored by xukaiqiang's avatar xukaiqiang

git

parent 3a29e559
......@@ -3,13 +3,13 @@
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">
<parent>
<artifactId>YeeAmosIec104IntfRoot</artifactId>
<artifactId>YeeAmosConnectRoot</artifactId>
<groupId>com.yeejoin.amos</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>YeeAmosConnectCommon</artifactId>
</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"
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>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>YeeAmosConnectStart</artifactId>
<name>YeeAmosConnectStart</name>
<artifactId>YeeAmosConnectStart</artifactId>
<parent>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnectRoot</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<!-- 业务模块jar -->
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosIec104IntfServer</artifactId>
<version>${iec104.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.yeejoin.amos</groupId>-->
<!-- <artifactId>YeeAmosUartServer</artifactId>-->
<!-- <version>${iec104.version}</version>-->
<!-- </dependency>-->
</dependencies>
<dependencies>
<!-- 业务模块jar -->
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId>
<version>${iec104.version}</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosIec104IntfServer</artifactId>
<version>${iec104.version}</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosUartServer</artifactId>
<version>${iec104.version}</version>
</dependency>
</dependencies>
<!-- maven打包时将lib提取到jar同目录,将配置文件提取到jar目录/config/下 -->
<build>
<resources>
<!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<!-- 过滤不需要引用的文件 -->
<excludes>
<exclude>package.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 -->
<!-- <index>true</index> -->
<manifest>
<mainClass>com.yeejoin.amos.YeeAmosIec104IntfStart</mainClass>
<!-- to create a class path to your dependecies you have to fill true
in this field -->
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<!--<classpathLayoutType>custom</classpathLayoutType> <customClasspathLayout>
lib/ artifact.groupId. {artifact.artifactId}.$${artifact.extension} </customClasspathLayout> -->
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
<!-- <excludes> <exclude>config/**</exclude> </excludes> -->
<includes>
<include>**/**.class</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- not append assembly id in release file name -->
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- maven打包时将lib提取到jar同目录,将配置文件提取到jar目录/config/下 -->
<build>
<resources>
<!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<!-- 过滤不需要引用的文件 -->
<excludes>
<exclude>package.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 -->
<!-- <index>true</index> -->
<manifest>
<mainClass>com.yeejoin.amos.YeeAmosIec104IntfStart</mainClass>
<!-- to create a class path to your dependecies you have to fill true
in this field -->
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<!--<classpathLayoutType>custom</classpathLayoutType> <customClasspathLayout>
lib/ artifact.groupId. {artifact.artifactId}.$${artifact.extension} </customClasspathLayout> -->
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
<!-- <excludes> <exclude>config/**</exclude> </excludes> -->
<includes>
<include>**/**.class</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- not append assembly id in release file name -->
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<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>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>YeeAmosIec104IntfServer</artifactId>
<name>YeeAmosIec104IntfServer</name>
<artifactId>YeeAmosIec104IntfServer</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<drools.version>6.5.0.Final</drools.version>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<drools.version>6.5.0.Final</drools.version>
</properties>
<parent>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosIec104IntfRoot</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<!-- 安全模块jar -->
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>AmosOPService</artifactId>
<version>${YeeOp.version}</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>amos-authtoken</artifactId>
<version>${YeeSecurity.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependencies>
<!-- 安全模块jar -->
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId>
<artifactId>AmosOPService</artifactId>
<version>${YeeOp.version}</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>amos-authtoken</artifactId>
<version>${YeeSecurity.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
......
package com.yeejoin.amos.iec104.tcp.client.invoke;
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;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.connect.common.enums.RedisKeyEnum;
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.param.AlarmParam;
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.IPointConfigService;
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 {
private static final BlockingQueue<AlarmParam> blockingQueue = new LinkedBlockingQueue<AlarmParam>();
ScheduledExecutorService service_general = null;
IClientListenService clientListenService;
IPointConfigService pointConfigService;
IConfService confService;
private volatile static GeneralDataQueue instance = null;
private GeneralDataQueue() {
clientListenService = (IClientListenService) FireAutoIntfContext.getInstance().getBean(IClientListenService.class);
confService = (IConfService) FireAutoIntfContext.getInstance().getBean(IConfService.class);
pointConfigService = (IPointConfigService) FireAutoIntfContext.getInstance().getBean(IPointConfigService.class);
}
public static GeneralDataQueue getInstance(){
//先检查实例是否存在,如果不存在才进入下面的同步块
if(instance == null){
//同步块,线程安全的创建实例
synchronized(GeneralDataQueue.class){
//再次检查实例是否存在,如果不存在才真的创建实例
if(instance == null){
instance = new GeneralDataQueue();
}
}
}
return instance;
private static final BlockingQueue<AlarmParam> blockingQueue = new LinkedBlockingQueue<AlarmParam>();
ScheduledExecutorService service_general = null;
IClientListenService clientListenService;
IPointConfigService pointConfigService;
IConfService confService;
private volatile static GeneralDataQueue instance = null;
@Autowired
private RedisTemplate<String, String> redisTemplate;
private GeneralDataQueue() {
clientListenService = (IClientListenService) FireAutoIntfContext.getInstance().getBean(IClientListenService.class);
confService = (IConfService) FireAutoIntfContext.getInstance().getBean(IConfService.class);
pointConfigService = (IPointConfigService) FireAutoIntfContext.getInstance().getBean(IPointConfigService.class);
}
public static GeneralDataQueue getInstance() {
//先检查实例是否存在,如果不存在才进入下面的同步块
if (instance == null) {
//同步块,线程安全的创建实例
synchronized (GeneralDataQueue.class) {
//再次检查实例是否存在,如果不存在才真的创建实例
if (instance == null) {
instance = new GeneralDataQueue();
}
}
}
return instance;
}
/**
* 启动apdu数据消费任务
*/
public void start() {
service_general = Executors.newSingleThreadScheduledExecutor();
service_general = Executors.newSingleThreadScheduledExecutor();
// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间
service_general.scheduleAtFixedRate(task_runnable, 5, 10, TimeUnit.SECONDS);
service_general.scheduleAtFixedRate(task_runnable, 5, 10, TimeUnit.SECONDS);
}
public void add(AlarmParam recData) {
blockingQueue.add(recData);
}
public void add(AlarmParam recData) {
blockingQueue.add(recData);
}
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() {
while(true) {
try {
AlarmParam param1 = blockingQueue.take();
LinkedList<AlarmParam> datas = new LinkedList<AlarmParam>();
PointConfigVo vo = pointConfigService.findByServicesIdAndInfoAddress(param1.getServiceId(), Integer.valueOf(param1.getInformationAddress()));
param1.setPointCode(vo.getPointCode());
datas.add(param1);
boolean isEmpty = false;
do {
AlarmParam param = blockingQueue.poll(1, TimeUnit.SECONDS);
if (!ObjectUtils.isEmpty(param)) {
PointConfigVo vo1 = pointConfigService.findByServicesIdAndInfoAddress(param.getServiceId(), Integer.valueOf(param.getInformationAddress()));
if (!ObjectUtils.isEmpty(vo1)) {
param.setPointCode(vo1.getPointCode());
datas.add(param);
if (datas.size() > 10000) {
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
datas.clear();
}
} else {
Logger.getLogger(this.getClass()).error(param.getServiceId() + " have not " + param.getInformationAddress());
}
} else {
isEmpty = true;
}
} while(!isEmpty);
try {
if (!ObjectUtils.isEmpty(datas)) {
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
}
datas.clear();
} catch (Exception e) {
}
} catch (Exception e) {
Logger.getLogger(this.getClass()).error(e.getMessage());
e.printStackTrace();
}
while (true) {
try {
AlarmParam param1 = blockingQueue.take();
if (!alarmParamIsChange(param1)) {
return;
}
LinkedList<AlarmParam> datas = new LinkedList<AlarmParam>();
PointConfigVo vo = pointConfigService.findByServicesIdAndInfoAddress(param1.getServiceId(), Integer.valueOf(param1.getInformationAddress()));
param1.setPointCode(vo.getPointCode());
datas.add(param1);
boolean isEmpty = false;
do {
AlarmParam param = blockingQueue.poll(1, TimeUnit.SECONDS);
if (!ObjectUtils.isEmpty(param)) {
PointConfigVo vo1 = pointConfigService.findByServicesIdAndInfoAddress(param.getServiceId(), Integer.valueOf(param.getInformationAddress()));
if (!ObjectUtils.isEmpty(vo1)) {
param.setPointCode(vo1.getPointCode());
datas.add(param);
if (datas.size() > 10000) {
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
datas.clear();
}
} else {
Logger.getLogger(this.getClass()).error(param.getServiceId() + " have not " + param.getInformationAddress());
}
} else {
isEmpty = true;
}
} while (!isEmpty);
try {
if (!ObjectUtils.isEmpty(datas)) {
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
}
datas.clear();
} catch (Exception e) {
}
} catch (Exception e) {
Logger.getLogger(this.getClass()).error(e.getMessage());
e.printStackTrace();
}
}
}
};
}
......@@ -13,7 +13,7 @@
<dependencies>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId>
<artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
......
......@@ -19,7 +19,7 @@
</dependency>
<dependency>
<groupId>com.yeejoin.amos</groupId>
<artifactId>YeeAmosConnentCommon</artifactId>
<artifactId>YeeAmosConnectCommon</artifactId>
<version>1.0.0</version>
</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