package dell_targets; import databases.DBConnector; import targets.LocationTag; 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 { public static List locationTags; private static ConcurrentHashMap tagMap; // É豸ID->±êÇ©¶ÔÏóµÄÓ³Éä public static List getlocationTags() throws SQLException{ List 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.setDeviceNumber(rs.getString("device_id")); locationTag.setDeviceName(rs.getString("device_name")); locationTag.setDeviceVersion(rs.getString("device_version")); locationTag.setDeviceCardNumber(rs.getString("device_card_number")); locationTag.setDeviceType(rs.getString("device_type")); locationTag.setTeam(rs.getString("affiliated_class")); locationTag.setGroup(rs.getString("affiliated_group")); locationTag.setDepartment(rs.getString("department")); locationTag.setIconAddress(rs.getString("icon_url")); locationTag.setGender(rs.getString("gender")); locationTag.setEthnicity(rs.getString("ethnic_group")); locationTag.setCommunicationAddress(rs.getString("communication_address")); locationTag.setBoundPhone(rs.getString("bound_phone")); locationTag.setIdNumber(rs.getString("id_card_number")); locationTag.setPosition(rs.getString("personnel_position")); locationTag.setBoundPlateNumber(rs.getString("bound_license_plate")); locationTag.setFaceAddress(rs.getString("face_image_url")); locationTag.setHeartRate(rs.getString("heart_rate")); locationTag.setBloodPressure(rs.getString("blood_pressure")); locationTag.setBloodOxygen(rs.getString("blood_oxygen")); locationTag.setTemperature(rs.getString("body_temperature")); locationTag.setSosStatus(rs.getString("sos_status")); locationTag.setMotionStatus(rs.getString("motion_status")); locationTag.setOnlineStatus(rs.getString("online_status")); locationTag.setSearchStatus(rs.getString("search_status")); locationTag.setBatteryStatus(rs.getString("battery_status")); locationTag.setDeviceBattery(rs.getString("device_battery")); locationTag.setRemovalStatus(rs.getString("removal_status")); locationTag.setCollisionStatus(rs.getString("collision_status")); locationTag.setElevationStatus(rs.getString("climbing_status")); locationTag.setGatheringCount(rs.getString("gathering_count")); locationTag.setProximityAlarm(rs.getString("proximity_alarm")); locationTag.setArea(rs.getString("current_area")); locationTag.setXCoordinate(rs.getString("x_coordinate")); locationTag.setYCoordinate(rs.getString("y_coordinate")); locationTag.setZCoordinate(rs.getString("z_coordinate")); locationTag.setFloor(rs.getString("current_floor")); locationTag.setSpeed(rs.getString("movement_speed")); locationTag.setLocationSource(rs.getString("position_source")); locationTag.setLastUwbSignalTime(rs.getString("last_uwb_signal_time")); locationTag.setLastSatelliteSignalTime(rs.getString("last_satellite_signal_time")); locationTag.setUwbTimeSlot(rs.getString("uwb_time_slot")); locationTag.setLatestRangingSeq(rs.getString("latest_ranging_packet_sequence")); locationTag.setLatestRangingBaseId(rs.getString("latest_ranging_base_station_id")); locationTag.setLatestRangingDistance(rs.getString("latest_ranging_base_station_distance")); locationTag.setLatestRangingBaseCount(rs.getString("latest_ranging_uwb_base_station_count")); locationTag.setLatestRangingSignalStrength(rs.getString("latest_ranging_base_station_signal_strength")); locationTag.setUtcTime(rs.getString("utc_times")); locationTag.setLatitude(rs.getString("latitude")); locationTag.setLongitude(rs.getString("longitude")); locationTag.setSatelliteQuality(rs.getString("satellite_positioning_quality")); locationTag.setHdop(rs.getString("hdop")); locationTag.setSatelliteCount(rs.getString("satellite_count")); locationTag.setAltitude(rs.getString("altitude")); locationTag.setDifferentialTime(rs.getString("differential_time")); locationTag.setGeoidHeight(rs.getString("geoid_height")); locationTag.setSatelliteSpeed(rs.getString("satellite_speed")); locationTag.setLastBarometricValue(rs.getString("last_barometric_pressure")); locationTag.setRecentCoordinates(rs.getString("recent_five_positions")); locationTag.setRecentBarometricValues(rs.getString("recent_five_barometric_values")); locationTag.setOfflineTime(rs.getString("offline_time")); locationTag.setOnlineTime(rs.getString("online_time")); locationTag.setOfflineDuration(rs.getString("offline_duration")); locationTag.setOnlineDuration(rs.getString("online_duration")); locationTag.setMotionlessStartTime(rs.getString("stationary_start_time")); 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")); locationTag.setSleepTime(rs.getString("sleep_time")); locationTag.setVibrationTime(rs.getString("vibration_time")); locationTag.setFrequency(rs.getString("frequency")); locationTag.setMotionlessTime(rs.getString("stationary_time")); locationTag.setAccelerationValue(rs.getString("acceleration_value")); locationTag.setImuTime(rs.getString("imu_time")); locationTag.setReserved1(rs.getString("reserved1")); locationTag.setReserved2(rs.getString("reserved2")); locationTag.setReserved3(rs.getString("reserved3")); locationTag.setReserved4(rs.getString("reserved4")); locationTag.setReserved5(rs.getString("reserved5")); locationTag.setIpAndPort(rs.getString("ip_and_port")); locationTag.setInteractionType(rs.getString("Interaction_Type")); locationTag.setIpAddress(rs.getString("ipAddress")); locationTag.setIpPort(rs.getString("Interaction_Type")); locationTags.add(locationTag); tagMap.put(locationTag.getDeviceNumber(), locationTag); // Ìí¼Óµ½Ó³Éä } return locationTags; } // ÐÂÔö²åÈë±êÇ©·½·¨ public static void insertLocationTag(LocationTag tag) throws SQLException { String sql = "INSERT INTO location_tag (device_id, device_name, device_type, company) " + "VALUES (?, ?, ?, ?)"; DBConnector.executeUpdate(sql, tag.getDeviceNumber(), tag.getDeviceName(), tag.getDeviceType(), tag.getCompany()); } // ÐÂÔöɾ³ý±êÇ©·½·¨ public static void deleteLocationTag(String deviceId) throws SQLException { String sql = "DELETE FROM location_tag WHERE device_id = ?"; 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; 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 getAlldeviceIds() { List types = new ArrayList<>(); try { // »ñÈ¡MessageType¶ÔÏóÁбí List typeList = getlocationTags(); // Ìáȡÿ¸ö¶ÔÏóµÄTypeName for (LocationTag mt : typeList) { types.add(mt.getDeviceNumber()); } } catch (SQLException e) { e.printStackTrace(); // ʵ¼ÊÓ¦ÓÃÖÐÓ¦´¦ÀíÒì³£ } return types; } /** * »ñÈ¡ËùÓÐÔÚÏß״̬(onlineStatus=1)µÄÉ豸£¨¸ßЧÄÚ´æ²Ù×÷£© * @return ²»¿ÉÐ޸ĵÄLocationTag¼¯ºÏ£¨±ÜÃâÍⲿÐ޸Ļº´æ£© */ public static List getOnlineLocationTags() { if (tagMap == null || tagMap.isEmpty()) { return Collections.emptyList(); // »º´æÎª¿Õʱ·µ»Ø¿Õ¼¯ºÏ } List 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(); } }