Browse Source

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

yeshijie 7 years ago
parent
commit
0b01085de7

+ 8 - 10
svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataSearchController.java

@ -27,7 +27,7 @@ public class DataSearchController {
    public Envelop getOne(
            @ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,1,1));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -39,7 +39,7 @@ public class DataSearchController {
                           @ApiParam(name = "page", value = "", defaultValue = "") @RequestParam int page,
                           @ApiParam(name = "size", value = "", defaultValue = "") @RequestParam int size){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -51,7 +51,7 @@ public class DataSearchController {
                               @ApiParam(name = "page", value = "", defaultValue = "") @RequestParam int page,
                               @ApiParam(name = "size", value = "", defaultValue = "") @RequestParam int size){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -59,11 +59,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent5, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取最近5条数据", notes = "根据居民的体征类型,测量时间获取")
    public Envelop getRecent5ByTypeAndTime(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData,
                              @ApiParam(name = "page", value = "", defaultValue = "") @RequestParam int page,
                              @ApiParam(name = "size", value = "", defaultValue = "") @RequestParam int size){
    public Envelop getRecent5ByTypeAndTime(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData ){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -75,7 +73,7 @@ public class DataSearchController {
                                         @ApiParam(name = "page", value = "", defaultValue = "") @RequestParam int page,
                                         @ApiParam(name = "size", value = "", defaultValue = "") @RequestParam int size){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -87,7 +85,7 @@ public class DataSearchController {
                                      @ApiParam(name = "page", value = "", defaultValue = "") @RequestParam int page,
                                      @ApiParam(name = "size", value = "", defaultValue = "") @RequestParam int size) {
        try {
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success, dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success, dataSearchService.getData(jsonData));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -99,7 +97,7 @@ public class DataSearchController {
                                       @ApiParam(name = "page", value = "", defaultValue = "") @RequestParam int page,
                                       @ApiParam(name = "size", value = "", defaultValue = "") @RequestParam int size){
        try{
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }

+ 57 - 7
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataSearchService.java

@ -1,5 +1,6 @@
package com.yihu.iot.datainput.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -17,6 +18,9 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CollectionUtils;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -106,18 +110,18 @@ public class DataSearchService {
        return query.toJSONString();
    }
    public String getData(String jsonData,int page, int size){
    public String getData(String jsonData){
//        String query = getQueryString(jsonData);
        JSONObject resultJsonObj = new JSONObject();
        JSONArray  resultArray = new JSONArray();
        List list = new ArrayList();
       /* List list = new ArrayList();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            list = objectMapper.readValue(jsonData,(List.class));
        } catch (IOException e) {
            e.printStackTrace();
        }
        SearchSourceBuilder query = getQueryBuilder(list,page,size);
        }*/
        SearchSourceBuilder query = getQueryBuilder(jsonData);
        SearchResult esResult = elastricSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,query.toString());
        if(esResult.getTotal() == 0){
            return "";
@ -177,7 +181,13 @@ public class DataSearchService {
        return resultJsonObj.toJSONString();
    }
    private SearchSourceBuilder getQueryBuilder(List<Map<String, Object>> filter,int page, int size) {
    //List<Map<String, Object>> filter,int page, int size,String sort
    private SearchSourceBuilder getQueryBuilder(String jsonData) {
        JSONObject json = JSONObject.parseObject(jsonData);
        List<Map<String, Object>> filter = (List)json.getJSONArray("filter");
        int page = json.getIntValue("page");
        int size = json.getIntValue("size");
        JSONArray sort = json.getJSONArray("sort");
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        for(Map<String, Object> param : filter) {
@ -227,6 +237,21 @@ public class DataSearchService {
        searchSourceBuilder.query(boolQueryBuilder);
        searchSourceBuilder.from((page -1)*size);
        searchSourceBuilder.size(size);
        if(CollectionUtils.notEmpty(sort)){
            for(Object obj:sort){
                JSONObject object = JSONObject.parseObject(obj.toString());
                for(String key:object.keySet()){
                    FieldSortBuilder fieldSortBuilder = new FieldSortBuilder(key);
                    JSONObject sortValue = object.getJSONObject(key);
                    if(StringUtils.equalsIgnoreCase(SortOrder.ASC.toString(),sortValue.getString("order"))){
                        fieldSortBuilder.order(SortOrder.ASC);
                    }else if(StringUtils.equalsIgnoreCase(SortOrder.DESC.toString(),sortValue.getString("order"))){
                        fieldSortBuilder.order(SortOrder.DESC);
                    }
                    searchSourceBuilder.sort(fieldSortBuilder);
                }
            }
        }
        return searchSourceBuilder;
    }
@ -238,6 +263,31 @@ public class DataSearchService {
    public String updateFiled(String json){
        return "success";
    }
    public static void main(String args[]) {
        }
    public static void main(String args[]) {}
}

+ 13 - 25
web-gateway/src/main/java/com/yihu/jw/controller/iot/data_input/DataSearchController.java

@ -29,17 +29,15 @@ public class DataSearchController {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop getOne(
            @ApiParam(name = "json_data", value = ""  ) @RequestBody String jsonData) {
            @ApiParam(name = "json_data", value = ""  )@RequestBody String jsonData) {
        return dataSearchFeign.getOne(jsonData);
    }
    @PostMapping(value = DataConstants.DataSearch.api_user_search_list, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询数据", notes = "根据条件查询数据")
    public Envelop getList(@ApiParam(name = "json_data", value = "json_data"  ) @RequestBody String jsonData,
                           @ApiParam(name = "page", value = "page"  ) @RequestParam(value = "page", required = true)  int page,
                           @ApiParam(name = "size", value = "size"  ) @RequestParam(value = "size", required = true)  int size){
    public Envelop getList(@ApiParam(name = "json_data", value = "json_data"  ) @RequestBody String jsonData){
        try{
            return dataSearchFeign.getList(jsonData,page,size);
            return dataSearchFeign.getList(jsonData );
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -47,42 +45,32 @@ public class DataSearchController {
    @PostMapping(value = DataConstants.DataSearch.api_user_search_list_page, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询数据,分页", notes = "根据条件查询数据,分页")
    public Envelop getListPage(@ApiParam(name = "json_data", value = ""  ) @RequestBody String jsonData,
                               @ApiParam(name = "page", value = "page"  ) @RequestParam(value = "page", required = true)  int page,
                               @ApiParam(name = "size", value = "size"  ) @RequestParam(value = "size", required = true)  int size){
    public Envelop getListPage(@ApiParam(name = "json_data", value = ""  )@RequestBody String jsonData ){
            return dataSearchFeign.getListPage(jsonData,page,size);
            return dataSearchFeign.getListPage(jsonData );
    }
    @PostMapping(value = DataConstants.DataSearch.api_user_search_recent5, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取最近5条数据", notes = "根据居民的体征类型,测量时间获取")
    public Envelop getRecent5(@ApiParam(name = "json_data", value = ""  ) @RequestBody String jsonData,
                              @ApiParam(name = "page", value = "page"  ) @RequestParam(value = "page", required = true)  int page,
                              @ApiParam(name = "size", value = "size"  ) @RequestParam(value = "size", required = true)  int size){
            return dataSearchFeign.getRecent5ByTypeAndTime(jsonData,page,size);
    public Envelop getRecent5ByTypeAndTime(@ApiParam(name = "json_data", value = ""  )@RequestBody String jsonData){
            return dataSearchFeign.getRecent5ByTypeAndTime(jsonData );
    }
    @PostMapping(value = DataConstants.DataSearch.api_user_abnormal_times_a_week, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取居民一周内体征数据异常次数", notes = "血糖或血压体征数据")
    public Envelop getAbnormalTimesAWeek(@ApiParam(name = "json_data", value = ""  ) @RequestBody String jsonData,
                                         @ApiParam(name = "page", value = "page"  ) @RequestParam(value = "page", required = true)  int page,
                                         @ApiParam(name = "size", value = "size"  ) @RequestParam(value = "size", required = true)  int size){
            return dataSearchFeign.getAbnormalTimesAWeek(jsonData,page,size);
    public Envelop getAbnormalTimesAWeek(@ApiParam(name = "json_data", value = "") @RequestBody String jsonData){
            return dataSearchFeign.getAbnormalTimesAWeek(jsonData );
    }
    @PostMapping(value = DataConstants.DataSearch.api_user_search_recent1, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取最近一次体征数据")
    public Envelop getOneByCodeAndDel(@ApiParam(name = "json_data", value = ""  ) @RequestBody String jsonData,
                                      @ApiParam(name = "page", value = "page"  ) @RequestParam(value = "page", required = true)  int page,
                                      @ApiParam(name = "size", value = "size"  ) @RequestParam(value = "size", required = true)  int size) {
            return dataSearchFeign.getRecent1ByCodeAndDel(jsonData,page,size);
    public Envelop getRecent1ByCodeAndDel(@ApiParam(name = "json_data", value = "") @RequestBody String jsonData) {
            return dataSearchFeign.getRecent1ByCodeAndDel(jsonData );
    }
    @PostMapping(value = DataConstants.DataSearch.api_user_search_list_code_del, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取所有体征数据,时间倒序")
    public Envelop getListByCodeAndDel(@ApiParam(name = "json_data", value = ""  ) @RequestBody String jsonData,
                                       @ApiParam(name = "page", value = "page"  )@RequestParam(value = "page", required = true)  int page,
                                       @ApiParam(name = "size", value = "size"  )@RequestParam(value = "size", required = true)  int size){
            return dataSearchFeign.getListByCodeAndDel(jsonData,page,size);
    public Envelop getListByCodeAndDel(@ApiParam(name = "json_data", value = "") @RequestBody String jsonData){
            return dataSearchFeign.getListByCodeAndDel(jsonData );
    }
}

+ 7 - 7
web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/data_input/DataSearchFeignFallbackFactory.java

@ -27,42 +27,42 @@ public class DataSearchFeignFallbackFactory implements FallbackFactory<DataSearc
            }
            @Override
            public Envelop getList(String jsonData, int page, int size) {
            public Envelop getList(String jsonData ) {
                tracer.getCurrentSpan().logEvent("获取多条数据失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getListPage(String jsonData, int page, int size) {
            public Envelop getListPage(String jsonData ) {
                tracer.getCurrentSpan().logEvent("获取数据分页列表失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getRecent5ByTypeAndTime(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("获取最近"+size+"条记录数据:原因:" + throwable.getMessage());
            public Envelop getRecent5ByTypeAndTime(String jsonData ) {
                tracer.getCurrentSpan().logEvent("获取最近5条记录数据失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getAbnormalTimesAWeek(String jsonData, int page, int size) {
            public Envelop getAbnormalTimesAWeek(String jsonData ) {
                tracer.getCurrentSpan().logEvent("获取最近体征数据异常次数失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getRecent1ByCodeAndDel(String jsonData, int page, int size) {
            public Envelop getRecent1ByCodeAndDel(String jsonData ) {
                tracer.getCurrentSpan().logEvent("根据居民code和删除标识获取最近一次体征数据:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getListByCodeAndDel(String jsonData, int page, int size) {
            public Envelop getListByCodeAndDel(String jsonData ) {
                tracer.getCurrentSpan().logEvent("根据居民code和删除标识获取所有体征数据失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;

+ 6 - 18
web-gateway/src/main/java/com/yihu/jw/feign/iot/data_input/DataSearchFeign.java

@ -27,33 +27,21 @@ public interface DataSearchFeign {
    public Envelop getOne(@RequestBody String jsonData);
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop getList( @RequestBody String jsonData,
                            @RequestParam(value = "page", required = true) int page,
                            @RequestParam(value = "size", required = true) int size);
    public Envelop getList( @RequestBody String jsonData);
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list_page, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop getListPage( @RequestBody String jsonData,
                                @RequestParam(value = "page", required = true) int page,
                                @RequestParam(value = "size", required = true) int size);
    public Envelop getListPage( @RequestBody String jsonData);
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent5, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop getRecent5ByTypeAndTime( @RequestBody String jsonData,
                               @RequestParam(value = "page", required = true) int page,
                               @RequestParam(value = "size", required = true) int size);
    public Envelop getRecent5ByTypeAndTime( @RequestBody String jsonData);
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_abnormal_times_a_week, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop getAbnormalTimesAWeek(@RequestBody String jsonData,
                                          @RequestParam(value = "page", required = true) int page,
                                          @RequestParam(value = "size", required = true) int size);
    public Envelop getAbnormalTimesAWeek(@RequestBody String jsonData);
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent1, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop getRecent1ByCodeAndDel(@RequestBody String jsonData,
                                      @RequestParam(value = "page", required = true) int page,
                                      @RequestParam(value = "size", required = true) int size);
    public Envelop getRecent1ByCodeAndDel(@RequestBody String jsonData);
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list_code_del, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop getListByCodeAndDel( @RequestBody String jsonData,
                                        @RequestParam(value = "page", required = true)int page,
                                        @RequestParam(value = "size", required = true)int size);
    public Envelop getListByCodeAndDel( @RequestBody String jsonData);
}