123
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.cai.executor;
|
||||
|
||||
import com.alibaba.ttl.threadpool.TtlExecutors;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@@ -10,6 +11,7 @@ import java.util.concurrent.*;
|
||||
* <p>created on 2023/3/3 11:16</p>
|
||||
* @author ZL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ExecutorConstant {
|
||||
|
||||
// private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
||||
@@ -18,9 +20,19 @@ public class ExecutorConstant {
|
||||
public static Executor SYNC_EXECUTOR;
|
||||
|
||||
public static Executor COMMON_EXECUTOR;
|
||||
public static Executor SMS_EXECUTOR;
|
||||
public static Executor ROOM_EXECUTOR;
|
||||
|
||||
static {
|
||||
ThreadPoolExecutor smsExecutor = new ThreadPoolExecutor(CPU_NUM,
|
||||
CPU_NUM << 2,
|
||||
5,
|
||||
TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(),
|
||||
init("smsExecutor-%d"));
|
||||
SMS_EXECUTOR = TtlExecutors.getTtlExecutor(smsExecutor);
|
||||
|
||||
|
||||
ThreadPoolExecutor syncExecutor = initExecutor(CPU_NUM,
|
||||
CPU_NUM << 2,
|
||||
5,
|
||||
@@ -49,10 +61,6 @@ public class ExecutorConstant {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(6 << 2);
|
||||
}
|
||||
|
||||
private static ThreadFactory init(String nameFormat){
|
||||
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.aliyuncs.profile.IClientProfile;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.ruoyi.cai.config.AliSmsProperties;
|
||||
import com.ruoyi.cai.enums.CodeEnum;
|
||||
import com.ruoyi.cai.executor.ExecutorConstant;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -102,9 +103,9 @@ public class AliSmsKit {
|
||||
|
||||
public boolean sendMessage(String phone, String messageTemplate, String messageCode, boolean isAsy) {
|
||||
if (isAsy) {
|
||||
new Thread(() -> {
|
||||
sendMessage(phone, messageTemplate, messageCode);
|
||||
}).start();
|
||||
ExecutorConstant.SMS_EXECUTOR.execute(() -> {
|
||||
sendMessage(phone, messageTemplate, messageCode);
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
return sendMessage(phone, messageTemplate, messageCode);
|
||||
|
||||
@@ -29,4 +29,6 @@ public interface AnchorService extends IService<Anchor> {
|
||||
void updateVideoStatus(Long userId, int videoStatus);
|
||||
|
||||
void incsServiceTimeAndCount(Long roomId);
|
||||
|
||||
void updateVideoStatusOnline(Long userId);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.ruoyi.cai.notice.YunxinHttpService;
|
||||
import com.ruoyi.cai.service.AnchorService;
|
||||
import com.ruoyi.cai.service.UserCallService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.cai.ws.constant.RoomStatusEnums;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -24,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 女神列表Service业务层处理
|
||||
*
|
||||
@@ -139,4 +142,23 @@ public class AnchorServiceImpl extends ServiceImpl<AnchorMapper, Anchor> impleme
|
||||
baseMapper.incsServiceTimeAndCount(userCall.getToUid(), userCall.getCallTime(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVideoStatusOnline(Long userId) {
|
||||
Anchor anchor = this.getByUserId(userId);
|
||||
if(anchor.getVideoStatus() == 0){
|
||||
throw new ServiceException("主播拨打状态已经是空闲中");
|
||||
}
|
||||
UserCall one = userCallService.getOne(Wrappers.lambdaQuery(UserCall.class).eq(UserCall::getToUid, userId).orderByDesc(UserCall::getCreateTime).last("limit 1"));
|
||||
if(one != null){
|
||||
if(one.getCreateTime().plusMinutes(3).isAfter(LocalDateTime.now())){
|
||||
throw new ServiceException("主播最近一次通话时间,没超过3分钟,不允许修改状态为空闲");
|
||||
}
|
||||
if(RoomStatusEnums.STATUS_AGREE.getCode().equals(one.getStatus())){
|
||||
throw new ServiceException("检测到主播正在通话中,不允许修改为空闲");
|
||||
}
|
||||
}
|
||||
userService.updateVideoStatus(userId,0);
|
||||
this.updateVideoStatus(userId,0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user