197 changed files with 210 additions and 9333 deletions
@ -1,32 +0,0 @@ |
|||
package com.xr.device_car.config.common; |
|||
|
|||
public interface Const { |
|||
|
|||
|
|||
/** |
|||
* 请求onvifurl拼接 |
|||
*/ |
|||
String REQUEST_ONVIF_URL = "http://%s:%d/onvif/media_service"; |
|||
|
|||
String ABSOLUTE_MOVE= "http://%s:%d/onvif/ptz_service"; |
|||
|
|||
String PTZ_MOVE= "http://%s:%d/onvif/PTZ"; |
|||
|
|||
/** |
|||
* 请求onvifurl拼接 |
|||
*/ |
|||
String REQUEST_DEVICE_ONVIF_URL = "http://%s:%d/onvif/device_service"; |
|||
|
|||
/** |
|||
*返回的respon 中的headers |
|||
*/ |
|||
String HEADERS_ONVIF_WWW_AUTHENTICATE= "WWW-Authenticate"; |
|||
|
|||
|
|||
/** |
|||
* token |
|||
*/ |
|||
String EQUEST_ONVIF_TOKEN="Digest username=\"%s\", realm=\"%s\", qop=\"%s\", algorithm=\"%s\", uri=\"%s\", nonce=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\""; |
|||
|
|||
|
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
package com.xr.device_car.config.common; |
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import com.alibaba.excel.metadata.GlobalConfiguration; |
|||
import com.alibaba.excel.metadata.data.ReadCellData; |
|||
import com.alibaba.excel.metadata.data.WriteCellData; |
|||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.time.format.DateTimeFormatter; |
|||
|
|||
/** |
|||
* @Author: ChenTaoTao |
|||
* @Date: 2022/3/28 10:07 |
|||
* @Describe: |
|||
*/ |
|||
public class LocalDateConverter implements Converter<LocalDate> { |
|||
|
|||
@Override |
|||
public Class<LocalDate> supportJavaTypeKey() { |
|||
return LocalDate.class; |
|||
} |
|||
|
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public LocalDate convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
|||
return LocalDate.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|||
} |
|||
|
|||
@Override |
|||
public WriteCellData<String> convertToExcelData(LocalDate value, ExcelContentProperty contentProperty, |
|||
GlobalConfiguration globalConfiguration) { |
|||
return new WriteCellData<>(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
|||
} |
|||
|
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
package com.xr.device_car.config.common; |
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import com.alibaba.excel.metadata.GlobalConfiguration; |
|||
import com.alibaba.excel.metadata.data.ReadCellData; |
|||
import com.alibaba.excel.metadata.data.WriteCellData; |
|||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
|
|||
/** |
|||
* @Author: ChenTaoTao |
|||
* @Date: 2022/3/28 10:07 |
|||
* @Describe: |
|||
*/ |
|||
public class LocalDateTimeConverter implements Converter<LocalDateTime> { |
|||
@Override |
|||
public Class<LocalDateTime> supportJavaTypeKey() { |
|||
return LocalDateTime.class; |
|||
} |
|||
|
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public LocalDateTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { |
|||
return LocalDateTime.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|||
} |
|||
|
|||
@Override |
|||
public WriteCellData<String> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, |
|||
GlobalConfiguration globalConfiguration) { |
|||
return new WriteCellData<>(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
|||
} |
|||
|
|||
} |
|||
@ -1,281 +0,0 @@ |
|||
package com.xr.device_car.config.common; |
|||
|
|||
import com.xr.device_car.config.utils.HttpResponseBean; |
|||
import org.apache.http.*; |
|||
import org.apache.http.client.HttpRequestRetryHandler; |
|||
import org.apache.http.client.config.CookieSpecs; |
|||
import org.apache.http.client.config.RequestConfig; |
|||
import org.apache.http.client.methods.HttpPost; |
|||
import org.apache.http.client.protocol.HttpClientContext; |
|||
import org.apache.http.conn.ssl.NoopHostnameVerifier; |
|||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
|||
import org.apache.http.entity.ContentType; |
|||
import org.apache.http.entity.StringEntity; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
|||
import org.apache.http.protocol.HttpContext; |
|||
import org.apache.http.ssl.SSLContextBuilder; |
|||
import org.apache.http.util.EntityUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import javax.net.ssl.HostnameVerifier; |
|||
import javax.net.ssl.SSLContext; |
|||
import javax.net.ssl.SSLHandshakeException; |
|||
import java.io.IOException; |
|||
import java.net.ConnectException; |
|||
import java.util.Arrays; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
|
|||
/** |
|||
* Http请求客户端 |
|||
* @author ChenYongHeng |
|||
* @since 2019/5/27 |
|||
*/ |
|||
public class RESTClient { |
|||
|
|||
|
|||
private static Logger log = LoggerFactory.getLogger(RESTClient.class); |
|||
|
|||
|
|||
|
|||
private volatile static RESTClient HttpClientConnectionPool; |
|||
|
|||
private static final String USERAGENT = "SZ-JAVA"; |
|||
private static final String CHARSET = "UTF-8"; |
|||
|
|||
private static final int MAX_TOTAL_CONNECTIONS = 200; |
|||
private static final int MAX_ROUTE_CONNECTIONS = 100; |
|||
|
|||
|
|||
/** |
|||
* 连接时间 |
|||
*/ |
|||
private static final int CONNECT_TIMEOUT = 5000; |
|||
/** |
|||
* 获取内容时间 |
|||
*/ |
|||
private static final int SOCKET_TIMEOUT = 30000; |
|||
|
|||
private static PoolingHttpClientConnectionManager cm = null; |
|||
|
|||
|
|||
private static CloseableHttpClient HTTP_CLIENTS; |
|||
|
|||
/** |
|||
* 初始化连接池 |
|||
*/ |
|||
static{ |
|||
try { |
|||
cm = new PoolingHttpClientConnectionManager(); |
|||
cm.setMaxTotal(MAX_TOTAL_CONNECTIONS); |
|||
// 默认设置为2
|
|||
cm.setDefaultMaxPerRoute(MAX_ROUTE_CONNECTIONS); |
|||
// 客户端请求的默认设置
|
|||
RequestConfig defaultRequestConfig = RequestConfig.custom() |
|||
.setSocketTimeout(SOCKET_TIMEOUT) |
|||
.setConnectTimeout(CONNECT_TIMEOUT) |
|||
.setConnectionRequestTimeout(CONNECT_TIMEOUT) |
|||
.setRedirectsEnabled(false) |
|||
.setCookieSpec(CookieSpecs.STANDARD_STRICT) |
|||
.build(); |
|||
|
|||
// 请求重试处理
|
|||
HttpRequestRetryHandler httpRequestRetryHandler = new HttpRequestRetryHandler() { |
|||
@Override |
|||
public boolean retryRequest(IOException exception, |
|||
int executionCount, HttpContext context) { |
|||
// 如果超过最大重试次数,那么就不要继续了
|
|||
if (executionCount >= 2) { |
|||
return false; |
|||
} |
|||
|
|||
// 如果服务器丢掉了连接,那么就重试
|
|||
if (exception instanceof NoHttpResponseException) { |
|||
return true; |
|||
} |
|||
// 不要重试SSL握手异常
|
|||
if (exception instanceof SSLHandshakeException) { |
|||
return false; |
|||
} |
|||
HttpRequest request = (HttpRequest) context.getAttribute(HttpClientContext.HTTP_REQUEST); |
|||
boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); |
|||
// 如果请求被认为是幂等的,那么就重试
|
|||
if (idempotent) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
}; |
|||
// https 信任所有
|
|||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true).build(); |
|||
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; |
|||
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); |
|||
|
|||
HTTP_CLIENTS = HttpClients.custom() |
|||
.setConnectionManager(cm) |
|||
.setDefaultRequestConfig(defaultRequestConfig) |
|||
.setRetryHandler(httpRequestRetryHandler) |
|||
//https
|
|||
.setSSLSocketFactory(sslSocketFactory) |
|||
.build(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
private RESTClient(){} |
|||
|
|||
/** |
|||
* 获取HttpClientConnectionPool对象,这是单例方法 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static RESTClient getClientConnectionPool() { |
|||
if (HttpClientConnectionPool == null) { |
|||
synchronized (RESTClient.class) { |
|||
if (HttpClientConnectionPool == null) { |
|||
HttpClientConnectionPool = new RESTClient(); |
|||
} |
|||
} |
|||
} |
|||
return HttpClientConnectionPool; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 一般情况下是AuthToken使用 |
|||
* @param url |
|||
* @param xmlFileName |
|||
* @return |
|||
*/ |
|||
public HttpResponseBean postXML(String url, String xmlFileName){ |
|||
return postXML( url, xmlFileName,""); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 一般情况下是DigestBean使用 |
|||
* @param url |
|||
* @param xmlFileName |
|||
* @param auth |
|||
* @return |
|||
*/ |
|||
public HttpResponseBean postXML(String url,String xmlFileName,String auth){ |
|||
HttpPost httpPost = new HttpPost(url); |
|||
String seqNum = String.valueOf(System.currentTimeMillis()); |
|||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/soap+xml; charset=utf-8"); |
|||
if(StringUtils.hasLength(xmlFileName))httpPost.setEntity(new StringEntity(xmlFileName, ContentType.APPLICATION_JSON)); |
|||
if(StringUtils.hasLength(auth)) httpPost.setHeader("Authorization",auth); |
|||
log.info(seqNum+">>> "+httpPost.toString()); |
|||
log.info(seqNum+"Body>>> " +xmlFileName); |
|||
return httpPost(httpPost,seqNum); |
|||
} |
|||
|
|||
/** |
|||
* Post方法封装,发送post请求,获取响应内容 |
|||
*/ |
|||
public String fetchByPostMethod(String url, String jsonStr) { |
|||
String resultStr = null; |
|||
HttpPost httpPost = httpPostAddHeader(url, jsonStr); |
|||
String seqNum = String.valueOf(System.currentTimeMillis()); |
|||
log.info(seqNum + ">>> " + httpPost.toString()); |
|||
log.info(seqNum + "Body>>> " + jsonStr); |
|||
HttpResponse response; |
|||
try { |
|||
response = HTTP_CLIENTS.execute(httpPost); |
|||
HttpEntity entity = response.getEntity(); |
|||
resultStr = EntityUtils.toString(entity, CHARSET); |
|||
EntityUtils.consume(entity); |
|||
} catch (IOException ce) {// 服务器请求失败
|
|||
log.error(ce.getMessage()); |
|||
} finally { |
|||
httpPost.abort(); |
|||
} |
|||
log.info(seqNum + "<<< " + resultStr); |
|||
return resultStr; |
|||
} |
|||
|
|||
/** |
|||
* 添加头部信息 |
|||
* @param url |
|||
* @param jsonStr |
|||
* @return |
|||
*/ |
|||
private HttpPost httpPostAddHeader(String url, String jsonStr){ |
|||
HttpPost httpPost = new HttpPost(url); |
|||
httpPost.setEntity(new StringEntity(jsonStr, ContentType.APPLICATION_JSON)); |
|||
httpPost.addHeader(HttpHeaders.USER_AGENT, USERAGENT); |
|||
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); |
|||
return httpPost; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* httppost |
|||
* @param httpPost |
|||
* @param seqNum |
|||
* @return |
|||
*/ |
|||
private HttpResponseBean httpPost(HttpPost httpPost,String seqNum ) { |
|||
String resultStr = null; |
|||
HttpResponse response = null; |
|||
try{ |
|||
response = HTTP_CLIENTS.execute(httpPost); |
|||
int statusCode = response.getStatusLine().getStatusCode(); |
|||
if(statusCode == HttpStatus.SC_UNAUTHORIZED) { |
|||
//如果是401直接返回
|
|||
return new HttpResponseBean(null, Arrays.asList(response.getAllHeaders()),response.getStatusLine().getStatusCode()); |
|||
} |
|||
HttpEntity entity = response.getEntity(); |
|||
resultStr = EntityUtils.toString(entity,CHARSET); |
|||
EntityUtils.consume(entity); |
|||
}catch (ConnectException ce){// 服务器请求失败
|
|||
log.error("ConnectException fetchByPostMethod---->>>{}",ce.getMessage()); |
|||
} catch (IOException e) { |
|||
log.error("IOException fetchByPostMethod---->>>{}",e.getMessage()); |
|||
}finally { |
|||
httpPost.abort(); |
|||
} |
|||
log.info(seqNum+"<<< "+resultStr); |
|||
if(response != null) return new HttpResponseBean(resultStr, Arrays.asList(response.getAllHeaders()),response.getStatusLine().getStatusCode()); |
|||
return null; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 正则获取字符编码 |
|||
* @param content_type |
|||
* @return |
|||
*/ |
|||
private static String getCharSetFromContentType(String content_type){ |
|||
String regex = "charset=\\s*(\\S*[^;])"; |
|||
Pattern pattern = Pattern.compile(regex,Pattern.DOTALL); |
|||
Matcher matcher = pattern.matcher(content_type); |
|||
if(matcher.find()){ |
|||
return matcher.group(1); |
|||
|
|||
}else{ |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
package com.xr.device_car.config.udp; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.MeterConfig; |
|||
import com.xr.device_car.modules.analysis.entity.MeterReadingRecord; |
|||
import lombok.Data; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.Random; |
|||
|
|||
@Data |
|||
public class UdbConfig { |
|||
|
|||
//获取资源信息配置报文
|
|||
public static String getUdbConfig(List<MeterConfig> list){ |
|||
StringBuffer buffer=new StringBuffer(); |
|||
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
buffer.append(new Date().getTime()+ new Random().nextInt(9000)+1000).append("\t"); |
|||
buffer.append("<!Entity=表计识别信息转发配置 ver='V1.0' time='"+sdf.format(new Date())+"'(文件最新时间)!>"); |
|||
buffer.append("<DeviceInfo::设备资源信息>"); |
|||
for(MeterConfig config:list){ |
|||
buffer.append("站序号").append("\t");//站序号
|
|||
buffer.append(config.getId()).append("\t");//监控索引号
|
|||
buffer.append("中山站").append("/").append(config.getOwningInterval()).append("/").append(config.getDeviceName()).append("/").append(config.getMeterName()).append("\t");//设备名称=站名称+间隔名称+设备名称+开关名称
|
|||
buffer.append(config.getMeterCode()).append("\t");//实物ID目前取表计ID
|
|||
buffer.append("否").append(";");//是否联动信号目前取否,目前结尾符号位;
|
|||
} |
|||
buffer.append("</DeviceInfo::设备资源信息>"); |
|||
return buffer.toString(); |
|||
} |
|||
|
|||
} |
|||
@ -1,68 +0,0 @@ |
|||
package com.xr.device_car.config.udp; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.xr.device_car.config.utils.StaticPropUtil; |
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import com.xr.device_car.modules.analysis.service.SendUdpLogService; |
|||
import io.netty.bootstrap.Bootstrap; |
|||
import io.netty.channel.ChannelHandlerContext; |
|||
import io.netty.channel.ChannelOption; |
|||
import io.netty.channel.EventLoopGroup; |
|||
import io.netty.channel.SimpleChannelInboundHandler; |
|||
import io.netty.channel.nio.NioEventLoopGroup; |
|||
import io.netty.channel.socket.DatagramChannel; |
|||
import io.netty.channel.socket.DatagramPacket; |
|||
import io.netty.channel.socket.nio.NioDatagramChannel; |
|||
import io.netty.util.CharsetUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import java.net.InetSocketAddress; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
@Configuration |
|||
public class UdpClientConfig { |
|||
|
|||
@Autowired |
|||
private SendUdpLogService sendUdpLogService; |
|||
|
|||
@Bean |
|||
public DatagramChannel udpChannel() { |
|||
EventLoopGroup group = new NioEventLoopGroup(); |
|||
try { |
|||
Bootstrap bootstrap = new Bootstrap(); |
|||
bootstrap.group(group) |
|||
.channel(NioDatagramChannel.class) |
|||
.option(ChannelOption.SO_BROADCAST, true) |
|||
.handler(new SimpleChannelInboundHandler<DatagramPacket>() { |
|||
@Override |
|||
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { |
|||
// 处理接收到的数据
|
|||
String data = msg.content().toString(CharsetUtil.UTF_8); |
|||
QueryWrapper<SendUdpLog> queryWrapper=new QueryWrapper(); |
|||
queryWrapper.eq("message_id",data.split(":")[0]); |
|||
SendUdpLog sendUdpLog = sendUdpLogService.getOne(queryWrapper); |
|||
if(sendUdpLog !=null){ |
|||
sendUdpLog.setResTime(new Date()); |
|||
sendUdpLog.setResMsg(data); |
|||
sendUdpLogService.updateById(sendUdpLog); |
|||
} |
|||
System.out.println("Received data: " + data); |
|||
} |
|||
}); |
|||
|
|||
return (DatagramChannel) bootstrap.bind(0).sync().channel(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
@Bean |
|||
public InetSocketAddress udpServerAddress() { |
|||
return new InetSocketAddress(StaticPropUtil.udpHost, StaticPropUtil.udpPort); |
|||
} |
|||
|
|||
} |
|||
@ -1,153 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
|
|||
import com.xr.device_car.modules.analysis.entity.BallheadPT; |
|||
import org.apache.commons.lang.StringEscapeUtils; |
|||
import org.dom4j.Document; |
|||
import org.dom4j.Element; |
|||
import org.dom4j.io.SAXReader; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.nio.charset.StandardCharsets; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public class AnalysisXml { |
|||
|
|||
|
|||
/** |
|||
* 解析xml[Profiles] 获取 token |
|||
* @param resultStr |
|||
* @return |
|||
*/ |
|||
public static List<String> analysisTokens(String resultStr){ |
|||
// 解析body
|
|||
// 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移
|
|||
String xmlStr = StringEscapeUtils.unescapeXml(resultStr); |
|||
SAXReader reader = new SAXReader(); |
|||
try { |
|||
Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); |
|||
Element root = document.getRootElement(); |
|||
List<Element> elements = root.element("Body").element("GetProfilesResponse").elements("Profiles"); |
|||
return elements.stream().map(element -> element.attribute("token").getText()).collect(Collectors.toList()); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
/** |
|||
* 解析xml[ProfilesName] 获取 token |
|||
* @param resultStr |
|||
* @return |
|||
*/ |
|||
public static List<String> analysisProfiles(String resultStr){ |
|||
// 解析body
|
|||
// 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移
|
|||
String xmlStr = StringEscapeUtils.unescapeXml(resultStr); |
|||
SAXReader reader = new SAXReader(); |
|||
try { |
|||
Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); |
|||
Element root = document.getRootElement(); |
|||
List<Element> elements = root.element("Body").element("GetProfilesResponse").elements("Preset"); |
|||
return elements.stream().map(element -> element.element("Name").getText() |
|||
).collect(Collectors.toList()); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
/** |
|||
* 解析xml[MediaUri] 获取 token |
|||
* @param resultStr |
|||
* @return |
|||
*/ |
|||
public static String analysisSnapshotUrl(String resultStr){ |
|||
// 解析body
|
|||
// 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移
|
|||
String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); |
|||
SAXReader reader = new SAXReader(); |
|||
try { |
|||
Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); |
|||
Element rootElement = document.getRootElement(); |
|||
Element element = rootElement.element("Body").element("GetSnapshotUriResponse").element("MediaUri"); |
|||
List<Element> elements=element.elements("Uri"); |
|||
return String.valueOf(elements.get(0).getData()); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析xml[MediaUri] 获取 streamUrl |
|||
* @param resultStr |
|||
* @return |
|||
*/ |
|||
public static String analysisStreamUrl(String resultStr){ |
|||
// 解析body
|
|||
// 转换返回结果中的特殊字符,返回的结果中会将xml转义,此处需要反转移
|
|||
String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); |
|||
SAXReader reader = new SAXReader(); |
|||
try { |
|||
Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); |
|||
Element rootElement = document.getRootElement(); |
|||
Element element = rootElement.element("Body").element("GetStreamUriResponse").element("MediaUri"); |
|||
List<Element> elements=element.elements("Uri"); |
|||
return String.valueOf(elements.get(0).getData()); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static List<BallheadPT> getBallheadPTs(String resultStr){ |
|||
List<BallheadPT> ballheadPTS=new ArrayList<>(); |
|||
String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); |
|||
SAXReader reader = new SAXReader(); |
|||
try { |
|||
Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); |
|||
Element root = document.getRootElement(); |
|||
List<Element> elements = root.element("Body").element("GetPresetsResponse").elements("Preset"); |
|||
for(Element element:elements){ |
|||
BallheadPT pt=new BallheadPT(); |
|||
String id = element.attribute(0).getValue(); |
|||
pt.setId(id); |
|||
String name = String.valueOf(element.element("Name").getText()); |
|||
pt.setName(name); |
|||
List<Element> ele=element.elements("PTZPosition"); |
|||
pt.setX(String.valueOf(ele.get(0).element("PanTilt").attribute(0).getValue())); |
|||
pt.setY(String.valueOf(ele.get(0).element("PanTilt").attribute(1).getValue())); |
|||
pt.setZ(String.valueOf(ele.get(0).element("Zoom").attribute(0).getValue())); |
|||
ballheadPTS.add(pt); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return ballheadPTS; |
|||
} |
|||
|
|||
public static BallheadPT getStatus(String resultStr){ |
|||
String xmlStr = StringEscapeUtils.unescapeXml(resultStr).replace("&", "&"); |
|||
SAXReader reader = new SAXReader(); |
|||
try { |
|||
Document document = reader.read(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8))); |
|||
Element root = document.getRootElement(); |
|||
Element element = root.element("Body").element("GetStatusResponse").element("PTZStatus").element("Position"); |
|||
String x=String.valueOf(element.element("PanTilt").attribute(0).getValue()); |
|||
String y=String.valueOf(element.element("PanTilt").attribute(1).getValue()); |
|||
String z=String.valueOf(element.element("Zoom").attribute(0).getValue()); |
|||
BallheadPT pt=new BallheadPT(); |
|||
pt.setX(x); |
|||
pt.setY(y); |
|||
pt.setZ(z); |
|||
return pt; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -1,151 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import org.apache.commons.codec.binary.Hex; |
|||
|
|||
import java.security.GeneralSecurityException; |
|||
import java.security.MessageDigest; |
|||
import java.util.Random; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* @author :dzp |
|||
* @date :Created in 2022/5/12 14:39 |
|||
* @description: |
|||
*/ |
|||
public class DigestsUtils { |
|||
/** |
|||
* |
|||
* respon |
|||
* HA1 = MD5(<username>:<reaml>:<psd>) |
|||
* HA2 = MD5(<method>:<disgestUriPath>) |
|||
* response = MD5(HA1:<nonce>:<nc>:<conce>:<qop>:HA2) |
|||
* 给wsse的使用 |
|||
* 加密遵循RFC2671规范 将相关参数加密生成一个MD5字符串,并返回 |
|||
* http_da_calc_HA1("onvif_test", "IP Camera(C7233)", "onvif123", |
|||
* "5a5446694d3259774e474d36596a6735596a646b4d6a493d", "00000002", "512bb12866dcbc1f", "auth", |
|||
* "GET", "/onvif-http/snapshot?Profile_1", "MD5"); |
|||
* @param username 用户名 |
|||
* @param realm 401 返回的是 应该是名称 |
|||
* @param password 密码 |
|||
* @param nonce 401 返回的 |
|||
* @param nc 16进制请求认证计数器, 00000001 |
|||
* @param cnonce 客户端随机数 |
|||
* @param qop auth |
|||
* @param method 请求 |
|||
* @param uri 地址 getSnapshotUil返回的 |
|||
* @param algorithm 加密方式 一般情况下是MD5 |
|||
* @return 获取response |
|||
*/ |
|||
public static String http_da_calc_HA1(String username, String realm, String password, |
|||
String nonce, String nc, String cnonce, String qop, |
|||
String method, String uri, String algorithm) { |
|||
String HA1, HA2; |
|||
if ("MD5-sess".equals(algorithm)) { |
|||
HA1 = HA1_MD5_sess(username, realm, password, nonce, cnonce); |
|||
} else { |
|||
HA1 = HA1_MD5(username, realm, password); |
|||
} |
|||
byte[] md5Byte = md5(HA1.getBytes()); |
|||
HA1 = new String(Hex.encodeHex(md5Byte)); |
|||
|
|||
md5Byte = md5(HA2(method, uri).getBytes()); |
|||
HA2 = new String(Hex.encodeHex(md5Byte)); |
|||
|
|||
String original = HA1 + ":" + (nonce + ":" + nc + ":" + cnonce + ":" + qop) + ":" + HA2; |
|||
|
|||
md5Byte = md5(original.getBytes()); |
|||
return new String(Hex.encodeHex(md5Byte)); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* algorithm值为MD5时规则 |
|||
*/ |
|||
private static String HA1_MD5(String username, String realm, String password) { |
|||
return username + ":" + realm + ":" + password; |
|||
} |
|||
|
|||
/** |
|||
* algorithm值为MD5-sess时规则 |
|||
*/ |
|||
private static String HA1_MD5_sess(String username, String realm, String password, String nonce, String cnonce) { |
|||
// MD5(username:realm:password):nonce:cnonce
|
|||
|
|||
String s = HA1_MD5(username, realm, password); |
|||
byte[] md5Byte = md5(s.getBytes()); |
|||
String smd5 = new String(Hex.encodeHex(md5Byte)); |
|||
|
|||
return smd5 + ":" + nonce + ":" + cnonce; |
|||
} |
|||
|
|||
private static String HA2(String method, String uri) { |
|||
return method + ":" + uri; |
|||
} |
|||
|
|||
/** |
|||
* 对输入字符串进行md5散列. |
|||
*/ |
|||
public static byte[] md5(byte[] input) { |
|||
return digest(input, "MD5", null, 1); |
|||
} |
|||
|
|||
/** |
|||
* 对字符串进行散列, 支持md5与sha1算法. |
|||
*/ |
|||
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) { |
|||
try { |
|||
MessageDigest digest = MessageDigest.getInstance(algorithm); |
|||
|
|||
if (salt != null) { |
|||
digest.update(salt); |
|||
} |
|||
|
|||
byte[] result = digest.digest(input); |
|||
|
|||
for (int i = 1; i < iterations; i++) { |
|||
digest.reset(); |
|||
result = digest.digest(result); |
|||
} |
|||
return result; |
|||
} catch (GeneralSecurityException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 字符串中匹配字符串 |
|||
* @param qopPattern |
|||
* @param str |
|||
* @return |
|||
*/ |
|||
public static String getStr(Pattern qopPattern, String str){ |
|||
Matcher matcher = qopPattern.matcher(str); |
|||
if (matcher.find()) { |
|||
return matcher.group(1); |
|||
|
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取nonce |
|||
* @return |
|||
*/ |
|||
public static String getNonce(int index) { |
|||
String base = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|||
Random random = new Random(); |
|||
StringBuffer sb = new StringBuffer(); |
|||
for (int i = 0; i < index; i++) { |
|||
int number = random.nextInt(base.length()); |
|||
sb.append(base.charAt(number)); |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -1,139 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import com.alibaba.excel.EasyExcel; |
|||
import com.alibaba.excel.metadata.Head; |
|||
import com.alibaba.excel.write.handler.CellWriteHandler; |
|||
import com.alibaba.excel.write.handler.RowWriteHandler; |
|||
import com.alibaba.excel.write.handler.SheetWriteHandler; |
|||
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext; |
|||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
|||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; |
|||
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; |
|||
import com.alibaba.excel.write.metadata.style.WriteCellStyle; |
|||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.baomidou.mybatisplus.extension.api.R; |
|||
import com.xr.device_car.config.common.LocalDateConverter; |
|||
import com.xr.device_car.config.common.LocalDateTimeConverter; |
|||
import com.xr.device_car.modules.analysis.entity.xslx.SendUdpLogXslx; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.poi.ss.usermodel.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.lang.reflect.Field; |
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.ArrayList; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author: ChenTaoTao |
|||
* @Date: 2022/3/19 16:51 |
|||
* @Describe: 文件导出 |
|||
*/ |
|||
@Slf4j |
|||
public class EasyExcelUtil { |
|||
public static <T> void writeExcel(HttpServletResponse response, List<T> data, Class tClass, String name){ |
|||
try { |
|||
List<Class> list=convertList(data,tClass); |
|||
String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
|||
name = name+dateStr; |
|||
//防止下载时中文乱码
|
|||
name = new String(name.getBytes("UTF-8"), "ISO-8859-1"); |
|||
response.setContentType("application/vnd.ms-excel"); |
|||
response.setCharacterEncoding("utf-8"); |
|||
//添加这个是防止前端拿不到Content-disposition
|
|||
response.setHeader("Content-Disposition", "attachment;filename=" + name+".xlsx"); |
|||
response.setHeader("Access-Control-Expose-Headers","Content-disposition"); |
|||
// 这里需要设置不关闭流
|
|||
EasyExcel.write(response.getOutputStream(), tClass).autoCloseStream(Boolean.FALSE).sheet(name).registerConverter(new LocalDateConverter()).registerConverter(new LocalDateTimeConverter()) |
|||
.registerWriteHandler(getCellStyleStrategy()).doWrite(list); |
|||
} catch (Exception e) { |
|||
log.error("文件导出失败,错误信息{}",e); |
|||
// 重置response
|
|||
response.reset(); |
|||
response.setContentType("application/json"); |
|||
response.setCharacterEncoding("utf-8"); |
|||
R r = R.failed("文件下载失败"); |
|||
try { |
|||
response.getWriter().println(JSON.toJSONString(r)); |
|||
} catch (IOException ioException) { |
|||
ioException.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
private static HorizontalCellStyleStrategy getCellStyleStrategy() { |
|||
// 创建标题样式和内容样式
|
|||
WriteCellStyle headerStyle = new WriteCellStyle(); |
|||
headerStyle.setBorderLeft(BorderStyle.THIN); |
|||
headerStyle.setBorderTop(BorderStyle.THIN); |
|||
headerStyle.setBorderRight(BorderStyle.THIN); |
|||
headerStyle.setBorderBottom(BorderStyle.THIN); |
|||
|
|||
WriteCellStyle contentStyle = new WriteCellStyle(); |
|||
contentStyle.setBorderLeft(BorderStyle.THIN); |
|||
contentStyle.setBorderTop(BorderStyle.THIN); |
|||
contentStyle.setBorderRight(BorderStyle.THIN); |
|||
contentStyle.setBorderBottom(BorderStyle.THIN); |
|||
|
|||
return new HorizontalCellStyleStrategy(headerStyle,contentStyle); |
|||
} |
|||
|
|||
public static <T, S> List<S> convertList(List<T> list, Class<S> targetClass) throws NoSuchFieldException, IllegalAccessException, ParseException, NoSuchMethodException, InvocationTargetException, InstantiationException { |
|||
List<S> resultList = new ArrayList<>(); |
|||
|
|||
for (T sourceObj : list) { |
|||
S targetObj = targetClass.getDeclaredConstructor().newInstance(); |
|||
Field[] sourceFields = sourceObj.getClass().getDeclaredFields(); |
|||
Field[] targetFields = targetClass.getDeclaredFields(); |
|||
|
|||
for (Field sourceField : sourceFields) { |
|||
Field targetField = getField(targetFields, sourceField.getName()); |
|||
if (targetField != null) { |
|||
sourceField.setAccessible(true); |
|||
targetField.setAccessible(true); |
|||
|
|||
Object sourceValue = sourceField.get(sourceObj); |
|||
Object targetValue = convertFieldValue(sourceValue, targetField.getType(),sourceField.getType()); |
|||
|
|||
targetField.set(targetObj, targetValue); |
|||
} |
|||
} |
|||
|
|||
resultList.add(targetObj); |
|||
} |
|||
|
|||
return resultList; |
|||
} |
|||
|
|||
private static Field getField(Field[] fields, String fieldName) { |
|||
for (Field field : fields) { |
|||
if (field.getName().equals(fieldName)) { |
|||
return field; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private static Object convertFieldValue(Object value, Class<?> targetType,Class<?> type1) throws ParseException { |
|||
if (type1 == String.class) { |
|||
return value.toString(); |
|||
} else if (targetType == String.class && value instanceof Date) { |
|||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
return dateFormat.format(value); |
|||
} |
|||
return value; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,125 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import org.springframework.core.io.ClassPathResource; |
|||
|
|||
import java.io.*; |
|||
|
|||
public class FileUtil { |
|||
|
|||
/** |
|||
* 读取文件 |
|||
*/ |
|||
public static String fileReader(String url) throws IOException { |
|||
File file = new File(url); |
|||
StringBuilder result = new StringBuilder(); |
|||
|
|||
//构造一个BufferedReader类来读取文件
|
|||
BufferedReader br = new BufferedReader(new FileReader(file)); |
|||
String s = null; |
|||
//使用readLine方法,一次读一行
|
|||
while ((s = br.readLine()) != null) { |
|||
result.append(s); |
|||
} |
|||
br.close(); |
|||
return result.toString(); |
|||
} |
|||
/** |
|||
* 读取文件 |
|||
*/ |
|||
public static String fileReader(ClassPathResource classPathResource ) { |
|||
InputStream fis= null; |
|||
ByteArrayOutputStream baos=null; |
|||
try { |
|||
fis = classPathResource.getInputStream(); |
|||
byte[] buffer = new byte[1024]; |
|||
baos = new ByteArrayOutputStream(); |
|||
int len = 0; |
|||
while((len = fis.read(buffer)) != -1){ |
|||
baos.write(buffer,0,len); |
|||
} |
|||
return baos.toString(); |
|||
}catch (Exception e) { |
|||
// 未读取到数据
|
|||
e.printStackTrace(); |
|||
}finally { |
|||
try { |
|||
if(fis != null)fis.close(); |
|||
if(baos != null)baos.close(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
} |
|||
//todo 未读取到数据
|
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 写入数据 |
|||
* @param path |
|||
* @param data |
|||
* @return |
|||
*/ |
|||
public static boolean readInputStream(String path,byte[] data) { |
|||
//得到图片的二进制数据,以二进制封装得到数据,具有通用性
|
|||
FileOutputStream outStream=null; |
|||
try { |
|||
//new一个文件对象用来保存图片,默认保存当前工程根目录
|
|||
File imageFile = new File(path); |
|||
|
|||
//创建输出流
|
|||
outStream = new FileOutputStream(imageFile); |
|||
//写入数据
|
|||
outStream.write(data); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
}finally { |
|||
//关闭输出流
|
|||
if(outStream!= null) { |
|||
try { |
|||
outStream.close(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 写入数据 |
|||
* @param file |
|||
* @param data |
|||
* @return |
|||
*/ |
|||
public static boolean readInputStream(File file,byte[] data) { |
|||
//得到图片的二进制数据,以二进制封装得到数据,具有通用性
|
|||
FileOutputStream outStream=null; |
|||
try { |
|||
//创建输出流
|
|||
outStream = new FileOutputStream(file); |
|||
//写入数据
|
|||
outStream.write(data); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
}finally { |
|||
//关闭输出流
|
|||
if(outStream!= null) { |
|||
try { |
|||
outStream.close(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,52 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.BallheadPT; |
|||
import com.xr.device_car.modules.analysis.entity.DeviceCamera; |
|||
import com.xr.device_car.modules.analysis.entity.OnvifAuthBean; |
|||
import com.xr.device_car.modules.analysis.entity.OnvifBean; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.util.List; |
|||
|
|||
public class HkComUtil { |
|||
|
|||
public static BufferedImage getBole(DeviceCamera device) throws Exception{ //拉取枪机图片
|
|||
OnvifAuthBean onvifBean= new OnvifAuthBean(device.getDeviceIp(),80,device.getAccount(),device.getPassword()); |
|||
String url= OnvifBean.getRequestUrl(onvifBean); |
|||
String auth = OnvifUtils.getAuthorization("digest",onvifBean,"digest/GetProfiles.wsdl", url); |
|||
System.out.println("鉴权:"+auth); |
|||
//获取Token
|
|||
List<String> profileTokens = OnvifUtils.getProfileTokens(onvifBean,auth); |
|||
System.out.println("Token:"+profileTokens); |
|||
onvifBean.setAuth(auth); |
|||
if(!CollectionUtils.isEmpty(profileTokens)){ |
|||
String snapshotUrl=null; |
|||
String token = profileTokens.get(0); |
|||
BallheadPT ballheadPT=OnvifUtils.getPtzStatus(token,onvifBean); |
|||
//如果类型是球机转换指定点位
|
|||
if(device.getDeviceType().equals("3") && OnvifUtils.ptzCamera(token,onvifBean,device.getX(),device.getY(),device.getZ())){ |
|||
Thread.sleep(1000); |
|||
//拉取图片
|
|||
snapshotUrl = OnvifUtils.getSnapshotUrl(token,onvifBean); |
|||
if(snapshotUrl!=null){ |
|||
//转回原来位置
|
|||
OnvifUtils.ptzCamera(token,onvifBean,ballheadPT.getX(),ballheadPT.getY(),ballheadPT.getZ()); |
|||
} |
|||
//如果类型是固定枪机,直接获取图片
|
|||
}else{ |
|||
snapshotUrl = OnvifUtils.getSnapshotUrl(token,onvifBean); |
|||
} |
|||
//返回图片地址
|
|||
return Files.urlByImages(snapshotUrl,device.getAccount(),device.getPassword()); |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
@ -1,55 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.Setter; |
|||
import org.apache.http.Header; |
|||
import org.apache.http.HttpStatus; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Setter |
|||
@Getter |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class HttpResponseBean { |
|||
private String body; |
|||
private List<Header> headers; |
|||
private Integer status; |
|||
|
|||
/** |
|||
* 获取头部信息。 |
|||
* @param name |
|||
* @return |
|||
*/ |
|||
public Header getFirstHeader(final String name) { |
|||
for (int i = 0; i < this.headers.size(); i++) { |
|||
final Header header = this.headers.get(i); |
|||
if (header.getName().equalsIgnoreCase(name)) { |
|||
return header; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/*** |
|||
* 判断是否成功 |
|||
*/ |
|||
public static boolean isSuccess(HttpResponseBean httpResponseBean){ |
|||
return httpResponseBean!= null && HttpStatus.SC_OK ==httpResponseBean.getStatus(); |
|||
} |
|||
|
|||
|
|||
/*** |
|||
* 判断是否是401 |
|||
*/ |
|||
public static boolean isUnAuthorzied(HttpResponseBean httpResponseBean){ |
|||
return httpResponseBean!= null && HttpStatus.SC_UNAUTHORIZED ==httpResponseBean.getStatus(); |
|||
} |
|||
|
|||
public HttpResponseBean(String body) { |
|||
this.body = body; |
|||
} |
|||
} |
|||
|
|||
@ -1,72 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import io.minio.MinioClient; |
|||
import io.minio.errors.*; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
import org.xmlpull.v1.XmlPullParserException; |
|||
|
|||
import java.io.*; |
|||
import java.security.InvalidKeyException; |
|||
import java.security.NoSuchAlgorithmException; |
|||
import java.util.UUID; |
|||
|
|||
public class MinioUtil { |
|||
|
|||
private final static Logger log= LoggerFactory.getLogger(MinioUtil.class); |
|||
|
|||
private static MinioClient minioClient; |
|||
|
|||
private static MinioClient minioInit(){ |
|||
try { |
|||
if(minioClient == null){ |
|||
minioClient = new MinioClient(StaticPropUtil.minioUrl, StaticPropUtil.minioAccess, StaticPropUtil.minioSecret); |
|||
} |
|||
} catch (InvalidEndpointException e) { |
|||
throw new RuntimeException(e); |
|||
} catch (InvalidPortException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
return minioClient; |
|||
} |
|||
|
|||
public static String uploadMultipartFile(MultipartFile file) throws Exception { |
|||
MinioClient minioClient = minioInit(); |
|||
InputStream is = file.getInputStream(); |
|||
//使用uuid生成新的唯一文件名
|
|||
String fileName = UUID.randomUUID().toString().replace("-", "") + file.getOriginalFilename(); |
|||
//获取文件类型
|
|||
String contentType = file.getContentType();//把文件放置Minio桶
|
|||
minioClient.putObject("meter", fileName, is, contentType); |
|||
//获取访问路径
|
|||
String url = minioClient.presignedGetObject("meter", fileName); |
|||
if (url != null) { |
|||
//返回路径不为空,即上传文件成功
|
|||
return url.split("\\?")[0]; |
|||
} else { |
|||
//上传失败
|
|||
return"上传失败"; |
|||
} |
|||
} |
|||
|
|||
public static String uploadFile(File file) throws IOException, InvalidArgumentException, InvalidBucketNameException, InsufficientDataException, XmlPullParserException, ErrorResponseException, NoSuchAlgorithmException, NoResponseException, InvalidKeyException, InternalException, InvalidExpiresRangeException { |
|||
MinioClient minioClient = minioInit(); |
|||
InputStream is = new FileInputStream(file); |
|||
//使用uuid生成新的唯一文件名
|
|||
String fileName = UUID.randomUUID().toString().replace("-", "") + file.getName(); |
|||
//获取文件类型
|
|||
String contentType = fileName.substring(fileName.lastIndexOf(".")+1);//把文件放置Minio桶
|
|||
minioClient.putObject("meter", fileName, is, contentType); |
|||
//获取访问路径
|
|||
String url = minioClient.presignedGetObject("meter", fileName); |
|||
if (url != null) { |
|||
//返回路径不为空,即上传文件成功
|
|||
return url.split("\\?")[0]; |
|||
} else { |
|||
//上传失败
|
|||
return"上传失败"; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -1,141 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import com.xr.device_car.config.common.RESTClient; |
|||
import com.xr.device_car.modules.analysis.entity.BallheadPT; |
|||
import com.xr.device_car.modules.analysis.entity.DigestBean; |
|||
import com.xr.device_car.modules.analysis.entity.OnvifAuthBean; |
|||
import com.xr.device_car.modules.analysis.entity.OnvifBean; |
|||
import org.springframework.core.io.ClassPathResource; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.util.List; |
|||
|
|||
import static com.xr.device_car.config.common.Const.HEADERS_ONVIF_WWW_AUTHENTICATE; |
|||
|
|||
|
|||
public class OnvifUtils { |
|||
|
|||
|
|||
/** |
|||
* 获取鉴权 |
|||
* @param authType |
|||
* @param requestOnvifBean |
|||
* @param wsdl |
|||
* @param requestUrl |
|||
* @return |
|||
*/ |
|||
public static String getAuthorization(String authType, OnvifBean requestOnvifBean, String wsdl, String requestUrl) { |
|||
//参数
|
|||
// 读取GetProfiles.wsdl
|
|||
String getProfiles = FileUtil.fileReader(new ClassPathResource(wsdl)); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, getProfiles); |
|||
//如果是401的话 获取WWW-Authenticate 重新请求
|
|||
if (HttpResponseBean.isUnAuthorzied(httpResponseBean)) { |
|||
DigestBean digestBean = new DigestBean().getDigestBean(authType,requestOnvifBean, httpResponseBean.getFirstHeader(HEADERS_ONVIF_WWW_AUTHENTICATE).getValue()); |
|||
return digestBean.getToken(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取Token |
|||
* @param requestOnvifBean |
|||
* @param auth |
|||
* @return |
|||
*/ |
|||
public static List<String> getProfileTokens(OnvifBean requestOnvifBean, String auth) { |
|||
//请求url
|
|||
String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); |
|||
//参数
|
|||
// 读取GetProfiles.wsdl
|
|||
String getProfiles = FileUtil.fileReader(new ClassPathResource("digest/GetProfiles.wsdl")); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, getProfiles,auth); |
|||
if(httpResponseBean != null) { |
|||
String resultStr = httpResponseBean.getBody(); |
|||
if (HttpResponseBean.isSuccess(httpResponseBean) && StringUtils.hasLength(resultStr)) { |
|||
return AnalysisXml.analysisTokens(resultStr); |
|||
} |
|||
|
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 获取截图地址 |
|||
* @param profileToken token |
|||
* @param requestOnvifBean |
|||
* @return |
|||
*/ |
|||
public static String getSnapshotUrl(String profileToken, OnvifAuthBean requestOnvifBean) { |
|||
String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); |
|||
//参数
|
|||
// 读取GetProfiles.wsdl
|
|||
String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/GetSnapshotUrl.wsdl")); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, String.format(snapshotUrlWsdl,profileToken),requestOnvifBean.getAuth()); |
|||
String resultStr = httpResponseBean.getBody(); |
|||
if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { |
|||
return AnalysisXml.analysisSnapshotUrl(resultStr); |
|||
} |
|||
return null; |
|||
} |
|||
//绝对位置转动球机
|
|||
public static boolean ptzCamera(String profileToken,OnvifAuthBean requestOnvifBean,String x,String y,String z){ |
|||
String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); |
|||
String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/AbsoluteMove.wsdl")); |
|||
String wsdl = String.format(snapshotUrlWsdl,profileToken,x,y,z); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); |
|||
String resultStr = httpResponseBean.getBody(); |
|||
if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
//获取球机当前位置
|
|||
public static BallheadPT getPtzStatus(String token,OnvifAuthBean requestOnvifBean){ |
|||
String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); |
|||
String snap = FileUtil.fileReader(new ClassPathResource("digest/GetStatus.wsdl")); |
|||
String wsdl = String.format(snap,token); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); |
|||
String resultStr = httpResponseBean.getBody(); |
|||
if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { |
|||
return AnalysisXml.getStatus(resultStr); |
|||
} |
|||
return null; |
|||
} |
|||
//获取所有预置点
|
|||
public static List<BallheadPT> getBallHeadPts(String profileToken,OnvifAuthBean requestOnvifBean){ |
|||
String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); |
|||
String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/GetPresets.wsdl")); |
|||
String wsdl = String.format(snapshotUrlWsdl,profileToken); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); |
|||
String resultStr = httpResponseBean.getBody(); |
|||
if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { |
|||
return AnalysisXml.getBallheadPTs(resultStr); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
//前往指定预置点
|
|||
public static boolean gotoBallHeadPts(String profileToken, OnvifAuthBean requestOnvifBean, BallheadPT ballheadPT){ |
|||
String requestUrl = OnvifBean.getRequestUrl(requestOnvifBean); |
|||
String snapshotUrlWsdl = FileUtil.fileReader(new ClassPathResource("digest/GotoPreset.wsdl")); |
|||
String wsdl = String.format(snapshotUrlWsdl,profileToken,ballheadPT.getId()); |
|||
HttpResponseBean httpResponseBean = RESTClient.getClientConnectionPool() |
|||
.postXML(requestUrl, wsdl,requestOnvifBean.getAuth()); |
|||
String resultStr = httpResponseBean.getBody(); |
|||
if(StringUtils.hasLength(resultStr) && HttpResponseBean.isSuccess(httpResponseBean)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
@ -1,231 +0,0 @@ |
|||
package com.xr.device_car.config.utils; |
|||
|
|||
import cn.hutool.extra.spring.SpringUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.xr.device_car.modules.analysis.entity.MeterInitialization; |
|||
import com.xr.device_car.modules.analysis.service.IMeterInitializationService; |
|||
import com.xr.device_car.modules.analysis.service.MeterConfigService; |
|||
import com.xr.device_car.modules.analysis.service.impl.MeterInitializationServiceImpl; |
|||
|
|||
import java.io.*; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public class PythonExecutor { |
|||
|
|||
|
|||
public static void main(String[] args) throws Exception { |
|||
try { |
|||
String pythonPath = StaticPropUtil.pythonPath; |
|||
|
|||
ProcessBuilder processBuilder = new ProcessBuilder(pythonPath); |
|||
// 启动子进程
|
|||
Process process = processBuilder.start(); |
|||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); |
|||
bw.write("import sys\n"); |
|||
bw.write("sys.path.append(\"D:\\smartGrid\\smartGrid\\models\")\n"); |
|||
bw.write("import indicatorLightStatus as ils\n"); |
|||
bw.write("import switchRecognition as sr\n"); |
|||
bw.write("import liquidLevel as ll\n"); |
|||
bw.write("liquid_level_image_path = 'D:\\smartGrid\\smartGrid\\weights\\DIGITAL_METER (41).JPG'\n"); |
|||
bw.write("ll.calculate_rgb_min_max([[112,\"D:\\smartGrid\\smartGrid\\weights\\DIGITAL_METER (41).JPG\"]])\n"); |
|||
bw.write("print(\"Liquid level weights initialized.\")\n"); |
|||
bw.write("liquid_level_image_path = 'D:\\smartGrid\\smartGrid\\weights\\DIGITAL_METER (10).JPG'\n"); |
|||
bw.write("liquid_level = ll.calculate_liquid_level([112,liquid_level_image_path])\n"); |
|||
bw.write("print(f\"Liquid level: {liquid_level}\")\n"); |
|||
|
|||
bw.close(); |
|||
|
|||
|
|||
// 获取子进程的输出流
|
|||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
|||
|
|||
String line; |
|||
// 读取输出
|
|||
while ((line = reader.readLine()) != null) { |
|||
System.out.println(line); |
|||
} |
|||
|
|||
// 等待进程执行完成
|
|||
int exitCode = process.waitFor(); |
|||
System.out.println("Exit Code: " + exitCode); |
|||
|
|||
} catch (IOException | InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
} |
|||
|
|||
private static boolean meterInit(String code) throws Exception { |
|||
String pythonPath = StaticPropUtil.pythonPath; |
|||
String modelPath = StaticPropUtil.modelPath; |
|||
|
|||
ProcessBuilder processBuilder = new ProcessBuilder(pythonPath); |
|||
// 启动子进程
|
|||
Process process = processBuilder.start(); |
|||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); |
|||
bw.write("import sys\n"); |
|||
String imports = "sys.path.append(\"%s\")\n"; |
|||
bw.write(String.format(imports, modelPath)); |
|||
bw.write("import indicatorLightStatus as ils\n"); |
|||
bw.write("import switchRecognition as sr\n"); |
|||
bw.write("import liquidLevel as ll\n"); |
|||
bw.write(code); |
|||
bw.write("print(\"success\")\n"); |
|||
bw.close(); |
|||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
|||
|
|||
List<String> list = new ArrayList<>(); |
|||
String line; |
|||
// 读取输出
|
|||
while ((line = reader.readLine()) != null) { |
|||
list.add(line); |
|||
System.out.println(line); |
|||
} |
|||
|
|||
BufferedReader exception = new BufferedReader(new InputStreamReader(process.getErrorStream())); |
|||
List<String> list1 = new ArrayList<>(); |
|||
String line1; |
|||
// 读取输出
|
|||
while ((line1 = exception.readLine()) != null) { |
|||
list1.add(line1); |
|||
System.out.println(line1); |
|||
} |
|||
|
|||
// 等待进程执行完成
|
|||
int exitCode = process.waitFor(); |
|||
System.out.println("Exit Code: " + exitCode); |
|||
if (list.contains("success") && list1.isEmpty()) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 初始化算法 |
|||
* id 表计配置ID |
|||
* sfType 4 灯光 3 开关 5 液位计 |
|||
*/ |
|||
public static boolean meterInit(Integer id, String sfType) throws Exception { |
|||
IMeterInitializationService meterInitializationService = SpringUtil.getBean(MeterInitializationServiceImpl.class); |
|||
QueryWrapper<MeterInitialization> query = new QueryWrapper<>(); |
|||
query.eq("meter_id", id); |
|||
query.orderByAsc("serial"); |
|||
List<MeterInitialization> list = meterInitializationService.list(query); |
|||
List<String> path = list.stream().map(n -> n.getImgAddress()).collect(Collectors.toList()); |
|||
String ph = ""; |
|||
for (String str : path) { |
|||
str = str.replace("\\", "\\\\"); |
|||
ph += "\"" + str + "\"" + ","; |
|||
} |
|||
ph = ph.substring(0, ph.length() - 1); |
|||
String code = ""; |
|||
if (sfType.equals("4")) { |
|||
List<List<Object>> list1 = new ArrayList<>(); |
|||
List<Object> list2 = new ArrayList<>(); |
|||
list2.add(id); |
|||
List<String> list3 = new ArrayList<>(); |
|||
list3.add(ph); |
|||
list2.add(list3); |
|||
list1.add(list2); |
|||
code = "ils.calculate_luminance_threshold(" + Arrays.toString(list1.toArray()) + ")\n"; |
|||
} |
|||
if (sfType.equals("3")) { |
|||
List<String> list1 = new ArrayList<>(); |
|||
path.add(0, id + ""); |
|||
list1.add(ph); |
|||
code = "sr.initialize(" + Arrays.toString(list1.toArray()) + ")\n"; |
|||
} |
|||
if (sfType.equals("5")) { |
|||
List<String> list1 = new ArrayList<>(); |
|||
// list1.add(id.toString());
|
|||
//path.add(0, id + "");
|
|||
list1.add(ph); |
|||
// String params = String.join( list1);
|
|||
//Arrays.toString(list1.toArray())
|
|||
code = "ll.calculate_rgb_min_max("+"[["+id+ ","+ ph +"]]"+")\n"; |
|||
} |
|||
return meterInit(code); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 读取结果 |
|||
* id 表计id |
|||
* path 图片路径 |
|||
* sfType 1 灯光 2 开关 3 液位计 4 指针 |
|||
*/ |
|||
public static String readNumber(Integer id, String path, String sfType) throws Exception { |
|||
String pythonPath = StaticPropUtil.pythonPath; |
|||
String modelPath = StaticPropUtil.modelPath; |
|||
|
|||
ProcessBuilder processBuilder = new ProcessBuilder(pythonPath); |
|||
// 启动子进程
|
|||
Process process = processBuilder.start(); |
|||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); |
|||
bw.write("import sys\n"); |
|||
String imports = "sys.path.append(\"%s\")\n"; |
|||
bw.write(String.format(imports, modelPath)); |
|||
bw.write("import indicatorLightStatus as ils\n"); |
|||
bw.write("import switchRecognition as sr\n"); |
|||
bw.write("import liquidLevel as ll\n"); |
|||
bw.write("indicator_light_image_path = '" + path + "'\n"); |
|||
if (sfType.equals("4")) { |
|||
bw.write("value = ils.check_indicator_light_status(" + id + ",indicator_light_image_path)\n"); |
|||
} |
|||
if (sfType.equals("3")) { |
|||
bw.write("value = sr.read_numbers(" + id + ",indicator_light_image_path)\n"); |
|||
} |
|||
if (sfType.equals("5")) { |
|||
bw.write("value = ll.calculate_liquid_level([" + id + ",indicator_light_image_path,\"down\"])\n"); |
|||
} |
|||
if (sfType.equals("0")) { |
|||
bw.write("rotate_angle, value = pr.getPointerAngleAndNum(" + id + ", indicator_light_image_path)\n"); |
|||
} |
|||
bw.write("print(f\"value:{value}\")"); |
|||
bw.close(); |
|||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
|||
List<String> list = new ArrayList<>(); |
|||
String line; |
|||
// 读取输出
|
|||
while ((line = reader.readLine()) != null) { |
|||
list.add(line); |
|||
} |
|||
|
|||
BufferedReader exception = new BufferedReader(new InputStreamReader(process.getErrorStream())); |
|||
List<String> list1 = new ArrayList<>(); |
|||
String line1; |
|||
// 读取输出
|
|||
while ((line1 = exception.readLine()) != null) { |
|||
list.add(line1); |
|||
} |
|||
|
|||
|
|||
// if(list.contains("value")){
|
|||
// String value = list.get(list.indexOf("value")).split(":")[1];
|
|||
// File file = new File(path);
|
|||
// if(file.exists()){
|
|||
// file.delete();
|
|||
// }
|
|||
// return value;
|
|||
// }
|
|||
for (String element : list) { |
|||
if (element.contains("value")) { |
|||
String[] parts = element.split(":"); |
|||
File file = new File(path); |
|||
if (file.exists()) { |
|||
file.delete(); |
|||
} |
|||
if (parts.length > 1) { |
|||
String result = parts[1].trim(); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -1,177 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.controller; |
|||
|
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.xr.device_car.config.common.Result; |
|||
import com.xr.device_car.config.utils.*; |
|||
import com.xr.device_car.modules.analysis.entity.DeviceCamera; |
|||
import com.xr.device_car.modules.analysis.entity.MeterConfig; |
|||
import com.xr.device_car.modules.analysis.entity.MeterInitialization; |
|||
import com.xr.device_car.modules.analysis.entity.MeterType; |
|||
import com.xr.device_car.modules.analysis.service.DeviceCameraService; |
|||
import com.xr.device_car.modules.analysis.service.IMeterInitializationService; |
|||
import com.xr.device_car.modules.analysis.service.MeterConfigService; |
|||
import com.xr.device_car.modules.analysis.service.MeterTypeService; |
|||
import io.minio.MinioClient; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.File; |
|||
import java.io.InputStream; |
|||
import java.util.*; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
|
|||
/** |
|||
* <p> |
|||
* 表计算法初始化 前端控制器 |
|||
* </p> |
|||
* |
|||
* @author gaoby |
|||
* @since 2023-11-20 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/meterInitialization") |
|||
@RequiredArgsConstructor |
|||
public class MeterInitializationController { |
|||
@Value("${upLoad.file}") |
|||
private String uploadDir; |
|||
|
|||
private final MeterConfigService meterConfigService; |
|||
|
|||
private final DeviceCameraService deviceCameraService; |
|||
|
|||
private final IMeterInitializationService iMeterInitializationService; |
|||
|
|||
private final MeterTypeService meterTypeService; |
|||
|
|||
@PostMapping("pullImages") |
|||
public Result<?> pullImages(MeterInitialization meterInitialization){ |
|||
MeterConfig config=meterConfigService.getById(meterInitialization.getMeterId()); |
|||
DeviceCamera deviceCamera = deviceCameraService.getById(config.getCameraId()); |
|||
BufferedImage bufferedImage=null; |
|||
try { |
|||
if(deviceCamera.getDeviceType().equals("1")|| deviceCamera.getDeviceType().equals("2")){ |
|||
bufferedImage= AdbUtil.getCamDevice(); |
|||
} |
|||
if(deviceCamera.getDeviceType().equals("3") || deviceCamera.getDeviceType().equals("4")){ // 拉取球机
|
|||
bufferedImage= HkComUtil.getBole(deviceCamera); |
|||
} |
|||
long l = new Date().getTime(); |
|||
String path = StaticPropUtil.imagePath +l+".png"; |
|||
File file=Files.saveImageForPath(bufferedImage,path); |
|||
String url = MinioUtil.uploadFile(file); |
|||
|
|||
QueryWrapper<MeterInitialization> queryWrapper=new QueryWrapper<>(); |
|||
queryWrapper.eq("meter_id",meterInitialization.getMeterId()); |
|||
queryWrapper.orderByDesc("serial"); |
|||
List<MeterInitialization> meterInitialization1=iMeterInitializationService.list(queryWrapper); |
|||
MeterInitialization meterInitialization2 = getMeterInitialization(meterInitialization, meterInitialization1, path,url); |
|||
iMeterInitializationService.save(meterInitialization2); |
|||
}catch (Exception e){ |
|||
e.printStackTrace(); |
|||
return Result.error(e.getMessage()); |
|||
} |
|||
return Result.OK("拉取成功!"); |
|||
} |
|||
|
|||
private static MeterInitialization getMeterInitialization(MeterInitialization meterInitialization, List<MeterInitialization> meterInitialization1, String path,String url) { |
|||
MeterInitialization meterInitialization2=new MeterInitialization(); |
|||
meterInitialization2.setMeterId(meterInitialization.getMeterId()); |
|||
if(meterInitialization1.isEmpty()){ |
|||
meterInitialization2.setSerial(0); |
|||
}else{ |
|||
meterInitialization2.setSerial(meterInitialization1.get(0).getSerial()+1); |
|||
} |
|||
meterInitialization2.setValue(meterInitialization.getValue()); |
|||
meterInitialization2.setImgAddress(path); |
|||
meterInitialization2.setImg(url); |
|||
return meterInitialization2; |
|||
} |
|||
|
|||
@PostMapping("/uploadImg") |
|||
public Result<?> uploadImg(@RequestParam("imgFile") MultipartFile imgFile,@RequestParam("value") String value,@RequestParam("serial") String serial,@RequestParam("meterId") String meterId) throws Exception { |
|||
if (!imgFile.isEmpty()) { |
|||
// 获取文件名
|
|||
String fileName = Objects.requireNonNull(imgFile.getOriginalFilename()); |
|||
File folder = new File(StaticPropUtil.imagePath); |
|||
// 检查文件夹是否存在,如果不存在就创建它
|
|||
if (!folder.exists()) { |
|||
folder.mkdirs(); // 创建文件夹及其父文件夹(如果不存在)
|
|||
} |
|||
// 构建上传路径
|
|||
String filePath = StaticPropUtil.imagePath + File.separator + fileName; |
|||
String imgAddress = StaticPropUtil.imagePath + fileName; |
|||
// 保存文件
|
|||
File dest = new File(filePath); |
|||
imgFile.transferTo(dest); |
|||
// 上传至minIo服务器
|
|||
String url = MinioUtil.uploadMultipartFile(imgFile); |
|||
if (url.equals("上传失败")){ |
|||
Result.error("图片上传至服务器异常"); |
|||
} |
|||
MeterInitialization meterInitialization = new MeterInitialization(); |
|||
meterInitialization.setImg(url); |
|||
meterInitialization.setImgAddress(imgAddress); |
|||
meterInitialization.setMeterId(Integer.valueOf(meterId)); |
|||
meterInitialization.setSerial(Integer.valueOf(serial)); |
|||
meterInitialization.setValue(value); |
|||
QueryWrapper<MeterInitialization> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq("meter_id",meterInitialization.getMeterId()); |
|||
iMeterInitializationService.save(meterInitialization); |
|||
return Result.OK("上传成功!"); |
|||
} |
|||
return Result.error("上传图片异常,请联系管理员"); |
|||
} |
|||
|
|||
|
|||
@PostMapping(value = "/queryPageList") |
|||
public Result<?> queryPageList(MeterInitialization meterInitialization, HttpServletRequest req)throws Exception{ |
|||
// Page<MeterInitialization> pg = StringFormatterUtil.returnPage(req);
|
|||
QueryWrapper<MeterInitialization> wrapper = StringFormatterUtil.returnQuery(req); |
|||
// meterId
|
|||
if (ObjectUtil.isNotEmpty(meterInitialization.getMeterId())){ |
|||
wrapper.eq("meter_id",meterInitialization.getMeterId()); |
|||
} |
|||
wrapper.orderByAsc("serial"); |
|||
List<MeterInitialization> meterInitializationList = iMeterInitializationService.list(wrapper); |
|||
return Result.OK(meterInitializationList); |
|||
} |
|||
|
|||
|
|||
|
|||
@PostMapping(value = "/delImg") |
|||
public Result<?> delImg(Integer id) throws Exception { |
|||
iMeterInitializationService.removeById(id); |
|||
return Result.OK("删除成功!"); |
|||
} |
|||
|
|||
/** |
|||
* 初始化算法 |
|||
*/ |
|||
@PostMapping("initMeter") |
|||
public Result<?> initMeter(Integer meterId){ |
|||
try{ |
|||
MeterConfig meterConfig=meterConfigService.getById(meterId); |
|||
MeterType meterType = meterTypeService.getById(meterConfig.getTypeId()); |
|||
if(PythonExecutor.meterInit(meterId,meterType.getMeterShape())){ |
|||
meterConfig.setInitStatus("1"); |
|||
meterConfigService.updateById(meterConfig); |
|||
}else{ |
|||
return Result.error("初始化失败"); |
|||
} |
|||
}catch (Exception e){ |
|||
e.printStackTrace(); |
|||
return Result.error(e.getMessage()); |
|||
} |
|||
return Result.OK("初始化完成"); |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -1,72 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.controller; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.xr.device_car.config.utils.EasyExcelUtil; |
|||
import com.xr.device_car.config.utils.StringFormatterUtil; |
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import com.xr.device_car.modules.analysis.entity.xslx.SendUdpLogXslx; |
|||
import com.xr.device_car.modules.analysis.service.SendUdpLogService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.util.*; |
|||
|
|||
@RestController |
|||
@RequestMapping("/udpLog") |
|||
@RequiredArgsConstructor |
|||
public class SendUdpLogController { |
|||
|
|||
private final SendUdpLogService sendUdpLogService; |
|||
|
|||
@RequestMapping("/pageList") |
|||
public IPage<SendUdpLog> pageList(SendUdpLog sendUdpLog, HttpServletRequest req){ |
|||
Page<SendUdpLog> page = StringFormatterUtil.returnPage(req); |
|||
QueryWrapper<SendUdpLog> query=new QueryWrapper<>(); |
|||
if(!sendUdpLog.getMessageId().isEmpty()){ |
|||
query.eq("message_id", sendUdpLog.getMessageId()); |
|||
} |
|||
if(sendUdpLog.getStartDate()!=null){ |
|||
query.ge("request_time", sendUdpLog.getStartDate()); |
|||
} |
|||
if(sendUdpLog.getEndDate()!=null){ |
|||
query.lt("request_time", sendUdpLog.getEndDate()); |
|||
} |
|||
query.orderByDesc("request_time"); |
|||
return sendUdpLogService.page(page,query); |
|||
} |
|||
|
|||
@RequestMapping("/downloadExcel") |
|||
public void downloadExcel(@RequestBody String data,HttpServletResponse res){ |
|||
System.out.println(data); |
|||
Map<String,Object> object = (Map<String, Object>) JSONObject.parse(data); |
|||
SendUdpLog sendUdpLog = JSONObject.parseObject(data,SendUdpLog.class); |
|||
List<String> list = (List<String>) object.get("ids"); |
|||
List<SendUdpLog> sendUdpLogs =new ArrayList<>(); |
|||
if(list.isEmpty()){ |
|||
QueryWrapper<SendUdpLog> query=new QueryWrapper<>(); |
|||
if(!sendUdpLog.getMessageId().isEmpty()){ |
|||
query.eq("message_id", sendUdpLog.getMessageId()); |
|||
} |
|||
if(sendUdpLog.getStartDate()!=null){ |
|||
query.ge("request_time", sendUdpLog.getStartDate()); |
|||
} |
|||
if(sendUdpLog.getEndDate()!=null){ |
|||
query.lt("request_time", sendUdpLog.getEndDate()); |
|||
} |
|||
sendUdpLogs = sendUdpLogService.list(query); |
|||
}else{ |
|||
sendUdpLogs = sendUdpLogService.listByIds(list); |
|||
} |
|||
EasyExcelUtil.writeExcel(res,sendUdpLogs,SendUdpLogXslx.class,"UDP日志"); |
|||
} |
|||
|
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class BallheadPT { |
|||
private String id; |
|||
|
|||
private String name; |
|||
|
|||
private String x; |
|||
|
|||
private String y; |
|||
|
|||
private String z; |
|||
|
|||
} |
|||
@ -1,120 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import com.xr.device_car.config.common.Const; |
|||
import com.xr.device_car.config.utils.DigestsUtils; |
|||
import lombok.Data; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.util.regex.Pattern; |
|||
|
|||
@Data |
|||
public class DigestBean { |
|||
/** |
|||
* 用户名 |
|||
*/ |
|||
private String username; |
|||
/** |
|||
* 服务端401返回的 名称 |
|||
*/ |
|||
private String realm; |
|||
/** |
|||
* auth |
|||
*/ |
|||
private String qop; |
|||
/** |
|||
* 加密方式 一般情况下是MD5 |
|||
*/ |
|||
private String algorithm="MD5"; |
|||
/** |
|||
*路径 |
|||
*/ |
|||
private String uri="/onvif/media_service"; |
|||
/*** |
|||
* 服务端401返回的 |
|||
*/ |
|||
private String nonce; |
|||
/** |
|||
* 16进制请求认证计数器,第一次 00000001 |
|||
*/ |
|||
private String nc="00000001"; |
|||
/** |
|||
* 客户端密码随机数 |
|||
*/ |
|||
private String cnonce; |
|||
/** |
|||
* 默认为空 |
|||
*/ |
|||
private String opaque=""; |
|||
/** |
|||
* http_da_calc_HA1 获取的 |
|||
*/ |
|||
private String response; |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 获取DigestBean对象 |
|||
* @param onvifBean |
|||
* @param value |
|||
* @return |
|||
*/ |
|||
public DigestBean getDigestBean(String authType,OnvifBean onvifBean, String value){ |
|||
this.setUsername(onvifBean.getUserName()); |
|||
// Digest realm="Login to a81d6710d0de6749fcdba591802e3864",qop="auth",nonce="b252aWYtZGlnZXN0OjQzNDIyNTEwNTQw", opaque="", stale="false"
|
|||
//正则匹配
|
|||
this.setRealm(DigestsUtils.getStr(Pattern.compile("realm=\"(.*?)\""),value)); |
|||
this.setQop(DigestsUtils.getStr(Pattern.compile("qop=\"(.*?)\""),value)); |
|||
this.setNonce(DigestsUtils.getStr(Pattern.compile("nonce=\"(.*?)\""),value)); |
|||
this.setCnonce(DigestsUtils.getNonce(32)); |
|||
if("None".equalsIgnoreCase(authType)) { |
|||
this.setResponse(getResponseHA1NoAuth(this, onvifBean.getPassWord())); |
|||
}else { |
|||
this.setResponse(getResponseHA1Auth(this, onvifBean.getPassWord())); |
|||
} |
|||
return this; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取Response |
|||
* @param pwd |
|||
* @return |
|||
*/ |
|||
private static String getResponseHA1Auth(DigestBean digestBean,String pwd){ |
|||
return getResponseHA1(digestBean,pwd,"","POST"); |
|||
} |
|||
|
|||
/** |
|||
* 获取Response |
|||
* @param pwd |
|||
* @return |
|||
*/ |
|||
private static String getResponseHA1NoAuth(DigestBean digestBean,String pwd){ |
|||
return getResponseHA1(digestBean,pwd,"","GET"); |
|||
} |
|||
/** |
|||
* 获取Response |
|||
* @param pwd |
|||
* @return |
|||
*/ |
|||
private static String getResponseHA1(DigestBean digestBean,String pwd,String uri,String method){ |
|||
return DigestsUtils.http_da_calc_HA1(digestBean.getUsername(), digestBean.getRealm(), pwd, |
|||
digestBean.getNonce(), String.valueOf(digestBean.getNc()), digestBean.getCnonce(), digestBean.getQop(), |
|||
method, StringUtils.hasLength(uri)?uri:digestBean.getUri(), "MD5"); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取token |
|||
* @return |
|||
*/ |
|||
public String getToken(){ |
|||
return String.format(Const.EQUEST_ONVIF_TOKEN,this.username, this.realm, |
|||
this.qop,this.algorithm,this.uri,this.nonce, String.valueOf(this.nc), |
|||
this.cnonce,this.opaque,this.response); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
@ -1,53 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* <p> |
|||
* 表计算法初始化 |
|||
* </p> |
|||
* |
|||
* @author gaoby |
|||
* @since 2023-11-20 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
public class MeterInitialization implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
private Integer id; |
|||
|
|||
/** |
|||
* 请求图片路径 |
|||
*/ |
|||
private String img; |
|||
|
|||
/** |
|||
* 盘符路径 |
|||
*/ |
|||
private String imgAddress; |
|||
|
|||
/** |
|||
* 常量值 |
|||
*/ |
|||
private String value; |
|||
|
|||
/** |
|||
* 表计id |
|||
*/ |
|||
private Integer meterId; |
|||
|
|||
private Integer Serial; |
|||
|
|||
|
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class OnvifAuthBean extends OnvifBean { |
|||
|
|||
/** |
|||
* 自定义参数 |
|||
*/ |
|||
private String auth; |
|||
|
|||
public OnvifAuthBean(String ip, Integer port, String userName, String passWord, String profileToken, String auth) { |
|||
super(ip, port, userName, passWord); |
|||
|
|||
this.auth = auth; |
|||
} |
|||
|
|||
public OnvifAuthBean(String ip, Integer port, String userName, String passWord) { |
|||
super(ip, port, userName, passWord); |
|||
|
|||
} |
|||
|
|||
public void setAuth(String auth){ |
|||
this.auth=auth; |
|||
} |
|||
|
|||
public String getAuth(){ |
|||
return this.auth; |
|||
} |
|||
|
|||
} |
|||
@ -1,53 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import com.xr.device_car.config.common.Const; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class OnvifBean { |
|||
|
|||
|
|||
private String ip; |
|||
|
|||
private Integer port; |
|||
|
|||
private String userName; |
|||
|
|||
private String passWord; |
|||
|
|||
private String x; |
|||
|
|||
private String y; |
|||
|
|||
private String z; |
|||
|
|||
|
|||
|
|||
public static String getRequestUrl(OnvifBean requestOnvifBean) { |
|||
return String.format(Const.REQUEST_ONVIF_URL,requestOnvifBean.getIp(),requestOnvifBean.getPort()); |
|||
} |
|||
|
|||
public static String getPTZUrl(OnvifBean requestOnvifBean){ |
|||
return String.format(Const.ABSOLUTE_MOVE,requestOnvifBean.getIp(),requestOnvifBean.getPort()); |
|||
} |
|||
|
|||
public static String getPTZ(OnvifBean requestOnvifBean){ |
|||
return String.format(Const.PTZ_MOVE,requestOnvifBean.getIp(),requestOnvifBean.getPort()); |
|||
} |
|||
|
|||
|
|||
public OnvifBean(String ip, Integer port) { |
|||
this.ip = ip; |
|||
this.port = port; |
|||
} |
|||
|
|||
public OnvifBean(String ip, Integer port,String userName,String passWord) { |
|||
this.ip = ip; |
|||
this.port = port; |
|||
this.userName=userName; |
|||
this.passWord=passWord; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
@ -1,38 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* onvif 连接信息 |
|||
* @author zf |
|||
*/ |
|||
@Data |
|||
public class OnvifCredentials { |
|||
/** |
|||
* 92.168.xx.yy, or http://host[:port]
|
|||
*/ |
|||
private String host; |
|||
/** |
|||
* admin |
|||
*/ |
|||
private String user; |
|||
/** |
|||
* secret |
|||
*/ |
|||
private String password; |
|||
/** |
|||
* "MediaProfile000" If empty, will use first profile. |
|||
*/ |
|||
private String profile; |
|||
|
|||
public OnvifCredentials(String host, String user, String password, String profile) { |
|||
this.host = host; |
|||
this.user = user; |
|||
this.password = password; |
|||
this.profile = profile; |
|||
} |
|||
|
|||
public String details() { |
|||
return host + "," + user + "," + password + "," + profile; |
|||
} |
|||
} |
|||
@ -1,68 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity; |
|||
|
|||
import com.alibaba.excel.annotation.ExcelProperty; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.xr.device_car.config.common.LocalDateTimeConverter; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* udb消息日志表 |
|||
* @TableName send_udb_log |
|||
*/ |
|||
@TableName(value ="send_udp_log") |
|||
@Data |
|||
public class SendUdpLog implements Serializable { |
|||
/** |
|||
* 主键 |
|||
*/ |
|||
@TableId(type = IdType.AUTO) |
|||
private Integer id; |
|||
|
|||
/** |
|||
* 消息主键 |
|||
*/ |
|||
private String messageId; |
|||
|
|||
/** |
|||
* 发送状态(0成功1失败) |
|||
*/ |
|||
private String requestStatus; |
|||
|
|||
/** |
|||
* 发送报文 |
|||
*/ |
|||
private String requestMsg; |
|||
|
|||
/** |
|||
* 发送时间 |
|||
*/ |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
private Date requestTime; |
|||
|
|||
/** |
|||
* 接收报文 |
|||
*/ |
|||
private String resMsg; |
|||
|
|||
/** |
|||
* 返回时间 |
|||
*/ |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
private Date resTime; |
|||
|
|||
@TableField(exist = false) |
|||
private Date startDate; |
|||
|
|||
@TableField(exist = false) |
|||
private Date endDate; |
|||
|
|||
@TableField(exist = false) |
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -1,68 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.entity.xslx; |
|||
|
|||
import com.alibaba.excel.annotation.ExcelProperty; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.lang.reflect.Field; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* udb消息日志表 |
|||
* @TableName send_udb_log |
|||
*/ |
|||
@TableName(value ="send_udp_log") |
|||
@Data |
|||
public class SendUdpLogXslx implements Serializable { |
|||
|
|||
/** |
|||
* 消息主键 |
|||
*/ |
|||
@ExcelProperty(value = "消息主键") |
|||
private String messageId; |
|||
|
|||
/** |
|||
* 发送状态(0成功1失败) |
|||
*/ |
|||
@ExcelProperty(value="发送状态") |
|||
private String requestStatus; |
|||
|
|||
/** |
|||
* 发送报文 |
|||
*/ |
|||
@ExcelProperty(value="发送报文") |
|||
private String requestMsg; |
|||
|
|||
/** |
|||
* 发送时间 |
|||
*/ |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ExcelProperty(value="发送时间") |
|||
private String requestTime; |
|||
|
|||
/** |
|||
* 接收报文 |
|||
*/ |
|||
@ExcelProperty(value="接收报文") |
|||
private String resMsg; |
|||
|
|||
/** |
|||
* 返回时间 |
|||
*/ |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ExcelProperty(value="返回时间") |
|||
private String resTime; |
|||
|
|||
public String getRequestStatus(){ |
|||
if(this.requestStatus.equals("0")){ |
|||
return "成功"; |
|||
} |
|||
return "失败"; |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.mapper; |
|||
|
|||
import com.baomidou.dynamic.datasource.annotation.DS; |
|||
import com.xr.device_car.modules.analysis.entity.MeterInitialization; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* <p> |
|||
* 表计算法初始化 Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author gaoby |
|||
* @since 2023-11-20 |
|||
*/ |
|||
@DS("db2") |
|||
@Mapper |
|||
public interface MeterInitializationMapper extends BaseMapper<MeterInitialization> { |
|||
|
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.mapper; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* @author 范亚杰 |
|||
* @description 针对表【send_udb_log(udb消息日志表)】的数据库操作Mapper |
|||
* @createDate 2023-11-29 13:41:51 |
|||
* @Entity com.xr.device_car.modules.analysis.entity.SendUdbLog |
|||
*/ |
|||
@Mapper |
|||
public interface SendUdpLogMapper extends BaseMapper<SendUdpLog> { |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
@ -1,16 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.service; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.MeterInitialization; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
/** |
|||
* <p> |
|||
* 表计算法初始化 服务类 |
|||
* </p> |
|||
* |
|||
* @author gaoby |
|||
* @since 2023-11-20 |
|||
*/ |
|||
public interface IMeterInitializationService extends IService<MeterInitialization> { |
|||
|
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.service; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
/** |
|||
* @author 范亚杰 |
|||
* @description 针对表【send_udb_log(udb消息日志表)】的数据库操作Service |
|||
* @createDate 2023-11-29 13:41:51 |
|||
*/ |
|||
public interface SendUdpLogService extends IService<SendUdpLog> { |
|||
|
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.service; |
|||
|
|||
public interface UdpClientService { |
|||
|
|||
void sendData(String data); |
|||
|
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.service.impl; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.MeterInitialization; |
|||
import com.xr.device_car.modules.analysis.mapper.MeterInitializationMapper; |
|||
import com.xr.device_car.modules.analysis.service.IMeterInitializationService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* <p> |
|||
* 表计算法初始化 服务实现类 |
|||
* </p> |
|||
* |
|||
* @author gaoby |
|||
* @since 2023-11-20 |
|||
*/ |
|||
@Service |
|||
public class MeterInitializationServiceImpl extends ServiceImpl<MeterInitializationMapper, MeterInitialization> implements IMeterInitializationService { |
|||
|
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.service.impl; |
|||
|
|||
import com.baomidou.dynamic.datasource.annotation.DS; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import com.xr.device_car.modules.analysis.service.SendUdpLogService; |
|||
import com.xr.device_car.modules.analysis.mapper.SendUdpLogMapper; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* @author 范亚杰 |
|||
* @description 针对表【send_udb_log(udb消息日志表)】的数据库操作Service实现 |
|||
* @createDate 2023-11-29 13:41:51 |
|||
*/ |
|||
@Service |
|||
@DS("db2") |
|||
public class SendUdpLogServiceImpl extends ServiceImpl<SendUdpLogMapper, SendUdpLog> |
|||
implements SendUdpLogService { |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
@ -1,48 +0,0 @@ |
|||
package com.xr.device_car.modules.analysis.service.impl; |
|||
|
|||
import com.xr.device_car.modules.analysis.entity.SendUdpLog; |
|||
import com.xr.device_car.modules.analysis.service.SendUdpLogService; |
|||
import com.xr.device_car.modules.analysis.service.UdpClientService; |
|||
import io.netty.buffer.Unpooled; |
|||
import io.netty.channel.socket.DatagramChannel; |
|||
import io.netty.channel.socket.DatagramPacket; |
|||
import io.netty.util.CharsetUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.net.InetSocketAddress; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
@Service |
|||
public class UdpClientServiceImpl implements UdpClientService { |
|||
|
|||
@Autowired |
|||
private DatagramChannel udpChannel; |
|||
|
|||
@Autowired |
|||
private InetSocketAddress udpServerAddress; |
|||
|
|||
@Autowired |
|||
private SendUdpLogService sendUdpLogService; |
|||
|
|||
|
|||
@Override |
|||
public void sendData(String data) { |
|||
SendUdpLog sendUdpLog =new SendUdpLog(); |
|||
sendUdpLog.setRequestMsg(data); |
|||
sendUdpLog.setRequestTime(new Date()); |
|||
sendUdpLog.setMessageId(data.split("\t")[0]); |
|||
try { |
|||
udpChannel.writeAndFlush(new DatagramPacket( |
|||
Unpooled.copiedBuffer(data, CharsetUtil.UTF_8), udpServerAddress)).sync(); |
|||
sendUdpLog.setRequestStatus("0"); |
|||
} catch (Exception e) { |
|||
sendUdpLog.setRequestStatus("1"); |
|||
sendUdpLog.setResMsg(e.getMessage()); |
|||
sendUdpLog.setResTime(new Date()); |
|||
e.printStackTrace(); |
|||
} |
|||
sendUdpLogService.save(sendUdpLog); |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<s:Body> |
|||
<tptz:AbsoluteMove> |
|||
<tptz:ProfileToken>%s</tptz:ProfileToken> |
|||
<tptz:Position> |
|||
<tt:PanTilt y="%s" x="%s" space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace" /> |
|||
<tt:Zoom x="%s" space="http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace" /> |
|||
</tptz:Position> |
|||
</tptz:AbsoluteMove> |
|||
</s:Body> |
|||
</s:Envelope> |
|||
@ -1,6 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<soap:Body> |
|||
<tds:GetOnvifInformation /> |
|||
</soap:Body> |
|||
</soap:Envelope> |
|||
@ -1,6 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"> |
|||
<s:Body> |
|||
<tptz:GetConfigurations /> |
|||
</s:Body> |
|||
</s:Envelope> |
|||
@ -1,8 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<s:Body> |
|||
<tptz:GetPresets> |
|||
<tptz:ProfileToken>%s</tptz:ProfileToken> |
|||
</tptz:GetPresets> |
|||
</s:Body> |
|||
</s:Envelope> |
|||
@ -1,6 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<soap:Body> |
|||
<trt:GetProfiles /> |
|||
</soap:Body> |
|||
</soap:Envelope> |
|||
@ -1,8 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<soap:Body> |
|||
<trt:GetSnapshotUri> |
|||
<trt:ProfileToken>%s</trt:ProfileToken> |
|||
</trt:GetSnapshotUri> |
|||
</soap:Body> |
|||
</soap:Envelope> |
|||
@ -1,8 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<s:Body> |
|||
<tptz:GetStatus> |
|||
<tptz:ProfileToken>%s</tptz:ProfileToken> |
|||
</tptz:GetStatus> |
|||
</s:Body> |
|||
</s:Envelope> |
|||
@ -1,25 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<s:Header xmlns:s="http://www.w3.org/2003/05/soap-envelope"> |
|||
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> |
|||
<wsse:UsernameToken> |
|||
<wsse:Username>%s</wsse:Username> |
|||
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%s</wsse:Password> |
|||
<wsse:Nonce>%s</wsse:Nonce> |
|||
<wsu:Created>%s</wsu:Created> |
|||
</wsse:UsernameToken> |
|||
</wsse:Security> |
|||
</s:Header> |
|||
<soap:Body> |
|||
<GetStreamUri xmlns="http://www.onvif.org/ver10/media/wsdl"> |
|||
<StreamSetup> |
|||
<!-- Attribute Wild card could not be matched. Generated XML may not be valid. --> |
|||
<Stream xmlns="http://www.onvif.org/ver10/schema">RTP-Unicast</Stream> |
|||
<Transport xmlns="http://www.onvif.org/ver10/schema"> |
|||
<Protocol>%s</Protocol> |
|||
</Transport> |
|||
</StreamSetup> |
|||
<ProfileToken>%s</ProfileToken> |
|||
</GetStreamUri> |
|||
</soap:Body> |
|||
</soap:Envelope> |
|||
@ -1,9 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema"> |
|||
<s:Body> |
|||
<tptz:GotoPreset> |
|||
<tptz:ProfileToken>%s</tptz:ProfileToken> |
|||
<tptz:PresetToken>%s</tptz:PresetToken> |
|||
</tptz:GotoPreset> |
|||
</s:Body> |
|||
</s:Envelope> |
|||
@ -1,14 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.xr.device_car.modules.analysis.mapper.MeterInitializationMapper"> |
|||
|
|||
<!-- 通用查询映射结果 --> |
|||
<resultMap id="BaseResultMap" type="com.xr.device_car.modules.analysis.entity.MeterInitialization"> |
|||
<id column="id" property="id" /> |
|||
<result column="img" property="img" /> |
|||
<result column="img_address" property="imgAddress" /> |
|||
<result column="value" property="value" /> |
|||
<result column="meter_id" property="meterId"/> |
|||
</resultMap> |
|||
|
|||
</mapper> |
|||
@ -1,22 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.xr.device_car.modules.analysis.mapper.SendUdpLogMapper"> |
|||
|
|||
<resultMap id="BaseResultMap" type="com.xr.device_car.modules.analysis.entity.SendUdpLog"> |
|||
<id property="id" column="id" jdbcType="INTEGER"/> |
|||
<result property="messageId" column="message_id" jdbcType="VARCHAR"/> |
|||
<result property="requestStatus" column="requst_status" jdbcType="VARCHAR"/> |
|||
<result property="requestMsg" column="request_msg" jdbcType="VARCHAR"/> |
|||
<result property="requestTime" column="request_time" jdbcType="TIMESTAMP"/> |
|||
<result property="resMsg" column="res_msg" jdbcType="VARCHAR"/> |
|||
<result property="resTime" column="res_time" jdbcType="TIMESTAMP"/> |
|||
</resultMap> |
|||
|
|||
<sql id="Base_Column_List"> |
|||
id,message_id,request_status, |
|||
request_msg,request_time,res_msg, |
|||
res_time |
|||
</sql> |
|||
</mapper> |
|||
@ -1,10 +0,0 @@ |
|||
package com.xr.device_display.modules.analysis.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class HistogramDto { |
|||
|
|||
private dataset dataset; |
|||
|
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
package com.xr.device_display.modules.analysis.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class dataset { |
|||
|
|||
List<List<Object>> source; |
|||
} |
|||
@ -1,422 +0,0 @@ |
|||
|
|||
package com.xr.iec61850clent.common.util; |
|||
|
|||
import org.apache.poi.hssf.usermodel.*; |
|||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
|||
import org.apache.poi.ss.usermodel.Cell; |
|||
import org.apache.poi.xssf.usermodel.XSSFCell; |
|||
import org.apache.poi.xssf.usermodel.XSSFRow; |
|||
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|||
|
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.text.DecimalFormat; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.List; |
|||
|
|||
|
|||
public class ExcelUtil { |
|||
public static final int CELL_TYPE_INTEGER = 1; |
|||
public static final int CELL_TYPE_DOUBLE = 2; |
|||
public static final int CELL_TYPE_STRING = 3; |
|||
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
|||
public static final String UNSUPPORT_CELL_TYPE = "UNSUPPORT CELL TYPE"; |
|||
/** |
|||
* 特殊字符转义 |
|||
*/ |
|||
public static String[] SpecialChar = {"'", "\"", "[", "]"}; |
|||
|
|||
/** |
|||
* 得到workBook |
|||
* |
|||
* @return |
|||
* @throws IOException |
|||
*/ |
|||
public static XSSFWorkbook getWorkbook(InputStream in) throws IOException { |
|||
XSSFWorkbook wb = new XSSFWorkbook(in); |
|||
return wb; |
|||
} |
|||
|
|||
/** |
|||
* 得到第一个sheet |
|||
* |
|||
* @param wb |
|||
* @return |
|||
*/ |
|||
public static XSSFSheet getFirstSheet(XSSFWorkbook wb) { |
|||
return wb.getSheetAt(0); |
|||
} |
|||
|
|||
/** |
|||
* 得到指定的一个sheet |
|||
* |
|||
* @param wb |
|||
* @param sheetIndex |
|||
* @return |
|||
*/ |
|||
public static HSSFSheet getSheet(HSSFWorkbook wb, int sheetIndex) { |
|||
return wb.getSheetAt(sheetIndex); |
|||
} |
|||
|
|||
/** |
|||
* 通过名称 得到一个指定sheet |
|||
* |
|||
* @param wb |
|||
* @param sheetName |
|||
* @return |
|||
*/ |
|||
public static HSSFSheet getSheet(HSSFWorkbook wb, String sheetName) { |
|||
return wb.getSheet(sheetName); |
|||
} |
|||
|
|||
/** |
|||
* 得到 第一行的值 |
|||
* |
|||
* @param sheet |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String[] getFirstSheetRow(HSSFSheet sheet) throws Exception { |
|||
return getSheetRow(sheet, 0); |
|||
} |
|||
|
|||
/** |
|||
* 得到 第一行的值 |
|||
* |
|||
* @param sheet |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String[] getFirstSheetRow_xlsx(XSSFSheet sheet) throws Exception { |
|||
return getSheetRow_xlsx(sheet, 0); |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* 得到 指定sheet中 一行的值 |
|||
* |
|||
* @param rowNum |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String[] getSheetRow(HSSFSheet sheet, int rowNum) throws Exception { |
|||
HSSFRow sheetRow = sheet.getRow(rowNum); |
|||
if (sheetRow == null) |
|||
return null; |
|||
return getSheetRow(sheet, rowNum, sheetRow.getLastCellNum()); |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* 得到 指定sheet中 一行的值 |
|||
* |
|||
* @param rowNum |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String[] getSheetRow_xlsx(XSSFSheet sheet, int rowNum) throws Exception { |
|||
XSSFRow sheetRow = sheet.getRow(rowNum); |
|||
if (sheetRow == null) |
|||
return null; |
|||
return getSheetRow_xlsx(sheet, rowNum, sheetRow.getLastCellNum()); |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* 判断一个sheet的某一行是否都没有填写数据 |
|||
* |
|||
* @param sheet |
|||
* @param rowNum |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static boolean isNullsRow(HSSFSheet sheet, int rowNum) throws Exception { |
|||
HSSFRow sheetRow = sheet.getRow(rowNum); |
|||
if (sheetRow != null) { |
|||
int len = sheetRow.getPhysicalNumberOfCells(); |
|||
for (int i = 0; i < len; i++) { |
|||
@SuppressWarnings("deprecation") |
|||
HSSFCell cell = sheetRow.getCell((short) i); |
|||
if (cell != null && !getSheetCell(cell).equals("")) { |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} else { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* sheet中一行的值 |
|||
* |
|||
* @param sheet |
|||
* @param rowNum |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
@SuppressWarnings("deprecation") |
|||
public static String[] getSheetRow(HSSFSheet sheet, int rowNum, int colNum) throws Exception { |
|||
HSSFRow sheetRow = sheet.getRow(rowNum); |
|||
if (sheetRow == null) |
|||
return null; |
|||
HSSFCell sheetCell = null; |
|||
if (colNum == -1) { |
|||
return null; |
|||
} |
|||
String[] obj = new String[colNum]; |
|||
for (int i = 0; i < colNum; i++) { |
|||
sheetCell = sheetRow.getCell((short) i); |
|||
if (sheetCell == null) { |
|||
obj[i] = "NULL"; |
|||
continue; |
|||
} |
|||
obj[i] = getSheetCell(sheetCell); |
|||
} |
|||
return obj; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* |
|||
* sheet中一行的值 |
|||
* |
|||
* @param sheet |
|||
* @param rowNum |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
@SuppressWarnings("deprecation") |
|||
public static String[] getSheetRow_xlsx(XSSFSheet sheet, int rowNum, int colNum) throws Exception { |
|||
XSSFRow sheetRow = sheet.getRow(rowNum); |
|||
if (sheetRow == null) |
|||
return null; |
|||
XSSFCell sheetCell = null; |
|||
if (colNum == -1) { |
|||
return null; |
|||
} |
|||
String[] obj = new String[colNum]; |
|||
for (int i = 0; i < colNum; i++) { |
|||
sheetCell = sheetRow.getCell((short) i); |
|||
if (sheetCell == null) { |
|||
obj[i] = "NULL"; |
|||
continue; |
|||
} |
|||
obj[i] = getCellValue_xlsx(sheetCell); |
|||
// obj[i] = getSheetCell(sheetCell);
|
|||
} |
|||
return obj; |
|||
} |
|||
|
|||
public static String getCellValue_xlsx(Cell cell) throws Exception { |
|||
if (cell == null || cell.toString().trim().equals("")) { |
|||
return ""; |
|||
} else { |
|||
return cell.toString(); |
|||
} |
|||
} |
|||
|
|||
|
|||
public static String getCellTypeByRowAndCol(HSSFSheet sheet, int row, int col) { |
|||
HSSFRow sheetRow = sheet.getRow(row); |
|||
if (sheetRow == null) { |
|||
return null; |
|||
} |
|||
@SuppressWarnings("deprecation") |
|||
HSSFCell cell = sheetRow.getCell((short) col); |
|||
return getSheetCellType(cell); |
|||
} |
|||
|
|||
public static String getSheetCellType(HSSFCell sheetCell) { |
|||
if (sheetCell == null) { |
|||
return null; |
|||
} |
|||
return sheetCell.getCellType() + ""; |
|||
} |
|||
|
|||
public static String getStringByRowAndCol(HSSFSheet sheet, int row, int col) throws Exception { |
|||
return getStringByRowAndCol(sheet, row, col, true); |
|||
} |
|||
|
|||
public static String getStringByRowAndCol_xlsx(XSSFSheet sheet, int row, int col) throws Exception { |
|||
return getStringByRowAndCol_xlsx(sheet, row, col, true); |
|||
} |
|||
// 得到单元格的值
|
|||
public static String getStringByRowAndCol_xlsx(XSSFSheet sheet, int row, int col, boolean flag) |
|||
throws Exception { |
|||
XSSFRow sheetRow = sheet.getRow(row); |
|||
if (sheetRow == null) { |
|||
return null; |
|||
} |
|||
@SuppressWarnings("deprecation") |
|||
XSSFCell cell = sheetRow.getCell((short) col); |
|||
return getCellValue_xlsx(cell); |
|||
} |
|||
|
|||
|
|||
// 得到单元格的值
|
|||
public static String getStringByRowAndCol(HSSFSheet sheet, int row, int col, boolean flag) |
|||
throws Exception { |
|||
HSSFRow sheetRow = sheet.getRow(row); |
|||
if (sheetRow == null) { |
|||
return null; |
|||
} |
|||
@SuppressWarnings("deprecation") |
|||
HSSFCell cell = sheetRow.getCell((short) col); |
|||
return getSheetCell(cell, flag); |
|||
} |
|||
|
|||
/** |
|||
* 得到单元格的值 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static String getSheetCell(HSSFCell sheetCell) throws Exception { |
|||
return getSheetCell(sheetCell, true); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* |
|||
* @param sheetCell |
|||
* @param flag true 表示需要去掉 excel中的特殊字符 false 保持元值 |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String getSheetCell(HSSFCell sheetCell, boolean flag) throws Exception { |
|||
String obj = null; |
|||
if (sheetCell == null) { |
|||
return obj; |
|||
} |
|||
int cellType = sheetCell.getCellType(); |
|||
switch (cellType) { |
|||
case HSSFCell.CELL_TYPE_BLANK: |
|||
obj = sheetCell.getRichStringCellValue().getString(); |
|||
break; |
|||
case HSSFCell.CELL_TYPE_BOOLEAN: |
|||
obj = sheetCell.getBooleanCellValue() + ""; |
|||
break; |
|||
case HSSFCell.CELL_TYPE_ERROR: |
|||
obj = sheetCell.getErrorCellValue() + ""; |
|||
break; |
|||
case HSSFCell.CELL_TYPE_FORMULA: |
|||
obj = sheetCell.getCellFormula(); |
|||
break; |
|||
case HSSFCell.CELL_TYPE_NUMERIC: |
|||
if (HSSFDateUtil.isCellDateFormatted(sheetCell)) { |
|||
obj = dateTimeFormat(sheetCell.getDateCellValue()); |
|||
} else { |
|||
obj = String.valueOf(sheetCell.getNumericCellValue()); |
|||
if (obj.indexOf("E") != -1) { |
|||
DecimalFormat df = new DecimalFormat(); |
|||
try { |
|||
obj = (df.parse(obj)).toString(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
obj = ""; |
|||
} |
|||
} |
|||
if (obj.endsWith(".0")) { |
|||
obj = obj.substring(0, obj.length() - 2); |
|||
} |
|||
} |
|||
break; |
|||
case HSSFCell.CELL_TYPE_STRING: |
|||
obj = sheetCell.getRichStringCellValue().getString(); |
|||
break; |
|||
default: |
|||
obj = UNSUPPORT_CELL_TYPE; |
|||
break; |
|||
} |
|||
if (obj != null && !obj.trim().equals("")) { |
|||
obj = obj.trim(); |
|||
if (flag) { |
|||
for (int i = 0; i < SpecialChar.length; i++) { |
|||
obj = encoding(obj); |
|||
} |
|||
} |
|||
} |
|||
return obj; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public static Object getSheetCell(HSSFCell sheetCell, int dataType) throws Exception { |
|||
String strObj = getSheetCell(sheetCell, true); |
|||
Object obj = null; |
|||
if (strObj == null || strObj.trim().equals("")) |
|||
return null; |
|||
switch (dataType) { |
|||
case CELL_TYPE_INTEGER: |
|||
obj = new Integer(strObj); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
return obj; |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 判断单元格的日期格式 |
|||
* |
|||
* @param date |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String dateTimeFormat(java.util.Date date) throws Exception { |
|||
SimpleDateFormat pdf = new SimpleDateFormat(DATE_TIME_FORMAT); |
|||
String dateStr = ""; |
|||
try { |
|||
if (date != null) { |
|||
dateStr = pdf.format(date); |
|||
} |
|||
return dateStr; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
throw new Exception("EXCEL 中日期格式不对!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 特殊字符替换 |
|||
* |
|||
* @param _src |
|||
* @return |
|||
* @throws NullPointerException |
|||
*/ |
|||
public static String encoding(String _src) throws NullPointerException { |
|||
if (_src == null) |
|||
throw new NullPointerException("value of parameter '_src' is null."); |
|||
StringBuilder result = new StringBuilder(); |
|||
if (_src != null) { |
|||
_src = _src.trim(); |
|||
for (int pos = 0; pos < _src.length(); pos++) { |
|||
switch (_src.charAt(pos)) { |
|||
case '[': |
|||
result.append(""); |
|||
break; |
|||
case ']': |
|||
result.append(""); |
|||
break; |
|||
case '\'': |
|||
result.append(""); |
|||
break; |
|||
case '"': |
|||
result.append(""); |
|||
break; |
|||
default: |
|||
result.append(_src.charAt(pos)); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
} |
|||
@ -1,151 +0,0 @@ |
|||
package com.xr.iec61850clent.common.util; |
|||
|
|||
import com.xr.iec61850clent.models.entity.ExcelConfig; |
|||
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
|||
import org.apache.poi.hssf.usermodel.HSSFSheet; |
|||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|||
import org.apache.poi.ss.usermodel.*; |
|||
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.text.DecimalFormat; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.ArrayList; |
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
@Component |
|||
public class IEC61850Config { |
|||
|
|||
private static final ThreadLocal<List<ExcelConfig>> CURRENT_CONFIG = new ThreadLocal<>(); |
|||
|
|||
@PostConstruct |
|||
public void setExcelConfig(){ |
|||
List<ExcelConfig> excelConfigs = readExcel(); |
|||
CURRENT_CONFIG.set(excelConfigs); |
|||
} |
|||
|
|||
public static List<ExcelConfig> readExcel(){ |
|||
InputStream inputStream = IEC61850Config.class.getClassLoader().getResourceAsStream("IEC61850.xlsx"); |
|||
XSSFWorkbook wb = null; |
|||
XSSFSheet sheet = null; // 创建工作sheet
|
|||
List<ExcelConfig> dataList = new ArrayList<>(); |
|||
try { |
|||
wb = ExcelUtil.getWorkbook(inputStream); |
|||
sheet = ExcelUtil.getFirstSheet(wb); |
|||
int readRowCount =sheet.getPhysicalNumberOfRows(); |
|||
// 解析sheet 的行
|
|||
for (int j = sheet.getFirstRowNum(); j < readRowCount; j++) { |
|||
ExcelConfig excelConfig=new ExcelConfig(); |
|||
Row row = sheet.getRow(j); |
|||
if(j == 0){ |
|||
continue; |
|||
} |
|||
if (row == null) { |
|||
continue; |
|||
} |
|||
if (row.getFirstCellNum() < 0) { |
|||
continue; |
|||
} |
|||
// 解析sheet 的列
|
|||
Cell cell0 = row.getCell(0); |
|||
cell0.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setDeviceIp(getCellValue(wb, cell0)); |
|||
|
|||
Cell cell1 = row.getCell(1); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setDevice(getCellValue(wb, cell1)); |
|||
|
|||
Cell cell2 = row.getCell(2); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setName(getCellValue(wb, cell2)); |
|||
|
|||
Cell cell3 = row.getCell(3); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setConnectId(getCellValue(wb, cell3)); |
|||
|
|||
Cell cell4 = row.getCell(4); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setAddress(getCellValue(wb, cell4)); |
|||
|
|||
Cell cell5 = row.getCell(5); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setGgio(getCellValue(wb, cell5)); |
|||
|
|||
Cell cell6 = row.getCell(6); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setAng(getCellValue(wb, cell6)); |
|||
|
|||
Cell cell7 = row.getCell(7); |
|||
cell1.setCellType(Cell.CELL_TYPE_STRING); |
|||
excelConfig.setMsg(getCellValue(wb, cell7)); |
|||
dataList.add(excelConfig); |
|||
} |
|||
} catch (Exception e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
return dataList; |
|||
} |
|||
|
|||
private static String getCellValue(Workbook wb, Cell cell) { |
|||
Object columnValue = null; |
|||
if (cell != null) { |
|||
DecimalFormat df = new DecimalFormat("0");// 格式化 number
|
|||
// String
|
|||
// 字符
|
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串
|
|||
DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
|
|||
switch (cell.getCellType()) { |
|||
case Cell.CELL_TYPE_STRING: |
|||
columnValue = cell.getStringCellValue(); |
|||
break; |
|||
case Cell.CELL_TYPE_NUMERIC: |
|||
if ("@".equals(cell.getCellStyle().getDataFormatString())) { |
|||
columnValue = df.format(cell.getNumericCellValue()); |
|||
} else if ("General".equals(cell.getCellStyle().getDataFormatString())) { |
|||
columnValue = nf.format(cell.getNumericCellValue()); |
|||
} else { |
|||
columnValue = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())); |
|||
} |
|||
break; |
|||
case Cell.CELL_TYPE_BOOLEAN: |
|||
columnValue = cell.getBooleanCellValue(); |
|||
break; |
|||
case Cell.CELL_TYPE_BLANK: |
|||
columnValue = ""; |
|||
break; |
|||
case Cell.CELL_TYPE_FORMULA: |
|||
// 格式单元格
|
|||
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); |
|||
evaluator.evaluateFormulaCell(cell); |
|||
CellValue cellValue = evaluator.evaluate(cell); |
|||
columnValue = cellValue.getNumberValue(); |
|||
break; |
|||
default: |
|||
columnValue = cell.toString(); |
|||
} |
|||
} |
|||
return columnValue.toString(); |
|||
} |
|||
|
|||
|
|||
public static ExcelConfig getExcelConfig(String ip,String node){ |
|||
List<ExcelConfig> list = CURRENT_CONFIG.get(); |
|||
if(null == list || list.isEmpty()){ |
|||
list = readExcel(); |
|||
CURRENT_CONFIG.set(list); |
|||
} |
|||
for(ExcelConfig config:list){ |
|||
String node1 = config.getName()+config.getConnectId()+config.getAddress()+config.getGgio()+"."+config.getAng(); |
|||
if(ip.equals(config.getDeviceIp()) && node.equals(node1)){ |
|||
return config; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
package com.xr.iec61850clent.models.entity; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class ExcelConfig { |
|||
|
|||
private String deviceIp; |
|||
|
|||
private String device; |
|||
|
|||
private String name; |
|||
|
|||
private String connectId; |
|||
|
|||
private String address; |
|||
|
|||
private String ggio; |
|||
|
|||
private String ang; |
|||
|
|||
private String msg; |
|||
|
|||
} |
|||
Binary file not shown.
@ -1,81 +0,0 @@ |
|||
package com.xr.iec61850server.models.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import java.io.Serializable; |
|||
import java.time.LocalDateTime; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* |
|||
* @TableName lds5000 |
|||
*/ |
|||
@TableName(value ="lds5000") |
|||
@Data |
|||
public class Lds5000 implements Serializable { |
|||
/** |
|||
* 主键 |
|||
*/ |
|||
@TableId(type = IdType.AUTO) |
|||
private Integer id; |
|||
|
|||
/** |
|||
* 客户端ip |
|||
*/ |
|||
private String clentIp; |
|||
|
|||
/** |
|||
* 描述 |
|||
*/ |
|||
private String ldsDesc; |
|||
|
|||
/** |
|||
* 类型 |
|||
*/ |
|||
private String fc; |
|||
|
|||
/** |
|||
* 0表计1一体化电源 |
|||
*/ |
|||
private Integer type; |
|||
|
|||
/** |
|||
* 结果节点 |
|||
*/ |
|||
private String node; |
|||
|
|||
/** |
|||
* 状态0true 1false |
|||
*/ |
|||
private String q; |
|||
|
|||
/** |
|||
* 时间 |
|||
*/ |
|||
private LocalDateTime t; |
|||
|
|||
/** |
|||
* 状态类 |
|||
*/ |
|||
private String stVal; |
|||
|
|||
/** |
|||
* 模拟值 |
|||
*/ |
|||
private String f; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
private LocalDateTime createTime; |
|||
|
|||
/** |
|||
* 修改时间 |
|||
*/ |
|||
private LocalDateTime updateTime; |
|||
|
|||
@TableField(exist = false) |
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
package com.xr.iec61850server.models.mapper; |
|||
|
|||
import com.xr.iec61850server.models.entity.Lds5000; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* @author 范亚杰 |
|||
* @description 针对表【lds5000】的数据库操作Mapper |
|||
* @createDate 2023-09-19 14:54:07 |
|||
* @Entity com.xr.iec61850server.models.entity.Lds5000 |
|||
*/ |
|||
public interface Lds5000Mapper extends BaseMapper<Lds5000> { |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
@ -1,13 +0,0 @@ |
|||
package com.xr.iec61850server.models.service; |
|||
|
|||
import com.xr.iec61850server.models.entity.Lds5000; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
/** |
|||
* @author 范亚杰 |
|||
* @description 针对表【lds5000】的数据库操作Service |
|||
* @createDate 2023-09-19 14:54:07 |
|||
*/ |
|||
public interface Lds5000Service extends IService<Lds5000> { |
|||
|
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
package com.xr.iec61850server.models.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.xr.iec61850server.models.entity.Lds5000; |
|||
import com.xr.iec61850server.models.service.Lds5000Service; |
|||
import com.xr.iec61850server.models.mapper.Lds5000Mapper; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* @author 范亚杰 |
|||
* @description 针对表【lds5000】的数据库操作Service实现 |
|||
* @createDate 2023-09-19 14:54:07 |
|||
*/ |
|||
@Service |
|||
public class Lds5000ServiceImpl extends ServiceImpl<Lds5000Mapper, Lds5000> |
|||
implements Lds5000Service{ |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
@ -1,28 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.xr.iec61850server.models.mapper.Lds5000Mapper"> |
|||
|
|||
<resultMap id="BaseResultMap" type="com.xr.iec61850server.models.entity.Lds5000"> |
|||
<id property="id" column="id" jdbcType="INTEGER"/> |
|||
<result property="clentIp" column="clent_ip" jdbcType="VARCHAR"/> |
|||
<result property="ldsDesc" column="lds_desc" jdbcType="VARCHAR"/> |
|||
<result property="fc" column="fc" jdbcType="VARCHAR"/> |
|||
<result property="type" column="type" jdbcType="INTEGER"/> |
|||
<result property="node" column="node" jdbcType="VARCHAR"/> |
|||
<result property="q" column="q" jdbcType="VARCHAR"/> |
|||
<result property="t" column="t" jdbcType="TIMESTAMP"/> |
|||
<result property="stVal" column="st_val" jdbcType="VARCHAR"/> |
|||
<result property="f" column="f" jdbcType="VARCHAR"/> |
|||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> |
|||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> |
|||
</resultMap> |
|||
|
|||
<sql id="Base_Column_List"> |
|||
id,clent_ip,lds_desc, |
|||
fc,type,node, |
|||
q,t,st_val, |
|||
f,create_time,update_time |
|||
</sql> |
|||
</mapper> |
|||
@ -1,120 +0,0 @@ |
|||
package com.xr.clent.utils; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.nio.ByteBuffer; |
|||
import java.util.Arrays; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
public class ModbusRtuUtil { |
|||
|
|||
public static void main(String[] args) { |
|||
// String str="FE 04 1A 08 D2 0C 35 06 6C 60 79 90 1C 04 04 00 00 00 00 00 00 00 00 00 00 00 00 CF 0A";
|
|||
// String str16[] = str.split("\\s+");
|
|||
// System.out.println("设备地址:"+Integer.parseInt(str16[0], 16));
|
|||
// System.out.println("功能码:"+Integer.parseInt(str16[1], 16));
|
|||
// System.out.println("字节数:"+Integer.parseInt(str16[2], 16));
|
|||
// System.out.println("温度:"+hexToDecimal(str16[3]+str16[4]));
|
|||
// System.out.println("湿度:"+hexToDecimal(str16[5]+str16[6]));
|
|||
// System.out.println("CO2:"+hexToDecimal(str16[7]+str16[8]));
|
|||
// System.out.println("光照:"+hexToDecimal(str16[9]+str16[10]));
|
|||
// System.out.println("大气压:"+hexToDecimal(str16[11]+str16[12]));
|
|||
// System.out.println("风速:"+hexToDecimal(str16[13]+str16[14]));
|
|||
// System.out.println("风向:"+hexToDecimal(str16[15]+str16[16]));
|
|||
// System.out.println("土壤湿度:"+hexToDecimal(str16[17]+str16[18]));
|
|||
// System.out.println("土壤温度:"+hexToDecimal(str16[19]+str16[20]));
|
|||
// System.out.println("PM2.5:"+hexToDecimal(str16[21]+str16[22]));
|
|||
// System.out.println("PM1.0:"+hexToDecimal(str16[23]+str16[24]));
|
|||
// System.out.println("PM10:"+hexToDecimal(str16[25]+str16[26]));
|
|||
// System.out.println("校验码:"+str16[27]+str16[28]);
|
|||
readHex(); |
|||
} |
|||
|
|||
|
|||
public static void readHex(){ |
|||
String str = "FE 04 3C 00 00 00 00 00 00 00 00 00 00 00 00 F0 00 45 13 D0 00 45 30 40 00 44 45 CC 00 46 01 3D 00 47 C7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1F F1"; |
|||
String str16[] = str.split("\\s+"); |
|||
int lth=str16.length; |
|||
System.out.println("设备地址:"+Integer.parseInt(str16[0], 16)); |
|||
System.out.println("功能码:"+Integer.parseInt(str16[1], 16)); |
|||
System.out.println("字节数:"+Integer.parseInt(str16[2], 16)); |
|||
System.out.println("校验码:"+str16[lth-1]+" "+str16[lth-2]); |
|||
String [] strs = Arrays.copyOfRange(str16, 3, lth-2); |
|||
String s = ""; |
|||
Map<Integer,String> map=new HashMap<>(); |
|||
map.put(1,"单次雨量"); |
|||
map.put(2,"瞬时雨量"); |
|||
map.put(3,"总雨量"); |
|||
map.put(4,"温度"); |
|||
map.put(5,"湿度"); |
|||
map.put(6,"CO2"); |
|||
map.put(7,"光照"); |
|||
map.put(8,"大气压"); |
|||
map.put(9,"风速"); |
|||
map.put(10,"风向"); |
|||
map.put(11,"土壤湿度"); |
|||
map.put(12,"土壤温度"); |
|||
map.put(13,"PM2.5"); |
|||
map.put(14,"PM1.0"); |
|||
map.put(15,"PM10"); |
|||
for(int i=0;i<strs.length-1;i++){ |
|||
s+=strs[i]; |
|||
if(s.length() == 8){ |
|||
int b =(i+1)/4; |
|||
String name = map.get(b); |
|||
BigDecimal d = new BigDecimal(1); |
|||
if(b == 4 || b ==5 || b==7|| b==9){ |
|||
d = new BigDecimal("0.01"); |
|||
} |
|||
if (b == 8){ |
|||
d = new BigDecimal("0.001"); |
|||
} |
|||
if(b == 10 || b == 12 || b == 11){ |
|||
d = new BigDecimal("0.1"); |
|||
} |
|||
|
|||
|
|||
s=s.substring(s.length()-4)+s.substring(0,4); |
|||
System.out.println(name+":"+new BigDecimal(hexStringToJavaFloat(s)).multiply(d)); |
|||
s=""; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
public static int hexToDecimal(String hex) { |
|||
int decimal = 0; |
|||
int length = hex.length(); |
|||
|
|||
for (int i = 0; i < length; i++) { |
|||
char c = hex.charAt(i); |
|||
int digit = Character.digit(c, 16); |
|||
decimal += digit * Math.pow(16, 2 * (length - i - 1)); |
|||
} |
|||
|
|||
return decimal; |
|||
} |
|||
|
|||
public static float hexStringToJavaFloat(String message){ |
|||
// 将字符串转换为字节数组
|
|||
byte[] bytes = hexStringToByteArray(message); |
|||
|
|||
// 创建一个ByteBuffer
|
|||
ByteBuffer buffer = ByteBuffer.wrap(bytes); |
|||
|
|||
// 获取float值
|
|||
return buffer.getFloat(); |
|||
} |
|||
|
|||
public static byte[] hexStringToByteArray(String s) { |
|||
int len = s.length(); |
|||
byte[] data = new byte[len / 2]; |
|||
for (int i = 0; i < len; i += 2) { |
|||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) |
|||
+ Character.digit(s.charAt(i+1), 16)); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
package com.xr.device_udpclent.common.config; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class BodyRequestConfig { |
|||
|
|||
private String ip; |
|||
|
|||
private Integer port; |
|||
|
|||
private String username; |
|||
|
|||
private String password; |
|||
|
|||
private String agreement; |
|||
|
|||
private String uri; |
|||
|
|||
private String entity; |
|||
|
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
package com.xr.device_udpclent.common.config; |
|||
|
|||
public interface Const { |
|||
|
|||
|
|||
/** |
|||
* 请求onvifurl拼接 |
|||
*/ |
|||
String REQUEST_ONVIF_URL = "http://%s:%d/onvif/media_service"; |
|||
|
|||
String ABSOLUTE_MOVE= "http://%s:%d/onvif/ptz_service"; |
|||
|
|||
String PTZ_MOVE= "http://%s:%d/onvif/PTZ"; |
|||
|
|||
/** |
|||
* 请求onvifurl拼接 |
|||
*/ |
|||
String REQUEST_DEVICE_ONVIF_URL = "http://%s:%d/onvif/device_service"; |
|||
|
|||
/** |
|||
*返回的respon 中的headers |
|||
*/ |
|||
String HEADERS_ONVIF_WWW_AUTHENTICATE= "WWW-Authenticate"; |
|||
|
|||
|
|||
/** |
|||
* token |
|||
*/ |
|||
String EQUEST_ONVIF_TOKEN="Digest username=\"%s\", realm=\"%s\", qop=\"%s\", algorithm=\"%s\", uri=\"%s\", nonce=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\""; |
|||
|
|||
|
|||
} |
|||
@ -1,59 +0,0 @@ |
|||
package com.xr.device_udpclent.common.config; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.File; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
@Data |
|||
public class FormRequestConfig { |
|||
/** |
|||
* 协议,http或者https |
|||
*/ |
|||
private String agreement = "http"; |
|||
/** |
|||
* example 175.13.254.22 |
|||
*/ |
|||
private String ip; |
|||
|
|||
/** |
|||
* 端口 |
|||
*/ |
|||
private Integer port = 80; |
|||
|
|||
/** |
|||
* 账号 |
|||
* example admin |
|||
*/ |
|||
private String username; |
|||
|
|||
/** |
|||
* 原密码 |
|||
* example 123456 |
|||
*/ |
|||
private String password; |
|||
|
|||
/** |
|||
* 除了协议、ip,端口后面的uri |
|||
* example /ISAPI/System/TwowayAudio/channels |
|||
*/ |
|||
private String uri; |
|||
|
|||
/** |
|||
* 请求参数 |
|||
*/ |
|||
private Map<String,String> formData = new HashMap<>(); |
|||
|
|||
private File file; |
|||
|
|||
/** |
|||
* 文件请求的name |
|||
*/ |
|||
private String fileName; |
|||
|
|||
/** |
|||
* application/json |
|||
* text/xml |
|||
*/ |
|||
private String type = "application/json"; |
|||
} |
|||
@ -1,55 +0,0 @@ |
|||
package com.xr.device_udpclent.common.config; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.Setter; |
|||
import org.apache.http.Header; |
|||
import org.apache.http.HttpStatus; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Setter |
|||
@Getter |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class HttpResponseBean { |
|||
private String body; |
|||
private List<Header> headers; |
|||
private Integer status; |
|||
|
|||
/** |
|||
* 获取头部信息。 |
|||
* @param name |
|||
* @return |
|||
*/ |
|||
public Header getFirstHeader(final String name) { |
|||
for (int i = 0; i < this.headers.size(); i++) { |
|||
final Header header = this.headers.get(i); |
|||
if (header.getName().equalsIgnoreCase(name)) { |
|||
return header; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/*** |
|||
* 判断是否成功 |
|||
*/ |
|||
public static boolean isSuccess(HttpResponseBean httpResponseBean){ |
|||
return httpResponseBean!= null && HttpStatus.SC_OK ==httpResponseBean.getStatus(); |
|||
} |
|||
|
|||
|
|||
/*** |
|||
* 判断是否是401 |
|||
*/ |
|||
public static boolean isUnAuthorzied(HttpResponseBean httpResponseBean){ |
|||
return httpResponseBean!= null && HttpStatus.SC_UNAUTHORIZED ==httpResponseBean.getStatus(); |
|||
} |
|||
|
|||
public HttpResponseBean(String body) { |
|||
this.body = body; |
|||
} |
|||
} |
|||
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue