吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package org.sxkj.odm.service.impl;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.sxkj.odm.config.PyToolsServiceProperties;
import org.sxkj.odm.constant.TifConstant;
import org.sxkj.odm.service.PyTifSendRequest;
import org.sxkj.odm.service.WhiteFilmGeoJsoService;
 
import java.util.HashMap;
import java.util.Map;
 
@Service
@Slf4j
public class WhiteFilmGeoJsoServiceImpl implements WhiteFilmGeoJsoService {
 
    @Autowired
    private PyTifSendRequest pyTifSendRequest;
 
    @Autowired
    private PyToolsServiceProperties pyToolsServiceProperties;
 
    /**
     * 获取建筑白膜模型的 GeoJSON 数据
     *
     * @param districtCode 行政区划code (可选)
     * @param orgId        机构id (可选)
     * @return GeoJSON 格式的建筑白膜数据
     */
    @Override
    public String getBuildingWhiteFilmGeoJson(String districtCode, String orgId) {
        try {
            // 构建请求URL
            String baseUrl = getBaseUrl(); // 根据当前环境选择 BASE_URL_DEV, BASE_URL_TEST 或 BASE_URL_PROD
            String url = baseUrl + TifConstant.GET_GEOJSON_API;
 
            // 构建请求参数
            Map<String, Object> params = new HashMap<>();
            if (districtCode != null) {
                params.put("district_code", districtCode);
            }
            if (orgId != null) {
                params.put("org_id", orgId);
            }
            // 发起HTTP GET请求
            String geojsonData = pyTifSendRequest.sendGetJsonByMap(url, params);
 
            // 记录成功日志
            log.info("成功获取建筑白膜 GeoJSON 数据");
 
            return geojsonData;
 
        } catch (Exception e) {
            log.error("获取建筑白膜数据失败: {}", e.getMessage(), e);
            throw new RuntimeException("获取建筑白膜数据失败", e);
        }
    }
 
    /**
     * 网格生成geojson接口
     * @param districtCode
     * @param orgId
     * @return
     */
    @Override
    public String getAreaGridFilmGeoJson(String districtCode, String orgId) {
        try {
            // 构建请求URL
            String baseUrl = getBaseUrl(); // 根据当前环境选择 BASE_URL_DEV, BASE_URL_TEST 或 BASE_URL_PROD
            String url = baseUrl + TifConstant.GET_GRID_GEOJSON_API;
 
            // 构建请求参数
            Map<String, Object> params = new HashMap<>();
            if (districtCode != null) {
                params.put("district_code", districtCode);
            }
            if (orgId != null) {
                params.put("org_id", orgId);
            }
            // 发起HTTP GET请求
            String geojsonData = pyTifSendRequest.sendGetJsonByMap(url, params);
 
            // 记录成功日志
            log.info("成功获取建筑白膜 GeoJSON 数据");
 
            return geojsonData;
 
        } catch (Exception e) {
            log.error("获取建筑白膜数据失败: {}", e.getMessage(), e);
            throw new RuntimeException("获取建筑白膜数据失败", e);
        }
    }
 
    // 辅助方法:根据当前环境选择基础URL
    private String getBaseUrl() {
        String url = pyToolsServiceProperties.getPyToolsService();
        return url;
    }
}