Browse Source

修改测量 接口
修改 提交热点默认icon处理

wuweihao 4 years ago
parent
commit
97fd9d0450

+ 9 - 0
laser/src/main/java/com/fdkankan/indoor/core/controller/PoiController.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -110,4 +111,12 @@ public class PoiController {
         Result result = poiService.deleteByDataId(sceneCode, dataId);
         return result.getData();
     }
+
+    @WebControllerLog(description = "poi热点-上传图标-post")
+    @ApiOperation(value = "上传图标")
+    @PostMapping("indoor/{sceneCode}/poi/image")
+    public Object upload(@PathVariable String sceneCode, MultipartFile image){
+        Result result = poiService.upload(sceneCode, image);
+        return result.getData();
+    }
 }

+ 1 - 1
laser/src/main/java/com/fdkankan/indoor/core/controller/PoiTypeController.java

@@ -54,7 +54,7 @@ public class PoiTypeController {
         return result.getData();
     }
 
-    @WebControllerLog(description = "PoiType-上传图标-put")
+    @WebControllerLog(description = "PoiType-上传图标-post")
     @ApiOperation(value = "上传图标")
     @PostMapping("indoor/{sceneCode}/poi/icon")
     public Object upload(@PathVariable String sceneCode, MultipartFile image){

+ 14 - 0
laser/src/main/java/com/fdkankan/indoor/core/entity/dto/LineDto.java

@@ -0,0 +1,14 @@
+package com.fdkankan.indoor.core.entity.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * Created by owen on 2021/8/23 0023 22:45
+ */
+@Data
+public class LineDto {
+
+    private List<Double[]> coordinates;
+}

+ 9 - 1
laser/src/main/java/com/fdkankan/indoor/core/entity/dto/MeasureGeometry.java

@@ -1,5 +1,6 @@
 package com.fdkankan.indoor.core.entity.dto;
 
+import com.alibaba.fastjson.JSONArray;
 import lombok.Data;
 
 import java.util.List;
@@ -13,7 +14,14 @@ public class MeasureGeometry {
 
     private String type;
 
-    private List<Double[]> coordinates;
+//    private List<List<Double[]>> coordinates; 多边形结构
+//    private List<Double[]> coordinates; 直线
+
+//    private List coordinates;
+    /**直线、多边形的结构不一样,需要用Object接收*/
+    private Object coordinates;
+
+//    private
 
 
 }

+ 3 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/PoiService.java

@@ -4,6 +4,7 @@ import com.fdkankan.indoor.base.util.Result;
 import com.fdkankan.indoor.core.entity.dto.PoiHotDto;
 import com.fdkankan.indoor.core.entity.dto.PoiSearchDto;
 import com.fdkankan.indoor.core.entity.PoiEntity;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -26,4 +27,6 @@ public interface PoiService {
     void remove(String sceneCode);
 
     Result deleteByDataId(String sceneCode, Integer dataId);
+
+    Result upload(String sceneCode, MultipartFile image);
 }

+ 74 - 4
laser/src/main/java/com/fdkankan/indoor/core/service/impl/MeasurementServiceImpl.java

@@ -1,7 +1,11 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.indoor.base.util.Result;
 import com.fdkankan.indoor.core.entity.MeasurementEntity;
+import com.fdkankan.indoor.core.entity.dto.LineDto;
+import com.fdkankan.indoor.core.entity.dto.MeasureGeometry;
 import com.fdkankan.indoor.core.entity.dto.MeasurementDto;
 import com.fdkankan.indoor.core.mapper.MeasurementMapper;
 import com.fdkankan.indoor.core.service.MeasurementService;
@@ -10,10 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -69,6 +70,20 @@ public class MeasurementServiceImpl extends IBaseServiceImpl implements Measurem
                 dto.setId(maxId);
             }
 
