|
|
|
@ -1,9 +1,11 @@ |
|
|
|
package com.qniao.zsh.application.service.createspider; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSON; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.qniao.zsh.domain.aggregate.spiderstate.entity.SpiderState; |
|
|
|
import com.qniao.zsh.domain.aggregate.spiderstate.repository.SpiderStateRepository; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -13,15 +15,25 @@ import javax.annotation.Resource; |
|
|
|
* @date 2023/3/1 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class CreateSpiderApplicationService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private SpiderStateRepository spiderStateRepository; |
|
|
|
public String create(String spiderName){ |
|
|
|
|
|
|
|
SpiderState spiderState = new SpiderState(); |
|
|
|
spiderState.setSpiderName(spiderName); |
|
|
|
spiderStateRepository.save(spiderState); |
|
|
|
return JSONUtil.toJsonStr(spiderStateRepository.load(spiderName)); |
|
|
|
String json = JSONUtil.toJsonStr(spiderStateRepository.load(spiderName)); |
|
|
|
//判断爬虫是否已经存在 |
|
|
|
if (json == null) { |
|
|
|
spiderStateRepository.save(spiderState); |
|
|
|
json = JSONUtil.toJsonStr(spiderStateRepository.load(spiderName)); |
|
|
|
}else { |
|
|
|
json = "{爬虫已经存在,请不要重复创建。}"; |
|
|
|
log.info(json); |
|
|
|
} |
|
|
|
return JSONUtil.toJsonStr(json); |
|
|
|
} |
|
|
|
|
|
|
|
} |