Commit 86fac754 by yangliang

修改全国案件调用

parent 8f9bfa49
...@@ -3,6 +3,7 @@ package com.founder.controller; ...@@ -3,6 +3,7 @@ package com.founder.controller;
import com.founder.model.User; import com.founder.model.User;
import com.founder.util.propertiesUtil; import com.founder.util.propertiesUtil;
import com.founder.utils.PropertiesUtil; import com.founder.utils.PropertiesUtil;
import com.founder.utils.Utils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
...@@ -42,9 +43,9 @@ public class CallDygabxxfw { ...@@ -42,9 +43,9 @@ public class CallDygabxxfw {
* @param jsonStr * @param jsonStr
* @return * @return
*/ */
@RequestMapping("/getGabZyInfo") @RequestMapping("/getGabZyInfo_bak")
@ResponseBody @ResponseBody
public Map<String,Object> getGabZyInfo(String zylx,String jsonStr) { public Map<String,Object> getGabZyInfo_bak(String zylx,String jsonStr) {
//"fzxyr", "[{\"ZHFZXYR_CYZJ_ZJHM\":\"" + zjhm + "\"}]" //"fzxyr", "[{\"ZHFZXYR_CYZJ_ZJHM\":\"" + zjhm + "\"}]"
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
try { try {
...@@ -65,6 +66,7 @@ public class CallDygabxxfw { ...@@ -65,6 +66,7 @@ public class CallDygabxxfw {
httpPost.setEntity(entity); httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost); CloseableHttpResponse response = httpClient.execute(httpPost);
System.out.println("response.getStatusLine().getStatusCode()======" + response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String jsonResult = EntityUtils.toString(response.getEntity(), "utf-8"); String jsonResult = EntityUtils.toString(response.getEntity(), "utf-8");
System.out.println("map=jsonResult===" + jsonResult); System.out.println("map=jsonResult===" + jsonResult);
...@@ -85,6 +87,46 @@ public class CallDygabxxfw { ...@@ -85,6 +87,46 @@ public class CallDygabxxfw {
} }
return map; return map;
} }
/**
* 获取全国资源
*
* @param zylx
* @param jsonStr
* @return
*/
@RequestMapping("/getGabZyInfo")
@ResponseBody
public Map<String,Object> getGabZyInfo(String zylx,String jsonStr) {
String url = p.getValue("qganurl");
//String url = "http://zhyy.xzxt.nm/qgfwzycx/queryDygabzy.action";
Map<String,Object> map = new HashMap<>();
String urlName = url+"?zylx="+zylx+"&jsonStr="+jsonStr;
String result = "";
try {
URL realURL = new URL(urlName);
URLConnection conn = realURL.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
conn.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line;
while ((line = in.readLine()) != null) {
result += "\n" + line;
}
if(result==null||"".equals(result)){
}else{
map = Utils.parseJSON2Map(result);
}
System.out.println("map=调取全国案件人员接口===" + map);
} catch (IOException e) {
System.out.println("获取全国案件数据异常===" + e.getMessage());
e.printStackTrace();
}
return map;
}
//根据条件调取部级资源-主方法 //根据条件调取部级资源-主方法
...@@ -93,19 +135,19 @@ public class CallDygabxxfw { ...@@ -93,19 +135,19 @@ public class CallDygabxxfw {
public String getGabZyInfo(HttpServletRequest request) { public String getGabZyInfo(HttpServletRequest request) {
String url = "http://zhyy.xzxt.nm/qgfwzycx/queryDygabzy.action"; String url = "http://zhyy.xzxt.nm/qgfwzycx/queryDygabzy.action";
String zylx = request.getParameter("zylx");//查询资源类型 String zylx = request.getParameter("zylx");//查询资源类型
String jsonStr = request.getParameter("jsonStr");//查询资源所需的条件 String jsonStr = request.getParameter("jsonStr");//查询资源所需的条件
String jsonResult = ""; String jsonResult = "";
url = url+"?zylx="+zylx+"&jsonStr="+jsonStr; url = url+"?zylx="+zylx+"&jsonStr="+jsonStr;
String result = ""; String result = "";
String urlName = url; String urlName = url;
try { try {
URL realURL = new URL(urlName); URL realURL = new URL(urlName);
URLConnection conn = realURL.openConnection(); URLConnection conn = realURL.openConnection();
conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"); conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
conn.connect(); conn.connect();
Map<String, List<String>> map = conn.getHeaderFields(); Map<String, List<String>> map = conn.getHeaderFields();
for (String s : map.keySet()) { for (String s : map.keySet()) {
System.out.println(s + "-->" + map.get(s)); System.out.println(s + "-->" + map.get(s));
...@@ -138,7 +180,7 @@ public class CallDygabxxfw { ...@@ -138,7 +180,7 @@ public class CallDygabxxfw {
try { try {
Map<Object, Object> param = new HashMap(); Map<Object, Object> param = new HashMap();
param.put("zjhm", zjhm); param.put("zjhm", zjhm);
// String url = "http://localhost:7001/getZtryDetailByZjhm.action?zjhm="+zjhm; // String url = "http://localhost:7001/getZtryDetailByZjhm.action?zjhm="+zjhm;
String url = p.getValue("qgzturl" ) + zjhm; String url = p.getValue("qgzturl" ) + zjhm;
// http链接工具 // http链接工具
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
...@@ -238,7 +280,7 @@ public class CallDygabxxfw { ...@@ -238,7 +280,7 @@ public class CallDygabxxfw {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
try { try {
//String url = "http://zhyy.xzxt.nm/szxc/query/person?rwbh=" + rwbh ; //String url = "http://zhyy.xzxt.nm/szxc/query/person?rwbh=" + rwbh ;
String url = p.getValue("zwbzurl") + "?rwbh=" + rwbh; String url = p.getValue("zwrwurl") + "?rwbh=" + rwbh;
// http链接工具 // http链接工具
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
Map<Object, Object> param = new HashMap(); Map<Object, Object> param = new HashMap();
......
...@@ -289,7 +289,7 @@ public class RyfkController { ...@@ -289,7 +289,7 @@ public class RyfkController {
//根据zjhm查询全国案件信息 //根据zjhm查询全国案件信息
public List getQgajxx(String zjhm) { public List getQgajxx(String zjhm) {
CallDygabxxfw fw = new CallDygabxxfw(); CallDygabxxfw fw = new CallDygabxxfw();
String jsonStr = "[{\"ZHFZXYR_CYZJ_ZJHM\":\"" + zjhm + "\"}]"; String jsonStr = "[\"{\\\"ZHFZXYR_CYZJ_ZJHM\\\":\\\"" + zjhm + "\\\"}\"]";
String zylx = "fzxyr"; String zylx = "fzxyr";
Map<String, Object> zbfzxyr = fw.getGabZyInfo(zylx, jsonStr); Map<String, Object> zbfzxyr = fw.getGabZyInfo(zylx, jsonStr);
List rowlist = new ArrayList(); List rowlist = new ArrayList();
...@@ -304,7 +304,7 @@ public class RyfkController { ...@@ -304,7 +304,7 @@ public class RyfkController {
String asjbh = maps.get("ASJBH").toString(); String asjbh = maps.get("ASJBH").toString();
System.out.println("asjbh= 根据人员查询案件编号==" + asjbh); System.out.println("asjbh= 根据人员查询案件编号==" + asjbh);
//获取案件信息 //获取案件信息
jsonStr = "[{\"ASJBH\":\"" + asjbh + "\"}]"; jsonStr = "[\"{\\\"ASJBH\\\":\\\"" + asjbh + "\\\"}\"]";
zylx = "asj"; zylx = "asj";
Map<String, Object> asjmap = fw.getGabZyInfo(zylx, jsonStr); Map<String, Object> asjmap = fw.getGabZyInfo(zylx, jsonStr);
List asjlist = new ArrayList(); List asjlist = new ArrayList();
......
package com.founder.utils; package com.founder.utils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
public class Utils { public class Utils {
...@@ -81,4 +82,26 @@ public class Utils { ...@@ -81,4 +82,26 @@ public class Utils {
return date; return date;
} }
public static Map<String, Object> parseJSON2Map(String jsonStr) {
Map<String, Object> map = new HashMap<String, Object>();
//最外层解析
JSONObject json = JSONObject.fromObject(jsonStr);
for (Object k : json.keySet()) {
Object v = json.get(k);
//如果内层还是数组的话,继续解析
if (v instanceof JSONArray) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Iterator<JSONObject> it = ((JSONArray) v).iterator();
while (it.hasNext()) {
JSONObject json2 = it.next();
list.add(parseJSON2Map(json2.toString()));
}
map.put(k.toString(), list);
} else {
map.put(k.toString(), v);
}
}
return map;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment