|
|
|
@ -9,6 +9,7 @@ |
|
|
|
package com.elink.esua.epdc.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.json.XML; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
@ -54,7 +55,13 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URLConnection; |
|
|
|
import java.util.*; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
@ -1332,6 +1339,86 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptDao, SysDeptEntit |
|
|
|
return new Result<List<SysDeptResultDTO>>().ok(childSortMenu); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<DeptItudeResultDTO> getDeptIdByItude(DeptItudeFormDTO dto) { |
|
|
|
String communityCode = getDeptAreaCodeByItude(dto); |
|
|
|
if(StringUtils.isBlank(communityCode)){ |
|
|
|
throw new RenException("暂未获取到相关社区信息,请重新选择地址后重试!"); |
|
|
|
} |
|
|
|
SysDeptEntity community = baseDao.selectByAreaCode(communityCode); |
|
|
|
DeptItudeResultDTO result = new DeptItudeResultDTO(); |
|
|
|
result.setCommunityId(community.getId()); |
|
|
|
result.setStreetId(community.getPid()); |
|
|
|
return new Result<DeptItudeResultDTO>().ok(result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @describe: 访问外部接口获取部门(社区)地区编码 |
|
|
|
* @author wangtong |
|
|
|
* @date 2022/8/31 13:47 |
|
|
|
* @params [dto] |
|
|
|
* @return java.lang.String |
|
|
|
*/ |
|
|
|
private String getDeptAreaCodeByItude(DeptItudeFormDTO dto){ |
|
|
|
String responseBody = ""; |
|
|
|
try { |
|
|
|
// 1 指定WebService服务的请求地址:
|
|
|
|
String wsUrl = "http://120.221.72.15:9089/WebService1.asmx/JW2DSJ?x="+dto.getLatitude()+"&y="+dto.getLongitude(); |
|
|
|
// 2 创建URL:
|
|
|
|
URL url = new URL(wsUrl); |
|
|
|
// 3 建立连接,并将连接强转为Http连接
|
|
|
|
URLConnection conn = url.openConnection(); |
|
|
|
HttpURLConnection con = (HttpURLConnection) conn; |
|
|
|
|
|
|
|
//设置请求方式和请求头:
|
|
|
|
con.setDoInput(true); // 是否有入参
|
|
|
|
con.setDoOutput(true); // 是否有出参
|
|
|
|
con.setRequestMethod("GET"); // 设置请求方式
|
|
|
|
con.setRequestProperty("content-type", "text/xml;charset=UTF-8"); |
|
|
|
// 7,服务端返回正常:
|
|
|
|
int code = con.getResponseCode(); |
|
|
|
if (code == 200) {// 服务端返回正常
|
|
|
|
InputStream is = con.getInputStream(); |
|
|
|
byte[] b = new byte[1024]; |
|
|
|
StringBuffer sb = new StringBuffer(); |
|
|
|
int len = 0; |
|
|
|
while ((len = is.read(b)) != -1) { |
|
|
|
String str = new String(b, 0, len, "UTF-8"); |
|
|
|
sb.append(str); |
|
|
|
} |
|
|
|
responseBody = sb.toString(); |
|
|
|
// responseBody中的数据格式为xml
|
|
|
|
is.close(); |
|
|
|
} |
|
|
|
con.disconnect(); |
|
|
|
//使用hutool工具类,取出在xml结点中的最终数据
|
|
|
|
cn.hutool.json.JSONObject json = XML.toJSONObject(responseBody); |
|
|
|
DeptAreaResultDTO reobject = json.toBean(DeptAreaResultDTO.class); |
|
|
|
String restring = reobject.getString().getContent(); |
|
|
|
return restring.substring(getFromIndex(restring,",",3)+1,getFromIndex(restring,",",4)); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw new RenException("暂未获取到相关社区信息,请重新选择地址!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//子字符串modelStr在字符串str中第count次出现时的下标
|
|
|
|
public static int getFromIndex(String str, String modelStr, Integer count) { |
|
|
|
//对子字符串进行匹配
|
|
|
|
Matcher slashMatcher = Pattern.compile(modelStr).matcher(str); |
|
|
|
int index = 0; |
|
|
|
//matcher.find();尝试查找与该模式匹配的输入序列的下一个子序列
|
|
|
|
while(slashMatcher.find()) { |
|
|
|
index++; |
|
|
|
//当modelStr字符第count次出现的位置
|
|
|
|
if(index == count){ |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
//matcher.start();返回以前匹配的初始索引。
|
|
|
|
return slashMatcher.start(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建树节点 |
|
|
|
*/ |
|
|
|
|