|
@@ -0,0 +1,63 @@
|
|
|
+package com.citygis.base.boot.controller;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import lombok.Builder;
|
|
|
+import lombok.Data;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+public class Test {
|
|
|
+ @Autowired
|
|
|
+ private GridPartitioningProperties properties;
|
|
|
+
|
|
|
+ @Data
|
|
|
+ @Builder
|
|
|
+ static class PartitionInfo {
|
|
|
+ private Integer longitudePartition;
|
|
|
+ private Integer latitudePartition;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PartitionInfo calculatePartitionNumber(String x, String y) {
|
|
|
+ Integer longitudePartition = calculateLongitude(x, LongitudeLatitudeEnum.LONGITUDE);
|
|
|
+ Integer latitudePartition = calculateLongitude(y, LongitudeLatitudeEnum.LATITUDE);
|
|
|
+ return PartitionInfo.builder()
|
|
|
+ .longitudePartition(longitudePartition)
|
|
|
+ .latitudePartition(latitudePartition)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ enum LongitudeLatitudeEnum {
|
|
|
+ LONGITUDE(),
|
|
|
+ LATITUDE()
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer calculateLongitude(String value, LongitudeLatitudeEnum type) {
|
|
|
+ Map<Integer, Integer> longitudeDegreeMap = properties.getLongitudeDegreeMap();
|
|
|
+ Map<Integer, Integer> latitudeDegreeMap = properties.getLatitudeDegreeMap();
|
|
|
+ String[] degreeAndMinutes = value.replace("′", "").replace("′", "").split("°");
|
|
|
+ Integer degree = Integer.parseInt(degreeAndMinutes[0]);
|
|
|
+ Integer minutes = Integer.parseInt(degreeAndMinutes[1]);
|
|
|
+ Integer quickCalculationDeduction = 0;
|
|
|
+ Integer result = 0;
|
|
|
+ switch (type) {
|
|
|
+ case LONGITUDE:
|
|
|
+ quickCalculationDeduction = longitudeDegreeMap.get(degree);
|
|
|
+ break;
|
|
|
+ case LATITUDE:
|
|
|
+ quickCalculationDeduction = latitudeDegreeMap.get(degree);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ result = quickCalculationDeduction + minutes;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/config/{x}&&{y}")
|
|
|
+ public Object config(@PathVariable String x, @PathVariable String y) throws JsonProcessingException {
|
|
|
+ return calculatePartitionNumber(x, y);
|
|
|
+ }
|
|
|
+}
|