|
|
@ -71,41 +71,47 @@ public class HttpService implements IHttpService{ |
|
|
|
for (int i = 0; i < dataArray.size(); i++) { |
|
|
|
LogisticsEnvironmentRecord environmentRecord = new LogisticsEnvironmentRecord(); |
|
|
|
JSONObject oneObject = dataArray.getJSONObject(i); |
|
|
|
environmentRecord.setEquipmentNum(oneObject.getString("deviceAddr")); |
|
|
|
environmentRecord.setRecordTime(System.currentTimeMillis()); |
|
|
|
|
|
|
|
JSONArray realTimeData = oneObject.getJSONArray("realTimeData"); |
|
|
|
for (int j = 0; j < realTimeData.size(); j++) { |
|
|
|
JSONObject realData = realTimeData.getJSONObject(j); |
|
|
|
switch (realData.getString("dataName")){ |
|
|
|
case Constant.TEMP : |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte)1); |
|
|
|
environmentRecord.setNumValue(new BigDecimal(realData.getString("dataValue"))); |
|
|
|
environmentRecord.setIsAlarm(realData.getBoolean("isAlarm") ? (byte) 1 : (byte) 0); |
|
|
|
break; |
|
|
|
case Constant.HUMIDITY: |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte)0); |
|
|
|
environmentRecord.setNumValue(new BigDecimal(realData.getString("dataValue"))); |
|
|
|
environmentRecord.setIsAlarm(realData.getBoolean("isAlarm") ? (byte) 1 : (byte) 0); |
|
|
|
break; |
|
|
|
case Constant.WATER_OUT: |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte)2); |
|
|
|
if(Constant.HAVE_WATER.equals(realData.getString("dataValue"))){ |
|
|
|
environmentRecord.setNumValue(new BigDecimal(100)); |
|
|
|
environmentRecord.setIsAlarm((byte)1); |
|
|
|
}else{ |
|
|
|
environmentRecord.setNumValue(new BigDecimal(0)); |
|
|
|
environmentRecord.setIsAlarm((byte)0); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
//获取设备运行状态 0未运行,1离线,2在线
|
|
|
|
Integer deviceStatus = oneObject.getInteger("deviceStatus"); |
|
|
|
//如果设备为在线状态 将数据存入到数据库
|
|
|
|
if (2 == deviceStatus){ |
|
|
|
environmentRecord.setEquipmentNum(oneObject.getString("deviceAddr")); |
|
|
|
environmentRecord.setRecordTime(System.currentTimeMillis()); |
|
|
|
|
|
|
|
JSONArray realTimeData = oneObject.getJSONArray("realTimeData"); |
|
|
|
for (int j = 0; j < realTimeData.size(); j++) { |
|
|
|
JSONObject realData = realTimeData.getJSONObject(j); |
|
|
|
switch (realData.getString("dataName")){ |
|
|
|
case Constant.TEMP : |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte)1); |
|
|
|
environmentRecord.setNumValue(new BigDecimal(realData.getString("dataValue"))); |
|
|
|
environmentRecord.setIsAlarm(realData.getBoolean("isAlarm") ? (byte) 1 : (byte) 0); |
|
|
|
break; |
|
|
|
case Constant.HUMIDITY: |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte)0); |
|
|
|
environmentRecord.setNumValue(new BigDecimal(realData.getString("dataValue"))); |
|
|
|
environmentRecord.setIsAlarm(realData.getBoolean("isAlarm") ? (byte) 1 : (byte) 0); |
|
|
|
break; |
|
|
|
case Constant.WATER_OUT: |
|
|
|
environmentRecord.setId(snowflake.nextId()); |
|
|
|
environmentRecord.setNumType((byte)2); |
|
|
|
if(Constant.HAVE_WATER.equals(realData.getString("dataValue"))){ |
|
|
|
environmentRecord.setNumValue(new BigDecimal(100)); |
|
|
|
environmentRecord.setIsAlarm((byte)1); |
|
|
|
}else{ |
|
|
|
environmentRecord.setNumValue(new BigDecimal(0)); |
|
|
|
environmentRecord.setIsAlarm((byte)0); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
environmentRecordDao.insertSelective(environmentRecord); |
|
|
|
} |
|
|
|
environmentRecordDao.insertSelective(environmentRecord); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|