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