|
@@ -6,6 +6,7 @@ import com.huimv.entity.EnvElectricity;
|
|
import com.huimv.entity.EnvWater;
|
|
import com.huimv.entity.EnvWater;
|
|
import com.huimv.service.IEnvElectricityService;
|
|
import com.huimv.service.IEnvElectricityService;
|
|
import com.huimv.service.IEnvWaterService;
|
|
import com.huimv.service.IEnvWaterService;
|
|
|
|
+import com.huimv.untils.MySQLDemo;
|
|
import com.huimv.untils.SpringUtil;
|
|
import com.huimv.untils.SpringUtil;
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -60,53 +61,48 @@ class PushCallback implements MqttCallback {
|
|
try {
|
|
try {
|
|
System.out.println("开始处理电表数据!");
|
|
System.out.println("开始处理电表数据!");
|
|
String substring = s.substring(6, 14);
|
|
String substring = s.substring(6, 14);
|
|
- System.out.println("截取字符串:"+substring);
|
|
|
|
// IEnvElectricityService electricityService = SpringUtil.getBean(IEnvElectricityService.class);
|
|
// IEnvElectricityService electricityService = SpringUtil.getBean(IEnvElectricityService.class);
|
|
- System.out.println("-------->1");
|
|
|
|
-
|
|
|
|
- EnvElectricity envElectricity = new EnvElectricity();
|
|
|
|
|
|
+ MySQLDemo demo = new MySQLDemo();
|
|
int eleOrigValue = Integer.parseInt(substring, 16);
|
|
int eleOrigValue = Integer.parseInt(substring, 16);
|
|
- System.out.println("整形:"+eleOrigValue);
|
|
|
|
Float f = Float.intBitsToFloat(eleOrigValue);
|
|
Float f = Float.intBitsToFloat(eleOrigValue);
|
|
- System.out.println("浮点:"+f);
|
|
|
|
BigDecimal bigDecimal = new BigDecimal(f);
|
|
BigDecimal bigDecimal = new BigDecimal(f);
|
|
- envElectricity.setOriginalValue(bigDecimal);
|
|
|
|
- envElectricity.setUpdateTime(new Date());
|
|
|
|
- envElectricity.setFarmId(27);
|
|
|
|
- envElectricityService.save(envElectricity);
|
|
|
|
|
|
+ java.util.Date date = new java.util.Date();
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String format = simpleDateFormat.format(date);
|
|
|
|
+ demo.add(format, bigDecimal);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
System.out.println("sssssssss"+ e);
|
|
System.out.println("sssssssss"+ e);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
if (s.startsWith("3303")) {
|
|
if (s.startsWith("3303")) {
|
|
System.out.println("开始处理水表数据!");
|
|
System.out.println("开始处理水表数据!");
|
|
String substring = s.substring(6, 14);
|
|
String substring = s.substring(6, 14);
|
|
- IEnvWaterService waterService = SpringUtil.getBean(IEnvWaterService.class);
|
|
|
|
- EnvWater water = new EnvWater();
|
|
|
|
int eleOrigValue = Integer.parseInt(substring, 16);
|
|
int eleOrigValue = Integer.parseInt(substring, 16);
|
|
BigDecimal value = BigDecimal.valueOf(eleOrigValue * 0.01);
|
|
BigDecimal value = BigDecimal.valueOf(eleOrigValue * 0.01);
|
|
- water.setOriginalValue(value);
|
|
|
|
- water.setUpdateTime(new Date());
|
|
|
|
- water.setFarmId(27);
|
|
|
|
- waterService.save(water);
|
|
|
|
|
|
+ MySQLDemo demo = new MySQLDemo();
|
|
|
|
+ java.util.Date date = new java.util.Date();
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String format = simpleDateFormat.format(date);
|
|
|
|
+ demo.add2(format, value);
|
|
}
|
|
}
|
|
System.out.println("数据处理完成!");
|
|
System.out.println("数据处理完成!");
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
- String s = "1c0404405c0a3d2426";
|
|
|
|
- String substring = s.substring(6, 14);
|
|
|
|
- System.out.println(substring);
|
|
|
|
|
|
+// String s = "1c0404405c0a3d2426";
|
|
|
|
+// String substring = s.substring(6, 14);
|
|
|
|
+// System.out.println(substring);
|
|
|
|
|
|
|
|
+ MySQLDemo mySQLDemo = new MySQLDemo();
|
|
|
|
+ mySQLDemo.select();
|
|
// int eleOrigValue = Integer.parseInt(substring, 16);
|
|
// int eleOrigValue = Integer.parseInt(substring, 16);
|
|
// BigDecimal value = BigDecimal.valueOf(eleOrigValue * 0.01);
|
|
// BigDecimal value = BigDecimal.valueOf(eleOrigValue * 0.01);
|
|
// System.out.println(value);
|
|
// System.out.println(value);
|
|
//
|
|
//
|
|
- int eleOrigValue = Integer.parseInt(substring, 16);
|
|
|
|
- Float f = Float.intBitsToFloat(eleOrigValue);
|
|
|
|
- BigDecimal bigDecimal = new BigDecimal(f);
|
|
|
|
- System.out.println(bigDecimal);
|
|
|
|
|
|
+// int eleOrigValue = Integer.parseInt(substring, 16);
|
|
|
|
+// Float f = Float.intBitsToFloat(eleOrigValue);
|
|
|
|
+// BigDecimal bigDecimal = new BigDecimal(f);
|
|
|
|
+// System.out.println(bigDecimal);
|
|
// Float f = Float.intBitsToFloat(1079773757);
|
|
// Float f = Float.intBitsToFloat(1079773757);
|
|
// System.out.println(f);
|
|
// System.out.println(f);
|
|
//// BigDecimal bigDecimal = new BigDecimal(f);
|
|
//// BigDecimal bigDecimal = new BigDecimal(f);
|