@@ -1,13 +1,17 @@ | |||||
package com.iformall.schedule; | package com.iformall.schedule; | ||||
import com.iformall.domain.po.sm.UserMouldVideo; | import com.iformall.domain.po.sm.UserMouldVideo; | ||||
import com.iformall.domain.po.sm.VideoTrans; | |||||
import com.iformall.domain.po.tt.TtCoupon; | import com.iformall.domain.po.tt.TtCoupon; | ||||
import com.iformall.enums.EnumVideoStatus; | import com.iformall.enums.EnumVideoStatus; | ||||
import com.iformall.enums.EnumaVideoTransStatus; | |||||
import com.iformall.mapper.TtCouponMapper; | import com.iformall.mapper.TtCouponMapper; | ||||
import com.iformall.mapper.VideoTransMapper; | |||||
import com.iformall.service.sm.UserMouldVideoService; | import com.iformall.service.sm.UserMouldVideoService; | ||||
import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
import com.iformall.video.VideoFactory; | import com.iformall.video.VideoFactory; | ||||
import com.iformall.video.aliyun.sdk.server.UploadCacheHelper; | import com.iformall.video.aliyun.sdk.server.UploadCacheHelper; | ||||
import com.iformall.video.entity.VideTransResult; | |||||
import com.iformall.video.entity.VideUploadResult; | import com.iformall.video.entity.VideUploadResult; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
@@ -30,6 +34,9 @@ public class VideoSchedule { | |||||
@Autowired | @Autowired | ||||
private UserMouldVideoService userMouldVideoService; | private UserMouldVideoService userMouldVideoService; | ||||
@Autowired | |||||
private VideoTransMapper videoTransMapper; | |||||
@Autowired | @Autowired | ||||
VideoFactory videoFactory; | VideoFactory videoFactory; | ||||
@@ -99,4 +106,63 @@ public class VideoSchedule { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 转码 | |||||
*/ | |||||
@Scheduled(cron = "0 10/30 * * * *?") // 每半小时检查一次 | |||||
public void videoTransSchedule() { | |||||
VideoTrans videoTransQ = new VideoTrans(); | |||||
videoTransQ.setStatus(EnumaVideoTransStatus.draft.getCode()); | |||||
List<VideoTrans> videos = videoTransMapper.findList(videoTransQ); | |||||
if (videos != null && videos.size() > 0) { | |||||
for (VideoTrans video : videos) { | |||||
try { | |||||
VideTransResult videTransResult = videoFactory.getExcutor(videoType).transVideo(video.getVideoId(), video.getTransTemplateId()); | |||||
if(videTransResult.isSuccess()){ | |||||
VideoTrans upd = new VideoTrans(); | |||||
upd.setId(video.getId()); | |||||
upd.setTaskId(videTransResult.getTaskId()); | |||||
upd.setStatus(EnumaVideoTransStatus.ing.getCode()); | |||||
upd.setMsg("ing"); | |||||
upd.setUpdateDate(new Date()); | |||||
videoTransMapper.updateById(upd); | |||||
} | |||||
} catch (Exception e) { | |||||
logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 转码结果 | |||||
*/ | |||||
@Scheduled(cron = "0 20/30 * * * *?") // 每半小时检查一次 | |||||
public void videoTransResultSchedule() { | |||||
VideoTrans videoTransQ = new VideoTrans(); | |||||
videoTransQ.setStatus(EnumaVideoTransStatus.ing.getCode()); | |||||
List<VideoTrans> videos = videoTransMapper.findList(videoTransQ); | |||||
if (videos != null && videos.size() > 0) { | |||||
for (VideoTrans video : videos) { | |||||
try { | |||||
VideTransResult transVideoResult = videoFactory.getExcutor(videoType).getTransVideoResult(video.getVideoId(), video.getTaskId()); | |||||
VideoTrans upd = new VideoTrans(); | |||||
upd.setId(video.getId()); | |||||
if (transVideoResult.isSuccess()){ | |||||
upd.setStatus(EnumaVideoTransStatus.success.getCode()); | |||||
upd.setMsg("success"); | |||||
}else{ | |||||
upd.setStatus(EnumaVideoTransStatus.fail.getCode()); | |||||
upd.setMsg(transVideoResult.getMsg()); | |||||
} | |||||
upd.setUpdateDate(new Date()); | |||||
videoTransMapper.updateById(upd); | |||||
} catch (Exception e) { | |||||
logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } |
@@ -54,7 +54,9 @@ public class UserMouldVideo extends TenantEntity { | |||||
* "videoType":, | * "videoType":, | ||||
* "title":, | * "title":, | ||||
* "mouldSmId":, | * "mouldSmId":, | ||||
* "material": | |||||
* "material":, | |||||
* "backgroundId:, | |||||
* "backgroundMaterial": | |||||
* } | * } | ||||
*/ | */ | ||||
@io.swagger.annotations.ApiModelProperty(value="人物模板",name="personMouldSm") | @io.swagger.annotations.ApiModelProperty(value="人物模板",name="personMouldSm") | ||||
@@ -73,8 +75,10 @@ public class UserMouldVideo extends TenantEntity { | |||||
* "mouldSmId":, | * "mouldSmId":, | ||||
* "personId":, | * "personId":, | ||||
* "personType":, | * "personType":, | ||||
* "personTypeStr":, | |||||
* "speakId":, | * "speakId":, | ||||
* "speakType": | |||||
* "speakType":, | |||||
* "speakTypeStr": | |||||
* } | * } | ||||
*/ | */ | ||||
@io.swagger.annotations.ApiModelProperty(value="声音模板",name="voiceMouldSm") | @io.swagger.annotations.ApiModelProperty(value="声音模板",name="voiceMouldSm") | ||||
@@ -0,0 +1,55 @@ | |||||
package com.iformall.domain.po.sm; | |||||
import cn.afterturn.easypoi.excel.annotation.Excel; | |||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.baomidou.mybatisplus.annotation.TableField; | |||||
import com.baomidou.mybatisplus.annotation.TableName; | |||||
import com.iformall.common.SortColumn; | |||||
import com.iformall.domain.po.base.TenantEntity; | |||||
import com.iformall.enums.EnumAgeType; | |||||
import com.iformall.enums.EnumPersonType; | |||||
import com.iformall.enums.EnumSex; | |||||
import com.iformall.enums.EnumSpeakType; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.ToString; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import java.math.BigDecimal; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
@TableName(value = "video_trans") | |||||
@Data | |||||
@ToString(callSuper = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
public class VideoTrans extends TenantEntity { | |||||
protected Long id; | |||||
@TableField(exist = false) | |||||
@io.swagger.annotations.ApiModelProperty(value="查询-起始时间",name="startDate") | |||||
private Date startDate; | |||||
@TableField(exist = false) | |||||
@io.swagger.annotations.ApiModelProperty(value="查询-结束时间",name="endDate") | |||||
private Date endDate; | |||||
@io.swagger.annotations.ApiModelProperty(value="videoid",name="videoId") | |||||
private String videoId; | |||||
@io.swagger.annotations.ApiModelProperty(value="转码模板",name="transTemplateId") | |||||
private String transTemplateId; | |||||
@io.swagger.annotations.ApiModelProperty(value="任务id",name="taskId") | |||||
private String taskId; | |||||
@io.swagger.annotations.ApiModelProperty(value="",name="msg") | |||||
private String msg; | |||||
@io.swagger.annotations.ApiModelProperty(value="EnumaVideoTransStatus ",name="status") | |||||
private Integer status; | |||||
@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||||
private Date createDate; | |||||
@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||||
private Date updateDate; | |||||
} |
@@ -0,0 +1,39 @@ | |||||
package com.iformall.enums; | |||||
/** | |||||
* | |||||
*/ | |||||
public enum EnumaVideoTransStatus { | |||||
// | |||||
draft(0, "已保存"), | |||||
ing(1, "转码中"), | |||||
success(2, "转码成功"), | |||||
fail(3, "转码失败"), | |||||
; | |||||
public static EnumaVideoTransStatus getEnum(Integer code) { | |||||
for (EnumaVideoTransStatus value : values()) { | |||||
if (value.getCode().equals(code)) { | |||||
return value; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
private Integer code; | |||||
private String message; | |||||
EnumaVideoTransStatus(Integer code, String message) { | |||||
this.code = code; | |||||
this.message = message; | |||||
} | |||||
public Integer getCode() { | |||||
return code; | |||||
} | |||||
public String getMessage() { | |||||
return message; | |||||
} | |||||
} |
@@ -0,0 +1,17 @@ | |||||
package com.iformall.mapper; | |||||
import com.iformall.common.CommonMapper; | |||||
import com.iformall.domain.po.sm.VideoTrans; | |||||
import com.iformall.domain.po.sm.VoiceMould; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import java.util.List; | |||||
public interface VideoTransMapper extends CommonMapper<VideoTrans, Long> { | |||||
List<VideoTrans> findList(VideoTrans record); | |||||
int deleteById(@Param("id")Long id); | |||||
} |
@@ -0,0 +1,57 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.iformall.mapper.VideoTransMapper"> | |||||
<resultMap id="BaseResultMap" type="com.iformall.domain.po.sm.VideoTrans"> | |||||
<id column="id" jdbcType="BIGINT" property="id"/> | |||||
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
<result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||||
<result column="video_id" jdbcType="VARCHAR" property="videoId"/> | |||||
<result column="trans_template_id" jdbcType="VARCHAR" property="transTemplateId"/> | |||||
<result column="task_id" jdbcType="VARCHAR" property="taskId"/> | |||||
<result column="msg" jdbcType="VARCHAR" property="msg"/> | |||||
<result column="status" jdbcType="INTEGER" property="status"/> | |||||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||||
</resultMap> | |||||
<sql id="allColumns"> | |||||
`id`, `tenant_id`, `parent_tenant_id`, `video_id`, `trans_template_id`, `task_id`, | |||||
`status`,`msg`, `create_date`, `update_date` | |||||
</sql> | |||||
<sql id="dynamicWhereConditions"> | |||||
where `is_del` = 0 | |||||
<if test=" null != status"> | |||||
and `status` = #{status} | |||||
</if> | |||||
<if test=" null != startDate "> | |||||
and create_date >= #{startDate} | |||||
</if> | |||||
<if test=" null != endDate"> | |||||
and create_date < #{endDate} | |||||
</if> | |||||
<if test=" null != ids "> | |||||
and id in | |||||
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
#{idItem} | |||||
</foreach> | |||||
</if> | |||||
<if test=" null != sortColumns">order by ${sortColumns}</if> | |||||
</sql> | |||||
<select id="findList" parameterType="com.iformall.domain.po.sm.VoiceMould" resultMap="BaseResultMap"> | |||||
select | |||||
<include refid="allColumns"/> | |||||
from video_trans | |||||
<include refid="dynamicWhereConditions"/> | |||||
</select> | |||||
<delete id="deleteById" parameterType="java.util.HashMap"> | |||||
update video_trans set is_del = 1,update_date = now() where id = #{id} | |||||
</delete> | |||||
</mapper> |
@@ -29,7 +29,7 @@ public interface VideoExcutor { | |||||
VideUploadResult getVideoDetailFromApi(String videoId); | VideUploadResult getVideoDetailFromApi(String videoId); | ||||
public VideTransResult transVideo(String videoId); | |||||
public VideTransResult transVideo(String videoId,String transTemplateId); | |||||
public VideTransResult getTransVideoResult(String videoId, String taskId); | public VideTransResult getTransVideoResult(String videoId, String taskId); | ||||
} | } |
@@ -197,14 +197,14 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||||
} | } | ||||
@Override | @Override | ||||
public VideTransResult transVideo(String videoId) { | |||||
public VideTransResult transVideo(String videoId,String transTemplateId) { | |||||
VideTransResult result = new VideTransResult(); | VideTransResult result = new VideTransResult(); | ||||
//解码 | //解码 | ||||
if ((!StringUtils.isBlank(videoId)) && (!StringUtils.isBlank(config.getTransTemplateId()))) { | |||||
if ((!StringUtils.isBlank(videoId)) && (!StringUtils.isBlank(transTemplateId))) { | |||||
result.setVideoId(videoId); | result.setVideoId(videoId); | ||||
SubmitTranscodeJobsResponse transResponse = new SubmitTranscodeJobsResponse(); | SubmitTranscodeJobsResponse transResponse = new SubmitTranscodeJobsResponse(); | ||||
try { | try { | ||||
transResponse = AliyunVedioServer.submitTranscodeJobs(config, videoId, config.getTransTemplateId()); | |||||
transResponse = AliyunVedioServer.submitTranscodeJobs(config, videoId, transTemplateId); | |||||
//任务ID | //任务ID | ||||
//System.out.println("JobId = " + transResponse.getTranscodeJobs().get(0).getJobId()); | //System.out.println("JobId = " + transResponse.getTranscodeJobs().get(0).getJobId()); | ||||
result.setTaskId(transResponse.getTranscodeTaskId()); | result.setTaskId(transResponse.getTranscodeTaskId()); | ||||
@@ -13,6 +13,6 @@ public class AliyunVideoConfig { | |||||
private String accessKeySecret; | private String accessKeySecret; | ||||
private String regionId;//cn-shanghai 点播服务接入区域 | private String regionId;//cn-shanghai 点播服务接入区域 | ||||
private String endPoint;//以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com | private String endPoint;//以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com | ||||
private String transTemplateId;//转码的模板编号 | |||||
// private String transTemplateId;//转码的模板编号 | |||||
private String autoTrans; | private String autoTrans; | ||||
} | } |