Forráskód Böngészése

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

叶仕杰 4 éve
szülő
commit
575525585a

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

@ -62,6 +62,8 @@ public class IotRequestMapping {
        public static final String bindUser = "bindUser";
        public static final String inputWeRunData = "inputWeRunData";
        public static final String uploadData = "uploadData";
        public static final String updateData = "updateData";
        public static final String deleteData = "deleteData";
    }
    /**

+ 12 - 2
svr/svr-iot/src/main/java/com/yihu/iot/controller/analyzer/IotAnalyzerController.java

@ -44,9 +44,9 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
     * @param jsonData
     * @return
     */
    @PostMapping(value = "/yitouxiaowu" ,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping(value = "/open/yitouxiaowu" ,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "奕拓体征数据解析入库", notes = "奕拓体征数据解析入库")
    public String updateDeviceData(
    public String yitouxiaowu(
            @ApiParam(name = "json_data", value = "Json数据", required = true)
            @RequestBody String jsonData)throws Exception {
@ -69,7 +69,17 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
            logger.info( "-------------- 体征数据入库失败~~!--------------- ");
            return strResult;
        }
    }
    @PostMapping(value = "/open/initIntoEs" ,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "初始化把奕拓小屋数据存入es", notes = "初始化把奕拓小屋数据存入es")
    public String initIntoEs(){
        try{
            iotAnalyzerService.initIntoEs();
        }catch (Exception e){
            e.printStackTrace();
        }
        return "success";
    }
}

+ 21 - 1
svr/svr-iot/src/main/java/com/yihu/iot/controller/third/ThirdDataInputController.java

@ -3,6 +3,7 @@ package com.yihu.iot.controller.third;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.aop.IntefaceLogRequired;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.iot.datainput.service.DataSearchService;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.restmodel.web.MixEnvelop;
@ -11,8 +12,8 @@ import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -27,6 +28,8 @@ public class ThirdDataInputController {
    @Autowired
    private DataInputService dataInputService;
    @Autowired
    private DataSearchService dataSearchService;
    @PostMapping(value = IotRequestMapping.ThirdOpen.bindUser)
    @ApiOperation(value = "设备注册绑定", notes = "设备注册并绑定用户")
@ -38,6 +41,23 @@ public class ThirdDataInputController {
        }
    }
    @PostMapping(value = IotRequestMapping.ThirdOpen.updateData)
    @ApiOperation(value = "更新体征记录", notes = "根据id更新体征记录(包括体征值、上传时间等)")
    @IntefaceLogRequired
    public MixEnvelop updateData(
            @ApiParam(name = "jsonData", value = "", defaultValue = "")
            @RequestParam String jsonData) throws IOException {
        try{
            String str = dataSearchService.updateData(jsonData);
            if(!StringUtils.equalsIgnoreCase("true",str)){
                return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.message_fail,str);
            }
            return MixEnvelop.getSuccess(DataRequestMapping.DataSearch.update_success,str);
        } catch (ApiException e){
            return MixEnvelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = IotRequestMapping.ThirdOpen.uploadData)
    @ApiOperation(value = "体征数据上传", notes = "数据上传入库")
    @IntefaceLogRequired

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