+            MeasureGeometry geometry = dto.getGeometry();
+            Object coordinates = geometry.getCoordinates();
+            String type = geometry.getType();
+            if ("LineString".equals(type)){
+                List<Double[]> line = this.line(coordinates.toString());
+                geometry.setCoordinates(line);
+
+                // 多边型
+            } else {
+                List<List<Double[]>> polygon = this.polygon(coordinates.toString());
+                geometry.setCoordinates(polygon);
+            }
+            dto.setGeometry(geometry);
+
             data.add(dto);
             resIds.add(dto.getId());
         }
@@ -83,6 +98,61 @@ public class MeasurementServiceImpl extends IBaseServiceImpl implements Measurem
         return Result.success(changeById(sceneCode,resIds));
     }
 
+
+    private List<Double[]> line(String str ){
+
+        JSONArray array = JSONArray.parseArray(str);
+//        System.out.printf(array.toJSONString());
+        JSONArray a1 = array.getJSONArray(0);
+        JSONArray a2 = array.getJSONArray(1);
+
+        Double a1_0 = a1.getDouble(0);
+        Double a1_1 = a1.getDouble(1);
+        Double a1_2 = a1.getDouble(2);
+
+        Double a2_0 = a2.getDouble(0);
+        Double a2_1 = a2.getDouble(1);
+        Double a2_2 = a2.getDouble(2);
+
+
+        Double[] t1 = {a1_0, a1_1, a1_2};
+        Double[] t2 = {a2_0, a2_1, a2_2};
+
+        List<Double[]> list = new ArrayList<>();
+        list.add(t1);
+        list.add(t2);
+
+        return list;
+    }
+
+    private List<List<Double[]>> polygon(String str ){
+
+        JSONArray array = JSONArray.parseArray(str);
+//        System.out.printf(array.toJSONString());
+
+        List<List<Double[]>>  r2List = new ArrayList<>();
+        for (Object o : array) {
+            JSONArray t1 = JSONArray.parseArray(o.toString());
+
+            List<Double[]> r1List = new ArrayList<>();
+            for (Object o1 : t1) {
+                JSONArray t2 = JSONArray.parseArray(o1.toString());
+//                System.out.printf("");
+
+                Double a1_0 = t2.getDouble(0);
+                Double a1_1 = t2.getDouble(1);
+                Double a1_2 = t2.getDouble(2);
+
+                Double[] r1 = {a1_0, a1_1, a1_2};
+                r1List.add(r1);
+            }
+
+            r2List.add(r1List);
+        }
+
+        return r2List;
+    }
+
     // 把更新后的值,返回给前端
     private List<MeasurementDto> changeById(String sceneCode, List<Integer> resIds){
         List<MeasurementDto> data = getDataBySceneCode(sceneCode);

+ 40 - 2
laser/src/main/java/com/fdkankan/indoor/core/service/impl/PoiServiceImpl.java

@@ -1,5 +1,8 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.indoor.base.constant.MsgCode;
 import com.fdkankan.indoor.base.exception.BaseRuntimeException;
@@ -20,7 +23,9 @@ import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.data.mongodb.core.query.Update;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -60,6 +65,33 @@ public class PoiServiceImpl extends IBaseServiceImpl implements PoiService {
         return Result.success();
     }
 
+    @Override
+    public Result upload(String sceneCode, MultipartFile file) {
+        if (file == null) {
+            throw new RuntimeException("文件为空");
+        }
+        String originalFilename = file.getOriginalFilename();
+        String suffix = StrUtil.subAfter(originalFilename, ".", true);
+
+//        String newName = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS");
+        UUID uuid = UUID.randomUUID();
+        String newName = "poi-" + uuid + "." + suffix;
+
+        String urlPath = "/" + sceneCode + "/poi/image/" + newName;
+        String savePath = configConstant.serverBasePath + urlPath;
+        log.info("保存图片路径:{}", savePath);
+        try {
+            FileUtil.writeFromStream(file.getInputStream(), savePath);
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        HashMap<Object, Object> result = new HashMap<>();
+        result.put("url", newName);
+        return Result.success(result);
+    }
+
 
     @Override
     public Result findBySceneCodeAndId(String code, Integer id) {
@@ -138,7 +170,7 @@ public class PoiServiceImpl extends IBaseServiceImpl implements PoiService {
                 dto.setId(maxId);
             }
 
-            // 通过poi_type_id 去poi_type表找对应icon
+            // 通过poi_type_id 去poi_type表找id对应icon
             if (dto.getIcon() == null) {
                 dto.setIcon(getIcon(sceneCode, dto.getPoi_type_id()));
                 log.info("设置图标:{}", dto.getIcon());
@@ -170,7 +202,12 @@ public class PoiServiceImpl extends IBaseServiceImpl implements PoiService {
 
     private String getIcon(String sceneCode, Integer poiTypeId){
         PoiTypeDto dto = poiTypeService.findBySceneCodeAndPoiTypeId(sceneCode, poiTypeId);
-        return dto.getIcon();
+        if (dto != null) {
+            return dto.getIcon();
+        }
+        log.warn("没有找到对应热点分类信息, 默认icon为空");
+        // 没有返回空
+        return "";
     }
 
     @Override
@@ -248,6 +285,7 @@ public class PoiServiceImpl extends IBaseServiceImpl implements PoiService {
 ////        System.out.println("列表中最小的数 : " + stats.getMin());
 ////        System.out.println("所有数之和 : " + stats.getSum());
 ////        System.out.println("平均数 : " + stats.getAverage());
+        System.out.println(UUID.randomUUID());
 
         numbers.stream().peek(System.out::println).count();
     }

+ 3 - 87
laser/src/main/resources/data/poi_type_group.json

@@ -7,92 +7,8 @@
     },
     "_id" : 1,
     "name" : {
-      "en" : "Access",
-      "zh" : "通道"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 2,
-    "name" : {
-      "en" : "Office",
-      "zh" : "办公场所"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 3,
-    "name" : {
-      "en" : "Transport",
-      "zh" : "交通工具"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 4,
-    "name" : {
-      "en" : "Restrooms",
-      "zh" : "厕所"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 5,
-    "name" : {
-      "en" : "Services",
-      "zh" : "服务区"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 6,
-    "name" : {
-      "en" : "Miscellaneous",
-      "zh" : "其他"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 7,
-    "name" : {
-      "en" : "Safety",
-      "zh" : "安全设施"
-    }
-  },
-  {
-    "security" : {
-      "group_read" : 0,
-      "group_write" : 1,
-      "can_write" : true
-    },
-    "_id" : 8,
-    "name" : {
-      "en" : "VR",
-      "zh" : "多媒体"
+      "en" : "",
+      "zh" : "公共空间"
     }
   }
-]
+]

+ 98 - 0
laser/src/main/resources/data/poi_type_group_1.json

@@ -0,0 +1,98 @@
+[
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 1,
+    "name" : {
+      "en" : "Access",
+      "zh" : "通道"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 2,
+    "name" : {
+      "en" : "Office",
+      "zh" : "办公场所"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 3,
+    "name" : {
+      "en" : "Transport",
+      "zh" : "交通工具"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 4,
+    "name" : {
+      "en" : "Restrooms",
+      "zh" : "厕所"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 5,
+    "name" : {
+      "en" : "Services",
+      "zh" : "服务区"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 6,
+    "name" : {
+      "en" : "Miscellaneous",
+      "zh" : "其他"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 7,
+    "name" : {
+      "en" : "Safety",
+      "zh" : "安全设施"
+    }
+  },
+  {
+    "security" : {
+      "group_read" : 0,
+      "group_write" : 1,
+      "can_write" : true
+    },
+    "_id" : 8,
+    "name" : {
+      "en" : "VR",
+      "zh" : "多媒体"
+    }
+  }
+]