From 33a9edea14fe8480dd0a0dd90dd2aad0e39f483c Mon Sep 17 00:00:00 2001 From: xjs <1294405880@qq.com> Date: Mon, 18 Apr 2022 16:26:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=B8=AD=E5=85=B3=E6=9D=91=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=88=AC=E8=99=AB=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webmagic/RemoteWebmagicZolFeign.java | 22 ++++++++++++ .../factory/RemoteWebmagicZolFactory.java | 25 ++++++++++++++ .../com/xjs/job/task/webmagic/ZolTask.java | 31 +++++++++++++++++ .../com/xjs/zol/controller/ZolController.java | 34 +++++++++++++++++++ .../zol/controller/ZolPhoneController.java | 15 -------- 5 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/RemoteWebmagicZolFeign.java create mode 100644 ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/factory/RemoteWebmagicZolFactory.java create mode 100644 ruoyi-modules/ruoyi-job/src/main/java/com/xjs/job/task/webmagic/ZolTask.java create mode 100644 xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolController.java diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/RemoteWebmagicZolFeign.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/RemoteWebmagicZolFeign.java new file mode 100644 index 00000000..4d2d5561 --- /dev/null +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/RemoteWebmagicZolFeign.java @@ -0,0 +1,22 @@ +package com.xjs.business.webmagic; + +import com.ruoyi.common.core.constant.ServiceNameConstants; +import com.ruoyi.common.core.domain.R; +import com.xjs.business.webmagic.factory.RemoteWebmagicZolFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * 内部 调用 中关村数据 爬虫定时任务feign + * @author xiejs + * @since 2022-04-18 + */ +@FeignClient(contextId = "remoteWebmagicZolFeign", + value = ServiceNameConstants.BUSINESS_WEBMAGIC_SERVICE, + fallbackFactory = RemoteWebmagicZolFactory.class) +public interface RemoteWebmagicZolFeign { + + @GetMapping("/zol/taskForPRC") + R ZolPhoneTaskForRPC(); + +} diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/factory/RemoteWebmagicZolFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/factory/RemoteWebmagicZolFactory.java new file mode 100644 index 00000000..723a4c7a --- /dev/null +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/xjs/business/webmagic/factory/RemoteWebmagicZolFactory.java @@ -0,0 +1,25 @@ +package com.xjs.business.webmagic.factory; + +import com.ruoyi.common.core.domain.R; +import com.xjs.business.webmagic.RemoteWebmagicZolFeign; +import lombok.extern.log4j.Log4j2; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * 内部 调用 中关村数据 爬虫定时任务feign降级 + * + * @author xiejs + * @since 2022-04-18 + */ +@Log4j2 +@Component +public class RemoteWebmagicZolFactory implements FallbackFactory { + @Override + public RemoteWebmagicZolFeign create(Throwable cause) { + return () -> { + log.error("中关村数据爬虫定时任务降级"); + return R.fail("中关村数据爬虫定时任务降级"); + }; + } +} diff --git a/ruoyi-modules/ruoyi-job/src/main/java/com/xjs/job/task/webmagic/ZolTask.java b/ruoyi-modules/ruoyi-job/src/main/java/com/xjs/job/task/webmagic/ZolTask.java new file mode 100644 index 00000000..8677161f --- /dev/null +++ b/ruoyi-modules/ruoyi-job/src/main/java/com/xjs/job/task/webmagic/ZolTask.java @@ -0,0 +1,31 @@ +package com.xjs.job.task.webmagic; + +import com.xjs.business.webmagic.RemoteWebmagicZolFeign; +import com.xjs.job.aop.TaskLog; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 爬虫 中关村数据 定时任务 + * @author xiejs + * @since 2022-04-18 + */ +@Component("ZolTask") +@Log4j2 +public class ZolTask { + @Resource + private RemoteWebmagicZolFeign remoteWebmagicZolFeign; + + + @TaskLog(name = "微信搜狗爬虫任务") + public void zol(){ + log.info("---------------爬虫-中关村数据定时任务Start-------------------"); + + remoteWebmagicZolFeign.ZolPhoneTaskForRPC(); + + log.info("---------------爬虫-中关村数据定时任务end---------------------"); + } + +} diff --git a/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolController.java b/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolController.java new file mode 100644 index 00000000..93819ce3 --- /dev/null +++ b/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolController.java @@ -0,0 +1,34 @@ +package com.xjs.zol.controller; + +import com.ruoyi.common.core.domain.R; +import com.xjs.zol.task.ZolTask; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 爬虫中关村controller + * + * @author xiejs + * @since 2022-04-18 + */ +@RestController +@RequestMapping("zol") +@Api(tags = "爬虫模块-中关村") +public class ZolController { + + @Autowired + private ZolTask zolTask; + + + //------------------------------内部调用rpc------------------------------------- + @GetMapping("taskForPRC") + @ApiOperation("供定时任务服务RPC远程调用") + public R ZolPhoneTaskForRPC() { + Long aLong = zolTask.reptileZol(); + return R.ok(aLong); + } +} diff --git a/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolPhoneController.java b/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolPhoneController.java index 0d761162..d903ead1 100644 --- a/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolPhoneController.java +++ b/xjs-business/xjs-business-webmagic/src/main/java/com/xjs/zol/controller/ZolPhoneController.java @@ -1,11 +1,6 @@ package com.xjs.zol.controller; -import com.ruoyi.common.core.domain.R; -import com.xjs.zol.task.ZolTask; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -19,15 +14,5 @@ import org.springframework.web.bind.annotation.RestController; @Api(tags = "爬虫模块-中关村手机") public class ZolPhoneController { - @Autowired - private ZolTask zolTask; - - //------------------------------内部调用rpc------------------------------------- - @GetMapping("taskForPRC") - @ApiOperation("供定时任务服务RPC远程调用") - public R ZolPhoneTaskForRPC() { - Long aLong = zolTask.reptileZol(); - return R.ok(aLong); - } }