Browse Source

查询广西贫困开发

anderx 2 years ago
parent
commit
0373934959

+ 7 - 1
pom.xml

@@ -437,7 +437,13 @@
 			<artifactId>thumbnailator</artifactId>
 			<version>0.4.8</version>
 		</dependency>
-
+		<!-- 爬虫JsoupXpath-->
+		<dependency>
+			<groupId>cn.wanghaomiao</groupId>
+			<artifactId>JsoupXpath</artifactId>
+			<version>2.5.3</version>
+			<type>pom</type>
+		</dependency>
 
 
 	</dependencies>

+ 27 - 0
src/main/java/com/goafanti/common/bo/InputPoverty.java

@@ -0,0 +1,27 @@
+package com.goafanti.common.bo;
+
+import com.goafanti.common.utils.excel.Excel;
+
+public class InputPoverty {
+
+    @Excel(name = "姓名")
+    private String name;
+    @Excel(name = "身份证号码")
+    private String idCard;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getIdCard() {
+        return idCard;
+    }
+
+    public void setIdCard(String idCard) {
+        this.idCard = idCard;
+    }
+}

+ 86 - 0
src/main/java/com/goafanti/common/bo/OutPoverty.java

@@ -0,0 +1,86 @@
+package com.goafanti.common.bo;
+
+public class OutPoverty {
+    //序号 市 县 乡镇 村 人口数  姓名 与户主关系  脱贫年度
+    private String id;
+    private String city;
+    private String county;
+    private String township;
+    private String village;
+    private String peopleSum;
+    private String name;
+    private String relationship;
+    private String povertyYear;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getCounty() {
+        return county;
+    }
+
+    public void setCounty(String county) {
+        this.county = county;
+    }
+
+    public String getTownship() {
+        return township;
+    }
+
+    public void setTownship(String township) {
+        this.township = township;
+    }
+
+    public String getVillage() {
+        return village;
+    }
+
+    public void setVillage(String village) {
+        this.village = village;
+    }
+
+    public String getPeopleSum() {
+        return peopleSum;
+    }
+
+    public void setPeopleSum(String peopleSum) {
+        this.peopleSum = peopleSum;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getRelationship() {
+        return relationship;
+    }
+
+    public void setRelationship(String relationship) {
+        this.relationship = relationship;
+    }
+
+    public String getPovertyYear() {
+        return povertyYear;
+    }
+
+    public void setPovertyYear(String povertyYear) {
+        this.povertyYear = povertyYear;
+    }
+}

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

@@ -7,11 +7,11 @@ import com.goafanti.common.bo.OutUser;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
-import com.goafanti.common.dao.TOrderMidMapper;
 import com.goafanti.common.enums.UserType;
 import com.goafanti.common.model.User;
 import com.goafanti.common.service.DistrictGlossoryService;
 import com.goafanti.common.service.IndustryCategoryService;
+import com.goafanti.common.service.PovertyService;
 import com.goafanti.common.utils.*;
 import com.goafanti.common.utils.excel.FileUtils;
 import com.goafanti.common.utils.excel.NewExcelUtil;
@@ -81,7 +81,7 @@ public class PublicController extends CertifyApiController {
 	private AdminService	adminService;
 
 	@Resource
-	private TOrderMidMapper			tOrderMidMapper;
+	private PovertyService povertyService;
 
 	@Autowired
 	private IndustryCategoryService	industryCategoryService;
@@ -769,4 +769,25 @@ public class PublicController extends CertifyApiController {
 		res.data(expenseAccountService.pushSupplementCheckNo());
 		return res;
 	}
+
+	/**
+	 * 查询贫困信息
+	 * @return
+	 */
+	@RequestMapping("/selectPoverty")
+	public Result selectPoverty(@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;
+		}
+		res.data(povertyService.selectPoverty(file));
+		return res;
+	}
 }

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

@@ -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;
+    }
+}

+ 1 - 1
src/main/resources/props/config_local.properties

@@ -52,7 +52,7 @@ yxjl_max=100
 amb.maxLvl=6
 
 avatar.host=//static.jishutao.com
-static.host=//static.jishutao.com/1.2.81
+static.host=//static.jishutao.com/1.2.82
 rd.static.host=//static.jishutao.com/RD/1.0.00
 #avatar.host=//172.16.0.255:3000
 #static.host=//172.16.0.255:3000/1.2.62