代码提交
This commit is contained in:
1 parent
f872556dab
commit
798878a541
586 files changed
+65645
No files matched your search
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>aibird</artifactId>
|
||||
<groupId>net.hzvtc</groupId>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>ai-bird-es</artifactId>
|
||||
<description>
|
||||
springboot-elasticsearch-service
|
||||
</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>co.elastic.clients</groupId>
|
||||
<artifactId>elasticsearch-java</artifactId>
|
||||
<version>8.14.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
<version>8.14.3</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>co.elastic.clients</groupId>-->
|
||||
<!-- <artifactId>elasticsearch-java</artifactId>-->
|
||||
<!-- <version>8.2.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.elasticsearch.client</groupId>-->
|
||||
<!-- <artifactId>elasticsearch-rest-client</artifactId>-->
|
||||
<!-- <version>8.14.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.elasticsearch.client</groupId>-->
|
||||
<!-- <artifactId>elasticsearch-rest-high-level-client</artifactId>-->
|
||||
<!-- <version>7.17.22</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>5.3.29</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.hzvtc</groupId>
|
||||
<artifactId>ai-bird-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.hzvtc</groupId>
|
||||
<artifactId>ai-bird-system</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.13.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.hzvtc.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class CustomDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {
|
||||
|
||||
private static final DateTimeFormatter INPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
|
||||
|
||||
@Override
|
||||
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt)
|
||||
throws IOException, JsonProcessingException {
|
||||
String dateStr = p.getText();
|
||||
return ZonedDateTime.parse(dateStr, INPUT_FORMATTER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.hzvtc.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class CustomDateTimeSerializer extends JsonSerializer<ZonedDateTime> {
|
||||
|
||||
private static final DateTimeFormatter OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
String formattedDate = value.format(OUTPUT_FORMATTER);
|
||||
gen.writeString(formattedDate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package net.hzvtc.config;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.json.JsonpMapper;
|
||||
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
||||
import co.elastic.clients.transport.ElasticsearchTransport;
|
||||
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import net.hzvtc.config.JacksonConfiguration;
|
||||
import org.apache.http.Header;
|
||||
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.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Configuration
|
||||
public class ESClientConfig {
|
||||
private static final Logger log = LoggerFactory.getLogger(ESClientConfig.class);
|
||||
@Value(value="${spring.elastic.hosts}")
|
||||
private String hosts;
|
||||
@Value(value="${spring.elastic.http}")
|
||||
private String http;
|
||||
@Value(value="${spring.elastic.apiKey}")
|
||||
private String apiKey;
|
||||
@Value(value="${spring.elastic.username}")
|
||||
private String username;
|
||||
@Value(value="${spring.elastic.password}")
|
||||
private String passwd;
|
||||
private static String certName;
|
||||
|
||||
@Value(value="${spring.elastic.certName}")
|
||||
public void setAppKey(String certName) {
|
||||
ESClientConfig.certName = certName;
|
||||
}
|
||||
|
||||
private HttpHost[] toHttpHost() {
|
||||
if (!StringUtils.hasLength((String)this.hosts)) {
|
||||
throw new RuntimeException("invalid elasticsearch configuration");
|
||||
}
|
||||
String[] hostArray = this.hosts.split(",");
|
||||
HttpHost[] httpHosts = new HttpHost[hostArray.length];
|
||||
for (int i = 0; i < hostArray.length; ++i) {
|
||||
HttpHost httpHost;
|
||||
String[] strings = hostArray[i].split(":");
|
||||
httpHosts[i] = httpHost = new HttpHost(strings[0], Integer.parseInt(strings[1]), "https");
|
||||
}
|
||||
return httpHosts;
|
||||
}
|
||||
|
||||
@Bean(value={"clientByPasswd"})
|
||||
public ElasticsearchClient clientByPasswd() {
|
||||
ElasticsearchTransport transport = ESClientConfig.getElasticsearchTransport(this.username, this.passwd, this.toHttpHost());
|
||||
return new ElasticsearchClient(transport);
|
||||
}
|
||||
|
||||
private static SSLContext buildSSLContext() {
|
||||
ClassPathResource resource = new ClassPathResource(certName);
|
||||
SSLContext sslContext = null;
|
||||
try {
|
||||
Certificate trustedCa;
|
||||
CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||
try (InputStream is = resource.getInputStream();){
|
||||
trustedCa = factory.generateCertificate(is);
|
||||
}
|
||||
KeyStore trustStore = KeyStore.getInstance("pkcs12");
|
||||
trustStore.load(null, null);
|
||||
trustStore.setCertificateEntry("ca", trustedCa);
|
||||
SSLContextBuilder sslContextBuilder = SSLContexts.custom().loadTrustMaterial(trustStore, null);
|
||||
sslContext = sslContextBuilder.build();
|
||||
}
|
||||
catch (IOException | KeyManagementException | KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
|
||||
log.error("ES\u8fde\u63a5\u8ba4\u8bc1\u5931\u8d25", (Throwable)e);
|
||||
}
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
private static ElasticsearchTransport getElasticsearchTransport(String username, String passwd, HttpHost ... hosts) {
|
||||
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(AuthScope.ANY, (Credentials)new UsernamePasswordCredentials(username, passwd));
|
||||
RestClientBuilder.HttpClientConfigCallback callback = arg_0 -> ESClientConfig.lambda$getElasticsearchTransport$0((CredentialsProvider)credentialsProvider, arg_0);
|
||||
RestClient client = RestClient.builder((HttpHost[])hosts).setHttpClientConfigCallback(callback).build();
|
||||
return new RestClientTransport(client, (JsonpMapper)new JacksonJsonpMapper(JacksonConfiguration.createObjectMapper()));
|
||||
}
|
||||
|
||||
private static ElasticsearchTransport getElasticsearchTransport(String apiKey, HttpHost ... hosts) {
|
||||
Header[] headers = new Header[]{new BasicHeader("Authorization", "ApiKey " + apiKey)};
|
||||
RestClientBuilder.HttpClientConfigCallback callback = httpAsyncClientBuilder -> httpAsyncClientBuilder.setSSLContext(ESClientConfig.buildSSLContext()).setSSLHostnameVerifier((HostnameVerifier)NoopHostnameVerifier.INSTANCE);
|
||||
RestClient client = RestClient.builder((HttpHost[])hosts).setHttpClientConfigCallback(callback).setDefaultHeaders(headers).build();
|
||||
return new RestClientTransport(client, (JsonpMapper)new JacksonJsonpMapper());
|
||||
}
|
||||
|
||||
public void setHosts(String hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
public void setHttp(String http) {
|
||||
this.http = http;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setPasswd(String passwd) {
|
||||
this.passwd = passwd;
|
||||
}
|
||||
|
||||
private static /* synthetic */ HttpAsyncClientBuilder lambda$getElasticsearchTransport$0(CredentialsProvider credentialsProvider, HttpAsyncClientBuilder httpAsyncClientBuilder) {
|
||||
return httpAsyncClientBuilder.setSSLContext(ESClientConfig.buildSSLContext()).setSSLHostnameVerifier((HostnameVerifier)NoopHostnameVerifier.INSTANCE).setDefaultCredentialsProvider(credentialsProvider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.hzvtc.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class JacksonConfiguration {
|
||||
public static ObjectMapper createObjectMapper() {
|
||||
return new ObjectMapper()
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.registerModule(new JavaTimeModule()
|
||||
.addSerializer(ZonedDateTime.class, new CustomDateTimeSerializer())
|
||||
.addDeserializer(ZonedDateTime.class, new CustomDateTimeDeserializer()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package net.hzvtc.es.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.hzvtc.common.core.domain.AjaxResult;
|
||||
import net.hzvtc.common.utils.file.FileUtils;
|
||||
import net.hzvtc.es.service.EsRecordReportService;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value={"/es/result/report"})
|
||||
public class EsRecordReportController {
|
||||
private final EsRecordReportService esRecordReportService;
|
||||
|
||||
@PostMapping(value={"/getBirdStatData"})
|
||||
public AjaxResult getBirdStatData(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.getBirdDailyReportStatByParam(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/getBirdWeeklyStatData"})
|
||||
public AjaxResult getBirdWeeklyStatData(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.getSpeciesWeeklyReportByParam(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/getBirdMonthlyStatData"})
|
||||
public AjaxResult getBirdMonthlyStatData(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.getSpeciesMonthlyReportByParam(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/getBirdYearlyStatData"})
|
||||
public AjaxResult getBirdYearlyStatData(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.getSpeciesYearlyReportByParam(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/downloadWeeklyReport"})
|
||||
public void downloadWeeklyReport(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("areaId", params.get("areaId"));
|
||||
obj.put("calcDate", params.get("calcDate"));
|
||||
obj.put("isDeleted", (Object)0);
|
||||
String filePath = this.esRecordReportService.getBirdDataStatWeeklyFileByParam(obj);
|
||||
this.processPath(filePath, response);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/downloadMonthlyReport"})
|
||||
public void downloadMonthlyReport(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("areaId", params.get("areaId"));
|
||||
obj.put("calcDate", params.get("calcDate"));
|
||||
obj.put("isDeleted", (Object)0);
|
||||
String filePath = this.esRecordReportService.getBirdDataMonthlyStatFileByParam(obj);
|
||||
this.processPath(filePath, response);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/downloadYearlyReport"})
|
||||
public void downloadYearlyReport(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("areaId", params.get("areaId"));
|
||||
obj.put("calcDate", params.get("calcDate"));
|
||||
obj.put("isDeleted", (Object)0);
|
||||
String filePath = this.esRecordReportService.getBirdDataYearlyStatFileByParam(obj);
|
||||
this.processPath(filePath, response);
|
||||
}
|
||||
|
||||
private void processPath(String filePath, HttpServletResponse response) {
|
||||
if (filePath != null) {
|
||||
try {
|
||||
String realFileName = System.currentTimeMillis() + ".xlsx";
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
FileUtils.setAttachmentResponseHeader((HttpServletResponse)response, (String)realFileName);
|
||||
FileUtils.writeBytes((String)filePath, (OutputStream)response.getOutputStream());
|
||||
}
|
||||
catch (Exception exception) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value={"/sendWeeklyEmail"})
|
||||
public AjaxResult sendWeeklyEmail(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.sendBirdDataStatWeeklyEmail(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/sendMonthlyEmail"})
|
||||
public AjaxResult sendMonthlyEmail(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.sendBirdDataStatMonthlyEmail(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/sendYearlyEmail"})
|
||||
public AjaxResult sendYearlyEmail(@RequestBody JSONObject object) {
|
||||
object.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esRecordReportService.sendBirdDataStatYearlyEmail(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/downloadDailyReport"})
|
||||
public void downloadReport(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("areaId", params.get("areaId"));
|
||||
obj.put("calcDate", params.get("calcDate"));
|
||||
obj.put("isDeleted", (Object)0);
|
||||
String filePath = this.esRecordReportService.getBirdDataStatDailyFileByParam(obj);
|
||||
this.processPath(filePath, response);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/sendDailyEmail"})
|
||||
public AjaxResult sendEmail(@RequestBody JSONObject object) {
|
||||
return AjaxResult.success((Object)this.esRecordReportService.sendBirdDataStatEmail(object));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/speciesMediaStatList"})
|
||||
public JSONObject getSpeciesMediaListByParam(@RequestBody JSONObject object) {
|
||||
return this.esRecordReportService.getSpeciesMediaListByParam(object);
|
||||
}
|
||||
|
||||
public EsRecordReportController(EsRecordReportService esRecordReportService) {
|
||||
this.esRecordReportService = esRecordReportService;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package net.hzvtc.es.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import net.hzvtc.common.core.domain.AjaxResult;
|
||||
import net.hzvtc.common.core.page.TableDataInfo;
|
||||
import net.hzvtc.device.domain.DeviceInfo;
|
||||
import net.hzvtc.es.service.EsResultRecordDetailsService;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value={"/es/result/details"})
|
||||
public class EsResultRecordDetailsController {
|
||||
private final EsResultRecordDetailsService esResultRecordDetailsService;
|
||||
|
||||
@PostMapping(value={"/querySpeciesByParam"})
|
||||
public TableDataInfo querySpeciesListByParam(@RequestBody JSONObject params) {
|
||||
params.put("isDeleted", (Object)0);
|
||||
return this.esResultRecordDetailsService.querySpeciesRecordListByParam(params, 0);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/queryDataByParam"})
|
||||
public TableDataInfo querySpeciesDataListByParam(@RequestBody JSONObject params) {
|
||||
return this.esResultRecordDetailsService.querySpeciesDataListByParam(params);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/getSpeciesStatInfoByParam"})
|
||||
public JSONObject getSpeciesStatInfoByParam(@RequestBody JSONObject params) {
|
||||
return this.esResultRecordDetailsService.getSpeciesStatInfo(params);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/querySpeciesByParamForApp"})
|
||||
public TableDataInfo querySpeciesListByParamForApp(@RequestBody JSONObject params) {
|
||||
params.put("isDeleted", (Object)0);
|
||||
return this.esResultRecordDetailsService.querySpeciesRecordListByParam(params, 1);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/querySpeciesByQuery"})
|
||||
public TableDataInfo querySpeciesListByQuery(@RequestBody JSONObject obj) {
|
||||
obj.put("isDeleted", (Object)0);
|
||||
return this.esResultRecordDetailsService.getProtectedAreaSpeciesByQuery(obj);
|
||||
}
|
||||
|
||||
@PostMapping(value={"/birdResultMedias"})
|
||||
public TableDataInfo getBirdResultMediasByParam(@RequestBody JSONObject params) {
|
||||
return this.esResultRecordDetailsService.getResultMediaListByParam(params);
|
||||
}
|
||||
|
||||
@DeleteMapping(value={"/delDocument/{ids}"})
|
||||
public AjaxResult deleteDocumentById(@PathVariable String ids) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.deleteDocumentById(ids));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/checkDocument/{ids}"})
|
||||
public AjaxResult updateDocumentCheckedById(@PathVariable String ids) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.updateDocumentCheckedById(ids));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/updateResultRecord"})
|
||||
public AjaxResult updateResultRecord(@RequestBody JSONObject data) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.updateResultRecordInfoById(data));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/updateResultRecords"})
|
||||
public AjaxResult updateResultRecords(@RequestBody JSONObject data) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.updateResultRecordInfoByIds(data));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/birdAudioDailyStat"})
|
||||
public AjaxResult getBirdAudioDailyStatList(@RequestBody JSONObject obj) {
|
||||
obj.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.getBirdAudioDailyStatListByParam(obj));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/birdDailyStat"})
|
||||
public AjaxResult getBirdDailyStatList(@RequestBody JSONObject obj) {
|
||||
obj.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.getBirdDailyStatListByParam(obj));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/birdAudioMonthStat"})
|
||||
public AjaxResult getBirdAudioMonthStatList(@RequestBody JSONObject obj) {
|
||||
obj.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.getBirdAudioMonthStatListByParam(obj));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/birdAudioYearStat"})
|
||||
public AjaxResult getBirdAudioYearStatList(@RequestBody JSONObject obj) {
|
||||
obj.put("isDeleted", (Object)0);
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.getBirdAudioYearStatListByParam(obj));
|
||||
}
|
||||
|
||||
@GetMapping(value={"/listByParam"})
|
||||
public AjaxResult getListByParam(DeviceInfo deviceInfo) {
|
||||
return AjaxResult.success(this.esResultRecordDetailsService.getDeviceInfoListForPage(deviceInfo));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/updateDocumentDeletedState"})
|
||||
public AjaxResult updateStatus(@RequestBody JSONObject param) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.updateResultRecordInfoById(param));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/updateDocumentFavorite"})
|
||||
public AjaxResult updateFavorite(@RequestBody JSONObject param) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.updateResultRecordInfoById(param));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/updateEsDocument/{recordId}"})
|
||||
public AjaxResult updateEsDocument(@PathVariable Long recordId) {
|
||||
this.esResultRecordDetailsService.bulkAddResultRecordDocumentById(recordId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@PostMapping(value={"/areaSpeciesListByParam"})
|
||||
public AjaxResult getSpeciesListByParam(@RequestBody JSONObject params) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.getAreaSpeciesListByParam(params));
|
||||
}
|
||||
|
||||
@PostMapping(value={"/updateMediaUrlPath"})
|
||||
public AjaxResult updateMediaUrlPath(@RequestBody JSONObject params) {
|
||||
return AjaxResult.success((Object)this.esResultRecordDetailsService.updateMediaUrlPrefixPathByParam(params));
|
||||
}
|
||||
|
||||
public EsResultRecordDetailsController(EsResultRecordDetailsService esResultRecordDetailsService) {
|
||||
this.esResultRecordDetailsService = esResultRecordDetailsService;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.hzvtc.es.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.hzvtc.common.core.controller.BaseController;
|
||||
import net.hzvtc.common.core.domain.AjaxResult;
|
||||
import net.hzvtc.es.service.EsResultRecordDetailsService;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/web/species/api")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
|
||||
public class EsSpeciesInfoApiController extends BaseController {
|
||||
private final EsResultRecordDetailsService esResultRecordDetailsService;
|
||||
|
||||
@PostMapping("/audioList")
|
||||
public AjaxResult getBirdAudioListByParam(@RequestBody JSONObject obj) {
|
||||
return AjaxResult.success(esResultRecordDetailsService.getAudioListByParam(obj));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.hzvtc.es.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import org.apache.ibatis.type.Alias;
|
||||
|
||||
@Alias(value="EsResultData")
|
||||
@Data
|
||||
public class EsResultData {
|
||||
private String id;
|
||||
private ZonedDateTime recordTime;
|
||||
private Long detailsId;
|
||||
private Long deviceId;
|
||||
private String deviceName;
|
||||
private String serialNumber;
|
||||
private Long speciesId;
|
||||
private String name;
|
||||
private String scientificName;
|
||||
private int count;
|
||||
private String habitat;
|
||||
private double confidence;
|
||||
private Long mediaId;
|
||||
private String mediaUrl;
|
||||
private String metaUrl;
|
||||
private String fileUrl;
|
||||
private Integer mediaType;
|
||||
private Integer subType;
|
||||
private String birdIcon;
|
||||
private String description;
|
||||
private BirdSpecies birdSpecies;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.hzvtc.es.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import org.apache.ibatis.type.Alias;
|
||||
|
||||
@Alias(value="EsResultRecordDetails")
|
||||
@Data
|
||||
public class EsResultRecordDetails {
|
||||
private Long id;
|
||||
private ZonedDateTime recordTime;
|
||||
private Long recordId;
|
||||
private Long deviceId;
|
||||
private String deviceName;
|
||||
private String serialNumber;
|
||||
private Long speciesId;
|
||||
private String speciesName;
|
||||
private String scientificName;
|
||||
private Long areaId;
|
||||
private String areaName;
|
||||
private int checked;
|
||||
private int count;
|
||||
private String habitat;
|
||||
private double confidence;
|
||||
private Long mediaId;
|
||||
private String mediaUrl;
|
||||
private String metaUrl;
|
||||
private int mediaType;
|
||||
private int recordType;
|
||||
private Integer favorite;
|
||||
private String birdIcon;
|
||||
private int isDeleted;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.hzvtc.es.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import org.apache.ibatis.type.Alias;
|
||||
|
||||
@Alias(value="EsResultRecordDetailsVo")
|
||||
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||
@Data
|
||||
public class EsResultRecordDetailsVo {
|
||||
private Long id;
|
||||
private LocalDateTime recordTime1;
|
||||
private Long recordId;
|
||||
private Long deviceId;
|
||||
private String deviceName;
|
||||
private String serialNumber;
|
||||
private Long speciesId;
|
||||
private String speciesName;
|
||||
private String scientificName;
|
||||
private Long areaId;
|
||||
private String areaName;
|
||||
private int checked;
|
||||
private int count;
|
||||
private String habitat;
|
||||
private double confidence;
|
||||
private Long mediaId;
|
||||
private String mediaUrl;
|
||||
private String metaUrl;
|
||||
private int mediaType;
|
||||
private int recordType;
|
||||
private Integer favorite;
|
||||
private String birdIcon;
|
||||
private int isDeleted;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.hzvtc.es.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.hzvtc.echart.domain.vo.BirdStatDataVo;
|
||||
import net.hzvtc.es.domain.EsResultRecordDetailsVo;
|
||||
|
||||
public interface EsResultRecordDetailsMapper {
|
||||
public List<EsResultRecordDetailsVo> getResultRecordListForElastic(Map<String, Object> var1);
|
||||
|
||||
public List<BirdStatDataVo> getDeviceListByParam(Map<String, Object> var1);
|
||||
|
||||
public List<BirdStatDataVo> getAreaBirdSpeciesByParam(Map<String, Object> var1);
|
||||
|
||||
public long getMediaUrlPrefixPathAmount(String var1);
|
||||
|
||||
public List<EsResultRecordDetailsVo> getMediaUrlPrefixPathListByParam(Map<String, Object> var1);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.hzvtc.es.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public interface EsRecordReportService {
|
||||
public JSONObject getBirdDailyReportStatByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getBirdDailyReportMaxStatByParam(JSONObject var1);
|
||||
|
||||
public String getBirdDataStatDailyFileByParam(JSONObject var1);
|
||||
|
||||
public String getBirdDataStatWeeklyFileByParam(JSONObject var1);
|
||||
|
||||
public boolean sendBirdDataStatEmail(JSONObject var1);
|
||||
|
||||
public boolean sendBirdDataStatWeeklyEmail(JSONObject var1);
|
||||
|
||||
public boolean sendBirdDataStatMonthlyEmail(JSONObject var1);
|
||||
|
||||
public boolean sendBirdDataStatYearlyEmail(JSONObject var1);
|
||||
|
||||
public JSONObject getSpeciesWeeklyReportByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getSpeciesMonthlyReportByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getSpeciesYearlyReportByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getSpeciesMediaListByParam(JSONObject var1);
|
||||
|
||||
public String getBirdDataMonthlyStatFileByParam(JSONObject var1);
|
||||
|
||||
public String getBirdDataYearlyStatFileByParam(JSONObject var1);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.hzvtc.es.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.List;
|
||||
import net.hzvtc.common.core.page.TableDataInfo;
|
||||
import net.hzvtc.device.domain.DeviceInfo;
|
||||
|
||||
public interface EsResultRecordDetailsService {
|
||||
public TableDataInfo querySpeciesRecordListByParam(JSONObject var1, int var2);
|
||||
|
||||
public TableDataInfo querySpeciesDataListByParam(JSONObject var1);
|
||||
|
||||
public TableDataInfo getProtectedAreaSpeciesByQuery(JSONObject var1);
|
||||
|
||||
public TableDataInfo getResultMediaListByParam(JSONObject var1);
|
||||
|
||||
public int deleteDocumentById(String var1);
|
||||
|
||||
public int updateDocumentCheckedById(String var1);
|
||||
|
||||
public void bulkAddResultRecordDocument();
|
||||
|
||||
public void bulkAddResultRecordDocumentById(Long var1);
|
||||
|
||||
public long getMaxResultRecordId();
|
||||
|
||||
public boolean updateResultRecordInfoById(JSONObject var1);
|
||||
|
||||
public boolean updateResultRecordInfoByIds(JSONObject var1);
|
||||
|
||||
public JSONObject getBirdAudioDailyStatListByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getBirdDailyStatListByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getBirdAudioMonthStatListByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getBirdAudioYearStatListByParam(JSONObject var1);
|
||||
|
||||
public List<DeviceInfo> getDeviceInfoListForPage(DeviceInfo var1);
|
||||
|
||||
public JSONArray getAreaSpeciesListByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getAudioListByParam(JSONObject var1);
|
||||
|
||||
public boolean updateDocumentStatusByParam(JSONObject var1);
|
||||
|
||||
public JSONObject getSpeciesStatInfo(JSONObject var1);
|
||||
|
||||
public long updateMediaUrlPrefixPathByParam(JSONObject var1);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package net.hzvtc.es.service.impl;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.BucketsPath;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.CalendarInterval;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.DateHistogramAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.MaxBucketAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.SumAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.TermsAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||
import co.elastic.clients.elasticsearch.core.search.TrackHits;
|
||||
import co.elastic.clients.json.JsonData;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import net.hzvtc.es.domain.EsResultRecordDetails;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CommonEsUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(CommonEsUtils.class);
|
||||
|
||||
public static JSONArray getSpeciesAggregateList(JSONObject param, String indexName, ElasticsearchClient elasticsearchClient, CalendarInterval calendarInterval) throws IOException {
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = SearchRequest.of(builder -> builder.index(indexName, new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("by_speciesId", a -> a.terms(TermsAggregation.of(ta -> ta.field("species_id").size(Integer.valueOf(100000)))).aggregations("by_calendarInterval", b -> b.dateHistogram(DateHistogramAggregation.of(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(calendarInterval))).aggregations("sum_count_field", s -> s.sum(SumAggregation.of(sa -> (SumAggregation.Builder)sa.field("count")))))));
|
||||
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate bySpeciesAgg = (Aggregate)aggs.get("by_speciesId");
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
bySpeciesAgg.lterms().buckets().array().forEach(speciesBucket -> {
|
||||
Aggregate byCalendarInterval = (Aggregate)speciesBucket.aggregations().get("by_calendarInterval");
|
||||
byCalendarInterval.dateHistogram().buckets().array().forEach(hourBucket -> {
|
||||
if (hourBucket.keyAsString() != null) {
|
||||
JSONObject item = new JSONObject();
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(hourBucket.keyAsString(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
LocalDateTime dateTime = zonedDateTime.toLocalDateTime();
|
||||
if (calendarInterval == CalendarInterval.Hour) {
|
||||
item.put("hour", (Object)dateTime.getHour());
|
||||
} else if (calendarInterval == CalendarInterval.Day) {
|
||||
item.put("weekDay", (Object)dateTime.getDayOfWeek());
|
||||
}
|
||||
item.put("speciesId", (Object)speciesBucket.key());
|
||||
Aggregate sumAgg = (Aggregate)hourBucket.aggregations().get("sum_count_field");
|
||||
item.put("count", (Object)((int)sumAgg.sum().value()));
|
||||
jsonArray.add((Object)item);
|
||||
}
|
||||
});
|
||||
});
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
public static JSONArray getMaxMonthStatDataByParam(JSONObject param, String indexName, ElasticsearchClient elasticsearchClient, CalendarInterval calendarMonthInterval, CalendarInterval calendarDayInterval, CalendarInterval calendarHourInterval) throws IOException {
|
||||
JSONArray array = new JSONArray();
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = new SearchRequest.Builder().index(indexName, new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("b_month", m -> m.dateHistogram(mh -> mh.field("record_time").timeZone("+08:00").calendarInterval(calendarMonthInterval).format("yyyy-MM")).aggregations("by_date", d -> d.dateHistogram(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(calendarDayInterval).format("yyyy-MM-dd")).aggregations("by_species_id", a -> a.terms(t -> t.field("species_id").size(Integer.valueOf(10000))).aggregations("hourly_sums", h -> h.dateHistogram(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(calendarHourInterval).minDocCount(Integer.valueOf(1))).aggregations("sum_per_hour", sa -> sa.sum(s -> (SumAggregation.Builder)s.field("count")))).aggregations("max_hourly_sum", maxBucket -> maxBucket.maxBucket(mb -> (MaxBucketAggregation.Builder)mb.bucketsPath(BucketsPath.of(bp -> bp.single("hourly_sums>sum_per_hour")))))))).build();
|
||||
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate byMonthAgg = (Aggregate)aggs.get("b_month");
|
||||
byMonthAgg.dateHistogram().buckets().array().forEach(bucket -> {
|
||||
JSONObject object = new JSONObject();
|
||||
String curDate = bucket.keyAsString();
|
||||
object.put("date", (Object)curDate);
|
||||
if (curDate != null) {
|
||||
String[] arr = curDate.split("-");
|
||||
object.put("weekDay", (Object)(Integer.parseInt(arr[1]) - 1));
|
||||
}
|
||||
double[] max = new double[]{0.0};
|
||||
((Aggregate)bucket.aggregations().get("by_date")).dateHistogram().buckets().array().forEach(subBucket -> {
|
||||
double[] sum = new double[]{0.0};
|
||||
((Aggregate)subBucket.aggregations().get("by_species_id")).lterms().buckets().array().forEach(item -> {
|
||||
sum[0] = sum[0] + ((Aggregate)item.aggregations().get("max_hourly_sum")).bucketMetricValue().value();
|
||||
});
|
||||
if (sum[0] > max[0]) {
|
||||
max[0] = sum[0];
|
||||
}
|
||||
});
|
||||
object.put("count", (Object)max[0]);
|
||||
array.add((Object)object);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
public static JSONArray getMaxDateStatDataByParam(JSONObject param, String indexName, ElasticsearchClient elasticsearchClient, CalendarInterval calendarDayInterval, CalendarInterval calendarHourInterval, int type) throws IOException {
|
||||
JSONArray array = new JSONArray();
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = new SearchRequest.Builder().index(indexName, new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("by_date", d -> d.dateHistogram(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(calendarDayInterval).format("yyyy-MM-dd")).aggregations("by_species_id", a -> a.terms(t -> t.field("species_id").size(Integer.valueOf(10000))).aggregations("hourly_sums", h -> h.dateHistogram(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(calendarHourInterval).minDocCount(Integer.valueOf(1))).aggregations("sum_per_hour", sa -> sa.sum(s -> (SumAggregation.Builder)s.field("count")))).aggregations("max_hourly_sum", maxBucket -> maxBucket.maxBucket(mb -> (MaxBucketAggregation.Builder)mb.bucketsPath(BucketsPath.of(bp -> bp.single("hourly_sums>sum_per_hour"))))))).build();
|
||||
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate byDataAgg = (Aggregate)aggs.get("by_date");
|
||||
byDataAgg.dateHistogram().buckets().array().forEach(bucket -> {
|
||||
JSONObject object = new JSONObject();
|
||||
String curDate = bucket.keyAsString();
|
||||
object.put("date", (Object)curDate);
|
||||
if (type == 1) {
|
||||
object.put("weekDay", (Object)CommonEsUtils.getWeekDay(curDate));
|
||||
} else if (type == 2) {
|
||||
object.put("weekDay", (Object)CommonEsUtils.getMonthDay(curDate));
|
||||
}
|
||||
AtomicReference<Double> sum = new AtomicReference<Double>(0.0);
|
||||
((Aggregate)bucket.aggregations().get("by_species_id")).lterms().buckets().array().forEach(subBucket -> sum.updateAndGet(v -> v + ((Aggregate)subBucket.aggregations().get("max_hourly_sum")).bucketMetricValue().value()));
|
||||
object.put("count", (Object)sum.get().intValue());
|
||||
array.add((Object)object);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
private static int getMonthDay(String dateString) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDate date = LocalDate.parse(dateString, formatter);
|
||||
return date.getDayOfMonth() - 1;
|
||||
}
|
||||
|
||||
private static int getWeekDay(String dateString) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDate date = LocalDate.parse(dateString, formatter);
|
||||
return date.getDayOfWeek().getValue() - 1;
|
||||
}
|
||||
|
||||
public static EsResultRecordDetails getResultRecordDetailsByParam(JSONObject param, String indexName, ElasticsearchClient elasticsearchClient) throws IOException {
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchResponse response = elasticsearchClient.search(s -> s.trackTotalHits((TrackHits)new TrackHits.Builder().enabled(Boolean.valueOf(true)).build()).index(indexName, new String[0]).query(q -> q.bool(boolQueryBuilder.build())).sort(sort -> sort.field(f -> f.field("favorite").order(SortOrder.Desc))).sort(sort -> sort.field(f -> f.field("id").order(SortOrder.Desc))).from(Integer.valueOf(0)).size(Integer.valueOf(1)), EsResultRecordDetails.class);
|
||||
List hitList = response.hits().hits();
|
||||
Iterator iterator = hitList.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
Hit mapHit = (Hit)iterator.next();
|
||||
return (EsResultRecordDetails)mapHit.source();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static long getSpeciesStatAmountByParam(JSONObject param, String indexName, ElasticsearchClient elasticsearchClient) throws IOException {
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = SearchRequest.of(builder -> builder.index(indexName, new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("sum_count_field", a -> a.sum(SumAggregation.of(ta -> (SumAggregation.Builder)ta.field("count")))));
|
||||
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate sumAgg = (Aggregate)aggs.get("sum_count_field");
|
||||
return (long)sumAgg.sum().value();
|
||||
}
|
||||
|
||||
public static BoolQuery.Builder createQuery(JSONObject param) {
|
||||
Integer subType;
|
||||
Integer notMediaType;
|
||||
Integer mediaType;
|
||||
String dateTo;
|
||||
String dateFrom;
|
||||
Long mediaId;
|
||||
Long speciesId;
|
||||
BoolQuery.Builder boolQueryBuilder = new BoolQuery.Builder();
|
||||
Long areaId = param.getLong("areaId");
|
||||
if (areaId != null) {
|
||||
boolQueryBuilder.must(m -> m.match(t -> t.field("area_id").query(areaId.longValue())));
|
||||
}
|
||||
if ((speciesId = param.getLong("speciesId")) != null) {
|
||||
boolQueryBuilder.must(m -> m.match(t -> t.field("species_id").query(speciesId.longValue())));
|
||||
}
|
||||
if ((mediaId = param.getLong("mediaId")) != null) {
|
||||
boolQueryBuilder.must(m -> m.match(t -> t.field("media_id").query(mediaId.longValue())));
|
||||
}
|
||||
if ((dateFrom = param.getString("dateFrom")) != null && !dateFrom.isEmpty()) {
|
||||
boolQueryBuilder.must(m -> m.range(v -> v.field("record_time").format("yyyy-MM-dd").gte(JsonData.of((Object)dateFrom)).timeZone("+08:00")));
|
||||
}
|
||||
if ((dateTo = param.getString("dateTo")) != null && !dateTo.isEmpty()) {
|
||||
boolQueryBuilder.must(m -> m.range(v -> v.field("record_time").format("yyyy-MM-dd").lte(JsonData.of((Object)dateTo)).timeZone("+08:00")));
|
||||
}
|
||||
if ((mediaType = param.getInteger("mediaType")) != null) {
|
||||
boolQueryBuilder.must(m -> m.match(t -> t.field("media_type").query((long)mediaType.intValue())));
|
||||
}
|
||||
if ((notMediaType = param.getInteger("notMediaType")) != null) {
|
||||
boolQueryBuilder.mustNot(m -> m.match(t -> t.field("media_type").query((long)notMediaType.intValue())));
|
||||
}
|
||||
if ((subType = param.getInteger("subType")) != null) {
|
||||
boolQueryBuilder.must(m -> m.match(t -> t.field("sub_type").query((long)subType.intValue())));
|
||||
}
|
||||
return boolQueryBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+885
@@ -0,0 +1,885 @@
|
||||
package net.hzvtc.es.service.impl;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.CalendarInterval;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.DateHistogramAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.MaxAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.SumAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.TermsAggregation;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
|
||||
import co.elastic.clients.elasticsearch.core.BulkRequest;
|
||||
import co.elastic.clients.elasticsearch.core.BulkResponse;
|
||||
import co.elastic.clients.elasticsearch.core.CountRequest;
|
||||
import co.elastic.clients.elasticsearch.core.CountResponse;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.elasticsearch.core.UpdateByQueryRequest;
|
||||
import co.elastic.clients.elasticsearch.core.UpdateRequest;
|
||||
import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
|
||||
import co.elastic.clients.elasticsearch.core.bulk.IndexOperation;
|
||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||
import co.elastic.clients.elasticsearch.core.search.TrackHits;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import net.hzvtc.area.domain.ProtectedAreaSpecies;
|
||||
import net.hzvtc.area.service.ProtectedAreaSpeciesService;
|
||||
import net.hzvtc.bird.domain.BirdSpecies;
|
||||
import net.hzvtc.bird.service.BirdMediaService;
|
||||
import net.hzvtc.bird.service.BirdSpeciesService;
|
||||
import net.hzvtc.common.core.page.TableDataInfo;
|
||||
import net.hzvtc.common.utils.CommonUtils;
|
||||
import net.hzvtc.common.utils.PageUtils;
|
||||
import net.hzvtc.common.utils.SecurityUtils;
|
||||
import net.hzvtc.data.check.domain.ResultMedia;
|
||||
import net.hzvtc.device.domain.DeviceInfo;
|
||||
import net.hzvtc.device.service.DeviceInfoService;
|
||||
import net.hzvtc.es.domain.EsResultData;
|
||||
import net.hzvtc.es.domain.EsResultRecordDetails;
|
||||
import net.hzvtc.es.domain.EsResultRecordDetailsVo;
|
||||
import net.hzvtc.es.mapper.EsResultRecordDetailsMapper;
|
||||
import net.hzvtc.es.service.EsResultRecordDetailsService;
|
||||
import net.hzvtc.es.service.impl.CommonEsUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service(value="esResultRecordDetailsService")
|
||||
public class EsResultRecordDetailsServiceImpl
|
||||
implements EsResultRecordDetailsService {
|
||||
private static final Logger log = LoggerFactory.getLogger(EsResultRecordDetailsServiceImpl.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(EsResultRecordDetailsService.class);
|
||||
private final ElasticsearchClient elasticsearchClient;
|
||||
private final BirdSpeciesService birdSpeciesService;
|
||||
private final BirdMediaService birdMediaService;
|
||||
private final DeviceInfoService deviceInfoService;
|
||||
private final ProtectedAreaSpeciesService protectedAreaSpeciesService;
|
||||
@Resource
|
||||
private final EsResultRecordDetailsMapper esResultRecordDetailsMapper;
|
||||
private final String indexName = "result_record_details";
|
||||
private final String indexDataName = "record_data_2030";
|
||||
private final String indexDataNewName = "record_data_new_2030";
|
||||
@Value(value="${hzvtc.fileServerUrl}")
|
||||
private String fileServerUrl;
|
||||
|
||||
@Override
|
||||
public TableDataInfo querySpeciesRecordListByParam(JSONObject param, int type) {
|
||||
Integer pageSize;
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
Integer pageNum = param.getInteger("pageNum");
|
||||
if (pageNum == null) {
|
||||
pageNum = 1;
|
||||
}
|
||||
if ((pageSize = param.getInteger("pageSize")) == null) {
|
||||
pageSize = 10;
|
||||
}
|
||||
int pageFrom = (pageNum - 1) * pageSize;
|
||||
try {
|
||||
Integer finalPageSize = pageSize;
|
||||
SearchResponse response = this.elasticsearchClient.search(s -> s.trackTotalHits((TrackHits)new TrackHits.Builder().enabled(Boolean.valueOf(true)).build()).index("result_record_details", new String[0]).query(q -> q.bool(boolQueryBuilder.build())).sort(sort -> sort.field(f -> f.field("record_time").order(SortOrder.Desc))).from(Integer.valueOf(pageFrom)).size(finalPageSize), EsResultRecordDetails.class);
|
||||
List hitList = response.hits().hits();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
for (Hit mapHit : hitList) {
|
||||
list.add(mapHit.source());
|
||||
}
|
||||
if (type == 1) {
|
||||
list = list.stream().peek(item -> item.setBirdIcon(this.birdMediaService.getBirdIconImageBySpeciesId(item.getSpeciesId()))).collect(Collectors.toList());
|
||||
}
|
||||
long total = response.hits().total() != null ? response.hits().total().value() : 0L;
|
||||
return this.getTableDataInfo(list, total);
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo querySpeciesDataListByParam(JSONObject param) {
|
||||
Integer pageSize;
|
||||
log.info("querySpeciesDataListByParam param:{}", (Object)param);
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
Integer mediaType = param.getInteger("mediaType");
|
||||
Integer subType = param.getInteger("subType");
|
||||
Integer pageNum = param.getInteger("pageNum");
|
||||
if (pageNum == null) {
|
||||
pageNum = 1;
|
||||
}
|
||||
if ((pageSize = param.getInteger("pageSize")) == null) {
|
||||
pageSize = 10;
|
||||
}
|
||||
int pageFrom = (pageNum - 1) * pageSize;
|
||||
try {
|
||||
Integer finalPageSize = pageSize;
|
||||
SearchResponse response = this.elasticsearchClient.search(s -> s.trackTotalHits((TrackHits)new TrackHits.Builder().enabled(Boolean.valueOf(true)).build()).index("record_data_2030", new String[0]).query(q -> q.bool(boolQueryBuilder.build())).sort(sort -> sort.field(f -> f.field("record_time").order(SortOrder.Desc))).from(Integer.valueOf(pageFrom)).size(finalPageSize), EsResultData.class);
|
||||
List hitList = response.hits().hits();
|
||||
ArrayList<Object> list = new ArrayList<Object>();
|
||||
if (mediaType != null && mediaType == 4 && subType != null && subType == 2) {
|
||||
for (Hit mapHit : hitList) {
|
||||
EsResultData esResultData = (EsResultData)mapHit.source();
|
||||
Long speciesId = esResultData.getSpeciesId();
|
||||
if (speciesId != null) {
|
||||
BirdSpecies birdSpecies = this.birdSpeciesService.selectBirdSpeciesById(speciesId);
|
||||
esResultData.setBirdSpecies(birdSpecies);
|
||||
}
|
||||
list.add(esResultData);
|
||||
}
|
||||
} else {
|
||||
for (Hit mapHit : hitList) {
|
||||
list.add(mapHit.source());
|
||||
}
|
||||
}
|
||||
long total = response.hits().total() != null ? response.hits().total().value() : 0L;
|
||||
return this.getTableDataInfo(list, total);
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ResultMedia getLastMediaInfoByParam(JSONObject param) {
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
try {
|
||||
SearchResponse response = this.elasticsearchClient.search(s -> s.trackTotalHits((TrackHits)new TrackHits.Builder().enabled(Boolean.valueOf(true)).build()).index("result_record_details", new String[0]).query(q -> q.bool(boolQueryBuilder.build())).sort(sort -> sort.field(f -> f.field("record_time").order(SortOrder.Desc))).from(Integer.valueOf(0)).size(Integer.valueOf(1)), EsResultRecordDetails.class);
|
||||
List hitList = response.hits().hits();
|
||||
ArrayList<Object> list = new ArrayList<Object>();
|
||||
for (Hit mapHit : hitList) {
|
||||
list.add(mapHit.source());
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
ResultMedia data = new ResultMedia();
|
||||
if (((EsResultRecordDetails)list.get(0)).getRecordTime() != null) {
|
||||
data.setTime(Date.from(((EsResultRecordDetails)list.get(0)).getRecordTime().toInstant()));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo getProtectedAreaSpeciesByQuery(JSONObject param) {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
Integer pageNum = param.getInteger("pageNum");
|
||||
Integer pageSize = param.getInteger("pageSize");
|
||||
PageUtils.startPage((Integer)pageNum, (Integer)pageSize);
|
||||
String name = param.getString("name");
|
||||
map.put("name", name);
|
||||
Long initAreaId = param.getLong("initAreaId");
|
||||
if (initAreaId != null) {
|
||||
map.put("areaId", initAreaId);
|
||||
}
|
||||
List birdSpecies = this.birdSpeciesService.getBirdSpeciesListByQuery(map);
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(200);
|
||||
rspData.setMsg("\u67e5\u8be2\u6210\u529f");
|
||||
rspData.setTotal(new PageInfo(birdSpecies).getTotal());
|
||||
ArrayList<ProtectedAreaSpecies> list = new ArrayList<ProtectedAreaSpecies>();
|
||||
for (BirdSpecies item : birdSpecies) {
|
||||
ProtectedAreaSpecies data = new ProtectedAreaSpecies();
|
||||
data.setSpeciesId(item.getId());
|
||||
data.setBirdSpecies(item);
|
||||
param.put("speciesId", (Object)item.getId());
|
||||
try {
|
||||
EsResultRecordDetails resultRecordDetails = CommonEsUtils.getResultRecordDetailsByParam(param, "result_record_details", this.elasticsearchClient);
|
||||
if (resultRecordDetails != null) {
|
||||
data.setAreaName(resultRecordDetails.getAreaName());
|
||||
if (resultRecordDetails.getRecordTime() != null) {
|
||||
data.setUpdateTime(Date.from(resultRecordDetails.getRecordTime().toInstant()));
|
||||
}
|
||||
} else {
|
||||
data.setAreaName("\u5f53\u524d\u672a\u76d1\u6d4b\u5230");
|
||||
}
|
||||
list.add(data);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
rspData.setRows(list);
|
||||
return rspData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo getResultMediaListByParam(JSONObject jsonObject) {
|
||||
Long mediaId = jsonObject.getLong("mediaId");
|
||||
String[] sources = new String[]{"id", "record_time", "species_name", "species_id", "device_id", "media_id", "media_url", "meta_url", "media_type", "favorite", "is_deleted"};
|
||||
BoolQuery.Builder boolQueryBuilder = null;
|
||||
Integer pageNum = null;
|
||||
Integer pageSize = null;
|
||||
if (mediaId != null) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("mediaId", (Object)mediaId);
|
||||
pageNum = 1;
|
||||
pageSize = 1;
|
||||
boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
} else {
|
||||
Integer type;
|
||||
pageNum = jsonObject.getInteger("pageNum");
|
||||
if (pageNum == null) {
|
||||
pageNum = 1;
|
||||
}
|
||||
if ((pageSize = jsonObject.getInteger("pageSize")) == null) {
|
||||
pageSize = 10;
|
||||
}
|
||||
if ((type = jsonObject.getInteger("type")) == null || 1 != type) {
|
||||
jsonObject.put("isDeleted", (Object)0);
|
||||
}
|
||||
boolQueryBuilder = CommonEsUtils.createQuery(jsonObject);
|
||||
}
|
||||
int pageFrom = (pageNum - 1) * pageSize;
|
||||
try {
|
||||
BoolQuery.Builder finalBoolQueryBuilder = boolQueryBuilder;
|
||||
Integer finalPageSize = pageSize;
|
||||
SearchResponse response = this.elasticsearchClient.search(s -> s.trackTotalHits((TrackHits)new TrackHits.Builder().enabled(Boolean.valueOf(true)).build()).index("result_record_details", new String[0]).query(q -> q.bool(finalBoolQueryBuilder.build())).sort(sort -> sort.field(f -> f.field("record_time").order(SortOrder.Desc))).source(sc -> sc.filter(f -> f.includes(Arrays.asList(sources)))).from(Integer.valueOf(pageFrom)).size(finalPageSize), EsResultRecordDetails.class);
|
||||
List hitList = response.hits().hits();
|
||||
long total = response.hits().total() != null ? response.hits().total().value() : 0L;
|
||||
ArrayList<Object> list = new ArrayList<Object>();
|
||||
for (Hit mapHit : hitList) {
|
||||
list.add(mapHit.source());
|
||||
}
|
||||
return this.getTableDataInfo(list, total);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
return this.getTableDataInfo(new ArrayList(), 0L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteDocumentById(String ids) {
|
||||
return this.updateDocumentsByParam(ids, 0);
|
||||
}
|
||||
|
||||
private int updateDocumentsByParam(String ids, int type) {
|
||||
try {
|
||||
String[] arr = ids.split(",");
|
||||
HashMap<String, Integer> params = new HashMap<String, Integer>();
|
||||
if (type == 0) {
|
||||
params.put("is_deleted", 1);
|
||||
} else {
|
||||
params.put("checked", 1);
|
||||
}
|
||||
for (String id : arr) {
|
||||
UpdateRequest request = UpdateRequest.of(builder -> builder.index("result_record_details").id(id).doc((Object)params));
|
||||
this.elasticsearchClient.update(request, Map.class);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateDocumentCheckedById(String ids) {
|
||||
return this.updateDocumentsByParam(ids, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bulkAddResultRecordDocument() {
|
||||
long maxValue = this.getMaxResultRecordId();
|
||||
this.processResultRecordDocument(maxValue);
|
||||
}
|
||||
|
||||
private void processResultRecordDocument(Long id) {
|
||||
HashMap<String, Object> param = new HashMap<String, Object>();
|
||||
param.put("recordId", id);
|
||||
List<EsResultRecordDetailsVo> list = this.esResultRecordDetailsMapper.getResultRecordListForElastic(param);
|
||||
if (!list.isEmpty()) {
|
||||
ArrayList operations = new ArrayList();
|
||||
list.forEach(data -> operations.add(new BulkOperation.Builder().index(((IndexOperation.Builder)((IndexOperation.Builder)new IndexOperation.Builder().index("result_record_details")).id(String.valueOf(data.getId()))).document(data).build()).build()));
|
||||
try {
|
||||
BulkRequest bulkRequest = new BulkRequest.Builder().operations(operations).build();
|
||||
BulkResponse bulkResponse = this.elasticsearchClient.bulk(bulkRequest);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bulkAddResultRecordDocumentById(Long id) {
|
||||
this.processResultRecordDocument(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxResultRecordId() {
|
||||
try {
|
||||
SearchResponse searchResponse = this.elasticsearchClient.search(s -> s.index("result_record_details", new String[0]).size(Integer.valueOf(0)).aggregations("max_value", a -> a.max(m -> (MaxAggregation.Builder)m.field("record_id"))), Void.class);
|
||||
Map aggregations = searchResponse.aggregations();
|
||||
long maxValue = 0L;
|
||||
if (aggregations != null && aggregations.containsKey("max_value")) {
|
||||
Aggregate maxAgg = (Aggregate)aggregations.get("max_value");
|
||||
maxValue = (long)maxAgg.max().value();
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateResultRecordInfoById(JSONObject object) {
|
||||
return this.updateResultRecordEsDocument(object);
|
||||
}
|
||||
|
||||
private boolean updateResultRecordEsDocument(JSONObject object) {
|
||||
String speciesName;
|
||||
Integer isDeleted;
|
||||
Integer favorite;
|
||||
Long speciesId;
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
String docId = object.getString("detailsId");
|
||||
Integer checked = object.getInteger("checked");
|
||||
if (checked != null) {
|
||||
params.put("checked", checked);
|
||||
}
|
||||
if ((speciesId = object.getLong("speciesId")) != null) {
|
||||
params.put("species_id", speciesId);
|
||||
}
|
||||
if ((favorite = object.getInteger("favorite")) != null) {
|
||||
params.put("favorite", favorite);
|
||||
}
|
||||
if ((isDeleted = object.getInteger("isDeleted")) != null) {
|
||||
params.put("is_deleted", isDeleted);
|
||||
}
|
||||
if ((speciesName = object.getString("speciesName")) != null) {
|
||||
params.put("species_name", speciesName);
|
||||
}
|
||||
UpdateRequest request = UpdateRequest.of(builder -> builder.index("result_record_details").id(docId).doc((Object)params));
|
||||
try {
|
||||
this.elasticsearchClient.update(request, Map.class);
|
||||
return true;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateResultRecordInfoByIds(JSONObject object) {
|
||||
String[] arr;
|
||||
String ids = object.getString("location");
|
||||
for (String detailsId : arr = ids.split(",")) {
|
||||
object.put("detailsId", (Object)detailsId);
|
||||
this.updateResultRecordEsDocument(object);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getBirdAudioDailyStatListByParam(JSONObject param) {
|
||||
param.put("mediaType", (Object)1);
|
||||
return this.getDailyAggregateListByParam(param, 0);
|
||||
}
|
||||
|
||||
private JSONObject getDailyAggregateListByParam(JSONObject param, int type) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
JSONArray jsonArray = CommonEsUtils.getSpeciesAggregateList(param, "result_record_details", this.elasticsearchClient, CalendarInterval.Hour);
|
||||
HashMap<Long, JSONObject> map = new HashMap<Long, JSONObject>();
|
||||
int[] hourAmount = new int[24];
|
||||
for (Object obj2 : jsonArray) {
|
||||
int hour;
|
||||
JSONObject item = (JSONObject)obj2;
|
||||
int n = hour = item.getInteger("hour").intValue();
|
||||
hourAmount[n] = hourAmount[n] + item.getInteger("count");
|
||||
Long speciesId = item.getLong("speciesId");
|
||||
JSONObject objItem = (JSONObject)map.get(speciesId);
|
||||
int data1 = 0;
|
||||
int data2 = 0;
|
||||
if (type == 0) {
|
||||
if (objItem == null) {
|
||||
objItem = new JSONObject();
|
||||
} else {
|
||||
data1 = objItem.getInteger("data1");
|
||||
data2 = objItem.getInteger("data2");
|
||||
}
|
||||
hour = item.getInteger("hour");
|
||||
if (hour < 18 && hour >= 6) {
|
||||
data1 += item.getInteger("count").intValue();
|
||||
} else {
|
||||
data2 += item.getInteger("count").intValue();
|
||||
}
|
||||
} else if (type == 1) {
|
||||
if (objItem == null) {
|
||||
objItem = new JSONObject();
|
||||
} else {
|
||||
data1 = objItem.getInteger("data1");
|
||||
data2 = objItem.getInteger("data2");
|
||||
}
|
||||
hour = item.getInteger("hour");
|
||||
int count = item.getInteger("count");
|
||||
if (hour <= 12) {
|
||||
if (count > data1) {
|
||||
data1 = count;
|
||||
}
|
||||
} else if (count > data2) {
|
||||
data2 = count;
|
||||
}
|
||||
}
|
||||
objItem.put("id", (Object)speciesId);
|
||||
objItem.put("data1", (Object)data1);
|
||||
objItem.put("data2", (Object)data2);
|
||||
objItem.put("dataAll", (Object)(data1 + data2));
|
||||
map.put(speciesId, objItem);
|
||||
}
|
||||
result.put("hourAmount", (Object)hourAmount);
|
||||
Object[] array = map.values().toArray();
|
||||
JSONArray list = new JSONArray();
|
||||
for (Object obj3 : array) {
|
||||
JSONObject objItem = (JSONObject)obj3;
|
||||
Long id = objItem.getLong("id");
|
||||
BirdSpecies birdSpecies = this.birdSpeciesService.selectBirdSpeciesForEsById(id);
|
||||
objItem.put("name", (Object)birdSpecies.getName());
|
||||
objItem.put("familyId", (Object)birdSpecies.getFamilyId());
|
||||
objItem.put("familyName", (Object)birdSpecies.getFamilyName());
|
||||
objItem.put("code", (Object)birdSpecies.getSpeciesType());
|
||||
objItem.put("codeName", (Object)birdSpecies.getSpeciesTypeName());
|
||||
list.add((Object)objItem);
|
||||
}
|
||||
list.sort(Comparator.comparing(obj -> ((JSONObject)obj).getInteger("dataAll")).reversed());
|
||||
result.put("list", (Object)list);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getBirdDailyStatListByParam(JSONObject param) {
|
||||
param.put("recordType", (Object)1);
|
||||
JSONObject object = this.getDailyAggregateListByParam(param, 1);
|
||||
JSONArray array = object.getJSONArray("list");
|
||||
if (array != null && !array.isEmpty()) {
|
||||
JSONArray ids = new JSONArray();
|
||||
for (Object obj2 : array) {
|
||||
JSONObject jsonObject = (JSONObject)obj2;
|
||||
ids.add((Object)jsonObject.getLong("id"));
|
||||
}
|
||||
param.put("ids", (Object)ids);
|
||||
} else {
|
||||
array = new JSONArray();
|
||||
}
|
||||
param.put("recordType", (Object)2);
|
||||
JSONObject subObj = this.getDailyAggregateListByParam(param, 1);
|
||||
if (subObj.getJSONArray("list") != null) {
|
||||
array.addAll((Collection)subObj.getJSONArray("list"));
|
||||
}
|
||||
array.sort(Comparator.comparing(obj -> ((JSONObject)obj).getInteger("dataAll")).reversed());
|
||||
object.put("list", (Object)array);
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getBirdAudioMonthStatListByParam(JSONObject param) {
|
||||
JSONObject result = new JSONObject();
|
||||
param.put("mediaType", (Object)1);
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = SearchRequest.of(builder -> builder.index("result_record_details", new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("by_month", a -> a.dateHistogram(DateHistogramAggregation.of(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(CalendarInterval.Month))).aggregations("by_hour", b -> b.dateHistogram(DateHistogramAggregation.of(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(CalendarInterval.Hour))).aggregations("sum_count_field", s -> s.sum(SumAggregation.of(sa -> (SumAggregation.Builder)sa.field("count")))))));
|
||||
try {
|
||||
SearchResponse searchResponse = this.elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate byMonthAgg = (Aggregate)aggs.get("by_month");
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
byMonthAgg.dateHistogram().buckets().array().forEach(monthBucket -> {
|
||||
String month = monthBucket.keyAsString();
|
||||
Aggregate byHourAgg = (Aggregate)monthBucket.aggregations().get("by_hour");
|
||||
byHourAgg.dateHistogram().buckets().array().forEach(hourBucket -> {
|
||||
String hour = hourBucket.keyAsString();
|
||||
if (month != null && hour != null) {
|
||||
JSONObject item = new JSONObject();
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(month, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
LocalDateTime dateTime = zonedDateTime.toLocalDateTime();
|
||||
item.put("month", (Object)dateTime.getMonth().getValue());
|
||||
zonedDateTime = ZonedDateTime.parse(hour, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
dateTime = zonedDateTime.toLocalDateTime();
|
||||
item.put("hour", (Object)dateTime.getHour());
|
||||
Aggregate sumAgg = (Aggregate)hourBucket.aggregations().get("sum_count_field");
|
||||
item.put("count", (Object)((int)sumAgg.sum().value()));
|
||||
jsonArray.add((Object)item);
|
||||
}
|
||||
});
|
||||
});
|
||||
HashMap<Integer, JSONObject> map = new HashMap<Integer, JSONObject>();
|
||||
for (Object obj2 : jsonArray) {
|
||||
JSONObject item = (JSONObject)obj2;
|
||||
Integer month = item.getInteger("month");
|
||||
JSONObject objItem = (JSONObject)map.get(month);
|
||||
int data1 = 0;
|
||||
int data2 = 0;
|
||||
if (objItem == null) {
|
||||
objItem = new JSONObject();
|
||||
} else {
|
||||
data1 = objItem.getInteger("data1");
|
||||
data2 = objItem.getInteger("data2");
|
||||
}
|
||||
Integer hour = item.getInteger("hour");
|
||||
if (hour < 18 && hour >= 6) {
|
||||
data1 += item.getInteger("count").intValue();
|
||||
} else {
|
||||
data2 += item.getInteger("count").intValue();
|
||||
}
|
||||
objItem.put("month", (Object)month);
|
||||
objItem.put("data1", (Object)data1);
|
||||
objItem.put("data2", (Object)data2);
|
||||
objItem.put("dataAll", (Object)(data1 + data2));
|
||||
map.put(month, objItem);
|
||||
}
|
||||
Object[] array = map.values().toArray();
|
||||
JSONArray list = new JSONArray();
|
||||
for (Object obj3 : array) {
|
||||
JSONObject objItem = (JSONObject)obj3;
|
||||
list.add((Object)objItem);
|
||||
}
|
||||
list.sort(Comparator.comparing(obj -> ((JSONObject)obj).getInteger("month")));
|
||||
result.put("list", (Object)array);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getBirdAudioYearStatListByParam(JSONObject param) {
|
||||
JSONObject result = new JSONObject();
|
||||
param.put("mediaType", (Object)1);
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = SearchRequest.of(builder -> builder.index("result_record_details", new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("by_year", a -> a.dateHistogram(DateHistogramAggregation.of(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(CalendarInterval.Year))).aggregations("by_month", b -> b.dateHistogram(DateHistogramAggregation.of(dh -> dh.field("record_time").timeZone("+08:00").calendarInterval(CalendarInterval.Month))).aggregations("sum_count_field", s -> s.sum(SumAggregation.of(sa -> (SumAggregation.Builder)sa.field("count")))))));
|
||||
try {
|
||||
SearchResponse searchResponse = this.elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate byYearAgg = (Aggregate)aggs.get("by_year");
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX+08:00");
|
||||
byYearAgg.dateHistogram().buckets().array().forEach(yearBucket -> {
|
||||
String year = yearBucket.keyAsString();
|
||||
Aggregate byMonthAgg = (Aggregate)yearBucket.aggregations().get("by_month");
|
||||
byMonthAgg.dateHistogram().buckets().array().forEach(hourBucket -> {
|
||||
String month = hourBucket.keyAsString();
|
||||
if (year != null && month != null) {
|
||||
JSONObject item = new JSONObject();
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(year, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
LocalDateTime dateTime = zonedDateTime.toLocalDateTime();
|
||||
item.put("year", (Object)dateTime.getYear());
|
||||
zonedDateTime = ZonedDateTime.parse(month, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
dateTime = zonedDateTime.toLocalDateTime();
|
||||
item.put("month", (Object)dateTime.getMonth().getValue());
|
||||
Aggregate sumAgg = (Aggregate)hourBucket.aggregations().get("sum_count_field");
|
||||
item.put("count", (Object)((int)sumAgg.sum().value()));
|
||||
jsonArray.add((Object)item);
|
||||
}
|
||||
});
|
||||
});
|
||||
HashMap<Integer, JSONObject> map = new HashMap<Integer, JSONObject>();
|
||||
for (Object obj2 : jsonArray) {
|
||||
JSONObject item = (JSONObject)obj2;
|
||||
Integer year = item.getInteger("year");
|
||||
JSONObject objItem = (JSONObject)map.get(year);
|
||||
int data1 = 0;
|
||||
int data2 = 0;
|
||||
int data3 = 0;
|
||||
int data4 = 0;
|
||||
if (objItem == null) {
|
||||
objItem = new JSONObject();
|
||||
} else {
|
||||
data1 = objItem.getInteger("data1");
|
||||
data2 = objItem.getInteger("data2");
|
||||
data3 = objItem.getInteger("data3");
|
||||
data4 = objItem.getInteger("data4");
|
||||
}
|
||||
Integer month = item.getInteger("month");
|
||||
if (month < 4 && month >= 1) {
|
||||
data1 += item.getInteger("count").intValue();
|
||||
} else if (month < 7 && month >= 4) {
|
||||
data2 += item.getInteger("count").intValue();
|
||||
} else if (month < 10 && month >= 7) {
|
||||
data3 += item.getInteger("count").intValue();
|
||||
} else {
|
||||
data4 += item.getInteger("count").intValue();
|
||||
}
|
||||
objItem.put("year", (Object)year);
|
||||
objItem.put("data1", (Object)data1);
|
||||
objItem.put("data2", (Object)data2);
|
||||
objItem.put("data3", (Object)data3);
|
||||
objItem.put("data4", (Object)data4);
|
||||
map.put(year, objItem);
|
||||
}
|
||||
Object[] array = map.values().toArray();
|
||||
JSONArray list = new JSONArray();
|
||||
for (Object obj3 : array) {
|
||||
JSONObject objItem = (JSONObject)obj3;
|
||||
list.add((Object)objItem);
|
||||
}
|
||||
list.sort(Comparator.comparing(obj -> ((JSONObject)obj).getInteger("year")));
|
||||
result.put("list", (Object)array);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceInfo> getDeviceInfoListForPage(DeviceInfo deviceInfo) {
|
||||
List list = this.deviceInfoService.getDeviceInfoListForPage(deviceInfo);
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("isDeleted", (Object)0);
|
||||
list.forEach(item -> {
|
||||
param.put("deviceId", (Object)item.getId());
|
||||
if (Objects.equals(item.getDeviceType(), "1")) {
|
||||
param.put("mediaType", (Object)3);
|
||||
} else {
|
||||
param.put("mediaType", (Object)1);
|
||||
}
|
||||
item.setResultMedia(this.getLastMediaInfoByParam(param));
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getAreaSpeciesListByParam(JSONObject param) {
|
||||
JSONArray array = new JSONArray();
|
||||
param.put("isDeleted", (Object)0);
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
SearchRequest searchRequest = SearchRequest.of(builder -> builder.index("result_record_details", new String[0]).size(Integer.valueOf(0)).query(q -> q.bool(boolQueryBuilder.build())).aggregations("by_species_id", a -> a.terms(TermsAggregation.of(dh -> dh.field("species_id").size(Integer.valueOf(10000))))));
|
||||
try {
|
||||
ArrayList list = new ArrayList();
|
||||
SearchResponse searchResponse = this.elasticsearchClient.search(searchRequest, Void.class);
|
||||
Map aggs = searchResponse.aggregations();
|
||||
Aggregate bySpeciesIdAgg = (Aggregate)aggs.get("by_species_id");
|
||||
bySpeciesIdAgg.lterms().buckets().array().forEach(idBucket -> list.add(idBucket.key()));
|
||||
HashMap map = new HashMap();
|
||||
if (!list.isEmpty()) {
|
||||
map.put("list", list);
|
||||
List birdSpecies = this.birdSpeciesService.getSpeciesSelectListByParam(map);
|
||||
if (birdSpecies != null && !birdSpecies.isEmpty()) {
|
||||
birdSpecies.forEach(item -> {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("speciesId", (Object)item.getId());
|
||||
obj.put("speciesName", (Object)item.getName());
|
||||
array.add((Object)obj);
|
||||
});
|
||||
List ids = this.protectedAreaSpeciesService.getProtectedAreaSpeciesListByParams(param);
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
CommonUtils.sortArrayByParam((JSONArray)array, (List)ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getAudioListByParam(JSONObject object) {
|
||||
Long areaId = this.getAreaId();
|
||||
if (areaId == null) {
|
||||
return new JSONObject();
|
||||
}
|
||||
object.put("areaId", (Object)areaId);
|
||||
String calcDate = object.getString("calcDate");
|
||||
if (calcDate == null || calcDate.isEmpty()) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
calcDate = df.format(new Date());
|
||||
}
|
||||
object.put("calcDate", (Object)calcDate);
|
||||
object.put("mediaType", (Object)1);
|
||||
TableDataInfo tableDataInfo = this.getResultMediaListByParam(object);
|
||||
List list = tableDataInfo.getRows();
|
||||
ArrayList<JSONObject> array = new ArrayList<JSONObject>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
for (Object eitem : list) {
|
||||
JSONObject obj = new JSONObject();
|
||||
EsResultRecordDetails item = (EsResultRecordDetails)eitem;
|
||||
obj.put("speciesName", (Object)item.getSpeciesName());
|
||||
obj.put("scientificName", (Object)item.getScientificName());
|
||||
obj.put("speciesId", (Object)item.getSpeciesId());
|
||||
obj.put("deviceId", (Object)item.getDeviceId());
|
||||
obj.put("time", (Object)(item.getRecordTime() == null ? "" : item.getRecordTime().withZoneSameInstant(ZoneId.of("Asia/Shanghai")).format(formatter)));
|
||||
String url = item.getMediaUrl();
|
||||
if (url != null) {
|
||||
if (url.startsWith("/")) {
|
||||
obj.put("mediaUrl", (Object)(this.fileServerUrl + url));
|
||||
} else {
|
||||
obj.put("mediaUrl", (Object)(this.fileServerUrl + "/" + url));
|
||||
}
|
||||
}
|
||||
if ((url = item.getMetaUrl()) != null) {
|
||||
if (url.startsWith("/")) {
|
||||
obj.put("imgPath", (Object)(this.fileServerUrl + url));
|
||||
} else {
|
||||
obj.put("imgPath", (Object)(this.fileServerUrl + "/" + url));
|
||||
}
|
||||
}
|
||||
array.add(obj);
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("total", (Object)tableDataInfo.getTotal());
|
||||
result.put("row", array);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Long getAreaId() {
|
||||
Set set = SecurityUtils.getLoginUser().getAreaIds();
|
||||
if (set == null || set.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
ArrayList ids = new ArrayList(set);
|
||||
return (Long)ids.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDocumentStatusByParam(JSONObject param) {
|
||||
try {
|
||||
Long mediaId = param.getLong("mediaId");
|
||||
int type = param.getInteger("type");
|
||||
String fieldName = "";
|
||||
Integer fieldValue = null;
|
||||
if (type == 0) {
|
||||
fieldName = "is_deleted";
|
||||
fieldValue = param.getInteger("isDeleted");
|
||||
} else {
|
||||
fieldName = "favorite";
|
||||
fieldValue = param.getInteger("favorite");
|
||||
}
|
||||
String finalFieldName = fieldName;
|
||||
Integer finalFieldValue = fieldValue;
|
||||
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest.Builder().index("result_record_details", new String[0]).query(q -> q.term(t -> t.field("media_id").value(mediaId.longValue()))).script(s -> s.inline(i -> i.source("ctx._source['" + finalFieldName + "'] = '" + finalFieldValue + "';"))).build();
|
||||
this.elasticsearchClient.updateByQuery(updateByQueryRequest);
|
||||
return true;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getSpeciesStatInfo(JSONObject param) {
|
||||
JSONObject result = new JSONObject();
|
||||
if (param == null) {
|
||||
param = new JSONObject();
|
||||
}
|
||||
param.put("mediaType", (Object)1);
|
||||
result.put("audioAmount", (Object)this.getSpeciesStatAmount(param));
|
||||
param.put("mediaType", (Object)2);
|
||||
result.put("imageAmount", (Object)this.getSpeciesStatAmount(param));
|
||||
param.put("mediaType", (Object)3);
|
||||
result.put("videoAmount", (Object)this.getSpeciesStatAmount(param));
|
||||
param.put("mediaType", (Object)5);
|
||||
result.put("textAmount", (Object)this.getSpeciesStatAmount(param));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long updateMediaUrlPrefixPathByParam(JSONObject param) {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
String path = param.getString("path");
|
||||
if (path == null || path.isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
map.put("path", path);
|
||||
long total = this.esResultRecordDetailsMapper.getMediaUrlPrefixPathAmount(path);
|
||||
if (total == 0L) {
|
||||
return 0L;
|
||||
}
|
||||
int size = 1000;
|
||||
map.put("size", size);
|
||||
long totalPage = total % (long)size == 0L ? total / (long)size : total % (long)size + 1L;
|
||||
int i = 0;
|
||||
while ((long)i < totalPage) {
|
||||
map.put("from", i * size);
|
||||
List<EsResultRecordDetailsVo> list = this.esResultRecordDetailsMapper.getMediaUrlPrefixPathListByParam(map);
|
||||
HashMap params = new HashMap();
|
||||
list.forEach(item -> {
|
||||
String url = item.getMediaUrl().replace(path, "");
|
||||
params.put("media_url", url);
|
||||
this.updateEsDocumentByParam(item.getId().toString(), params);
|
||||
});
|
||||
++i;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private void updateEsDocumentByParam(String id, Map<String, Object> params) {
|
||||
try {
|
||||
UpdateRequest request = UpdateRequest.of(builder -> builder.index("result_record_details").id(id).doc((Object)params).detectNoop(Boolean.valueOf(false)));
|
||||
this.elasticsearchClient.update(request, Map.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private long getSpeciesStatAmount(JSONObject param) {
|
||||
BoolQuery.Builder boolQueryBuilder = CommonEsUtils.createQuery(param);
|
||||
CountRequest countRequest = CountRequest.of(builder -> builder.index("record_data_2030", new String[0]).query(q -> q.bool(boolQueryBuilder.build())));
|
||||
try {
|
||||
CountResponse response = this.elasticsearchClient.count(countRequest);
|
||||
return response.count();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("error", (Throwable)ex);
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
private TableDataInfo getTableDataInfo(List<?> list, long total) {
|
||||
TableDataInfo tableDataInfo = new TableDataInfo();
|
||||
tableDataInfo.setRows(list);
|
||||
tableDataInfo.setTotal(total);
|
||||
tableDataInfo.setCode(200);
|
||||
tableDataInfo.setMsg("\u67e5\u8be2\u6210\u529f");
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
@Lazy
|
||||
public EsResultRecordDetailsServiceImpl(ElasticsearchClient elasticsearchClient, BirdSpeciesService birdSpeciesService, BirdMediaService birdMediaService, DeviceInfoService deviceInfoService, ProtectedAreaSpeciesService protectedAreaSpeciesService, EsResultRecordDetailsMapper esResultRecordDetailsMapper) {
|
||||
this.elasticsearchClient = elasticsearchClient;
|
||||
this.birdSpeciesService = birdSpeciesService;
|
||||
this.birdMediaService = birdMediaService;
|
||||
this.deviceInfoService = deviceInfoService;
|
||||
this.protectedAreaSpeciesService = protectedAreaSpeciesService;
|
||||
this.esResultRecordDetailsMapper = esResultRecordDetailsMapper;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?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="net.hzvtc.es.mapper.EsResultRecordDetailsMapper">
|
||||
<resultMap type="EsResultRecordDetailsVo" id="EsResultRecordDetailsResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="mediaId" column="media_id"/>
|
||||
<result property="recordId" column="record_id"/>
|
||||
<result property="count" column="count"/>
|
||||
<result property="habitat" column="habitat"/>
|
||||
<result property="recordTime1" column="record_time"/>
|
||||
<result property="recordType" column="record_type"/>
|
||||
<result property="deviceId" column="device_id"/>
|
||||
<result property="deviceName" column="device_name"/>
|
||||
<result property="speciesId" column="species_id"/>
|
||||
<result property="confidence" column="confidence"/>
|
||||
<result property="checked" column="checked"/>
|
||||
<result property="serialNumber" column="serial_number"/>
|
||||
<result property="speciesName" column="species_name"/>
|
||||
<result property="mediaType" column="media_type"/>
|
||||
<result property="mediaUrl" column="media_url"/>
|
||||
<result property="metaUrl" column="meta_url"/>
|
||||
<result property="areaName" column="area_name"/>
|
||||
<result property="areaId" column="area_id"/>
|
||||
<result property="scientificName" column="scientific_name"/>
|
||||
<result property="isDeleted" column="is_deleted"/>
|
||||
</resultMap>
|
||||
<resultMap type="EsResultRecordDetailsVo" id="EsResultRecordDetailsMediaUrlResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="mediaUrl" column="media_url"/>
|
||||
</resultMap>
|
||||
<resultMap type="BirdStatDataVo" id="EchartDataBirdResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
</resultMap>
|
||||
<select id="getAreaBirdSpeciesByParam" resultMap="EchartDataBirdResult">
|
||||
select b.name as name,b.id from protected_area_species c
|
||||
left JOIN bird_species b on c.species_id = b.id
|
||||
where
|
||||
c.is_deleted = 0
|
||||
and
|
||||
c.area_id = #{areaId}
|
||||
<if test="isCommon != null">
|
||||
and c.is_common = #{isCommon}
|
||||
</if>
|
||||
order by c.position desc,c.species_id
|
||||
<if test="limit!=null">
|
||||
limit #{limit}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getDeviceListByParam" resultMap="EchartDataBirdResult">
|
||||
select a.device_name as name, a.id
|
||||
from device_info a
|
||||
where a.is_deleted = 0
|
||||
and a.device_type = 1
|
||||
and a.id in (select device_id from device_in_area where device_in_area.area_id = #{areaId})
|
||||
order by a.id
|
||||
</select>
|
||||
<select id="getMediaUrlPrefixPathAmount" resultType="long">
|
||||
select count(1) as rowamount
|
||||
from result_record_details a
|
||||
INNER JOIN result_media b on a.media_id = b.media_id
|
||||
where a.is_deleted = 0
|
||||
and b.media_url like CONCAT(#{path}, '%')
|
||||
</select>
|
||||
<select id="getMediaUrlPrefixPathListByParam" resultMap="EsResultRecordDetailsMediaUrlResult">
|
||||
select a.details_id as id, b.media_url
|
||||
from result_record_details a
|
||||
INNER JOIN result_media b on a.media_id = b.media_id
|
||||
where a.is_deleted = 0
|
||||
and b.media_url like CONCAT(#{path}, '%')
|
||||
order by details_id
|
||||
limit #{from},#{size}
|
||||
</select>
|
||||
<select id="getResultRecordListForElastic" resultMap="EsResultRecordDetailsResult">
|
||||
select a.*,
|
||||
c.device_name,
|
||||
c.serial_number,
|
||||
d.name as species_name,
|
||||
e.media_type,
|
||||
e.media_url,
|
||||
e.meta_url,
|
||||
d.scientific_name
|
||||
from (select a.details_id as id,
|
||||
a.media_id,
|
||||
a.record_id,
|
||||
IF(a.count = NULL, 1, if(a.count = 0, 1, a.count)) as count,
|
||||
a.habitat,
|
||||
b.record_time,
|
||||
b.record_type,
|
||||
b.device_id,
|
||||
a.species_id,
|
||||
IFNULL(a.confidence = NULL, 0.0) as confidence,
|
||||
IFNULL(a.checked, 0) as checked,
|
||||
a.is_deleted
|
||||
from result_record b
|
||||
INNER JOIN result_record_details a on b.record_id = a.record_id
|
||||
where b.record_id > #{recordId}
|
||||
and a.media_id in (select media_id from result_media where is_deleted != 1)
|
||||
and a.is_deleted = 0) as a
|
||||
INNER JOIN bird_species d on a.species_id = d.id
|
||||
inner join device_info c on a.device_id = c.id
|
||||
inner JOIN result_media e on a.media_id = e.media_id
|
||||
order by a.id
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user