|  | @ -1,6 +1,9 @@
 | 
	
		
			
				|  |  | package com.yihu.iot.service.analyzer;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 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.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @ -20,10 +23,12 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WlyyIotDDao wlyyIotDDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DataInputService dataInputService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WlyyIotMDao wlyyIotMDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String dataSource = "yituoHouse";
 | 
	
		
			
				|  |  |     private String accessToken = "yituoHouse";
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     ObjectMapper objectMapper;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -80,9 +85,190 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //存es start
 | 
	
		
			
				|  |  |         try{
 | 
	
		
			
				|  |  |             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);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             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();
 | 
	
		
			
				|  |  |                     JSONArray jsonArray = new JSONArray();
 | 
	
		
			
				|  |  |                     JSONObject js = new JSONObject();
 | 
	
		
			
				|  |  |                     js.put("measure_time",code);//测量时间
 | 
	
		
			
				|  |  |                     js.put("del",1);
 | 
	
		
			
				|  |  |                     js.put("status","0");
 | 
	
		
			
				|  |  |                     js.put("type",code);
 | 
	
		
			
				|  |  |                     analyzerMap(valueMap,js,code);
 | 
	
		
			
				|  |  |                     jsonArray.add(js);
 | 
	
		
			
				|  |  |                     json.put("data",jsonArray);
 | 
	
		
			
				|  |  |                     dataInputService.inputBodySignsData(json.toJSONString());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //end
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String transfor(Object o){
 | 
	
		
			
				|  |  |         return o == null?"":o.toString();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void analyzerMap(Map<String,Object> mapInfo,JSONObject js,String type)throws Exception{
 | 
	
		
			
				|  |  |         int i = 0;
 | 
	
		
			
				|  |  |         for(Object o: mapInfo.values()){
 | 
	
		
			
				|  |  |             String value = o == null?"":o.toString();
 | 
	
		
			
				|  |  |             if("".equals(value) || "0".equals(value) || "null".equals(value) || value == null ){
 | 
	
		
			
				|  |  |                 continue;
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 i++;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(i>0){
 | 
	
		
			
				|  |  |             //只有数据都不为空才保存es
 | 
	
		
			
				|  |  |             switch (type){
 | 
	
		
			
				|  |  |                 case "Height":
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Height")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Weight")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("BMI")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("IdealWeight")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "MinFat":
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Height")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Weight")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("FatRate")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("BasicMetabolism")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("Bmi")));
 | 
	
		
			
				|  |  |                     js.put("value6",transfor(mapInfo.get("Physique")));
 | 
	
		
			
				|  |  |                     js.put("value7",transfor(mapInfo.get("Shape")));
 | 
	
		
			
				|  |  |                     js.put("value8",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "BloodPressure":
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("HighPressure")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("LowPressure")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("Pulse")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Bo":
 | 
	
		
			
				|  |  |                     //血氧
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Oxygen")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("OxygenList")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("Bpm")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("BpmList")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     js.put("value6",transfor(mapInfo.get("StartTime")));
 | 
	
		
			
				|  |  |                     js.put("value7",transfor(mapInfo.get("EndTime")));
 | 
	
		
			
				|  |  |                     js.put("value8",transfor(mapInfo.get("SecondCount")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Ecg":
 | 
	
		
			
				|  |  |                     //单导心电
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Hr")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("EcgData")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("nGain")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("Analysis")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Temperature":
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Temperature")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Whr":
 | 
	
		
			
				|  |  |                     //腰臀比
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Waistline")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Hipline")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("Whr")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "BloodSugar":
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("BloodSugar")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("BloodsugarType")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Ua":
 | 
	
		
			
				|  |  |                     //血尿酸
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Ua")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "BloodFat":
 | 
	
		
			
				|  |  |                     //血脂
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("TChol")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("HdlChol")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("Trig")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("TcHdl")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("CalcLdl")));
 | 
	
		
			
				|  |  |                     js.put("value6",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Alcohol":
 | 
	
		
			
				|  |  |                     //酒精浓度
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Alcohol")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("AlcoholImg")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("errcode")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("errinfo")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Lung":
 | 
	
		
			
				|  |  |                     //肺活量
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Lung")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("FVC")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("FEV1")));
 | 
	
		
			
				|  |  |                     js.put("value4",transfor(mapInfo.get("PEF")));
 | 
	
		
			
				|  |  |                     js.put("value5",transfor(mapInfo.get("FEF25")));
 | 
	
		
			
				|  |  |                     js.put("value6",transfor(mapInfo.get("FEF75")));
 | 
	
		
			
				|  |  |                     js.put("value7",transfor(mapInfo.get("FEF2575")));
 | 
	
		
			
				|  |  |                     js.put("value8",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "Hb":
 | 
	
		
			
				|  |  |                     //血红蛋白
 | 
	
		
			
				|  |  |                     js.put("value1",transfor(mapInfo.get("Hb")));
 | 
	
		
			
				|  |  |                     js.put("value2",transfor(mapInfo.get("Hct")));
 | 
	
		
			
				|  |  |                     js.put("value3",transfor(mapInfo.get("Result")));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case "BMD":
 | 
	
		
			
				|  |  |                     //骨密度
 | 
	
		
			
				|  |  |                 case "PEEcg":
 | 
	
		
			
				|  |  |                     //12导心电
 | 
	
		
			
				|  |  |                 case "Urinalysis":
 | 
	
		
			
				|  |  |                     //尿液分析
 | 
	
		
			
				|  |  |                 case "Fat":
 | 
	
		
			
				|  |  |                     //脂肪
 | 
	
		
			
				|  |  |                 case "Cardiovascular":
 | 
	
		
			
				|  |  |               //心血管功能
 | 
	
		
			
				|  |  |                     js.put("value1",JSONObject.toJSONString(mapInfo));
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 单项细表数据存储,因为体征数据上传,不管怎么样都返回成功,若数据未上传则直接查看LOG日志
 | 
	
		
			
				|  |  |      * @param mapInfo
 |