Browse Source

奕拓小屋体征数据优化

hill9868 5 years ago
parent
commit
2209bec5ef

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

@ -11,7 +11,7 @@
    </parent>
    <groupId>com.yihu.iot</groupId>
    <artifactId>svr-iot</artifactId>
    <artifactId>svr-iot-third</artifactId>
    <version>${parent.version}</version>
    <packaging>war</packaging>
@ -42,23 +42,6 @@
        </dependency>
        <!-- 支持Tomcat启动 -->
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
@ -116,30 +99,15 @@
            <artifactId>mysql-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!--<dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-log</artifactId>
        </dependency>-->
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>fastdfs-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>elasticsearch-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!--<dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-es-starter</artifactId>
            <version>1.1.2</version>
        </dependency>-->
    </dependencies>
    <build>
        <finalName>svr-iot</finalName>
        <finalName>svr-iot-third</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
@ -154,5 +122,4 @@
            </plugin>
        </plugins>
    </build>
</project>

+ 23 - 1
svr/svr-iot/src/main/java/com/yihu/iot/controller/analyzer/IotAnalyzerController.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.analyzer.IotAnalyzerService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.date.DateUtil;
@ -37,8 +38,11 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
    @Autowired
    ObjectMapper objectMapper;
    @Autowired
    private IotAnalyzerService iotAnalyzerService;
    /**
     * 基于奕拓小屋上传的体征数据,进行解析入库
     * 基于奕拓小屋上传的体征数据,进行解析入库  V1.0 版本
     * @param jsonData
     * @return
     */
@ -725,6 +729,24 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
    }
    /**
     * 基于奕拓小屋上传的体征数据,进行解析入库  V2.0 版本
     * @param jsonData
     * @return
     */
    @PostMapping(value = "/yitouxiaowu2" ,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "奕拓体征数据解析入库", notes = "奕拓体征数据解析入库")
    public Envelop updateDeviceData(
            @ApiParam(name = "json_data", value = "Json数据", required = true)
            @RequestBody String jsonData)throws Exception {
        boolean res = iotAnalyzerService.analyzerMapM(jsonData);
        if(res){
            return success("体征数据上传成功");
        }else {
            return failed("体征数据上传失败");
        }
    }
}

+ 137 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/IotAnalyzerService.java

@ -0,0 +1,137 @@
package com.yihu.iot.service.analyzer;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
 * @author cws on 2019/6/16
 */
