Browse Source

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

yeshijie 7 years ago
parent
commit
5b659d8e08

+ 100 - 0
common/common-entity/src/main/java/com/yihu/jw/iot/device/LocationDataDO.java

@ -0,0 +1,100 @@
package com.yihu.jw.iot.device;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.searchbox.annotations.JestId;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import java.util.Date;
/**
 * Created by chenweida on 2018/2/12.
 */
public class LocationDataDO {
    @JestId
    private String id;
    private String idCard; //设备绑定身份证
    private String deviceSn;//设备SnID
    private String categoryCode;//设备类型标识
    @GeoPointField
    private GeoPoint location;//经纬度
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXX")
    @JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXX")
    private Date deviceTime;//设备绑定时间
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXX")
    @JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXX")
    private Date createTime;  // 创建时间(ES:必填)
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getIdCard() {
        return idCard;
    }
    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public GeoPoint getLocation() {
        return location;
    }
    public void setLocation(GeoPoint location) {
        this.location = location;
    }
    public Date getDeviceTime() {
        return deviceTime;
    }
    public void setDeviceTime(Date deviceTime) {
        this.deviceTime = deviceTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public void setLocation(Double lat, Double lng) {
        GeoPoint geoPoint = new GeoPoint(lat, lng);
        this.location = geoPoint;
    }
}

+ 20 - 1
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotPatientDeviceVO.java

@ -12,7 +12,7 @@ import java.io.Serializable;
 * @author yeshijie on 2018/1/16.
 */
@JsonInclude(JsonInclude.Include.ALWAYS)
@ApiModel(value = "设备质检计划表", description = "设备质检计划表")
@ApiModel(value = "居民设备绑定表", description = "居民设备绑定表")
public class IotPatientDeviceVO extends BaseVO implements Serializable {
    @ApiModelProperty("居民code")
@ -33,6 +33,10 @@ public class IotPatientDeviceVO extends BaseVO implements Serializable {
    private String agent;
    @ApiModelProperty("按键号")
    private String userType;
    @ApiModelProperty("设备类型标识(1血压计,2血糖仪)")
    private String categoryCode;
    @ApiModelProperty("地址")
    private String address;
    public String getPatient() {
        return patient;
@ -106,4 +110,19 @@ public class IotPatientDeviceVO extends BaseVO implements Serializable {
        this.userType = userType;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
}

+ 80 - 0
common/common-util/src/main/java/com/yihu/jw/util/common/LatitudeUtils.java

@ -0,0 +1,80 @@
package com.yihu.jw.util.common;
import org.springframework.util.StringUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class LatitudeUtils {
    public static final String KEY_1 = "7d9fbeb43e975cd1e9477a7e5d5e192a";
    /**
     * 返回输入地址的经纬度坐标
     * key lng(经度),lat(纬度)
     */
    public static Map<String,String> getGeocoderLatitude(String address){
        BufferedReader in = null;
        try {
            //将地址转换成utf-8的16进制
            address = URLEncoder.encode(address, "UTF-8");
            URL tirc = new URL("http://api.map.baidu.com/geocoder?address="+ address +"&output=json&key="+ UUID.randomUUID().toString().replace("-",""));
            in = new BufferedReader(new InputStreamReader(tirc.openStream(),"UTF-8"));
            String res;
            StringBuilder sb = new StringBuilder("");
            while((res = in.readLine())!=null){
                sb.append(res.trim());
            }
            String str = sb.toString();
            Map<String,String> map = null;
            if(!StringUtils.isEmpty(str)){
                int lngStart = str.indexOf("lng\":");
                int lngEnd = str.indexOf(",\"lat");
                int latEnd = str.indexOf("},\"precise");
                if(lngStart > 0 && lngEnd > 0 && latEnd > 0){
                    String lng = str.substring(lngStart+5, lngEnd);
                    String lat = str.substring(lngEnd+7, latEnd);
                    map = new HashMap<String,String>();
                    map.put("lng", lng);
                    map.put("lat", lat);
                    return map;
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
//    public static void main(String args[]){
//        try {
//            Map<String, String> json = LatitudeUtils.getGeocoderLatitude("浦东区张杨路1725号");
//            System.out.println("经度 : " + json.get("lng"));
//            System.out.println("纬度 : " + json.get("lat"));
//        }catch (Exception e ){
//            e.printStackTrace();
//        }
//    }
}

+ 5 - 3
server/svr-configuration/src/main/resources/bootstrap.yml

@ -35,8 +35,9 @@ spring:
      failFast: true #启动快速失败 即链接不到配置服务就启动失败
      server:
        git:
          uri: http://192.168.1.220:10080/jiwei/jw.config.git
        default-label: master
#         uri: http://192.168.1.220:10080/jiwei/jw.config.git
         uri: http://192.168.1.220:10080/jiwei/jw.config.git
        default-label: jwdev
---
@ -48,7 +49,8 @@ spring:
      failFast: true #启动快速失败 即链接不到配置服务就启动失败
      server:
        git:
          uri: http://192.168.1.220:10080/jiwei/jw.config.git
#          uri: http://192.168.1.220:10080/EHR/ehr.config.git
          uri: http://192.168.1.220:10080/chenyongxing/jw.config.git
        default-label: master
---

+ 4 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotPatientDeviceController.java

@ -34,8 +34,12 @@ public class IotPatientDeviceController extends EnvelopRestController{
    public Envelop<IotPatientDeviceVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                                       @RequestParam String jsonData) {
        try {
            //设备绑定
            IotPatientDeviceDO patientDevice = toEntity(jsonData, IotPatientDeviceDO.class);
            iotPatientDeviceService.create(patientDevice);
            //地址信息存入es
            IotPatientDeviceVO deviceVO = toEntity(jsonData, IotPatientDeviceVO.class);
            iotPatientDeviceService.deviceData2Es(deviceVO);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_create);
        } catch (Exception e) {
            e.printStackTrace();

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

@ -16,4 +16,8 @@ public class ConstantUtils {
    //微信运动数据es类型
    public static String weRunDataType = "step_data";
    //设备坐标es索引
    public static String deviceLocationIndex = "device_location_index";
    //设备坐标es类型
    public static String deviceLocationType = "device_location_type";
}

+ 44 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -1,13 +1,24 @@
package com.yihu.iot.service.device;
import com.alibaba.fastjson.JSONObject;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.iot.dao.device.IotPatientDeviceDao;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.jw.iot.device.IotPatientDeviceDO;
import com.yihu.jw.iot.device.LocationDataDO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
import com.yihu.jw.util.common.LatitudeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2018/1/16.
@ -15,8 +26,11 @@ import java.util.List;
@Service
public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,IotPatientDeviceDao> {
    private Logger logger = LoggerFactory.getLogger(IotPatientDeviceService.class);
    @Autowired
    private IotPatientDeviceDao iotPatientDeviceDao;
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    /**
     * 新增
@ -30,6 +44,36 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,I
        return iotPatientDeviceDao.save(patientDevice);
    }
    /**
     * 设备绑定时 把坐标信息存入es
     * @param deviceVO
     */
    public void deviceData2Es(IotPatientDeviceVO deviceVO) {
        try {
            if (StringUtils.isEmpty(deviceVO.getAddress())) {
                return;
            }
//            List<LocationDataDO> dataDTOs = new ArrayList<>();
            LocationDataDO dataDTO = new LocationDataDO();
            dataDTO.setCreateTime(new Date());
            dataDTO.setDeviceTime(new Date());
            dataDTO.setCategoryCode(deviceVO.getCategoryCode());
            dataDTO.setDeviceSn(deviceVO.getDeviceSn());
            dataDTO.setIdCard(deviceVO.getIdcard());
            Map<String, String> json = LatitudeUtils.getGeocoderLatitude(deviceVO.getAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
            if (json == null) {
                return;
            }
            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));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 按id查找
     * @param id

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

@ -27,14 +27,14 @@ spring:
  data:
    elasticsearch: #ElasticsearchProperties
      cluster-name: jkzl #默认即为elasticsearch  集群名
      cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      cluster-nodes: 172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
      local: false #是否本地连接
      properties: # Additional properties used to configure the client.
        enable: true
  # JEST (Elasticsearch HTTP client) (JestProperties)
  elasticsearch:
    jest:
      uris: http://172.19.103.45:9200,http://172.19.103.68:9200
      uris: 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.