123
This commit is contained in:
@@ -87,7 +87,7 @@ public class AnchorController extends BaseController {
|
||||
if(user == null){
|
||||
return R.fail("用户不存在");
|
||||
}
|
||||
anchorService.joinAnchor(user.getId());
|
||||
anchorService.joinAnchor(user.getId(),true);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ruoyi.cai.dto.commom.anchor;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class CheckAnchorAutoResp {
|
||||
// 是否忽略数据
|
||||
private Boolean ignore;
|
||||
// 是否加入成功
|
||||
private Boolean joinSuccess;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public class LockManager {
|
||||
public static final String LOCK_ADD_USER_GREET_REDIS = RedisHttpConstant.REDIS_P + "lock:addUserGreet:%s";
|
||||
public static final String LOCK_SEND_GREET_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGreet:%s";
|
||||
public static final String LOCK_SEND_GUARD_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGuard:%s";
|
||||
public static final String LOCK_JOIN_ANCHOR_REDIS = RedisHttpConstant.REDIS_P + "lock:joinAnchor:%s";
|
||||
public static final String LOCK_SEND_GIFT_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGift:%s";
|
||||
public static final String LOCK_VIDEO_SETTLE_REDIS = RedisHttpConstant.REDIS_P + "lock:videoSettle:%s";
|
||||
public static final String LOCK_ONLINE_LOGIN_NOTICE_REDIS = RedisHttpConstant.REDIS_P + "lockHand:loginFansNotice:%s";
|
||||
@@ -44,4 +45,8 @@ public class LockManager {
|
||||
public static String getLoginNoticeFansLock(Long userId){
|
||||
return String.format(LOCK_ONLINE_LOGIN_NOTICE_REDIS,userId);
|
||||
}
|
||||
|
||||
public static String getJoinAnchor(Long userId){
|
||||
return String.format(LOCK_JOIN_ANCHOR_REDIS,userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.AnchorApply;
|
||||
import com.ruoyi.cai.dto.admin.vo.AnchorApplyAdminVo;
|
||||
import com.ruoyi.cai.dto.app.vo.AnchorJoinHomeVo;
|
||||
import com.ruoyi.cai.dto.commom.anchor.CheckAnchorAutoResp;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 播主申请管理Service接口
|
||||
@@ -23,6 +25,9 @@ public interface AnchorApplyService extends IService<AnchorApply> {
|
||||
|
||||
boolean joinAnchor(Long userId);
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
CheckAnchorAutoResp checkAnchorAuto(Long userId);
|
||||
|
||||
void auditAnchorSuccess(Long id);
|
||||
|
||||
void auditAnchorFail(Long id);
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.ruoyi.common.core.domain.PageQuery;
|
||||
*/
|
||||
public interface AnchorService extends IService<Anchor> {
|
||||
|
||||
void joinAnchor(Long userId);
|
||||
void joinAnchor(Long userId,boolean autoFinishStatus);
|
||||
|
||||
boolean closeAnchor(Long userId);
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ import com.ruoyi.cai.domain.AnchorApply;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.dto.admin.vo.AnchorApplyAdminVo;
|
||||
import com.ruoyi.cai.dto.app.vo.AnchorJoinHomeVo;
|
||||
import com.ruoyi.cai.dto.commom.anchor.CheckAnchorAutoResp;
|
||||
import com.ruoyi.cai.enums.AuditStatusEnum;
|
||||
import com.ruoyi.cai.enums.GenderEnum;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.LockManager;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.mapper.AnchorApplyMapper;
|
||||
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||
@@ -19,6 +21,8 @@ import com.ruoyi.cai.service.AnchorService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -42,6 +46,8 @@ public class AnchorApplyServiceImpl extends ServiceImpl<AnchorApplyMapper, Ancho
|
||||
private SystemConfigManager systemConfigManager;
|
||||
@Autowired
|
||||
private YunxinHttpService yunxinHttpService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
@Override
|
||||
public AnchorApply getByUserId(Long userId){
|
||||
@@ -103,6 +109,33 @@ public class AnchorApplyServiceImpl extends ServiceImpl<AnchorApplyMapper, Ancho
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CheckAnchorAutoResp checkAnchorAuto(Long userId){
|
||||
User user = userService.getById(userId);
|
||||
if(user == null || user.getIsAnchor() == 1){
|
||||
return CheckAnchorAutoResp.builder().ignore(true).build();
|
||||
}
|
||||
Anchor anchor = anchorService.getByUserId(userId);
|
||||
if(anchor != null){
|
||||
return CheckAnchorAutoResp.builder().ignore(true).build();
|
||||
}
|
||||
if(user.getAvatarState() == 1 && user.getCameraStatus() == 1 && user.getAgreeProtocol() == 1){
|
||||
// 开始自动成为主播
|
||||
RLock joinAnchorLock = redissonClient.getLock(LockManager.getJoinAnchor(userId));
|
||||
try {
|
||||
joinAnchorLock.lock();
|
||||
anchorService.joinAnchor(userId, false);
|
||||
return CheckAnchorAutoResp.builder().joinSuccess(true).build();
|
||||
}catch (Exception e){
|
||||
log.error("自动加入主播失败!",e);
|
||||
}finally {
|
||||
joinAnchorLock.unlock();
|
||||
}
|
||||
}
|
||||
return CheckAnchorAutoResp.builder().joinSuccess(false).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void auditAnchorSuccess(Long id) {
|
||||
@@ -117,7 +150,7 @@ public class AnchorApplyServiceImpl extends ServiceImpl<AnchorApplyMapper, Ancho
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
if(user.getIsAnchor() == 1 || anchor != null){
|
||||
throw new ServiceException("改用户已经是主播");
|
||||
throw new ServiceException("用户已经是主播");
|
||||
}
|
||||
if(!GenderEnum.WOMEN.getCode().equals(user.getGender())){
|
||||
throw new ServiceException("只有女用户可以加入主播");
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.ruoyi.cai.enums.GenderEnum;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.mapper.AnchorMapper;
|
||||
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||
import com.ruoyi.cai.service.AnchorService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
@@ -35,10 +36,12 @@ public class AnchorServiceImpl extends ServiceImpl<AnchorMapper, Anchor> impleme
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
@Autowired
|
||||
private YunxinHttpService yunxinHttpService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void joinAnchor(Long userId){
|
||||
public void joinAnchor(Long userId,boolean autoFinishStatus){
|
||||
User user = userService.getById(userId);
|
||||
Anchor anchor = this.getByUserId(userId);
|
||||
if(user == null){
|
||||
@@ -57,12 +60,14 @@ public class AnchorServiceImpl extends ServiceImpl<AnchorMapper, Anchor> impleme
|
||||
throw new ServiceException("加入主播失败");
|
||||
}
|
||||
// 将用户的协议都自动完成
|
||||
if(autoFinishStatus){
|
||||
userService.update(Wrappers.lambdaUpdate(User.class)
|
||||
.eq(User::getId,user.getId())
|
||||
.set(User::getCameraStatus,1)
|
||||
.set(User::getFinishStatus,1)
|
||||
.set(User::getAgreeProtocol,1)
|
||||
.set(User::getAvatarState,1));
|
||||
}
|
||||
Long price = systemConfigManager.getSystemConfigOfLong(SystemConfigEnum.DEFAULT_ANCHOR_PRICE);
|
||||
Anchor save = new Anchor();
|
||||
save.setUserId(user.getId());
|
||||
@@ -71,6 +76,7 @@ public class AnchorServiceImpl extends ServiceImpl<AnchorMapper, Anchor> impleme
|
||||
save.setGuardRate(systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_ANCHOR_GUARD_PRICE));
|
||||
save.setGiftRate(systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_ANCHOR_GIFT_PRICE));
|
||||
this.save(save);
|
||||
yunxinHttpService.passAnchorSendMessage(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.ruoyi.cai.dto.admin.vo.UserCameraAuditAdminVo;
|
||||
import com.ruoyi.cai.dto.app.vo.CameraAuditVo;
|
||||
import com.ruoyi.cai.enums.AuditStatusEnum;
|
||||
import com.ruoyi.cai.mapper.UserCameraAuditMapper;
|
||||
import com.ruoyi.cai.service.AnchorApplyService;
|
||||
import com.ruoyi.cai.service.UserCameraAuditService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
@@ -45,6 +46,8 @@ public class UserCameraAuditServiceImpl extends ServiceImpl<UserCameraAuditMappe
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private AnchorApplyService anchorApplyService;
|
||||
|
||||
@Override
|
||||
public UserCameraAudit getByUserId(Long userId){
|
||||
@@ -120,6 +123,11 @@ public class UserCameraAuditServiceImpl extends ServiceImpl<UserCameraAuditMappe
|
||||
userService.update(Wrappers.lambdaUpdate(User.class)
|
||||
.eq(User::getId, userCameraAudit.getUserId())
|
||||
.set(User::getCameraStatus, 1));
|
||||
try {
|
||||
anchorApplyService.checkAnchorAuto(userCameraAudit.getUserId());
|
||||
}catch (Exception e){
|
||||
log.error("检查是否自动主播失败!",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.ruoyi.cai.domain.UserPictureAudit;
|
||||
import com.ruoyi.cai.dto.admin.vo.user.UserPictureAuditAdminVo;
|
||||
import com.ruoyi.cai.enums.AuditStatusEnum;
|
||||
import com.ruoyi.cai.mapper.UserPictureAuditMapper;
|
||||
import com.ruoyi.cai.service.AnchorApplyService;
|
||||
import com.ruoyi.cai.service.UserPictureAuditService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
@@ -26,6 +27,9 @@ import java.time.LocalDateTime;
|
||||
@Service
|
||||
public class UserPictureAuditServiceImpl extends ServiceImpl<UserPictureAuditMapper,UserPictureAudit> implements UserPictureAuditService {
|
||||
|
||||
@Autowired
|
||||
private AnchorApplyService anchorApplyService;
|
||||
|
||||
@Override
|
||||
public UserPictureAudit getOneUserAuditRunningPic(Integer type, Long userId) {
|
||||
return this.getOne(Wrappers.lambdaQuery(UserPictureAudit.class)
|
||||
@@ -57,6 +61,11 @@ public class UserPictureAuditServiceImpl extends ServiceImpl<UserPictureAuditMap
|
||||
.eq(User::getId, userPictureAudit.getUserId())
|
||||
.set(User::getAvatar, userPictureAudit.getUrl())
|
||||
.set(User::getAvatarState, 1));
|
||||
try {
|
||||
anchorApplyService.checkAnchorAuto(userPictureAudit.getUserId());
|
||||
}catch (Exception e){
|
||||
log.error("检查是否自动主播失败!",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -204,6 +204,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
this.update(Wrappers.lambdaUpdate(User.class)
|
||||
.eq(User::getId,userId)
|
||||
.set(User::getAgreeProtocol,1));
|
||||
try {
|
||||
anchorApplyService.checkAnchorAuto(userId);
|
||||
}catch (Exception e){
|
||||
log.error("检查是否自动主播失败!",e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user