Browse Source

项目类新增项目坐标 新增坐标转换工具类

hxf 2 năm trước cách đây
mục cha
commit
68585d4449

+ 2 - 0
neim-biz/src/main/java/com/jiayue/biz/domain/ProjectInfo.java

@@ -17,6 +17,8 @@ import java.util.List;
 public class ProjectInfo {
 
     private String id;
+    //项目经纬度
+    private String position;
     //基本信息
     private ProjectBasicInfo projectBasicInfo;
     //关联设备

+ 6 - 3
neim-biz/src/main/java/com/jiayue/biz/service/impl/HomePageServiceImpl.java

@@ -2,6 +2,7 @@ package com.jiayue.biz.service.impl;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.db.Entity;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jiayue.biz.domain.*;
@@ -929,10 +930,12 @@ public class HomePageServiceImpl extends ServiceImpl<WindTowerDataParentTableMap
         List<ProjectInfo> projectInfoList = projectInfoService.getProjectInfoList();
         for (ProjectInfo projectInfo : projectInfoList) {
             if (projectInfo.getEquipment() != null && projectInfo.getEquipment().size() > 0) {
-                Equipment equipment = projectInfo.getEquipment().get(0);
                 HashMap<String, Object> map = new HashMap<>();
-                map.put("longitude", equipment.getLongitude());
-                map.put("latitude", equipment.getLatitude());
+                if (StrUtil.isNotBlank(projectInfo.getPosition())) {
+                    String[] split = projectInfo.getPosition().split(",");
+                    map.put("longitude", split[0]);
+                    map.put("latitude", split[1]);
+                }
                 map.put("id", projectInfo.getId());
                 map.put("projectNameEasy", projectInfo.getProjectBasicInfo().getProjectNameEasy());
                 map.put("projectName", projectInfo.getProjectBasicInfo().getProjectName());

+ 63 - 0
neim-biz/src/main/java/com/jiayue/biz/util/CoordinateUtil.java

@@ -0,0 +1,63 @@
+package com.jiayue.biz.util;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class CoordinateUtil {
+
+    /**
+     * 将经纬度转换为度分秒格式
+     *
+     * @param du 116.418847
+     * @return 116°25'7.85"
+     */
+    public static String changeToDFM(double du) {
+        int du1 = (int)du;
+        double tp = (du - du1) * 60;
+        int fen = (int)tp;
+        String miao = String.format("%.2f", Math.abs(((tp - fen) * 60)));
+        return du1 + "°" + Math.abs(fen) + "′" + miao + "″";
+    }
+
+    /**
+     * 度分秒转经纬度
+     *
+     * @param dms 116°25'7.85"
+     * @return 116.418847
+     */
+    public static double changeToDu(String dms) {
+        if (dms == null)
+            return 0;
+        try {
+            dms = dms.replace(" ", "");
+            String[] str2 = dms.split("°");
+            if (str2.length < 2)
+                return 0;
+            int d = Integer.parseInt(str2[0]);
+            String[] str3 = str2[1].split("′");
+            if (str3.length < 2)
+                return 0;
+            int f = Integer.parseInt(str3[0]);
+            String str4 = str3[1].substring(0, str3[1].length() - 1);
+            BigDecimal m = new BigDecimal(str4);
+            BigDecimal fen = BigDecimal.valueOf(f).add(m.divide(BigDecimal.valueOf(60), 8, RoundingMode.HALF_UP));
+            BigDecimal du =
+                    fen.divide(BigDecimal.valueOf(60), 8, RoundingMode.HALF_UP).add(BigDecimal.valueOf(Math.abs(d)));
+            if (du.compareTo(BigDecimal.ZERO) < 0) {
+                return -du.doubleValue();
+            }
+            return du.doubleValue();
+            //            double m = Double.parseDouble(str4);
+            //
+            //            double fen = f + (m / 60);
+            //            double du = (fen / 60) + Math.abs(d);
+            //            if (d < 0)
+            //                du = -du;
+            //            return du;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return 0;
+    }
+
+}