fix: 代码规范化修改

This commit is contained in:
zigzag 2023-06-11 23:03:54 +08:00
parent 13dc04d4af
commit 7e78a63bb4
7 changed files with 20 additions and 16 deletions

View File

@ -6,10 +6,12 @@ import org.springframework.context.ApplicationEvent;
@Getter
public class MessageMarkEvent extends ApplicationEvent {
private ChatMessageMarkDTO dto;
private final ChatMessageMarkDTO dto;
public MessageMarkEvent(Object source, ChatMessageMarkDTO dto) {
super(source);
this.dto = dto;
}
}

View File

@ -6,10 +6,12 @@ import org.springframework.context.ApplicationEvent;
@Getter
public class MessageRecallEvent extends ApplicationEvent {
private ChatMsgRecallDTO recallDTO;
private final ChatMsgRecallDTO recallDTO;
public MessageRecallEvent(Object source, ChatMsgRecallDTO recallDTO) {
super(source);
this.recallDTO = recallDTO;
}
}

View File

@ -17,7 +17,7 @@ public abstract class AbstractRedisStringCache<IN, OUT> implements BatchCache<IN
private Class<OUT> outClass;
public AbstractRedisStringCache() {
protected AbstractRedisStringCache() {
ParameterizedType genericSuperclass = (ParameterizedType) this.getClass().getGenericSuperclass();
this.outClass = (Class<OUT>) genericSuperclass.getActualTypeArguments()[1];
}

View File

@ -8,6 +8,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import java.lang.reflect.Method;
import java.util.Optional;
/**
* Description: spring el表达式解析
@ -19,7 +20,7 @@ public class SpElUtils {
private static final DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
public static String parseSpEl(Method method, Object[] args, String spEl) {
String[] params = parameterNameDiscoverer.getParameterNames(method);//解析参数名
String[] params = Optional.ofNullable(parameterNameDiscoverer.getParameterNames(method)).orElse(new String[]{});//解析参数名
EvaluationContext context = new StandardEvaluationContext();//el解析需要的上下文对象
for (int i = 0; i < params.length; i++) {
context.setVariable(params[i], args[i]);//所有参数都作为原材料扔进去

View File

@ -33,7 +33,7 @@ public enum ItemEnum {
cache = Arrays.stream(ItemEnum.values()).collect(Collectors.toMap(ItemEnum::getId, Function.identity()));
}
public static ItemEnum of(Integer type) {
public static ItemEnum of(Long type) {
return cache.get(type);
}
}

View File

@ -29,7 +29,7 @@ public enum RoleEnum {
cache = Arrays.stream(RoleEnum.values()).collect(Collectors.toMap(RoleEnum::getId, Function.identity()));
}
public static RoleEnum of(Integer type) {
public static RoleEnum of(Long type) {
return cache.get(type);
}
}

View File

@ -33,10 +33,10 @@ import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class IpServiceImpl implements IpService, DisposableBean {
private static ExecutorService executor = new ThreadPoolExecutor(1, 1,
private static final ExecutorService EXECUTOR = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(500),
new NamedThreadFactory("refresh-ipDetail", (ThreadGroup) null, false,
new LinkedBlockingQueue<>(500),
new NamedThreadFactory("refresh-ipDetail", null, false,
new GlobalUncaughtExceptionHandler()));
@Autowired
@ -47,7 +47,7 @@ public class IpServiceImpl implements IpService, DisposableBean {
@Override
public void refreshIpDetailAsync(Long uid) {
executor.execute(() -> {
EXECUTOR.execute(() -> {
User user = userDao.getById(uid);
IpInfo ipInfo = user.getIpInfo();
if (Objects.isNull(ipInfo)) {
@ -106,7 +106,7 @@ public class IpServiceImpl implements IpService, DisposableBean {
Date begin = new Date();
for (int i = 0; i < 100; i++) {
int finalI = i;
executor.execute(() -> {
EXECUTOR.execute(() -> {
IpDetail ipDetail = TryGetIpDetailOrNullTreeTimes("113.90.36.126");
if (Objects.nonNull(ipDetail)) {
Date date = new Date();
@ -118,13 +118,12 @@ public class IpServiceImpl implements IpService, DisposableBean {
@Override
public void destroy() throws InterruptedException {
executor.shutdown();
if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {//最多等30秒处理不完就拉倒
EXECUTOR.shutdown();
if (!EXECUTOR.awaitTermination(30, TimeUnit.SECONDS)) {//最多等30秒处理不完就拉倒
if (log.isErrorEnabled()) {
log.error("Timed out while waiting for executor [{}] to terminate", executor);
log.error("Timed out while waiting for executor [{}] to terminate", EXECUTOR);
}
}
}
}