动态头像-mp4-退款
This commit is contained in:
@@ -18,6 +18,8 @@ public class MediaTransferRecord {
|
||||
private String inputPath;
|
||||
|
||||
private String outputPath;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String redisKey;
|
||||
|
||||
|
@@ -1,8 +1,5 @@
|
||||
package com.accompany.business.service;
|
||||
|
||||
import com.accompany.business.model.MediaTransferRecord;
|
||||
import com.accompany.business.mybatismapper.MediaTransferRecordMapper;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.EnvComponent;
|
||||
import com.accompany.core.base.SpringContextHolder;
|
||||
@@ -10,7 +7,6 @@ import com.accompany.core.service.common.JedisService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URL;
|
||||
@@ -23,18 +19,16 @@ public class MediaTransferService {
|
||||
private TencentDataInfiniteService tencentDataInfiniteService;
|
||||
@Autowired
|
||||
private EnvComponent envComponent;
|
||||
@Autowired
|
||||
private MediaTransferRecordMapper mediaTransferRecordMapper;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void transfer2Gif(Long uid, String avatar, String redisKey, Long price, String ip, String deviceId) {
|
||||
URL url = new URL(avatar);
|
||||
String inputPath = url.getPath();
|
||||
String outputPath = inputPath.replace(".mp4", ".gif");
|
||||
String outputAvatar = url.getHost() + outputPath;
|
||||
String newAvatar = avatar.replace(".mp4", ".gif");
|
||||
|
||||
String taskId = tencentDataInfiniteService.transfer2Gif(uid, inputPath, outputPath, redisKey, price, ip, deviceId);
|
||||
String taskId = tencentDataInfiniteService.transfer2Gif(uid, inputPath, outputPath, newAvatar, redisKey, price, ip, deviceId);
|
||||
|
||||
//正式环境等回调
|
||||
if (!envComponent.getDevOrNativeEnv()){
|
||||
|
@@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TencentDataInfiniteService {
|
||||
@@ -27,11 +29,13 @@ public class TencentDataInfiniteService {
|
||||
private COSClient client;
|
||||
@Autowired
|
||||
private MediaTransferRecordMapper mediaTransferRecordMapper;
|
||||
@Autowired
|
||||
private UploadAvatarService uploadAvatarService;
|
||||
|
||||
private final String channel = "tencent";
|
||||
|
||||
@SneakyThrows
|
||||
public String transfer2Gif(Long uid, String inputPath, String outputPath, String redisKey, Long price, String ip, String deviceId) {
|
||||
public String transfer2Gif(Long uid, String inputPath, String outputPath, String newAvatar, String redisKey, Long price, String ip, String deviceId) {
|
||||
//1.创建任务请求对象
|
||||
MediaJobsRequest request = new MediaJobsRequest();
|
||||
//2.添加请求参数 参数详情请见 API 接口文档
|
||||
@@ -60,22 +64,24 @@ public class TencentDataInfiniteService {
|
||||
mediaTransferRecord.setProvider(channel); // 默认使用腾讯云
|
||||
mediaTransferRecord.setInputPath(inputPath);
|
||||
mediaTransferRecord.setOutputPath(outputPath);
|
||||
mediaTransferRecord.setAvatar(newAvatar);
|
||||
mediaTransferRecord.setRedisKey(redisKey);
|
||||
mediaTransferRecord.setPrice(price);
|
||||
mediaTransferRecord.setIp(ip);
|
||||
mediaTransferRecord.setDeviceId(deviceId);
|
||||
mediaTransferRecord.setStatus(Constant.status.delete); // 处理中
|
||||
mediaTransferRecord.setStatus(Constant.status.delete);
|
||||
mediaTransferRecord.setCreateTime(new Date());
|
||||
mediaTransferRecordMapper.insert(mediaTransferRecord);
|
||||
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void handleResult(MediaJobObject jobsDetail) {
|
||||
if (null == jobsDetail || !"Success".equals(jobsDetail.getCode())){
|
||||
if (null == jobsDetail){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
|
||||
//todo 校验jobsDetail
|
||||
boolean success = "Success".equals(jobsDetail.getCode());
|
||||
|
||||
String id = String.join("_", jobsDetail.getJobId(), channel);
|
||||
MediaTransferRecord record = mediaTransferRecordMapper.selectById(id);
|
||||
@@ -83,11 +89,19 @@ public class TencentDataInfiniteService {
|
||||
throw new ServiceException(BusiStatus.ALREADY_NOTEXISTS_CONFIG);
|
||||
}
|
||||
|
||||
//todo 失败退钱
|
||||
|
||||
//record.setStatus();
|
||||
if (success){
|
||||
record.setStatus(Constant.status.valid);
|
||||
} else {
|
||||
record.setStatus(Constant.status.invalid);
|
||||
record.setErrorMsg(jobsDetail.getMessage());
|
||||
}
|
||||
record.setUpdateTime(new Date());
|
||||
mediaTransferRecordMapper.updateById(record);
|
||||
|
||||
YidunCheckUtil.reviewAvatar(record.getUid(), record.getOutputPath(), record.getRedisKey(), record.getPrice(), record.getIp(), record.getDeviceId());
|
||||
if (success){
|
||||
YidunCheckUtil.reviewAvatar(record.getUid(), record.getAvatar(), record.getRedisKey(), record.getPrice(), record.getIp(), record.getDeviceId());
|
||||
} else if (null != record.getPrice() && record.getPrice() > 0L){
|
||||
uploadAvatarService.refundPaidAvatar(record.getUid(), record.getPrice().doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -60,10 +60,11 @@ public class UploadAvatarService extends BaseService {
|
||||
private UserPurseService userPurseService;
|
||||
@Autowired
|
||||
private AvatarPaidRecordMapper avatarPaidRecordMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private MediaTransferService mediaTransferService;
|
||||
|
||||
private final Long gifAvatarGoldPrice = 10000L;
|
||||
@Autowired
|
||||
private MediaTransferService mediaTransferService;
|
||||
|
||||
public long getGifAvatarGoldPrice(){
|
||||
return gifAvatarGoldPrice;
|
||||
@@ -151,12 +152,16 @@ public class UploadAvatarService extends BaseService {
|
||||
jedisService.hdel(RedisKey.user_avatar_paid_price.getKey(), paidCacheKey);
|
||||
}
|
||||
|
||||
public void refundPaidAvatar(Long uid, Double price) {
|
||||
userPurseService.addDiamond(uid, price, BillObjTypeEnum.PAID_GIF_AVATAR_UPLOAD_REFUND);
|
||||
|
||||
SpringContextHolder.getBean(UploadAvatarService.class).profileAvatarReviewNoPassNotify(uid.toString());
|
||||
}
|
||||
|
||||
public void reportReviewProfileFail(String uidStr, String avatarUrl) {
|
||||
delReviewAvatar(RedisKey.user_avatar_under_review.getKey(), uidStr);
|
||||
|
||||
refundPaidAvatar(uidStr, avatarUrl);
|
||||
|
||||
SpringContextHolder.getBean(UploadAvatarService.class).profileAvatarReviewNoPassNotify(uidStr);
|
||||
}
|
||||
|
||||
private void refundPaidAvatar(String uidStr, String avatarUrl) {
|
||||
@@ -168,7 +173,7 @@ public class UploadAvatarService extends BaseService {
|
||||
|
||||
Long uid = Long.parseLong(uidStr);
|
||||
Double price = Double.parseDouble(priceStr);
|
||||
userPurseService.addDiamond(uid, price, BillObjTypeEnum.PAID_GIF_AVATAR_UPLOAD_REFUND);
|
||||
refundPaidAvatar(uid, price);
|
||||
|
||||
jedisService.hdel(RedisKey.user_avatar_paid_price.getKey(), paidCacheKey);
|
||||
}
|
||||
@@ -202,11 +207,21 @@ public class UploadAvatarService extends BaseService {
|
||||
}
|
||||
|
||||
public void reviewAvatar(Long uid, String avatar, String redisKey, Long price, String ip, String deviceId) {
|
||||
if (ImageFileUtils.isMp4(avatar)){
|
||||
mediaTransferService.transfer2Gif(uid, avatar, redisKey, price, ip, deviceId);
|
||||
return;
|
||||
try {
|
||||
if (ImageFileUtils.isMp4(avatar)){
|
||||
mediaTransferService.transfer2Gif(uid, avatar, redisKey, price, ip, deviceId);
|
||||
return;
|
||||
}
|
||||
YidunCheckUtil.reviewAvatar(uid, avatar, redisKey, price, ip, deviceId);
|
||||
} catch (Exception e) {
|
||||
if (null == price || price <= 0L){
|
||||
throw e;
|
||||
}
|
||||
|
||||
//异常就退钱
|
||||
reportReviewProfileFail(uid.toString(), avatar);
|
||||
}
|
||||
YidunCheckUtil.reviewAvatar(uid, avatar, redisKey, price, ip, deviceId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -152,16 +152,6 @@ public class YidunCheckUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对图片进行审核
|
||||
*
|
||||
* @param avatar
|
||||
* @param deviceInfo
|
||||
*/
|
||||
public static void reviewAvatar(Long uid, String avatar, String redisKey, DeviceInfo deviceInfo) {
|
||||
reviewAvatar(uid, avatar, redisKey, null, deviceInfo.getClientIp(), deviceInfo.getDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 对图片进行审核
|
||||
*
|
||||
|
Reference in New Issue
Block a user