Browse Source

15天水量

lihui001 3 years ago
parent
commit
eb9afc6181

+ 126 - 9
zoniot-common/zoniot-core-utils/src/main/java/com/zcxk/core/utils/BigDecimalUtils.java

@@ -12,12 +12,65 @@ import java.math.RoundingMode;
 public class BigDecimalUtils {
 
 
+    /**
+    * 转换BigDecimal,如value==null,直接返回null
+    * @author Andy
+    * @date 17:20 2021/9/9
+    * @param value:
+    * @return java.math.BigDecimal
+    **/
+    public static BigDecimal convert(Object value){
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof BigDecimal) {
+            return (BigDecimal) value;
+        }
+        return new BigDecimal(value.toString());
+    }
+
+    /**
+    * 转换BigDecimal,如value==null,返回初始值0
+    * @author Andy
+    * @date 17:21 2021/9/9
+    * @param value:
+    * @return java.math.BigDecimal
+    **/
+    public static BigDecimal convertDefault(Object value){
+        if (value == null) {
+            return new BigDecimal("0");
+        }
+        if (value instanceof BigDecimal) {
+            return (BigDecimal) value;
+        }
+        return new BigDecimal(value.toString());
+    }
+
+
+    /**
+    * 百分比计算,不进行四舍五入
+    * @author Andy
+    * @date 17:00 2021/9/9
+    * @param value:
+    * @param value2:
+    * @param scale:
+    * @return java.lang.String
+    **/
     public static String percentDivideDown(Object value, Object value2, int scale){
-        return divideDown(value, value2, scale).multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%";
+        return divideDown(value, value2, scale).multiply(convert("100")).stripTrailingZeros().toPlainString() + "%";
     }
 
+    /**
+    * 百分比计算,进行四舍五入
+    * @author Andy
+    * @date 17:01 2021/9/9
+    * @param value:
+    * @param value2:
+    * @param scale:
+    * @return java.lang.String
+    **/
     public static String percentDivide(Object value, Object value2, int scale){
-        return divide(value, value2, scale).multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%";
+        return divide(value, value2, scale).multiply(convert("100")).stripTrailingZeros().toPlainString() + "%";
     }
 
     /**
@@ -28,7 +81,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal divideDown(Object value, Object value2, int scale){
-        return new BigDecimal(value.toString()).divide(new BigDecimal(value2.toString()), scale, RoundingMode.DOWN);
+        return convertDefault(value).divide(convertDefault(value2), scale, RoundingMode.DOWN);
     }
 
     /**
@@ -39,7 +92,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal divide(Object value, Object value2, int scale){
-        return new BigDecimal(value.toString()).divide(new BigDecimal(value2.toString()), scale, RoundingMode.HALF_UP);
+        return convertDefault(value).divide(convertDefault(value2), scale, RoundingMode.HALF_UP);
     }
 
     public static double divideToDouble(Object value, Object value2, int scale){
@@ -47,7 +100,7 @@ public class BigDecimalUtils {
     }
 
     public static BigDecimal setScale(Object value, int scale){
-        return new BigDecimal(value.toString()).setScale(scale, BigDecimal.ROUND_HALF_UP);
+        return convertDefault(value).setScale(scale, BigDecimal.ROUND_HALF_UP);
     }
 
 
@@ -63,7 +116,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal multiply(Object value, Object value2){
-        return multiply(new BigDecimal(value.toString()), new BigDecimal(value2.toString()), 2);
+        return multiply(convertDefault(value), convertDefault(value2), 2);
     }
 
     /**
@@ -75,7 +128,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal subtract(Object value, Object value2){
-        return subtract(new BigDecimal(value.toString()), new BigDecimal(value2.toString()));
+        return subtract(convert(value), convert(value2));
     }
 
     /**
@@ -107,7 +160,7 @@ public class BigDecimalUtils {
     * @return java.math.BigDecimal
     **/
     public static BigDecimal add(Object value, Object value2){
-        return new BigDecimal(value.toString()).add(new BigDecimal(value2.toString()));
+        return convertDefault(value).add(convertDefault(value2));
     }
 
     /**
@@ -125,7 +178,71 @@ public class BigDecimalUtils {
         if (value == null || value2 == null) {
             return false;
         }
-        return new BigDecimal(value.toString()).compareTo(new BigDecimal(value2.toString())) == 0;
+        return convert(value).compareTo(convert(value2)) == 0;
+    }
+
+    /**
+    * 大于等于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean gte(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) > -1;
+    }
+
+    /**
+    * 大于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean gt(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) == 1;
     }
 
+    /**
+    * 小于等于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean lte(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) < 1;
+    }
+
+    /**
+    * 小于
+    * @author Andy
+    * @date 17:04 2021/9/9
+    * @param value:
+    * @param value2:
+    * @return boolean
+    **/
+    public static boolean lt(Object value, Object value2) {
+        if (value == null || value2 == null) {
+            return false;
+        }
+        return convert(value).compareTo(convert(value2)) == -1;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(new BigDecimal("12.150"));
+        System.out.println(convert(12.150 + ""));
+    }
 }

