From 1bda9524add969e315d870f284046ecf1097f956 Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期日, 24 八月 2025 18:01:25 +0800
Subject: [PATCH] 修改

---
 src/dell_targets/Dell_tag.java |  468 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 464 insertions(+), 4 deletions(-)

diff --git a/src/dell_targets/Dell_tag.java b/src/dell_targets/Dell_tag.java
index 1d74352..bad10aa 100644
--- a/src/dell_targets/Dell_tag.java
+++ b/src/dell_targets/Dell_tag.java
@@ -4,15 +4,24 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 public class Dell_tag {
-	static List<LocationTag> locationTags;
+	public static List<LocationTag> locationTags;
+	private static ConcurrentHashMap<String, LocationTag> tagMap; // 设备ID->标签对象的映射
 	public static List<LocationTag> getlocationTags() throws SQLException{
-		List<LocationTag> locationTags = new ArrayList<>();        
+		List<LocationTag> locationTags = new ArrayList<>();    
+		tagMap = new ConcurrentHashMap<>(); // 初始化映射
 		ResultSet rs =DBConnector.queryTableData("location_tag");
+		 if (rs == null) {
+		        // 说明底层拿不到数据,直接抛异常或打印日志
+		        throw new SQLException("DBConnector.queryTableData returned null, "
+		                             + "please check database connection & SQL.");
+		    }
 		while (rs.next()) {
 			LocationTag locationTag = new LocationTag();
-			locationTag.setId((int) rs.getLong("id"));			
+			locationTag.setId((int) rs.getLong("id"));
 			locationTag.setDeviceNumber(rs.getString("device_id"));
 			locationTag.setDeviceName(rs.getString("device_name"));
 			locationTag.setDeviceVersion(rs.getString("device_version"));
@@ -81,7 +90,11 @@
 			locationTag.setMotionlessEndTime(rs.getString("stationary_end_time"));
 			locationTag.setMotionlessDuration(rs.getString("stationary_duration"));
 			locationTag.setValidSatelliteSignal(rs.getString("tag_valid_satellite_signal"));
-			locationTag.setCompany(rs.getString("company"));
+			String company=rs.getString("company");
+			if (company == null || company.trim().isEmpty() || company.equals("-1") ) {
+			    company = "Unknown";
+			}
+			locationTag.setCompany(company);
 			locationTag.setSleepTime(rs.getString("sleep_time"));
 			locationTag.setVibrationTime(rs.getString("vibration_time"));
 			locationTag.setFrequency(rs.getString("frequency"));
@@ -97,7 +110,259 @@
 			locationTag.setInteractionType(rs.getString("Interaction_Type"));
 			locationTag.setIpAddress(rs.getString("ipAddress"));
 			locationTag.setIpPort(rs.getString("Interaction_Type"));
+
+			locationTag.setId((int) rs.getLong("id"));
+
+			String deviceNumber = rs.getString("device_id");
+			if (deviceNumber == null || deviceNumber.trim().isEmpty() || deviceNumber.equals("-1")) {
+			    deviceNumber = "Unknown";
+			}
+			locationTag.setDeviceNumber(deviceNumber);
+
+			String deviceName = rs.getString("device_name");
+			if (deviceName == null || deviceName.trim().isEmpty() || deviceName.equals("-1")) {
+			    deviceName = "Unknown";
+			}
+			locationTag.setDeviceName(deviceName);
+
+			String deviceVersion = rs.getString("device_version");
+			if (deviceVersion == null || deviceVersion.trim().isEmpty() || deviceVersion.equals("-1")) {
+			    deviceVersion = "Unknown";
+			}
+			locationTag.setDeviceVersion(deviceVersion);
+
+			String deviceCardNumber = rs.getString("device_card_number");
+			if (deviceCardNumber == null || deviceCardNumber.trim().isEmpty() || deviceCardNumber.equals("-1")) {
+			    deviceCardNumber = "Unknown";
+			}
+			locationTag.setDeviceCardNumber(deviceCardNumber);
+
+			String deviceType = rs.getString("device_type");
+			if (deviceType == null || deviceType.trim().isEmpty() || deviceType.equals("-1")) {
+			    deviceType = "Unknown";
+			}
+			locationTag.setDeviceType(deviceType);
+
+			String team = rs.getString("affiliated_class");
+			if (team == null || team.trim().isEmpty() || team.equals("-1")) {
+			    team = "Unknown";
+			}
+			locationTag.setTeam(team);
+
+			String group = rs.getString("affiliated_group");
+			if (group == null || group.trim().isEmpty() || group.equals("-1")) {
+			    group = "Unknown";
+			}
+			locationTag.setGroup(group);
+
+			String department = rs.getString("department");
+			if (department == null || department.trim().isEmpty() || department.equals("-1")) {
+			    department = "Unknown";
+			}
+			locationTag.setDepartment(department);
+
+			String iconAddress = rs.getString("icon_url");
+			if (iconAddress == null || iconAddress.trim().isEmpty() || iconAddress.equals("-1")) {
+			    iconAddress = "Unknown";
+			}
+			locationTag.setIconAddress(iconAddress);
+
+			String gender = rs.getString("gender");
+			if (gender == null || gender.trim().isEmpty() || gender.equals("-1")) {
+			    gender = "Unknown";
+			}
+			locationTag.setGender(gender);
+
+			String ethnicity = rs.getString("ethnic_group");
+			if (ethnicity == null || ethnicity.trim().isEmpty() || ethnicity.equals("-1")) {
+			    ethnicity = "Unknown";
+			}
+			locationTag.setEthnicity(ethnicity);
+
+			String communicationAddress = rs.getString("communication_address");
+			if (communicationAddress == null || communicationAddress.trim().isEmpty() || communicationAddress.equals("-1")) {
+			    communicationAddress = "Unknown";
+			}
+			locationTag.setCommunicationAddress(communicationAddress);
+
+			String boundPhone = rs.getString("bound_phone");
+			if (boundPhone == null || boundPhone.trim().isEmpty() || boundPhone.equals("-1")) {
+			    boundPhone = "Unknown";
+			}
+			locationTag.setBoundPhone(boundPhone);
+
+			String idNumber = rs.getString("id_card_number");
+			if (idNumber == null || idNumber.trim().isEmpty() || idNumber.equals("-1")) {
+			    idNumber = "Unknown";
+			}
+			locationTag.setIdNumber(idNumber);
+
+			String position = rs.getString("personnel_position");
+			if (position == null || position.trim().isEmpty() || position.equals("-1")) {
+			    position = "Unknown";
+			}
+			locationTag.setPosition(position);
+
+			String boundPlateNumber = rs.getString("bound_license_plate");
+			if (boundPlateNumber == null || boundPlateNumber.trim().isEmpty() || boundPlateNumber.equals("-1")) {
+			    boundPlateNumber = "Unknown";
+			}
+			locationTag.setBoundPlateNumber(boundPlateNumber);
+
+			String faceAddress = rs.getString("face_image_url");
+			if (faceAddress == null || faceAddress.trim().isEmpty() || faceAddress.equals("-1")) {
+			    faceAddress = "Unknown";
+			}
+			locationTag.setFaceAddress(faceAddress);
+
+			String heartRate = rs.getString("heart_rate");
+			if (heartRate == null || heartRate.trim().isEmpty() || heartRate.equals("-1")) {
+			    heartRate = "Unknown";
+			}
+			locationTag.setHeartRate(heartRate);
+
+			String bloodPressure = rs.getString("blood_pressure");
+			if (bloodPressure == null || bloodPressure.trim().isEmpty() || bloodPressure.equals("-1")) {
+			    bloodPressure = "Unknown";
+			}
+			locationTag.setBloodPressure(bloodPressure);
+
+			String bloodOxygen = rs.getString("blood_oxygen");
+			if (bloodOxygen == null || bloodOxygen.trim().isEmpty() || bloodOxygen.equals("-1")) {
+			    bloodOxygen = "Unknown";
+			}
+			locationTag.setBloodOxygen(bloodOxygen);
+
+			String temperature = rs.getString("body_temperature");
+			if (temperature == null || temperature.trim().isEmpty() || temperature.equals("-1")) {
+			    temperature = "Unknown";
+			}
+			locationTag.setTemperature(temperature);
+
+			String sosStatus = rs.getString("sos_status");
+			if (sosStatus == null || sosStatus.trim().isEmpty() || sosStatus.equals("-1")) {
+			    sosStatus = "Unknown";
+			}
+			locationTag.setSosStatus(sosStatus);
+
+			String motionStatus = rs.getString("motion_status");
+			if (motionStatus == null || motionStatus.trim().isEmpty() || motionStatus.equals("-1")) {
+			    motionStatus = "Unknown";
+			}
+			locationTag.setMotionStatus(motionStatus);
+
+			String onlineStatus = rs.getString("online_status");
+			if (onlineStatus == null || onlineStatus.trim().isEmpty() || onlineStatus.equals("-1")) {
+			    onlineStatus = "Unknown";
+			}
+			locationTag.setOnlineStatus(onlineStatus);
+
+			String searchStatus = rs.getString("search_status");
+			if (searchStatus == null || searchStatus.trim().isEmpty() || searchStatus.equals("-1")) {
+			    searchStatus = "Unknown";
+			}
+			locationTag.setSearchStatus(searchStatus);
+
+			String batteryStatus = rs.getString("battery_status");
+			if (batteryStatus == null || batteryStatus.trim().isEmpty() || batteryStatus.equals("-1")) {
+			    batteryStatus = "Unknown";
+			}
+			locationTag.setBatteryStatus(batteryStatus);
+
+			String deviceBattery = rs.getString("device_battery");
+			if (deviceBattery == null || deviceBattery.trim().isEmpty() || deviceBattery.equals("-1")) {
+			    deviceBattery = "Unknown";
+			}
+			locationTag.setDeviceBattery(deviceBattery);
+
+			String removalStatus = rs.getString("removal_status");
+			if (removalStatus == null || removalStatus.trim().isEmpty() || removalStatus.equals("-1")) {
+			    removalStatus = "Unknown";
+			}
+			locationTag.setRemovalStatus(removalStatus);
+
+			String collisionStatus = rs.getString("collision_status");
+			if (collisionStatus == null || collisionStatus.trim().isEmpty() || collisionStatus.equals("-1")) {
+			    collisionStatus = "Unknown";
+			}
+			locationTag.setCollisionStatus(collisionStatus);
+
+			String elevationStatus = rs.getString("climbing_status");
+			if (elevationStatus == null || elevationStatus.trim().isEmpty() || elevationStatus.equals("-1")) {
+			    elevationStatus = "Unknown";
+			}
+			locationTag.setElevationStatus(elevationStatus);
+
+			String gatheringCount = rs.getString("gathering_count");
+			if (gatheringCount == null || gatheringCount.trim().isEmpty() || gatheringCount.equals("-1")) {
+			    gatheringCount = "Unknown";
+			}
+			locationTag.setGatheringCount(gatheringCount);
+
+			String proximityAlarm = rs.getString("proximity_alarm");
+			if (proximityAlarm == null || proximityAlarm.trim().isEmpty() || proximityAlarm.equals("-1")) {
+			    proximityAlarm = "Unknown";
+			}
+			locationTag.setProximityAlarm(proximityAlarm);
+
+			String area = rs.getString("current_area");
+			if (area == null || area.trim().isEmpty() || area.equals("-1")) {
+			    area = "Unknown";
+			}
+			locationTag.setArea(area);
+
+			String xCoordinate = rs.getString("x_coordinate");
+			if (xCoordinate == null || xCoordinate.trim().isEmpty() || xCoordinate.equals("-1")) {
+			    xCoordinate = "Unknown";
+			}
+			locationTag.setXCoordinate(xCoordinate);
+
+			String yCoordinate = rs.getString("y_coordinate");
+			if (yCoordinate == null || yCoordinate.trim().isEmpty() || yCoordinate.equals("-1")) {
+			    yCoordinate = "Unknown";
+			}
+			locationTag.setYCoordinate(yCoordinate);
+
+			String zCoordinate = rs.getString("z_coordinate");
+			if (zCoordinate == null || zCoordinate.trim().isEmpty() || zCoordinate.equals("-1")) {
+			    zCoordinate = "Unknown";
+			}
+			locationTag.setZCoordinate(zCoordinate);
+
+			String floor = rs.getString("current_floor");
+			if (floor == null || floor.trim().isEmpty() || floor.equals("-1")) {
+			    floor = "Unknown";
+			}
+			locationTag.setFloor(floor);
+
+			String speed = rs.getString("movement_speed");
+			if (speed == null || speed.trim().isEmpty() || speed.equals("-1")) {
+			    speed = "Unknown";
+			}
+			locationTag.setSpeed(speed);
+
+			String locationSource = rs.getString("position_source");
+			if (locationSource == null || locationSource.trim().isEmpty() || locationSource.equals("-1")) {
+			    locationSource = "Unknown";
+			}
+			locationTag.setLocationSource(locationSource);
+
+			String lastUwbSignalTime = rs.getString("last_uwb_signal_time");
+			if (lastUwbSignalTime == null || lastUwbSignalTime.trim().isEmpty() || lastUwbSignalTime.equals("-1")) {
+			    lastUwbSignalTime = "Unknown";
+			}
+			locationTag.setLastUwbSignalTime(lastUwbSignalTime);
+
+			String lastSatelliteSignalTime = rs.getString("last_satellite_signal_time");
+			if (lastSatelliteSignalTime == null || lastSatelliteSignalTime.trim().isEmpty() || lastSatelliteSignalTime.equals("-1")) {
+			    lastSatelliteSignalTime = "Unknown";
+			}
+			
+			locationTag.setAutoUpgraded("Unknown");
+			locationTag.setIsSatelliteDevice("-1");
+			locationTag.setRTKsource("Unknown");
 			locationTags.add(locationTag);
+			tagMap.put(locationTag.getDeviceNumber(), locationTag); // 添加到映射
 		}
 		return locationTags;
 	}
@@ -119,6 +384,120 @@
         DBConnector.executeUpdate(sql, deviceId);
     }
     
