From bc3cd4df0ef19370078d939aa7f29a05c7615e79 Mon Sep 17 00:00:00 2001 From: wangchunxiang Date: Thu, 11 Dec 2025 18:10:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(crawler):=20=E5=AE=9E=E7=8E=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8A=93=E5=8F=96=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96UI=E4=BA=A4=E4=BA=92=20-=20=E6=96=B0=E5=A2=9E=20Crawle?= =?UTF-8?q?rConfigAppraisalDTO=20=E7=B1=BB=E7=94=A8=E4=BA=8E=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E6=8A=93=E5=8F=96=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= =?UTF-8?q?=20-=20=E5=9C=A8=20DataCrawlView=20=E4=B8=AD=E9=9B=86=E6=88=90?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E5=99=A8=E5=92=8C=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E9=80=89=E6=8B=A9=E9=80=BB=E8=BE=91=20-=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20ProgressIndicator=20=E5=8A=A0=E8=BD=BD=E6=8C=87?= =?UTF-8?q?=E7=A4=BA=E5=99=A8=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=20-=20=E5=BC=95=E5=85=A5=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BD=91=E7=BB=9C=E8=AF=B7=E6=B1=82=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E7=95=8C=E9=9D=A2=E5=8D=A1=E9=A1=BF=20-=20=E9=9B=86?= =?UTF-8?q?=E6=88=90=20HttpUtil=20=E5=8F=91=E9=80=81=E6=8A=93=E5=8F=96?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=B9=B6=E4=B8=8E=E5=90=8E=E7=AB=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=80=9A=E4=BF=A1=20-=20=E9=80=9A=E8=BF=87=20GlobalCo?= =?UTF-8?q?nfig=20=E9=85=8D=E7=BD=AE=E6=8A=93=E5=8F=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=20-=20=E5=A2=9E=E5=BC=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=9C=BA=E5=88=B6=E5=B9=B6=E5=9C=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E6=98=BE=E7=A4=BA=E7=9B=B8=E5=BA=94=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=20-=20=E8=B0=83=E6=95=B4=E6=8C=89=E9=92=AE=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BB=A5=E9=98=B2=E6=AD=A2=E9=87=8D=E5=A4=8D=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=8A=93=E5=8F=96=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fantaibao/config/GlobalConfig.java | 5 + .../model/CrawlerConfigAppraisalDTO.java | 30 ++++++ .../com/fantaibao/page/DataCrawlView.java | 92 ++++++++++++++++--- 3 files changed, 113 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/fantaibao/model/CrawlerConfigAppraisalDTO.java diff --git a/src/main/java/com/fantaibao/config/GlobalConfig.java b/src/main/java/com/fantaibao/config/GlobalConfig.java index e7c6aaf..3aab778 100644 --- a/src/main/java/com/fantaibao/config/GlobalConfig.java +++ b/src/main/java/com/fantaibao/config/GlobalConfig.java @@ -30,6 +30,11 @@ public class GlobalConfig { */ public static final String configInterfaceAddress = BASE_NET_URL+"/crawler/appraisal/config"; + /** + * 数据抓取接口 + */ + public static final String crawlInterfaceAddress = BASE_NET_URL+"/crawler/appraisal/evaluation-list-scraping-interface"; + /** * 网络图标接口地址 */ diff --git a/src/main/java/com/fantaibao/model/CrawlerConfigAppraisalDTO.java b/src/main/java/com/fantaibao/model/CrawlerConfigAppraisalDTO.java new file mode 100644 index 0000000..f8bde71 --- /dev/null +++ b/src/main/java/com/fantaibao/model/CrawlerConfigAppraisalDTO.java @@ -0,0 +1,30 @@ +package com.fantaibao.model; + +import lombok.Data; + +import java.util.Date; + +@Data +public class CrawlerConfigAppraisalDTO { + + /** + * 开始时间yyyy-MM-dd HH:mm:ss,例如2025-12-01 00:00:00 + */ + private Date startTime; + /** + * 结束时间yyyy-MM-dd HH:mm:ss,例如2025-12-10 23:59:59 + */ + private Date endTime; + /** + * 动态投递topic名称 + */ + private String topic; + /** + * 指定租户 + */ + private String tenantId; + /** + * 平台0美团,1抖音,2饿了么商家端3美团外卖商家版4京东5大众点评 + */ + private Integer platform; +} diff --git a/src/main/java/com/fantaibao/page/DataCrawlView.java b/src/main/java/com/fantaibao/page/DataCrawlView.java index 36af293..aba2d91 100644 --- a/src/main/java/com/fantaibao/page/DataCrawlView.java +++ b/src/main/java/com/fantaibao/page/DataCrawlView.java @@ -1,6 +1,11 @@ package com.fantaibao.page; -import com.fantaibao.page.PlatformSelectionView; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.fantaibao.config.GlobalConfig; +import com.fantaibao.model.CrawlerConfigAppraisalDTO; +import javafx.application.Platform; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; @@ -9,7 +14,12 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; + import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.util.Date; public class DataCrawlView { @@ -17,6 +27,7 @@ public class DataCrawlView { private DatePicker startDatePicker; private DatePicker endDatePicker; private Button crawlButton; + private ProgressIndicator progressIndicator; // 添加加载指示器 private Stage primaryStage; private Scene previousScene; @@ -124,11 +135,16 @@ public class DataCrawlView { "-fx-padding: 15px 40px; -fx-border-radius: 30px; -fx-background-radius: 30px; " + "-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 10, 0, 0, 0);")); + // 创建加载指示器(默认隐藏) + progressIndicator = new ProgressIndicator(); + progressIndicator.setPrefSize(30, 30); + progressIndicator.setVisible(false); + // 为按钮添加点击事件 crawlButton.setOnAction(e -> handleCrawlAction()); // 添加按钮到按钮区域 - buttonBox.getChildren().addAll(backButton, crawlButton); + buttonBox.getChildren().addAll(backButton, crawlButton, progressIndicator); // 将组件添加到主容器 root.getChildren().addAll(titleLabel, formPane, buttonBox); @@ -142,15 +158,14 @@ public class DataCrawlView { private void handleCrawlAction() { // 获取选择的平台值 String selectedPlatform = platformComboBox.getValue(); - int platformValue = 0; // 默认美团 - + int platformValue; // 默认美团 if ("大众点评".equals(selectedPlatform)) { platformValue = 5; + } else { + platformValue = 0; } - LocalDate startDate = startDatePicker.getValue(); LocalDate endDate = endDatePicker.getValue(); - // 验证日期 if (startDate == null || endDate == null) { showAlert(Alert.AlertType.WARNING, "警告", "请选择完整的日期范围"); @@ -161,14 +176,63 @@ public class DataCrawlView { showAlert(Alert.AlertType.WARNING, "警告", "开始时间不能晚于结束时间"); return; } - - // 显示成功提示 - showAlert(Alert.AlertType.INFORMATION, "抓取成功", - "平台: " + selectedPlatform + "\n" + - "平台值: " + platformValue + "\n" + - "开始时间: " + startDate + "\n" + - "结束时间: " + endDate + "\n" + - "数据抓取任务已启动!"); + + // 显示加载指示器,禁用抓取按钮 + progressIndicator.setVisible(true); + crawlButton.setDisable(true); + crawlButton.setText("抓取中..."); + + // 在新线程中执行抓取操作 + new Thread(() -> { + try { + // 构造请求参数 + CrawlerConfigAppraisalDTO configDTO = new CrawlerConfigAppraisalDTO(); + // 设置开始时间(当天00:00:00) + LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.MIN); + configDTO.setStartTime(Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant())); + // 设置结束时间(当天23:59:59) + LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.MAX); + configDTO.setEndTime(Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant())); + configDTO.setTenantId(GlobalConfig.tenantId); + configDTO.setTopic("ftb-crawler-mt-evaluate-"+GlobalConfig.tenantId); + configDTO.setPlatform(platformValue); + System.out.println(JSON.toJSONString(configDTO)); + + // 发送网络请求 + String result = HttpUtil.post(GlobalConfig.crawlInterfaceAddress, JSON.toJSONString(configDTO)); + + // 解析返回结果 + JSONObject jsonResultObject = JSON.parseObject(result); + + // 在JavaFX主线程中更新UI + Platform.runLater(() -> { + // 隐藏加载指示器,启用抓取按钮 + progressIndicator.setVisible(false); + crawlButton.setDisable(false); + crawlButton.setText("开始抓取"); + // 根据结果提示用户 + if (jsonResultObject.getInteger("code") == 200) { + showAlert(Alert.AlertType.INFORMATION, "抓取成功", + "平台: " + selectedPlatform + "\n" + + "开始时间: " + startDate + "\n" + + "结束时间: " + endDate + "\n" + + "数据抓取任务已启动!"); + } else { + showAlert(Alert.AlertType.ERROR, "抓取失败", jsonResultObject.getString("msg")); + } + }); + } catch (Exception ex) { + // 发生异常时也要恢复UI状态 + Platform.runLater(() -> { + progressIndicator.setVisible(false); + crawlButton.setDisable(false); + crawlButton.setText("开始抓取"); + + // 显示错误提示弹窗 + showAlert(Alert.AlertType.ERROR, "抓取失败", "抓取过程中发生错误: " + ex.getMessage()); + }); + } + }).start(); } private void handleBackAction() {