浏览代码

智能手表

zdm 5 年之前
父节点
当前提交
73a070161d

+ 95 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotDeviceBaiyiDO.java

@ -0,0 +1,95 @@
package com.yihu.jw.entity.iot.device;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author zdm on 2019/6/11.
 */
@Entity
@Table(name = "iot_device_baiyi")
public class IotDeviceBaiyiDO extends UuidIdentityEntityWithOperator implements Serializable {
    /** 15位设备唯一序号*/
    @Column(name = "imei")
    private String imei;
    /** 发生时间*/
    @Column(name = "time_begin")
    private String timeBegin;
    /**心率/舒张压*/
    @Column(name = "value1")
    private Integer value1;
    /** 心率阈值上限/舒张压报警下限*/
    @Column(name = "value2")
    private Integer value2;
    /** 心率阈值下限/收缩压*/
    @Column(name = "value3")
    private Integer value3;
    /** 测量数据种类名称/收缩压报警上限*/
    @Column(name = "value4")
    private Integer value4;
    /** 类型:1血压、5心率*/
    @Column(name = "type")
    private Integer type;
    public String getImei() {
        return imei;
    }
    public void setImei(String imei) {
        this.imei = imei;
    }
    public String getTimeBegin() {
        return timeBegin;
    }
    public void setTimeBegin(String timeBegin) {
        this.timeBegin = timeBegin;
    }
    public Integer getValue1() {
        return value1;
    }
    public void setValue1(Integer value1) {
        this.value1 = value1;
    }
    public Integer getValue2() {
        return value2;
    }
    public void setValue2(Integer value2) {
        this.value2 = value2;
    }
    public Integer getValue3() {
        return value3;
    }
    public void setValue3(Integer value3) {
        this.value3 = value3;
    }
    public Integer getValue4() {
        return value4;
    }
    public void setValue4(Integer value4) {
        this.value4 = value4;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
}

+ 146 - 8
svr/svr-iot-sunnuo/src/main/java/com/yihu/iot/datainput/controller/IotAnalyzerController.java

@ -3,24 +3,19 @@ package com.yihu.iot.datainput.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.datainput.dao.IotDeviceBaiyiDao;
import com.yihu.iot.datainput.service.DataInputService;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.jw.entity.iot.device.IotDeviceBaiyiDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.text.SimpleDateFormat;
import java.util.Date;
@ -43,6 +38,8 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
    @Autowired
    ObjectMapper objectMapper;
    @Autowired
    private IotDeviceBaiyiDao iotDeviceBaiyiDao;
    /**
     * 基于奕拓小屋上传的体征数据,进行解析入库
@ -160,4 +157,145 @@ public class IotAnalyzerController extends EnvelopRestEndpoint {
            return strResult;
        }
    }
    @PostMapping(value = "/heartRate" /*,consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE*/)
    @ApiOperation(value = "柏颐心率数据接收", notes = "柏颐心率数据接收")
    public String heartRate(
            @ApiParam(name = "imei", value = "15位设备唯一序号")
            @RequestParam(value = "imei",required = true)String imei,
            @ApiParam(name = "time_begin", value = "发生时间YYYY-MM-DD HH:mm:SS")
            @RequestParam(value = "time_begin",required = true)String time_begin,
            @ApiParam(name = "heartrate", value = "心率")
            @RequestParam(value = "heartrate",required = true)int heartrate,
            @ApiParam(name = "theshold_heartrate_h", value = "心率阈值上限")
            @RequestParam(value = "theshold_heartrate_h",required = true)int theshold_heartrate_h,
            @ApiParam(name = "theshold_heartrate_l", value = "心率阈值下限")
            @RequestParam(value = "theshold_heartrate_l",required = true)int theshold_heartrate_l) throws Exception{
        String strResult = "";
        Map res = new HashMap();
        IotDeviceBaiyiDO iotDeviceBaiyiDO=new IotDeviceBaiyiDO();
        iotDeviceBaiyiDO.setImei(imei);
        iotDeviceBaiyiDO.setType(5);
        iotDeviceBaiyiDO.setTimeBegin(time_begin);
        iotDeviceBaiyiDO.setValue1(heartrate);
        iotDeviceBaiyiDO.setValue2(theshold_heartrate_h);
        iotDeviceBaiyiDO.setValue3(theshold_heartrate_l);
        iotDeviceBaiyiDao.save(iotDeviceBaiyiDO);
        try {
            String info  = "imei="+imei+";time_begin="+time_begin+";heartrate="+heartrate+";theshold_heartrate_h="+theshold_heartrate_h+";theshold_heartrate_l="+theshold_heartrate_l;
            logger.info("info="+info);
            return BaiyiDataParam(iotDeviceBaiyiDO);
        } catch (Exception e) {
            e.printStackTrace();
            res.put("statusCode", "03");
            res.put("desc", "服务异常,体征信息上传失败。");
            strResult = objectMapper.writeValueAsString(res);
            logger.error(strResult);
            return strResult;
        }
    }
    @PostMapping(value = "/bloodPressure" /*,consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE*/)
    @ApiOperation(value = "柏颐血压数据接收", notes = "柏颐血压数据接收")
    public String bloodPressure(
            @ApiParam(name = "imei", value = "15位设备唯一序号", required = true)
            @RequestParam(value = "imei",required = true)String imei,
            @ApiParam(name = "time_begin", value = "发生时间YYYY-MM-DD HH:mm:SS", required = true)
            @RequestParam(value = "time_begin",required = true)String time_begin,
            @ApiParam(name = "dbp", value = "舒张压", required = true)
            @RequestParam(value = "dbp",required = true)int dbp,
            @ApiParam(name = "dbp_l", value = "舒张压报警下限", required = true)
            @RequestParam(value = "dbp_l",required = true)int dbp_l,
            @ApiParam(name = "sbp", value = "收缩压", required = true)
            @RequestParam(value = "sbp",required = true)int sbp,
            @ApiParam(name = "sbp_h", value = "收缩压报警上限", required = true)
            @RequestParam(value = "sbp_h",required = true)int sbp_h) throws Exception{
        String strResult = "";
        Map res = new HashMap();
        IotDeviceBaiyiDO iotDeviceBaiyiDO=new IotDeviceBaiyiDO();
        iotDeviceBaiyiDO.setImei(imei);
        iotDeviceBaiyiDO.setTimeBegin(time_begin);
        iotDeviceBaiyiDO.setType(1);
        iotDeviceBaiyiDO.setValue1(dbp);
        iotDeviceBaiyiDO.setValue2(dbp_l);
        iotDeviceBaiyiDO.setValue3(sbp);
        iotDeviceBaiyiDO.setValue4(sbp_h);
        iotDeviceBaiyiDao.save(iotDeviceBaiyiDO);
        try {
            String info= "imei="+imei+";time_begin="+time_begin+";dbp="+dbp+";dbp_l="+dbp_l+";sbp="+sbp+";sbp_h="+sbp_h;
            logger.info("info="+info);
            return BaiyiDataParam(iotDeviceBaiyiDO);
        } catch (Exception e) {
            e.printStackTrace();
            res.put("statusCode", "03");
            res.put("desc", "服务异常,体征信息上传失败。");
            strResult = objectMapper.writeValueAsString(res);
            logger.error(strResult);
            return strResult;
        }
    }
    /**
     * 封装数据上传至i健康
     * @param iotDeviceBaiyiDO 设备数据实体
     * @return
     * @throws Exception
     */
    public String BaiyiDataParam(IotDeviceBaiyiDO iotDeviceBaiyiDO)throws Exception {
        JSONArray jsonArray = new JSONArray();
        JSONObject params = new JSONObject();
        JSONObject data = new JSONObject();
        Map res = new HashMap();
        // 增加判断,当测量值小于1时,定义为异常值,不进行数据的存储。
        if (iotDeviceBaiyiDO.getValue1() < 1) {
            res.put("statusCode", "00");
            res.put("desc", iotDeviceBaiyiDO.getImei() + "体征数据异常(小于正常值)。");
            return objectMapper.writeValueAsString(res);
        } else {
            if (1 == iotDeviceBaiyiDO.getType()) {
                //血压测量数据
                data.put("data", iotDeviceBaiyiDO.getValue1() + "," + iotDeviceBaiyiDO.getValue3());
                //单位
                data.put("unit", "mmHg");
            } else {
                //心率测量数据
                data.put("data", iotDeviceBaiyiDO.getValue1());
                //单位
                data.put("unit", "bpm");
            }
        }
        //按键号
        data.put("button", "-1");
        //设备唯一码
        data.put("deviceSn", iotDeviceBaiyiDO.getImei());
        //设备类型1:血压 5:心率
        data.put("deviceType", "4");
        //厂商代码
        data.put("manufacturerCode", "baiyi");
        //厂商名称
        data.put("manufacturerName", "柏颐设备");
        //发送时间yyyy-MM-dd HH:mm:ss
        data.put("sendTime", iotDeviceBaiyiDO.getTimeBegin());
        data.put("state", 0);
        //单位mmol/L,mmHg
        data.put("unit", "");
        //体征上传时间yyyy-MM-dd HH:mm:ss
        data.put("uploadTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        jsonArray.add(data);
        params.put("data", jsonArray);
        //体征信息上传成功后,同步到厦门I健康
        data.put("id", "");
        boolean synFlag = dataInputService.synXMIjk(data);
        if (synFlag) {
            res.put("statusCode", "00");
            res.put("desc", iotDeviceBaiyiDO.getImei() + "体征信息上传厦门I健康成功。");
        } else {
            res.put("statusCode", "02");
            res.put("desc", iotDeviceBaiyiDO.getImei() + "体征信息上传厦门I健康失败。");
        }
        String strResult = objectMapper.writeValueAsString(res);
        logger.info(strResult);
        return strResult;
    }
}

+ 12 - 0
svr/svr-iot-sunnuo/src/main/java/com/yihu/iot/datainput/dao/IotDeviceBaiyiDao.java

@ -0,0 +1,12 @@
package com.yihu.iot.datainput.dao;
import com.yihu.jw.entity.iot.device.IotDeviceBaiyiDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author zdm on 2019/6/11.
 */
public interface IotDeviceBaiyiDao extends PagingAndSortingRepository<IotDeviceBaiyiDO,String>,JpaSpecificationExecutor<IotDeviceBaiyiDO> {
}

+ 12 - 0
svr/svr-iot-sunnuo/src/main/java/com/yihu/iot/datainput/service/IotAnalyzerService.java

@ -0,0 +1,12 @@
package com.yihu.iot.datainput.service;
import org.springframework.stereotype.Service;
/**
 * Created by zdm on 2019/6/11.
 */
@Service
public class IotAnalyzerService {
}