20260716215550

This commit is contained in:
oneao committed 2026-07-16 21:55:51 +08:00
1 parent 5cd4e1e1d2
commit 49dafe524c
21 files changed
+1218 -272

No files matched your search

@@ -28,6 +28,9 @@ public class OrgDataSourceFactory {
dataSource.setTestWhileIdle(poolProperties.isTestWhileIdle());
dataSource.setTestOnBorrow(poolProperties.isTestOnBorrow());
dataSource.setTestOnReturn(poolProperties.isTestOnReturn());
dataSource.setConnectionErrorRetryAttempts(0);
dataSource.setBreakAfterAcquireFailure(true);
dataSource.setFailFast(true);
dataSource.setTimeBetweenEvictionRunsMillis(
poolProperties.getTimeBetweenEvictionRuns().toMillis()
);
@@ -1,5 +1,6 @@
package cn.g3soft.fmsapi.database;
import cn.g3soft.fmsapi.exception.AuthenticationException;
import cn.g3soft.fmsapi.exception.BusinessException;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
@@ -39,7 +40,7 @@ public class OrgDatabaseConfigLoader {
throw new IllegalArgumentException("机构配置文件路径不合法");
}
if (!Files.isRegularFile(configFile)) {
throw new IllegalStateException("未找到机构数据库配置文件: " + configFile);
throw new AuthenticationException("机构码错误");
}
Properties properties = new Properties();
@@ -0,0 +1,8 @@
package cn.g3soft.fmsapi.exception;
public class AuthenticationException extends BusinessException {
public AuthenticationException(String message) {
super(message);
}
}
@@ -4,23 +4,48 @@ import cn.g3soft.fmsapi.utils.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLException;
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(AuthenticationException.class)
public ApiResponse<Void> handleAuthenticationException(AuthenticationException exception) {
return ApiResponse.fail(ApiResponse.AUTH_ERROR_CODE, exception.getMessage());
}
@ExceptionHandler(BusinessException.class)
public ApiResponse<Void> handleBusinessException(BusinessException exception) {
return ApiResponse.fail(exception.getMessage());
}
@ExceptionHandler({SQLException.class, DataAccessException.class})
public ApiResponse<Void> handleDatabaseException(
Exception exception,
HttpServletRequest request
) {
logSystemException(exception, request);
return systemErrorResponse();
}
@ExceptionHandler(Exception.class)
public ApiResponse<Void> handleException(
Exception exception,
HttpServletRequest request
) {
logSystemException(exception, request);
return systemErrorResponse();
}
private void logSystemException(
Exception exception,
HttpServletRequest request
) {
LOGGER.error(
"系统异常,method={},uri={}",
@@ -28,6 +53,9 @@ public class GlobalExceptionHandler {
request.getRequestURI(),
exception
);
}
private ApiResponse<Void> systemErrorResponse() {
return ApiResponse.fail(
ApiResponse.SYSTEM_ERROR_CODE,
"系统异常,请稍后重试"
@@ -17,10 +17,10 @@ public class DataService {
public List<Map<String, Object>> loadData(Map<String, Object> params) throws SQLException {
return dbUtils.loadData(
ParamUtils.getRequiredString(params, "viewName"),
ParamUtils.getString(params, "searchCondition"),
ParamUtils.getString(params, "orderField"),
ParamUtils.getList(params, "searchColumns")
ParamUtils.getRequiredString(params, "view_name"),
ParamUtils.getString(params, "search_condition"),
ParamUtils.getString(params, "order_field"),
ParamUtils.getList(params, "search_columns")
);
}