@@ -8,6 +8,7 @@ import com.iformall.domain.po.sm.MouldPatch; | |||
import com.iformall.domain.po.sm.MouldPatchSign; | |||
import com.iformall.domain.po.sm.UserMouldVideo; | |||
import com.iformall.enums.EnumMouldSendType; | |||
import com.iformall.enums.EnumVideoStatus; | |||
import com.iformall.enums.EnumaMouldPatchStatus; | |||
import com.iformall.service.sm.MouldPatchService; | |||
import com.iformall.service.sm.MouldPatchSignService; | |||
@@ -22,6 +23,7 @@ import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.Date; | |||
import java.util.List; | |||
@@ -53,8 +55,11 @@ public class UserMouldVideoController extends BaseController { | |||
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
public ResultData findById(Long id) { | |||
logger.debug("[" + getIpAddr() + "] MouldPatchController::findById"); | |||
UserMouldVideo userMouldVideo = userMouldVideoService.getById(id); | |||
return new ResultData(userMouldVideo); | |||
UserMouldVideo mouldVideo = userMouldVideoService.getById(id); | |||
if(mouldVideo == null || !mouldVideo.getUserId().equals(getMemberId())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到用户数据"); | |||
} | |||
return new ResultData(mouldVideo); | |||
} | |||
@ApiOperation("新增接口") | |||
@@ -76,14 +81,31 @@ public class UserMouldVideoController extends BaseController { | |||
if(mouldVideo == null || !mouldVideo.getUserId().equals(getMemberId())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到用户数据"); | |||
} | |||
if(StringUtils.isEmpty(mouldVideo.getPaperwork())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未填写视频文案"); | |||
} | |||
if(EnumVideoStatus.ing.getCode().equals(mouldVideo.getVideoStatus())){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"生成视频中"); | |||
} | |||
UserMouldVideo mouldVideoUpd = new UserMouldVideo(); | |||
mouldVideoUpd.setId(record.getId()); | |||
// mouldVideoUpd.setVideoId(); | |||
// mouldVideoUpd.setVideoPath(); | |||
// mouldVideoUpd.setVideoTime(); | |||
return userMouldVideoService.saveOrUpdate(mouldVideoUpd); | |||
mouldVideoUpd.setVideoStatus(EnumVideoStatus.ing.getCode()); | |||
mouldVideoUpd.setCreateVideoDate(new Date()); | |||
userMouldVideoService.saveOrUpdate(mouldVideoUpd); | |||
userMouldVideoService.createVideo(mouldVideo); | |||
return new ResultData(); | |||
} | |||
@ApiOperation("根据id查询接口") | |||
@GetMapping("/findVideo") | |||
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
public ResultData findVideo(Long id) { | |||
logger.debug("[" + getIpAddr() + "] MouldPatchController::findVideo"); | |||
UserMouldVideo userMouldVideo = userMouldVideoService.findVideo(id); | |||
return new ResultData(userMouldVideo); | |||
} | |||
} |
@@ -62,7 +62,11 @@ public class UserMouldVideo extends TenantEntity { | |||
@io.swagger.annotations.ApiModelProperty(value="",name="videoPath") | |||
private String videoPath; | |||
@io.swagger.annotations.ApiModelProperty(value="视频时长",name="videoTime") | |||
private Integer videoTime; | |||
private float videoTime; | |||
@io.swagger.annotations.ApiModelProperty(value="EnumVideoStatus 视频状态",name="videoStatus") | |||
private Integer videoStatus; | |||
@io.swagger.annotations.ApiModelProperty(value="生成视频信息",name="videoMsg") | |||
private String videoMsg; | |||
@io.swagger.annotations.ApiModelProperty(value="生成视频时间",name="createVideoDate") | |||
private Date createVideoDate; | |||
@@ -0,0 +1,51 @@ | |||
package com.iformall.enums; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
public enum EnumVideoStatus { | |||
draft(0, "草稿"), | |||
ing(1, "生成视频中"), | |||
success(2, "生成视频成功"), | |||
fail(3, "生成视频失败"), | |||
; | |||
public static EnumVideoStatus getEnum(Integer code) { | |||
for (EnumVideoStatus value : values()) { | |||
if (value.getCode().equals(code)) { | |||
return value; | |||
} | |||
} | |||
return null; | |||
} | |||
public static List<Integer> getAllCodes(){ | |||
List<Integer> codes = new ArrayList<>(); | |||
for (EnumVideoStatus value : values()) { | |||
codes.add(value.getCode()); | |||
} | |||
return codes; | |||
} | |||
private Integer code; | |||
private String message; | |||
EnumVideoStatus(Integer code, String message) { | |||
this.code = code; | |||
this.message = message; | |||
} | |||
public Integer getCode() { | |||
return code; | |||
} | |||
public String getMessage() { | |||
return message; | |||
} | |||
} |
@@ -19,4 +19,5 @@ public interface UserMouldVideoMapper extends CommonMapper<UserMouldVideo, Long> | |||
*/ | |||
List<UserMouldVideo> findCList(UserMouldVideo record); | |||
UserMouldVideo findVideo(@Param("id")Long id); | |||
} |
@@ -39,4 +39,8 @@ public interface UserMouldVideoService { | |||
* @param id | |||
*/ | |||
void deleteById(Long id); | |||
void createVideo(UserMouldVideo mouldVideo); | |||
UserMouldVideo findVideo(Long id); | |||
} |
@@ -5,11 +5,16 @@ import com.github.pagehelper.PageInfo; | |||
import com.iformall.common.IdWorker; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.sm.UserMouldVideo; | |||
import com.iformall.enums.EnumVideoStatus; | |||
import com.iformall.mapper.UserMouldVideoMapper; | |||
import com.iformall.service.sm.UserMouldVideoService; | |||
import com.iformall.sm.AiVideoHelper; | |||
import com.iformall.sm.AiVideoResult; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.scheduling.annotation.Async; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Date; | |||
@@ -61,4 +66,55 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { | |||
userMouldVideoMapper.deleteById(id); | |||
} | |||
@Async | |||
@Override | |||
public void createVideo(UserMouldVideo mouldVideo) { | |||
UserMouldVideo videoUpd = new UserMouldVideo(); | |||
videoUpd.setId(mouldVideo.getId()); | |||
if(StringUtils.isBlank(mouldVideo.getPersonMouldPath())){ | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg("未找到人物模板数据"); | |||
this.saveOrUpdate(videoUpd); | |||
return; | |||
} | |||
if(StringUtils.isBlank(mouldVideo.getPaperwork())){ | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg("未填写视频文案"); | |||
this.saveOrUpdate(videoUpd); | |||
return; | |||
} | |||
try{ | |||
AiVideoResult video = AiVideoHelper.createVideo(mouldVideo.getPersonMouldPath(), mouldVideo.getVoiceMouldPath(), mouldVideo.getPaperwork()); | |||
if(video.isSuccess()){ | |||
videoUpd.setVideoPath(video.getUrl()); | |||
videoUpd.setVideoTime(video.getDuration()); | |||
videoUpd.setVideoStatus(EnumVideoStatus.success.getCode()); | |||
videoUpd.setVideoMsg(video.getMsg()); | |||
videoUpd.setCreateVideoDate(new Date()); | |||
this.saveOrUpdate(videoUpd); | |||
return; | |||
} | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg(video.getMsg()); | |||
this.saveOrUpdate(videoUpd); | |||
return; | |||
}catch(Exception e){ | |||
e.printStackTrace(); | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg(e.getMessage()); | |||
this.saveOrUpdate(videoUpd); | |||
return; | |||
} | |||
} | |||
@Override | |||
public UserMouldVideo findVideo(Long id) { | |||
return userMouldVideoMapper.findVideo(id); | |||
} | |||
} |
@@ -0,0 +1,90 @@ | |||
package com.iformall.sm; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.iformall.common.ErrorCode; | |||
import com.iformall.douyin.pay.orderQuery.OrderQueryResult; | |||
import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; | |||
import com.iformall.douyin.pay.orderQuery.QueryRefundResult; | |||
import com.iformall.douyin.pay.orderQuery.QuerySettleResult; | |||
import com.iformall.douyin.pay.preOrder.*; | |||
import com.iformall.enums.EnumPayStatus; | |||
import com.iformall.exception.MallinkException; | |||
import com.iformall.utils.HttpUtil; | |||
import com.iformall.utils.sign.SignUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.nio.charset.StandardCharsets; | |||
import java.security.MessageDigest; | |||
import java.security.NoSuchAlgorithmException; | |||
import java.util.*; | |||
@Slf4j | |||
public class AiVideoHelper { | |||
public static String doPost(String url, Map<String, Object> params) { | |||
return HttpUtil.doPost(url,null, JSON.toJSONString(params)); | |||
} | |||
public static AiVideoResult createVideo(String video_template_id,String voice_id,String gen_txt) { | |||
Map<String,Object> params = new HashMap<>(); | |||
params.put("video_template_id",video_template_id); | |||
if(StringUtils.isBlank(voice_id)){ | |||
voice_id = "default"; | |||
} | |||
params.put("voice_id",voice_id); | |||
params.put("gen_txt",gen_txt); | |||
String response = doPost("http://222.128.9.132:22266/gen_dh_video", params); | |||
log.info("服务端预下单 request:"+params.toString()+" response:"+response); | |||
AiVideoResult result = new AiVideoResult(); | |||
JSONObject jsonObject = JSON.parseObject(response); | |||
JSONObject status = jsonObject.getJSONObject("status"); | |||
Integer code = status.getInteger("code"); | |||
if(null != code && code.intValue() == 1000){ | |||
JSONObject data = jsonObject.getJSONObject("data"); | |||
JSONObject video = data.getJSONObject("video"); | |||
result.setSuccess(true); | |||
result.setMsg("success"); | |||
result.setDuration(video.getFloatValue("duration")); | |||
result.setUrl(video.getString("url")); | |||
}else{ | |||
result.setSuccess(false); | |||
result.setMsg(status.getString("msg")); | |||
} | |||
return result; | |||
// Integer code = jsonObject.getInteger("err_no"); | |||
// if (null != code && code.intValue() == 0 ) { | |||
// CreatePreOrderResult result = new CreatePreOrderResult(); | |||
// result.setSuccess(true); | |||
// result.setOutOrderNo(preOrder.getOutOrderNo()); | |||
// JSONObject data = jsonObject.getJSONObject("data"); | |||
// if (null != data ) { | |||
// result.setOrderId(data.getString("order_id")); | |||
// result.setToken(data.getString("order_token")); | |||
// }else { | |||
// log.error("createPreOrder reponse empity. request: "+JSON.toJSONString(preOrder.toRequestMap())+" response:"+response); | |||
// result.setSuccess(false); | |||
// result.setMsg("createPreOrder reponse empity."+response); | |||
// } | |||
// return result; | |||
// }else { | |||
// log.error("createPreOrder reponse error. request: "+JSON.toJSONString(preOrder.toRequestMap())+" response:"+response); | |||
// CreatePreOrderResult result = new CreatePreOrderResult(); | |||
// result.setSuccess(false); | |||
// result.setMsg("createPreOrder reponse error."+response); | |||
// return result; | |||
// } | |||
} | |||
public static void main(String[] args) { | |||
createVideo("16739389169485046_nVi875Ej","default","人们自古以来,在这条路上行走,然而,这条路确实是坎坷不平、逶迤曲折、无边无际的,它具有无数分支,充满着欢乐、痛苦、艰险,但这就是人生的道路。"); | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.iformall.sm; | |||
import lombok.Data; | |||
@Data | |||
public class AiVideoResult { | |||
private boolean success; | |||
private String msg; | |||
private float duration; | |||
private String url; | |||
} |
@@ -18,7 +18,10 @@ | |||
<result column="remark" jdbcType="VARCHAR" property="remark"/> | |||
<result column="video_id" jdbcType="VARCHAR" property="videoId"/> | |||
<result column="video_path" jdbcType="VARCHAR" property="videoPath"/> | |||
<result column="video_time" jdbcType="INTEGER" property="videoTime"/> | |||
<result column="video_time" jdbcType="float" property="videoTime"/> | |||
<result column="video_status" jdbcType="INTEGER" property="videoStatus"/> | |||
<result column="video_msg" jdbcType="VARCHAR" property="videoMsg"/> | |||
<result column="create_video_date" jdbcType="TIMESTAMP" property="createVideoDate"/> | |||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
@@ -27,7 +30,7 @@ | |||
<sql id="allColumns"> | |||
`id`, `tenant_id`, `parent_tenant_id`, `user_id`, `type`, | |||
`person_mould_id`, `person_mould_path`, `voice_mould_id`, `voice_mould_path`, `paperwork`, `background_mould_id`, `background_mould_path`, | |||
`title`, `remark`, `video_id`, `video_path`, `video_time`, `create_video_date`, `create_date`, `update_date` | |||
`title`, `remark`, `video_id`, `video_path`, `video_time`, `video_status`, `video_msg`, `create_video_date`, `create_date`, `update_date` | |||
</sql> | |||
<sql id="dynamicWhereConditions"> | |||
@@ -68,6 +71,10 @@ | |||
and `title` like concat('%', #{title},'%') | |||
</if> | |||
<if test=" null != videoStatus "> | |||
and `video_status` = #{videoStatus} | |||
</if> | |||
<if test=" null != startDate and null!=endDate"> | |||
and `create_date` between #{startDate} and #{endDate} | |||
</if> | |||
@@ -97,9 +104,19 @@ | |||
select | |||
`id`, `type`, | |||
`paperwork`, | |||
`title`, `remark`, `video_id`, `video_path`, `video_time`, `create_video_date`, `create_date`, `update_date` | |||
`title`, `remark`, `video_id`, `video_path`, `video_time`,`video_status`, | |||
`create_video_date`, `create_date`, `update_date` | |||
from user_mould_video | |||
<include refid="dynamicWhereConditions"/> | |||
</select> | |||
<select id="findVideo" parameterType="java.util.HashMap" resultMap="BaseResultMap"> | |||
select | |||
`video_id`, `video_path`, `video_time`,`video_status` | |||
from user_mould_video | |||
where `id` = #{id} | |||
</select> | |||
</mapper> |