wangchangsheng před 2 roky
rodič
revize
5d97442583

+ 9 - 4
web/backmanagerconfig/src/main/java/com/gyee/backconfig/service/auto/impl/WindpowerstationServiceImpl.java

@@ -12,6 +12,7 @@ import com.gyee.backconfig.service.auto.IWindpowerstationService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gyee.backconfig.service.auto.RedisService;
 import com.gyee.backconfig.util.realtimedate.EdosUtil;
+import com.gyee.backconfig.util.realtimedate.MathUtil;
 import com.gyee.backconfig.vo.WindpowerstationAdmVo;
 import com.gyee.common.model.PointData;
 import com.gyee.common.model.StringUtils;
@@ -128,8 +129,10 @@ public class WindpowerstationServiceImpl extends ServiceImpl<WindpowerstationMap
             Map<String, Windpowerstationpointnew> stringMapMap = JSONObject.parseObject(wpString, new TypeReference<Map<String, Windpowerstationpointnew>>() {
 
             });
-            codes.add(stringMapMap.get("RPJFS").getCode());//日平局风速
-            codes.add(stringMapMap.get("RFDL").getCode());//日发电量
+            if(null !=stringMapMap){
+                codes.add(stringMapMap.get("RPJFS").getCode());//日平局风速
+                codes.add(stringMapMap.get("RFDL").getCode());//日发电量
+            }
             try {
                 List<PointData> pointList = goldenUtil.getRealData(codes);
                 WindpowerstationAdmVo vo = new WindpowerstationAdmVo();
@@ -142,8 +145,10 @@ public class WindpowerstationServiceImpl extends ServiceImpl<WindpowerstationMap
                 vo.setModel(i.getModel());//机型
                 vo.setSystemmanufact(i.getSystemmanufact());//厂家
                 vo.setAddress(i.getAddress());//地址
-                vo.setRfdl(pointList.get(0).getPointValueInDouble());
-                vo.setRfdl(pointList.get(1).getPointValueInDouble());
+                if(null != pointList && pointList.size()>=2){
+                    vo.setRfdl(MathUtil.twoBit(pointList.get(0).getPointValueInDouble()));
+                    vo.setRfdl(MathUtil.twoBit(pointList.get(1).getPointValueInDouble()));
+                }
                 admvos.add(vo);
             } catch (Exception e) {
                 e.printStackTrace();

+ 1 - 2
web/backmanagerconfig/src/main/java/com/gyee/backconfig/util/realtimedate/EdosUtil.java

@@ -20,8 +20,7 @@ import java.util.*;
 public class EdosUtil  implements IEdosUtil {
 
     private RestTemplate restTemplate =new RestTemplate();
-    private static String baseURL = "http://10.155.32.4:8011/ts";
-    //    private static String baseURL = "http://10.65.79.30:8019/ts";
+    private static String baseURL = "http://10.81.3.155:8011/ts";
     @Override
     public PointData getRealData(Windpowerstationpointnew point) throws Exception {
         try {

+ 128 - 0
web/backmanagerconfig/src/main/java/com/gyee/backconfig/util/realtimedate/MathUtil.java

@@ -0,0 +1,128 @@
+package com.gyee.backconfig.util.realtimedate;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author fhq
+ *
+ */
+public class MathUtil {
+
+	// 截取小数点后两位
+	public static Double twoBit(Double dd) {
+		if (dd == null) {
+			return dd;
+		} else {
+			BigDecimal decimal = new BigDecimal(dd);
+			decimal = decimal.setScale(2, BigDecimal.ROUND_HALF_UP);
+			return decimal.doubleValue();
+		}
+	}
+
+	/**
+	 * 格式化小数位数,四舍五入
+	 *
+	 * @param dd
+	 * @param Scale
+	 *            小数位数
+	 * @return
+	 */
+	public static Double decimal(Double dd, int Scale) {
+		return new BigDecimal(dd).setScale(Scale, BigDecimal.ROUND_HALF_UP)
+				.doubleValue();
+	}
+
+	/**
+	 * 格式化小数位数,四舍五入
+	 *
+	 * @param dd
+	 * @param Scale
+	 *            小数位数
+	 * @return 无格式字符串 ,末位去零
+	 */
+	public static String plain(Double dd, int Scale) {
+		if (dd == 0) {
+			return "0";
+		} else {
+			return new BigDecimal(dd).setScale(Scale, BigDecimal.ROUND_HALF_UP)
+					.stripTrailingZeros().toPlainString();
+		}
+	}
+
+	/**
+	 * 字符串转Double
+	 *
+	 * @param value
+	 * @return
+	 */
+	public static Double getDouble(String value) {
+		return new BigDecimal(value).doubleValue();
+	}
+
+	/**
+	 * 格式化小数位数,四舍五入
+	 *
+	 * @param dd
+	 * @param Scale
+	 *            小数位数
+	 * @return
+	 */
+	public static Float decimal(Float dd, int Scale) {
+		return new BigDecimal(dd).setScale(Scale, BigDecimal.ROUND_HALF_UP)
+				.floatValue();
+	}
+
+	/**
+	 * 格式化小数位数,四舍五入
+	 *
+	 * @param dd
+	 * @param Scale
+	 *            小数位数
+	 * @return 无格式字符串
+	 */
+	public static String plain(Float dd, int Scale) {
+		return new BigDecimal(dd).setScale(Scale, BigDecimal.ROUND_HALF_UP)
+				.toPlainString();
+	}
+
+	/**
+	 * 字符串转Float
+	 *
+	 * @param value
+	 * @return
+	 */
+	public static Float getFloat(String value) {
+		return new BigDecimal(value).floatValue();
+	}
+
+	/**
+	 * 将10进制数转换成二进制数
+	 */
+	public static String getBinaryString(Double value) {
+		return Integer.toBinaryString(value.intValue());
+	}
+
+	/**
+	 * 在指定时间上加指定的小时
+	 * @param date
+	 * @param hour
+	 * @return
+	 */
+	public static Date addHours(Date date, double hour) {
+		return new Date(date.getTime() + (long) (hour * 3600 * 1000));
+	}
+
+	public static Integer toInt(String str) {
+		return Integer.parseInt(str);
+	}
+
+	public static Float toFloat(String str) {
+		return Float.parseFloat(str);
+	}
+
+	public static Double toDouble(String str) {
+		return Double.parseDouble(str);
+	}
+
+}