sonarqube质量修复

This commit is contained in:
gaoqr
2024-10-09 12:04:54 +08:00
parent 2e96dd8173
commit 220d0ff28a
36 changed files with 242 additions and 513 deletions
@@ -12,38 +12,32 @@ import com.cf.imes.framework.common.exception.ErrorCode;
*
* @author 晨丰科技
*/
public interface GlobalErrorCodeConstants {
public class GlobalErrorCodeConstants {
ErrorCode SUCCESS = new ErrorCode(0, "成功");
public static final ErrorCode SUCCESS = new ErrorCode(0, "成功");
// ========== 客户端错误段 ==========
ErrorCode BAD_REQUEST = new ErrorCode(400, "请求参数不正确");
ErrorCode UNAUTHORIZED = new ErrorCode(401, "账号未登录");
ErrorCode FORBIDDEN = new ErrorCode(403, "没有该操作权限");
ErrorCode NOT_FOUND = new ErrorCode(404, "请求未找到");
ErrorCode METHOD_NOT_ALLOWED = new ErrorCode(405, "请求方法不正确");
ErrorCode LOCKED = new ErrorCode(423, "请求失败,请稍后重试"); // 并发请求,不允许
ErrorCode TOO_MANY_REQUESTS = new ErrorCode(429, "请求过于频繁,请稍后重试");
ErrorCode DATA_SOURCE_CODE_NOT_FOUND = new ErrorCode(430, "未传递数据源标识");
ErrorCode ORGAN_ID_NOT_FOUND = new ErrorCode(431, "未传组织标识");
public static final ErrorCode BAD_REQUEST = new ErrorCode(400, "请求参数不正确");
public static final ErrorCode UNAUTHORIZED = new ErrorCode(401, "账号未登录");
public static final ErrorCode FORBIDDEN = new ErrorCode(403, "没有该操作权限");
public static final ErrorCode NOT_FOUND = new ErrorCode(404, "请求未找到");
public static final ErrorCode METHOD_NOT_ALLOWED = new ErrorCode(405, "请求方法不正确");
public static final ErrorCode LOCKED = new ErrorCode(423, "请求失败,请稍后重试"); // 并发请求,不允许
public static final ErrorCode TOO_MANY_REQUESTS = new ErrorCode(429, "请求过于频繁,请稍后重试");
// ========== 服务端错误段 ==========
ErrorCode INTERNAL_SERVER_ERROR = new ErrorCode(500, "系统异常,请联系客服处理");
ErrorCode NOT_IMPLEMENTED = new ErrorCode(501, "功能未实现/未开启");
ErrorCode ERROR_CONFIGURATION = new ErrorCode(502, "错误的配置项");
public static final ErrorCode INTERNAL_SERVER_ERROR = new ErrorCode(500, "系统异常,请联系客服处理");
public static final ErrorCode NOT_IMPLEMENTED = new ErrorCode(501, "功能未实现/未开启");
// ES文档更新失败
ErrorCode ES_ERROR_UPDATE = new ErrorCode(503, "数据异常,请勿点击过快,请稍等再试");
public static final ErrorCode ES_ERROR_UPDATE = new ErrorCode(503, "数据异常,请勿点击过快,请稍等再试");
// ES文档删除失败
ErrorCode ES_ERROR_DELETE = new ErrorCode(504, "数据异常,请勿点击过快,请稍等再试");
ErrorCode DATA_EXCEPTION_ERROR = new ErrorCode(505, "数据异常,请联系客服处理");
public static final ErrorCode ES_ERROR_DELETE = new ErrorCode(504, "数据异常,请勿点击过快,请稍等再试");
public static final ErrorCode DATA_EXCEPTION_ERROR = new ErrorCode(505, "数据异常,请联系客服处理");
// ========== 自定义错误段 ==========
ErrorCode REPEATED_REQUESTS = new ErrorCode(900, "重复请求,请稍后重试"); // 重复请求
ErrorCode DEMO_DENY = new ErrorCode(901, "演示模式,禁止写操作");
ErrorCode UNKNOWN = new ErrorCode(999, "未知错误");
public static final ErrorCode REPEATED_REQUESTS = new ErrorCode(900, "重复请求,请稍后重试"); // 重复请求
public static final ErrorCode DEMO_DENY = new ErrorCode(901, "演示模式,禁止写操作");
}
@@ -34,6 +34,8 @@ public class JsonUtils {
private static ObjectMapper objectMapper = new ObjectMapper();
private static final String JSON_PARSE_ERROR_NOTIFICATION = "json parse err,json:{}";
static {
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -74,7 +76,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, clazz);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -88,7 +90,7 @@ public class JsonUtils {
JsonNode pathNode = treeNode.path(path);
return objectMapper.readValue(pathNode.toString(), clazz);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -100,7 +102,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructType(type));
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -128,7 +130,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(bytes, clazz);
} catch (IOException e) {
log.error("json parse err,json:{}", bytes, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, bytes, e);
throw new RuntimeException(e);
}
}
@@ -137,7 +139,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, typeReference);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -149,7 +151,7 @@ public class JsonUtils {
try {
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -163,7 +165,7 @@ public class JsonUtils {
JsonNode pathNode = treeNode.path(path);
return objectMapper.readValue(pathNode.toString(), objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -172,7 +174,7 @@ public class JsonUtils {
try {
return objectMapper.readTree(text);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -181,7 +183,7 @@ public class JsonUtils {
try {
return objectMapper.readTree(text);
} catch (IOException e) {
log.error("json parse err,json:{}", text, e);
log.error(JSON_PARSE_ERROR_NOTIFICATION, text, e);
throw new RuntimeException(e);
}
}
@@ -246,23 +248,26 @@ public class JsonUtils {
//设置解压缩的输入数据。
inflater.setInput(decode);
final byte[] bytes = new byte[256];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
try {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256)) {
//finished() 如果已到达压缩数据流的末尾,则返回true。
while (!inflater.finished()) {
//将字节解压缩到指定的缓冲区中。
int length = inflater.inflate(bytes);
outputStream.write(bytes, 0, length);
}
return outputStream.toString();
} catch (DataFormatException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
//关闭解压缩器并丢弃任何未处理的输入。
inflater.end();
}
return outputStream.toString();
}