123333
This commit is contained in:
@@ -26,10 +26,13 @@ public class RoomCheckDelayMqConsumer {
|
||||
JobResp resp = roomCheckJobService.checkRoom(roomId);
|
||||
if(resp.isNextCreateJob()){
|
||||
// 1分钟后继续执行
|
||||
log.info("1分钟后继续执行房间检测: roomId={}",roomIdStr);
|
||||
amqpProducer.sendRoomCheckDelay(roomIdStr,60);
|
||||
}
|
||||
}catch (Exception e){
|
||||
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();
|
||||
UserCall userCall = userCallService.getById(roomData.getRoomId());
|
||||
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 totalAmount = callPrice * ((callTime / 60) + 1); // 本次需要支付的金额
|
||||
if(callTime % 60 == 0){
|
||||
totalAmount = callPrice * (callTime / 60);
|
||||
}
|
||||
Long payCoin = roomData.getPayCoin(); // 已经支付的余额
|
||||
Long payIncome = roomData.getPayIncome(); // 已经支付的收益
|
||||
// 补差价
|
||||
long diff = totalAmount - (payCoin + payIncome);
|
||||
Account callAccount = this.getByUserId(callUserData.getId());
|
||||
|
||||
@@ -8,12 +8,12 @@ import java.math.BigDecimal;
|
||||
@Data
|
||||
public class RoomData {
|
||||
private Long roomId;
|
||||
private Long callPrice;
|
||||
private Integer callPrice;
|
||||
private String skillName;
|
||||
private Integer status;
|
||||
private BigDecimal videoDivide;
|
||||
private Long payCoin = 0L;
|
||||
private Long payIncome = 0L;
|
||||
private Integer payCoin = 0;
|
||||
private Integer payIncome = 0;
|
||||
private Long hangupTime; // 结束时间
|
||||
|
||||
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" +
|
||||
"if hangupTime and hangupTime > 0 then\n" +
|
||||
private final static String HANG_UP = "local hangupTime = redis.call('hGet', KEYS[1], '\"hangupTime\"')\n" +
|
||||
"if hangupTime then\n" +
|
||||
" return 0\n" +
|
||||
"end\n" +
|
||||
"return redis.call('hMSet', KEYS[1], '\"status\"', 8, '\"hangupTime\"', ARGV[1])";
|
||||
|
||||
public boolean hangUp(Long roomId) {
|
||||
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,
|
||||
Collections.singletonList(getKey(roomId)), currentTime);
|
||||
// DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<>(HANG_UP,Boolean.class);
|
||||
@@ -111,8 +111,8 @@ public class RoomDataCache {
|
||||
|
||||
private final static String SET_STATUS_AGREE =
|
||||
"local status = tonumber(redis.call('hget', KEYS[1], '\"status\"'))\n" +
|
||||
"local beginTime = tonumber(redis.call('hget', KEYS[1], '\"beginTime\"'))\n" +
|
||||
"if status ~= 3 or (beginTime and beginTime > 0) then\n" +
|
||||
"local beginTime = redis.call('hget', KEYS[1], '\"beginTime\"')\n" +
|
||||
"if status ~= 3 or beginTime) then\n" +
|
||||
" return 0\n" +
|
||||
"end\n" +
|
||||
"return redis.call('hmset', KEYS[1], '\"status\"', 7, '\"beginTime\"', ARGV[1])";
|
||||
|
||||
@@ -128,7 +128,9 @@ public class RoomCheckJobService {
|
||||
nextCreateJob = settleResp.isNextRun();
|
||||
}
|
||||
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(true).build();
|
||||
|
||||
@@ -103,7 +103,7 @@ public class WebSocketManager {
|
||||
// 初始化
|
||||
RoomData roomData = new RoomData();
|
||||
roomData.setRoomId(call.getId());
|
||||
roomData.setCallPrice(call.getCallPrice());
|
||||
roomData.setCallPrice(call.getCallPrice().intValue());
|
||||
roomData.setStatus(call.getStatus());
|
||||
roomData.setVideoDivide(call.getReceiverVideoDivide());
|
||||
roomDataCache.init(roomData);
|
||||
|
||||
@@ -59,8 +59,8 @@ public class SettleService {
|
||||
SettleService settleService = SpringUtil.getBean(SettleService.class);
|
||||
try {
|
||||
Long userId = room.getCallUserData().getId();
|
||||
Long price = room.getRoomData().getCallPrice();
|
||||
settleService.withholdingFeeUser(userId,price,room);
|
||||
Integer price = room.getRoomData().getCallPrice();
|
||||
settleService.withholdingFeeUser(userId,Long.valueOf(price),room);
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
log.error("预扣费失败!准备挂断电话",e);
|
||||
@@ -125,9 +125,12 @@ public class SettleService {
|
||||
* @param room
|
||||
*/
|
||||
private SettleResp deal(Room room){
|
||||
if(room.isCanCall() || room.isSettle()){ // 正在通话中,或者已经结算了 ,都无需在结算
|
||||
if(room.isCanCall()){ // 正在通话中,无需在结算
|
||||
return SettleResp.builder().nextRun(true).build();
|
||||
}
|
||||
if(room.isSettle()){ // 已经结算了,无需结算
|
||||
return SettleResp.builder().nextRun(false).build();
|
||||
}
|
||||
if(!room.isReleaseRes()){ // 房间资源是否已经释放
|
||||
roomService.releaseRes(room.getRoomId()); // 释放房间会更新用户和主播的状态
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user