Browse Source

查询网关接口

LiTaohong 7 years ago
parent
commit
f893d5b0ab

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

@ -147,6 +147,7 @@ public class ElastricSearchHelper {
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("delete data count:" + saveModels.size());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {

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

@ -59,7 +59,7 @@ public class DataSearchController {
    @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,
    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){
        try{
@ -83,11 +83,11 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent1, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取最近一次体征数据")
    public Envelop getOneByCodeAndDel(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData,
    public Envelop getRecent1ByCodeAndDel(@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) {
        try {
            return Envelop.getSuccess(DataRequestMapping.DataInput.message_success, dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success, dataSearchService.getData(jsonData,page,size));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -99,7 +99,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.DataInput.message_success,dataSearchService.getData(jsonData,page,size));
            return Envelop.getSuccess(DataRequestMapping.DataSearch.message_success,dataSearchService.getData(jsonData,page,size));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }

+ 16 - 0
web-gateway/src/main/java/com/yihu/jw/commnon/iot/DataConstants.java

@ -15,4 +15,20 @@ public class DataConstants {
        public static final String api_bind_user = "/userBind";
        public static final String api_upload_data = "/input";
    }
    /**
     * 数据查询
     */
    public static class DataSearch{
        public static final String api_common = api_iot_common + "/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";
    }
}

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

@ -0,0 +1,88 @@
package com.yihu.jw.controller.iot.data_input;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yihu.jw.commnon.iot.DataConstants;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.feign.iot.data_input.DataInputFeign;
import com.yihu.jw.feign.iot.data_input.DataSearchFeign;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(DataConstants.DataSearch.api_common)
@Api(value = "数据查询", description = "数据查询")
public class DataSearchController {
    @Autowired
    private DataSearchFeign dataSearchFeign;
    @PostMapping(value = DataConstants.DataSearch.api_data_search_one, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询单条数据", notes = "根据id查询单条数据")
    @HystrixCommand(commandProperties = {
            @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) {
        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){
        try{
            return dataSearchFeign.getList(jsonData,page,size);
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @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){
            return dataSearchFeign.getListPage(jsonData,page,size);
    }
    @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);
    }
    @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);
    }
    @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);
    }
    @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);
    }
}

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

@ -0,0 +1,72 @@
package com.yihu.jw.feign.fallbackfactory.iot.data_input;
import com.yihu.jw.feign.iot.data_input.DataInputFeign;
import com.yihu.jw.feign.iot.data_input.DataSearchFeign;
import com.yihu.jw.restmodel.common.Envelop;
import feign.hystrix.FallbackFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
@Component
public class DataSearchFeignFallbackFactory implements FallbackFactory<DataSearchFeign> {
    @Autowired
    private Tracer tracer;
    @Override
    public DataSearchFeign create(Throwable throwable) {
        return new DataSearchFeign() {
            @Override
            public Envelop getOne(String jsonData) {
                tracer.getCurrentSpan().logEvent("根据id获取单条数据失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getList(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("获取多条数据失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getListPage(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("获取数据分页列表失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getRecent5(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("获取最近"+size+"条记录数据:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getAbnormalTimesAWeek(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("获取最近体征数据异常次数失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getOneByCodeAndDel(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("根据居民code和删除标识获取最近一次体征数据:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop getListByCodeAndDel(String jsonData, int page, int size) {
                tracer.getCurrentSpan().logEvent("根据居民code和删除标识获取所有体征数据失败:原因:" + throwable.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
        };
    }
}

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

@ -0,0 +1,59 @@
package com.yihu.jw.feign.iot.data_input;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.feign.fallbackfactory.iot.data_input.DataInputFeignFallbackFactory;
import com.yihu.jw.feign.fallbackfactory.iot.data_input.DataSearchFeignFallbackFactory;
import com.yihu.jw.restmodel.CommonContants;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.rm.iot.DataRequestMapping;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.feign.FeignClient;
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.RequestParam;
@FeignClient(
        name = CommonContants.svr_iot // name值是eurika的实例名字
        ,fallbackFactory  = DataSearchFeignFallbackFactory.class
)
@RequestMapping(DataRequestMapping.api_iot_common)
public interface DataSearchFeign {
    @PostMapping(value = DataRequestMapping.DataSearch.api_data_search_one, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    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);
    @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);
    @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);
    @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);
    @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);
    @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);
}