target fix
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package kz.konturai.parser.controller;
|
||||
|
||||
import kz.konturai.parser.config.FacebookLeadProperties;
|
||||
import kz.konturai.parser.dto.ApiResponse;
|
||||
import kz.konturai.parser.service.FacebookLeadCollectorService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Контроллер для ручного запуска скрапинг-парсера Facebook лидов.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/facebook/leads")
|
||||
@RequiredArgsConstructor
|
||||
public class FacebookLeadsController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FacebookLeadsController.class);
|
||||
|
||||
private final FacebookLeadCollectorService leadCollectorService;
|
||||
private final FacebookLeadProperties leadProperties;
|
||||
|
||||
/**
|
||||
* Ручной запуск сбора горячих лидов из Facebook.
|
||||
*
|
||||
* POST /api/facebook/leads/scrape
|
||||
*/
|
||||
@PostMapping("/scrape")
|
||||
public ResponseEntity<ApiResponse<Map<String, Object>>> scrapeLeads() {
|
||||
log.info("Manual Facebook lead scraping triggered");
|
||||
|
||||
try {
|
||||
if (!isConfigured()) {
|
||||
return ResponseEntity.badRequest().body(
|
||||
ApiResponse.error("Facebook не настроен: отсутствуют pageId или accessToken")
|
||||
);
|
||||
}
|
||||
|
||||
int newLeadsCount = leadCollectorService.collectHotLeads();
|
||||
|
||||
Map<String, Object> result = Map.of(
|
||||
"newLeadsCount", newLeadsCount,
|
||||
"pageId", leadProperties.getPageId(),
|
||||
"triggerTime", LocalDateTime.now().toString(),
|
||||
"triggerType", "manual"
|
||||
);
|
||||
|
||||
String message = newLeadsCount > 0
|
||||
? "Сбор лидов завершен. Найдено новых лидов: " + newLeadsCount
|
||||
: "Сбор лидов завершен. Новых лидов не найдено";
|
||||
|
||||
return ResponseEntity.ok(ApiResponse.success(message, result));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Manual Facebook lead scraping failed", e);
|
||||
return ResponseEntity.internalServerError().body(
|
||||
ApiResponse.error("Ошибка при сборе лидов: " + e.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка статуса конфигурации Facebook.
|
||||
*
|
||||
* GET /api/facebook/leads/status
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
public ResponseEntity<ApiResponse<Map<String, Object>>> getStatus() {
|
||||
try {
|
||||
boolean configured = isConfigured();
|
||||
Map<String, Object> status = Map.of(
|
||||
"configured", configured,
|
||||
"pageId", configured ? leadProperties.getPageId() : null,
|
||||
"accessTokenPresent", StringUtils.hasText(leadProperties.getAccessToken()),
|
||||
"cronExpression", leadProperties.getCron(),
|
||||
"graphApiVersion", leadProperties.getGraphApiVersion(),
|
||||
"postsPageSize", leadProperties.getPostsPageSize(),
|
||||
"commentsPageSize", leadProperties.getCommentsPageSize()
|
||||
);
|
||||
|
||||
String message = configured
|
||||
? "Facebook настроен корректно"
|
||||
: "Facebook не настроен: проверьте pageId и accessToken";
|
||||
|
||||
return ResponseEntity.ok(ApiResponse.success(message, status));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to get Facebook lead status", e);
|
||||
return ResponseEntity.internalServerError().body(
|
||||
ApiResponse.error("Ошибка при получении статуса: " + e.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConfigured() {
|
||||
return StringUtils.hasText(leadProperties.getPageId())
|
||||
&& StringUtils.hasText(leadProperties.getAccessToken());
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,7 @@ public class MarketingStrategyResponse {
|
||||
|
||||
public static class PostCalendarItem {
|
||||
private LocalDateTime publishDate;
|
||||
private Integer weekNumber;
|
||||
private String platform;
|
||||
private String contentType;
|
||||
private String theme;
|
||||
@@ -184,13 +185,17 @@ public class MarketingStrategyResponse {
|
||||
private String imageFilename;
|
||||
private String taskId;
|
||||
private String taskStatus;
|
||||
private String videoUrl;
|
||||
private String videoFilename;
|
||||
|
||||
public PostCalendarItem() {
|
||||
}
|
||||
|
||||
public PostCalendarItem(LocalDateTime publishDate, String platform, String contentType, String theme,
|
||||
public PostCalendarItem(LocalDateTime publishDate, Integer weekNumber, String platform, String contentType,
|
||||
String theme,
|
||||
String postText, List<String> hashtags, String publishTime) {
|
||||
this.publishDate = publishDate;
|
||||
this.weekNumber = weekNumber;
|
||||
this.platform = platform;
|
||||
this.contentType = contentType;
|
||||
this.theme = theme;
|
||||
@@ -207,6 +212,14 @@ public class MarketingStrategyResponse {
|
||||
this.publishDate = publishDate;
|
||||
}
|
||||
|
||||
public Integer getWeekNumber() {
|
||||
return weekNumber;
|
||||
}
|
||||
|
||||
public void setWeekNumber(Integer weekNumber) {
|
||||
this.weekNumber = weekNumber;
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
@@ -286,5 +299,21 @@ public class MarketingStrategyResponse {
|
||||
public void setTaskStatus(String taskStatus) {
|
||||
this.taskStatus = taskStatus;
|
||||
}
|
||||
|
||||
public String getVideoUrl() {
|
||||
return videoUrl;
|
||||
}
|
||||
|
||||
public void setVideoUrl(String videoUrl) {
|
||||
this.videoUrl = videoUrl;
|
||||
}
|
||||
|
||||
public String getVideoFilename() {
|
||||
return videoFilename;
|
||||
}
|
||||
|
||||
public void setVideoFilename(String videoFilename) {
|
||||
this.videoFilename = videoFilename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,9 @@ public class MarketingStrategy {
|
||||
@Field("publish_date")
|
||||
private LocalDateTime publishDate;
|
||||
|
||||
@Field("week_number")
|
||||
private Integer weekNumber;
|
||||
|
||||
@Field("platform")
|
||||
private String platform;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -144,8 +144,8 @@ facebook.page.id=918835061309575
|
||||
facebook.page.token=EAAaocqgT3JoBROtsPgmyXxbOCrhL1o6q43rdbXfZCxsrRTRFG4BFrndpZB1SeC77oI3iDqTws6ZBY3Kvv1ZAoZCFubulQjZAItIORmzdQZAmR0szuadwdAkvKENlpERtexNxNRfFEVZCWKDYm1px9knYzoJQOeGjOQOMi3oyweLgouC4ZBB3PoGB6Y8xz5Jh9b5nYCBc3
|
||||
|
||||
# Facebook Hot Leads Configuration
|
||||
facebook.leads.page-id=${FACEBOOK_LEADS_PAGE_ID:122096212527158660}
|
||||
facebook.leads.access-token=${FACEBOOK_LEADS_ACCESS_TOKEN:}
|
||||
facebook.leads.page-id=${FACEBOOK_LEADS_PAGE_ID:918835061309575}
|
||||
facebook.leads.access-token=${FACEBOOK_LEADS_ACCESS_TOKEN:EAAaocqgT3JoBROtsPgmyXxbOCrhL1o6q43rdbXfZCxsrRTRFG4BFrndpZB1SeC77oI3iDqTws6ZBY3Kvv1ZAoZCFubulQjZAItIORmzdQZAmR0szuadwdAkvKENlpERtexNxNRfFEVZCWKDYm1px9knYzoJQOeGjOQOMi3oyweLgouC4ZBB3PoGB6Y8xz5Jh9b5nYCBc3}
|
||||
facebook.leads.cron=${FACEBOOK_LEADS_CRON:0 */15 * * * *}
|
||||
facebook.leads.graph-api-version=${FACEBOOK_LEADS_GRAPH_API_VERSION:v19.0}
|
||||
facebook.leads.timeout-ms=${FACEBOOK_LEADS_TIMEOUT_MS:30000}
|
||||
|
||||
Reference in New Issue
Block a user