Forráskód Böngészése

更新字段,增加实体类字段,转换数值类型

zhuoning 4 éve
szülő
commit
6193d30d69

+ 13 - 1
huimv-test-platform/huimv-ctwing/pom.xml

@@ -11,5 +11,17 @@
 
     <artifactId>huimv-ctwing</artifactId>
 
-
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 </project>

+ 37 - 1
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/entity/DeviceUpdataEntity.java

@@ -63,6 +63,15 @@ public class DeviceUpdataEntity implements Serializable {
     @Column(name = "tenant_id")
     private String tenantId;
 
+    @Column(name = "convert_temp")
+    private double convertTemp;
+
+    @Column(name = "convert_humi")
+    private double convertHumi;
+
+    @Column(name = "convert_bat")
+    private double convertBat;
+
     public void setId(Integer id) {
         this.id = id;
     }
@@ -207,13 +216,37 @@ public class DeviceUpdataEntity implements Serializable {
         this.tenantId = tenantId;
     }
 
+    public double getConvertTemp() {
+        return convertTemp;
+    }
+
+    public void setConvertTemp(double convertTemp) {
+        this.convertTemp = convertTemp;
+    }
+
+    public double getConvertHumi() {
+        return convertHumi;
+    }
+
+    public void setConvertHumi(double convertHumi) {
+        this.convertHumi = convertHumi;
+    }
+
+    public double getConvertBat() {
+        return convertBat;
+    }
+
+    public void setConvertBat(double convertBat) {
+        this.convertBat = convertBat;
+    }
+
     @Override
     public String toString() {
         return "DeviceUpdataEntity{" +
                 "id=" + id +
                 ", productId='" + productId + '\'' +
                 ", deviceId='" + deviceId + '\'' +
-                ", timestamp=" + timestamp +
+                ", timestamp='" + timestamp + '\'' +
                 ", serviceId='" + serviceId + '\'' +
                 ", protocol='" + protocol + '\'' +
                 ", imsi='" + imsi + '\'' +
@@ -228,6 +261,9 @@ public class DeviceUpdataEntity implements Serializable {
                 ", dataHumi=" + dataHumi +
                 ", dataBat=" + dataBat +
                 ", tenantId='" + tenantId + '\'' +
+                ", convertTemp=" + convertTemp +
+                ", convertHumi=" + convertHumi +
+                ", convertBat=" + convertBat +
                 '}';
     }
 }

+ 9 - 1
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/service/impl/DeviceDataServiceImpl.java

@@ -8,6 +8,7 @@ import com.huimv.devicedata.repo.DeviceResponseEntityRepository;
 import com.huimv.devicedata.repo.DeviceUpdataEntityRepository;
 import com.huimv.devicedata.service.IDeviceDataService;
 import com.huimv.devicedata.utils.DateUtil;
+import com.huimv.devicedata.utils.MathUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -29,7 +30,8 @@ public class DeviceDataServiceImpl implements IDeviceDataService {
     private DeviceUpdataEntityRepository deviceUpdataEntityRepo;
     @Autowired
     private DateUtil dateUtil;
-
+    @Autowired
+    private MathUtil mathUtil;
     @Autowired
     private DeviceResponseEntityRepository deviceResponseEntityRepo;
 
@@ -72,6 +74,12 @@ public class DeviceDataServiceImpl implements IDeviceDataService {
         deviceUpdataEntity.setDataHumi(dataHumi);
         deviceUpdataEntity.setDataBat(dataBat);
         deviceUpdataEntity.setTenantId(tenantId);
+        deviceUpdataEntity.setConvertTemp(mathUtil.formatDecimalNumber(dataTemp*0.1,1));
+        deviceUpdataEntity.setConvertHumi(mathUtil.formatDecimalNumber(dataHumi*0.1,1));
+        deviceUpdataEntity.setConvertBat(mathUtil.formatDecimalNumber(dataBat*0.01,1));
+        System.out.println("dataTemp/10:"+mathUtil.formatDecimalNumber(dataTemp*0.1,1));
+        System.out.println("dataHumi/10:"+mathUtil.formatDecimalNumber(dataHumi*0.1,1));
+        System.out.println("dataBat/10:"+mathUtil.formatDecimalNumber(dataBat*0.01,1));
         //
         deviceUpdataEntityRepo.saveAndFlush(deviceUpdataEntity);
     }

+ 34 - 0
huimv-test-platform/huimv-ctwing/src/main/java/com/huimv/devicedata/utils/MathUtil.java

@@ -0,0 +1,34 @@
+package com.huimv.devicedata.utils;
+
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class MathUtil {
+    
+    /**
+     * @Method      : formatDecimalNumber
+     * @Description : 格式化小数精度,保留N位小数
+     * @Params      : [inNum, n]
+     * @Return      : double
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/4/7       
+     * @Time        : 20:27
+     */
+    public double formatDecimalNumber(double inNum,int n){
+        BigDecimal b   =   new   BigDecimal(inNum);
+        return  b.setScale(n,   BigDecimal.ROUND_HALF_UP).doubleValue();
+    }
+
+
+}

+ 33 - 0
huimv-test-platform/huimv-ctwing/src/test/java/com/huimv/devicedata/ConvertUtil.java

@@ -0,0 +1,33 @@
+package com.huimv.devicedata;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.math.BigDecimal;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ConvertUtil {
+
+    @Test
+    public void testIntConvert(){
+//        System.out.println("testIntConvert");
+        int temp= 142;
+        double result = temp*0.1;
+        BigDecimal b   =   new   BigDecimal(result);
+        double   f1   =   b.setScale(1,   BigDecimal.ROUND_HALF_UP).doubleValue();
+        System.out.println(f1);
+    }
+}

+ 1 - 0
huimv-test-platform/pom.xml

@@ -5,6 +5,7 @@
     <packaging>pom</packaging>
     <modules>
         <module>huimv-ctwing</module>
+        <module>huimv-ctwing-manage</module>
     </modules>
     <parent>
         <groupId>org.springframework.boot</groupId>