Browse Source

IOT ES统一版本

suxiaoyang 6 years ago
parent
commit
28a519df51

+ 9 - 3
common/common-entity/src/main/java/com/yihu/jw/entity/base/role/RoleDO.java

@ -14,11 +14,17 @@ import javax.persistence.Table;
@Table(name = "base_role")
public class RoleDO extends UuidIdentityEntityWithOperator {
	//角色名称
	/**
	 * 角色名称
	 */
	private String name;
	//备注
	/**
	 * 备注
	 */
	private String remark;
	//是否系统管理员
	/**
	 * 是否系统管理员
	 */
	private Boolean system;
	@Column(name = "name", length = 50)

+ 11 - 4
common/common-entity/src/main/java/com/yihu/jw/entity/base/user/UserHideModuleFunctionDO.java

@ -7,17 +7,24 @@ import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by progr1mmer on 2018/8/14.
 * @author progr1mmer
 * @date Created on 2018/8/14.
 */
@Entity
@Table(name = "base_user_hide_module_function")
public class UserHideModuleFunctionDO extends IntegerIdentityEntity {
    //用户ID
    /**
     * 用户ID
     */
    private String userId;
    //模块ID
    /**
     * 模块ID
     */
    private Integer moduleId;
    //功能ID(该字段为空则直接隐藏上级模块)
    /**
     * 功能ID(该字段为空则直接隐藏上级模块)
     */
    private Integer functionId;
    @Column(name = "user_id", nullable = false, length = 50)

+ 8 - 13
common/common-entity/src/main/java/com/yihu/jw/entity/iot/datainput/DataStandardDO.java

@ -11,27 +11,16 @@ import java.io.Serializable;
@Table(name = "iot_base_data_def")
public class DataStandardDO extends UuidIdentityEntity implements Serializable {
    @Column(name = "base_name")
    private String baseName;
    @Column(name = "item_code")
    private String baseName;
    private String itemCode;
    @Column(name = "item_name")
    private String itemName;
    @Column(name = "item_type")
    private String itemType;
    @Column(name = "required")
    private String required;
    @Column(name = "item_value_min")
    private String itemValueMin;
    @Column(name = "item_value_max")
    private String itemValueMax;
    @Column(name = "base_name")
    public String getBaseName() {
        return baseName;
    }
@ -40,6 +29,7 @@ public class DataStandardDO extends UuidIdentityEntity implements Serializable {
        this.baseName = baseName;
    }
    @Column(name = "item_code")
    public String getItemCode() {
        return itemCode;
    }
@ -48,6 +38,7 @@ public class DataStandardDO extends UuidIdentityEntity implements Serializable {
        this.itemCode = itemCode;
    }
    @Column(name = "item_name")
    public String getItemName() {
        return itemName;
    }
@ -56,6 +47,7 @@ public class DataStandardDO extends UuidIdentityEntity implements Serializable {
        this.itemName = itemName;
    }
    @Column(name = "item_type")
    public String getItemType() {
        return itemType;
    }
@ -64,6 +56,7 @@ public class DataStandardDO extends UuidIdentityEntity implements Serializable {
        this.itemType = itemType;
    }
    @Column(name = "required")
    public String getRequired() {
        return required;
    }
@ -72,6 +65,7 @@ public class DataStandardDO extends UuidIdentityEntity implements Serializable {
        this.required = required;
    }
    @Column(name = "item_value_min")
    public String getItemValueMin() {
        return itemValueMin;
    }
@ -80,6 +74,7 @@ public class DataStandardDO extends UuidIdentityEntity implements Serializable {
        this.itemValueMin = itemValueMin;
    }
    @Column(name = "item_value_max")
    public String getItemValueMax() {
        return itemValueMax;
    }

+ 59 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/user/UserHideModuleFunctionVO.java

@ -0,0 +1,59 @@
package com.yihu.jw.restmodel.base.user;
import com.yihu.jw.restmodel.IntegerIdentityVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.Column;
/**
 * @author progr1mmer
 * @date Created on 2018/9/11.
 */
@ApiModel(value = "UserHideModuleFunctionVO", description = "用户取消订阅的模块或者功能")
public class UserHideModuleFunctionVO extends IntegerIdentityVO {
    /**
     * 用户ID
     */
    @ApiModelProperty(value = "用户ID", example = "402303ee65634dfs0234sf9a324a0023")
    private String userId;
    /**
     * 模块ID
     */
    @ApiModelProperty(value = "模块ID", example = "402303ee65634dfs0234sf9a324a0024")
    private Integer moduleId;
    /**
     * 功能ID(该字段为空则直接隐藏上级模块)
     */
    @ApiModelProperty(value = "功能ID", example = "402303ee65634dfs0234sf9a324a0025")
    private Integer functionId;
    @Column(name = "user_id", nullable = false, length = 50)
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    @Column(name = "module_id", nullable = false)
    public Integer getModuleId() {
        return moduleId;
    }
    public void setModuleId(Integer moduleId) {
        this.moduleId = moduleId;
    }
    @Column(name = "function_id")
    public Integer getFunctionId() {
        return functionId;
    }
    public void setFunctionId(Integer functionId) {
        this.functionId = functionId;
    }
}

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

@ -127,7 +127,7 @@
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>elasticsearch-jest-starter</artifactId>
            <artifactId>elasticsearch-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!--<dependency>

+ 29 - 29
svr/svr-iot/src/main/java/com/yihu/iot/config/jpa/HibernateProperties.java

@ -1,29 +1,29 @@
package com.yihu.iot.config.jpa;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import java.util.Properties;
/**
 * Created by chenweida on 2017/4/6.
 */
@Component
@RefreshScope
public class HibernateProperties {
    @Value("${hibernate.dialect}")
    private String dialect;
    @Value("${hibernate.show_sql}")
    private String show_sql;
    @Value("${hibernate.ejb.naming_strategy}")
    private String naming_strategy;
    public  Properties hibProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect",dialect);
        properties.put("hibernate.show_sql", show_sql);
        properties.put("hibernate.ejb.naming_strategy", naming_strategy);
        return properties;
    }
}
//package com.yihu.iot.config.jpa;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.stereotype.Component;
//
//import java.util.Properties;
//
///**
// * Created by chenweida on 2017/4/6.
// */
//@Component
//@RefreshScope
//public class HibernateProperties {
//    @Value("${hibernate.dialect}")
//    private String dialect;
//    @Value("${hibernate.show_sql}")
//    private String show_sql;
//    @Value("${hibernate.ejb.naming_strategy}")
//    private String naming_strategy;
//
//    public  Properties hibProperties() {
//        Properties properties = new Properties();
//        properties.put("hibernate.dialect",dialect);
//        properties.put("hibernate.show_sql", show_sql);
//        properties.put("hibernate.ejb.naming_strategy", naming_strategy);
//        return properties;
//    }
//}

+ 65 - 65
svr/svr-iot/src/main/java/com/yihu/iot/config/jpa/IotJpa.java

@ -1,65 +1,65 @@
package com.yihu.iot.config.jpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
/**
 * Created by chenweida on 2017/4/6.
 */
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "iotEntityManagerFactory",
        transactionManagerRef = "iotTransactionManager",
        basePackages = {"com.yihu.iot.dao","com.yihu.iot.datainput.dao"})   //设置Repository所在位置
public class IotJpa {
    @Autowired
    private HibernateProperties hibernateProperties;
    @Bean(name = "iotEntityManagerFactory")
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(DataSource dataSource) {
        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setDataSource(dataSource);
        emfb.setPackagesToScan("com.yihu.jw.entity.iot");
        emfb.setPersistenceUnitName("iot");
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        emfb.setJpaVendorAdapter(vendorAdapter);
        emfb.setJpaProperties(hibernateProperties.hibProperties());
        return emfb;
    }
    @Bean(name = "iotTransactionManager")
    @Primary
    JpaTransactionManager transactionManagerSecondary(
            @Qualifier("iotEntityManagerFactory") EntityManagerFactory builder) {
        return new JpaTransactionManager(builder);
    }
    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource(){
        return DataSourceBuilder.create().build();
    }
}
//package com.yihu.iot.config.jpa;
//
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.JpaVendorAdapter;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.persistence.EntityManagerFactory;
//import javax.sql.DataSource;
//
///**
// * Created by chenweida on 2017/4/6.
// */
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//        entityManagerFactoryRef = "iotEntityManagerFactory",
//        transactionManagerRef = "iotTransactionManager",
//        basePackages = {"com.yihu.iot.dao","com.yihu.iot.datainput.dao"})   //设置Repository所在位置
//public class IotJpa {
//
//    @Autowired
//    private HibernateProperties hibernateProperties;
//
//    @Bean(name = "iotEntityManagerFactory")
//    @Primary
//    public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(DataSource dataSource) {
//
//        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
//        emfb.setDataSource(dataSource);
//        emfb.setPackagesToScan("com.yihu.jw.entity.iot");
//        emfb.setPersistenceUnitName("iot");
//        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
//        emfb.setJpaVendorAdapter(vendorAdapter);
//        emfb.setJpaProperties(hibernateProperties.hibProperties());
//
//        return emfb;
//    }
//
//
//    @Bean(name = "iotTransactionManager")
//    @Primary
//    JpaTransactionManager transactionManagerSecondary(
//            @Qualifier("iotEntityManagerFactory") EntityManagerFactory builder) {
//        return new JpaTransactionManager(builder);
//    }
//
//    @Bean
//    @Primary
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DataSource dataSource(){
//        return DataSourceBuilder.create().build();
//    }
//
//}

+ 5 - 1
svr/svr-iot/src/main/java/com/yihu/iot/datainput/controller/DataInputController.java

@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
@RestController
@RequestMapping(DataRequestMapping.api_iot_common)
@Api(tags = "数据上传操作", description = "数据上传操作")
@ -35,7 +37,9 @@ public class DataInputController {
    @PostMapping(value = DataRequestMapping.DataInput.api_data_input, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "体征数据上传", notes = "数据上传入库")
    public MixEnvelop uploadData(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData) {
    public MixEnvelop uploadData(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException  {
        String str = "";
        try {
            str = dataInputService.inputBodySignsData(jsonData);

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

@ -15,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@RestController
@RequestMapping(DataRequestMapping.api_iot_common)
@Api(tags = "数据查询操作", description = "数据查询操作")
@ -26,7 +28,8 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_data_search_one, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询单条数据", notes = "根据id查询单条数据")
    public MixEnvelop<DataBodySignsVO, DataBodySignsVO> getOne(
            @ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getDataToBean(jsonData));
        } catch (ApiException e){
@ -37,7 +40,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询数据", notes = "根据条件查询数据")
    @ApiModelProperty()
    public MixEnvelop<DataBodySignsVO, DataBodySignsVO> getList(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop<DataBodySignsVO, DataBodySignsVO> getList(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getDataToBean(jsonData));
        } catch (ApiException e){
@ -47,9 +52,11 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list_page, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询数据,分页", notes = "根据条件查询数据,分页")
    public MixEnvelop getListPage(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop getListPage(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getDataToBean(jsonData));
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success, dataSearchService.getDataToBean(jsonData));
        } catch (ApiException e){
            return MixEnvelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -57,11 +64,13 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent5, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取最近5条数据", notes = "根据居民的体征类型,测量时间获取")
    public MixEnvelop<DataBodySignsVO, DataBodySignsVO> getRecent5ByTypeAndTime(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData ){
    public MixEnvelop<DataBodySignsVO, DataBodySignsVO> getRecent5ByTypeAndTime(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData ) throws IOException {
        try{
            JSONObject jsonObject = JSONObject.parseObject(jsonData);
            jsonObject.put("size",5);
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getDataToBean(jsonObject.toJSONString()));
            jsonObject.put("size", 5);
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success, dataSearchService.getDataToBean(jsonObject.toJSONString()));
        } catch (ApiException e){
            return MixEnvelop.getError(e.getMessage(), e.getErrorCode());
        }
@ -69,7 +78,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_abnormal_times_a_week, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取居民一周内体征数据异常次数", notes = "血糖或血压体征数据")
    public MixEnvelop getAbnormalTimesAWeek(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop getAbnormalTimesAWeek(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getDataToBean(jsonData));
        } catch (ApiException e){
@ -79,7 +90,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_recent1, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取最近一次体征数据")
    public MixEnvelop getRecent1ByCodeAndDel(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData) {
    public MixEnvelop getRecent1ByCodeAndDel(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try {
            JSONObject jsonObject = JSONObject.parseObject(jsonData);
            jsonObject.put("size",1);
@ -91,7 +104,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_list_code_del, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询体征数据", notes = "根据居民code和删除标识获取所有体征数据,时间倒序")
    public MixEnvelop getListByCodeAndDel(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop getListByCodeAndDel(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getDataToBean(jsonData));
        } catch (ApiException e){
@ -101,7 +116,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_delete, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "体征数据删除", notes = "根据id删除标志,支持伪删除")
    public MixEnvelop delete(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop delete(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            String str = dataSearchService.updateData(jsonData);
            if(!StringUtils.equalsIgnoreCase("true",str)){
@ -115,7 +132,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新体征记录", notes = "根据id更新体征记录(包括体征值、上传时间等)")
    public MixEnvelop update(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop update(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            String str = dataSearchService.updateData(jsonData);
            if(!StringUtils.equalsIgnoreCase("true",str)){
@ -129,7 +148,9 @@ public class DataSearchController {
    @PostMapping(value = DataRequestMapping.DataSearch.api_user_search_werun_datas, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询微信运动数据", notes = "根据Id获取用户微信运动数据")
    public MixEnvelop getWeRunDataListById(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
    public MixEnvelop getWeRunDataListById(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) throws IOException {
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.search_success,dataSearchService.getWeRunDataList(jsonData));
        } catch (ApiException e){

+ 8 - 7
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataInputService.java

@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
//import com.yihu.base.hbase.HBaseAdmin;
//import com.yihu.base.hbase.HBaseHelper;
import com.yihu.elasticsearch.jest.ElastricSearchHelper;
import com.yihu.elasticsearch.ElasticSearchHelper;
import com.yihu.iot.datainput.enums.DataOperationTypeEnum;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.datainput.util.RowKeyUtils;
@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.*;
/**
@ -41,7 +42,7 @@ public class DataInputService {
    private DataProcessLogService dataProcessLogService;
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    private ElasticSearchHelper elasticSearchHelper;
//    @Autowired
//    private HBaseHelper hBaseHelper;
@ -125,7 +126,7 @@ public class DataInputService {
     * @param json
     * @return
     */
    public String uploadData(String json){
    public String uploadData(String json) throws IOException {
        String fileName = "";
        String fileAbsPath = "";
        String rowkey = "";
@ -186,7 +187,7 @@ public class DataInputService {
        }
        //将数据存入es
        elastricSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, jsonObject.toJSONString());
        elasticSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, jsonObject.toJSONString());
        try {
//            boolean tableExists = hBaseAdmin.isTableExists(ConstantUtils.tableName);
@ -216,7 +217,7 @@ public class DataInputService {
     * @param json
     * @return
     */
    public String inputBodySignsData(String json){
    public String inputBodySignsData(String json) throws IOException {
        String fileName = "";
        String fileAbsPath = "";
        String rowkey = "";
@ -279,7 +280,7 @@ public class DataInputService {
        JSONArray saveArray = new JSONArray();
        saveArray.add(bodySignsDO);
        //将数据存入es
        elastricSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, saveArray.toJSONString());
        elasticSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, saveArray.toJSONString());
        /*try {
            boolean tableExists = hBaseAdmin.isTableExists(ConstantUtils.tableName);
@ -323,7 +324,7 @@ public class DataInputService {
            return "invalid stepinfolist";
        }
        try{
            bool = elastricSearchHelper.save(ConstantUtils.weRunDataIndex,ConstantUtils.weRunDataType,json);
            bool = elasticSearchHelper.save(ConstantUtils.weRunDataIndex,ConstantUtils.weRunDataType,json);
        }catch (Exception e){
            logger.error("upload weRunData to elasticsearch failed," + e.getMessage());
            return e.getMessage();

+ 15 - 13
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataSearchService.java

@ -3,7 +3,7 @@ package com.yihu.iot.datainput.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
//import com.yihu.base.hbase.HBaseHelper;
import com.yihu.elasticsearch.jest.ElastricSearchHelper;
import com.yihu.elasticsearch.ElasticSearchHelper;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.datainput.util.RowKeyUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
@ -20,6 +20,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.*;
@Component
@ -28,7 +30,7 @@ public class DataSearchService {
    private Logger logger = LoggerFactory.getLogger(DataSearchService.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    private ElasticSearchHelper elasticSearchHelper;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
@ -36,12 +38,12 @@ public class DataSearchService {
//    @Autowired
//    private HBaseHelper hBaseHelper;
    public String getData(String jsonData){
    public String getData(String jsonData) throws IOException {
        logger.info("load data from elasticsearch start:" + org.apache.http.client.utils.DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss));
        JSONObject resultJsonObj = new JSONObject();
        JSONArray  resultArray = new JSONArray();
        SearchSourceBuilder query = elasticSearchQueryGenerator.getQueryBuilder("data",jsonData);
        SearchResult esResult = elastricSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,query.toString());
        SearchResult esResult = elasticSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,query.toString());
        if(esResult.getTotal() == 0){
            return "";
        }
@ -78,7 +80,7 @@ public class DataSearchService {
     * @param json
     * @return
     */
    public String updateData(String json) {
    public String updateData(String json) throws IOException {
        JSONObject params = JSONObject.parseObject(json);
        //拿到rid,构造通用查询结构,查询对应es Id
        String rid = params.getString("rid");
@ -95,7 +97,7 @@ public class DataSearchService {
        String _id = "";
        try {
            //将该rid的文档取出来
            SearchResult searchResult = elastricSearchHelper.search(ConstantUtils.esIndex, ConstantUtils.esType, queryString.toString());
            SearchResult searchResult = elasticSearchHelper.search(ConstantUtils.esIndex, ConstantUtils.esType, queryString.toString());
            params.remove("rid");
            _id = getEsId(searchResult.getJsonString());
            String resultSource = searchResult.getSourceAsString();
@ -121,7 +123,7 @@ public class DataSearchService {
//        boolean bool = elastricSearchHelper.update(ConstantUtils.esIndex, ConstantUtils.esType, _id, updateObj.toJSONString());
//        Update update = new Update();
//        update.
        boolean bool = elastricSearchHelper.update(ConstantUtils.esIndex, ConstantUtils.esType, _id, resultObject);
        boolean bool = elasticSearchHelper.update(ConstantUtils.esIndex, ConstantUtils.esType, _id, resultObject);
        return String.valueOf(bool);
    }
@ -191,11 +193,11 @@ public class DataSearchService {
     * @param jsonData
     * @return
     */
    public List<DataBodySignsVO> getDataToBean(String jsonData){
    public List<DataBodySignsVO> getDataToBean(String jsonData) throws IOException {
        List<DataBodySignsVO> result = new ArrayList<>();
        logger.info("load data from elasticsearch start:" + org.apache.http.client.utils.DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss));
        SearchSourceBuilder query = elasticSearchQueryGenerator.getQueryBuilder("data",jsonData);
        SearchResult esResult = elastricSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,query.toString());
        SearchResult esResult = elasticSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,query.toString());
        if(null== esResult || esResult.getTotal()==null || esResult.getTotal() == 0){
            return result;
        }
@ -212,14 +214,14 @@ public class DataSearchService {
     * @param json
     * @return
     */
    public List<WeRunDataVO> getWeRunDataList(String json){
    public List<WeRunDataVO> getWeRunDataList(String json) throws IOException {
        List<WeRunDataVO> result = new ArrayList<>();
        SearchSourceBuilder query = elasticSearchQueryGenerator.getQueryBuilder("stepInfoList",json);
        SearchResult esResult = elastricSearchHelper.search(ConstantUtils.weRunDataIndex,ConstantUtils.weRunDataType,query.toString());
        if(null != esResult && esResult.getTotal() == 0){
        SearchResult esResult = elasticSearchHelper.search(ConstantUtils.weRunDataIndex,ConstantUtils.weRunDataType,query.toString());
        if (null != esResult && esResult.getTotal() == 0){
            return result;
        }
        for(String str:esResult.getSourceAsStringList()){
        for (String str:esResult.getSourceAsStringList()){
            WeRunDataVO weRunDataVO = JSONObject.parseObject(str,WeRunDataVO.class);
            result.add(weRunDataVO);
        }

+ 19 - 18
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -1,7 +1,7 @@
package com.yihu.iot.service.device;
import com.alibaba.fastjson.JSONObject;
import com.yihu.elasticsearch.jest.ElastricSearchHelper;
import com.yihu.elasticsearch.ElasticSearchHelper;
import com.yihu.iot.dao.device.IotPatientDeviceDao;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
@ -21,19 +21,20 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.*;
/**
 * @author yeshijie on 2018/1/16.
 */
@Service
public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,IotPatientDeviceDao> {
public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO, IotPatientDeviceDao> {
    private Logger logger = LoggerFactory.getLogger(IotPatientDeviceService.class);
    @Autowired
    private IotPatientDeviceDao iotPatientDeviceDao;
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    private ElasticSearchHelper elasticSearchHelper;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
@ -86,7 +87,7 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
            logger.info("地址:," + deviceVO.getAddress() + "坐标" + json.toString());
            dataDTO.setLocation(Double.valueOf(json.get("lat")), Double.valueOf(json.get("lng")));
//            dataDTOs.add(dataDTO);
            elastricSearchHelper.save(ConstantUtils.deviceLocationIndex, ConstantUtils.deviceLocationType,JSONObject.toJSONString(dataDTO));
            elasticSearchHelper.save(ConstantUtils.deviceLocationIndex, ConstantUtils.deviceLocationType,JSONObject.toJSONString(dataDTO));
        } catch (Exception e) {
            e.printStackTrace();
        }
@ -179,9 +180,9 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
     * 查询所有设备地址
     * @return
     */
    public List<LocationDataVO> findAllDeviceLocations(){
    public List<LocationDataVO> findAllDeviceLocations() throws IOException {
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryAllBuilder();
        JestResult esResult = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        JestResult esResult = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        return getESResultBeanList(esResult);
    }
@ -189,9 +190,9 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
     * 根据居民绑定的idCard查询设备地址
     * @return
     */
    public List<LocationDataVO> findDeviceLocationsByIdCard(String jsonData){
    public List<LocationDataVO> findDeviceLocationsByIdCard(String jsonData) throws IOException {
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        JestResult esResult = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        JestResult esResult = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        return getESResultBeanList(esResult);
    }
@ -199,9 +200,9 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
     * 根据设备SN码查询设备地址
     * @return
     */
    public List<LocationDataVO> findDeviceLocationsBySn(String jsonData){
    public List<LocationDataVO> findDeviceLocationsBySn(String jsonData) throws IOException {
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        JestResult esResult = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        JestResult esResult = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        return getESResultBeanList(esResult);
    }
@ -222,10 +223,10 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
     * 设备解绑,根据Sn或idCard删除地址
     * @return
     */
    public boolean deleteLocationsByIdcardOrSn(String jsonData){
    public boolean deleteLocationsByIdcardOrSn(String jsonData) throws IOException {
        List<Map<String,Object>> idList = new ArrayList<>();
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        JestResult esResult = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        JestResult esResult = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        List<LocationDataVO> resultList = getESResultBeanList(esResult);
        for(LocationDataVO locationDataVO : resultList){
                Map<String,Object> map = new HashMap<>();
@ -234,7 +235,7 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
        }
        boolean bool = true;
        try {
            elastricSearchHelper.delete(ConstantUtils.deviceLocationIndex, ConstantUtils.deviceLocationType, idList);
            elasticSearchHelper.delete(ConstantUtils.deviceLocationIndex, ConstantUtils.deviceLocationType, idList);
        }catch (Exception e){
            bool = false;
        }
@ -247,17 +248,17 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
     * 设备地址修改,根据Sn或idCard修改地址
     * @return
     */
    public boolean updateLocationsByIdcardOrSn(String jsonData){
    public boolean updateLocationsByIdcardOrSn(String jsonData) throws IOException {
        List<Map<String,Object>> idList = new ArrayList<>();
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        JestResult esResult = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        JestResult esResult = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        List<LocationDataVO> resultList = getESResultBeanList(esResult);
        for(LocationDataVO locationDataVO : resultList){
            Map<String,Object> map = new HashMap<>();
            map.put("_id",locationDataVO.getId());
            idList.add(map);
        }
        boolean bool = elastricSearchHelper.updateByMap(ConstantUtils.deviceLocationIndex, ConstantUtils.deviceLocationType,idList);
        boolean bool = elasticSearchHelper.updateByMap(ConstantUtils.deviceLocationIndex, ConstantUtils.deviceLocationType,idList);
        return bool;
    }
@ -266,10 +267,10 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
     * @param jsonData
     * @return
     */
    public int getESCount(String jsonData){
    public int getESCount(String jsonData)throws IOException {
        int count = 0;
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        io.searchbox.core.SearchResult result = elastricSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        io.searchbox.core.SearchResult result = elasticSearchHelper.search(ConstantUtils.deviceLocationIndex,ConstantUtils.deviceLocationType,queryStr.toString());
        count = result.getTotal();
        return count;
    }

+ 7 - 13
svr/svr-iot/src/main/java/com/yihu/iot/service/label/FigureLabelSerachService.java

@ -2,8 +2,7 @@ package com.yihu.iot.service.label;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.elasticsearch.jest.ElasticFactory;
import com.yihu.elasticsearch.jest.ElastricSearchHelper;
import com.yihu.elasticsearch.ElasticSearchHelper;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import io.searchbox.client.JestClient;
@ -17,6 +16,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@ -30,20 +30,18 @@ public class FigureLabelSerachService implements Serializable {
    private Logger logger = LoggerFactory.getLogger(FigureLabelSerachService.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    private ElasticFactory elasticFactory;
    private ElasticSearchHelper elastricSearchHelper;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
    @Autowired
    private JestClient jestClient;
    /**
     * 查询标签
     * @param list
     */
    public void getFigureLabelByList(List<LocationDataVO> list){
        JestClient jestClient = null;
        try {
            jestClient = this.elasticFactory.getJestClient();
            for (LocationDataVO one:list) {
                JSONArray jsonArray = new JSONArray();
                JSONObject json = new JSONObject();
@ -79,10 +77,6 @@ public class FigureLabelSerachService implements Serializable {
            }
        } catch (Exception var10) {
            var10.printStackTrace();
        } finally {
            if(jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
@ -110,7 +104,7 @@ public class FigureLabelSerachService implements Serializable {
     * @param json
     * @return
     */
    public List<FigureLabelDataModelVO> getFigureLabelByIdcard(String json){
    public List<FigureLabelDataModelVO> getFigureLabelByIdcard(String json) throws IOException {
        List<FigureLabelDataModelVO> list = new ArrayList<>();
        if(!json.contains("idcard")){
            logger.error("invalid elasticserach query condition,no parameter [idcard]!");
@ -130,7 +124,7 @@ public class FigureLabelSerachService implements Serializable {
     * @param json
     * @return
     */
    public List<FigureLabelDataModelVO> getFigureLabelByLabel(String json){
    public List<FigureLabelDataModelVO> getFigureLabelByLabel(String json) throws IOException {
        List<FigureLabelDataModelVO> list = new ArrayList<>();
        if(!json.contains("labelType") || !json.contains("labelCode")){
            logger.error("invalid elasticserach query condition,no parameter [labelType] or [labelCode]!");

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

@ -5,7 +5,6 @@ server:
spring:
  jmx:
    default-domain: svr-iot
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    max-active: 50
@ -23,20 +22,14 @@ spring:
    test-while-idle: true #指明连接是否被空闲连接回收器(如果有)进行检验,如果检测失败,则连接将被从池中去除
    min-evictable-idle-time-millis: 3600000 #连接池中连接,在时间段内一直空闲,被逐出连接池的时间(1000*60*60),以毫秒为单位
    time-between-eviction-runs-millis: 300000 #在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位,一般比minEvictableIdleTimeMillis小
  data:
    elasticsearch: #ElasticsearchProperties
      cluster-name: jkzl #默认即为elasticsearch  集群名
      cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      cluster-nodes-jest: http://172.19.103.45:9200,http://172.19.103.68:9200  #多个逗号分割
      local: false #是否本地连接
      properties: # Additional properties used to configure the client.
        enable: true
  # JEST (Elasticsearch HTTP client) (JestProperties)
  # Elasticsearch Transport
  elasticsearch:
    cluster-name: jkzl #默认即为elasticsearch  集群名
    cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
    client-transport-sniff: false
    # JEST (Elasticsearch HTTP client) (JestProperties)
    jest:
      uris: http://172.19.103.45:9200,http://172.19.103.68:9200
#      uris: http://172.19.103.68:9200
      connection-timeout: 60000 # Connection timeout in milliseconds.
      multi-threaded: true # Enable connection requests from multiple execution threads.
#      username: # Login user.
@ -74,12 +67,9 @@ fast-dfs:
#  user:
#    name: root
---
spring:
  profiles: jwdev
  datasource:
    url: jdbc:mysql://172.19.103.77:3306/xmiot?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
    username: root