1.添加安全登录功能

2.调整部分接口
This commit is contained in:
2024-08-13 16:14:45 +08:00
parent 7449efc6a3
commit 9617f3d975
5 changed files with 127 additions and 53 deletions

View File

@@ -149,6 +149,11 @@
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@@ -0,0 +1,19 @@
package com.njcn.roma.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class Security extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin().and().authorizeRequests().anyRequest().authenticated().and().csrf().disable();
}
}

View File

@@ -112,7 +112,7 @@ public class TestController {
for(int i=0;i<300;i++){ for(int i=0;i<1000;i++){
JSONObject map = JSONObject.parseObject(clientHandler.topicMsg); JSONObject map = JSONObject.parseObject(clientHandler.topicMsg);
map.put("customDevId",clientHandler.devId); map.put("customDevId",clientHandler.devId);
double vA = Double.valueOf(map.get("PhV_phsA").toString()); double vA = Double.valueOf(map.get("PhV_phsA").toString());
@@ -160,6 +160,7 @@ public class TestController {
try { try {
Thread.sleep(1000); Thread.sleep(1000);
//Thread.sleep(180000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@@ -1,9 +1,17 @@
server: server:
port: 8790 port: 8790
servlet:
session:
timeout: 1440m
spring: spring:
security:
user:
name: data_njcn
password: dnzl@#002
application: application:
name: roma name: roma
roma: roma:
acceptIp: 25.36.190.3:19776 acceptIp: 25.36.190.3:19776
sendIp: 25.36.190.7:11443 sendIp: 25.36.190.7:11443

View File

@@ -13,37 +13,39 @@
<div> <div>
<button id="buttonHistory">历史趋势</button> <button id="buttonHistory">历史趋势</button>
<button id="buttonPinPu">谐波频谱</button> <button id="buttonPinPu">谐波频谱</button>
<label>设备标识:</label> <label>设备标识:</label>
<select id="selectId"> <select id="selectId">
<option value="NJCN230497">NJCN230497</option> <option value="NJCN230497">NJCN230497</option>
<option value="NJCN230497">NJCN230447</option> <option value="NJCN230497">NJCN230447</option>
<option value="3206010121">3206010121</option> <option value="3206010121">3206010121</option>
</select> </select>
<span style="float: right" id="stationId">xxxxxxxxxxxxxx</span> <button style="margin-left: 100px" id="export">导出历史数据</button>
<span style="float: right;margin-right: 15px" id="timeId">yyyy-MM-dd HH:mm:ss</span> <span style="float: right" id="stationId">xxxxxxxxxxxxxx</span>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div id="history"> <span style="float: right;margin-right: 15px" id="timeId">yyyy-MM-dd HH:mm:ss</span>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div id="history">
<div id="mainOne" style="width: 100%;height: 800px"></div> <div id="mainOne" style="width: 100%;height: 800px"></div>
<div id="mainTwo" style="width: 100%;height: 800px"></div> <div id="mainTwo" style="width: 100%;height: 800px"></div>
</div> </div>
<div id="pinPu" style="display: none"> <div id="pinPu" style="display: none">
<div id="pinPuChar" style="width: 100%;height: 800px"></div> <div id="pinPuChar" style="width: 100%;height: 800px"></div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var devId; var devId;
$(function () { $(function () {
$('#mainOne').css('height', window.innerHeight / 2 -20) $('#mainOne').css('height', window.innerHeight / 2 - 20)
$('#mainTwo').css('height', window.innerHeight / 2 -20) $('#mainTwo').css('height', window.innerHeight / 2 - 20)
devId = $('#selectId').find('option:selected').val() devId = $('#selectId').find('option:selected').val()
@@ -70,6 +72,41 @@
initVEchart() initVEchart()
}) })
$('#export').click(function () {
let str = ``;
if(historyMessage.length > 0){
for(let i in historyMessage[0]){
str+=i+',';
}
str = str.substring(0,str.lastIndexOf(','))+'\n'
}else {
alert("当前无历史数据")
return false
}
download(str, historyMessage)
})
const download = (str, data) => {
// 增加\t为了不让表格显示科学计数法或者其他格式
for (let i = 0; i < data.length; i++) {
for (const key in data[i]) {
str += `${data[i][key] + '\t'},`;
}
str += '\n';
}
// encodeURIComponent解决中文乱码
const uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
// 通过创建a标签实现
const link = document.createElement("a");
link.href = uri;
// 对下载的文件命名
link.download = "下载数据.csv";
link.click();
}
function initVEchart() { function initVEchart() {
// 基于准备好的dom初始化echarts实例 // 基于准备好的dom初始化echarts实例
@@ -109,7 +146,7 @@
}, },
xAxis: { xAxis: {
name:'时间', name: '时间',
type: 'category', type: 'category',
value: vTime, value: vTime,
boundaryGap: true, boundaryGap: true,
@@ -128,7 +165,7 @@
} }
}, },
yAxis: { yAxis: {
name:'V', name: 'V',
type: 'value', type: 'value',
axisLabel: { axisLabel: {
interval: 0, interval: 0,
@@ -256,7 +293,7 @@
}, },
xAxis: { xAxis: {
name:'时间', name: '时间',
type: 'category', type: 'category',
value: vTime, value: vTime,
boundaryGap: true, boundaryGap: true,
@@ -275,7 +312,7 @@
} }
}, },
yAxis: { yAxis: {
name:'A', name: 'A',
type: 'value', type: 'value',
axisLabel: { axisLabel: {
interval: 0, interval: 0,
@@ -370,6 +407,7 @@
} }
var historyMessage = []
/** /**
@@ -389,6 +427,7 @@
* 当服务端打开连接 * 当服务端打开连接
*/ */
webSocket.onopen = function (event) { webSocket.onopen = function (event) {
historyMessage = []
console.log('WebSocket打开连接'); console.log('WebSocket打开连接');
}; };
@@ -399,28 +438,29 @@
console.log('WebSocket收到消息%c' + event.data, 'color:green'); console.log('WebSocket收到消息%c' + event.data, 'color:green');
//获取服务端消息 //获取服务端消息
var message = JSON.parse(event.data) || {}; var message = JSON.parse(event.data) || {};
historyMessage.push(message)
devId = $('#selectId').find('option:selected').val() devId = $('#selectId').find('option:selected').val()
if(devId != message.customDevId){ if (devId != message.customDevId) {
return false; return false;
} }
$("#timeId").text(message.time.substring(0,4)+'-'+message.time.substring(4,6)+'-'+message.time.substring(6,8)+' '+message.time.substring(9,11)+':'+message.time.substring(11,13)+':'+message.time.substring(13,15)) $("#timeId").text(message.time.substring(0, 4) + '-' + message.time.substring(4, 6) + '-' + message.time.substring(6, 8) + ' ' + message.time.substring(9, 11) + ':' + message.time.substring(11, 13) + ':' + message.time.substring(13, 15))
if(devId == 'NJCN230447'){ if (devId == 'NJCN230447') {
$("#stationId").text("当前位置:保定-满城区-电能质量监测装置-0447") $("#stationId").text("当前位置:保定-满城区-电能质量监测装置-0447")
}else if(devId == 'NJCN230497'){ } else if (devId == 'NJCN230497') {
$("#stationId").text("当前位置:保定-满城区-电能质量监测装置-0497") $("#stationId").text("当前位置:保定-满城区-电能质量监测装置-0497")
}else if(devId == '3206010121'){ } else if (devId == '3206010121') {
$("#stationId").text("当前位置:xx-xx-电能质量监测装置-0121") $("#stationId").text("当前位置:xx-xx-电能质量监测装置-0121")
}else { } else {
$("#stationId").text("暂无数据") $("#stationId").text("暂无数据")
} }
if(vTime.length>50){ if (vTime.length > 50) {
vTime.shift(); vTime.shift();
vA.shift(); vA.shift();
@@ -432,7 +472,7 @@
} }
let temDate = message.time let temDate = message.time
let aaaDate = temDate.substring(0,4)+'-'+temDate.substring(4,6)+'-'+temDate.substring(6,8)+' '+temDate.substring(9,11)+':'+temDate.substring(11,13)+':'+temDate.substring(13,15) let aaaDate = temDate.substring(0, 4) + '-' + temDate.substring(4, 6) + '-' + temDate.substring(6, 8) + ' ' + temDate.substring(9, 11) + ':' + temDate.substring(11, 13) + ':' + temDate.substring(13, 15)
vTime.push(aaaDate) vTime.push(aaaDate)
vA.push(message.PhV_phsA) vA.push(message.PhV_phsA)
vB.push(message.PhV_phsB) vB.push(message.PhV_phsB)
@@ -482,10 +522,11 @@
}) })
if (pinPuEcharts) {
serviseV = [] serviseV = []
for(let i=2;i<26;i++){ for (let i = 2; i < 26; i++) {
let temValV = (Number(message['HRPhV_H'+i+'_phsA'])+Number(message['HRPhV_H'+i+'_phsB'])+Number(message['HRPhV_H'+i+'_phsC']))/3 let temValV = (Number(message['HRPhV_H' + i + '_phsA']) + Number(message['HRPhV_H' + i + '_phsB']) + Number(message['HRPhV_H' + i + '_phsC'])) / 3
serviseV.push(temValV.toFixed(3)) serviseV.push(temValV.toFixed(3))
} }
@@ -496,6 +537,7 @@
}, },
] ]
}) })
}
}; };
@@ -518,7 +560,6 @@
} }
var serviseV = [] var serviseV = []
var pinPuEcharts var pinPuEcharts
$('#buttonPinPu').click(function () { $('#buttonPinPu').click(function () {
@@ -526,12 +567,12 @@
$('#history').hide() $('#history').hide()
var pinPuX = [] var pinPuX = []
for(let i=2;i<26;i++){ for (let i = 2; i < 26; i++) {
pinPuX.push(i+'次') pinPuX.push(i + '次')
} }
// 基于准备好的dom初始化echarts实例 // 基于准备好的dom初始化echarts实例
pinPuEcharts= echarts.init(document.getElementById('pinPuChar')); pinPuEcharts = echarts.init(document.getElementById('pinPuChar'));
pinPuEcharts.clear() pinPuEcharts.clear()
// 指定图表的配置项和数据 // 指定图表的配置项和数据
@@ -569,7 +610,7 @@
}, },
xAxis: { xAxis: {
name:'次数', name: '次数',
data: pinPuX, data: pinPuX,
boundaryGap: true, boundaryGap: true,
axisLine: { axisLine: {
@@ -587,7 +628,7 @@
} }
}, },
yAxis: { yAxis: {
name:'%', name: '%',
boundaryGap: true, boundaryGap: true,
axisLine: { axisLine: {
show: true, show: true,
@@ -608,10 +649,10 @@
name: '谐波电压含有率', name: '谐波电压含有率',
type: 'bar', type: 'bar',
data: serviseV, data: serviseV,
color:'#339966' color: '#339966'
}, },
{ {
color:'#FF9900', color: '#FF9900',
name: '限值', name: '限值',
type: 'bar', type: 'bar',
data: [ data: [