mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
修复流量倍率能为0的bug,我也没想到有人会设置0
This commit is contained in:
@@ -28,9 +28,9 @@ public class TunnelDto {
|
||||
private Integer flow;
|
||||
|
||||
// 流量倍率,默认为1.0
|
||||
@DecimalMin(value = "0.0", message = "流量倍率不能小于0.0")
|
||||
@DecimalMin(value = "0.0", inclusive = false, message = "流量倍率必须大于0.0")
|
||||
@DecimalMax(value = "100.0", message = "流量倍率不能大于100.0")
|
||||
private BigDecimal trafficRatio = new BigDecimal("1.0");
|
||||
private BigDecimal trafficRatio;
|
||||
|
||||
private String interfaceName;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class TunnelUpdateDto {
|
||||
private Integer flow;
|
||||
|
||||
// 流量倍率
|
||||
@DecimalMin(value = "0.0", message = "流量倍率不能小于0.0")
|
||||
@DecimalMin(value = "0.0", inclusive = false, message = "流量倍率必须大于0.0")
|
||||
@DecimalMax(value = "100.0", message = "流量倍率不能大于100.0")
|
||||
private BigDecimal trafficRatio;
|
||||
|
||||
|
||||
@@ -140,7 +140,6 @@ public class FlowController extends BaseController {
|
||||
public String uploadFlowData(@RequestBody String rawData, String secret) {
|
||||
// 1. 验证节点权限
|
||||
if (!isValidNode(secret)) {
|
||||
log.info("节点密钥验证失败==>" + secret);
|
||||
return SUCCESS_RESPONSE;
|
||||
}
|
||||
|
||||
@@ -150,7 +149,6 @@ public class FlowController extends BaseController {
|
||||
// 3. 解析为FlowDto列表
|
||||
FlowDto flowDataList = JSONObject.parseObject(decryptedData, FlowDto.class);
|
||||
if (Objects.equals(flowDataList.getN(), "web_api")) {
|
||||
System.out.println("不处理web_api==>" + flowDataList.getN());
|
||||
return SUCCESS_RESPONSE;
|
||||
}
|
||||
|
||||
@@ -180,17 +178,27 @@ public class FlowController extends BaseController {
|
||||
throw new IllegalArgumentException("数据不能为空");
|
||||
}
|
||||
|
||||
EncryptedMessage encryptedMessage = JSON.parseObject(rawData, EncryptedMessage.class);
|
||||
if (encryptedMessage.isEncrypted() && encryptedMessage.getData() != null) {
|
||||
// 获取或创建加密器
|
||||
AESCrypto crypto = getOrCreateCrypto(secret);
|
||||
if (crypto == null) {
|
||||
log.info("⚠️ 收到加密消息但无法创建解密器,使用原始数据");
|
||||
return rawData;
|
||||
try {
|
||||
// 尝试解析为加密消息格式
|
||||
EncryptedMessage encryptedMessage = JSON.parseObject(rawData, EncryptedMessage.class);
|
||||
|
||||
if (encryptedMessage.isEncrypted() && encryptedMessage.getData() != null) {
|
||||
// 获取或创建加密器
|
||||
AESCrypto crypto = getOrCreateCrypto(secret);
|
||||
if (crypto == null) {
|
||||
log.info("⚠️ 收到加密消息但无法创建解密器,使用原始数据");
|
||||
return rawData;
|
||||
}
|
||||
|
||||
// 解密数据
|
||||
String decryptedData = crypto.decryptString(encryptedMessage.getData());
|
||||
return decryptedData;
|
||||
}
|
||||
// 解密数据
|
||||
return crypto.decryptString(encryptedMessage.getData());
|
||||
} catch (Exception e) {
|
||||
// 解析失败,可能是非加密格式,直接返回原始数据
|
||||
log.info("数据未加密或解密失败,使用原始数据: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return rawData;
|
||||
}
|
||||
|
||||
@@ -229,7 +237,7 @@ public class FlowController extends BaseController {
|
||||
checkUserRelatedLimits(userId, name);
|
||||
checkUserTunnelRelatedLimits(userTunnelId, name, userId);
|
||||
}
|
||||
log.info("流量处理完成");
|
||||
|
||||
return SUCCESS_RESPONSE;
|
||||
}
|
||||
|
||||
@@ -340,8 +348,7 @@ public class FlowController extends BaseController {
|
||||
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD());
|
||||
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU());
|
||||
|
||||
boolean update = forwardService.update(null, updateWrapper);
|
||||
System.out.println(update);
|
||||
forwardService.update(null, updateWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,8 +361,7 @@ public class FlowController extends BaseController {
|
||||
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD());
|
||||
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU());
|
||||
|
||||
boolean update = userService.update(null, updateWrapper);
|
||||
System.out.println(update);
|
||||
userService.update(null, updateWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,8 +376,7 @@ public class FlowController extends BaseController {
|
||||
updateWrapper.eq("id", userTunnelId);
|
||||
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD());
|
||||
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU());
|
||||
boolean update = userTunnelService.update(null, updateWrapper);
|
||||
System.out.println(update);
|
||||
userTunnelService.update(null, updateWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user