|
@@ -94,35 +94,36 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//Step1:更新设备注册表[设置活动状态为1,设置活动状态更新时间]
|
|
|
//Step2:更新在线统计[心跳数+1,心跳第一次上传时间,心跳最后一次时间],预先判断该数据是否存在,如果不存在要先添加记录,如果存在就修改数据
|
|
|
|
|
|
-
|
|
|
System.out.println("dataJo>"+dataJo);
|
|
|
String deviceCode = dataJo.getString("device");
|
|
|
//{获取牧场id}
|
|
|
String farmId = getFarmIdByDeviceCode(deviceCode);
|
|
|
- String todayDateText = new com.huimv.eartag2.common.utils.DateUtil().getTodayDateText();
|
|
|
- java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
|
- Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
-
|
|
|
- //1、{保存设备心跳记录}
|
|
|
- saveDeviceHeartbeat(dataJo,todayDate);
|
|
|
-
|
|
|
- String updateType="设备心跳";
|
|
|
- //2、{更新设备注册表}
|
|
|
- updateDeviceRegister(farmId, deviceCode,nowTimestamp,updateType);
|
|
|
-
|
|
|
- //3、{更新在线统计表}
|
|
|
- updateDeviceOnlineCountWithHeartbeat(farmId, deviceCode,todayDateText,nowTimestamp,todayDate);
|
|
|
-
|
|
|
- //判断该设备编号是否存在缓存在线集合当中;
|
|
|
- Boolean isExist = cacheService.isExistDeviceOnlineSet(farmId, deviceCode, todayDateText);
|
|
|
- System.out.println("心跳处理 isExist>>"+isExist);
|
|
|
- if (!isExist) {
|
|
|
- //4、{更新总状态表}
|
|
|
-// updateDeviceAllStatus(farmId, deviceCode,todayDateText,nowTimestamp,todayDate);
|
|
|
- updateEnvtempOfDeviceAllStatus(farmId, todayDateText,todayDate,nowTimestamp);
|
|
|
-
|
|
|
- //# 将新设备编号加入在线缓存 #
|
|
|
- cacheService.putDeviceToOnlineSet(farmId, deviceCode,todayDateText);
|
|
|
+ if(farmId != null){
|
|
|
+ String todayDateText = new com.huimv.eartag2.common.utils.DateUtil().getTodayDateText();
|
|
|
+ java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
|
+ Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
+ //1、{保存设备心跳记录}
|
|
|
+ saveDeviceHeartbeat(dataJo,todayDate);
|
|
|
+
|
|
|
+ String updateType="设备心跳";
|
|
|
+ //2、{更新设备注册表}
|
|
|
+ updateDeviceRegister(farmId, deviceCode,nowTimestamp,updateType);
|
|
|
+
|
|
|
+ //3、{更新在线统计表}
|
|
|
+ updateDeviceOnlineCountWithHeartbeat(farmId, deviceCode,todayDateText,nowTimestamp,todayDate);
|
|
|
+
|
|
|
+ //判断该设备编号是否存在缓存在线集合当中;
|
|
|
+ Boolean isExist = cacheService.isExistDeviceOnlineSet(farmId, deviceCode, todayDateText);
|
|
|
+ System.out.println("心跳处理 isExist>>"+isExist);
|
|
|
+ if (!isExist) {
|
|
|
+ //4、{更新总状态表}
|
|
|
+ updateEnvtempOfDeviceAllStatus(farmId, todayDateText,todayDate,nowTimestamp);
|
|
|
+
|
|
|
+ //# 将新设备编号加入在线缓存 #
|
|
|
+ cacheService.putDeviceToOnlineSet(farmId, deviceCode,todayDateText);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("出错:该请求的FarmId为空.请检查该设备编码["+deviceCode+"]是否存在FarmId.");
|
|
|
}
|
|
|
System.out.println("## END 心跳.");
|
|
|
}
|
|
@@ -191,12 +192,14 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
public int getDeviceTotalByFarmIdFromDeviceRegister(String farmId){
|
|
|
//从缓存钟读取设备总数
|
|
|
Integer deviceTotal = cacheService.getDeviceTotal(farmId);
|
|
|
- if(deviceTotal != null) {
|
|
|
+ if(deviceTotal != null && deviceTotal != 0) {
|
|
|
return deviceTotal;
|
|
|
}else{
|
|
|
- List<Object[]> deviceRegList = deviceRegisterRepo.getDeviceCountByFarmId(farmId);
|
|
|
- Object[] deviceRegObj = (Object[]) deviceRegList.get(0);
|
|
|
- Integer total = Integer.parseInt(deviceRegObj[0].toString());
|
|
|
+// List<Object[]> deviceRegList = deviceRegisterRepo.getDeviceCountByFarmId(farmId);
|
|
|
+// System.out.println("deviceRegList.size>>>>"+deviceRegList.size());
|
|
|
+// Object[] deviceRegObj = (Object[]) deviceRegList.get(0);
|
|
|
+// Integer total = Integer.parseInt(deviceRegObj[0].toString());
|
|
|
+ Integer total = getEffectiveDeviceSum(farmId);
|
|
|
//设置缓存
|
|
|
cacheService.putDeviceTotal(total,farmId);
|
|
|
//设备总数
|
|
@@ -352,33 +355,34 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
String deviceCode = dataJo.getString("device");
|
|
|
//{通过设备编码取货牧场id}
|
|
|
String farmId = getFarmIdByDeviceCode(deviceCode);
|
|
|
- if(farmId == null){
|
|
|
- log.error("出错:该设备编码["+deviceCode+"]的设备已经不存在。");
|
|
|
- }
|
|
|
- String temp = dataJo.getString("temp");
|
|
|
- String envtemp = com.huimv.eartag2.common.utils.MathUtil.countEnvtemp(temp,2).toString();
|
|
|
- String todayDateText = new com.huimv.eartag2.common.utils.DateUtil().getTodayDateText();
|
|
|
- java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
|
- Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
-
|
|
|
- //1.保存环境温度流水
|
|
|
- saveDeviceTemp(dataJo,todayDate,nowTimestamp);
|
|
|
-
|
|
|
- String updateType = "环境温度";
|
|
|
- //2.{更新设备注册表}
|
|
|
- updateDeviceRegister(farmId, deviceCode,nowTimestamp,updateType);
|
|
|
-
|
|
|
- //3.{更新在线统计表}
|
|
|
- updateDeviceOnlineWithEnvtemp(farmId, deviceCode,envtemp,todayDate,nowTimestamp);
|
|
|
-
|
|
|
- //判断该设备编号是否存在牧场缓存在线集合当中;
|
|
|
- Boolean isExist = cacheService.isExistDeviceOnlineSet(farmId, deviceCode,todayDateText);
|
|
|
- System.out.println("## 环境温度 isExist>>"+isExist);
|
|
|
- if (!isExist) {
|
|
|
- //4.{更新总状态表}
|
|
|
- updateEnvtempOfDeviceAllStatus(farmId, todayDateText,todayDate,nowTimestamp);
|
|
|
- //{将新设备编号加入在线缓存}
|
|
|
- cacheService.putDeviceToOnlineSet(farmId, deviceCode, todayDateText);
|
|
|
+ if(farmId != null){
|
|
|
+ String temp = dataJo.getString("temp");
|
|
|
+ String envtemp = com.huimv.eartag2.common.utils.MathUtil.countEnvtemp(temp,2).toString();
|
|
|
+ String todayDateText = new com.huimv.eartag2.common.utils.DateUtil().getTodayDateText();
|
|
|
+ java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
|
+ Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
+
|
|
|
+ //1.保存环境温度流水
|
|
|
+ saveDeviceTemp(dataJo,todayDate,nowTimestamp);
|
|
|
+
|
|
|
+ String updateType = "环境温度";
|
|
|
+ //2.{更新设备注册表}
|
|
|
+ updateDeviceRegister(farmId, deviceCode,nowTimestamp,updateType);
|
|
|
+
|
|
|
+ //3.{更新在线统计表}
|
|
|
+ updateDeviceOnlineWithEnvtemp(farmId, deviceCode,envtemp,todayDate,nowTimestamp);
|
|
|
+
|
|
|
+ //判断该设备编号是否存在牧场缓存在线集合当中;
|
|
|
+ Boolean isExist = cacheService.isExistDeviceOnlineSet(farmId, deviceCode,todayDateText);
|
|
|
+ System.out.println("## 环境温度 isExist>>"+isExist);
|
|
|
+ if (!isExist) {
|
|
|
+ //4.{更新总状态表}
|
|
|
+ updateEnvtempOfDeviceAllStatus(farmId, todayDateText,todayDate,nowTimestamp);
|
|
|
+ //{将新设备编号加入在线缓存}
|
|
|
+ cacheService.putDeviceToOnlineSet(farmId, deviceCode, todayDateText);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("出错:该请求的FarmId为空.请检查该设备编码["+deviceCode+"]是否存在FarmId.");
|
|
|
}
|
|
|
System.out.println("## END 环境数据");
|
|
|
}
|
|
@@ -386,6 +390,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
//更新设备环境信息
|
|
|
@Override
|
|
|
public void updateEnvtempOfDeviceAllStatus(String farmId, String todayDateText, java.sql.Date todayDate, Timestamp nowTimestamp) throws ParseException {
|
|
|
+ System.out.println("## farmId>>"+farmId);
|
|
|
//{获取处于工作状态的设备数量}
|
|
|
Integer deviceTotal = getDeviceTotalByFarmIdFromDeviceRegister(farmId);
|
|
|
System.out.println("## deviceTotal>>"+deviceTotal);
|
|
@@ -690,10 +695,10 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
System.out.println("result>>"+result);
|
|
|
}
|
|
|
|
|
|
+ //读取有效的设备数量
|
|
|
public Integer getEffectiveDeviceSum(String farmId){
|
|
|
List<Object[]> deviceRegisterList = deviceRegisterRepo.getDeviceCountByFarmId(farmId);
|
|
|
Object[] deviceRegObj = (Object[]) deviceRegisterList.get(0);
|
|
|
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+deviceRegObj[0].toString());
|
|
|
//设备总数
|
|
|
return Integer.parseInt(deviceRegObj[0].toString());
|
|
|
}
|