+ 4 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/DeviceServiceImpl.java

@@ -50,6 +50,8 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.text.NumberFormat;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -434,7 +436,7 @@ public class DeviceServiceImpl implements DeviceService{
      **/
     private void ratioDevice(List<DeviceStatisticsVo.DeviceRatio> ratioList, int total){
         for (DeviceStatisticsVo.DeviceRatio ratio : ratioList) {
-            ratio.setRatio(BigDecimalUtils.percentDivide(ratio.getTotal(), total, 2));
+            ratio.setRatio(BigDecimalUtils.percentDivide(ratio.getTotal(), total, 4));
         }
     }
 
@@ -568,4 +570,5 @@ public class DeviceServiceImpl implements DeviceService{
     public List<DeviceVo> queryDeviceInfoList(String deviceNo, String meterNo) {
         return deviceMapper.queryDeviceInfoList(deviceNo,meterNo,UserUtil.getCurrentUser().getUserCondition());
     }
+
 }

+ 1 - 0
zoniot-water/zoniot-water-web/pom.xml

@@ -68,6 +68,7 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-amqp</artifactId>
         </dependency>
+
     </dependencies>
 
     <build>

+ 1 - 1
zoniot-water/zoniot-water-web/src/main/java/com/zcxk/water/web/ZoniotWaterApplication.java

@@ -21,7 +21,7 @@ import java.net.UnknownHostException;
 @SpringBootApplication(scanBasePackages="com.zcxk")
 @EnableSwagger2
 @MapperScan("com.zcxk.water.core.dao")
-@EnableFeignClients
+@EnableFeignClients("com.zcxk")
 @Slf4j
 public class ZoniotWaterApplication {
 

+ 4 - 0
zoniot-water/zoniot-water-web/src/main/java/com/zcxk/water/web/config/FeignConfig.java

@@ -16,6 +16,8 @@ import javax.servlet.http.HttpServletRequest;
  */
 @Configuration
 public class FeignConfig implements RequestInterceptor {
+
+
     @Override
     public void apply(RequestTemplate requestTemplate) {
         ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
@@ -26,4 +28,6 @@ public class FeignConfig implements RequestInterceptor {
             }
         }
     }
+
+
 }

+ 5 - 0
zoniot-water/zoniot-water-web/src/main/java/com/zcxk/water/web/controller/WaterPropertyController.java

@@ -1,6 +1,8 @@
 package com.zcxk.water.web.controller;
 
 
+import com.zcxk.rmcp.api.dto.meterreadrecord.MeterReadRecordSyncDto;
+import com.zcxk.rmcp.api.feign.MeterReadRecordClient;
 import com.zcxk.water.core.entity.WaterPropertyEntity;
 import com.zcxk.water.web.service.WaterPropertyService;
 import com.zcxk.core.common.pojo.AjaxMessage;
@@ -12,6 +14,8 @@ import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -72,4 +76,5 @@ public class WaterPropertyController {
         }
         return AjaxMessage.success( waterPropertyService.save(waterPropertyList));
     }
+
 }