|
@@ -4,8 +4,12 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import com.huimv.devicedata.entity.DeviceResponseEntity;
|
|
import com.huimv.devicedata.entity.DeviceResponseEntity;
|
|
import com.huimv.devicedata.entity.DeviceUpdataEntity;
|
|
import com.huimv.devicedata.entity.DeviceUpdataEntity;
|
|
|
|
+import com.huimv.devicedata.entity.SetTemperatureEntity;
|
|
|
|
+import com.huimv.devicedata.entity.WarningInfoEntity;
|
|
import com.huimv.devicedata.repo.DeviceResponseEntityRepository;
|
|
import com.huimv.devicedata.repo.DeviceResponseEntityRepository;
|
|
import com.huimv.devicedata.repo.DeviceUpdataEntityRepository;
|
|
import com.huimv.devicedata.repo.DeviceUpdataEntityRepository;
|
|
|
|
+import com.huimv.devicedata.repo.SetTemperatureRepo;
|
|
|
|
+import com.huimv.devicedata.repo.WarningInfoRepo;
|
|
import com.huimv.devicedata.service.IDeviceDataService;
|
|
import com.huimv.devicedata.service.IDeviceDataService;
|
|
import com.huimv.devicedata.utils.DateUtil;
|
|
import com.huimv.devicedata.utils.DateUtil;
|
|
import com.huimv.devicedata.utils.MathUtil;
|
|
import com.huimv.devicedata.utils.MathUtil;
|
|
@@ -34,6 +38,10 @@ public class DeviceDataServiceImpl implements IDeviceDataService {
|
|
private MathUtil mathUtil;
|
|
private MathUtil mathUtil;
|
|
@Autowired
|
|
@Autowired
|
|
private DeviceResponseEntityRepository deviceResponseEntityRepo;
|
|
private DeviceResponseEntityRepository deviceResponseEntityRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SetTemperatureRepo setTemperatureRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private WarningInfoRepo WarningInfoRepo;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void saveDeviceChangedUpData(JSONObject deviceUpDataJo) {
|
|
public void saveDeviceChangedUpData(JSONObject deviceUpDataJo) {
|
|
@@ -74,6 +82,8 @@ public class DeviceDataServiceImpl implements IDeviceDataService {
|
|
deviceUpdataEntity.setDataHumi(dataHumi);
|
|
deviceUpdataEntity.setDataHumi(dataHumi);
|
|
deviceUpdataEntity.setDataBat(dataBat);
|
|
deviceUpdataEntity.setDataBat(dataBat);
|
|
deviceUpdataEntity.setTenantId(tenantId);
|
|
deviceUpdataEntity.setTenantId(tenantId);
|
|
|
|
+ System.out.println("dataTemp: "+dataTemp);
|
|
|
|
+ System.out.println("TempConvert: "+mathUtil.formatDecimalNumber(dataTemp*0.1,1));
|
|
deviceUpdataEntity.setDataTempConvert(mathUtil.formatDecimalNumber(dataTemp*0.1,1));
|
|
deviceUpdataEntity.setDataTempConvert(mathUtil.formatDecimalNumber(dataTemp*0.1,1));
|
|
deviceUpdataEntity.setDataHumiConvert(mathUtil.formatDecimalNumber(dataHumi*0.1,1));
|
|
deviceUpdataEntity.setDataHumiConvert(mathUtil.formatDecimalNumber(dataHumi*0.1,1));
|
|
deviceUpdataEntity.setDataBatConvert(mathUtil.formatDecimalNumber(dataBat*0.01,1));
|
|
deviceUpdataEntity.setDataBatConvert(mathUtil.formatDecimalNumber(dataBat*0.01,1));
|
|
@@ -114,9 +124,87 @@ public class DeviceDataServiceImpl implements IDeviceDataService {
|
|
deviceResponseEntity.setResultCode(resultCode);
|
|
deviceResponseEntity.setResultCode(resultCode);
|
|
deviceResponseEntity.setResultDetailLength(length);
|
|
deviceResponseEntity.setResultDetailLength(length);
|
|
deviceResponseEntity.setResultDetailRspData(rspdata);
|
|
deviceResponseEntity.setResultDetailRspData(rspdata);
|
|
-
|
|
|
|
//保存到数据库
|
|
//保存到数据库
|
|
deviceResponseEntityRepo.saveAndFlush(deviceResponseEntity);
|
|
deviceResponseEntityRepo.saveAndFlush(deviceResponseEntity);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveWarningInfo(JSONObject deviceUpDataJo) {
|
|
|
|
+ String productId = deviceUpDataJo.getString("productId");
|
|
|
|
+ String deviceId = deviceUpDataJo.getString("deviceId");
|
|
|
|
+ long timestamp = deviceUpDataJo.getLong("timestamp");
|
|
|
|
+ String upDataDate = dateUtil.formatLongDate(timestamp);
|
|
|
|
+ String serviceId = deviceUpDataJo.getString("serviceId");
|
|
|
|
+ String imsi = deviceUpDataJo.getString("IMSI");
|
|
|
|
+ String imei = deviceUpDataJo.getString("IMEI");
|
|
|
|
+ String deviceType = deviceUpDataJo.getString("deviceType");
|
|
|
|
+ String messageType = deviceUpDataJo.getString("messageType");
|
|
|
|
+ String protocol = deviceUpDataJo.getString("protocol");
|
|
|
|
+ String tenantId = deviceUpDataJo.getString("tenantId");
|
|
|
|
+ JSONObject businessDataJo = deviceUpDataJo.getJSONObject("payload");
|
|
|
|
+ int dataVer = businessDataJo.getInteger("VER");
|
|
|
|
+ int dataTime = businessDataJo.getInteger("TIME");
|
|
|
|
+ int dataTemp = businessDataJo.getInteger("TEMP");
|
|
|
|
+ int dataStc = businessDataJo.getInteger("STC");
|
|
|
|
+ int dataRssi = businessDataJo.getInteger("RSSI");
|
|
|
|
+ int dataHumi = businessDataJo.getInteger("HUMI");
|
|
|
|
+ int dataBat = businessDataJo.getInteger("BAT");
|
|
|
|
+ Double tempVal = mathUtil.formatDecimalNumber(dataTemp*0.1,1);
|
|
|
|
+
|
|
|
|
+ // 读取温度参数阈值
|
|
|
|
+ SetTemperatureEntity setTemperatureEntity = setTemperatureRepo.getOne(2);
|
|
|
|
+ String high = setTemperatureEntity.getHighTemperature();
|
|
|
|
+ String low = setTemperatureEntity.getLowTemperature();
|
|
|
|
+ Double highVal = Double.parseDouble(high);
|
|
|
|
+ Double lowVal = Double.parseDouble(low);
|
|
|
|
+ if(tempVal>highVal){
|
|
|
|
+ // 生成高温报警
|
|
|
|
+ WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
+ warningInfoEntity.setLQID(deviceId);
|
|
|
|
+ warningInfoEntity.setType("出现高温报警:"+tempVal);
|
|
|
|
+ warningInfoEntity.setUploadTime(dateUtil.getTimestamp());
|
|
|
|
+ warningInfoEntity.setWarningType(2);
|
|
|
|
+ warningInfoEntity.setShowStatus(true);
|
|
|
|
+ WarningInfoRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
+ }
|
|
|
|
+ if(tempVal<lowVal){
|
|
|
|
+ // 生成低端报警
|
|
|
|
+ WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
+ warningInfoEntity.setLQID(deviceId);
|
|
|
|
+ warningInfoEntity.setType("出现低温报警:"+tempVal);
|
|
|
|
+ warningInfoEntity.setUploadTime(dateUtil.getTimestamp());
|
|
|
|
+ warningInfoEntity.setWarningType(2);
|
|
|
|
+ warningInfoEntity.setShowStatus(true);
|
|
|
|
+ WarningInfoRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
+ }
|
|
|
|
+ // 湿度数据
|
|
|
|
+ Double humiVal = mathUtil.formatDecimalNumber(dataHumi*0.1,1);
|
|
|
|
+ // 读取湿度参数阈值
|
|
|
|
+ SetTemperatureEntity setHumiEntity = setTemperatureRepo.getOne(3);
|
|
|
|
+ String highHumi = setHumiEntity.getHighTemperature();
|
|
|
|
+ String lowHumi = setHumiEntity.getLowTemperature();
|
|
|
|
+ Double highHumiVal = Double.parseDouble(highHumi);
|
|
|
|
+ Double lowHumiVal = Double.parseDouble(lowHumi);
|
|
|
|
+ if(humiVal>highHumiVal){
|
|
|
|
+ // 生成过高湿度报警
|
|
|
|
+ WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
+ warningInfoEntity.setLQID(deviceId);
|
|
|
|
+ warningInfoEntity.setType("出现过高湿度报警:"+humiVal);
|
|
|
|
+ warningInfoEntity.setUploadTime(dateUtil.getTimestamp());
|
|
|
|
+ warningInfoEntity.setWarningType(2);
|
|
|
|
+ warningInfoEntity.setShowStatus(true);
|
|
|
|
+ WarningInfoRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
+ }
|
|
|
|
+ if(humiVal<lowHumiVal){
|
|
|
|
+ // 生成过低湿度报警
|
|
|
|
+ WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
|
|
|
|
+ warningInfoEntity.setLQID(deviceId);
|
|
|
|
+ warningInfoEntity.setType("出现过低湿度报警:"+humiVal);
|
|
|
|
+ warningInfoEntity.setUploadTime(dateUtil.getTimestamp());
|
|
|
|
+ warningInfoEntity.setWarningType(2);
|
|
|
|
+ warningInfoEntity.setShowStatus(true);
|
|
|
|
+ WarningInfoRepo.saveAndFlush(warningInfoEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|