Commit 604464f5 authored by qinhu's avatar qinhu

jna 和 波形图 过滤

parent 02de534a
......@@ -90,6 +90,7 @@
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
......@@ -108,5 +109,6 @@
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -13,7 +13,21 @@
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--名字生成第三方包-->
<dependency>
<groupId>com.simplename</groupId>
<artifactId>jna</artifactId>
<version>5.6.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jna-5.6.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.simplename</groupId>
<artifactId>jna-platform</artifactId>
<version>5.6.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jna-platform-5.6.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
......@@ -146,6 +160,17 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<!-- 指定该Main Class为全局的唯一入口 -->
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
......@@ -13,6 +13,12 @@ import org.springframework.scheduling.annotation.EnableScheduling;
public class PowerPlantApplication {
public static void main(String[] args) {
SpringApplication.run(PowerPlantApplication.class, args);
WaveAnalysis.waveAnalysisModel("{}");
String str = "{\"Record\":{\"Data\":{\"Data\":[{\"Data\":[14.5446,19.6776,33.1913,35.8237,30.389],\"KKSCode\":\"c0a00101mka12cy616r\",\"KeyPhaseOffset\":[],\"Period\":1}],\"Direction\":0,\"GenerationFreq\":50,\"KeyPhaseTyped\":1,\"PoleNum\":2,\"RecordFlag\":1}},\"StartTime\":1597126940000,\"TimeSpan\":1280}";
System.out.println("===========调用开始================");
System.out.println("参数从信息:===");
System.out.println(str);
String s = WaveAnalysis.INSTANCE.WaveAnalysisModel(str);
System.out.println("===========================");
System.out.println("结果:" + s);
}
}
......@@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotEmpty;
import java.io.BufferedReader;
import java.io.InputStreamReader;
......@@ -78,74 +79,7 @@ public class CharacterParamController {
@PostMapping("/oscillogram")
public BaseResponse<List<Oscillogram>> oscillogram(@RequestBody List<String> kksCodes) {
List<Filter> filters = new ArrayList<>(kksCodes.size());
for (String kkscode : kksCodes) {
RowFilter filter = new RowFilter(CompareFilter.CompareOp.EQUAL
, new SubstringComparator(StrUtil.swapCase(kkscode)));
filters.add(filter);
}
FilterList filterList = new FilterList(filters);
Scan scan1 = new Scan();
scan1.setCaching(10000);
scan1.setFilter(filterList);
scan1.addFamily(Bytes.toBytes("records"));
OscillogramRowMapper oscillogramRowMapper = new OscillogramRowMapper();
List<Oscillogram> oscillograms = hbaseTemplate.find("thermalpower-plant-wave-data",
scan1, oscillogramRowMapper);
Scan scan2 = new Scan();
scan2.setCaching(10000);
scan2.setFilter(filterList);
scan2.addFamily(Bytes.toBytes("tags"));
OscillogramTagsMapper oscillogramRowMapper2 = new OscillogramTagsMapper();
List<Oscillogram> oscillogramsTags = hbaseTemplate.find("thermalpower-plant-wave-data",
scan2, oscillogramRowMapper2);
System.out.println("=================波形图数据====================");
System.out.println(oscillograms.size());
System.out.println(oscillogramsTags.size());
//关联tags
oscillograms.forEach(arg -> oscillogramsTags.forEach(opt -> {
if (opt.getRowKey().equals(arg.getRowKey())) {
arg.setTimeSpan(opt.getTimeSpan());
arg.getMapData();
arg.setRecordFlag(opt.getRecordFlag());
}
}));
List<CharacterParamInfo> characterParamInfos = iCharacterParamService.getByKksCodes(kksCodes);
List<Oscillogram> rts = new ArrayList<>(oscillograms.size());
for (Oscillogram oscillogram : oscillograms) {
characterParamInfos.forEach(arg -> {
if (oscillogram.getKKsCode().equals(arg.getKksCode())) {
rts.add(oscillogram);
}
});
}
// FrequencyQuery frequencyQuery = new FrequencyQuery();
// FrequencyQuery.Record record = new FrequencyQuery.Record();
// FrequencyQuery.DataOut dataOut = new FrequencyQuery.DataOut();
// frequencyQuery.setRecord(record);
// frequencyQuery.getRecord().setData(dataOut);
// frequencyQuery.getRecord().getData().setData(new ArrayList<>());
// for (Oscillogram oscillogram : rts) {
// FrequencyQuery.DataIn dataIn = new FrequencyQuery.DataIn();
// dataIn.setKKSCode(oscillogram.getKKsCode());
// dataIn.setData(oscillogram.getMapData());
// dataIn.setKeyPhaseOffset(oscillogram.getNoVersionKeyPhaseOffset());
// dataIn.setPeriod(oscillogram.getPeriod());
// dataOut.setDirection(0);
// dataOut.setGenerationFreq(oscillogram.getGenerationFreq());
// dataOut.setRecordFlag(oscillogram.getRecordFlag());
// dataOut.setPoleNum(oscillogram.getPoleNum());
// frequencyQuery.getRecord().getData().getData().add(dataIn);
// }
//
// iCharacterParamService.getFrequency(JSON.toJSONString(rts));
return BaseResponse.okData(rts);
return BaseResponse.okData(iCharacterParamService.getOscillogram(kksCodes));
}
@PostMapping("/upload")
......@@ -169,4 +103,5 @@ public class CharacterParamController {
return BaseResponse.okDataMsg(false, "上传失败!");
}
}
}
......@@ -55,4 +55,9 @@ public class UserInfoController {
return iUserInfoService.edit(userInfo);
}
public static void main(String[] args) {
String str = "{\"Record\":{\"Data\":{\"Data\":[{\"Data\":[14.5446,19.6776,33.1913,35.8237,30.389],\"KKSCode\":\"c0a00101mka12cy616r\",\"KeyPhaseOffset\":[],\"Period\":1}],\"Direction\":0,\"GenerationFreq\":50,\"KeyPhaseTyped\":1,\"PoleNum\":2,\"RecordFlag\":1}},\"StartTime\":1597126940000,\"TimeSpan\":1280}";
System.out.println(str);
}
}
package cn.wise.sc.energy.power.plant.business.domain;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.List;
......@@ -15,18 +16,22 @@ public class FrequencyQuery {
/**
* 开始时间
*/
private Long StartTime;
@JSONField(name = "StartTime")
private Long startTime;
/**
* 时间间隔
*/
private Long TimeSpan;
@JSONField(name = "TimeSpan")
private Long timeSpan;
@JSONField(name = "Record")
private Record record;
@lombok.Data
public static class Record{
private DataOut Data;
@JSONField(name = "Record")
private DataOut data;
}
@lombok.Data
......@@ -34,28 +39,33 @@ public class FrequencyQuery {
/**
* 键相类型为波形数据数组下标
*/
private Integer KeyPhaseTyped = 1;
@JSONField(name = "KeyPhaseTyped")
private Integer keyPhaseTyped = 1;
/**
* 磁极数目
*/
private Integer PoleNum;
@JSONField(name = "PoleNum")
private Integer poleNum;
/**
* 发电机频率单位(Hz)
*/
private String GenerationFreq;
@JSONField(name = "GenerationFreq")
private String generationFreq;
/**
* 旋转方向(0:顺时针,1:逆时针)
*/
private Integer Direction;
@JSONField(name = "Direction")
private Integer direction;
/**
* 记录类型(0:连续采样,1定时采样:)
*/
private Integer RecordFlag;
private List<DataIn> Data;
@JSONField(name = "RecordFlag")
private Integer recordFlag;
@JSONField(name = "Data")
private List<DataIn> data;
}
@Data
......@@ -64,21 +74,25 @@ public class FrequencyQuery {
/**
* 测点对应KKS编码
*/
private String KKSCode;
@JSONField(name = "KKSCode")
private String kKSCode;
/**
* 样包采样周期数
*/
private Integer Period;
@JSONField(name = "Period")
private Integer period;
/**
* 各键相点相对起始时间偏移
*/
private String KeyPhaseOffset;
@JSONField(name = "KeyPhaseOffset")
private String keyPhaseOffset;
/**
* 数据区域
*/
private String Data;
@JSONField(name = "Data")
private String data;
}
}
......@@ -49,7 +49,7 @@ public class Oscillogram {
private Integer recordFlag;
private String startTime;
private Long startTime;
private String rowKey;
......
package cn.wise.sc.energy.power.plant.business.jni;
import com.sun.jna.Library;
import com.sun.jna.Native;
/**
* @description:
* @author: qh
* @create: 2020-08-24 19:40
**/
public class WaveAnalysis{
public interface WaveAnalysis extends Library {
String dllPath = "libGMWaveAnalysisModel.so";
WaveAnalysis INSTANCE = Native.load(dllPath, WaveAnalysis.class);
public static native String waveAnalysisModel(String jstr);
String WaveAnalysisModel(String jstr);
}
......@@ -4,11 +4,14 @@ import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.util.StringUtils;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
......@@ -16,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;
import static cn.wise.sc.energy.power.plant.business.security.SecurityConstants.AUTHORIZATION_HEADER;
import static cn.wise.sc.energy.power.plant.business.security.SecurityConstants.TOKEN_PREFIX;
......@@ -38,12 +42,20 @@ public class JWTFilter extends BasicAuthenticationFilter {
filterChain.doFilter(request, response);
return;
}
final Claims claims = Jwts.parserBuilder()
Claims claims;
try {
claims = Jwts.parserBuilder()
.setSigningKey(JWTKeyHolder.KEY)
.build()
.parseClaimsJws(token)
.getBody();
} catch (Exception e) {
response.setStatus(401);
filterChain.doFilter(request, response);
return;
}
final UserDetails userDetails = this.userDetailsService
.loadUserByUsername(claims.getSubject());
SecurityContextHolder.getContext()
......
......@@ -4,6 +4,7 @@ import cn.wise.sc.energy.power.plant.business.bean.DataPower;
import cn.wise.sc.energy.power.plant.business.bean.TimeModelQuery;
import cn.wise.sc.energy.power.plant.business.domain.CharacterParamInfo;
import cn.wise.sc.energy.power.plant.business.domain.Frequency;
import cn.wise.sc.energy.power.plant.business.domain.Oscillogram;
import cn.wise.sc.energy.power.plant.business.domain.vo.CharacterParamInfoVo;
import cn.wise.sc.energy.power.plant.business.domain.vo.EntityVo;
import cn.wise.sc.energy.power.plant.common.core.bean.BaseResponse;
......@@ -106,4 +107,10 @@ public interface ICharacterParamService extends IBaseService<String, CharacterPa
* @return list
*/
List<Frequency> getFrequency(String toJSONString);
/**
* 获取波形图
* @param kksCodes kkscode
*/
List<Oscillogram> getOscillogram(List<String> kksCodes);
}
......@@ -5,10 +5,15 @@ import cn.wise.sc.energy.power.plant.business.bean.DataPower;
import cn.wise.sc.energy.power.plant.business.bean.TimeModelQuery;
import cn.wise.sc.energy.power.plant.business.domain.CharacterParamInfo;
import cn.wise.sc.energy.power.plant.business.domain.Frequency;
import cn.wise.sc.energy.power.plant.business.domain.FrequencyQuery;
import cn.wise.sc.energy.power.plant.business.domain.Oscillogram;
import cn.wise.sc.energy.power.plant.business.domain.OscillogramRowMapper;
import cn.wise.sc.energy.power.plant.business.domain.OscillogramTagsMapper;
import cn.wise.sc.energy.power.plant.business.domain.UnitInfo;
import cn.wise.sc.energy.power.plant.business.domain.eum.TendencyStatus;
import cn.wise.sc.energy.power.plant.business.domain.vo.CharacterParamInfoVo;
import cn.wise.sc.energy.power.plant.business.domain.vo.EntityVo;
import cn.wise.sc.energy.power.plant.business.jni.WaveAnalysis;
import cn.wise.sc.energy.power.plant.business.opentsdb.OpentsdbOkHttpClient;
import cn.wise.sc.energy.power.plant.business.opentsdb.bean.QueryExt;
import cn.wise.sc.energy.power.plant.business.opentsdb.bean.QueryRequestExt;
......@@ -17,14 +22,20 @@ import cn.wise.sc.energy.power.plant.business.repository.UnitInfoRepository;
import cn.wise.sc.energy.power.plant.business.service.ICharacterParamService;
import cn.wise.sc.energy.power.plant.common.core.bean.BaseResponse;
import cn.wise.sc.energy.power.plant.common.core.exception.ResponseEnum;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.spring4all.spring.boot.starter.hbase.api.HbaseTemplate;
import lombok.extern.slf4j.Slf4j;
import net.opentsdb.client.api.query.request.QueryLastRequest;
import net.opentsdb.client.api.query.response.QueryLastResponse;
import net.opentsdb.client.api.query.response.QueryResponse;
import net.opentsdb.client.bean.Aggregator;
import net.opentsdb.client.bean.LastDataPointQuery;
import net.opentsdb.client.bean.QueryResult;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.filter.SubstringComparator;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.domain.Specification;
......@@ -58,13 +69,17 @@ public class CharacterParamServiceImpl extends BaseServiceImpl<String, Character
CharacterParamRepository characterParamRepository;
final
UnitInfoRepository unitInfoRepository;
final
HbaseTemplate hbaseTemplate;
public CharacterParamServiceImpl(UnitInfoServiceImpl unitInfoService,
CharacterParamRepository characterParamRepository,
UnitInfoRepository unitInfoRepository) {
UnitInfoRepository unitInfoRepository,
HbaseTemplate hbaseTemplate) {
this.unitInfoService = unitInfoService;
this.characterParamRepository = characterParamRepository;
this.unitInfoRepository = unitInfoRepository;
this.hbaseTemplate = hbaseTemplate;
}
@Override
......@@ -319,11 +334,112 @@ public class CharacterParamServiceImpl extends BaseServiceImpl<String, Character
@Override
public List<Frequency> getFrequency(String toJSONString) {
//todo 调用C函数 获取频谱图
System.out.println("参数:");
System.out.println(toJSONString);
String s = WaveAnalysis.INSTANCE.WaveAnalysisModel(toJSONString);
System.out.println(s);
return null;
}
@Override
public List<Oscillogram> getOscillogram(List<String> kksCodes) {
//添加过滤器 过滤名字中包含kkscode
List<Filter> filters = new ArrayList<>(kksCodes.size());
for (String kkscode : kksCodes) {
RowFilter filter = new RowFilter(CompareFilter.CompareOp.EQUAL
, new SubstringComparator(StrUtil.swapCase(kkscode)));
filters.add(filter);
}
FilterList filterList = new FilterList(filters);
Scan scanRow = new Scan();
scanRow.setCaching(10000);
scanRow.setFilter(filterList);
scanRow.addFamily(Bytes.toBytes("records"));
scanRow.setReversed(true);
Scan scanTags = new Scan();
scanTags.setCaching(10000);
scanTags.setFilter(filterList);
scanTags.addFamily(Bytes.toBytes("tags"));
scanTags.setReversed(true);
OscillogramRowMapper oscillogramRowMapper = new OscillogramRowMapper();
List<Oscillogram> oscillograms = hbaseTemplate.find("thermalpower-plant-wave-data",
scanRow, oscillogramRowMapper);
OscillogramTagsMapper oscillogramRowMapper2 = new OscillogramTagsMapper();
List<Oscillogram> oscillogramsTags = hbaseTemplate.find("thermalpower-plant-wave-data",
scanTags, oscillogramRowMapper2);
System.out.println("=================波形图数据====================");
System.out.println(oscillograms.size());
System.out.println(oscillogramsTags.size());
//关联tags 这会很慢!!!
long start = System.currentTimeMillis();
System.out.println(start);
oscillogramsTags.forEach(opt -> {
oscillograms.forEach(arg -> {
if (opt.getRowKey().equals(arg.getRowKey())) {
arg.setTimeSpan(opt.getTimeSpan());
arg.getMapData();
arg.setRecordFlag(opt.getRecordFlag());
arg.setGenerationFreq(opt.getGenerationFreq());
arg.setPoleNum(opt.getPoleNum());
arg.setPeriod(opt.getPeriod());
}
});
});
//筛选最新的一条数据
List<CharacterParamInfo> characterParamInfos = this.getByKksCodes(kksCodes);
Map<String, Oscillogram> oscillogramLastMap = new HashMap<>(characterParamInfos.size());
for (Oscillogram oscillogram : oscillograms) {
characterParamInfos.forEach(arg -> {
String kKSCode = oscillogram.getKKsCode();
if (kKSCode.equals(arg.getKksCode())) {
if (oscillogramLastMap.containsKey(kKSCode)) {
//比较已存在的startTime大小
if (oscillogramLastMap.get(kKSCode).getStart() < oscillogram.getStart()) {
oscillogramLastMap.put(kKSCode, oscillogram);
}
} else {
oscillogramLastMap.put(kKSCode, oscillogram);
}
}
});
}
List<Oscillogram> rts = new ArrayList<>(oscillogramLastMap.size());
for (String key : oscillogramLastMap.keySet()) {
rts.add(oscillogramLastMap.get(key));
}
FrequencyQuery frequencyQuery = new FrequencyQuery();
FrequencyQuery.Record record = new FrequencyQuery.Record();
FrequencyQuery.DataOut dataOut = new FrequencyQuery.DataOut();
frequencyQuery.setRecord(record);
frequencyQuery.getRecord().setData(dataOut);
frequencyQuery.getRecord().getData().setData(new ArrayList<>());
for (Oscillogram oscillogram : rts) {
frequencyQuery.setStartTime(oscillogram.getStart());
frequencyQuery.setTimeSpan(oscillogram.getTimeSpan());
FrequencyQuery.DataIn dataIn = new FrequencyQuery.DataIn();
dataIn.setKKSCode(StrUtil.swapCase(oscillogram.getKKsCode()));
dataIn.setData(oscillogram.getMapData());
dataIn.setKeyPhaseOffset(oscillogram.getNoVersionKeyPhaseOffset());
dataIn.setPeriod(oscillogram.getPeriod());
dataOut.setDirection(0);
dataOut.setGenerationFreq(oscillogram.getGenerationFreq());
dataOut.setRecordFlag(oscillogram.getRecordFlag());
dataOut.setPoleNum(oscillogram.getPoleNum());
frequencyQuery.getRecord().getData().getData().add(dataIn);
}
getFrequency(JSON.toJSONString(frequencyQuery));
return rts;
}
private DataPower buildDataPower(List<QueryResult> results,
List<CharacterParamInfo> characterParamInfos) {
......
......@@ -53,8 +53,8 @@ spring:
nodeParent: /hbase-unsecure
redisson:
master-name: mymaster
address: redis://127.0.0.1:6379
# password: Risen12348765
address: redis://127.0.0.1:6378
password: Risen12348765
subscriptionConnectionMinimumIdleSize: 1
dnsMonitoring: false
failedAttempts: 2
......
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