This commit is contained in:
77
2024-07-26 16:48:16 +08:00
parent 068a48a128
commit a872a3d26c
12 changed files with 152 additions and 7 deletions

View File

@@ -44,6 +44,18 @@ public class Account implements Serializable {
* 充值彩贝总额
*/
private Long totalBuyCoin;
/**
* 聊天收入
*/
private Long messageIncomeCoin;
/** 视频收入 */
private Long videoIncomeCoin;
/** 礼物收入 */
private Long giftIncomeCoin;
/** 守护收入 */
private Long guardIncomeCoin;
/** 工会收入 */
private Long unionIncomeCoin;
/**
* 账户锁定 0 正常 1 锁定
*/

View File

@@ -0,0 +1,41 @@
package com.ruoyi.cai.manager;
import com.ruoyi.cai.mapper.AccountMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
@Component
@Slf4j
public class AccountTotalManager {
@Resource
private AccountMapper accountMapper;
public void incsGuardIncomeCoin(Long userId, Long amount, Long businessLogId){
log.info("开始收入统计 守护: userId={},amount={}, businessLogId={}", userId, amount, businessLogId);
accountMapper.incsGuardIncomeIcon(userId, amount);
}
public void incsGiftIncomeCoin(Long userId, Long amount, Long businessLogId){
log.info("开始收入统计 礼物: userId={},amount={}, businessLogId={}", userId, amount, businessLogId);
accountMapper.incsGiftIncomeIcon(userId, amount);
}
public void incsMessageIncomeCoin(Long userId, Long amount, Long businessLogId) {
log.info("开始收入统计 聊天: userId={},amount={}, businessLogId={}", userId, amount, businessLogId);
accountMapper.incsMessageIncomeIcon(userId, amount);
}
public void incsVideoIncomeCoin(Long userId, Long amount, Long businessLogId) {
log.info("开始收入统计 视频: userId={},amount={}, businessLogId={}", userId, amount, businessLogId);
accountMapper.incsVideoIncomeIcon(userId, amount);
}
public void incsPayIncomeCoin(Long userId, Long rechargeCoin, BigDecimal price, Long consumeLogId) {
log.info("开始收入统计 充值: userId={},price={},rechargeCoin={}, businessLogId={}", userId, price, rechargeCoin,consumeLogId);
accountMapper.incsPayTotal(userId, rechargeCoin, price);
}
}

View File

@@ -52,6 +52,8 @@ public class ConsumerManager {
private UserService userService;
@Autowired
private AnchorService anchorService;
@Autowired
private AccountTotalManager accountTotalManager;
public GuardConsumerResp sendGuard(GiveGuardReq query){
GuardConsumerResp resp = guardTotalService.giveGuard(query);
@@ -61,6 +63,12 @@ public class ConsumerManager {
}catch (Exception e){
log.error("RabbitMq 发送失败, 守护分销流程流转失败!",e);
}
try {
// 记录主播的消费记录
accountTotalManager.incsGuardIncomeCoin(resp.getToUid(), resp.getAnchorIncomeCoin(),resp.getConsumeLogId());
}catch (Exception e){
log.error("主播消费记录失败-守护",e);
}
try {
Account account = accountService.getByUserId(resp.getToUid());
if(account != null){
@@ -83,6 +91,12 @@ public class ConsumerManager {
}catch (Exception e){
log.error("RabbitMq 发送失败, 礼物分销流程流转失败!",e);
}
try {
// 记录主播的消费记录
accountTotalManager.incsGiftIncomeCoin(resp.getToUid(), resp.getAnchorIncomeCoin(),resp.getConsumeLogId());
}catch (Exception e){
log.error("主播消费记录失败-礼物",e);
}
try {
Account account = accountService.getByUserId(resp.getToUid());
if(account != null){
@@ -125,6 +139,12 @@ public class ConsumerManager {
}catch (Exception e){
log.error("RabbitMq 发送失败, 视频分销流程流转失败!",e);
}
try {
// 记录主播的消费记录
accountTotalManager.incsVideoIncomeCoin(consumeLog.getTargetUserId(), consumeLog.getAnchorAmount(),consumeLog.getId());
}catch (Exception e){
log.error("主播消费记录失败-视频",e);
}
try {
anchorService.incsServiceTimeAndCount(room.getRoomId());
}catch (Exception e){
@@ -156,6 +176,12 @@ public class ConsumerManager {
}catch (Exception e){
log.error("RabbitMq 发送失败, 充值分销流程流转失败!",e);
}
try {
// 记录主播的消费记录
accountTotalManager.incsPayIncomeCoin(resp.getUserId(), resp.getRechargeCoin(),resp.getPrice(), resp.getConsumeLogId());
}catch (Exception e){
log.error("主播消费记录失败-充值",e);
}
try {
Account account = accountService.getByUserId(resp.getUserId());
if(account != null){

View File

@@ -6,6 +6,8 @@ import com.ruoyi.cai.domain.Account;
import com.ruoyi.cai.dto.admin.vo.AccountAdminVo;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
/**
* 用户账户Mapper接口
*
@@ -24,4 +26,14 @@ public interface AccountMapper extends BaseMapper<Account> {
boolean decrIncomeCoinNotCheck(@Param("userId") Long userId, @Param("incomeCoin") Long incomeCoin);
Page<AccountAdminVo> pageAdmin(@Param("build") Page<Object> build, @Param("bo") AccountAdminVo bo);
void incsGiftIncomeIcon(@Param("userId") Long userId, @Param("amount") Long amount);
void incsGuardIncomeIcon(@Param("userId") Long userId, @Param("amount") Long amount);
void incsMessageIncomeIcon(@Param("userId") Long userId, @Param("amount") Long amount);
void incsVideoIncomeIcon(@Param("userId") Long userId, @Param("amount") Long amount);
void incsPayTotal(@Param("userId") Long userId, @Param("rechargeCoin") Long rechargeCoin, @Param("price") BigDecimal price);
}

View File

@@ -13,6 +13,7 @@ import com.ruoyi.cai.enums.ConsumeLogType;
import com.ruoyi.cai.enums.SystemConfigEnum;
import com.ruoyi.cai.enums.account.AccountChangeCodeEnum;
import com.ruoyi.cai.enums.account.AccountTypeEnum;
import com.ruoyi.cai.manager.AccountTotalManager;
import com.ruoyi.cai.manager.IdManager;
import com.ruoyi.cai.manager.SystemConfigManager;
import com.ruoyi.cai.mapper.AccountMapper;
@@ -53,6 +54,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
private SystemConfigManager systemConfigManager;
@Autowired
private CaiProperties caiProperties;
@Autowired
private AccountTotalManager accountTotalManager;
@Override
@@ -170,6 +173,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
// 记录接收方的流水
if(anchorAmount != 0){
try {
// 记录主播的消费记录
accountTotalManager.incsMessageIncomeCoin(toUser.getId(), anchorAmount,tractId);
}catch (Exception e){
log.error("主播消费记录失败",e);
}
accountChangeLogService.saveLogNoAdmin(toUser.getId(),toUser.getUsercode(), AccountChangeCodeEnum.IM_INCOME,anchorAmount,tractId,fromUser.getId());
}
return tractId;

View File

@@ -54,7 +54,7 @@ public class UserChatRecordServiceImpl extends ServiceImpl<UserChatRecordMapper,
this.save(userChatRecord);
String key = String.format(RedisHttpConstant.CHAT_RECORD_CACHE_REDIS, userChatRecord.getId());
RBucket<UserChatRecord> bucket = redissonClient.getBucket(key);
bucket.set(userChatRecord,10, TimeUnit.MINUTES);
bucket.set(userChatRecord,5, TimeUnit.MINUTES);
return userChatRecord;
}

View File

@@ -285,6 +285,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
if(!b){
throw new ServiceException("用户不存在");
}
this.update(Wrappers.lambdaUpdate(User.class)
.eq(User::getInviteId, user.getId())
.set(User::getInviteId, null));
userOnlineService.remove(Wrappers.lambdaQuery(UserOnline.class).eq(UserOnline::getUserId, id));
userInfoService.remove(Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserId, id));
userInviteService.remove(Wrappers.lambdaQuery(UserInvite.class).eq(UserInvite::getUserId, id));

View File

@@ -58,7 +58,7 @@ public class MessageHandleApplication {
Room room = roomService.load(roomId);
if(room == null){
WsExceptionUtil.throwException(session, "房间不可用" ,HangUpEnums.OTHER, roomId);
log.info("调试日志:房间不可用 wsToken={}", JSON.toJSONString(wsToken));
log.info("调试日志:房间不可用 roomId={} wsToken={}", roomId, JSON.toJSONString(wsToken));
return;
}
CheckConnectionDTO checkConnect = roomService.checkConnect(room);

View File

@@ -33,6 +33,10 @@ public class RoomWebSocketUtil {
// WebSocketUtils.sendMessage(sessionKey, JSON.toJSONString(r));
}
public static void sendSendMessageFast(WebSocketSession sessionKey, WsR r){
WebSocketUtils.sendMessage(sessionKey, JSON.toJSONString(r));
}
public static void sendSendMessage(List<String> sessionKey, WsR r){
for (String s : sessionKey) {
sendMessageStatic.sendMessage(s, JSON.toJSONString(r));

View File

@@ -24,15 +24,20 @@ public class WsExceptionUtil {
if(hangUpType == null){
hangUpType = HangUpEnums.OTHER;
}
RoomWebSocketUtil.sendSendMessage(sessionKey, WsRMsgGen.hangup(message,roomId,hangUpType.getCode()));
boolean close = WebSocketUtils.close(sessionKey);
if(!close){
log.warn("ws连接时发现异常{}sessionKey {} roomid {}", message, sessionKey, roomId);
try {
RoomWebSocketUtil.sendSendMessageFast(sessionKey, WsRMsgGen.hangup(message,roomId,hangUpType.getCode()));
boolean close = WebSocketUtils.close(sessionKey);
if(!close){
log.error("ws关闭时发现异常{}sessionKey {} roomid {}", message, sessionKey, roomId);
}
}catch (Exception e){
log.error("ws关闭时发现异常{}sessionKey {} roomid {}", message, sessionKey, roomId,e);
}
}
public static void throwExceptionFast(WebSocketSession session,String message){
RoomWebSocketUtil.sendSendMessage(session, WsRMsgGen.hangup(message, null, HangUpEnums.OTHER.getCode()));
RoomWebSocketUtil.sendSendMessageFast(session, WsRMsgGen.hangup(message, null, HangUpEnums.OTHER.getCode()));
try {
session.close();
} catch (IOException e) {

View File

@@ -41,6 +41,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
set income_coin = income_coin - #{incomeCoin}
where user_id = #{userId}
</update>
<update id="incsGiftIncomeIcon">
update cai_account
set gift_income_coin = gift_income_coin + #{amount}
where user_id = #{userId}
</update>
<update id="incsGuardIncomeIcon">
update cai_account
set guard_income_coin = guard_income_coin + #{amount}
where user_id = #{userId}
</update>
<update id="incsMessageIncomeIcon">
update cai_account
set message_income_coin = message_income_coin + #{amount}
where user_id = #{userId}
</update>
<update id="incsVideoIncomeIcon">
update cai_account
set video_income_coin = video_income_coin + #{amount}
where user_id = #{userId}
</update>
<update id="incsPayTotal">
update cai_account
set total_buy_money = total_buy_money + #{price},
total_buy_coin = total_buy_coin + #{rechargeCoin}
where user_id = #{userId}
</update>
<select id="pageAdmin" resultType="com.ruoyi.cai.dto.admin.vo.AccountAdminVo">
select t1.*,t2.usercode,t2.nickname,t2.mobile,t2.avatar,t2.gender,t2.is_anchor,t2.age
from cai_account t1