|
@@ -1,15 +1,9 @@
|
|
|
package cn.reghao.tnb.content.app.geo.controller;
|
|
package cn.reghao.tnb.content.app.geo.controller;
|
|
|
|
|
|
|
|
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
|
|
import cn.reghao.jutil.web.WebResult;
|
|
import cn.reghao.jutil.web.WebResult;
|
|
|
-import cn.reghao.tnb.content.app.geo.db.mapper.GeoChinaMapper;
|
|
|
|
|
-import cn.reghao.tnb.content.app.geo.model.po.GeoJson;
|
|
|
|
|
import cn.reghao.tnb.content.app.geo.model.vo.ChartMap;
|
|
import cn.reghao.tnb.content.app.geo.model.vo.ChartMap;
|
|
|
-import cn.reghao.tnb.content.app.geo.model.vo.ChartMapData;
|
|
|
|
|
import cn.reghao.tnb.content.app.geo.model.vo.SelectOption;
|
|
import cn.reghao.tnb.content.app.geo.model.vo.SelectOption;
|
|
|
-import cn.reghao.tnb.content.app.util.RandomUtil;
|
|
|
|
|
-import com.google.gson.JsonElement;
|
|
|
|
|
-import com.google.gson.JsonObject;
|
|
|
|
|
|
|
+import cn.reghao.tnb.content.app.geo.service.ChartMapService;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -17,60 +11,34 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2025-08-19 15:59:13
|
|
* @date 2025-08-19 15:59:13
|
|
|
*/
|
|
*/
|
|
|
-@Tag(name = "地图接口")
|
|
|
|
|
|
|
+@Tag(name = "数据地图接口")
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api/geo/chartmap")
|
|
@RequestMapping("/api/geo/chartmap")
|
|
|
public class ChartMapController {
|
|
public class ChartMapController {
|
|
|
- private final GeoChinaMapper geoChinaMapper;
|
|
|
|
|
|
|
+ private final ChartMapService chartMapService;
|
|
|
|
|
|
|
|
- public ChartMapController(GeoChinaMapper geoChinaMapper) {
|
|
|
|
|
- this.geoChinaMapper = geoChinaMapper;
|
|
|
|
|
|
|
+ public ChartMapController(ChartMapService chartMapService) {
|
|
|
|
|
+ this.chartMapService = chartMapService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping(value = "/area", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@GetMapping(value = "/area", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public String getGeoJsonList() {
|
|
public String getGeoJsonList() {
|
|
|
- List<GeoJson> list = geoChinaMapper.findGeoJsonObject();
|
|
|
|
|
- List<SelectOption> selectOptionList = list.stream().map(geoJson -> {
|
|
|
|
|
- String name = geoJson.getName();
|
|
|
|
|
- int areaCode = geoJson.getAreaCode();
|
|
|
|
|
- int deep = geoJson.getDeep();
|
|
|
|
|
- String label = String.format("%s-%s", name, deep);
|
|
|
|
|
- String value = String.format("%s-%s", areaCode, deep);
|
|
|
|
|
- return new SelectOption(label, value);
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
|
|
+ List<SelectOption> selectOptionList = chartMapService.getAreaNameValue();
|
|
|
return WebResult.success(selectOptionList);
|
|
return WebResult.success(selectOptionList);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping(value = "/geojson", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@GetMapping(value = "/geojson", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public String getGeoJson(@RequestParam("areaCode") String areaCodeStr) {
|
|
public String getGeoJson(@RequestParam("areaCode") String areaCodeStr) {
|
|
|
- // /chartmap/geojson
|
|
|
|
|
String[] arr = areaCodeStr.split("-");
|
|
String[] arr = areaCodeStr.split("-");
|
|
|
int areaCode = Integer.parseInt(arr[0]);
|
|
int areaCode = Integer.parseInt(arr[0]);
|
|
|
int deep = Integer.parseInt(arr[1]);
|
|
int deep = Integer.parseInt(arr[1]);
|
|
|
- String geoJson = geoChinaMapper.findGeoJson(areaCode, deep);
|
|
|
|
|
- List<ChartMapData> chartMapDataList = parseGeoJson(geoJson);
|
|
|
|
|
- ChartMap chartMap = new ChartMap(geoJson, chartMapDataList);
|
|
|
|
|
|
|
+ ChartMap chartMap = chartMapService.getChartMap(areaCode, deep);
|
|
|
return WebResult.success(chartMap);
|
|
return WebResult.success(chartMap);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private List<ChartMapData> parseGeoJson(String geoJson) {
|
|
|
|
|
- List<ChartMapData> list = new ArrayList<>();
|
|
|
|
|
- JsonObject jsonObject = JsonConverter.jsonToJsonElement(geoJson).getAsJsonObject();
|
|
|
|
|
- for (JsonElement jsonElement : jsonObject.get("features").getAsJsonArray()) {
|
|
|
|
|
- JsonObject propertiesObject = jsonElement.getAsJsonObject().get("properties").getAsJsonObject();
|
|
|
|
|
- int adcode = propertiesObject.get("adcode").getAsInt();
|
|
|
|
|
- String name = propertiesObject.get("name").getAsString();
|
|
|
|
|
- list.add(new ChartMapData(name, RandomUtil.getRandomNumber(1000)));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return list;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|