Browse Source

Merge branch 'dev' of LiTaohong/jw2.0 into dev

yeshijie 7 years ago
parent
commit
94948d49c7
20 changed files with 905 additions and 104 deletions
  1. 10 1
      base/common-data-es/src/main/java/com/yihu/base/es/config/ElasticFactory.java
  2. 37 0
      base/common-data-es/src/main/java/com/yihu/base/es/config/ElastricSearchHelper.java
  3. 185 0
      base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchClient.java
  4. 34 0
      base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchConfig.java
  5. 89 0
      base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchPool.java
  6. 137 0
      base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchUtil.java
  7. 2 1
      base/common-data-es/src/main/resources/template.yml
  8. 35 0
      base/common-data-hbase/src/main/java/com/yihu/base/hbase/HBaseHelper.java
  9. 1 1
      common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceDO.java
  10. 20 2
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/DataRequestMapping.java
  11. 0 12
      svr-lib-parent-pom/pom.xml
  12. 32 14
      svr/svr-iot/pom.xml
  13. 21 2
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataInputController.java
  14. 106 0
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataSearchController.java
  15. 55 51
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataInputService.java
  16. 1 1
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataProcessLogService.java
  17. 35 0
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataSearchService.java
  18. 12 0
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/ConstantUtils.java
  19. 88 5
      svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/RowKeyUtils.java
  20. 5 14
      svr/svr-iot/src/main/resources/application.yml

+ 10 - 1
base/common-data-es/src/main/java/com/yihu/base/es/config/ElasticFactory.java

