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">
<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>
<artifactId>YeeAmosConnectStart</artifactId>
<name>YeeAmosConnectStart</name>
<parent> <dependencies>
<groupId>com.yeejoin.amos</groupId> <!-- 业务模块jar -->
<artifactId>YeeAmosConnectRoot</artifactId> <dependency>
<version>1.0.0</version> <groupId>com.yeejoin.amos</groupId>
</parent> <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> <!-- maven打包时将lib提取到jar同目录,将配置文件提取到jar目录/config/下 -->
<!-- 业务模块jar --> <build>
<dependency> <resources>
<groupId>com.yeejoin.amos</groupId> <!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 -->
<artifactId>YeeAmosConnentCommon</artifactId> <resource>
<version>${iec104.version}</version> <directory>src/main/resources</directory>
</dependency> <includes>
<dependency> <include>**/*</include>
<groupId>com.yeejoin.amos</groupId> </includes>
<artifactId>YeeAmosIec104IntfServer</artifactId> <!-- 过滤不需要引用的文件 -->
<version>${iec104.version}</version> <excludes>
</dependency> <exclude>package.xml</exclude>
<dependency> </excludes>
<groupId>com.yeejoin.amos</groupId> </resource>
<artifactId>YeeAmosUartServer</artifactId> </resources>
<version>${iec104.version}</version> <plugins>
</dependency> <plugin>
</dependencies> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<!-- maven打包时将lib提取到jar同目录,将配置文件提取到jar目录/config/下 --> <configuration>
<build> <archive>
<resources> <!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 -->
<!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 --> <!-- <index>true</index> -->
<resource> <manifest>
<directory>src/main/resources</directory> <mainClass>com.yeejoin.amos.YeeAmosIec104IntfStart</mainClass>
<includes> <!-- to create a class path to your dependecies you have to fill true
<include>**/*</include> in this field -->
</includes> <addClasspath>true</addClasspath>
<!-- 过滤不需要引用的文件 --> <classpathPrefix>lib/</classpathPrefix>
<excludes> <!--<classpathLayoutType>custom</classpathLayoutType> <customClasspathLayout>
<exclude>package.xml</exclude> lib/ artifact.groupId. {artifact.artifactId}.$${artifact.extension} </customClasspathLayout> -->
</excludes> </manifest>
</resource> <manifestEntries>
</resources> <Class-Path>./</Class-Path>
<plugins> </manifestEntries>
<plugin> </archive>
<groupId>org.apache.maven.plugins</groupId> <!-- <excludes> <exclude>config/**</exclude> </excludes> -->
<artifactId>maven-jar-plugin</artifactId> <includes>
<configuration> <include>**/**.class</include>
<archive> </includes>
<!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 --> </configuration>
<!-- <index>true</index> --> </plugin>
<manifest> <plugin>
<mainClass>com.yeejoin.amos.YeeAmosIec104IntfStart</mainClass> <artifactId>maven-assembly-plugin</artifactId>
<!-- to create a class path to your dependecies you have to fill true <configuration>
in this field --> <!-- not append assembly id in release file name -->
<addClasspath>true</addClasspath> <appendAssemblyId>false</appendAssemblyId>
<classpathPrefix>lib/</classpathPrefix> <descriptors>
<!--<classpathLayoutType>custom</classpathLayoutType> <customClasspathLayout> <descriptor>src/main/resources/package.xml</descriptor>
lib/ artifact.groupId. {artifact.artifactId}.$${artifact.extension} </customClasspathLayout> --> </descriptors>
</manifest> </configuration>
<manifestEntries> <executions>
<Class-Path>./</Class-Path> <execution>
</manifestEntries> <id>make-assembly</id>
</archive> <phase>package</phase>
<!-- <excludes> <exclude>config/**</exclude> </excludes> --> <goals>
<includes> <goal>single</goal>
<include>**/**.class</include> </goals>
</includes> </execution>
</configuration> </executions>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <groupId>org.springframework.boot</groupId>
<configuration> <artifactId>spring-boot-maven-plugin</artifactId>
<!-- not append assembly id in release file name --> <executions>
<appendAssemblyId>false</appendAssemblyId> <execution>
<descriptors> <goals>
<descriptor>src/main/resources/package.xml</descriptor> <goal>repackage</goal>
</descriptors> </goals>
</configuration> </execution>
<executions> </executions>
<execution> </plugin>
<id>make-assembly</id> <plugin>
<phase>package</phase> <artifactId>maven-compiler-plugin</artifactId>
<goals> <configuration>
<goal>single</goal> <source>1.8</source>
</goals> <target>1.8</target>
</execution> </configuration>
</executions> </plugin>
</plugin> </plugins>
<plugin> </build>
<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> </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" <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>
<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 -->
<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>
<dependency> <dependency>
<groupId>com.yeejoin.amos</groupId> <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> <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>();
ScheduledExecutorService service_general = null; ScheduledExecutorService service_general = null;
IClientListenService clientListenService; IClientListenService clientListenService;
IPointConfigService pointConfigService; IPointConfigService pointConfigService;
IConfService confService; IConfService confService;
private volatile static GeneralDataQueue instance = null; private volatile static GeneralDataQueue instance = null;
private GeneralDataQueue() { @Autowired
clientListenService = (IClientListenService) FireAutoIntfContext.getInstance().getBean(IClientListenService.class); private RedisTemplate<String, String> redisTemplate;
confService = (IConfService) FireAutoIntfContext.getInstance().getBean(IConfService.class);
pointConfigService = (IPointConfigService) FireAutoIntfContext.getInstance().getBean(IPointConfigService.class); private GeneralDataQueue() {
} clientListenService = (IClientListenService) FireAutoIntfContext.getInstance().getBean(IClientListenService.class);
confService = (IConfService) FireAutoIntfContext.getInstance().getBean(IConfService.class);
public static GeneralDataQueue getInstance(){ pointConfigService = (IPointConfigService) FireAutoIntfContext.getInstance().getBean(IPointConfigService.class);
//先检查实例是否存在,如果不存在才进入下面的同步块
if(instance == null){
//同步块,线程安全的创建实例
synchronized(GeneralDataQueue.class){
//再次检查实例是否存在,如果不存在才真的创建实例
if(instance == null){
instance = new GeneralDataQueue();
}
}
}
return instance;
} }
public static GeneralDataQueue getInstance() {
//先检查实例是否存在,如果不存在才进入下面的同步块
if (instance == null) {
//同步块,线程安全的创建实例
synchronized (GeneralDataQueue.class) {
//再次检查实例是否存在,如果不存在才真的创建实例
if (instance == null) {
instance = new GeneralDataQueue();
}
}
}
return instance;
}
/** /**
* 启动apdu数据消费任务 * 启动apdu数据消费任务
*/ */
public void start() { 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) { Runnable task_runnable = new Runnable() {
blockingQueue.add(recData);
} private boolean alarmParamIsChange(AlarmParam alarmParam) {
String redisKey = RedisKeyEnum.buildKey(alarmParam.getPointCode(), RedisKeyEnum.K001);
Runnable task_runnable = new Runnable() { 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();
LinkedList<AlarmParam> datas = new LinkedList<AlarmParam>(); if (!alarmParamIsChange(param1)) {
PointConfigVo vo = pointConfigService.findByServicesIdAndInfoAddress(param1.getServiceId(), Integer.valueOf(param1.getInformationAddress())); return;
param1.setPointCode(vo.getPointCode()); }
datas.add(param1); LinkedList<AlarmParam> datas = new LinkedList<AlarmParam>();
boolean isEmpty = false; PointConfigVo vo = pointConfigService.findByServicesIdAndInfoAddress(param1.getServiceId(), Integer.valueOf(param1.getInformationAddress()));
do { param1.setPointCode(vo.getPointCode());
AlarmParam param = blockingQueue.poll(1, TimeUnit.SECONDS); datas.add(param1);
if (!ObjectUtils.isEmpty(param)) { boolean isEmpty = false;
PointConfigVo vo1 = pointConfigService.findByServicesIdAndInfoAddress(param.getServiceId(), Integer.valueOf(param.getInformationAddress())); do {
if (!ObjectUtils.isEmpty(vo1)) { AlarmParam param = blockingQueue.poll(1, TimeUnit.SECONDS);
if (!ObjectUtils.isEmpty(param)) {
param.setPointCode(vo1.getPointCode()); PointConfigVo vo1 = pointConfigService.findByServicesIdAndInfoAddress(param.getServiceId(), Integer.valueOf(param.getInformationAddress()));
datas.add(param); if (!ObjectUtils.isEmpty(vo1)) {
if (datas.size() > 10000) {
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas); param.setPointCode(vo1.getPointCode());
datas.clear(); datas.add(param);
} if (datas.size() > 10000) {
} else { clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
Logger.getLogger(this.getClass()).error(param.getServiceId() + " have not " + param.getInformationAddress()); datas.clear();
} }
} else { } else {
isEmpty = true; Logger.getLogger(this.getClass()).error(param.getServiceId() + " have not " + param.getInformationAddress());
} }
} while(!isEmpty); } else {
try { isEmpty = true;
if (!ObjectUtils.isEmpty(datas)) { }
clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas); } while (!isEmpty);
} try {
datas.clear(); if (!ObjectUtils.isEmpty(datas)) {
} catch (Exception e) { clientListenService.sendDatas(IEC104Constant.GENERAL_MESSAGE, datas);
} }
} catch (Exception e) { datas.clear();
Logger.getLogger(this.getClass()).error(e.getMessage()); } catch (Exception e) {
e.printStackTrace(); }
} } catch (Exception e) {
Logger.getLogger(this.getClass()).error(e.getMessage());
e.printStackTrace();
}
} }
} }
}; };
} }
...@@ -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