+    /**
+     * 根据设备ID高效修改属性值
+     * @param deviceId 设备ID(device_id)
+     * @param propertyName 属性名(需与setter方法匹配)
+     * @param value 新属性值
+     */
+    public static void updateLocationTagProperty(String deviceId, String propertyName, String value) {
+        LocationTag tag = tagMap.get(deviceId);
+        if (tag == null) return; // 标签不存在则忽略
+        
+        // 根据属性名调用对应setter
+        switch (propertyName) {
+            case "id": tag.setId(Integer.parseInt(value)); break;
+            case "deviceNumber": tag.setDeviceNumber(value); break;
+            case "deviceName": tag.setDeviceName(value); break;
+            case "deviceVersion": tag.setDeviceVersion(value); break;
+            case "deviceCardNumber": tag.setDeviceCardNumber(value); break;
+            case "deviceType": tag.setDeviceType(value); break;
+            case "team": tag.setTeam(value); break;
+            case "group": tag.setGroup(value); break;
+            case "department": tag.setDepartment(value); break;
+            case "iconAddress": tag.setIconAddress(value); break;
+            case "gender": tag.setGender(value); break;
+            case "ethnicity": tag.setEthnicity(value); break;
+            case "communicationAddress": tag.setCommunicationAddress(value); break;
+            case "boundPhone": tag.setBoundPhone(value); break;
+            case "idNumber": tag.setIdNumber(value); break;
+            case "position": tag.setPosition(value); break;
+            case "boundPlateNumber": tag.setBoundPlateNumber(value); break;
+            case "faceAddress": tag.setFaceAddress(value); break;
+            case "heartRate": tag.setHeartRate(value); break;
+            case "bloodPressure": tag.setBloodPressure(value); break;
+            case "bloodOxygen": tag.setBloodOxygen(value); break;
+            case "temperature": tag.setTemperature(value); break;
+            case "sosStatus": tag.setSosStatus(value); break;
+            case "motionStatus": tag.setMotionStatus(value); break;
+            case "onlineStatus": tag.setOnlineStatus(value); break;
+            case "searchStatus": tag.setSearchStatus(value); break;
+            case "batteryStatus": tag.setBatteryStatus(value); break;
+            case "deviceBattery": tag.setDeviceBattery(value); break;
+            case "removalStatus": tag.setRemovalStatus(value); break;
+            case "collisionStatus": tag.setCollisionStatus(value); break;
+            case "elevationStatus": tag.setElevationStatus(value); break;
+            case "gatheringCount": tag.setGatheringCount(value); break;
+            case "proximityAlarm": tag.setProximityAlarm(value); break;
+            case "area": tag.setArea(value); break;
+            case "xCoordinate": tag.setXCoordinate(value); break;
+            case "yCoordinate": tag.setYCoordinate(value); break;
+            case "zCoordinate": tag.setZCoordinate(value); break;
+            case "floor": tag.setFloor(value); break;
+            case "speed": tag.setSpeed(value); break;
+            case "locationSource": tag.setLocationSource(value); break;
+            case "lastUwbSignalTime": tag.setLastUwbSignalTime(value); break;
+            case "lastSatelliteSignalTime": tag.setLastSatelliteSignalTime(value); break;
+            case "uwbTimeSlot": tag.setUwbTimeSlot(value); break;
+            case "latestRangingSeq": tag.setLatestRangingSeq(value); break;
+            case "latestRangingBaseId": tag.setLatestRangingBaseId(value); break;
+            case "latestRangingDistance": tag.setLatestRangingDistance(value); break;
+            case "latestRangingBaseCount": tag.setLatestRangingBaseCount(value); break;
+            case "latestRangingSignalStrength": tag.setLatestRangingSignalStrength(value); break;
+            case "utcTime": tag.setUtcTime(value); break;
+            case "latitude": tag.setLatitude(value); break;
+            case "longitude": tag.setLongitude(value); break;
+            case "satelliteQuality": tag.setSatelliteQuality(value); break;
+            case "hdop": tag.setHdop(value); break;
+            case "satelliteCount": tag.setSatelliteCount(value); break;
+            case "altitude": tag.setAltitude(value); break;
+            case "differentialTime": tag.setDifferentialTime(value); break;
+            case "geoidHeight": tag.setGeoidHeight(value); break;
+            case "satelliteSpeed": tag.setSatelliteSpeed(value); break;
+            case "lastBarometricValue": tag.setLastBarometricValue(value); break;
+            case "recentCoordinates": tag.setRecentCoordinates(value); break;
+            case "recentBarometricValues": tag.setRecentBarometricValues(value); break;
+            case "offlineTime": tag.setOfflineTime(value); break;
+            case "onlineTime": tag.setOnlineTime(value); break;
+            case "offlineDuration": tag.setOfflineDuration(value); break;
+            case "onlineDuration": tag.setOnlineDuration(value); break;
+            case "motionlessStartTime": tag.setMotionlessStartTime(value); break;
+            case "motionlessEndTime": tag.setMotionlessEndTime(value); break;
+            case "motionlessDuration": tag.setMotionlessDuration(value); break;
+            case "validSatelliteSignal": tag.setValidSatelliteSignal(value); break;
+            case "company": tag.setCompany(value); break;
+            case "sleepTime": tag.setSleepTime(value); break;
+            case "vibrationTime": tag.setVibrationTime(value); break;
+            case "frequency": tag.setFrequency(value); break;
+            case "motionlessTime": tag.setMotionlessTime(value); break;
+            case "accelerationValue": tag.setAccelerationValue(value); break;
+            case "imuTime": tag.setImuTime(value); break;
+            case "reserved1": tag.setReserved1(value); break;
+            case "reserved2": tag.setReserved2(value); break;
+            case "reserved3": tag.setReserved3(value); break;
+            case "reserved4": tag.setReserved4(value); break;
+            case "reserved5": tag.setReserved5(value); break;
+            case "ipAndPort": tag.setIpAndPort(value); break;
+            case "interactionType": tag.setInteractionType(value); break;
+            case "ipAddress": tag.setIpAddress(value); break;
+            case "ipPort": tag.setIpPort(value); break;
+            case "gnGgaDataTime": tag.setGnGgaDataTime(value); break;
+            case "isSatelliteDevice": tag.setIsSatelliteDevice(value);break;
+            case "RTKsource": tag.setRTKsource(value);break;
+            default: 
+                throw new IllegalArgumentException("无效属性: " + propertyName);
+        }
+    }
+    
+    /**
+     * 根据设备ID获取标签对象(高效访问)
+     * @param deviceId 设备ID
+     * @return 标签对象(不存在返回null)
+     */
+    public static LocationTag getTagByDeviceId(String deviceId) {
+        return tagMap.get(deviceId);
+    }
+    
     //获取所有的tagid
     public static List<String> getAlldeviceIds() {
         List<String> types = new ArrayList<>();
@@ -134,4 +513,85 @@
         }
         return types;
     }
