Commit 3bae4198 authored by 赵啸非's avatar 赵啸非

修改重试机制

parent 7f5e2976
...@@ -26,50 +26,7 @@ public class MatterDetailHtmlParseUtil { ...@@ -26,50 +26,7 @@ public class MatterDetailHtmlParseUtil {
try { try {
document = Jsoup.connect(url).get(); document = Jsoup.connect(url).get();
return document; return document;
/*Jsoup.connect(url).get();
html = Jsoup.connect(url).get().body().html();
// html = HttpUtil.get(url);
//System.out.println(html);
HtmlCleaner hc = new HtmlCleaner();
TagNode tn = hc.clean(html);
Object[] rs = tn.evaluateXPath("//div");
for (Integer i = 0; i < rs.length; i++) {
TagNode n = (TagNode) rs[i];
System.out.println(n.getText());
}*/
// System.out.println(tn.getText());
/* CleanerProperties cleanerProperties = new CleanerProperties();
cleanerProperties.setAdvancedXmlEscape(true);
cleanerProperties.setOmitXmlDeclaration(true);
cleanerProperties.setOmitDoctypeDeclaration(true);
cleanerProperties.setTranslateSpecialEntities(true);
cleanerProperties.setTransResCharsToNCR(true);
cleanerProperties.setRecognizeUnicodeChars(true);
cleanerProperties.setIgnoreQuestAndExclam(true);
cleanerProperties.setUseEmptyElementTags(false);
Document dom = new DomSerializer(cleanerProperties).createDOM(tn);*/
/*XPath xPath = XPathFactory.newInstance().newXPath();
String tklrExp = String.format("//div[@class=\"smltc9_bottom\"]//p");
Object result = xPath.evaluate(tklrExp, dom, XPathConstants.NODESET);
NodeList nodeList = (NodeList) result;
for (Integer i = 0; i < nodeList.getLength(); i++) {
System.out.println(nodeList.item(i).getTextContent());
System.out.println("===============");
}*/
//div[@class='section10']//table[1]//tr[%d]//td
//return dom;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -50,6 +50,7 @@ public class MatterHtmlParseUtil { ...@@ -50,6 +50,7 @@ public class MatterHtmlParseUtil {
Integer pageNum = elements.get(0) == null ? 0 : DataUtil.converStr2Int(elements.get(0).attr("value"), 0); Integer pageNum = elements.get(0) == null ? 0 : DataUtil.converStr2Int(elements.get(0).attr("value"), 0);
resultMap.put("pageNum", pageNum); resultMap.put("pageNum", pageNum);
} }
break;
} catch (Exception e) { } catch (Exception e) {
log.error("获取事项数量异常!params:{},重试:{}次", JSON.toJSONString(params), reCount, e); log.error("获取事项数量异常!params:{},重试:{}次", JSON.toJSONString(params), reCount, e);
reCount++; reCount++;
...@@ -230,6 +231,7 @@ public class MatterHtmlParseUtil { ...@@ -230,6 +231,7 @@ public class MatterHtmlParseUtil {
String deptCode = builder.getQuery().get("deptCode").toString(); String deptCode = builder.getQuery().get("deptCode").toString();
map.put(deptCode, deptName); map.put(deptCode, deptName);
} }
break;
} catch (Exception e) { } catch (Exception e) {
log.error("当前站点同步添加部门异常!params:{},重试:{}次", JSON.toJSONString(params), reCount, e); log.error("当前站点同步添加部门异常!params:{},重试:{}次", JSON.toJSONString(params), reCount, e);
reCount++; reCount++;
......
...@@ -22,6 +22,8 @@ import java.util.HashMap; ...@@ -22,6 +22,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.mortals.xhx.common.key.Constant.MAX_RETRY_COUNT;
/** /**
* 解析事项类型,主题,热度等 * 解析事项类型,主题,热度等
*/ */
...@@ -40,10 +42,13 @@ public class MatterTypeHtmlParseUtil { ...@@ -40,10 +42,13 @@ public class MatterTypeHtmlParseUtil {
String matterTotalExp = "//input[@id=\"result_countTheme\"]"; String matterTotalExp = "//input[@id=\"result_countTheme\"]";
String matterPageExp = "//input[@id=\"pageNumTheme\"]"; String matterPageExp = "//input[@id=\"pageNumTheme\"]";
Map<String, Integer> resultMap = new HashMap<>(); Map<String, Integer> resultMap = new HashMap<>();
int reCount = 0;
while (reCount < MAX_RETRY_COUNT) {
try { try {
Document dom = Jsoup.connect(url) Document dom = Jsoup.connect(url)
.ignoreContentType(true) .ignoreContentType(true)
.ignoreHttpErrors(true) .ignoreHttpErrors(true)
.timeout(60 * 1000)
.data(params).get(); .data(params).get();
Elements elements = dom.selectXpath(matterTotalExp); Elements elements = dom.selectXpath(matterTotalExp);
if (elements.size() > 0) { if (elements.size() > 0) {
...@@ -60,10 +65,15 @@ public class MatterTypeHtmlParseUtil { ...@@ -60,10 +65,15 @@ public class MatterTypeHtmlParseUtil {
} else { } else {
resultMap.put("pageNum", 0); resultMap.put("pageNum", 0);
} }
break;
} catch (Exception e) { } catch (Exception e) {
log.error("获取事项数量异常!params:" + JSON.toJSONString(params), e); log.error("获取事项数量异常!params:" + JSON.toJSONString(params), e);
return Rest.fail(e.getMessage()); reCount++;
try {
Thread.sleep(2000);
} catch (InterruptedException interruptedException) {
}
}
} }
return Rest.ok(resultMap); return Rest.ok(resultMap);
...@@ -80,10 +90,13 @@ public class MatterTypeHtmlParseUtil { ...@@ -80,10 +90,13 @@ public class MatterTypeHtmlParseUtil {
String matterTotalExp = "//input[@id=\"result_count\"]"; String matterTotalExp = "//input[@id=\"result_count\"]";
String matterPageExp = "//input[@id=\"pageNum\"]"; String matterPageExp = "//input[@id=\"pageNum\"]";
Map<String, Integer> resultMap = new HashMap<>(); Map<String, Integer> resultMap = new HashMap<>();
int reCount = 0;
while (reCount < MAX_RETRY_COUNT) {
try { try {
Document dom = Jsoup.connect(url) Document dom = Jsoup.connect(url)
.ignoreContentType(true) .ignoreContentType(true)
.ignoreHttpErrors(true) .ignoreHttpErrors(true)
.timeout(60 * 1000)
.data(params).get(); .data(params).get();
Elements elements = dom.selectXpath(matterTotalExp); Elements elements = dom.selectXpath(matterTotalExp);
if (elements.size() > 0) { if (elements.size() > 0) {
...@@ -100,10 +113,15 @@ public class MatterTypeHtmlParseUtil { ...@@ -100,10 +113,15 @@ public class MatterTypeHtmlParseUtil {
} else { } else {
resultMap.put("pageNum", 0); resultMap.put("pageNum", 0);
} }
break;
} catch (Exception e) { } catch (Exception e) {
log.error("获取事项数量异常!params:" + JSON.toJSONString(params), e); log.error("获取事项数量异常!params:" + JSON.toJSONString(params), e);
return Rest.fail(e.getMessage()); reCount++;
try {
Thread.sleep(2000);
} catch (InterruptedException interruptedException) {
}
}
} }
return Rest.ok(resultMap); return Rest.ok(resultMap);
...@@ -120,10 +138,13 @@ public class MatterTypeHtmlParseUtil { ...@@ -120,10 +138,13 @@ public class MatterTypeHtmlParseUtil {
public static Rest<Map<String, String>> getThemeList(Map<String, String> params, String url) { public static Rest<Map<String, String>> getThemeList(Map<String, String> params, String url) {
String ThemeListExp = "//ul[@class=\"zhuti_list\"]//li//a"; String ThemeListExp = "//ul[@class=\"zhuti_list\"]//li//a";
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
int reCount = 0;
while (reCount < MAX_RETRY_COUNT) {
try { try {
Document dom = Jsoup.connect(url) Document dom = Jsoup.connect(url)
.ignoreContentType(true) .ignoreContentType(true)
.ignoreHttpErrors(true) .ignoreHttpErrors(true)
.timeout(60 * 1000)
.data(params).get(); .data(params).get();
Elements elements = dom.selectXpath(ThemeListExp); Elements elements = dom.selectXpath(ThemeListExp);
...@@ -137,10 +158,15 @@ public class MatterTypeHtmlParseUtil { ...@@ -137,10 +158,15 @@ public class MatterTypeHtmlParseUtil {
String title = element.attr("title"); String title = element.attr("title");
map.put(themeCode, title); map.put(themeCode, title);
} }
break;
} catch (Exception e) { } catch (Exception e) {
log.error("获取列表异常!params:" + JSON.toJSONString(params), e); log.error("获取列表异常!params:" + JSON.toJSONString(params), e);
return Rest.fail(e.getMessage()); reCount++;
try {
Thread.sleep(2000);
} catch (InterruptedException interruptedException) {
}
}
} }
return Rest.ok(map); return Rest.ok(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