123333
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package com.ruoyi.test.business;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.ruoyi.cai.ws.cache.RoomDataCache;
|
||||||
|
import com.ruoyi.cai.ws.job.JobResp;
|
||||||
|
import com.ruoyi.cai.ws.job.RoomCheckJobService;
|
||||||
|
import com.ruoyi.cai.ws.service.RoomService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Slf4j
|
||||||
|
public class RoomTest {
|
||||||
|
@Autowired
|
||||||
|
private RoomCheckJobService roomCheckJobService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
Long roomId = 1761964822147088386L;
|
||||||
|
JobResp resp = roomCheckJobService.checkRoom(roomId);
|
||||||
|
log.error(JSON.toJSONString(resp));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoomService roomService;
|
||||||
|
@Autowired
|
||||||
|
private RoomDataCache roomDataCache;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRedisLua(){
|
||||||
|
Long roomId = 1761964822147088386L;
|
||||||
|
// boolean b = roomService.hangUp(roomId);
|
||||||
|
boolean b = roomDataCache.setStatusAgree(roomId);
|
||||||
|
log.error("结果 b:{}",b);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,10 +26,13 @@ public class RoomCheckDelayMqConsumer {
|
|||||||
JobResp resp = roomCheckJobService.checkRoom(roomId);
|
JobResp resp = roomCheckJobService.checkRoom(roomId);
|
||||||
if(resp.isNextCreateJob()){
|
if(resp.isNextCreateJob()){
|
||||||
// 1分钟后继续执行
|
// 1分钟后继续执行
|
||||||
|
log.info("1分钟后继续执行房间检测: roomId={}",roomIdStr);
|
||||||
amqpProducer.sendRoomCheckDelay(roomIdStr,60);
|
amqpProducer.sendRoomCheckDelay(roomIdStr,60);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("每分钟定时检测房间失败! roomId={}",roomIdStr);
|
log.error("每分钟定时检测房间失败! roomId={}",roomIdStr);
|
||||||
|
}finally {
|
||||||
|
log.info("结束执行房间检测: roomId={}",roomIdStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,15 +321,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
RoomData roomData = room.getRoomData();
|
RoomData roomData = room.getRoomData();
|
||||||
UserCall userCall = userCallService.getById(roomData.getRoomId());
|
UserCall userCall = userCallService.getById(roomData.getRoomId());
|
||||||
UserData callUserData = room.getCallUserData();
|
UserData callUserData = room.getCallUserData();
|
||||||
Long callPrice = roomData.getCallPrice();
|
Long callPrice = Long.valueOf(roomData.getCallPrice()); // 通话单价
|
||||||
|
Long payCoin = Long.valueOf(roomData.getPayCoin()); // 已经支付的余额
|
||||||
|
Long payIncome = Long.valueOf(roomData.getPayIncome()); // 已经支付的收益
|
||||||
Long callTime = roomService.getCallTime(room);
|
Long callTime = roomService.getCallTime(room);
|
||||||
// 本次支付金额
|
// 本次支付金额
|
||||||
long totalAmount = callPrice * ((callTime / 60) + 1); // 本次需要支付的金额
|
long totalAmount = callPrice * ((callTime / 60) + 1); // 本次需要支付的金额
|
||||||
if(callTime % 60 == 0){
|
if(callTime % 60 == 0){
|
||||||
totalAmount = callPrice * (callTime / 60);
|
totalAmount = callPrice * (callTime / 60);
|
||||||
}
|
}
|
||||||
Long payCoin = roomData.getPayCoin(); // 已经支付的余额
|
|
||||||
Long payIncome = roomData.getPayIncome(); // 已经支付的收益
|
|
||||||
// 补差价
|
// 补差价
|
||||||
long diff = totalAmount - (payCoin + payIncome);
|
long diff = totalAmount - (payCoin + payIncome);
|
||||||
Account callAccount = this.getByUserId(callUserData.getId());
|
Account callAccount = this.getByUserId(callUserData.getId());
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import java.math.BigDecimal;
|
|||||||
@Data
|
@Data
|
||||||
public class RoomData {
|
public class RoomData {
|
||||||
private Long roomId;
|
private Long roomId;
|
||||||
private Long callPrice;
|
private Integer callPrice;
|
||||||
private String skillName;
|
private String skillName;
|
||||||
private Integer status;
|
private Integer status;
|
||||||
private BigDecimal videoDivide;
|
private BigDecimal videoDivide;
|
||||||
private Long payCoin = 0L;
|
private Integer payCoin = 0;
|
||||||
private Long payIncome = 0L;
|
private Integer payIncome = 0;
|
||||||
private Long hangupTime; // 结束时间
|
private Long hangupTime; // 结束时间
|
||||||
|
|
||||||
private Long settleTime; // 结算时间
|
private Long settleTime; // 结算时间
|
||||||
|
|||||||
@@ -71,15 +71,15 @@ public class RoomDataCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final static String HANG_UP = "local hangupTime = tonumber(redis.call('hGet', KEYS[1], '\"hangupTime\"'))\n" +
|
private final static String HANG_UP = "local hangupTime = redis.call('hGet', KEYS[1], '\"hangupTime\"')\n" +
|
||||||
"if hangupTime and hangupTime > 0 then\n" +
|
"if hangupTime then\n" +
|
||||||
" return 0\n" +
|
" return 0\n" +
|
||||||
"end\n" +
|
"end\n" +
|
||||||
"return redis.call('hMSet', KEYS[1], '\"status\"', 8, '\"hangupTime\"', ARGV[1])";
|
"return redis.call('hMSet', KEYS[1], '\"status\"', 8, '\"hangupTime\"', ARGV[1])";
|
||||||
|
|
||||||
public boolean hangUp(Long roomId) {
|
public boolean hangUp(Long roomId) {
|
||||||
RScript script = redissonClient.getScript();
|
RScript script = redissonClient.getScript();
|
||||||
Long currentTime = System.currentTimeMillis() / 1000;
|
Long currentTime = (System.currentTimeMillis() / 1000);
|
||||||
Boolean execute = script.eval(RScript.Mode.READ_WRITE, HANG_UP, RScript.ReturnType.BOOLEAN,
|
Boolean execute = script.eval(RScript.Mode.READ_WRITE, HANG_UP, RScript.ReturnType.BOOLEAN,
|
||||||
Collections.singletonList(getKey(roomId)), currentTime);
|
Collections.singletonList(getKey(roomId)), currentTime);
|
||||||
// DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<>(HANG_UP,Boolean.class);
|
// DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<>(HANG_UP,Boolean.class);
|
||||||
@@ -111,8 +111,8 @@ public class RoomDataCache {
|
|||||||
|
|
||||||
private final static String SET_STATUS_AGREE =
|
private final static String SET_STATUS_AGREE =
|
||||||
"local status = tonumber(redis.call('hget', KEYS[1], '\"status\"'))\n" +
|
"local status = tonumber(redis.call('hget', KEYS[1], '\"status\"'))\n" +
|
||||||
"local beginTime = tonumber(redis.call('hget', KEYS[1], '\"beginTime\"'))\n" +
|
"local beginTime = redis.call('hget', KEYS[1], '\"beginTime\"')\n" +
|
||||||
"if status ~= 3 or (beginTime and beginTime > 0) then\n" +
|
"if status ~= 3 or beginTime) then\n" +
|
||||||
" return 0\n" +
|
" return 0\n" +
|
||||||
"end\n" +
|
"end\n" +
|
||||||
"return redis.call('hmset', KEYS[1], '\"status\"', 7, '\"beginTime\"', ARGV[1])";
|
"return redis.call('hmset', KEYS[1], '\"status\"', 7, '\"beginTime\"', ARGV[1])";
|
||||||
|
|||||||
@@ -128,7 +128,9 @@ public class RoomCheckJobService {
|
|||||||
nextCreateJob = settleResp.isNextRun();
|
nextCreateJob = settleResp.isNextRun();
|
||||||
}
|
}
|
||||||
roomService.closeAllFd(roomId);
|
roomService.closeAllFd(roomId);
|
||||||
yunxinWsService.sendToCallNotify(callUserData.getId(),receiverUserData.getId(), CallNoticeEnum.TIMEOUT,0L);
|
if(!nextCreateJob){
|
||||||
|
yunxinWsService.sendToCallNotify(callUserData.getId(),receiverUserData.getId(), CallNoticeEnum.TIMEOUT,0L);
|
||||||
|
}
|
||||||
return JobResp.builder().nextCreateJob(nextCreateJob).build();
|
return JobResp.builder().nextCreateJob(nextCreateJob).build();
|
||||||
}
|
}
|
||||||
return JobResp.builder().nextCreateJob(true).build();
|
return JobResp.builder().nextCreateJob(true).build();
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class WebSocketManager {
|
|||||||
// 初始化
|
// 初始化
|
||||||
RoomData roomData = new RoomData();
|
RoomData roomData = new RoomData();
|
||||||
roomData.setRoomId(call.getId());
|
roomData.setRoomId(call.getId());
|
||||||
roomData.setCallPrice(call.getCallPrice());
|
roomData.setCallPrice(call.getCallPrice().intValue());
|
||||||
roomData.setStatus(call.getStatus());
|
roomData.setStatus(call.getStatus());
|
||||||
roomData.setVideoDivide(call.getReceiverVideoDivide());
|
roomData.setVideoDivide(call.getReceiverVideoDivide());
|
||||||
roomDataCache.init(roomData);
|
roomDataCache.init(roomData);
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ public class SettleService {
|
|||||||
SettleService settleService = SpringUtil.getBean(SettleService.class);
|
SettleService settleService = SpringUtil.getBean(SettleService.class);
|
||||||
try {
|
try {
|
||||||
Long userId = room.getCallUserData().getId();
|
Long userId = room.getCallUserData().getId();
|
||||||
Long price = room.getRoomData().getCallPrice();
|
Integer price = room.getRoomData().getCallPrice();
|
||||||
settleService.withholdingFeeUser(userId,price,room);
|
settleService.withholdingFeeUser(userId,Long.valueOf(price),room);
|
||||||
return true;
|
return true;
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("预扣费失败!准备挂断电话",e);
|
log.error("预扣费失败!准备挂断电话",e);
|
||||||
@@ -125,9 +125,12 @@ public class SettleService {
|
|||||||
* @param room
|
* @param room
|
||||||
*/
|
*/
|
||||||
private SettleResp deal(Room room){
|
private SettleResp deal(Room room){
|
||||||
if(room.isCanCall() || room.isSettle()){ // 正在通话中,或者已经结算了 ,都无需在结算
|
if(room.isCanCall()){ // 正在通话中,无需在结算
|
||||||
return SettleResp.builder().nextRun(true).build();
|
return SettleResp.builder().nextRun(true).build();
|
||||||
}
|
}
|
||||||
|
if(room.isSettle()){ // 已经结算了,无需结算
|
||||||
|
return SettleResp.builder().nextRun(false).build();
|
||||||
|
}
|
||||||
if(!room.isReleaseRes()){ // 房间资源是否已经释放
|
if(!room.isReleaseRes()){ // 房间资源是否已经释放
|
||||||
roomService.releaseRes(room.getRoomId()); // 释放房间会更新用户和主播的状态
|
roomService.releaseRes(room.getRoomId()); // 释放房间会更新用户和主播的状态
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
t1.*,t2.age,t2.avatar,t2.usercode,t2.nickname,t2.mobile,t2.gender,t2.age,t2.city
|
t1.*,t2.age,t2.avatar,t2.usercode,t2.nickname,t2.mobile,t2.gender,t2.age,t2.city
|
||||||
from cai_anchor t1
|
from cai_anchor t1
|
||||||
left join cai_user t2 on t1.user_id = t2.id
|
left join cai_user t2 on t1.user_id = t2.id
|
||||||
|
<where>
|
||||||
|
<if test="bo.mobile != null and bo.mobile != ''">
|
||||||
|
and t2.mobile = #{bo.mobile}
|
||||||
|
</if>
|
||||||
|
<if test="bo.usercode != null and bo.usercode != ''">
|
||||||
|
and t2.usercode = #{bo.usercode}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
order by t1.create_time desc
|
order by t1.create_time desc
|
||||||
</select>
|
</select>
|
||||||
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.AnchorListVo">
|
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.AnchorListVo">
|
||||||
|
|||||||
Reference in New Issue
Block a user