package com.mzl.flower.schedule; import com.mzl.flower.entity.film.AiContentTaskConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import java.util.Date; import org.springframework.stereotype.Component; @Component public class TaskExecutor { private final RestTemplate restTemplate; @Autowired public TaskExecutor(RestTemplate restTemplate) { this.restTemplate = restTemplate; } public void executeTask(AiContentTaskConfig config) { String paramsJson = config.getAiParams(); System.out.println("发送的 JSON 参数: " + paramsJson); // 添加这行 System.out.println("定时任务执行 - 时间: " + new Date()); try { // String aiResult = callPythonAiService(paramsJson); // System.out.println("AI 服务返回结果: " + aiResult); System.out.println("开始执行调用AI服务: "); // 这里处理结果入库逻辑... } catch (Exception e) { System.err.println("调用 AI 服务失败: " + e.getMessage()); e.printStackTrace(); } } public String callPythonAiService(String paramsJson) { String url = "http://127.0.0.1:5000/crawl-douban"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity request = new HttpEntity<>(paramsJson, headers); ResponseEntity response = restTemplate.postForEntity(url, request, String.class); return response.getBody(); } }