Commit f5dfab98 authored by tangwei's avatar tangwei

增加es

parent 8caa8b83
package com.yeejoin.amos.boot.module.jxiop.biz.ESDto;
import io.github.classgraph.json.Id;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.util.Date;
/**
* @description:
* @author: tw
* @createDate: 2023/8/8
*/
@Data
@Accessors(chain = true)
@Document(indexName = "jxiop_equipments")
public class ESEquipments {
@Id
private String id;
@Field(type = FieldType.Text, index = false)
private String address;
@Field(type = FieldType.Text, index = false)
private String dataType;
@Field(type = FieldType.Text)
private String equipmentSpecificName;
@Field(type = FieldType.Text)
private String gatewayId;
@Field(type = FieldType.Text)
private String isAlarm;
@Field(type = FieldType.Date, format = DateFormat.basic_date_time, index = false)
private Date createdTime;
@Field(type = FieldType.Text , index = false)
private String unit;
@Field(type = FieldType.Text, index = false,fielddata=true)
private String value;
@Field(type = FieldType.Double, index = false,fielddata=true)
private Double valueDouble;
@Field(type = FieldType.Text , index = false)
private String valueLabel;
@Field(type = FieldType.Text , index = false)
private String traceId;
@Field(type = FieldType.Text )
private String equipmentIndexName;
@Field(type = FieldType.Text )
private String equipmentNumber;
@Field(type = FieldType.Text)
private String frontModule;
@Field(type = FieldType.Text)
private String systemType;
@Field(type = FieldType.Text , index = false)
private String pictureName;
@Field(type = FieldType.Text , index = false)
private String displayName;
public ESEquipments(Double valueDouble,String id, String address, String dataType, String equipmentSpecificName, String gatewayId, String isAlarm, Date createdTime, String unit, String value, String valueLabel, String traceId, String equipmentIndexName, String equipmentNumber, String frontModule, String systemType, String pictureName, String displayName) {
this.valueDouble = valueDouble;
this.id = id;
this.address = address;
this.dataType = dataType;
this.equipmentSpecificName = equipmentSpecificName;
this.gatewayId = gatewayId;
this.isAlarm = isAlarm;
this.createdTime = createdTime;
this.unit = unit;
this.value = value;
this.valueLabel = valueLabel;
this.traceId = traceId;
this.equipmentIndexName = equipmentIndexName;
this.equipmentNumber = equipmentNumber;
this.frontModule = frontModule;
this.systemType = systemType;
this.pictureName = pictureName;
this.displayName = displayName;
}
public ESEquipments() {
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.config;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.tomcat.util.codec.binary.Base64;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}")
private String uris;
@Value("${elasticsearch.username}")
private String username;
@Value("${elasticsearch.password}")
private String password;
@Bean
@Qualifier("highLevelClient")
public RestHighLevelClient restHighLevelClient() {
try {
String url = uris.replace("http://", "");
final String[] parts = StringUtils.split(url, ":");
HttpHost httpHost = new HttpHost(parts[0], Integer.parseInt(parts[1]), "http");
RestClientBuilder builder = RestClient.builder(httpHost);
//增加安全配置,使用kibana,勿删
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));
builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
@Override
public RequestConfig.Builder customizeRequestConfig(
RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(5000 * 1000) // 连接超时(默认为1秒)
.setSocketTimeout(6000 * 1000);// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
}
});// 调整最大重试超时时间(默认为30秒).setMaxRetryTimeoutMillis(60000);
//增加安全配置,使用kibana,勿删
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
});
return new RestHighLevelClient(builder);
} catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
}
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.repository;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* @description:
* @author: tw
* @createDate: 2023/8/8
*/
@Repository
public interface ESEquipmentsRepository extends PagingAndSortingRepository<ESEquipments, String> {
}
...@@ -73,4 +73,18 @@ station.isok=false ...@@ -73,4 +73,18 @@ station.isok=false
station.section=10 station.section=10
gl.sum.column=日发电量,月发电量,年发电量 gl.sum.column=日发电量,月发电量,年发电量
gl.avg.column=有功功率,日利用小时,瞬时风速 gl.avg.column=有功功率,日利用小时,瞬时风速
\ No newline at end of file
spring.elasticsearch.rest.uris=http://39.98.224.23:9200
spring.elasticsearch.rest.connection-timeout=30000
spring.elasticsearch.rest.username=elastic
spring.elasticsearch.rest.password=123456
spring.elasticsearch.rest.read-timeout=30000
#elasticsearch.username= elastic
#elasticsearch.password= 123456
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment