Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/jiwei/wlyy2.0 into dev

yeshijie 7 years ago
parent
commit
29a5163dc6

+ 8 - 2
app/app-iot-server/pom.xml

@ -29,12 +29,12 @@
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-core</artifactId>
@ -75,7 +75,7 @@
        </dependency>
        <dependency>
        <!--<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
@ -93,7 +93,13 @@
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>4.0.0.RELEASE</version>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-extras</artifactId>

+ 0 - 2
app/app-iot-server/src/main/resources/application.yml

@ -24,8 +24,6 @@ spring:
    static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/front/,classpath:/
#    cache-period: 0
permissions:
  info: admin

+ 5 - 0
common/common-entity/pom.xml

@ -46,6 +46,11 @@
            <artifactId>jest-common</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>2.1.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-es</artifactId>

+ 12 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java

@ -21,6 +21,7 @@ public class IotRequestMapping {
        public static final String quality = api_iot_common + "/quality";
        public static final String patientDevice = api_iot_common + "/patientDevice";
        public static final String wlyy = api_iot_common + "/wlyy";
        public static final String figereLabel = api_iot_common + "/figereLabel";
        public static final String message_success_update = "update success";
@ -265,4 +266,15 @@ public class IotRequestMapping {
    }
    /**
     * 居民标签信息模块常量
     */
    public static class FigureLabelInfo{
        public static final String api_getByIdcard = "getLabelByIdcard";
        public static final String api_getByTypeAndCode = "getLabelByTypeAndCode";
        public static final String message_success_find = "FigureLabelInfo find success";
    }
}

+ 90 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/FigureLabelDataModelVO.java

@ -0,0 +1,90 @@
package com.yihu.jw.restmodel.iot.device;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.searchbox.annotations.JestId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "居民标签信息", description = "居民标签信息")
public class FigureLabelDataModelVO {
    //es ID
    @JestId
    private String id;
    @ApiModelProperty("身份证")
    private String idcard;
    @ApiModelProperty("标签类型")
    private String labelType;
    @ApiModelProperty("标签code")
    private String labelCode;
    @ApiModelProperty("标签名称")
    private String labeName;
    @ApiModelProperty("标签值,仅当标签只有一个分类的时候才有此值,比如生日,体重等")
    private String labelValue;
    @ApiModelProperty("创建时间")
    private String createTime;
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
    public String getLabelType() {
        return labelType;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }
    public String getLabelCode() {
        return labelCode;
    }
    public void setLabelCode(String labelCode) {
        this.labelCode = labelCode;
    }
    public String getLabeName() {
        return labeName;
    }
    public void setLabeName(String labeName) {
        this.labeName = labeName;
    }
    public String getLabelValue() {
        return labelValue;
    }
    public void setLabelValue(String labelValue) {
        this.labelValue = labelValue;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
}

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

@ -133,11 +133,12 @@
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <dependency>
        <!--暂时环境不用hbase,先注释掉-->
       <!-- <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-hbase</artifactId>
            <version>1.0.0</version>
        </dependency>
        </dependency>-->
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-es-starter</artifactId>

+ 51 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/label/FigureLabelSearchController.java

@ -0,0 +1,51 @@
package com.yihu.iot.controller.label;
import com.yihu.iot.service.label.FigureLabelSerachService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.iot.device.FigureLabelDataModelVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
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.*;
import java.util.List;
/**
 * @author lith on 2018/03/16
 */
@RestController
@RequestMapping(IotRequestMapping.Common.figereLabel)
@Api(tags = "居民标签查询控制器", description = "居民标签查询控制器")
public class FigureLabelSearchController extends EnvelopRestController {
    @Autowired
    private FigureLabelSerachService figureLabelSerachService;
    @PostMapping(value = IotRequestMapping.FigureLabelInfo.api_getByIdcard,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据idcard查询居民标签", notes = "根据idcard查询居民标签")
    public Envelop<List<FigureLabelDataModelVO>> findByIdcard(@ApiParam(name = "jsonData", value = "", defaultValue = "") @RequestBody String jsonData) {
        try {
            return Envelop.getSuccess(IotRequestMapping.FigureLabelInfo.message_success_find, figureLabelSerachService.getFigureLabelByIdcard(jsonData));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = IotRequestMapping.FigureLabelInfo.api_getByTypeAndCode,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据type和code居民标签", notes = "根据type和code居民标签")
    public Envelop<List<FigureLabelDataModelVO>> findByTypeAndCode(@ApiParam(name = "jsonData", value = "", defaultValue = "") @RequestBody String jsonData) {
        try {
            return Envelop.getSuccess(IotRequestMapping.FigureLabelInfo.message_success_find, figureLabelSerachService.getFigureLabelByLabel(jsonData));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

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

@ -4,8 +4,8 @@ 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.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;
@ -15,8 +15,9 @@ import com.yihu.jw.iot.datainput.WeRunDataDO;
import com.yihu.jw.iot.device.IotDeviceDO;
import com.yihu.jw.restmodel.iot.datainput.WeRunDataVO;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hbase.util.CollectionUtils;
//import org.apache.hadoop.hbase.util.CollectionUtils;
import org.apache.http.client.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,11 +45,10 @@ public class DataInputService {
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    private HBaseHelper hBaseHelper;
    @Autowired
    private HBaseAdmin hBaseAdmin;
//    @Autowired
//    private HBaseHelper hBaseHelper;
//    @Autowired
//    private HBaseAdmin hBaseAdmin;
    /**
     * 居民设备注册及绑定
@ -191,11 +191,11 @@ public class DataInputService {
        elastricSearchHelper.save(ConstantUtils.esIndex, ConstantUtils.esType, jsonObject.toJSONString());
        try {
            boolean tableExists = hBaseAdmin.isTableExists(ConstantUtils.tableName);
            if (!tableExists) {
                hBaseAdmin.createTable(ConstantUtils.tableName,ConstantUtils.familyB);
            }
            hBaseHelper.addBulk(ConstantUtils.tableName, rowkeyList, familyList);
//            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();
            //保存日志

+ 8 - 8
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.es.config.ElastricSearchHelper;
import com.yihu.base.hbase.HBaseHelper;
//import com.yihu.base.hbase.HBaseHelper;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.datainput.util.RowKeyUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
@ -12,9 +12,9 @@ import com.yihu.jw.restmodel.iot.datainput.WeRunDataVO;
import com.yihu.jw.util.date.DateUtil;
import io.searchbox.core.SearchResult;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
//import org.apache.hadoop.hbase.Cell;
//import org.apache.hadoop.hbase.client.Result;
//import org.apache.hadoop.hbase.util.Bytes;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,8 +33,8 @@ public class DataSearchService {
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
    @Autowired
    private HBaseHelper hBaseHelper;
//    @Autowired
//    private HBaseHelper hBaseHelper;
    public String getData(String jsonData){
        logger.info("load data from elasticsearch start:" + org.apache.http.client.utils.DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss));
@ -142,7 +142,7 @@ public class DataSearchService {
     * @param esResult
     * @return
     */
    public String getDataFromHbase(List<String> rowkeys,SearchResult esResult){
   /* public String getDataFromHbase(List<String> rowkeys,SearchResult esResult){
        long time = System.currentTimeMillis();
        logger.info("load data from hbase start:" + org.apache.http.client.utils.DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss));
        JSONObject resultJsonObj = new JSONObject();
@ -184,7 +184,7 @@ public class DataSearchService {
        long count = System.currentTimeMillis() - time;
        logger.info("load data from hbase end:" + org.apache.http.client.utils.DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss) + ",count: " + count);
        return resultJsonObj.toJSONString();
    }
    }*/
    /**
     * 体征数据查询,数据转为视图展示VO类

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

@ -20,4 +20,9 @@ public class ConstantUtils {
    public static String deviceLocationIndex = "device_location_index";
    //设备坐标es类型
    public static String deviceLocationType = "device_location_type";
    //居民标签es索引
    public static String figureLabelIndex = "figure_label_index";
    //居民标签es类型
    public static String figureLabelType = "figure_label_type";
}

+ 3 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/common/ElasticSearchQueryGenerator.java

@ -7,8 +7,9 @@ import com.yihu.iot.datainput.enums.DataTypeEnum;
import com.yihu.iot.datainput.service.DataStandardConvertService;
import com.yihu.jw.iot.datainput.Data;
import com.yihu.jw.iot.datainput.StepInfoDO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hbase.util.CollectionUtils;
//import org.apache.hadoop.hbase.util.CollectionUtils;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
@ -76,7 +77,7 @@ public class ElasticSearchQueryGenerator {
        searchSourceBuilder.from((page -1)*size);
        searchSourceBuilder.size(size);
        //排序
        if(CollectionUtils.notEmpty(sort)){
        if(!CollectionUtils.isEmpty(sort)){
            for(Object obj:sort){
                JSONObject object = JSONObject.parseObject(obj.toString());
                FieldSortBuilder fieldSortBuilder = null;

+ 74 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/label/FigureLabelSerachService.java

@ -0,0 +1,74 @@
package com.yihu.iot.service.label;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import com.yihu.jw.restmodel.iot.device.FigureLabelDataModelVO;
import io.searchbox.client.JestResult;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
 * @author lith on 2018/03/16
 */
@Service
public class FigureLabelSerachService implements Serializable {
    private Logger logger = LoggerFactory.getLogger(FigureLabelSerachService.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
    /**
     *根据idcard查询标签
     * @param json
     * @return
     */
    public List<FigureLabelDataModelVO> getFigureLabelByIdcard(String json){
        List<FigureLabelDataModelVO> list = new ArrayList<>();
        if(!json.contains("idcard")){
            logger.error("invalid elasticserach query condition,no parameter [idcard]!");
            return list;
        }
        JSONObject jsonObject = JSONObject.parseObject(json);
        //elasticsearch 默认查询上限为10000条,但是我们根据条件查询,不知道数据会有几条,此处给最大值
        jsonObject.put("size",10000);
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonObject.toJSONString());
        JestResult jestResult = elastricSearchHelper.search(ConstantUtils.figureLabelIndex,ConstantUtils.figureLabelType,queryStr.toString());
        list = jestResult.getSourceAsObjectList(FigureLabelDataModelVO.class);
        return list;
    }
    /**
     * 根据标签类型和标签code查询标签
     * @param json
     * @return
     */
    public List<FigureLabelDataModelVO> getFigureLabelByLabel(String json){
        List<FigureLabelDataModelVO> list = new ArrayList<>();
        if(!json.contains("labelType") || !json.contains("labelCode")){
            logger.error("invalid elasticserach query condition,no parameter [labelType] or [labelCode]!");
            return list;
        }
        JSONObject jsonObject = JSONObject.parseObject(json);
        //elasticsearch 默认查询上限为10000条,但是我们根据条件查询,不知道数据会有几条,此处给最大值
        jsonObject.put("size",10000);
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonObject.toJSONString());
        JestResult jestResult = elastricSearchHelper.search(ConstantUtils.figureLabelIndex,ConstantUtils.figureLabelType,queryStr.toString());
        list = jestResult.getSourceAsObjectList(FigureLabelDataModelVO.class);
        return list;
    }
}

+ 8 - 8
svr/svr-iot/src/main/resources/application.yml

@ -66,14 +66,14 @@ fast-dfs:
    max-size: 20
    wait-time: 500
hadoop:
  hbase-properties:
    hbase.zookeeper.property.clientPort: 2181
    zookeeper.znode.parent: /hbase-unsecure
    hbase.zookeeper.quorum:  node1.hde.h3c.com,node2.hde.h3c.com,node3.hde.h3c.com
  user:
    name: root
#暂时先不用hbase,先注释掉
#hadoop:
#  hbase-properties:
#    hbase.zookeeper.property.clientPort: 2181
#    zookeeper.znode.parent: /hbase-unsecure
#    hbase.zookeeper.quorum:  node1.hde.h3c.com,node2.hde.h3c.com,node3.hde.h3c.com
#  user:
#    name: root