Browse Source

计算es符合查询条件的总数

LiTaohong 7 years ago
parent
commit
69df067cab

+ 25 - 3
svr/svr-base/pom.xml

@ -12,7 +12,7 @@
    <groupId>com.yihu.jw</groupId>
    <artifactId>svr-base</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <packaging>war</packaging>
    <dependencies>
        <!--公共的 start-->
@ -53,14 +53,31 @@
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-servlet-api</artifactId>
            <version>8.5.28</version>
            <!--tomcat 启动时 打开注释 end-->
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
@ -128,6 +145,11 @@
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-data-redis</artifactId>-->

+ 1 - 1
svr/svr-base/src/main/java/com/yihu/jw/business/version/controller/UserVersionController.java

@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import javax.ws.rs.PathParam;
import java.util.ArrayList;
import java.util.List;

+ 13 - 0
svr/svr-base/src/main/java/com/yihu/jw/config/SvrBaseWarConfig.java

@ -0,0 +1,13 @@
package com.yihu.jw.config;
import com.yihu.jw.SvrBaseApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class SvrBaseWarConfig extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(SvrBaseApplication.class);
    }
}

+ 17 - 2
svr/svr-base/src/main/resources/application.yml

@ -2,8 +2,23 @@
spring:
  application:
    name:  svr-base  #注册到发现服务的id 如果id一样 eurika会自动做负载
  jmx:
    default-domain: svr-base
  data:
    elasticsearch: #ElasticsearchProperties
      cluster-name: jkzl #默认即为elasticsearch  集群名
      cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      local: false #是否本地连接
      properties: # Additional properties used to configure the client.
        enable: true
  # JEST (Elasticsearch HTTP client) (JestProperties)
  elasticsearch:
    jest:
      uris: http://172.19.103.45:9200,http://172.19.103.68:9200
#      uris: http://172.19.103.68:9200
      connection-timeout: 60000 # Connection timeout in milliseconds.
      multi-threaded: true

+ 2 - 2
svr/svr-iot/pom.xml

@ -56,12 +56,12 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--tomcat 启动时 打开注释 start-->
            <exclusions>
           <!-- <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
            </exclusions>-->
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>

+ 13 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -22,6 +22,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.naming.directory.SearchResult;
import java.util.*;
/**
@ -254,4 +255,16 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
        return bool;
    }
    /**
     * 计算符合查询条件的总数
     * @param jsonData
     * @return
     */
    public int getESCount(String jsonData){
        int count = 0;
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        io.searchbox.core.SearchResult result = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        count = result.getTotal();
        return count;
    }
}