Browse Source

查询全国贫困开发

anderx 2 years ago
parent
commit
e1935c12f9

+ 23 - 0
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -864,4 +864,27 @@ public class PublicController extends CertifyApiController {
 			LoggerUtils.error(PublicController.class,"下载文件失败", e);
 		}
 	}
+
+	/**
+	 * 查询贫困信息
+	 * @return
+	 */
+	@RequestMapping("/selectFlag")
+	public Result selectFlag(@RequestParam(value = "file", required = false) MultipartFile file) {
+		Result res=new Result();
+		//判断文件是否存在
+		if(null == file){
+			res.getError().add(buildError("文件不存在!","文件不存在!"));
+			return res;
+		}
+		String fileName = file.getOriginalFilename();
+		if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
+			res.getError().add(buildError("格式不正确","格式不正确"));
+			return res;
+		}
+		String id = jdbcIdGenerator.generateId().toString();
+		res.data(povertyService.selectFlag(file,id));
+		return res;
+	}
+
 }

+ 25 - 0
src/main/java/com/goafanti/common/service/PovertyService.java

@@ -1,7 +1,9 @@
 package com.goafanti.common.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.goafanti.common.bo.InputPoverty;
 import com.goafanti.common.bo.OutPoverty;
+import com.goafanti.common.utils.HttpUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.common.utils.excel.NewExcelUtil;
 import org.jsoup.Jsoup;
@@ -110,4 +112,27 @@ public class PovertyService {
         }
         return out;
     }
+
+    private static final String flag_url="https://cpadis.cpad.gov.cn:1443/cpad_par/app/observeHouse/checkIdentity?loginToken=&userId=&version=";
+    public Object selectFlag(MultipartFile file, String id) {
+        NewExcelUtil<InputPoverty> newExcelUtil=new NewExcelUtil<>(InputPoverty.class);
+        List<InputPoverty> list = null;
+        try {
+            list = newExcelUtil.importExcel(file.getInputStream(),0);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        List<OutPoverty> res=new ArrayList<>();
+        Map<String, Object> map=new HashMap<>();
+        for (InputPoverty in : list) {
+            String name=StringUtils.deleteWhitespace(in.getName());
+            String idCode=StringUtils.deleteWhitespace(in.getIdCard());
+            map.put("name",name);
+            map.put("idCode",idCode);
+            JSONObject jsonObject = HttpUtils.httpPostBody(flag_url, map);
+            String data = jsonObject.getString("data");
+            System.out.println("name="+name+",flag="+data);
+        }
+        return 1;
+    }
 }

+ 38 - 15
src/main/java/com/goafanti/common/utils/HttpUtils.java

@@ -1,9 +1,7 @@
 package com.goafanti.common.utils;
 
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.Map;
-
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ParseException;
@@ -15,13 +13,15 @@ import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Map;
+import java.util.Set;
 
 public class HttpUtils {
-	
-	
-	
+
+
+
 	 public static JSONObject httpGet(String url) {
 			JSONObject jsonResult = null;
 			try {
@@ -39,19 +39,33 @@ public class HttpUtils {
 			}
 			return jsonResult;
 		}
-	    
+
+
+	public static JSONObject httpPost(String url,Map<String, Object>map){
+		return httpPost(url,map,0);
+	}
+	public static JSONObject httpPostBody(String url,Map<String, Object>map){
+		return httpPost(url,map,1);
+	}
 		 /**
-		  *  
+		  *
 		  * @param url 地址
 		  * @param map 参数
+		  * @param type  0 json  1body
 		  * @return
 		  */
-		public static JSONObject httpPost(String url,Map<String, Object>map){
+		public static JSONObject httpPost(String url,Map<String, Object>map,Integer type) {
 			HttpClient httpClient = HttpClientBuilder.create().build();
 			HttpPost httpPost = new HttpPost(url);
-			httpPost.addHeader("Content-type", "application/json");
 			httpPost.setHeader("Accept", "application/json");
-			httpPost.setEntity(new StringEntity(JSON.toJSONString(map), Charset.forName("UTF-8")));
+			if (type==0){
+				httpPost.addHeader("Content-type", "application/json");
+				httpPost.setEntity(new StringEntity(JSON.toJSONString(map), Charset.forName("UTF-8")));
+			}else{
+				httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
+				httpPost.setEntity(new StringEntity(ParamMap(map), Charset.forName("UTF-8")));
+			}
+
 			HttpResponse response = null;
 			try {
 				response = httpClient.execute(httpPost);
@@ -77,7 +91,16 @@ public class HttpUtils {
 			return jsonObj;
 			}
 
+	private static String ParamMap(Map<String, Object> map) {
+		StringBuffer str =new StringBuffer();
+		Set<String> strings = map.keySet();
+		for (String string : strings) {
+			str=str.append(string).append("=").append(map.get(string)).append("&");
+		}
+		String substring = str.substring(0, str.length() - 1);
+		System.out.println(substring);
+		return substring;
+	}
 
-		
 
 }