Skip to content

Commit

Permalink
增加批量任务,修正jar包冲突,修正模态框rest重复请求
Browse files Browse the repository at this point in the history
  • Loading branch information
gsh199449 committed Feb 16, 2017
1 parent 1cb3568 commit 24d2ceb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0.1</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -82,6 +88,12 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.gs.spider.service.commons.spider.CommonsSpiderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -139,4 +140,16 @@ public ResultListBundle<String> getIgnoredUrls() {
public ResultBundle<String> addIgnoredUrl(String postfix) {
return spiderService.addIgnoredUrl(postfix);
}

/**
* 根据爬虫模板ID批量启动任务
*
* @param spiderInfoIdList 爬虫模板ID列表
* @return 任务id列表
*/
@RequestMapping(value = "startAll", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResultListBundle<String> startAll(String spiderInfoIdList) {
return spiderService.startAll(Lists.newArrayList(spiderInfoIdList.split(",")));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gs.spider.service.commons.spider;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.gs.spider.gather.async.AsyncGather;
import com.gs.spider.gather.commons.CommonSpider;
Expand All @@ -18,6 +19,8 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.management.JMException;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -187,4 +190,26 @@ private void validateSpiderInfo(SpiderInfo spiderInfo) {
"动态字段配置含有无效配置,每一个动态字段都必须有name,而且正则和xpath不可同时为空,请检查");
}
}

/**
* 根据爬虫模板ID批量启动任务
*
* @param spiderInfoIdList 爬虫模板ID列表
* @return 任务id列表
*/
public ResultListBundle<String> startAll(List<String> spiderInfoIdList) {
return bundleBuilder.listBundle(spiderInfoIdList.toString(), () -> {
List<String> taskIdList = Lists.newArrayList();
for (String id : spiderInfoIdList) {
try {
SpiderInfo info = spiderInfoService.getById(id).getResult();
String taskId = commonSpider.start(info);
taskIdList.add(taskId);
} catch (JMException e) {
LOG.error("启动任务ID{}出错,{}", id, e);
}
}
return taskIdList;
});
}
}
2 changes: 1 addition & 1 deletion src/main/webapp/js/my.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function rpc(url, pram, callback) {
$('#confirmModal').modal('hide');
needShowResultModel = true;
});
$("#confirmModal").on('hidden.bs.modal', function () {
$("#confirmModal").one('hidden.bs.modal', function () {
if (needShowResultModel) {
$.getJSON(url, pram, callback);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/webapp/pages/panel/commons/listSpiderInfo.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
});
});
function checkAll() {
$('input:checkbox').each(function () {
$(this).attr('checked', true);
});
}
function startAll() {
var idList = [];
$("input:checkbox:checked").each(function () {
idList.push($(this).attr('data-infoid'));
});
rpcAndShowData('${pageContext.request.contextPath}/commons/spider/startAll', {spiderInfoIdList: idList.join(',')});
}
</script>
</head>
<body>
Expand All @@ -53,6 +65,10 @@
</form>
</div>
<div class="container">
<div class="row">
<button type="button" onclick="startAll()">启动选中</button>
<button type="button" onclick="checkAll()">全选</button>
</div>
<table class="table table-hover">
<thead class="thead-inverse">
<tr>
Expand All @@ -67,6 +83,9 @@
<tbody>
<c:forEach items="${spiderInfoList}" var="info" varStatus="index">
<tr>
<th><label>
<input type="checkbox" data-infoid="${info.id}">
</label></th>
<th scope="row">${index.count}</th>
<td>${info.domain}</td>
<td>${info.siteName}</td>
Expand Down

0 comments on commit 24d2ceb

Please sign in to comment.