|
@ -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;
|
|
|
}
|
|
|
}
|