@@ -9,6 +9,7 @@ import com.iformall.domain.po.*; | |||
import com.iformall.enums.*; | |||
import com.iformall.service.*; | |||
import com.iformall.service.cuser.CUserServiceFactory; | |||
import com.iformall.service.sm.UserCreateVideoNumService; | |||
import com.iformall.utils.Constant; | |||
import com.iformall.utils.PasswordHelper; | |||
import com.iformall.utils.RedisCacheUtils; | |||
@@ -81,6 +82,9 @@ public class WxUserGrantController extends BaseController { | |||
@Autowired | |||
private QrCodeService qrCodeService; | |||
@Autowired | |||
private UserCreateVideoNumService userCreateVideoNumService; | |||
@AuthIgnore | |||
@ApiOperation("验证码") | |||
@GetMapping("/captcha.jpg") | |||
@@ -347,7 +351,11 @@ public class WxUserGrantController extends BaseController { | |||
// } | |||
// if(isValidCode) { | |||
basicInfo = wxCUserBasicInfoService.register(getTenantInfo(),phone,password); | |||
return new ResultData(); | |||
Boolean aBoolean = userCreateVideoNumService.initializationUserCreateVideoNum(basicInfo.getId()); | |||
if (!aBoolean){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "初始化创建视频时间表失败"); | |||
} | |||
return new ResultData(); | |||
// } else { | |||
// return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND); | |||
// } | |||
@@ -391,6 +399,10 @@ public class WxUserGrantController extends BaseController { | |||
// } | |||
// if(isValidCode) { | |||
basicInfo = wxCUserBasicInfoService.registerEmail(getTenantInfo(),email,password); | |||
Boolean aBoolean = userCreateVideoNumService.initializationUserCreateVideoNum(basicInfo.getId()); | |||
if (!aBoolean){ | |||
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "初始化创建视频时间表失败"); | |||
} | |||
return new ResultData(); | |||
// } else { | |||
// return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND); | |||
@@ -7,6 +7,7 @@ import com.iformall.enums.EnumVideoStatus; | |||
import com.iformall.enums.EnumaVideoTransStatus; | |||
import com.iformall.mapper.VideoTransMapper; | |||
import com.iformall.service.sm.PhotoSpeakVideoService; | |||
import com.iformall.service.sm.UserCreateVideoNumService; | |||
import com.iformall.service.sm.UserMouldVideoService; | |||
import com.iformall.utils.DateUtils; | |||
import com.iformall.video.VideoFactory; | |||
@@ -21,8 +22,11 @@ import org.springframework.scheduling.annotation.EnableScheduling; | |||
import org.springframework.scheduling.annotation.Scheduled; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.concurrent.Future; | |||
import java.util.stream.Collectors; | |||
@Configuration | |||
@EnableScheduling | |||
@@ -39,6 +43,8 @@ public class PhotoSpeakSchedule { | |||
@Autowired | |||
String videoType; | |||
@Autowired | |||
private UserCreateVideoNumService userCreateVideoNumService; | |||
/** | |||
* 生成视频 | |||
*/ | |||
@@ -103,4 +109,29 @@ public class PhotoSpeakSchedule { | |||
} | |||
} | |||
} | |||
/** | |||
* 统计用户创建视频成功的时长 | |||
*/ | |||
@Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 | |||
public void userCreateVideoTimeSchedule() { | |||
List<PhotoSpeakVideo> videos = photoSpeakVideoService.getUploadSuccessList(); | |||
if (videos != null && videos.size() > 0) { | |||
HashMap<Long, Long> map = new HashMap<>(); | |||
for (PhotoSpeakVideo video : videos) { | |||
try { | |||
if (map.get(video.getUserId()) == null) { | |||
map.put(video.getUserId(), Long.parseLong(video.getVideoTime())); | |||
} else { | |||
Long time = map.get(video.getUserId()); | |||
map.put(video.getUserId(), Long.parseLong(video.getVideoTime()) + time); | |||
} | |||
} catch (Exception e) { | |||
logger.error("TtCouponVideoSchedule error.couponVideoSchedule:" + video.getId(), e); | |||
} | |||
} | |||
userCreateVideoNumService.uploadUserCreateVideoNum(map); | |||
} | |||
} | |||
} |
@@ -0,0 +1,57 @@ | |||
package com.iformall.domain.po.sm; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
/** | |||
* @author LRH | |||
* @date Thu Jun 08 16:50:35 CST 2023 | |||
* @describe 用户邀请码表 | |||
*/ | |||
@Data | |||
@TableName("invite_code") | |||
public class InviteCode implements Serializable { | |||
private static final long serialVersionUID = 6951051673755053615L; | |||
/** | |||
* 主键ID | |||
*/ | |||
@TableId | |||
private Long id; | |||
/** | |||
* 租户ID | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 父租户ID | |||
*/ | |||
private String parentTenantId; | |||
/** | |||
* 用户id(wx_c_user_basic_info.id) | |||
*/ | |||
private Long userId; | |||
/** | |||
* 邀请码code | |||
*/ | |||
private Long code; | |||
/** | |||
* 邀请码使用次数 | |||
*/ | |||
private Long total; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private Date createDate; | |||
/** | |||
* 更新时间 | |||
*/ | |||
private Date updateDate; | |||
/** | |||
* 是否删除1是0否 | |||
*/ | |||
private Integer isDel; | |||
} |
@@ -0,0 +1,71 @@ | |||
package com.iformall.domain.po.sm; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import io.swagger.models.auth.In; | |||
import lombok.Data; | |||
import lombok.ToString; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
/** | |||
* @author LRH | |||
* @date Thu Jun 08 16:50:35 CST 2023 | |||
* @describe 被邀请码表 | |||
*/ | |||
@Data | |||
@TableName("invite_code_info") | |||
public class InviteCodeInfo implements Serializable { | |||
private static final long serialVersionUID = 5349786757453017803L; | |||
/** | |||
* 主键ID | |||
*/ | |||
@TableId | |||
private Long id; | |||
/** | |||
* 租户ID | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 父租户ID | |||
*/ | |||
private String parentTenantId; | |||
/** | |||
* 邀请的用户id(wx_c_user_basic_info.id) | |||
*/ | |||
private Long userId; | |||
/** | |||
* 邀请码code | |||
*/ | |||
private String code; | |||
/** | |||
* 被邀请的用户id(wx_c_user_basic_info.id) | |||
*/ | |||
private Long inviteUserId; | |||
/** | |||
* 用户邀请id(user_invite_code.id) | |||
*/ | |||
private Long inviteId; | |||
/** | |||
* 被邀请人手机号 | |||
*/ | |||
private String phone; | |||
/** | |||
* 被邀请人email | |||
*/ | |||
private String email; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private Date createDate; | |||
/** | |||
* 更新时间 | |||
*/ | |||
private Date updateDate; | |||
/** | |||
* 是否删除1是0否 | |||
*/ | |||
private Integer isDel; | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.iformall.domain.po.sm; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import lombok.Data; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
/** | |||
* @author LRH | |||
* @date Wed Jun 07 17:06:17 CST 2023 | |||
* @describe 用户创建视频时间表 | |||
*/ | |||
@Data | |||
@TableName("user_create_video_num") | |||
public class UserCreateVideoNum implements Serializable { | |||
private static final long serialVersionUID = 6845742086152117203L; | |||
/** | |||
* 主键ID | |||
*/ | |||
@TableId | |||
private Long id; | |||
/** | |||
* 租户ID | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 父租户ID | |||
*/ | |||
private String parentTenantId; | |||
/** | |||
* 用户id(wx_c_user_basic_info.id) | |||
*/ | |||
private Long userId; | |||
/** | |||
* 剩余条数 | |||
*/ | |||
private Integer residueNum; | |||
/** | |||
* 总条数 | |||
*/ | |||
private Integer residueTotal; | |||
/** | |||
* 用户生成视频的个数 | |||
*/ | |||
private Integer createNum; | |||
/** | |||
* 用户生成视频的总时长(s) | |||
*/ | |||
private Long createAllTime; | |||
/** | |||
* 总时长(单位:s) | |||
*/ | |||
private Long totalTime; | |||
/** | |||
* 剩余时长(单位:s) | |||
*/ | |||
private Long residueTime; | |||
/** | |||
* 有效期 | |||
*/ | |||
private Date effectiveDate; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private Date createDate; | |||
/** | |||
* 更新时间 | |||
*/ | |||
private Date updateDate; | |||
/** | |||
* 是否删除1是0否 | |||
*/ | |||
private long isDel; | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.iformall.mapper; | |||
import com.iformall.common.CommonMapper; | |||
import com.iformall.domain.po.sm.UserCreateVideoNum; | |||
public interface UserCreateVideoNumMapper extends CommonMapper<UserCreateVideoNum, String> { | |||
} |
@@ -0,0 +1,5 @@ | |||
package com.iformall.service.sm; | |||
public interface InviteCodeInfoService { | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.iformall.service.sm; | |||
import com.iformall.domain.po.sm.UserCreateVideoNum; | |||
import java.util.Map; | |||
public interface InviteCodeService { | |||
} |
@@ -55,6 +55,8 @@ public interface PhotoSpeakVideoService { | |||
List<PhotoSpeakVideo> getUpLoadIngList(); | |||
List<PhotoSpeakVideo> getUploadSuccessList(); | |||
int updateById(PhotoSpeakVideo video); | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.iformall.service.sm; | |||
import com.github.pagehelper.PageInfo; | |||
import com.iformall.common.ResultData; | |||
import com.iformall.domain.po.sm.MouldPatch; | |||
import com.iformall.domain.po.sm.UserCreateVideoNum; | |||
import java.util.Map; | |||
public interface UserCreateVideoNumService { | |||
Boolean initializationUserCreateVideoNum(Long id); | |||
void addOrSubtractNumberOfTimes(Integer type, UserCreateVideoNum createVideoNum); | |||
UserCreateVideoNum queryInfoByUserId(Long userId); | |||
void uploadUserCreateVideoNum(Map<Long, Long> collect); | |||
} |
@@ -0,0 +1,10 @@ | |||
package com.iformall.service.sm.impl; | |||
import com.iformall.service.sm.InviteCodeInfoService; | |||
import com.iformall.service.sm.InviteCodeService; | |||
import org.springframework.stereotype.Service; | |||
@Service | |||
public class InviteCodeInfoServiceImpl implements InviteCodeInfoService { | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.iformall.service.sm.impl; | |||
import com.iformall.service.sm.InviteCodeService; | |||
import org.springframework.stereotype.Service; | |||
@Service | |||
public class InviteCodeServiceImpl implements InviteCodeService { | |||
} |
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.scheduling.annotation.Async; | |||
import org.springframework.scheduling.annotation.AsyncResult; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.util.ObjectUtils; | |||
import javax.transaction.xa.XAException; | |||
import java.util.ArrayList; | |||
@@ -59,6 +60,9 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
@Autowired | |||
String videoType; | |||
@Autowired | |||
private UserCreateVideoNumService userCreateVideoNumService; | |||
@Override | |||
public PageInfo<PhotoSpeakVideo> listAsPage(PhotoSpeakVideo record, Integer pageIndex, Integer pageSize) { | |||
@@ -163,13 +167,17 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
msg = "未查询到人物照片"; | |||
} else { | |||
personPhotoUrl = photoSpeakVideo.getPersonPhotoUrl(); | |||
//校验图片是否合法 | |||
ResultData data = personPhotoService.checkPhoto(personPhotoUrl); | |||
if (data.code != 2000) { | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg("图片质量审核失败:" + data.message); | |||
this.saveOrUpdate(videoUpd); | |||
return new AsyncResult<>(0); | |||
PersonPhoto personPhotoInfo = personPhotoService.getById(photoSpeakVideo.getPersonPhotoId()); | |||
//如果是上传图片就去检验合法 | |||
if (EnumMouldSendType.build.getCode().equals(personPhotoInfo.getSendType())) { | |||
//校验图片是否合法 | |||
ResultData data = personPhotoService.checkPhoto(personPhotoUrl); | |||
if (data.code != 2000) { | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg("图片质量审核失败:" + data.message); | |||
this.saveOrUpdate(videoUpd); | |||
return new AsyncResult<>(0); | |||
} | |||
} | |||
} | |||
if(StringUtils.isBlank(personPhotoUrl)){ | |||
@@ -230,6 +238,21 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
return new AsyncResult<>(0); | |||
} | |||
//修改用户生成视频次数 | |||
UserCreateVideoNum createVideoNum = userCreateVideoNumService.queryInfoByUserId(photoSpeakVideo.getUserId()); | |||
if (ObjectUtils.isEmpty(createVideoNum)) { | |||
return new AsyncResult<>("用户没有生成视频次数"); | |||
}else { | |||
//剩余条数 | |||
Integer residueNum = createVideoNum.getResidueNum(); | |||
if (residueNum.intValue() <= 0){ | |||
return new AsyncResult<>("剩余生成视频次数不足"); | |||
}else { | |||
//减去生成视频次数 | |||
userCreateVideoNumService.addOrSubtractNumberOfTimes(1, createVideoNum); | |||
} | |||
} | |||
try { | |||
AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
param.setImg(Base64Util.imageUrlToBase64(photoSpeakVideo.getPersonPhotoUrl())); | |||
@@ -272,6 +295,9 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
videoUpd.setVideoMsg(video.getMsg()); | |||
this.saveOrUpdate(videoUpd); | |||
//如果生成视频失败了,就把创建视频的次数加回去 | |||
userCreateVideoNumService.addOrSubtractNumberOfTimes(2, createVideoNum); | |||
return new AsyncResult<>(0); | |||
} catch (Exception e) { | |||
@@ -321,6 +347,13 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||
return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
} | |||
@Override | |||
public List<PhotoSpeakVideo> getUploadSuccessList() { | |||
PhotoSpeakVideo umVideoQ = new PhotoSpeakVideo(); | |||
umVideoQ.setVideoStatus(EnumVideoStatus.upload_success.getCode()); | |||
return photoSpeakVideoMapper.getSortList(umVideoQ); | |||
} | |||
@Override | |||
public int updateById(PhotoSpeakVideo video) { | |||
return photoSpeakVideoMapper.updateById(video); | |||
@@ -0,0 +1,80 @@ | |||
package com.iformall.service.sm.impl; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |||
import com.iformall.common.IdWorker; | |||
import com.iformall.domain.po.sm.UserCreateVideoNum; | |||
import com.iformall.mapper.UserCreateVideoNumMapper; | |||
import com.iformall.service.sm.UserCreateVideoNumService; | |||
import io.swagger.models.auth.In; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Date; | |||
import java.util.Map; | |||
@Service | |||
public class UserCreateVideoNumServiceImpl implements UserCreateVideoNumService { | |||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
@Autowired | |||
private UserCreateVideoNumMapper userCreateVideoNumMapper; | |||
//总条数初始值 | |||
private static final Integer RESIDUE_TOTAL = 10; | |||
/** | |||
* 初始化注册用户创建视频的次数 | |||
* | |||
* @param id 用户id | |||
* @Author LWH | |||
* @version 1.0 | |||
* @date: 2023/6/8 10:23 | |||
*/ | |||
public Boolean initializationUserCreateVideoNum(Long id) { | |||
UserCreateVideoNum createVideoNum = new UserCreateVideoNum(); | |||
createVideoNum.setId(IdWorker.get().nextId()); | |||
createVideoNum.setUserId(id); | |||
createVideoNum.setResidueNum(RESIDUE_TOTAL); | |||
createVideoNum.setResidueTotal(RESIDUE_TOTAL); | |||
Date date = new Date(); | |||
createVideoNum.setCreateDate(date); | |||
createVideoNum.setUpdateDate(date); | |||
createVideoNum.setIsDel(0); | |||
return userCreateVideoNumMapper.insert(createVideoNum) > 0; | |||
} | |||
@Override | |||
public void addOrSubtractNumberOfTimes(Integer type, UserCreateVideoNum createVideoNum) { | |||
if (type == 1) { | |||
createVideoNum.setResidueNum(createVideoNum.getResidueNum() - 1); | |||
createVideoNum.setCreateNum(createVideoNum.getCreateNum() + 1); | |||
} else if (type == 2) { | |||
createVideoNum.setResidueNum(createVideoNum.getResidueNum() + 1); | |||
createVideoNum.setCreateNum(createVideoNum.getCreateNum() - 1); | |||
} | |||
userCreateVideoNumMapper.updateById(createVideoNum); | |||
} | |||
@Override | |||
public UserCreateVideoNum queryInfoByUserId(Long userId) { | |||
return userCreateVideoNumMapper.selectOne(new LambdaQueryWrapper<UserCreateVideoNum>().eq(UserCreateVideoNum::getUserId, userId)); | |||
} | |||
@Override | |||
public void uploadUserCreateVideoNum(Map<Long, Long> collect) { | |||
for (Map.Entry<Long, Long> entry : collect.entrySet()) { | |||
UserCreateVideoNum videoNum = new UserCreateVideoNum(); | |||
videoNum.setUserId(entry.getKey()); | |||
videoNum.setCreateAllTime(entry.getValue()); | |||
userCreateVideoNumMapper.update(videoNum, | |||
new LambdaUpdateWrapper<UserCreateVideoNum>() | |||
.eq(UserCreateVideoNum::getIsDel, 0) | |||
.eq(UserCreateVideoNum::getUserId, entry.getKey())); | |||
} | |||
} | |||
} |
@@ -219,27 +219,27 @@ public class AiVideoHelper { | |||
// AiVideoResult video = AiVideoHelper.createVideo(videoParam); | |||
// | |||
// AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
// param.setGen_txt("人多泰达股份冲冠怒发代发"); | |||
// param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/digitalperson/16760216806604820_cSHoijDX_matting.png")); | |||
// param.setGender("male"); | |||
// param.setVoice_id("zh-CN-YunxiNeural"); | |||
// param.setVoice_style("sad"); | |||
// param.setUrl("None"); | |||
// AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||
AiPhotoSpeakParam param = new AiPhotoSpeakParam(); | |||
param.setGen_txt("人多泰达股份冲冠怒发代发"); | |||
param.setImg(Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/digitalperson/16760216806604820_cSHoijDX_matting.png")); | |||
param.setGender("male"); | |||
param.setVoice_id("zh-CN-YunxiNeural"); | |||
param.setVoice_style("sad"); | |||
param.setUrl("None"); | |||
AiPhotoSpeakResult video = AiVideoHelper.createPhotoSpeakVideo(param); | |||
// | |||
// AiCheckPhotoParam param = new AiCheckPhotoParam(); | |||
// String img = Base64Util.imageUrlToBase64("https://suimang.oss-accelerate.aliyuncs.com/builtin/personmould/16760216806604820_cSHoijDX_grace_1080.jpg"); | |||
// param.setImg(img); | |||
// AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param); | |||
// System.out.println(result); | |||
// | |||
AiPreviewParam param = new AiPreviewParam(); | |||
param.setGen_txt("今天是个好日子"); | |||
param.setVoice_id("zh-CN-YunyangNeural"); | |||
param.setVoice_style("default"); | |||
param.setGender("male"); | |||
AiPreviewResult result = AiVideoHelper.voicePreview(param); | |||
// AiPreviewParam param = new AiPreviewParam(); | |||
// param.setGen_txt("今天是个好日子"); | |||
// param.setVoice_id("zh-CN-YunyangNeural"); | |||
// param.setVoice_style("default"); | |||
// param.setGender("male"); | |||
// AiPreviewResult result = AiVideoHelper.voicePreview(param); | |||
} | |||