修复流量倍率能为0的bug,我也没想到有人会设置0

This commit is contained in:
qaq
2025-08-27 16:42:28 +08:00
parent afdafe3593
commit 414a3a2c91
4 changed files with 28 additions and 23 deletions
@@ -28,9 +28,9 @@ public class TunnelDto {
private Integer flow; private Integer flow;
// 流量倍率,默认为1.0 // 流量倍率,默认为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") @DecimalMax(value = "100.0", message = "流量倍率不能大于100.0")
private BigDecimal trafficRatio = new BigDecimal("1.0"); private BigDecimal trafficRatio;
private String interfaceName; private String interfaceName;
@@ -24,7 +24,7 @@ public class TunnelUpdateDto {
private Integer flow; 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") @DecimalMax(value = "100.0", message = "流量倍率不能大于100.0")
private BigDecimal trafficRatio; private BigDecimal trafficRatio;
@@ -140,7 +140,6 @@ public class FlowController extends BaseController {
public String uploadFlowData(@RequestBody String rawData, String secret) { public String uploadFlowData(@RequestBody String rawData, String secret) {
// 1. 验证节点权限 // 1. 验证节点权限
if (!isValidNode(secret)) { if (!isValidNode(secret)) {
log.info("节点密钥验证失败==>" + secret);
return SUCCESS_RESPONSE; return SUCCESS_RESPONSE;
} }
@@ -150,7 +149,6 @@ public class FlowController extends BaseController {
// 3. 解析为FlowDto列表 // 3. 解析为FlowDto列表
FlowDto flowDataList = JSONObject.parseObject(decryptedData, FlowDto.class); FlowDto flowDataList = JSONObject.parseObject(decryptedData, FlowDto.class);
if (Objects.equals(flowDataList.getN(), "web_api")) { if (Objects.equals(flowDataList.getN(), "web_api")) {
System.out.println("不处理web_api==>" + flowDataList.getN());
return SUCCESS_RESPONSE; return SUCCESS_RESPONSE;
} }
@@ -180,17 +178,27 @@ public class FlowController extends BaseController {
throw new IllegalArgumentException("数据不能为空"); throw new IllegalArgumentException("数据不能为空");
} }
EncryptedMessage encryptedMessage = JSON.parseObject(rawData, EncryptedMessage.class); try {
if (encryptedMessage.isEncrypted() && encryptedMessage.getData() != null) { // 尝试解析为加密消息格式
// 获取或创建加密器 EncryptedMessage encryptedMessage = JSON.parseObject(rawData, EncryptedMessage.class);
AESCrypto crypto = getOrCreateCrypto(secret);
if (crypto == null) { if (encryptedMessage.isEncrypted() && encryptedMessage.getData() != null) {
log.info("⚠️ 收到加密消息但无法创建解密器,使用原始数据"); // 获取或创建加密器
return rawData; AESCrypto crypto = getOrCreateCrypto(secret);
if (crypto == null) {
log.info("⚠️ 收到加密消息但无法创建解密器,使用原始数据");
return rawData;
}
// 解密数据
String decryptedData = crypto.decryptString(encryptedMessage.getData());
return decryptedData;
} }
// 解密数据 } catch (Exception e) {
return crypto.decryptString(encryptedMessage.getData()); // 解析失败,可能是非加密格式,直接返回原始数据
log.info("数据未加密或解密失败,使用原始数据: {}", e.getMessage());
} }
return rawData; return rawData;
} }
@@ -229,7 +237,7 @@ public class FlowController extends BaseController {
checkUserRelatedLimits(userId, name); checkUserRelatedLimits(userId, name);
checkUserTunnelRelatedLimits(userTunnelId, name, userId); checkUserTunnelRelatedLimits(userTunnelId, name, userId);
} }
log.info("流量处理完成");
return SUCCESS_RESPONSE; return SUCCESS_RESPONSE;
} }
@@ -340,8 +348,7 @@ public class FlowController extends BaseController {
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD()); updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD());
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU()); updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU());
boolean update = forwardService.update(null, updateWrapper); forwardService.update(null, updateWrapper);
System.out.println(update);
} }
} }
@@ -354,8 +361,7 @@ public class FlowController extends BaseController {
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD()); updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD());
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU()); updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU());
boolean update = userService.update(null, updateWrapper); userService.update(null, updateWrapper);
System.out.println(update);
} }
} }
@@ -370,8 +376,7 @@ public class FlowController extends BaseController {
updateWrapper.eq("id", userTunnelId); updateWrapper.eq("id", userTunnelId);
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD()); updateWrapper.setSql("in_flow = in_flow + " + flowStats.getD());
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU()); updateWrapper.setSql("out_flow = out_flow + " + flowStats.getU());
boolean update = userTunnelService.update(null, updateWrapper); userTunnelService.update(null, updateWrapper);
System.out.println(update);
} }
} }
@@ -35,8 +35,8 @@ server:
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:/mapper/**Mapper.xml mapper-locations: classpath*:/mapper/**Mapper.xml
configuration: # configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
jwt-secret: ${JWT_SECRET} jwt-secret: ${JWT_SECRET}
log-dir: ${LOG_DIR} log-dir: ${LOG_DIR}