| | |
| | | package com.mzl.flower.schedule; |
| | | |
| | | import com.mzl.flower.constant.Constants; |
| | | 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.util.StringUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.Date; |
| | |
| | | System.out.println("定时任务执行 - 时间: " + new Date()); |
| | | |
| | | try { |
| | | // String aiResult = callPythonAiService(paramsJson); |
| | | // System.out.println("AI 服务返回结果: " + aiResult); |
| | | System.out.println("开始执行调用AI服务: "); |
| | | if(Constants.GENERATOR_CONTENT.film_content.name().equals(config.getType())){ |
| | | System.out.println("开始执行调用内容生成服务: "); |
| | | String aiResult = callPythonContentService(paramsJson); |
| | | System.out.println("AI 服务返回结果: " + aiResult); |
| | | }else{ |
| | | System.out.println("开始执行调用作品名称生成服务: "); |
| | | String aiResult = callPythonFilmNameService(paramsJson); |
| | | System.out.println("AI 服务返回结果: " + aiResult); |
| | | } |
| | | // 这里处理结果入库逻辑... |
| | | } catch (Exception e) { |
| | | System.err.println("调用 AI 服务失败: " + e.getMessage()); |
| | |
| | | } |
| | | } |
| | | |
| | | public String callPythonAiService(String paramsJson) { |
| | | String url = "http://127.0.0.1:5000/crawl-douban"; |
| | | public String callPythonFilmNameService(String paramsJson) { |
| | | System.out.println("开始执行调用python crawl: "); |
| | | String url = "http://14.103.144.28: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(); |
| | | } |
| | | |
| | | public String callPythonContentService(String paramsJson) { |
| | | System.out.println("开始执行调用python generate: "); |
| | | // String url = "http://192.168.1.213:5000/generate-film-content"; |
| | | String url = "http://14.103.144.28:5000/generate-film-content"; |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |