省厅位置汇聚处理redis数据入在线库提示唯一索引报错问题

stwzhj
luyya 2025-11-21 11:21:53 +08:00
parent 659a894d67
commit 61b89e502b
2 changed files with 5 additions and 2 deletions

View File

@ -45,7 +45,10 @@ public class DeviceRedisServiceImpl implements IDeviceRedisService {
// 在插入前对数据进行去重(基于唯一约束)
Map<String, DeviceRedis> uniqueMap = new LinkedHashMap<>();
for (DeviceRedis device : list) {
String key = device.getDeviceCode() + "|" +
if ("99".equals(device.getDeviceType())){
continue;
}
String key = device.getDeviceCode() + "|" + device.getDeviceType() + "|" +
device.getInfoSource();
// 保留最后一次出现的记录(根据业务需求调整)
uniqueMap.put(key, device);

View File

@ -20,7 +20,7 @@
#{entity.deviceCode},#{entity.deviceType},#{entity.online},#{entity.zzjgdm},#{entity.gpsTime},#{entity.infoSource}
)
</foreach>
ON conflict(device_code,info_source) do update set
ON conflict(device_code,device_type,info_source) do update set
(online,zzjgdm,gps_time) =(EXCLUDED.online,EXCLUDED.zzjgdm,EXCLUDED.gps_time)
</insert>