|  | @ -10,10 +10,8 @@ import com.yihu.iot.datainput.util.ConstantUtils;
 | 
	
		
			
				|  |  | import com.yihu.iot.datainput.util.RowKeyUtils;
 | 
	
		
			
				|  |  | import com.yihu.iot.service.common.MyJdbcTemplate;
 | 
	
		
			
				|  |  | import com.yihu.jw.datainput.DataBodySignsDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.apache.http.client.utils.DateUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
	
		
			
				|  | @ -52,6 +50,14 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DeviceHealthyInfoMappingDao deviceHealthyInfoMappingDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String bloodSugarUnit = "mmol/L";
 | 
	
		
			
				|  |  |     private String bloodPressureUnit = "mmHg";
 | 
	
		
			
				|  |  |     private String pulseUnit = "bpm";
 | 
	
		
			
				|  |  |     private String heightUnit = "cm";
 | 
	
		
			
				|  |  |     private String weightUnit = "kg";
 | 
	
		
			
				|  |  |     private String bmiUnit = "kg/m^2";
 | 
	
		
			
				|  |  |     private String waistUnit = "cm";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void initIHealthIntoEs(){
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             Integer id = 0;
 | 
	
	
		
			
				|  | @ -74,7 +80,7 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |                         DeviceHealthyInfoMapping info = new DeviceHealthyInfoMapping();
 | 
	
		
			
				|  |  |                         info.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                         info.setIndexId(one.getLong("id"));
 | 
	
		
			
				|  |  |                         info.setRid(tmp.getJSONArray("data").getJSONObject(0).getString("rid"));
 | 
	
		
			
				|  |  |                         info.setRid(tmp.getString("rid"));
 | 
	
		
			
				|  |  |                         infos.add(info);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
	
		
			
				|  | @ -94,7 +100,7 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |                 deviceHealthyInfoMappingDao.save(infos);
 | 
	
		
			
				|  |  |                 //下一次
 | 
	
		
			
				|  |  |                 id = list.get(list.size()-1).getInteger("id");
 | 
	
		
			
				|  |  |                 list = myJdbcTemplate.queryJson(sql,new Object[]{id});
 | 
	
		
			
				|  |  | //                list = myJdbcTemplate.queryJson(sql,new Object[]{id});
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
	
		
			
				|  | @ -110,7 +116,6 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |     public String initUpload(JSONObject jsonObject){
 | 
	
		
			
				|  |  |         JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |         Integer type = jsonObject.getInteger("type");
 | 
	
		
			
				|  |  |         json.put("access_token","iHealth");
 | 
	
		
			
				|  |  |         json.put("data_source","iHealth");
 | 
	
		
			
				|  |  |         json.put("sn",StringUtils.trimToEmpty(jsonObject.getString("device_sn")));
 | 
	
		
			
				|  |  |         json.put("ext_code",StringUtils.trimToEmpty(jsonObject.getString("user_type")));
 | 
	
	
		
			
				|  | @ -119,54 +124,111 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |             json.put("device_model",StringUtils.trimToEmpty(jsonObject.getString("device_name")));
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             //历史数据未绑定居民
 | 
	
		
			
				|  |  |             String sql = "SELECT i.device_code,i.device_model,i.device_name from device.wlyy_devices i WHERE device_code = '"+jsonObject.getString("device_sn")+"'";
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             if(list.size()>0){
 | 
	
		
			
				|  |  |                 json.put("device_name",StringUtils.trimToEmpty(list.get(0).get("device_name").toString()));
 | 
	
		
			
				|  |  |                 json.put("device_model",StringUtils.trimToEmpty(list.get(0).get("device_model").toString()));
 | 
	
		
			
				|  |  |             if(StringUtils.isNotEmpty(jsonObject.getString("device_sn"))){
 | 
	
		
			
				|  |  |                 String sql = "SELECT i.device_code,i.device_model,i.device_name from device.wlyy_devices i WHERE device_code = '"+jsonObject.getString("device_sn")+"'";
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if(list.size()>0){
 | 
	
		
			
				|  |  |                     json.put("device_name",StringUtils.trimToEmpty(list.get(0).get("device_name").toString()));
 | 
	
		
			
				|  |  |                     json.put("device_model",StringUtils.trimToEmpty(list.get(0).get("device_model").toString()));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         json.put("idcard",StringUtils.trimToEmpty(jsonObject.getString("idcard")));
 | 
	
		
			
				|  |  |         json.put("username",StringUtils.trimToEmpty(jsonObject.getString("name")));
 | 
	
		
			
				|  |  |         json.put("usercode",StringUtils.trimToEmpty(jsonObject.getString("user")));
 | 
	
		
			
				|  |  |         json.put("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
 | 
	
		
			
				|  |  |         json.put("status",getStatus(jsonObject.getString("status")));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONArray jsonArray = new JSONArray();
 | 
	
		
			
				|  |  |         JSONObject js = new JSONObject();
 | 
	
		
			
				|  |  |         js.put("measure_time",subStringTime(jsonObject.getString("record_date")));
 | 
	
		
			
				|  |  |         js.put("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
 | 
	
		
			
				|  |  |         js.put("status",getStatus(jsonObject.getString("status")));
 | 
	
		
			
				|  |  |         js.put("type",String.valueOf(type));
 | 
	
		
			
				|  |  |         String measure_time = subStringTime(jsonObject.getString("record_date"));
 | 
	
		
			
				|  |  |         switch (type){
 | 
	
		
			
				|  |  |             case 1:
 | 
	
		
			
				|  |  |                 //血糖
 | 
	
		
			
				|  |  |                 js.put("value1",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 js.put("value2",jsonObject.getString("value2"));
 | 
	
		
			
				|  |  |                 JSONObject blood_sugar = new JSONObject();
 | 
	
		
			
				|  |  |                 blood_sugar.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 blood_sugar.put("type","BloodSugar");
 | 
	
		
			
				|  |  |                 blood_sugar.put("sign_name","blood_sugar");
 | 
	
		
			
				|  |  |                 blood_sugar.put("sign_value",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 blood_sugar.put("sign_unit",bloodSugarUnit);
 | 
	
		
			
				|  |  |                 jsonArray.add(blood_sugar);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 JSONObject blood_sugar_result = new JSONObject();
 | 
	
		
			
				|  |  |                 blood_sugar_result.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 blood_sugar_result.put("type","BloodSugar");
 | 
	
		
			
				|  |  |                 blood_sugar_result.put("sign_name","blood_sugar_result");
 | 
	
		
			
				|  |  |                 blood_sugar_result.put("sign_value",jsonObject.getString("value2"));
 | 
	
		
			
				|  |  |                 jsonArray.add(blood_sugar_result);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 2:
 | 
	
		
			
				|  |  |                 //血压
 | 
	
		
			
				|  |  |                 js.put("value1",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 js.put("value2",jsonObject.getString("value2"));
 | 
	
		
			
				|  |  |                 JSONObject systolic = new JSONObject();
 | 
	
		
			
				|  |  |                 systolic.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 systolic.put("type","BloodPressure");
 | 
	
		
			
				|  |  |                 systolic.put("sign_name","systolic");
 | 
	
		
			
				|  |  |                 systolic.put("sign_value",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 systolic.put("sign_unit",bloodPressureUnit);
 | 
	
		
			
				|  |  |                 jsonArray.add(systolic);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 JSONObject diastolic = new JSONObject();
 | 
	
		
			
				|  |  |                 diastolic.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 diastolic.put("type","BloodPressure");
 | 
	
		
			
				|  |  |                 diastolic.put("sign_name","diastolic");
 | 
	
		
			
				|  |  |                 diastolic.put("sign_value",jsonObject.getString("value2"));
 | 
	
		
			
				|  |  |                 diastolic.put("sign_unit",bloodPressureUnit);
 | 
	
		
			
				|  |  |                 jsonArray.add(diastolic);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if(StringUtils.isNotBlank(jsonObject.getString("value3"))){
 | 
	
		
			
				|  |  |                     js.put("value3",jsonObject.getString("value3"));
 | 
	
		
			
				|  |  |                     JSONObject pulse = new JSONObject();
 | 
	
		
			
				|  |  |                     pulse.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                     pulse.put("type","BloodPressure");
 | 
	
		
			
				|  |  |                     pulse.put("sign_name","pulse");
 | 
	
		
			
				|  |  |                     pulse.put("sign_value",jsonObject.getString("value3"));
 | 
	
		
			
				|  |  |                     pulse.put("sign_unit",pulseUnit);
 | 
	
		
			
				|  |  |                     jsonArray.add(pulse);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 3:
 | 
	
		
			
				|  |  |                 //体重/身高/BMI
 | 
	
		
			
				|  |  |                 js.put("value1",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 js.put("value2",jsonObject.getString("value2"));
 | 
	
		
			
				|  |  |                 JSONObject height = new JSONObject();
 | 
	
		
			
				|  |  |                 height.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 height.put("type","Height");
 | 
	
		
			
				|  |  |                 height.put("sign_name","height");
 | 
	
		
			
				|  |  |                 height.put("sign_value",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 height.put("sign_unit",heightUnit);
 | 
	
		
			
				|  |  |                 jsonArray.add(height);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 JSONObject weight = new JSONObject();
 | 
	
		
			
				|  |  |                 weight.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 weight.put("type","Height");
 | 
	
		
			
				|  |  |                 weight.put("sign_name","weight");
 | 
	
		
			
				|  |  |                 weight.put("sign_value",jsonObject.getString("value2"));
 | 
	
		
			
				|  |  |                 weight.put("sign_unit",weightUnit);
 | 
	
		
			
				|  |  |                 jsonArray.add(weight);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if(StringUtils.isNotBlank(jsonObject.getString("value3"))){
 | 
	
		
			
				|  |  |                     js.put("value3",jsonObject.getString("value3"));
 | 
	
		
			
				|  |  |                     JSONObject bmi = new JSONObject();
 | 
	
		
			
				|  |  |                     bmi.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                     bmi.put("type","Height");
 | 
	
		
			
				|  |  |                     bmi.put("sign_name","bmi");
 | 
	
		
			
				|  |  |                     bmi.put("sign_value",jsonObject.getString("value3"));
 | 
	
		
			
				|  |  |                     bmi.put("sign_unit",bmiUnit);
 | 
	
		
			
				|  |  |                     jsonArray.add(bmi);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 4:
 | 
	
		
			
				|  |  |                 //腰围
 | 
	
		
			
				|  |  |                 js.put("value1",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 JSONObject waist = new JSONObject();
 | 
	
		
			
				|  |  |                 waist.put("measure_time",measure_time);
 | 
	
		
			
				|  |  |                 waist.put("type","Waist");
 | 
	
		
			
				|  |  |                 waist.put("sign_name","waist");
 | 
	
		
			
				|  |  |                 waist.put("sign_value",jsonObject.getString("value1"));
 | 
	
		
			
				|  |  |                 waist.put("sign_unit",waistUnit);
 | 
	
		
			
				|  |  |                 jsonArray.add(waist);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             default:
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         jsonArray.add(js);
 | 
	
		
			
				|  |  |         json.put("data",jsonArray);
 | 
	
		
			
				|  |  |         json.put("measure_data",jsonArray);
 | 
	
		
			
				|  |  |         //上传
 | 
	
		
			
				|  |  |         return json.toJSONString();
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -289,36 +351,16 @@ public class IotAnalyzerService extends BaseJpaService<WlyyIotD, WlyyIotDDao> {
 | 
	
		
			
				|  |  |             logger.error("json parse error,invalid json string");
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject jsonObject = JSONObject.parseObject(json);
 | 
	
		
			
				|  |  |         String accessToken= dataBodySignsDO.getAccess_token();
 | 
	
		
			
				|  |  |         String dataSource = dataBodySignsDO.getData_source();
 | 
	
		
			
				|  |  |         String deviceSn = dataBodySignsDO.getSn();
 | 
	
		
			
				|  |  |         String extCode = dataBodySignsDO.getExt_code();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONArray jsonArray = jsonObject.getJSONArray("data");
 | 
	
		
			
				|  |  |         JSONArray jsonArray = jsonObject.getJSONArray("measure_data");
 | 
	
		
			
				|  |  |         if(null == jsonArray || jsonArray.size() == 0){
 | 
	
		
			
				|  |  |             logger.error("msg","parameter 'data' of json no exist");
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         rowkey = RowKeyUtils.makeRowKey();
 | 
	
		
			
				|  |  |         jsonObject.put("rid",rowkey);//hbase的rowkey
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //循环数据,一组数据存一行,生成一个rowkey,并将该rowkey存到es中
 | 
	
		
			
				|  |  |         for(Object obj:jsonArray){
 | 
	
		
			
				|  |  |             JSONObject data = (JSONObject)obj;
 | 
	
		
			
				|  |  |             data.put("del","1"); //添加删除标记
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 String measuretime = jsonObject.getString("measure_time");
 | 
	
		
			
				|  |  |                 if(null == measuretime){
 | 
	
		
			
				|  |  |                     measuretime = DateUtils.formatDate(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //生成一份json数据的rowkey
 | 
	
		
			
				|  |  |                 rowkey = RowKeyUtils.makeRowKey(dataSource,deviceSn);
 | 
	
		
			
				|  |  |                 data.put("rid",rowkey);//hbase的rowkey
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 logger.error("make rowkey error");
 | 
	
		
			
				|  |  |                 return null;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return jsonObject;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 |