mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 11:56:50 +08:00
添加接口调用
This commit is contained in:
@@ -239,6 +239,10 @@
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
<version>2.3.0</version> <!-- 请根据实际需求选择版本 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xboe.module.course.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -7,9 +8,21 @@ import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.module.course.dto.CourseParam;
|
||||
import com.xboe.module.course.dto.*;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.utils.HttpUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -21,13 +34,6 @@ import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.core.log.AutoLog;
|
||||
import com.xboe.module.course.dto.CourseFullDto;
|
||||
import com.xboe.module.course.dto.CourseHRBPAuditDto;
|
||||
import com.xboe.module.course.dto.CourseQueryDto;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseAudit;
|
||||
import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseHRBPAudit;
|
||||
import com.xboe.module.course.service.ICourseAuditService;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseHRBPAuditService;
|
||||
@@ -435,16 +441,68 @@ public class CourseAuditApi extends ApiBaseController{
|
||||
param.setOrgName(dto.getCourse().getOrgName());
|
||||
thirdApi.updateOrSaveCourse(param,token);
|
||||
log.info("---------------在线课同步到讲师管理完毕 -------");
|
||||
//AI视频处理-调用接口
|
||||
this.sendMessageToKJB(dto);
|
||||
log.info("---------------AI视频处理-调用接口完毕 -------");
|
||||
return success(true);
|
||||
} catch (Exception e) {
|
||||
log.error("默认管理员提交直接发布处理失败",e);
|
||||
e.printStackTrace();
|
||||
return error("发布课程失败",e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void sendMessageToKJB(CourseFullDto dto) throws JsonProcessingException {
|
||||
Course course = dto.getCourse();
|
||||
List<CourseTeacher> teachers = dto.getTeachers();
|
||||
StringBuilder teacherNames = new StringBuilder();
|
||||
for (CourseTeacher teacher : teachers) {
|
||||
teacherNames.append(teacher.getTeacherName()).append(",");
|
||||
}
|
||||
List<CourseContent> cclist = ccontentService.getByCourseId(course.getId());
|
||||
List<String> languageCode = course.getLanguageCode();
|
||||
String code = String.join(",", languageCode);
|
||||
BoeaiCourseDto boeaiCourseDto = new BoeaiCourseDto();
|
||||
List<BoeaiVideoResourceDto> videoList = new ArrayList<>();
|
||||
boeaiCourseDto = BoeaiCourseDto.builder()
|
||||
.courseId(course.getId())
|
||||
.title(course.getName())
|
||||
.description(course.getSummary())
|
||||
.instructor(teacherNames.toString())
|
||||
.chapterCount(1) //章节数
|
||||
.languageCode(code) //语言
|
||||
.build() ;
|
||||
for (CourseContent cc : cclist) {
|
||||
//筛选视频资源
|
||||
if(cc.getContentType() == 10 ){
|
||||
JSONObject json = JSONObject.parseObject(cc.getContent());
|
||||
if(json == null || json.getString("url") == null) {
|
||||
continue;
|
||||
}
|
||||
String videoUrl = json.getString("url");
|
||||
String videoUrlPerfix = "https://u-pre.boe.com/upload"; //测试
|
||||
//String videoUrlPerfix = "https://u.boe.com/upload"; //生产
|
||||
String videoType = videoUrl.substring(videoUrl.lastIndexOf(".")+1);
|
||||
videoList.add(BoeaiVideoResourceDto.builder()
|
||||
.courseId(cc.getCourseId())
|
||||
.videoId(cc.getId())
|
||||
.title(cc.getContentName())
|
||||
.originalUrl(videoUrlPerfix+videoUrl)
|
||||
.duration(cc.getDuration())
|
||||
.format(videoType)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
boeaiCourseDto.setBoeaiVideoResourceReqList(videoList);
|
||||
boeaiCourseDto.setVideoCount(videoList.size());
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String message = objectMapper.writeValueAsString(boeaiCourseDto);
|
||||
String url = "http://10.251.160.38:8088/aiVideo/saveCourse";
|
||||
HttpUtils.sendMessage(message,url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* 审核
|
||||
* @param dto
|
||||
@@ -475,5 +533,8 @@ public class CourseAuditApi extends ApiBaseController{
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @date 2025年11月18日
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BoeaiCourseDto {
|
||||
List<BoeaiVideoResourceDto> boeaiVideoResourceReqList;
|
||||
|
||||
|
||||
List<String> courseVideoIds;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 课程ID
|
||||
*/
|
||||
private String courseId;
|
||||
/**
|
||||
* 视频ID
|
||||
*/
|
||||
private String videoId;
|
||||
|
||||
/**
|
||||
* 课程标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 讲师名称
|
||||
*/
|
||||
private String instructor;
|
||||
|
||||
/**
|
||||
* 章节数
|
||||
*/
|
||||
private Integer chapterCount;
|
||||
|
||||
/**
|
||||
* 视频数
|
||||
*/
|
||||
private Integer videoCount;
|
||||
|
||||
/**
|
||||
* 总时长(秒)
|
||||
*/
|
||||
private Integer totalDuration;
|
||||
|
||||
private Date createdAt;
|
||||
|
||||
private Date updatedAt;
|
||||
|
||||
/**
|
||||
* 课程描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 视频语言编码 如 zh-CN, en-US
|
||||
*/
|
||||
private String languageCode;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @date 2025年11月18日
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BoeaiVideoResourceDto {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 视频业务ID
|
||||
*/
|
||||
private String videoId;
|
||||
/**
|
||||
* 课程ID
|
||||
*/
|
||||
private String courseId;
|
||||
|
||||
/**
|
||||
* 视频标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 原始视频URL
|
||||
*/
|
||||
private String originalUrl;
|
||||
|
||||
/**
|
||||
* 视频时长(秒)
|
||||
*/
|
||||
private Integer duration;
|
||||
|
||||
/**
|
||||
* 文件大小(字节)
|
||||
*/
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
* 视频格式 mp4/avi等
|
||||
*/
|
||||
private String format;
|
||||
|
||||
/**
|
||||
* 状态 0-待处理 1-处理中 2-已完成 3-失败
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 是否已审核 0-否 1-是
|
||||
*/
|
||||
private Integer isReviewed;
|
||||
|
||||
/**
|
||||
* 审核人ID
|
||||
*/
|
||||
private String reviewerId;
|
||||
|
||||
/**
|
||||
* 审核时间
|
||||
*/
|
||||
private Date reviewedAt;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Date createdAt;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Date updatedAt;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@@ -216,6 +217,33 @@ public class Course extends BaseEntity {
|
||||
@Column(name = "device",length = 1)
|
||||
private Integer device;
|
||||
|
||||
|
||||
/**
|
||||
* 0:关闭;1:打开;
|
||||
* */
|
||||
// @Column(name = "ai_set",length = 1)
|
||||
private Integer aiSet;
|
||||
/**
|
||||
* 摘要 0:上架;1:下架;
|
||||
* */
|
||||
//@Column(name = "ai_abstract",length = 1)
|
||||
private Integer aiAbstract;
|
||||
/**
|
||||
* 文稿 0:上架;1:下架;
|
||||
* */
|
||||
// @Column(name = "ai_draft",length = 1)
|
||||
private Integer aiDraft;
|
||||
/**
|
||||
* 翻译 0:上架;1:下架;
|
||||
* */
|
||||
//@Column(name = "ai_translate",length = 1)
|
||||
private Integer aiTranslate;
|
||||
/**
|
||||
* 语言 zh-CN,en-US,ja-JP,ko-KR
|
||||
* */
|
||||
//Column(name = "language_code",length = 120)
|
||||
private List<String> languageCode;
|
||||
|
||||
/**
|
||||
* 课程状态,多人审核机制,所以这里并没有审核通过与不通过的状态了
|
||||
* 课程状态 1:未提交(草稿);2:已提交;3: 审核未通过,5审核完成
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.xboe.module.course.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @date 2025年11月18日
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpUtils {
|
||||
public static CloseableHttpResponse sendMessage(String message,String url) {
|
||||
log.info("----------------发送消息开始 -------");
|
||||
//log.info("----------------发送消息url -------{}",url);
|
||||
log.info("----------------发送消息参数 -------{}",message);
|
||||
// POST 请求
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
// POST 请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
//HttpPost httpPost = new HttpPost("https://jsonplaceholder.typicode.com/posts");
|
||||
httpPost.setEntity(new StringEntity(message));
|
||||
httpPost.setHeader("Content-Type", "application/json");
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
log.info("---------------发送消息响应 -------{}",response);
|
||||
return response;
|
||||
// System.out.println("状态码: " + response.getCode());
|
||||
// System.out.println("响应体: " + EntityUtils.toString(response.getEntity()));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("KJB-发送消息错误",e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user