/// 设备相关领域实体(家属端对接 client 接口)。 /// /// 以不可变类表达,避免 UI / 仓库直接依赖后台 DTO 结构。 /// 因未运行 build_runner(避免改动依赖与生成产物),此处手写等价实现: /// 所有字段 final、提供 const 构造与 copyWith,并手动实现 JSON 转换。 /// 设备简要信息(「我的设备」列表)。 class DeviceBrief { const DeviceBrief({ required this.serialno, this.snName, this.snModel, this.snMobile, this.status, this.activateTime, this.online, this.lastHeartbeatTime, }); final String serialno; final String? snName; final String? snModel; final String? snMobile; final int? status; final String? activateTime; /// 在线状态(1 在线 / 0 离线),后台按 Redis 心跳 TTL 判定。 final int? online; /// 最后心跳时间。 final String? lastHeartbeatTime; bool get isOnline => online == 1; /// 展示名称:优先自定义备注名,缺省回退 SN。 String get displayName => snName?.isNotEmpty == true ? snName! : serialno; factory DeviceBrief.fromJson(Map json) => DeviceBrief( serialno: json['serialno'] as String, snName: json['snName'] as String?, snModel: json['snModel'] as String?, snMobile: json['snMobile'] as String?, status: _toInt(json['status']), activateTime: json['activateTime']?.toString(), online: _toInt(json['online']), lastHeartbeatTime: json['lastHeartbeatTime']?.toString(), ); } /// 设备基本信息(系统信息面板)。 class DeviceSystemInfo { const DeviceSystemInfo({ this.serialno, this.deviceName, this.deviceBrand, this.deviceModel, this.androidVersion, this.releaseVersion, this.screenResolution, this.osType, this.osVersion, this.firmwareVersion, }); final String? serialno; final String? deviceName; final String? deviceBrand; final String? deviceModel; final String? androidVersion; final String? releaseVersion; final String? screenResolution; final String? osType; final String? osVersion; final String? firmwareVersion; factory DeviceSystemInfo.fromJson(Map json) => DeviceSystemInfo( serialno: json['serialno'] as String?, deviceName: json['deviceName'] as String?, deviceBrand: json['deviceBrand'] as String?, deviceModel: json['deviceModel'] as String?, androidVersion: json['androidVersion'] as String?, releaseVersion: json['releaseVersion'] as String?, screenResolution: json['screenResolution'] as String?, osType: json['osType'] as String?, osVersion: json['osVersion'] as String?, firmwareVersion: json['firmwareVersion'] as String?, ); } /// 设备定位信息。 class DeviceLocation { const DeviceLocation({ this.sn, this.country, this.province, this.city, this.district, this.street, this.address, this.locationDescribe, this.longitude, this.latitude, this.lastSuccessfulTime, }); final String? sn; final String? country; final String? province; final String? city; final String? district; final String? street; final String? address; final String? locationDescribe; final String? longitude; final String? latitude; final String? lastSuccessfulTime; factory DeviceLocation.fromJson(Map json) => DeviceLocation( sn: json['sn'] as String?, country: json['country'] as String?, province: json['province'] as String?, city: json['city'] as String?, district: json['district'] as String?, street: json['street'] as String?, address: json['address'] as String?, locationDescribe: json['locationDescribe'] as String?, longitude: _toDoubleString(json['longitude']), latitude: _toDoubleString(json['latitude']), lastSuccessfulTime: json['lastSuccessfulTime']?.toString(), ); /// 拼接展示用地址:省+市+区+街道+详细地址。 String get displayAddress { final parts = [ province, city, district, street, address, ].where((e) => e != null && e.isNotEmpty); return parts.join(''); } } /// 设备已安装应用信息。 class DeviceApkInfo { const DeviceApkInfo({ required this.packageName, this.appName, this.versionName, this.versionCode, this.installTime, this.lastUpdateTime, this.apkSize, this.systemApp = false, this.iconUrl, }); final String packageName; final String? appName; final String? versionName; final int? versionCode; final String? installTime; final String? lastUpdateTime; final int? apkSize; final bool systemApp; final String? iconUrl; factory DeviceApkInfo.fromJson(Map json) => DeviceApkInfo( packageName: json['packageName'] as String, appName: json['appName'] as String?, versionName: json['versionName'] as String?, versionCode: _toInt(json['versionCode']), installTime: json['installTime']?.toString(), lastUpdateTime: json['lastUpdateTime']?.toString(), apkSize: _toInt(json['apkSize']), systemApp: json['systemApp'] as bool? ?? false, iconUrl: json['iconUrl'] as String?, ); } /// 设备截图实体(与后台 SnScreenshot 对齐)。 class SnScreenshot { const SnScreenshot({ this.id, this.sn, this.fileName, this.filePath, this.fileSize, this.fileMd5, this.fileSha1, this.fileSha256, this.uploadTime, }); final int? id; final String? sn; final String? fileName; final String? filePath; final int? fileSize; final String? fileMd5; final String? fileSha1; final String? fileSha256; final String? uploadTime; factory SnScreenshot.fromJson(Map json) => SnScreenshot( id: _toInt(json['id']), sn: json['sn'] as String?, fileName: json['fileName'] as String?, filePath: json['filePath'] as String?, fileSize: _toInt(json['fileSize']), fileMd5: json['fileMd5'] as String?, fileSha1: json['fileSha1'] as String?, fileSha256: json['fileSha256'] as String?, uploadTime: json['uploadTime']?.toString(), ); } /// 设备策略信息(与后台 DevicePolicyVO 对齐,字段均对应「0关闭 1开启」策略开关)。 class DevicePolicy { const DevicePolicy({ this.id, this.serialno, this.usbData, this.timeSetting, this.storageCard, this.factoryReset, this.wifiHotspot, this.bluetooth, this.wallpaper, this.notificationBar, this.statusBarPullDown, this.systemNavBarShow, this.systemNavBarSetting, this.navBarOptions, this.configBluetooth, this.otaUpgrade, this.installApps, this.autoRotate, this.autoBrightness, this.eyeProtection, this.darkMode, this.safeBoot, this.adbUsbDebug, this.mountPhysicalStorage, this.modifySystemTimeZone, this.toggleAirplaneMode, this.modifyMobileApn, this.uninstallApps, this.camera, this.usbFileTransfer, this.modifyLocationSwitch, this.bluetoothSharing, this.resetNetworkSettings, this.adjustGlobalVolume, this.modifyScreenTimeout, this.manualAdjustTimeZone, this.modifySystemLanguage, this.manualAdjustBrightness, }); final int? id; final String? serialno; // 策略开关(0关闭 1开启),null 视为未返回。 final int? usbData; final int? timeSetting; final int? storageCard; final int? factoryReset; final int? wifiHotspot; final int? bluetooth; final int? wallpaper; final int? notificationBar; final int? statusBarPullDown; final int? systemNavBarShow; final int? systemNavBarSetting; final int? navBarOptions; final int? configBluetooth; final int? otaUpgrade; final int? installApps; final int? autoRotate; final int? autoBrightness; final int? eyeProtection; final int? darkMode; final int? safeBoot; final int? adbUsbDebug; final int? mountPhysicalStorage; final int? modifySystemTimeZone; final int? toggleAirplaneMode; final int? modifyMobileApn; final int? uninstallApps; final int? camera; final int? usbFileTransfer; final int? modifyLocationSwitch; final int? bluetoothSharing; final int? resetNetworkSettings; final int? adjustGlobalVolume; final int? modifyScreenTimeout; final int? manualAdjustTimeZone; final int? modifySystemLanguage; final int? manualAdjustBrightness; /// 读取某个策略字段开关值(0/1,缺失按 0 关闭处理)。 bool enabled(String field) { final value = _intField(field); return value == 1; } /// 返回某个策略字段当前值(null 表示未知)。 int? valueOf(String field) => _intField(field); int? _intField(String field) { switch (field) { case 'usbData': return usbData; case 'timeSetting': return timeSetting; case 'storageCard': return storageCard; case 'factoryReset': return factoryReset; case 'wifiHotspot': return wifiHotspot; case 'bluetooth': return bluetooth; case 'wallpaper': return wallpaper; case 'notificationBar': return notificationBar; case 'statusBarPullDown': return statusBarPullDown; case 'systemNavBarShow': return systemNavBarShow; case 'systemNavBarSetting': return systemNavBarSetting; case 'navBarOptions': return navBarOptions; case 'configBluetooth': return configBluetooth; case 'otaUpgrade': return otaUpgrade; case 'installApps': return installApps; case 'autoRotate': return autoRotate; case 'autoBrightness': return autoBrightness; case 'eyeProtection': return eyeProtection; case 'darkMode': return darkMode; case 'safeBoot': return safeBoot; case 'adbUsbDebug': return adbUsbDebug; case 'mountPhysicalStorage': return mountPhysicalStorage; case 'modifySystemTimeZone': return modifySystemTimeZone; case 'toggleAirplaneMode': return toggleAirplaneMode; case 'modifyMobileApn': return modifyMobileApn; case 'uninstallApps': return uninstallApps; case 'camera': return camera; case 'usbFileTransfer': return usbFileTransfer; case 'modifyLocationSwitch': return modifyLocationSwitch; case 'bluetoothSharing': return bluetoothSharing; case 'resetNetworkSettings': return resetNetworkSettings; case 'adjustGlobalVolume': return adjustGlobalVolume; case 'modifyScreenTimeout': return modifyScreenTimeout; case 'manualAdjustTimeZone': return manualAdjustTimeZone; case 'modifySystemLanguage': return modifySystemLanguage; case 'manualAdjustBrightness': return manualAdjustBrightness; default: return null; } } factory DevicePolicy.fromJson(Map json) => DevicePolicy( id: _toInt(json['id']), serialno: json['serialno'] as String?, usbData: _toInt(json['usbData']), timeSetting: _toInt(json['timeSetting']), storageCard: _toInt(json['storageCard']), factoryReset: _toInt(json['factoryReset']), wifiHotspot: _toInt(json['wifiHotspot']), bluetooth: _toInt(json['bluetooth']), wallpaper: _toInt(json['wallpaper']), notificationBar: _toInt(json['notificationBar']), statusBarPullDown: _toInt(json['statusBarPullDown']), systemNavBarShow: _toInt(json['systemNavBarShow']), systemNavBarSetting: _toInt(json['systemNavBarSetting']), navBarOptions: _toInt(json['navBarOptions']), configBluetooth: _toInt(json['configBluetooth']), otaUpgrade: _toInt(json['otaUpgrade']), installApps: _toInt(json['installApps']), autoRotate: _toInt(json['autoRotate']), autoBrightness: _toInt(json['autoBrightness']), eyeProtection: _toInt(json['eyeProtection']), darkMode: _toInt(json['darkMode']), safeBoot: _toInt(json['safeBoot']), adbUsbDebug: _toInt(json['adbUsbDebug']), mountPhysicalStorage: _toInt(json['mountPhysicalStorage']), modifySystemTimeZone: _toInt(json['modifySystemTimeZone']), toggleAirplaneMode: _toInt(json['toggleAirplaneMode']), modifyMobileApn: _toInt(json['modifyMobileApn']), uninstallApps: _toInt(json['uninstallApps']), camera: _toInt(json['camera']), usbFileTransfer: _toInt(json['usbFileTransfer']), modifyLocationSwitch: _toInt(json['modifyLocationSwitch']), bluetoothSharing: _toInt(json['bluetoothSharing']), resetNetworkSettings: _toInt(json['resetNetworkSettings']), adjustGlobalVolume: _toInt(json['adjustGlobalVolume']), modifyScreenTimeout: _toInt(json['modifyScreenTimeout']), manualAdjustTimeZone: _toInt(json['manualAdjustTimeZone']), modifySystemLanguage: _toInt(json['modifySystemLanguage']), manualAdjustBrightness: _toInt(json['manualAdjustBrightness']), ); } /// 设备截图视图对象(与后台 ScreenshotVO 对齐)。 class ScreenshotVO { const ScreenshotVO({ this.id, this.sn, this.fileName, this.fileSize, this.url, this.uploadTime, }); final int? id; final String? sn; final String? fileName; final int? fileSize; final String? url; final String? uploadTime; factory ScreenshotVO.fromJson(Map json) => ScreenshotVO( id: _toInt(json['id']), sn: json['sn'] as String?, fileName: json['fileName'] as String?, fileSize: _toInt(json['fileSize']), url: json['url'] as String?, uploadTime: json['uploadTime']?.toString(), ); } //// 设备壁纸配置(与后台 DeviceWallpaperVO 对齐)。 class WallpaperConfig { const WallpaperConfig({ this.serialno, this.mode, this.images = const [], }); final String? serialno; /// 壁纸模式:0-单个壁纸,1-轮换壁纸。 final int? mode; /// 壁纸图片URL列表(单个1张,轮换最多7张;可能为相对路径 /static/wallpaper/xxx)。 final List images; factory WallpaperConfig.fromJson(Map json) => WallpaperConfig( serialno: json['serialno'] as String?, mode: _toInt(json['mode']), images: (json['images'] as List? ?? const []) .whereType() .toList(), ); } /// 已发送到设备的图片信息(与后台 DevicePictureVO 对齐)。 class DevicePictureInfo { const DevicePictureInfo({ required this.url, this.sourceUrl, this.favorite = false, this.fileSize = 0, }); /// 图片完整URL。 final String url; /// 原始服务端地址,用于按原记录设置收藏。 final String? sourceUrl; /// 是否收藏。 final bool favorite; /// 文件大小(字节)。 final int fileSize; factory DevicePictureInfo.fromJson(Map json) => DevicePictureInfo( url: (json['url'] as String?) ?? '', favorite: _toInt(json['favorite']) == 1, fileSize: _toInt(json['fileSize']) ?? 0, ); DevicePictureInfo copyWith({bool? favorite}) => DevicePictureInfo( url: url, sourceUrl: sourceUrl, favorite: favorite ?? this.favorite, fileSize: fileSize, ); } /// 容错整型解析:后台可能以字符串(如 "123")或数字返回整型字段, /// 直接用 `as int?` 在字符串场景下会抛出 /// `type 'String' is not a subtype of type 'int'`,故统一在此转换。 int? _toInt(dynamic value) { if (value == null) return null; if (value is int) return value; if (value is num) return value.toInt(); if (value is String) return int.tryParse(value); return null; } /// 容错浮点解析(用于经纬度等带小数的字段),返回字符串形式便于上层 `double.tryParse`。 /// /// 经纬度必须保留小数精度: /// - 后台若以数字(如 `116.404`)返回,直接截断成整数会偏移数公里; /// - 后台若以字符串(如 `"39.915"`)返回,`int.tryParse` 会解析失败变成 null。 String? _toDoubleString(dynamic value) { if (value == null) return null; if (value is num) return value.toString(); if (value is String) { final parsed = double.tryParse(value); return parsed?.toString(); } return null; }