cloudroam
2025-07-05 18f59ad508af9d49705b579b5094251687a9e3dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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<String> request = new HttpEntity<>(paramsJson, headers);
 
        ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
 
        return response.getBody();
    }
}