init
This commit is contained in:
@@ -16,6 +16,10 @@ import com.ruoyi.common.core.domain.PageQuery;
|
||||
*/
|
||||
public interface AnchorService extends IService<Anchor> {
|
||||
|
||||
void joinAnchor(Long userId);
|
||||
|
||||
void closeAnchor(Long userId);
|
||||
|
||||
Page<AnchorAdminVo> pageAdmin(PageQuery pageQuery, AnchorAdminVo bo);
|
||||
|
||||
Page<AnchorListVo> pageApp(PageQuery pageQuery, AnchorListQuery query);
|
||||
|
||||
@@ -4,13 +4,20 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.Anchor;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.dto.admin.vo.AnchorAdminVo;
|
||||
import com.ruoyi.cai.dto.app.query.index.AnchorListQuery;
|
||||
import com.ruoyi.cai.dto.app.vo.AnchorListVo;
|
||||
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.service.AnchorService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -23,6 +30,66 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class AnchorServiceImpl extends ServiceImpl<AnchorMapper, Anchor> implements AnchorService {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
@Override
|
||||
public void joinAnchor(Long userId){
|
||||
User user = userService.getById(userId);
|
||||
Anchor anchor = this.getByUserId(userId);
|
||||
if(user == null){
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
if(user.getIsAnchor() == 1 || anchor != null){
|
||||
throw new ServiceException("改用户已经是主播");
|
||||
}
|
||||
if(!GenderEnum.WOMEN.getCode().equals(user.getGender())){
|
||||
throw new ServiceException("只有女用户可以加入主播");
|
||||
}
|
||||
boolean boo = userService.update(Wrappers.lambdaUpdate(User.class)
|
||||
.eq(User::getId, user.getId()).eq(User::getIsAnchor, 0)
|
||||
.set(User::getIsAnchor, 1));
|
||||
if(!boo){
|
||||
throw new ServiceException("加入主播失败");
|
||||
}
|
||||
// 将用户的协议都自动完成
|
||||
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());
|
||||
save.setPrice(price);
|
||||
save.setVideoRate(systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_ANCHOR_VIDEO_PRICE));
|
||||
save.setGuardRate(systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_ANCHOR_GUARD_PRICE));
|
||||
save.setGiftRate(systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_ANCHOR_GIFT_PRICE));
|
||||
this.save(save);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAnchor(Long userId){
|
||||
User user = userService.getById(userId);
|
||||
Anchor anchor = this.getByUserId(userId);
|
||||
if(user == null){
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
if(user.getIsAnchor() == 0){
|
||||
throw new ServiceException("该用户不是主播,无需取消");
|
||||
}
|
||||
boolean boo = userService.update(Wrappers.lambdaUpdate(User.class)
|
||||
.eq(User::getId, user.getId()).eq(User::getIsAnchor, 1)
|
||||
.set(User::getIsAnchor, 0));
|
||||
if(!boo){
|
||||
throw new ServiceException("取消主播失败");
|
||||
}
|
||||
this.removeById(anchor.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<AnchorAdminVo> pageAdmin(PageQuery pageQuery, AnchorAdminVo bo) {
|
||||
return baseMapper.pageAdmin(pageQuery.build(),bo);
|
||||
|
||||
Reference in New Issue
Block a user