+    
+    /**
+     * 获取所有在线状态(onlineStatus=1)的设备(高效内存操作)
+     * @return 不可修改的LocationTag集合(避免外部修改缓存)
+     */
+    public static List<LocationTag> getOnlineLocationTags() {
+        if (tagMap == null || tagMap.isEmpty()) {
+            return Collections.emptyList(); // 缓存为空时返回空集合
+        }
+
+        List<LocationTag> onlineTags = new ArrayList<>();
+        for (LocationTag tag : tagMap.values()) {
+            if ("1".equals(tag.getOnlineStatus())) { // 字符串比较避免NPE
+                onlineTags.add(tag);
+            }
+        }
+        return Collections.unmodifiableList(onlineTags); // 返回不可变集合
+    }
+    
+    /**
+     * 快速获取LocationTag对象的总数(使用内存缓存提高性能)
+     * @return LocationTag对象的总数
+     */
+    public static int getLocationTagCount() {
+        if (tagMap == null) {
+            synchronized (Dell_tag.class) {
+                if (tagMap == null) {
+                    try {
+                        getlocationTags(); // 初始化缓存
+                    } catch (SQLException e) {
+                        e.printStackTrace();
+                        return 0; // 初始化失败返回0
+                    }
+                }
+            }
+        }
+        return tagMap.size();
+    }
+    
+    /**
+     * 根据单个属性查询LocationTag对象
+     * @param propertyName 属性名(deviceNumber/deviceVersion/company)
+     * @param propertyValue 属性值
+     * @return 满足条件的LocationTag对象列表
+     */
+    public static List<LocationTag> getLocationTagsByProperty(String propertyName, String propertyValue) {
+        if (tagMap == null || tagMap.isEmpty()) {
+            try {
+                getlocationTags(); // 初始化数据
+            } catch (SQLException e) {
+                e.printStackTrace();
+                return Collections.emptyList();
+            }
+        }
+        
+        List<LocationTag> result = new ArrayList<>();
+        
+        for (LocationTag tag : tagMap.values()) {
+            switch (propertyName) {
+                case "deviceNumber":
+                    if (propertyValue.equals(tag.getDeviceNumber())) {
+                        result.add(tag);
+                    }
+                    break;
+                case "deviceVersion":
+                    if (propertyValue.equals(tag.getDeviceVersion())) {
+                        result.add(tag);
+                    }
+                    break;
+                case "company":
+                    if (propertyValue.equals(tag.getCompany())) {
+                        result.add(tag);
+                    }
+                    break;
+                default:
+                    throw new IllegalArgumentException("不支持的属性: " + propertyName);
+            }
+        }
+        
+        return result;
+    }
 } 
\ No newline at end of file

--
Gitblit v1.9.3