fix:给设备充值,去掉设备归属用户限制,允许给子账号充值。
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.intc.common.core.exception.ServiceException;
|
import com.intc.common.core.exception.ServiceException;
|
||||||
|
import com.intc.common.tenant.helper.TenantHelper;
|
||||||
import com.intc.fishery.constant.DefineDeviceWarnCode;
|
import com.intc.fishery.constant.DefineDeviceWarnCode;
|
||||||
import com.intc.fishery.domain.Device;
|
import com.intc.fishery.domain.Device;
|
||||||
import com.intc.fishery.domain.PayDevice;
|
import com.intc.fishery.domain.PayDevice;
|
||||||
@@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付订单业务服务实现
|
* 支付订单业务服务实现
|
||||||
@@ -54,14 +56,50 @@ public class PayOrderBusinessServiceImpl implements PayOrderBusinessService {
|
|||||||
throw new ServiceException("支付选项不存在");
|
throw new ServiceException("支付选项不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 验证设备归属
|
// 2. 去重设备ID(防止前端传入重复ID导致 size 不匹配)
|
||||||
List<Device> devices = deviceMapper.selectList(
|
List<Long> uniqueDeviceIds = deviceIds.stream().distinct().collect(Collectors.toList());
|
||||||
|
if (uniqueDeviceIds.size() != deviceIds.size()) {
|
||||||
|
log.warn("设备ID列表存在重复,原始数量={},去重后数量={}", deviceIds.size(), uniqueDeviceIds.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 验证设备归属(忽略租户过滤,因为设备可能由IOT模块写入,租户ID可能不一致)
|
||||||
|
List<Device> devices = TenantHelper.ignore(() ->
|
||||||
|
deviceMapper.selectList(
|
||||||
new LambdaQueryWrapper<Device>()
|
new LambdaQueryWrapper<Device>()
|
||||||
.in(Device::getId, deviceIds)
|
.in(Device::getId, uniqueDeviceIds)
|
||||||
.eq(Device::getUserId, userId)
|
// .eq(Device::getUserId, userId)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (devices == null || devices.size() != deviceIds.size()) {
|
if (devices == null || devices.size() != uniqueDeviceIds.size()) {
|
||||||
|
// 诊断日志:定位具体缺失的设备
|
||||||
|
Set<Long> foundIds = devices != null
|
||||||
|
? devices.stream().map(Device::getId).collect(Collectors.toSet())
|
||||||
|
: Collections.emptySet();
|
||||||
|
List<Long> missingIds = uniqueDeviceIds.stream()
|
||||||
|
.filter(id -> !foundIds.contains(id))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.error("设备归属验证失败: userId={}, 请求设备数={}, 找到设备数={}, 缺失设备ID={}",
|
||||||
|
userId, uniqueDeviceIds.size(), devices != null ? devices.size() : 0, missingIds);
|
||||||
|
|
||||||
|
// 进一步诊断:检查缺失设备是否存在于数据库(不限制userId)
|
||||||
|
if (!missingIds.isEmpty()) {
|
||||||
|
List<Device> existDevices = TenantHelper.ignore(() ->
|
||||||
|
deviceMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<Device>()
|
||||||
|
.in(Device::getId, missingIds)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (existDevices != null && !existDevices.isEmpty()) {
|
||||||
|
for (Device d : existDevices) {
|
||||||
|
log.error("设备存在但不属于当前用户: deviceId={}, deviceUserId={}, currentUserId={}, tenantId={}",
|
||||||
|
d.getId(), d.getUserId(), userId, d.getTenantId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("设备在数据库中不存在: missingIds={}", missingIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw new ServiceException("部分设备不存在或无权限操作");
|
throw new ServiceException("部分设备不存在或无权限操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user