@ -1,5 +1,6 @@
package com.yihu.iot.datainput.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.iot.datainput.util.ConstantUtils;
@ -12,10 +13,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
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.RestController;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@ -27,6 +25,25 @@ public class DataInputController {
    @Autowired
    private DataInputService dataInputService;
    @PostMapping(value = "open/deleteEsByCondition")
    @ApiOperation(value = "删除es数据", notes = "删除es数据")
    public MixEnvelop deleteEsByCondition(@ApiParam(name = "jsonData", value = "", defaultValue = "{\"filter\":[{\"andOr\":\"and\",\"condition\":\"=\",\"field\":\"access_token\",\"value\":\"iHealth\"}]}") @RequestParam String jsonData){
        try{
            return MixEnvelop.getSuccess(DataRequestMapping.DataInput.message_success,dataInputService.deleteEsByCondition(jsonData));
        } catch (Exception e){
            return MixEnvelop.getError(e.getMessage());
        }
    }
    private void field(String andOr,String field,String condition,String value,JSONArray jsonArray){
        JSONObject json = new JSONObject();
        json.put("andOr",andOr);
        json.put("field",field);
        json.put("condition",condition);
        json.put("value",value);
        jsonArray.add(json);
    }
    @PostMapping(value = DataRequestMapping.DataInput.api_user_bind, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "设备注册绑定", notes = "设备注册并绑定用户")
    public MixEnvelop bindUser(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){

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

@ -2,20 +2,20 @@ package com.yihu.iot.datainput.service;
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.ElasticSearchHelper;
import com.yihu.iot.datainput.enums.DataOperationTypeEnum;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.datainput.util.RowKeyUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import com.yihu.iot.service.device.IotDeviceService;
import com.yihu.jw.datainput.DataBodySignsDO;
import com.yihu.jw.datainput.WeRunDataDO;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
import com.yihu.jw.util.date.DateUtil;
import io.searchbox.client.JestResult;
import org.apache.commons.lang.StringUtils;
//import org.apache.hadoop.hbase.util.CollectionUtils;
import org.apache.http.client.utils.DateUtils;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -25,6 +25,10 @@ import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.*;
//import com.yihu.base.hbase.HBaseAdmin;
//import com.yihu.base.hbase.HBaseHelper;
//import org.apache.hadoop.hbase.util.CollectionUtils;
/**
 * 1、设备注册及绑定
 * 2、不含居民身份的数据上传协议
@ -40,7 +44,8 @@ public class DataInputService {
    @Autowired
    private DataProcessLogService dataProcessLogService;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
    @Autowired
    private ElasticSearchHelper elasticSearchHelper;
@ -212,6 +217,42 @@ public class DataInputService {
        return result.toJSONString();
    }
    /**
     * 删除es指定数据
     * @return
     */
    public boolean deleteEsByCondition(String jsonData) throws IOException {
        List<Map<String,Object>> idList = new ArrayList<>();
        SearchSourceBuilder queryStr = elasticSearchQueryGenerator.getQueryBuilder("",jsonData);
        JestResult esResult = elasticSearchHelper.search(ConstantUtils.esIndex,ConstantUtils.esType,queryStr.toString());
        List<DataBodySignsDO> resultList = getESResultBeanList(esResult);
        for(DataBodySignsDO locationDataVO : resultList){
            Map<String,Object> map = new HashMap<>();
            map.put("id", locationDataVO.getId());
            idList.add(map);
        }
        boolean bool = true;
        try {
            elasticSearchHelper.delete(ConstantUtils.esIndex, ConstantUtils.esType, idList);
        }catch (Exception e){
            bool = false;
        }
        return bool;
    }
    /**
     * 返回对象集合
     * @param esResult
     * @return
     */
    private List<DataBodySignsDO> getESResultBeanList(JestResult esResult){
        List<DataBodySignsDO> resultList = new ArrayList<>();
        if(!esResult.isSucceeded()){
            return resultList;
        }
        return esResult.getSourceAsObjectList(DataBodySignsDO.class);
    }
    /**
     * 上传数据
     * @param json

+ 76 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/IotAnalyzerService.java

@ -4,14 +4,18 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.iot.service.common.MyJdbcTemplate;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
@ -31,6 +35,76 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
    private String accessToken = "yituoHouse";
    @Autowired
    ObjectMapper objectMapper;
    @Autowired
    private MyJdbcTemplate myJdbcTemplate;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 初始化把奕拓小屋数据存入es
     */
    public void initIntoEs(){
        String id = "";
        String sqlM = "SELECT * FROM wlyy_iot_m WHERE id >? and create_time is not null ORDER BY id limit 2";
        String sqlD = "SELECT * from wlyy_iot_d WHERE mid = ?";
        List<WlyyIotM> list = jdbcTemplate.query(sqlM, new Object[] {id}, new BeanPropertyRowMapper<>(WlyyIotM.class));
        while (list.size()>0){
            list.forEach(wlyyIotM->{
                List<WlyyIotD> wlyyIotDList = jdbcTemplate.query(sqlD, new Object[] {wlyyIotM.getId()}, new BeanPropertyRowMapper<>(WlyyIotD.class));
                JSONObject json = new JSONObject();
                json.put("sn", wlyyIotM.getSn());
                JSONObject ext_code = new JSONObject();
                ext_code.put("UnitNo",wlyyIotM.getUnitNo());
                ext_code.put("UnitName",wlyyIotM.getUnitName());
                ext_code.put("DoctorId",wlyyIotM.getDoctorId());
                ext_code.put("DoctorName",wlyyIotM.getDoctorName());
                ext_code.put("RecordNo",wlyyIotM.getRecordNo());
                ext_code.put("MacAddr",wlyyIotM.getMacAddr());
                json.put("ext_code",ext_code.toJSONString());
                json.put("device_name",wlyyIotM.getDeviceName());
                json.put("device_model",wlyyIotM.getDeviceModel());
                json.put("idcard",wlyyIotM.getIdCardNo());
                json.put("username",wlyyIotM.getUserName());
                json.put("access_token",accessToken);
                json.put("data_source",dataSource);
                Map<String,Map<String,Object>> map2 = new HashMap<String, Map<String, Object>>();
                for(WlyyIotD iotD:wlyyIotDList){
                    String value =  "EcgData".equals(iotD.getCode())?iotD.getContent():iotD.getValue();
                    if(map2.containsKey(iotD.getType())){
                        map2.get(iotD.getType()).put(iotD.getCode(),iotD.getValue());
                    }else{
                        Map<String,Object> map = new HashMap<>();
                        map.put(iotD.getCode(),iotD.getValue());
                        map2.put(iotD.getType(),map);
                    }
                }
                for (Map.Entry entry : map2.entrySet()) {
                    String code = entry.getKey().toString();
                    Map<String,Object> valueMap = (HashMap)entry.getValue();
                    JSONArray jsonArray = new JSONArray();
                    JSONObject js = new JSONObject();
                    js.put("measure_time",wlyyIotM.getMeasureTime());//测量时间
                    js.put("del",1);
                    js.put("status","0");
                    js.put("type",code);
                    analyzerMap(valueMap,js,code);
                    jsonArray.add(js);
                    json.put("data",jsonArray);
                    try {
                        dataInputService.inputBodySignsData(json.toJSONString());
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            });
            logger.info("初始化把奕拓小屋数据存入es,导入"+list.size()+"条,初始id:"+id);
            id = list.get(list.size()-1).getId();
            list = jdbcTemplate.query(sqlM, new Object[] {id}, new BeanPropertyRowMapper<>(WlyyIotM.class));
        }
    }
    /**
     * 针对上传的体数据进行基础数据的解析,进行主表数据的存储
@ -118,7 +192,7 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
                    LinkedHashMap valueMap = (LinkedHashMap)entry.getValue();
                    JSONArray jsonArray = new JSONArray();
                    JSONObject js = new JSONObject();
                    js.put("measure_time",code);//测量时间
                    js.put("measure_time",wlyyIotM.getMeasureTime());//测量时间
                    js.put("del",1);
                    js.put("status","0");
                    js.put("type",code);
@ -140,7 +214,7 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
        return o == null?"":o.toString();
    }
    public void analyzerMap(Map<String,Object> mapInfo,JSONObject js,String type)throws Exception{
    public void analyzerMap(Map<String,Object> mapInfo,JSONObject js,String type){
        int i = 0;
        for(Object o: mapInfo.values()){
            String value = o == null?"":o.toString();

+ 12 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/WlyyIotM.java

@ -6,6 +6,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "wlyy_iot_m")
@ -46,6 +47,9 @@ public class WlyyIotM extends UuidIdentityEntity implements Serializable {
    @Column(name = "mac_addr")
    private String macAddr;
    @Column(name = "create_time")
    private Date createTime;
    public String getSn() {
        return sn;
    }
@ -141,4 +145,12 @@ public class WlyyIotM extends UuidIdentityEntity implements Serializable {
    public void setMacAddr(String macAddr) {
        this.macAddr = macAddr;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}