drone-service/drone-gd/src/main/java/org/sxkj/gd/flyer/mapper/GdFlyerMapper.xml
@@ -60,6 +60,10 @@ <if test="param2.skilledTaskType != null and param2.skilledTaskType != ''"> and skilled_task_type = #{param2.skilledTaskType} </if> <if test="param2.areaCode != null and param2.areaCode != ''"> and area_code like concat('%',#{param2.areaCode},'%') </if> <!-- <if test="param2.deptList != null and param2.deptList.size > 0"> --> <!-- AND create_dept in --> <!-- <foreach collection="param2.deptList" item="deptId" open="(" separator="," close=")"> --> drone-service/drone-gd/src/main/java/org/sxkj/gd/flyer/param/GdFlyerPageParam.java
@@ -53,4 +53,7 @@ @ApiModelProperty(value = "部门集合",hidden = true) private List<Long> deptList; @ApiModelProperty(value = "区域编码") private String areaCode; } drone-service/drone-gd/src/main/java/org/sxkj/gd/flyer/service/impl/GdFlyerServiceImpl.java
@@ -17,6 +17,7 @@ package org.sxkj.gd.flyer.service.impl; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.StringUtil; import org.sxkj.gd.flyer.entity.GdFlyerEntity; import org.sxkj.gd.flyer.param.GdFlyerPageParam; import org.sxkj.gd.flyer.vo.GdFlyerVO; @@ -27,6 +28,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.core.mp.base.BaseServiceImpl; import org.sxkj.gd.utils.GdGeoAddressUtil; import org.sxkj.system.cache.SysCache; import java.util.List; @@ -44,6 +46,14 @@ public IPage<GdFlyerVO> selectGdFlyerPage(IPage<GdFlyerVO> page, GdFlyerPageParam gdFlyer) { List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); gdFlyer.setDeptList(deptList); // 通过经纬度获取行政区划 if (StringUtil.isNotBlank(gdFlyer.getLongitude()) && StringUtil.isNotBlank(gdFlyer.getLatitude())) { String areaCode = GdGeoAddressUtil.getCountyCode(Double.valueOf(gdFlyer.getLongitude()), Double.valueOf(gdFlyer.getLatitude())); if (areaCode != null && areaCode.length() > 6) { areaCode = areaCode.substring(0, 6); } gdFlyer.setAreaCode(areaCode); } return page.setRecords(baseMapper.selectGdFlyerPage(page, gdFlyer)); } @@ -51,7 +61,7 @@ @Override public List<GdFlyerExcel> exportGdFlyer(Wrapper<GdFlyerEntity> queryWrapper) { List<GdFlyerExcel> gdFlyerList = baseMapper.exportGdFlyer(queryWrapper); //gdFlyerList.forEach(gdFlyer -> { // gdFlyerList.forEach(gdFlyer -> { // gdFlyer.setTypeName(DictCache.getValue(DictEnum.YES_NO, GdFlyer.getType())); //}); return gdFlyerList; drone-service/drone-gd/src/main/java/org/sxkj/gd/utils/GdGeoAddressUtil.java
@@ -18,6 +18,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.core.tool.utils.StringUtil; @@ -26,7 +27,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import org.springframework.web.util.UriUtils; @Slf4j public class GdGeoAddressUtil { private static final Logger logger = LoggerFactory.getLogger(GdGeoAddressUtil.class); private static final String TIAN_DI_TU_KEY = "9171789c872b8cfee7bba45c35a6b955"; @@ -48,6 +49,26 @@ } } /** * 根据经纬度获取区县代码 * @param longitude 经度 * @param latitude 纬度 * @return 区县代码 */ public static String getCountyCode(Double longitude, Double latitude) { if (longitude == null || latitude == null) { return null; } try { String postStr = String.format("{'lon':%s,'lat':%s,'ver':1}", longitude, latitude); String countyCode = requestCountyCode(postStr); return StringUtil.isBlank(countyCode) ? null : countyCode; } catch (Exception e) { logger.warn("天地图逆地理编码获取区县代码失败", e); return null; } } private static String requestAddress(String postStr) { String encodedPostStr = UriUtils.encodeQueryParam(postStr, StandardCharsets.UTF_8); String url = TIAN_DI_TU_URL + "?postStr=" + encodedPostStr + "&type=geocode&tk=" + TIAN_DI_TU_KEY; @@ -57,6 +78,7 @@ return null; } try { log.debug("天地图逆地理编码结果:{}", response); JsonNode root = OBJECT_MAPPER.readTree(response); String address = root.path("result").path("formatted_address").asText(); return StringUtil.isBlank(address) ? null : address; @@ -65,4 +87,35 @@ return null; } } /** * 请求天地图API获取区县代码 * @param postStr 请求参数 * @return 区县代码 */ private static String requestCountyCode(String postStr) { String encodedPostStr = UriUtils.encodeQueryParam(postStr, StandardCharsets.UTF_8); String url = TIAN_DI_TU_URL + "?postStr=" + encodedPostStr + "&type=geocode&tk=" + TIAN_DI_TU_KEY; URI uri = URI.create(url); String response = REST_TEMPLATE.getForObject(uri, String.class); if (StringUtil.isBlank(response)) { return null; } try { log.debug("天地图逆地理编码结果:{}", response); JsonNode root = OBJECT_MAPPER.readTree(response); String countyCode = root.path("result").path("addressComponent").path("county_code").asText(); return StringUtil.isBlank(countyCode) ? null : countyCode; } catch (Exception e) { logger.warn("解析天地图逆地理编码区县代码失败", e); return null; } } // public static void main(String[] args) { // String formattedAddress = getFormattedAddress(116.39742, 39.90923); // String countyCode = getCountyCode(116.39742, 39.90923); // System.out.println("地址:" + formattedAddress); // System.out.println("区县代码:" + countyCode); // } }