init
This commit is contained in:
@@ -14,4 +14,6 @@ public interface CaiAccountService extends IService<CaiAccount> {
|
||||
CaiAccount getByUserId(Long userId);
|
||||
|
||||
boolean incs(Long userId, Long value);
|
||||
|
||||
boolean decr(Long userId, Long value);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,27 @@ package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.CaiUserAlbum;
|
||||
import com.ruoyi.cai.dto.app.query.AlbumAddRes;
|
||||
import com.ruoyi.cai.dto.app.query.AlbumResetRes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主播集锦Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @author 77
|
||||
* @date 2023-12-23
|
||||
*/
|
||||
public interface CaiUserAlbumService extends IService<CaiUserAlbum> {
|
||||
|
||||
|
||||
List<String> getUserAlbum(Long userId, Integer anchor);
|
||||
|
||||
List<CaiUserAlbum> listByUserId(Long userId);
|
||||
|
||||
boolean addAlbum(AlbumAddRes res);
|
||||
|
||||
boolean removeAlbum(Long id);
|
||||
|
||||
boolean resetAlbum(List<AlbumResetRes> res, Long userId);
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ public interface CaiUserCountService extends IService<CaiUserCount> {
|
||||
void visitor(Long fromUserId,Long toUserId);
|
||||
void reset(Long userId);
|
||||
void resetAsync(Long userId);
|
||||
|
||||
CaiUserCount getByUserId(Long userId);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.CaiAccount;
|
||||
import com.ruoyi.cai.mapper.CaiAccountMapper;
|
||||
import com.ruoyi.cai.service.CaiAccountService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 用户账户Service业务层处理
|
||||
@@ -16,6 +18,7 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccount> implements CaiAccountService {
|
||||
|
||||
|
||||
@Override
|
||||
public CaiAccount getByUserId(Long userId) {
|
||||
return this.getOne(Wrappers.lambdaQuery(CaiAccount.class).eq(CaiAccount::getUserId,userId).last("limit 1"));
|
||||
@@ -25,4 +28,25 @@ public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccou
|
||||
public boolean incs(Long userId, Long value) {
|
||||
return baseMapper.incs(userId,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean decr(Long userId, Long value) {
|
||||
CaiAccount account = this.getByUserId(userId);
|
||||
if(account.getTotalCoin() < value){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
boolean incs = baseMapper.incs(userId, -value);
|
||||
if(!incs){
|
||||
return false;
|
||||
}
|
||||
CaiAccount newAccount = this.getByUserId(userId);
|
||||
Long decrCoinFlag = newAccount.getCoin() - value;
|
||||
if(decrCoinFlag >= 0){
|
||||
baseMapper.incsCoin(userId, -value,0L);
|
||||
}else{
|
||||
baseMapper.incsCoin(userId, -newAccount.getCoin(), decrCoinFlag);
|
||||
}
|
||||
return incs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,7 @@ public class CaiGuardTotalServiceImpl extends ServiceImpl<CaiGuardTotalMapper,Ca
|
||||
throw new ServiceException("只能给女神送守护");
|
||||
}
|
||||
Long guardValue = query.getGuardNum() * GUARD_UNIT_PRICE;
|
||||
CaiAccount account = accountService.getByUserId(fromUserId);
|
||||
if(account.getCoin() < guardValue){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
boolean boo = accountService.incs(fromUserId, -guardValue);
|
||||
boolean boo = accountService.decr(fromUserId, -guardValue);
|
||||
if(!boo){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
|
||||
@@ -3,25 +3,32 @@ package com.ruoyi.cai.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.CaiUser;
|
||||
import com.ruoyi.cai.domain.CaiUserAlbum;
|
||||
import com.ruoyi.cai.dto.app.query.AlbumAddRes;
|
||||
import com.ruoyi.cai.dto.app.query.AlbumResetRes;
|
||||
import com.ruoyi.cai.mapper.CaiUserAlbumMapper;
|
||||
import com.ruoyi.cai.service.CaiUserAlbumService;
|
||||
import com.ruoyi.cai.service.CaiUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 主播集锦Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @author 77
|
||||
* @date 2023-12-23
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CaiUserAlbumServiceImpl extends ServiceImpl<CaiUserAlbumMapper, CaiUserAlbum> implements CaiUserAlbumService {
|
||||
|
||||
@Autowired
|
||||
private CaiUserService userService;
|
||||
@Override
|
||||
public List<String> getUserAlbum(Long userId,Integer anchor){
|
||||
LambdaQueryWrapper<CaiUserAlbum> eq = Wrappers.lambdaQuery(CaiUserAlbum.class)
|
||||
@@ -35,4 +42,57 @@ public class CaiUserAlbumServiceImpl extends ServiceImpl<CaiUserAlbumMapper, Cai
|
||||
List<CaiUserAlbum> list = this.list(eq);
|
||||
return list.stream().map(CaiUserAlbum::getUrl).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CaiUserAlbum> listByUserId(Long userId) {
|
||||
return this.list(Wrappers.lambdaQuery(CaiUserAlbum.class).eq(CaiUserAlbum::getUserId,userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAlbum(AlbumAddRes res) {
|
||||
CaiUser user = userService.getById(res.getUserId());
|
||||
CaiUserAlbum album = new CaiUserAlbum();
|
||||
album.setUserId(res.getUserId());
|
||||
album.setUrl(res.getUrl());
|
||||
album.setIsAnchor(user.getIsAnchor());
|
||||
album.setOrderBy(res.getOrderBy());
|
||||
this.save(album);
|
||||
if(user.getIsAnchor() == 1 && res.getOrderBy() == 0){
|
||||
userService.update(Wrappers.lambdaUpdate(CaiUser.class)
|
||||
.eq(CaiUser::getId,res.getUserId())
|
||||
.set(CaiUser::getAvatar,res.getUrl()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAlbum(Long id){
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resetAlbum(List<AlbumResetRes> res, Long userId) {
|
||||
CaiUser user = userService.getById(userId);
|
||||
List<CaiUserAlbum> update = new ArrayList<>();
|
||||
Long id = null;
|
||||
for (AlbumResetRes re : res) {
|
||||
CaiUserAlbum album = new CaiUserAlbum();
|
||||
album.setId(re.getId());
|
||||
album.setOrderBy(re.getOrderBy());
|
||||
update.add(album);
|
||||
if(re.getOrderBy() == 0){
|
||||
id = re.getId();
|
||||
}
|
||||
}
|
||||
this.updateBatchById(update);
|
||||
if(id != null){
|
||||
CaiUserAlbum album = this.getById(id);
|
||||
if(album != null && (album.getIsAnchor() == 1 || album.getStatus() == 1)){
|
||||
userService.update(Wrappers.lambdaUpdate(CaiUser.class)
|
||||
.eq(CaiUser::getId,album.getUserId())
|
||||
.set(CaiUser::getAvatar,album.getUrl()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,9 @@ public class CaiUserCountServiceImpl extends ServiceImpl<CaiUserCountMapper,CaiU
|
||||
public void resetAsync(Long userId) {
|
||||
ExecutorConstant.SYNC_EXECUTOR.execute(() -> reset(userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaiUserCount getByUserId(Long userId) {
|
||||
return this.getOne(Wrappers.lambdaQuery(CaiUserCount.class).eq(CaiUserCount::getUserId,userId).last("limit 1"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +47,7 @@ public class CaiUserGiftServiceImpl extends ServiceImpl<CaiUserGiftMapper,CaiUse
|
||||
}
|
||||
Long price = gift.getPrice();
|
||||
Long giftAmount = query.getGiftCount() * price;
|
||||
CaiAccount account = accountService.getByUserId(fromUserId);
|
||||
if(account.getCoin() < giftAmount){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
boolean boo = accountService.incs(fromUserId, -giftAmount);
|
||||
boolean boo = accountService.decr(fromUserId, -giftAmount);
|
||||
if(!boo){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user