|
|
@@ -0,0 +1,69 @@
|
|
|
+package com.goafanti.common.service;
|
|
|
+
|
|
|
+import com.goafanti.common.bo.InputPoverty;
|
|
|
+import com.goafanti.common.bo.OutPoverty;
|
|
|
+import com.goafanti.common.utils.excel.NewExcelUtil;
|
|
|
+import org.jsoup.Jsoup;
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
+import org.jsoup.select.Elements;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PovertyService {
|
|
|
+ private static final String gx_url="http://fpb.gxxw.cn/index.php?m=check&c=index&a=list_jdlk&name=";
|
|
|
+ public Object selectPoverty(MultipartFile file) {
|
|
|
+ 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<>();
|
|
|
+ for (InputPoverty e : list) {
|
|
|
+ res.add(selectHttpPoverty(e));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private OutPoverty selectHttpPoverty(InputPoverty in) {
|
|
|
+ OutPoverty out=new OutPoverty();
|
|
|
+ try {
|
|
|
+ String name=in.getName();
|
|
|
+ String idcard=in.getIdCard();
|
|
|
+ StringBuffer url=new StringBuffer(gx_url);
|
|
|
+ url=url.append(name).append("&idcard=").append(idcard);
|
|
|
+ Document document = Jsoup
|
|
|
+ .connect(url.toString()).get();
|
|
|
+ Elements filequery_table = document.getElementsByClass("Filequery_table");
|
|
|
+ Elements tr = filequery_table.select("tr");
|
|
|
+ if (tr.size()>1){
|
|
|
+ Element element = tr.get(1);
|
|
|
+ Elements td = element.select("td");
|
|
|
+ out.setId(td.get(0).text());
|
|
|
+ out.setCity(td.get(1).text());
|
|
|
+ out.setCounty(td.get(2).text());
|
|
|
+ out.setTownship(td.get(3).text());
|
|
|
+ out.setVillage(td.get(4).text());
|
|
|
+ out.setPeopleSum(td.get(5).text());
|
|
|
+ out.setName(td.get(6).text());
|
|
|
+ out.setRelationship(td.get(7).text());
|
|
|
+ out.setPovertyYear(td.get(8).text());
|
|
|
+ }else {
|
|
|
+ out.setName(name);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+}
|