| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package com.goafanti.common.service;
- import com.goafanti.common.bo.InputPoverty;
- import com.goafanti.common.bo.OutPoverty;
- import com.goafanti.common.utils.StringUtils;
- 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.cache.annotation.Cacheable;
- import org.springframework.stereotype.Service;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Service
- public class PovertyService {
- private static final String gx_url="http://fpb.gxxw.cn/index.php?m=check&c=index&a=list_jdlk&name=";
- @Cacheable(value = "selectPoverty#300", key = "'selectPoverty:key='+#id")
- public Map<String,Object> selectPoverty(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<>();
- Integer totalcount =0;
- Integer effectiveCount =0;
- for (InputPoverty e : list) {
- OutPoverty outPoverty = selectHttpPoverty(e);
- if (outPoverty.getId()!=null){
- effectiveCount++;
- }
- totalcount++;
- res.add(outPoverty);
- }
- Map<String ,Object> map=new HashMap<>();
- map.put("list",res);
- map.put("totalcount",totalcount);
- map.put("effectiveCount",effectiveCount);
- map.put("id",id);
- return map;
- }
- private OutPoverty selectHttpPoverty(InputPoverty in) {
- OutPoverty out=new OutPoverty();
- try {
- String name= StringUtils.deleteWhitespace(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;
- }
- }
|