diff --git a/spider-flow-core/src/main/java/org/spiderflow/core/service/SpiderFlowService.java b/spider-flow-core/src/main/java/org/spiderflow/core/service/SpiderFlowService.java index 9a0aba7..670447d 100644 --- a/spider-flow-core/src/main/java/org/spiderflow/core/service/SpiderFlowService.java +++ b/spider-flow-core/src/main/java/org/spiderflow/core/service/SpiderFlowService.java @@ -35,13 +35,13 @@ import java.util.stream.Collectors; */ @Service public class SpiderFlowService extends ServiceImpl { - + @Autowired private SpiderFlowMapper sfMapper; - + @Autowired private SpiderJobManager spiderJobManager; - + @Autowired private FlowNoticeMapper flowNoticeMapper; @@ -73,15 +73,15 @@ public class SpiderFlowService extends ServiceImpl public IPage selectSpiderPage(Page page, String name){ return sfMapper.selectSpiderPage(page,name); } - + public int executeCountIncrement(String id, Date lastExecuteTime, Date nextExecuteTime){ if(nextExecuteTime == null){ return sfMapper.executeCountIncrement(id, lastExecuteTime); } return sfMapper.executeCountIncrementAndExecuteTime(id, lastExecuteTime, nextExecuteTime); - + } - + /** * 重置定时任务 * @param id 爬虫的ID @@ -130,13 +130,20 @@ public class SpiderFlowService extends ServiceImpl } return true; } - + public void stop(String id){ sfMapper.resetSpiderStatus(id,"0"); sfMapper.resetNextExecuteTime(id); spiderJobManager.remove(id); } - + + public void copy(String id){ + // 复制ID + SpiderFlow spiderFlow = sfMapper.selectById(id); + String new_id = UUID.randomUUID().toString().replace("-", ""); + sfMapper.insertSpiderFlow(new_id, spiderFlow.getName() + "-copy", spiderFlow.getXml()); + } + public void start(String id){ spiderJobManager.remove(id); SpiderFlow spiderFlow = getById(id); @@ -147,11 +154,11 @@ public class SpiderFlowService extends ServiceImpl sfMapper.resetSpiderStatus(id, "1"); } } - + public void run(String id){ spiderJobManager.run(id); } - + public void resetExecuteCount(String id){ sfMapper.resetExecuteCount(id); } @@ -160,11 +167,11 @@ public class SpiderFlowService extends ServiceImpl spiderJobManager.remove(id); flowNoticeMapper.deleteById(id); } - + public List selectOtherFlows(String id){ return sfMapper.selectOtherFlows(id); } - + public List selectFlows(){ return sfMapper.selectFlows(); } diff --git a/spider-flow-web/src/main/java/org/spiderflow/controller/SpiderFlowController.java b/spider-flow-web/src/main/java/org/spiderflow/controller/SpiderFlowController.java index a550d63..b81acfa 100644 --- a/spider-flow-web/src/main/java/org/spiderflow/controller/SpiderFlowController.java +++ b/spider-flow-web/src/main/java/org/spiderflow/controller/SpiderFlowController.java @@ -48,29 +48,29 @@ import java.util.stream.Collectors; @RestController @RequestMapping("/spider") public class SpiderFlowController { - + @Autowired private List functionExecutors; - + @Autowired private List functionExtensions; - + @Autowired private List grammerables; - + @Autowired private SpiderFlowService spiderFlowService; - + @Autowired(required = false) private List pluginConfigs; - + @Value("${spider.workspace}") private String workspace; - + private final List grammers = new ArrayList(); - + private static Logger logger = LoggerFactory.getLogger(SpiderFlowController.class); - + @PostConstruct private void init(){ for (FunctionExecutor executor : functionExecutors) { @@ -84,7 +84,7 @@ public class SpiderFlowController { grammer.setFunction(function); grammers.add(grammer); } - + for (FunctionExtension extension : functionExtensions) { String owner = extension.support().getSimpleName(); grammers.addAll(Grammer.findGrammers(extension.getClass(),null,owner,true)); @@ -93,7 +93,7 @@ public class SpiderFlowController { grammers.addAll(grammerable.grammers()); } } - + /** * 爬虫列表 * @param page 页数 @@ -104,7 +104,7 @@ public class SpiderFlowController { public IPage list(@RequestParam(name = "page", defaultValue = "1") Integer page, @RequestParam(name = "limit", defaultValue = "1") Integer size, @RequestParam(name = "name", defaultValue = "") String name) { return spiderFlowService.selectSpiderPage(new Page<>(page, size), name); } - + @RequestMapping("/save") public String save(SpiderFlow spiderFlow){ spiderFlowService.save(spiderFlow); @@ -119,12 +119,12 @@ public class SpiderFlowController { return new JsonBean<>(spiderFlowService.historyList(id)); } } - + @RequestMapping("/get") public SpiderFlow get(String id){ return spiderFlowService.getById(id); } - + @RequestMapping("/other") public List other(String id){ if(StringUtils.isBlank(id)){ @@ -132,32 +132,37 @@ public class SpiderFlowController { } return spiderFlowService.selectOtherFlows(id); } - + @RequestMapping("/remove") public void remove(String id){ spiderFlowService.remove(id); } - + @RequestMapping("/start") public void start(String id){ spiderFlowService.start(id); } - + @RequestMapping("/stop") public void stop(String id){ spiderFlowService.stop(id); } - + + @RequestMapping("/copy") + public void copy(String id){ + spiderFlowService.copy(id); + } + @RequestMapping("/run") public void run(String id){ spiderFlowService.run(id); } - + @RequestMapping("/cron") public void cron(String id,String cron){ spiderFlowService.resetCornExpression(id, cron); } - + @RequestMapping("/xml") public String xml(String id){ return spiderFlowService.getById(id).getXml(); @@ -192,17 +197,17 @@ public class SpiderFlowController { return new JsonBean<>(-1,"读取日志文件出错"); } } - + @RequestMapping("/shapes") public List shapes(){ return ExecutorsUtils.shapes(); } - + @RequestMapping("/pluginConfigs") public List pluginConfigs(){ return null == pluginConfigs ? Collections.emptyList() : pluginConfigs.stream().filter(e-> e.plugin() != null).map(plugin -> plugin.plugin()).collect(Collectors.toList()); } - + @RequestMapping("/grammers") public JsonBean> grammers(){ return new JsonBean<>(this.grammers); diff --git a/spider-flow-web/src/main/resources/static/spiderList.html b/spider-flow-web/src/main/resources/static/spiderList.html index a777303..ab0001a 100644 --- a/spider-flow-web/src/main/resources/static/spiderList.html +++ b/spider-flow-web/src/main/resources/static/spiderList.html @@ -84,7 +84,7 @@ align : 'center' },{ title : '操作', - width : 195, + width : 250, align : 'center', templet : '#buttons' }]] @@ -121,6 +121,28 @@ } $("body").on('click','.btn-search',function(){ reloadTable(); + }).on('click','.btn-copy',function(){ + var id = $(this).data('id'); + layui.layer.confirm('您确定要复制此爬虫吗?',{ + title : '复制' + },function(index){ + $table.reload(); + $.ajax({ + url : 'spider/copy', + data : { + id : id + }, + success : function(){ + layui.layer.msg('复制成功',{time : 500},function(){ + $table.reload(); + }) + }, + error : function(){ + layui.layer.msg('复制失败') + } + }) + layui.layer.close(index); + }) }).on('click','.btn-remove',function(){ var id = $(this).data('id'); layui.layer.confirm('您确定要删除此爬虫吗?',{ @@ -205,4 +227,4 @@ - \ No newline at end of file +