@Service
public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
    private Logger logger = LoggerFactory.getLogger(IotAnalyzerService.class);
    @Autowired
    private WlyyIotDDao wlyyIotDDao;
    @Autowired
    private WlyyIotMDao wlyyIotMDao;
    @Autowired
    ObjectMapper objectMapper;
    /**
     * 针对上传的体数据进行基础数据的解析,进行主表数据的存储
     * @param jsonData
     * @return
     * @throws Exception
     */
    public boolean analyzerMapM(String jsonData)throws Exception{
        WlyyIotM wlyyIotM = new WlyyIotM();
        boolean addFlag = false;
        String mid = "";
        //1-0 JSON 数据解析成 map 对象
        Map<String, Object> dataDetail = objectMapper.readValue(jsonData, HashMap.class);
        // 1-1 存储体征数据的基本信息
        LinkedHashMap memberMap = (LinkedHashMap)dataDetail.get("Member");
        wlyyIotM.setSn(dataDetail.get("MachineId") == null? "":dataDetail.get("MachineId").toString());
        wlyyIotM.setUnitNo(dataDetail.get("UnitNo") == null? "":dataDetail.get("UnitNo").toString());
        wlyyIotM.setUnitName(dataDetail.get("UnitName") == null? "":dataDetail.get("UnitName").toString());
        wlyyIotM.setDoctorId(dataDetail.get("DoctorId") == null? "":dataDetail.get("DoctorId").toString());
        wlyyIotM.setDoctorName(dataDetail.get("DoctorName") == null? "":dataDetail.get("DoctorName").toString());
        wlyyIotM.setRecordNo(dataDetail.get("RecordNo") == null? "":dataDetail.get("RecordNo").toString());
        wlyyIotM.setMeasureTime(dataDetail.get("MeasureTime") == null? "":dataDetail.get("MeasureTime").toString());
        wlyyIotM.setDeviceName("弈拓健康小屋测量仪");
        wlyyIotM.setDeviceModel(dataDetail.get("DeviceType") == null? "":dataDetail.get("DeviceType").toString());
        wlyyIotM.setMacAddr(dataDetail.get("MacAddr") == null? "":dataDetail.get("MacAddr").toString());
        wlyyIotM.setIdCardNo(memberMap.get("IdCode")==null?"":memberMap.get("IdCode").toString());
        wlyyIotM.setUserName(memberMap.get("Name")==null?"":memberMap.get("Name").toString());
        WlyyIotM wlyyIotMS =  wlyyIotMDao.save(wlyyIotM);
        if(wlyyIotMS != null){
            // 主表存储成功后,返回主表ID,用于细表存储关联用
            mid = wlyyIotMS.getId().toString();
        }
        for (Map.Entry entry : dataDetail.entrySet()) {
            String code = entry.getKey().toString();
            if("Member".equals(code) || "Member".equals(code) ){
                continue;
            }
            if("Height".equals(code) || "Fat".equals(code)|| "MinFat".equals(code)|| "BloodPressure".equals(code)|| "Bo".equals(code)
                    || "Ecg".equals(code)|| "PEEcg".equals(code)|| "Temperature".equals(code)|| "Whr".equals(code)|| "BloodSugar".equals(code)
                    || "Ua".equals(code)|| "Chol".equals(code)|| "BloodFat".equals(code)|| "Cardiovascular".equals(code)|| "BMD".equals(code)
                    || "Alcohol".equals(code)|| "Lung".equals(code)|| "Hb".equals(code)|| "Urinalysis".equals(code)){
                LinkedHashMap valueMap = (LinkedHashMap)entry.getValue();
                analyzerMapD(valueMap,mid,code);
            }
        }
        return true;
    }
    /**
     * 单项细表数据存储,因为体征数据上传,不管怎么样都返回成功,若数据未上传则直接查看LOG日志
     * @param mapInfo
     * @param mid
     * @param type
     * @return
     * @throws Exception
     */
    public boolean analyzerMapD(Map<String,String> mapInfo, String mid,String type)throws Exception{
        boolean addFlag = false;
        for (Map.Entry<String, String> entry : mapInfo.entrySet()) {
            String code = entry.getKey().toString();
            String value = entry.getValue() == ""?"":entry.getValue().toString();
            // 当数值为空时,不进行存储操作
            if("".equals(value)){
                continue;
            }else {
                WlyyIotD wlyyIotD = new WlyyIotD();
                wlyyIotD.setMid(mid);
                wlyyIotD.setType(type);
                wlyyIotD.setCode(code);
                wlyyIotD.setValue(value);
                wlyyIotD = addIotRecord(wlyyIotD);
                if(wlyyIotD != null){
                    logger.info( "体征数据新增成功:id = " + wlyyIotD.getId() + " ; type = " + type +" ; code = " + code +"; value = " +  value);
                    continue;
                }else {
                    logger.error( "体征数据新增成功:mid = " + mid + " ; type = " + type +" ; code = " + code +"; value = " +  value);
                    continue;
                }
            }
        }
        return true;
    }
    /**
     * 单条记录的存储,用于遍历循环操作
     * @param wlyyIotD
     * @return
     */
    public WlyyIotD addIotRecord(WlyyIotD wlyyIotD){
        WlyyIotD wlyyIotDRes = wlyyIotDDao.save(wlyyIotD);
        if(wlyyIotDRes != null){
            return wlyyIotDRes;
        }else{
            return null;
        }
    }
}

+ 79 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/WlyyIotD.java