@ -2,6 +2,7 @@ package com.yihu.base.es.config;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.ClientConfig;
import io.searchbox.client.config.HttpClientConfig;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
@ -9,10 +10,14 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
@ -28,6 +33,7 @@ public class ElasticFactory {
    private String clusterNodes; // 120.25.194.233:9300,120.25.194.233:9300,120.25.194.233:9300
    @Value("${spring.elasticsearch.jest.uris}")
    private String jestHost; // http://192.168.226.133:9200
//-----------------------------------jestClient----------------------------------------
    /**
@ -48,8 +54,11 @@ public class ElasticFactory {
    public synchronized void init() {
        // Construct a new Jest client according to configuration via factory
        factory = new JestClientFactory();
        Set<String> serverList = new LinkedHashSet<>();
        String[] uris = jestHost.split(",");
        serverList.addAll(CollectionUtils.arrayToList(uris));
        factory.setHttpClientConfig(new HttpClientConfig
                .Builder(jestHost)
                .Builder(serverList)
                .multiThreaded(true)
                .maxTotalConnection(50)// 最大链接
                .maxConnectionIdleTime(120, TimeUnit.SECONDS)//链接等待时间

+ 37 - 0
base/common-data-es/src/main/java/com/yihu/base/es/config/ElastricSearchHelper.java

@ -1,8 +1,10 @@
package com.yihu.base.es.config;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.yihu.base.es.config.model.SaveModel;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestResult;
import io.searchbox.core.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -155,4 +157,39 @@ public class ElastricSearchHelper {
            }
        }
    }
    /**
     * 查询
     */
    public String search(String index, String type, String queryStr) {
        JestClient jestClient = null;
        JestResult result = null;
        try {
            jestClient = elasticFactory.getJestClient();
            Search search = new Search.Builder(queryStr)
                    // multiple index or types can be added.
                    .addIndex(index)
                    .addType(type)
                    .build();
            result = jestClient.execute(search);
            JSONObject resultJsonObject = (JSONObject)JSONObject.parse(result.getJsonString());
            JSONObject jsonObject = (JSONObject)resultJsonObject.get("hits");
            logger.info("search data count:" + jsonObject.get("total"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return result.getJsonString();
    }
    public static void main(String args[]){
        String json = "";
        JSONObject resultJsonObject = (JSONObject)JSONObject.parse(json);
        JSONObject jsonObject = (JSONObject)resultJsonObject.get("hits");
        System.out.println(jsonObject.get("total"));
    }
}

+ 185 - 0
base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchClient.java

@ -0,0 +1,185 @@
package com.yihu.base.es.config.elasticsearch;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.engine.DocumentMissingException;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Client - Es搜索服务
 * Created by progr1mmer on 2017/12/1.
 */
@Repository
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ElasticSearchClient {
    @Autowired
    private ElasticSearchPool elasticSearchPool;
    public void mapping(String index, String type, XContentBuilder xContentBuilder) {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            CreateIndexRequestBuilder createIndexRequestBuilder = transportClient.admin().indices().prepareCreate(index);
            createIndexRequestBuilder.addMapping(type, xContentBuilder);
            createIndexRequestBuilder.get();
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public void remove(String index) {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            DeleteIndexRequestBuilder deleteIndexRequestBuilder = transportClient.admin().indices().prepareDelete(index);
            deleteIndexRequestBuilder.get();
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public Map<String, Object> index(String index, String type, Map<String, Object> source) {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            IndexResponse response = transportClient.prepareIndex(index, type).setSource(source).get();
            source.put("_id", response.getId());
            return source;
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public void delete(String index, String type, String [] idArr) {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            for (String id : idArr) {
                transportClient.prepareDelete(index, type, id).get();
            }
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public Map<String, Object> update(String index, String type, String id, Map<String, Object> source) throws DocumentMissingException {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            transportClient.prepareUpdate(index, type, id).setDoc(source).get();
            return findById(index, type, id);
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public Map<String, Object> findById(String index, String type, String id) {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            GetRequest getRequest = new GetRequest(index, type, id);
            GetResponse response = transportClient.get(getRequest).actionGet();
            Map<String, Object> source = response.getSource();
            if(source != null) {
                source.put("_id", response.getId());
            }
            return source;
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public List<Map<String, Object>> findByField(String index, String type, QueryBuilder queryBuilder) {
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            SearchRequestBuilder builder = transportClient.prepareSearch(index);
            builder.setTypes(type);
            builder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
            builder.setQuery(queryBuilder);
            builder.setExplain(true);
            SearchResponse response = builder.get();
            SearchHits hits = response.getHits();
            List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
            for (SearchHit hit : hits.getHits()) {
                Map<String, Object> source = hit.getSource();
                source.put("_id", hit.getId());
                resultList.add(source);
            }
            return resultList;
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public List<Map<String, Object>> page(String index, String type, QueryBuilder queryBuilder, int page, int size){
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            SearchRequestBuilder builder = transportClient.prepareSearch(index);
            builder.setTypes(type);
            builder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
            builder.setQuery(queryBuilder);
            builder.setFrom((page - 1) * size).setSize(size);
            builder.setExplain(true);
            SearchResponse response = builder.get();
            SearchHits hits = response.getHits();
            List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
            for (SearchHit hit : hits.getHits()) {
                Map<String, Object> source = hit.getSource();
                source.put("_id", hit.getId());
                resultList.add(source);
            }
            return resultList;
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public List<String> getIds(String index, String type, QueryBuilder queryBuilder){
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            SearchRequestBuilder builder = transportClient.prepareSearch(index);
            builder.setTypes(type);
            builder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
            builder.setQuery(queryBuilder);
            builder.setFrom(0).setSize(10000);
            builder.setExplain(true);
            SearchResponse response = builder.get();
            SearchHits hits = response.getHits();
            List<String> resultList = new ArrayList<>();
            for (SearchHit hit : hits.getHits()) {
                resultList.add(hit.getId());
            }
            return resultList;
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
    public long count(String index, String type, QueryBuilder queryBuilder){
        TransportClient transportClient = elasticSearchPool.getClient();
        try {
            SearchRequestBuilder builder = transportClient.prepareSearch(index);
            builder.setTypes(type);
            builder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
            builder.setQuery(queryBuilder);
            builder.setExplain(true);
            return builder.get().getHits().totalHits();
        }finally {
            elasticSearchPool.releaseClient(transportClient);
        }
    }
}

+ 34 - 0
base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchConfig.java

@ -0,0 +1,34 @@
package com.yihu.base.es.config.elasticsearch;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
 * Created by progr1mmer on 2017/12/1.
 */
@ConfigurationProperties(prefix = "elasticsearch")
@Configuration
public class ElasticSearchConfig {
    // 集群名称
    private String clusterName;
    // 节点
    private String clusterNodes;
    public String getClusterName() {
        return clusterName;
    }
    public void setClusterName(String clusterName) {
        this.clusterName = clusterName;
    }
    public String getClusterNodes() {
        return clusterNodes;
    }
    public void setClusterNodes(String clusterNodes) {
        this.clusterNodes = clusterNodes;
    }
}

+ 89 - 0
base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchPool.java

@ -0,0 +1,89 @@
package com.yihu.base.es.config.elasticsearch;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by progr1mmer on 2018/1/4.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ElasticSearchPool {
    @Value("${elasticsearch.pool.init-size}")
    private int initSize;
    @Value("${elasticsearch.pool.max-size}")
    private int maxSize;
    private List<TransportClient> clientPool;
    @Autowired
    private ElasticSearchConfig elasticSearchConfig;
    @PostConstruct
    private void init() {
        if(clientPool == null) {
            clientPool = new ArrayList<TransportClient>();
        }
        synchronized (ElasticSearchClient.class) {
            while (clientPool.size() < initSize) {
                Settings settings = Settings.builder()
                        .put("cluster.name", elasticSearchConfig.getClusterName())
                        .put("client.transport.sniff", true)
                        .build();
                String[] nodeArr = elasticSearchConfig.getClusterNodes().split(",");
                InetSocketTransportAddress[] socketArr = new InetSocketTransportAddress[nodeArr.length];
                for (int i = 0; i < socketArr.length; i++) {
                    if (!StringUtils.isEmpty(nodeArr[i])) {
                        String[] nodeInfo = nodeArr[i].split(":");
                        socketArr[i] = new InetSocketTransportAddress(new InetSocketAddress(nodeInfo[0], new Integer(nodeInfo[1])));
                    }
                }
                TransportClient transportClient = TransportClient.builder().settings(settings).build().addTransportAddresses(socketArr);
                clientPool.add(transportClient);
            }
        }
    }
    @PreDestroy
    private void destroy(){
        if (null != clientPool) {
            for (TransportClient transportClient : clientPool) {
                transportClient.close();
            }
        }
    }
    public synchronized TransportClient getClient() {
        int last_index = clientPool.size() - 1;
        TransportClient transportClient = clientPool.get(last_index);
        clientPool.remove(last_index);
        if(clientPool.isEmpty()) {
            init();
        }
        return transportClient;
    }
    public synchronized void releaseClient(TransportClient transportClient) {
        if(clientPool.size() > maxSize) {
            if (null != transportClient) {
                transportClient.close();
            }
        }else {
            clientPool.add(transportClient);
        }
    }
}

+ 137 - 0
base/common-data-es/src/main/java/com/yihu/base/es/config/elasticsearch/ElasticSearchUtil.java

@ -0,0 +1,137 @@
package com.yihu.base.es.config.elasticsearch;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.engine.DocumentMissingException;
import org.elasticsearch.index.query.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
/**
 * Util - Es搜索服务
 * Created by progr1mmer on 2017/12/2.
 */
@Service
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ElasticSearchUtil {
    @Autowired
    private ElasticSearchClient elasticSearchClient;
    public void mapping(String index, String type, Map<String, Map<String, String>> source) throws IOException{
        XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("properties");
        for(String field : source.keySet()) {
            xContentBuilder.startObject(field);
            Map<String, String> propsMap = source.get(field);
            for(String prop : propsMap.keySet()) {
                xContentBuilder.field(prop, propsMap.get(prop));
            }
            xContentBuilder.endObject();
        }
        xContentBuilder.endObject().endObject();
        elasticSearchClient.mapping(index, type, xContentBuilder);
    }
    public void remove(String index){
        elasticSearchClient.remove(index);
    }
    public Map<String, Object> index(String index, String type, Map<String, Object> source) throws ParseException{
        return elasticSearchClient.index(index, type, source);
    }
    public void delete(String index, String type, String [] idArr) {
        elasticSearchClient.delete(index, type, idArr);
    }
    public void deleteByField(String index, String type, String field, Object value) {
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchPhraseQuery(field, value);
        boolQueryBuilder.must(matchQueryBuilder);
        List<String> idList = elasticSearchClient.getIds(index, type, boolQueryBuilder);
        String [] idArr = new String[idList.size()];
        idArr = idList.toArray(idArr);
        elasticSearchClient.delete(index, type, idArr);
    }
    public Map<String, Object> update(String index, String type, String id, Map<String, Object> source) throws DocumentMissingException {
        if(source.containsKey("_id")) {
            source.remove("_id");
        }
        return elasticSearchClient.update(index, type, id, source);
    }
    public Map<String, Object> findById(String index, String type, String id) {
        return elasticSearchClient.findById(index, type, id);
    }
    public List<Map<String, Object>> findByField(String index, String type, String field, Object value) {
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchPhraseQuery(field, value);
        boolQueryBuilder.must(matchQueryBuilder);
        return elasticSearchClient.findByField(index, type, boolQueryBuilder);
    }
    public List<Map<String, Object>> page(String index, String type, List<Map<String, Object>> filter, int page, int size) {
        QueryBuilder boolQueryBuilder = getQueryBuilder(filter);
        return elasticSearchClient.page(index, type, boolQueryBuilder, page, size);
    }
    public long count(String index, String type, List<Map<String, Object>> filter) {
        QueryBuilder boolQueryBuilder = getQueryBuilder(filter);
        return elasticSearchClient.count(index, type, boolQueryBuilder);
    }
    private QueryBuilder getQueryBuilder(List<Map<String, Object>> filter) {
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        for(Map<String, Object> param : filter) {
            String andOr = String.valueOf(param.get("andOr"));
            String condition = String.valueOf(param.get("condition"));
            String field = String.valueOf(param.get("field"));
            Object value = param.get("value");
            if(condition.equals("=")) {
                MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchPhraseQuery(field, value);
                if("and".equals(andOr)) {
                    boolQueryBuilder.must(matchQueryBuilder);
                }else if("or".equals(andOr)) {
                    boolQueryBuilder.should(matchQueryBuilder);
                }
            }else if (condition.equals("?")) {
                QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(field + ":" + value);
                if("and".equals(andOr)) {
                    boolQueryBuilder.must(queryStringQueryBuilder);
                }else if("or".equals(andOr)) {
                    boolQueryBuilder.should(queryStringQueryBuilder);
                }
            }else {
                RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(field);;
                if(field.endsWith("Date")) {
                    rangeQueryBuilder.format("yyyy-MM-dd HH:mm:ss");
                }
                if(condition.equals(">")) {
                    rangeQueryBuilder.gt(value);
                }else if(condition.equals(">=")) {
                    rangeQueryBuilder.gte(value);
                }else if(condition.equals("<=")) {
                    rangeQueryBuilder.lte(value);
                }else if(condition.equals("<")) {
                    rangeQueryBuilder.lt(value);
                }
                if("and".equals(andOr)) {
                    boolQueryBuilder.must(rangeQueryBuilder);
                }else if("or".equals(andOr)) {
                    boolQueryBuilder.should(rangeQueryBuilder);
                }
            }
        }
        return boolQueryBuilder;
    }
}

+ 2 - 1
base/common-data-es/src/main/resources/template.yml

@ -13,11 +13,12 @@ spring:
      cluster-nodes: 120.25.194.233:9300,120.25.194.233:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      local: false ##是否本地连接
      properties: # Additional properties used to configure the client.
        enable: true
  # JEST (Elasticsearch HTTP client) (JestProperties)
  elasticsearch:
    jest:
      uris: http://192.168.226.133:9200
      uris: http://172.17.110.217:9200,http://172.17.110.128:9200
      connection-timeout: # Connection timeout in milliseconds.
      multi-threaded: true # Enable connection requests from multiple execution threads.
      username: # Login user.

+ 35 - 0
base/common-data-hbase/src/main/java/com/yihu/base/hbase/HBaseHelper.java

@ -203,6 +203,9 @@ public class HBaseHelper extends AbstractHBaseClient {
                    for (String qualifier : map.keySet())
                    {
                        String value = map.get(qualifier);
                        if(value == null){
                            continue;
                        }
                        p.add(familyName.getBytes(), qualifier.getBytes(), value.getBytes());
                    }
                }
@ -213,6 +216,38 @@ public class HBaseHelper extends AbstractHBaseClient {
        });
    }
    /**
     * 批量新增行
     */
    public void addBulk(String tableName , List<String> rowkeyList, List<Map<String,Map<String,String>>> familyList) throws Exception
    {
        hbaseTemplate.execute(tableName, new TableCallback<String>() {
            public String doInTable(HTableInterface table) throws Throwable {
                List<Put> list = new ArrayList<>();
                for(int i = 0; i < rowkeyList.size();i++){
                    Put p = new Put(rowkeyList.get(i).getBytes());
                    Map<String,Map<String,String>> family = familyList.get(i);
                    for(String familyName : family.keySet())
                    {
                        Map<String,String> map = family.get(familyName);
                        for (String qualifier : map.keySet())
                        {
                            String value = map.get(qualifier);
                            if(value == null){
                                continue;
                            }
                            p.add(familyName.getBytes(), qualifier.getBytes(), value.getBytes());
                        }
                    }
                    list.add(p);
                }
                table.put(list);
                return null;
            }
        });
    }
    /**
     * 新增数据
     */

+ 1 - 1
common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceDO.java

@ -51,7 +51,7 @@ public class IotDeviceDO extends IdEntityWithOperation implements Serializable {
    @Column(name = "manufacturer_name")
    private String manufacturerName;//厂商名称
    @Column(name = "manufacturer_tel")
    @Column(name = "manufacture_tel")
    private String manufactureTel;//厂商名称
    @Column(name = "order_code")

+ 20 - 2
common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/DataRequestMapping.java

@ -22,10 +22,28 @@ public class DataRequestMapping {
    public static class DataInput{
        public static final String api_data_input = "input";//数据上传
        public static final String api_user_bind = "userBind";//设备注册绑定
        public static final String api_update_record = "updateRecord";//更新体征状态标识
        public static final String message_success = "上传成功";
        public static final String message_fail = "上传失败";
        public static final String message_success = "upload success";
        public static final String message_fail = "upload fail";
        public static final String message_fail_jsonData_is_null = "jsonData is null";
    }
    /**
     * 数据查询
     */
    public static class DataSearch{
        public static final String api_data_search_one = "getById";
        public static final String api_user_search_list = "searchList";
        public static final String api_user_search_list_page = "listPage";
        public static final String api_user_search_recent5 = "recent5";
        public static final String api_user_search_recent1 = "recent1";
        public static final String api_user_abnormal_times_a_week = "abnormalTimes";
        public static final String api_user_search_list_code_del = "searchListByCodeAndDel";
        public static final String message_success = "search success";
        public static final String message_fail = "search fail";
        public static final String message_fail_jsonData_is_null = "param is null";
    }
}

+ 0 - 12
svr-lib-parent-pom/pom.xml

@ -76,8 +76,6 @@
        <version.hbase>1.1.12</version.hbase>
        <version.hadoop>2.7.4</version.hadoop>
        <version.scala>2.10.6</version.scala>
        <version.elasticsearch>2.4.4</version.elasticsearch>
        <version.jest>2.4.0</version.jest>
        <version.hbase-client>1.1.1</version.hbase-client>
        <version.joda-time>2.8.2</version.joda-time>
        <version.solr>5.5.1</version.solr>
@ -370,16 +368,6 @@
                <artifactId>elasticsearch-sql</artifactId>
                <version>${version.elasticsearch-sql}</version>
            </dependency>
            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>${version.elasticsearch}</version>
            </dependency>
            <dependency>
                <groupId>io.searchbox</groupId>
                <artifactId>jest</artifactId>
                <version>${version.jest}</version>
            </dependency>
            <!--elasticsearch end-->
            <!--alibaba  json 包-->
            <dependency>

+ 32 - 14
svr/svr-iot/pom.xml

@ -10,8 +10,10 @@
        <relativePath>../../svr-lib-parent-pom/pom.xml</relativePath>
    </parent>
    <groupId>com.yihu.iot</groupId>
    <artifactId>svr-iot</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
@ -21,6 +23,7 @@
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-es</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
@ -62,18 +65,6 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-mysql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
@ -127,13 +118,40 @@
        </dependency>
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-es</artifactId>
            <artifactId>common-data-hbase</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-hbase</artifactId>
            <artifactId>common-data-es</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>svr-iot</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.yihu.iot.IOTApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

+ 21 - 2
svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataInputController.java

@ -9,6 +9,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -34,11 +35,29 @@ public class DataInputController {
    @PostMapping(value = DataRequestMapping.DataInput.api_data_input, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "数据上传", notes = "数据上传入库")
    public Envelop uoloadData(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public Envelop uploadData(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData) {
        String str = "";
        try {
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success, dataInputService.uploadData(jsonData));
            str = dataInputService.uploadData(jsonData);
            if (str.equals("fail")) {
                return Envelop.getError(DataRequestMapping.DataInput.message_fail, 0);
            }
            if (str.equals("json no data")) {
                return Envelop.getError(DataRequestMapping.DataInput.message_fail_jsonData_is_null, 1);
            }
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
        return Envelop.getSuccess(DataRequestMapping.DataInput.message_success, str);
    }
    @PostMapping(value = DataRequestMapping.DataInput.api_update_record, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "用户体征状态修改", notes = "用户体征状态修改,0-标准,1-异常")
    public Envelop updateRecord(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataInputService.bindUser(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 106 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataSearchController.java

@ -0,0 +1,106 @@
package com.yihu.iot.datainput.controller;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.datainput.service.DataSearchService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.rm.iot.DataRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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(DataRequestMapping.api_iot_common)
@Api(value = "数据查询操作", description = "数据查询操作")
public class DataSearchController {
    @Autowired
    private DataSearchService dataSearchService;
    @PostMapping(value = DataRequestMapping.DataSearch.api_data_search_one, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询单条数据", notes = "根据id查询单条数据")
    public Envelop getOne(@ApiParam(name = "id", value = "", defaultValue = "") @RequestBody String id){
        try{
            String jsonData = "{\"id\":" + id + "}";
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询数据", notes = "根据条件查询数据")
    public Envelop getList(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list_page, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询数据,分页", notes = "根据条件查询数据,分页")
    public Envelop getListPage(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent5, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取最近5条数据", notes = "根据居民的体征类型,测量时间获取")
    public Envelop getRecent5(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_abnormal_times_a_week, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取居民一周内体征数据异常次数", notes = "血糖或血压体征数据")
    public Envelop getAbnormalTimesAWeek(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent1, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取最近一次体征数据")
    public Envelop getOneByCodeAndDel(@ApiParam(name = "userCode", value = "", defaultValue = "") @RequestBody String userCode,
                                      @ApiParam(name = "del", value = "", defaultValue = "") @RequestBody String del) {
        try {
            String jsonData = "{\"userCode\":" + userCode + ",\"del\":" + del + "}";
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success, dataSearchService.getData(jsonData));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list_code_del, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取所有体征数据,时间倒序")
    public Envelop getListByCodeAndDel(
            @ApiParam(name = "userCode", value = "", defaultValue = "") @RequestBody String userCode,
            @ApiParam(name = "del", value = "", defaultValue = "") @RequestBody String del){
        try{
            String jsonData = "{\"userCode\":"+userCode+",\"del\":"+ del +"}";
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(QueryBuilders.matchQuery("user", "kimchy"));
//            searchSourceBuilder.query(JSONObject.parseObject(jsonData).);
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 55 - 51
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataInputService.java

@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.base.es.config.model.SaveModel;
import com.yihu.base.hbase.HBaseAdmin;
import com.yihu.base.hbase.HBaseHelper;
import com.yihu.iot.datainput.enums.DataOperationTypeEnum;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.datainput.util.RowKeyUtils;
import com.yihu.iot.service.device.IotDeviceService;
import com.yihu.jw.iot.device.IotDeviceDO;
@ -40,22 +42,16 @@ public class DataInputService {
    @Autowired
    private HBaseHelper hBaseHelper;
    private String esIndex = "body_health_data";
    private String esType = "signs_data";
    private String tableName = "body_health_data";
    private String familyA = "column_signs_header";
    private String familyB = "column_signs_data";
    @Autowired
    private HBaseAdmin hBaseAdmin;
    /**
     * 居民设备注册及绑定
     */
    public String bindUser(String json){
        List<IotDeviceDO> deviceDOList = new ArrayList<>();
        JSONObject jsonObject = JSONObject.parseObject(json);
        String data_source = jsonObject.getString("data_source");
        List<IotDeviceDO> deviceDOList = new ArrayList<>();
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        try {
            if(null != jsonArray){
@ -68,7 +64,7 @@ public class DataInputService {
                        continue; //表示设备已经绑定过
                    }
                    iotDeviceDO.setDeviceSn(sn);
                    iotDeviceDO.setCode(dataJson.getString("ext_code"));
//                    iotDeviceDO.setCode(dataJson.getString("ext_code"));
                    iotDeviceDO.setName(dataJson.getString("device_name"));
                    iotDeviceDO.setDeviceModel(dataJson.getString("device_model"));
                    iotDeviceDO.setDeviceSource("2"); //设备来源为居民绑定
@ -90,7 +86,6 @@ public class DataInputService {
                iotDeviceService.bindUser(deviceDOList);
                //保存日志
                dataProcessLogService.saveLog("","",data_source,"", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss),"1","4","com.yihu.iot.datainput.service.DataInputService.bindUser",DataOperationTypeEnum.bindUser.getName(),0);
            }
        }catch (Exception e){
            logger.error("注册绑定失败");
@ -109,6 +104,12 @@ public class DataInputService {
        if(null != iotDeviceDO){
            iotDeviceDO.setUpdateUser(idcard);
            iotDeviceDO.setUpdateUserName(username);
        }else{
            iotDeviceDO = new IotDeviceDO();
            iotDeviceDO.setDeviceSource(data_source);
            iotDeviceDO.setDeviceSn(deviveSn);
            iotDeviceDO.setCreateUser(idcard);
            iotDeviceDO.setCreateUserName(username);
        }
        iotDeviceService.save(iotDeviceDO);
        //保存日志
@ -125,16 +126,13 @@ public class DataInputService {
        String fileName = "";
        String fileAbsPath = "";
        String rowkey = "";
        //提取json各项值
        //提取json某些项值
        JSONObject jsonObject = JSONObject.parseObject(json);
        String accessToken= jsonObject.getString("access_token");
        String dataSource = jsonObject.getString("data_source");
        String deviceSn = jsonObject.getString("sn");
        String extCode = jsonObject.getString("ext_code");
        String measuretime = jsonObject.getString("measure_time");
        if(null == measuretime){
            measuretime = DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss);
        }
        //包含居民身份的数据,对设备数据进行校验绑定,此处包含的信息只有身份证号和用户名以及设备序列号,如果设备库中存在该序号的设备,则对绑定居民进行修改,改为当前居民,如果没有则跳过
        if(jsonObject.containsKey("idcard") && jsonObject.containsKey("username")){
            String idcard = jsonObject.getString("idcard");
@ -142,54 +140,60 @@ public class DataInputService {
            updateBindUser(dataSource,deviceSn,idcard,username);
        }
        try {
            rowkey = RowKeyUtils.makeRowKey(accessToken, deviceSn, extCode, DateUtil.dateTimeParse(measuretime).getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //将数据存入es
        jsonObject.put("_id", new SaveModel().getId());//es的id继承至jestId
        jsonObject.put("id", rowkey);//hbase的rowkey
        elastricSearchHelper.save(esIndex, esType, jsonObject.toJSONString());
        Map<String, Map<String, String>> family = new HashMap<>();
        Map<String, String> columnsA = new HashMap<>();
        Map<String, String> columnsB = new HashMap<>();
        //组装A列
        columnsA.put("access_token",accessToken);
        columnsA.put("data_source",dataSource);
        columnsA.put("sn",deviceSn);
        columnsA.put("ext_code",extCode);
        columnsA.put("device_name",jsonObject.getString("device_name"));
        columnsA.put("device_model",jsonObject.getString("device_model"));
        family.put(familyA,columnsA);
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        if(null == jsonArray || jsonArray.size() == 0){
            return "json no data";
        }
        //组装B列
        List<String> rowkeyList = new ArrayList<>();
        List<Map<String,Map<String,String>>> familyList = new ArrayList<>();
        //循环数据,一组数据存一行,生成一个rowkey,并将该rowkey存到es中
        for(Object obj:jsonArray){
            JSONObject data = (JSONObject)obj;
           for(String key:data.keySet()){
               columnsB.put(key,data.getString(key));
           }
           if(data.containsKey("ecg")){
               fileName = data.getString("fileName");
               fileAbsPath = data.getString("filepath");
           }
            data.put("del","1"); //添加删除标记
            try {
                String measuretime = jsonObject.getString("measure_time");
                if(null == measuretime){
                    measuretime = DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss);
                }
                //生成一份json数据的rowkey
                rowkey = RowKeyUtils.makeRowKey(accessToken,deviceSn, extCode, DateUtil.dateTimeParse(measuretime).getTime());
                data.put("rid",rowkey);//hbase的rowkey
                rowkeyList.add(rowkey);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //组装B列
            Map<String, Map<String, String>> family = new HashMap<>();
            Map<String, String> columnsB = new HashMap<>();
            for(String key:data.keySet()){
                columnsB.put(key,data.getString(key));
            }
            if(data.containsKey("ecg")){
                fileName = data.getString("fileName");
                fileAbsPath = data.getString("filepath");
            }
            family.put(ConstantUtils.tableName,columnsB);
            familyList.add(family);
        }
        family.put(familyB,columnsB);
        //将数据存入es
        elastricSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, jsonObject.toJSONString());
        try {
            hBaseHelper.add(tableName,rowkey,family);
            boolean tableExists = hBaseAdmin.isTableExists(ConstantUtils.tableName);
            if (!tableExists) {
                hBaseAdmin.createTable(ConstantUtils.tableName,ConstantUtils.familyB);
            }
            hBaseHelper.addBulk(ConstantUtils.tableName, rowkeyList, familyList);
        } catch (Exception e) {
            e.printStackTrace();
            //保存日志
            dataProcessLogService.saveLog(fileName,fileAbsPath,dataSource,"", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss),"1","3","com.yihu.iot.datainput.service.DataInputService.uploadData", DataOperationTypeEnum.upload1.getName(),1);
            dataProcessLogService.saveLog(fileName, fileAbsPath, dataSource, "", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss), "1", "3", "com.yihu.iot.datainput.service.DataInputService.uploadData", DataOperationTypeEnum.upload1.getName(), 1);
        }
        //保存日志
        dataProcessLogService.saveLog(fileName,fileAbsPath,dataSource,"", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss),"1","4","com.yihu.iot.datainput.service.DataInputService.uploadData",DataOperationTypeEnum.upload1.getName(),0);
        dataProcessLogService.saveLog(fileName, fileAbsPath, dataSource, "", DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss), "1", "4", "com.yihu.iot.datainput.service.DataInputService.uploadData", DataOperationTypeEnum.upload1.getName(), 0);
        return "success";
    }

+ 1 - 1
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataProcessLogService.java

@ -31,7 +31,7 @@ public class DataProcessLogService extends BaseJpaService<DataProcessLogDO,DataP
        dataProcessLog.setUploadTime(uploadTime);
        dataProcessLog.setProcessType(processType);
        dataProcessLog.setProcessStatus(status);
        dataProcessLog.setProcessInterface(processInterface);
//        dataProcessLog.setProcessInterface(processInterface);
        dataProcessLog.setProcessDes(desc);
        dataProcessLog.setFileCount(failCount);
        dataProcessLogDao.save(dataProcessLog);

+ 35 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataSearchService.java

@ -0,0 +1,35 @@
package com.yihu.iot.datainput.service;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.base.hbase.HBaseHelper;
import com.yihu.iot.datainput.util.ConstantUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class DataSearchService {
    private Logger logger = LoggerFactory.getLogger(DataSearchService.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    private HBaseHelper hBaseHelper;
    /**
     * 获取数据
     * @param json
     * @return
     */
    public String getData(String json){
        String result = elastricSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,json);
        if(null == result){
            return "no data";
        }
        return result;
    }
}

+ 12 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/ConstantUtils.java

@ -0,0 +1,12 @@
package com.yihu.iot.datainput.util;
public class ConstantUtils {
    public static String esIndex = "body_health_data";
    public static String esType = "signs_data";
    public static String tableName = "body_health_data";
    public static String familyA = "column_signs_header";
    public static String familyB = "column_signs_data";
}

+ 88 - 5
svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/RowKeyUtils.java

@ -1,17 +1,100 @@
package com.yihu.iot.datainput.util;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.jcajce.provider.symmetric.DES;
import org.springframework.util.Base64Utils;
import org.springframework.util.DigestUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.io.UnsupportedEncodingException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
public class RowKeyUtils {
    public static String makeRowKey(String accessToken,String deviceSn,String extCode,long measureTime) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    private static EncryptUtil encryptUtil = EncryptUtil.getInstance();
    public static String makeRowKey(String accessToken,String deviceSn,String extCode,long measureTime) throws Exception {
        StringBuilder sb = new StringBuilder();
        sb.append(accessToken+"_");
        sb.append(deviceSn+"_");
        sb.append(extCode+"_");
        sb.append(accessToken+",");
        sb.append(deviceSn+",");
        sb.append(extCode+",");
        sb.append(measureTime);
        return DigestUtils.md5DigestAsHex(sb.toString().getBytes("utf-8"));
        return encryptUtil.encode(sb.toString());
    }
    /**
     * 将rowkey里的信息还原回去
     */
    public static String getMessageFromRowKey(String rowkey) throws Exception {
        return encryptUtil.decode(rowkey);
    }
    static class EncryptUtil {
        private final byte[] DESIV = new byte[] { 0x12, 0x34, 0x56, 120, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef };// 向量
        private AlgorithmParameterSpec iv = null;// 加密算法的参数接口
        private Key key = null;
        private static String charset = "utf-8";
        private static String deskey = "9ba45bfd500642328ec03ad8ef1b6e75";// 自定义密钥
        private static EncryptUtil encryptUtils = null;
        public static synchronized EncryptUtil getInstance()  {
            try {
                if(null == encryptUtils){
                    encryptUtils = new EncryptUtil(deskey,charset);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            return encryptUtils;
        }
        /**
         * 初始化
         * @param deSkey    密钥
         * @throws Exception
         */
        private EncryptUtil(String deSkey, String charset) throws Exception {
            if (StringUtils.isNotBlank(charset)) {
                this.charset = charset;
            }
            DESKeySpec keySpec = new DESKeySpec(deSkey.getBytes(this.charset));// 设置密钥参数
            iv = new IvParameterSpec(DESIV);// 设置向量
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");// 获得密钥工厂
            key = keyFactory.generateSecret(keySpec);// 得到密钥对象
        }
        /**
         * 加密
         */
        public String encode(String data) throws Exception {
            Cipher enCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");// 得到加密对象Cipher
            enCipher.init(Cipher.ENCRYPT_MODE, key, iv);// 设置工作模式为加密模式,给出密钥和向量
            byte[] pasByte = enCipher.doFinal(data.getBytes("utf-8"));
            BASE64Encoder base64Encoder = new BASE64Encoder();
            return base64Encoder.encode(pasByte);
        }
        /**
         * 解密
         */
        public String decode(String data) throws Exception {
            Cipher deCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
            deCipher.init(Cipher.DECRYPT_MODE, key, iv);
            BASE64Decoder base64Decoder = new BASE64Decoder();
            byte[] pasByte = deCipher.doFinal(base64Decoder.decodeBuffer(data));
            return new String(pasByte, "UTF-8");
        }
    }
}

+ 5 - 14
svr/svr-iot/src/main/resources/application.yml

@ -27,14 +27,15 @@ spring:
  data:
    elasticsearch: #ElasticsearchProperties
      cluster-name: jkzl #默认即为elasticsearch  集群名
      cluster-nodes: 172.17.110.217:9300,172.17.110.128:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      local: false #是否本地连接
#      properties: # Additional properties used to configure the client.
      properties: # Additional properties used to configure the client.
        enable: true
  # JEST (Elasticsearch HTTP client) (JestProperties)
  elasticsearch:
    jest:
      uris: http://localhost:9200
      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 # Enable connection requests from multiple execution threads.
#      username: # Login user.
@ -63,16 +64,6 @@ fast-dfs:
    max-size: 20
    wait-time: 500
#es配置
es:
  host:  127.0.0.1
  port: 9200 #默认是9200
  tPort: 9300 #http端口 默认是9300
  clusterName: jkzl
hadoop:
  hbase-properties: