对一大波idea提醒需要优化的地方进行处理

This commit is contained in:
handy
2023-11-23 16:25:59 +08:00
parent 8b1fb129ce
commit efa2538736
98 changed files with 195 additions and 289 deletions

View File

@@ -1,23 +1,15 @@
package com.zyplayer.doc.manage;
import com.zyplayer.doc.core.util.ZyplayerDocVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.net.InetAddress;
import java.util.Optional;
/**
* 程序启动器
*
@@ -34,14 +26,14 @@ import java.util.Optional;
})
public class Application extends SpringBootServletInitializer {
private static Logger logger = LoggerFactory.getLogger(Application.class);
private static final Logger logger = LoggerFactory.getLogger(Application.class);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
}
}

View File

@@ -3,15 +3,9 @@ package com.zyplayer.doc.manage.framework.config;
import com.zyplayer.doc.api.framework.config.EnableDocApi;
import com.zyplayer.doc.db.framework.configuration.EnableDocDb;
import com.zyplayer.doc.wiki.framework.config.EnableDocWiki;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
/**
* 按需开启zyplayer-doc所有的服务
*
@@ -25,18 +19,18 @@ public class ZyplayerDocConfig {
@EnableDocWiki
//wiki模块加载注解条件化配合配置文件决定是否加载
@ConditionalOnProperty(prefix = "zyplayer.doc.manage.enable", name = "wiki", matchIfMissing = true)
public class enableWiki {
public static class enableWiki {
}
@EnableDocDb
//db模块加载注解条件化配合配置文件决定是否加载
@ConditionalOnProperty(prefix = "zyplayer.doc.manage.enable", name = "db", matchIfMissing = true)
public class enableDb {
public static class enableDb {
}
@EnableDocApi
//api模块加载注解条件化配合配置文件决定是否加载
@ConditionalOnProperty(prefix = "zyplayer.doc.manage.enable", name = "api", matchIfMissing = true)
public class enableApi {
public static class enableApi {
}
}

View File

@@ -16,7 +16,7 @@ import java.util.HashMap;
*/
@Configuration
public class ZyplayerModuleKeeper implements ApplicationContextAware {
HashMap<String, Boolean> moduleInfo = new HashMap<>();
final HashMap<String, Boolean> moduleInfo = new HashMap<>();
private ApplicationContext applicationContext;
@Override
@@ -26,7 +26,7 @@ public class ZyplayerModuleKeeper implements ApplicationContextAware {
//获取模块是否启动
public boolean ismoduleStarted(Class<?> clazz) {
if (moduleInfo.size() < 1) {
if (moduleInfo.isEmpty()) {
getmoduleInfo();
}
return moduleInfo.get(clazz.getName().split("\\$")[1]);
@@ -34,7 +34,7 @@ public class ZyplayerModuleKeeper implements ApplicationContextAware {
//提供模块开启状态数组,给前端控制页面展示
public HashMap<String, Boolean> getmoduleInfo() {
if (moduleInfo.size() < 1) {
if (moduleInfo.isEmpty()) {
synchronized (ZyplayerModuleKeeper.class) {
Class<? extends ZyplayerDocConfig> clazz = ZyplayerDocConfig.class;
Class<?>[] innerClasses = clazz.getClasses();
@@ -54,6 +54,6 @@ public class ZyplayerModuleKeeper implements ApplicationContextAware {
} catch (BeansException e) {
return false;
}
return null != bean;
return true;
}
}

View File

@@ -23,7 +23,7 @@ public class ApplicationInfoConsolePrint implements IConsolePrint {
public void buildPrintInfo(StringBuilder printInfo) throws Exception {
String contextPath = environment.getProperty("server.servlet.context-path");
contextPath = Optional.ofNullable(contextPath).orElse("").replaceFirst("/", "");
contextPath = (contextPath.length() <= 0 || contextPath.endsWith("/")) ? contextPath : contextPath + "/";
contextPath = (contextPath.isEmpty() || contextPath.endsWith("/")) ? contextPath : contextPath + "/";
String hostAddress = InetAddress.getLocalHost().getHostAddress();
String serverPort = environment.getProperty("server.port");
String urlCtx = hostAddress + ":" + serverPort + "/" + contextPath;

View File

@@ -1,9 +1,6 @@
package com.zyplayer.doc.manage.framework.console;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import java.net.UnknownHostException;
/**
* 启动后打印信息接口
@@ -12,5 +9,5 @@ import java.net.UnknownHostException;
* @since 2023年6月16日
*/
public interface IConsolePrint extends Ordered {
public void buildPrintInfo(StringBuilder printInfo) throws Exception;
void buildPrintInfo(StringBuilder printInfo) throws Exception;
}

View File

@@ -19,7 +19,7 @@ public class ModuleInfoConsolePrint implements IConsolePrint {
ZyplayerModuleKeeper moduleKeeper;
@Override
public void buildPrintInfo(StringBuilder printInfo) throws Exception {
public void buildPrintInfo(StringBuilder printInfo) {
printInfo.append("\n\n\t\t\t\t↓zyplayer-doc模块的启动情况\n")
.append("\t\t\t\t------------------------\n");
HashMap<String, Boolean> moduleInfoMap = moduleKeeper.getmoduleInfo();

View File

@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
public class ZyplayerConsolePrint implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(ZyplayerConsolePrint.class);
StringBuilder logInfoHolder = new StringBuilder();
final StringBuilder logInfoHolder = new StringBuilder();
@Resource
ObjectProvider<List<IConsolePrint>> consolePrintListProvider;

View File

@@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

View File

@@ -23,7 +23,7 @@ import java.util.Properties;
*/
@Component
public class SchedulerTask {
private static Logger logger = LoggerFactory.getLogger(SchedulerTask.class);
private static final Logger logger = LoggerFactory.getLogger(SchedulerTask.class);
@Value("${zyplayer.doc.manage.upgradePropertiesUrl:}")
private String upgradePropertiesUrl;

View File

@@ -32,7 +32,7 @@ import java.util.Objects;
*/
@RestController
public class LoginController {
private static Logger logger = LoggerFactory.getLogger(LoginController.class);
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
@Resource
private UserInfoService userInfoService;

View File

@@ -2,7 +2,6 @@ package com.zyplayer.doc.manage.web;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.manage.framework.config.ZyplayerDocConfig;
import com.zyplayer.doc.manage.framework.config.ZyplayerModuleKeeper;
import com.zyplayer.doc.manage.framework.upgrade.UpgradeUtil;
import org.springframework.web.bind.annotation.GetMapping;

View File

@@ -11,7 +11,6 @@ import com.zyplayer.doc.data.repository.manage.entity.UserAuth;
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
import com.zyplayer.doc.data.service.manage.AuthInfoService;
import com.zyplayer.doc.data.service.manage.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -119,7 +119,7 @@ public class UserInfoController {
if (StringUtils.isBlank(userInfo.getUserName())) {
return DocResponseJson.warn("用户名必填");
}
Long userId = Optional.ofNullable(userInfo.getId()).orElse(0L);
long userId = Optional.ofNullable(userInfo.getId()).orElse(0L);
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_no", userInfo.getUserNo());
queryWrapper.ne(userId > 0, "id", userInfo.getId());