@ -0,0 +1,79 @@
package com.yihu.iot.service.analyzer;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
@Entity
@Table(name = "wlyy_iot_d")
public class WlyyIotD extends UuidIdentityEntity implements Serializable {
    @Column(name = "mid")
    private String mid;
    @Column(name = "type")
    private String type;
    @Column(name = "code")
    private String code;
    @Column(name = "name")
    private String name;
    @Column(name = "value")
    private String value;
    @Column(name = "unit")
    private String unit;
    public String getMid() {
        return mid;
    }
    public void setMid(String mid) {
        this.mid = mid;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String getUnit() {
        return unit;
    }
    public void setUnit(String unit) {
        this.unit = unit;
    }
}

+ 14 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/WlyyIotDDao.java

@ -0,0 +1,14 @@
package com.yihu.iot.service.analyzer;
import com.yihu.jw.entity.base.dict.DictDiseaseDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Map;
public interface WlyyIotDDao extends PagingAndSortingRepository<WlyyIotD, Integer>, JpaSpecificationExecutor<WlyyIotD>  {
}

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

@ -0,0 +1,144 @@
package com.yihu.iot.service.analyzer;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
@Entity
@Table(name = "wlyy_iot_m")
public class WlyyIotM extends UuidIdentityEntity implements Serializable {
    @Column(name = "sn")
    private String sn;
    @Column(name = "device_name")
    private String deviceName;
    @Column(name = "device_model")
    private String deviceModel;
    @Column(name = "id_card_no")
    private String idCardNo;
    @Column(name = "user_name")
    private String userName;
    @Column(name = "unit_no")
    private String unitNo;
    @Column(name = "unit_name")
    private String unitName;
    @Column(name = "doctor_id")
    private String doctorId;
    @Column(name = "doctor_name")
    private String doctorName;
    @Column(name = "record_no")
    private String recordNo;
    @Column(name = "measure_time")
    private String measureTime;
    @Column(name = "mac_addr")
    private String macAddr;
    public String getSn() {
        return sn;
    }
    public void setSn(String sn) {
        this.sn = sn;
    }
    public String getDeviceName() {
        return deviceName;
    }
    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }
    public String getDeviceModel() {
        return deviceModel;
    }
    public void setDeviceModel(String deviceModel) {
        this.deviceModel = deviceModel;
    }
    public String getIdCardNo() {
        return idCardNo;
    }
    public void setIdCardNo(String idCardNo) {
        this.idCardNo = idCardNo;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUnitNo() {
        return unitNo;
    }
    public void setUnitNo(String unitNo) {
        this.unitNo = unitNo;
    }
    public String getUnitName() {
        return unitName;
    }
    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }
    public String getDoctorId() {
        return doctorId;
    }
    public void setDoctorId(String doctorId) {
        this.doctorId = doctorId;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public String getRecordNo() {
        return recordNo;
    }
    public void setRecordNo(String recordNo) {
        this.recordNo = recordNo;
    }
    public String getMeasureTime() {
        return measureTime;
    }
    public void setMeasureTime(String measureTime) {
        this.measureTime = measureTime;
    }
    public String getMacAddr() {
        return macAddr;
    }
    public void setMacAddr(String macAddr) {
        this.macAddr = macAddr;
    }
}

+ 8 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/analyzer/WlyyIotMDao.java

@ -0,0 +1,8 @@
package com.yihu.iot.service.analyzer;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface WlyyIotMDao extends PagingAndSortingRepository<WlyyIotM, Integer>, JpaSpecificationExecutor<WlyyIotM>  {
}

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

@ -125,9 +125,9 @@ spring:
    password: jkzlehr@123
  elasticsearch:
    cluster-name: jkzl #默认即为elasticsearch  集群名
    cluster-nodes: 59.61.92.90:9208,59.61.92.90:9210 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
    cluster-nodes: 59.61.92.90:9208, 59.61.92.90:9210 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
    jest:
      uris: http://59.61.92.90:9208,http://59.61.92.90:9210
      uris: http://59.61.92.90:9208, http://59.61.92.90:9210
  wlyy:
    url: http://www.xmtyw.cn/wlyy/
#fast-dfs:

+ 1 - 14
svr/svr-iot/src/main/resources/bootstrap.yml

@ -1,16 +1,3 @@
spring:
  application:
    name: svr-iot  #注册到发现服务的id 如果id一样 eurika会自动做负载
  cloud:
    config:
      failFast: true
      username: jw
      password: jkzl
---
spring:
  profiles: jwdev
  cloud:
    config:
      uri: ${wlyy.spring.config.uri:http://172.26.0.107:1221}
      label: ${wlyy.spring.config.label:jwdev}
    name: svr-iot-third  #注册到发现服务的id 如果id一样 eurika会自动做负载