| @@ -85,23 +85,20 @@ public class PersonPhotoController extends BaseController { | |||
| } | |||
| @ApiOperation("图片质量审核接口") | |||
| @GetMapping("checkPhoto") | |||
| @ApiImplicitParam(name = "material", value = "material", dataType = "String", paramType = "query", required = true) | |||
| public ResultData checkPhoto(String material) { | |||
| @PostMapping(value = "checkPhoto", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||
| @ApiImplicitParam(name = "file", value = "file", dataType = "MultipartFile", paramType = "query", required = true) | |||
| public ResultData checkPhoto(@RequestPart("file") MultipartFile file) { | |||
| logger.debug("[" + getIpAddr() + "] PersonPhotoController::checkPhoto"); | |||
| if (StringUtils.isBlank(material)) { | |||
| if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "素材为空"); | |||
| } | |||
| ResultData data = personPhotoService.checkPhoto(material); | |||
| if (data.code == 2000) { | |||
| return new ResultData(); | |||
| } | |||
| return new ResultData(data.message); | |||
| personPhotoService.checkPhoto(file); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("百度图片审核接口") | |||
| @PostMapping(value = "baiduPhoto", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||
| @ApiImplicitParam(name = "material", value = "material", dataType = "String", paramType = "query", required = true) | |||
| @ApiImplicitParam(name = "file", value = "file", dataType = "MultipartFile", paramType = "query", required = true) | |||
| public ResultData baiduCheckPhoto(@RequestPart("file") MultipartFile file) { | |||
| logger.debug("[" + getIpAddr() + "] PersonPhotoController::baiduCheckPhoto"); | |||
| if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { | |||
| @@ -466,7 +466,7 @@ public class PhotoSpeakVideoController extends BaseController { | |||
| speakVideo.setUpdateDate(new Date()); | |||
| photoSpeakVideoService.updateById(speakVideo); | |||
| photoSpeakVideoService.videoHy(speakVideo,true); | |||
| photoSpeakVideoService.videoHy(speakVideo); | |||
| return new ResultData(); | |||
| } | |||
| @@ -17,10 +17,9 @@ import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.util.ObjectUtils; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.util.Date; | |||
| @@ -43,12 +42,12 @@ public class SDKController extends BaseController { | |||
| @ApiOperation("图片质量审核接口") | |||
| @PostMapping("checkPhoto") | |||
| @ApiImplicitParam(name = "material", value = "material", dataType = "String", paramType = "query", required = true) | |||
| public ResultData checkPhoto(String material) { | |||
| public ResultData checkPhoto(@RequestPart("file") MultipartFile file) { | |||
| logger.debug("[" + getIpAddr() + "] SDKController::checkPhoto"); | |||
| if (StringUtils.isBlank(material)) { | |||
| if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "素材为空"); | |||
| } | |||
| ResultData data = personPhotoService.checkPhoto(material); | |||
| ResultData data = personPhotoService.checkPhoto(file); | |||
| if (data.code == 2000) { | |||
| return new ResultData(); | |||
| } | |||
| @@ -110,7 +110,12 @@ public class VideoCallbackController extends BaseController { | |||
| photoSpeakVideo.setUpdateDate(new Date()); | |||
| photoSpeakVideoService.updateById(photoSpeakVideo); | |||
| //TODO 用户相关操作 | |||
| photoSpeakVideoService.uploadVideo(photoSpeakVideo); | |||
| if (sr){ | |||
| photoSpeakVideoService.uploadHyVideo(photoSpeakVideo); | |||
| }else { | |||
| photoSpeakVideoService.uploadVideo(photoSpeakVideo); | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| @@ -11,12 +11,12 @@ import java.util.Map; | |||
| /** | |||
| * http 工具类 | |||
| */ | |||
| public class HttpUtil { | |||
| public class BaiDuHttpUtil { | |||
| public static String post(String requestUrl, String accessToken, String params) | |||
| throws Exception { | |||
| String contentType = "application/x-www-form-urlencoded"; | |||
| return HttpUtil.post(requestUrl, accessToken, contentType, params); | |||
| return BaiDuHttpUtil.post(requestUrl, accessToken, contentType, params); | |||
| } | |||
| public static String post(String requestUrl, String accessToken, String contentType, String params) | |||
| @@ -25,13 +25,13 @@ public class HttpUtil { | |||
| if (requestUrl.contains("nlp")) { | |||
| encoding = "GBK"; | |||
| } | |||
| return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); | |||
| return BaiDuHttpUtil.post(requestUrl, accessToken, contentType, params, encoding); | |||
| } | |||
| public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) | |||
| throws Exception { | |||
| String url = requestUrl + "?access_token=" + accessToken; | |||
| return HttpUtil.postGeneralUrl(url, contentType, params, encoding); | |||
| return BaiDuHttpUtil.postGeneralUrl(url, contentType, params, encoding); | |||
| } | |||
| public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) | |||
| @@ -3,7 +3,6 @@ package com.iformall.utils; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import okhttp3.*; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.*; | |||
| @@ -12,7 +11,6 @@ import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.net.URL; | |||
| import java.net.URLConnection; | |||
| import java.util.Base64; | |||
| /** | |||
| * 图片质量检查方法 | |||
| @@ -41,7 +39,7 @@ public class BaiduImageCheckUtil { | |||
| // Access Token的有效期(秒为单位,有效期30天) | |||
| // String accessToken = getAuth(); | |||
| //这里暂时写死 | |||
| String result = HttpUtil.post(photo_check_url, access_token, param); | |||
| String result = BaiDuHttpUtil.post(photo_check_url, access_token, param); | |||
| System.out.println(result); | |||
| JSONObject jsonObject = JSON.parseObject(result); | |||
| //1:合规,2:不合规,3:疑似,4:审核失败 | |||
| @@ -11,7 +11,8 @@ public class UrlCheck { | |||
| || url.contains("awsImgUpload") | |||
| || url.contains("getCarStopFee") | |||
| || url.contains("/video/upload") | |||
| || url.contains("/personPhoto/baiduPhoto"); | |||
| || url.contains("/personPhoto/baiduPhoto") | |||
| || url.contains("/personPhoto/checkPhoto"); | |||
| } | |||
| } | |||
| @@ -109,6 +109,22 @@ public class PhotoSpeakSchedule { | |||
| } | |||
| } | |||
| /** | |||
| * 超分上传阿里云 | |||
| */ | |||
| @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 | |||
| public void userVideoHyUploadSchedule() { | |||
| List<PhotoSpeakVideo> videos = photoSpeakVideoService.getNotHyUploadList(); | |||
| if (videos != null && videos.size() > 0) { | |||
| for (PhotoSpeakVideo video : videos) { | |||
| try { | |||
| photoSpeakVideoService.uploadHyVideo(video); | |||
| } catch (Exception e) { | |||
| logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 获取超分时长和大小 | |||
| @@ -149,7 +165,7 @@ public class PhotoSpeakSchedule { | |||
| if (list != null && list.size() > 0) { | |||
| for (PhotoSpeakVideo video : list) { | |||
| try { | |||
| photoSpeakVideoService.videoHy(video,false); | |||
| photoSpeakVideoService.videoHy(video); | |||
| } catch (Exception e) { | |||
| logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); | |||
| } | |||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.sm.MaterialMould; | |||
| import com.iformall.domain.po.sm.PersonPhoto; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| public interface PersonPhotoService { | |||
| @@ -43,5 +44,5 @@ public interface PersonPhotoService { | |||
| void updateOnline(PersonPhoto record); | |||
| ResultData checkPhoto(String material); | |||
| ResultData checkPhoto(MultipartFile file); | |||
| } | |||
| @@ -59,10 +59,12 @@ public interface PhotoSpeakVideoService { | |||
| int updateById(PhotoSpeakVideo video); | |||
| void videoHy(PhotoSpeakVideo speakVideo,Boolean flag); | |||
| ResultData videoHy(PhotoSpeakVideo speakVideo); | |||
| void uploadHyVideo(PhotoSpeakVideo mouldVideo); | |||
| List<PhotoSpeakVideo> getUpLoadHyIngList(); | |||
| List<PhotoSpeakVideo> getNotHyUploadList(); | |||
| } | |||
| @@ -29,8 +29,11 @@ import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.IOException; | |||
| import java.math.BigDecimal; | |||
| import java.net.URLEncoder; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| @@ -135,13 +138,20 @@ public class PersonPhotoServiceImpl implements PersonPhotoService { | |||
| } | |||
| @Override | |||
| public ResultData checkPhoto(String material) { | |||
| AiCheckPhotoParam param = new AiCheckPhotoParam(); | |||
| param.setImg(Base64Util.imageUrlToBase64(material)); | |||
| AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param); | |||
| if (result.isSuccess()){ | |||
| return new ResultData(); | |||
| public ResultData checkPhoto(MultipartFile file) { | |||
| try { | |||
| byte[] fileBytes = file.getBytes(); | |||
| String imgStr = Base64Util.encode(fileBytes); | |||
| AiCheckPhotoParam param = new AiCheckPhotoParam(); | |||
| param.setImg(imgStr); | |||
| AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param); | |||
| if (result.isSuccess()) { | |||
| return new ResultData(); | |||
| } | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), result.getMsg()); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), "接口请求异常"); | |||
| } | |||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), result.getMsg()); | |||
| } | |||
| } | |||
| @@ -231,17 +231,20 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||
| if (video.isSuccess()) { | |||
| photoSpeakVideo.setSaveDir(video.getSaveDir()); | |||
| photoSpeakVideo.setVideoPath(video.getUrl()); | |||
| this.updateById(photoSpeakVideo); | |||
| return new ResultData(); | |||
| } | |||
| photoSpeakVideo.setVideoStatus(EnumVideoStatus.draft.getCode()); | |||
| photoSpeakVideo.setVideoMsg(video.getMsg()); | |||
| this.saveOrUpdate(photoSpeakVideo); | |||
| this.updateById(photoSpeakVideo); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"接口请求异常"); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| photoSpeakVideo.setVideoStatus(EnumVideoStatus.draft.getCode()); | |||
| photoSpeakVideo.setVideoMsg("口请求异常"); | |||
| this.saveOrUpdate(photoSpeakVideo); | |||
| photoSpeakVideo.setVideoMsg("接口请求异常"); | |||
| this.updateById(photoSpeakVideo); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"接口请求异常"); | |||
| } | |||
| } | |||
| @@ -312,24 +315,33 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| } | |||
| @Override | |||
| public void videoHy(PhotoSpeakVideo speakVideo,Boolean flag) { | |||
| AiVideoHqParam param = new AiVideoHqParam(); | |||
| param.setSave_dir(speakVideo.getSaveDir()); | |||
| AiVideoHqResult result = AiVideoHelper.videoHq(param); | |||
| if(result.isSuccess()){ | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.success.getCode()); | |||
| speakVideo.setVideoMsg("超分视频生成成功"); | |||
| speakVideo.setIsHy(EnumYesOrNo.YES.getCode()); | |||
| public ResultData videoHy(PhotoSpeakVideo speakVideo) { | |||
| try { | |||
| AiVideoHqParam param = new AiVideoHqParam(); | |||
| param.setSave_dir(speakVideo.getSaveDir()); | |||
| AiVideoHqResult result = AiVideoHelper.videoHq(param); | |||
| if (result.isSuccess()) { | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.success.getCode()); | |||
| speakVideo.setVideoMsg("超分视频生成成功"); | |||
| speakVideo.setVideoPath(result.getUrl()); | |||
| speakVideo.setIsHy(EnumYesOrNo.YES.getCode()); | |||
| this.updateById(speakVideo); | |||
| return new ResultData(); | |||
| } | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.draft.getCode()); | |||
| speakVideo.setVideoMsg("视频超分失败"); | |||
| this.updateById(speakVideo); | |||
| this.uploadHyVideo(speakVideo); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "接口请求异常"); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.draft.getCode()); | |||
| speakVideo.setVideoMsg("接口请求异常"); | |||
| this.updateById(speakVideo); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "接口请求异常"); | |||
| } | |||
| speakVideo.setVideoHyStatus(EnumVideoStatus.fail.getCode()); | |||
| speakVideo.setVideoMsg("视频超分失败"); | |||
| this.updateById(speakVideo); | |||
| } | |||
| @Async | |||
| @Override | |||
| public void uploadHyVideo(PhotoSpeakVideo mouldVideo){ | |||
| if(EnumVideoStatus.success.getCode().equals(mouldVideo.getVideoHyStatus()) | |||
| @@ -342,6 +354,19 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| videoUpd.setVideoId(result.getVideoId()); | |||
| videoUpd.setVideoHyStatus(EnumVideoStatus.upload_ing.getCode()); | |||
| this.saveOrUpdate(videoUpd); | |||
| AtomicInteger integer = new AtomicInteger(30); | |||
| while (true){ | |||
| String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); | |||
| if (progress.equals("complete")) { | |||
| mouldVideo.setVideoHyStatus(EnumVideoStatus.upload_success.getCode()); | |||
| this.updateById(mouldVideo); | |||
| break; | |||
| } | |||
| if (integer.getAndDecrement() <= 0){ | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -352,4 +377,14 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
| umVideoQ.setVideoHyStatus(EnumVideoStatus.upload_ing.getCode()); | |||
| return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
| } | |||
| @Override | |||
| public List<PhotoSpeakVideo> getNotHyUploadList() { | |||
| PhotoSpeakVideo umVideoQ = new PhotoSpeakVideo(); | |||
| List<Integer> videoStatuss = new ArrayList<>(); | |||
| videoStatuss.add(EnumVideoStatus.success.getCode()); | |||
| videoStatuss.add(EnumVideoStatus.upload_fail.getCode()); | |||
| umVideoQ.setVideoStatuss(videoStatuss); | |||
| return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
| } | |||
| } | |||
| @@ -278,9 +278,9 @@ public class AiVideoHelper { | |||
| AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
| param.setGen_txt("人多泰达股份冲冠怒发代发"); | |||
| param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/digitalperson/16760216806604820_cSHoijDX_matting.png")); | |||
| param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/personphoto/16564099737021232.png")); | |||
| param.setGender("male"); | |||
| param.setVoice_id("zh-CN-YunyangNeural"); | |||
| param.setVoice_id("yue-CN-YunSongNeural"); | |||
| param.setVoice_style("default"); | |||
| param.setUrl("None"); | |||
| AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||