远程遥控相关
This commit is contained in:
@@ -1,3 +1,39 @@
|
||||
/// 设备归属操作类型(设备归属与安全页的两个高风险动作)。
|
||||
///
|
||||
/// 两者共用同一套「扫码核验 + 组织/场站/负责人三级选择」流程,
|
||||
/// 差别只在提交:
|
||||
/// - [transfer] 转交设备 = 将设备挂到选定层级(POST /iot/device/bind)
|
||||
/// - [unbind] 解绑设备 = 将设备从选定层级摘除(POST /iot/device/unbind)
|
||||
enum OwnershipAction {
|
||||
transfer,
|
||||
unbind;
|
||||
}
|
||||
|
||||
/// 解绑清除范围(后端解绑接口的 type 字段)
|
||||
///
|
||||
/// 归属层级为“组织 → 场站 → 负责人”,解绑需要指明从哪一级摘除:
|
||||
/// 1 = 清除负责人,2 = 清除场站,3 = 清除组织。
|
||||
/// 值越大解绑得越彻底,不可越级(例如设备只挂在场站下时不要传 org)。
|
||||
enum UnbindScope {
|
||||
user(1, '清除负责人'),
|
||||
site(2, '清除场站'),
|
||||
org(3, '清除组织');
|
||||
|
||||
final int value;
|
||||
final String label;
|
||||
|
||||
const UnbindScope(this.value, this.label);
|
||||
|
||||
/// 后端回传的 type 反查枚举;未知值返回 null
|
||||
static UnbindScope? fromValue(int? value) {
|
||||
if (value == null) return null;
|
||||
for (final scope in values) {
|
||||
if (scope.value == value) return scope;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class OrgEntity {
|
||||
final int id;
|
||||
final String name;
|
||||
|
||||
@@ -12,6 +12,12 @@ class DeviceEntity {
|
||||
final double? radiation;
|
||||
final bool isRobot;
|
||||
|
||||
/// 产品型号(如「割草机产品MC700」)
|
||||
final String productName;
|
||||
|
||||
/// 机型编码(如 MC700PRO),列表型号展示以此为准
|
||||
final String? productModel;
|
||||
|
||||
const DeviceEntity({
|
||||
required this.deviceId,
|
||||
required this.name,
|
||||
@@ -24,5 +30,7 @@ class DeviceEntity {
|
||||
this.voltage,
|
||||
this.radiation,
|
||||
this.isRobot = false,
|
||||
this.productName = '',
|
||||
this.productModel,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
/// 设备机型:把后端 productModel 解析成「系列 + 版本」。
|
||||
///
|
||||
/// 字段口径:getSiteList 返回的 productModel 形如
|
||||
/// `MC700` / `MC700STD` / `MC700PLUS` / `MC700PRO`,
|
||||
/// 也可能带长后缀:`MC700PRO-CN-JS-1751525588120-0000000A-9527`。
|
||||
///
|
||||
/// 该解析结果同时供列表卡展示与详情页功能开放使用,禁止再用伪随机/写死兜底。
|
||||
/// `label` 仅供内部解析/搜索匹配,展示请用 `labelOf` 取当前语言文案。
|
||||
enum DeviceEdition {
|
||||
std('标准版', 'std'),
|
||||
plus('智能版', 'plus'),
|
||||
pro('旗舰版', 'pro'),
|
||||
air('轻享版', 'air'),
|
||||
unknown('未知版本', 'unknown');
|
||||
|
||||
const DeviceEdition(this.label, this.code);
|
||||
|
||||
/// 中文短名(仅解析/搜索匹配用,不再直接展示)
|
||||
final String label;
|
||||
|
||||
/// 语言包代码:device_list_v2.edition_<code>
|
||||
final String code;
|
||||
}
|
||||
|
||||
class DeviceModelInfo {
|
||||
/// 后端原始值(如 MC700PRO)
|
||||
final String raw;
|
||||
|
||||
/// 型号系列(MC700 / MCAIR / RCHWD …)
|
||||
final String series;
|
||||
|
||||
/// 设备版本(std / plus / pro / air)
|
||||
final DeviceEdition edition;
|
||||
|
||||
const DeviceModelInfo({
|
||||
required this.raw,
|
||||
required this.series,
|
||||
required this.edition,
|
||||
});
|
||||
|
||||
static const empty = DeviceModelInfo(
|
||||
raw: '',
|
||||
series: '',
|
||||
edition: DeviceEdition.unknown,
|
||||
);
|
||||
|
||||
/// 是否解析出版本
|
||||
bool get resolved => edition != DeviceEdition.unknown;
|
||||
|
||||
/// 展示文案:`MC700 · PRO 旗舰版`;只有系列时 `MC700`;
|
||||
/// productModel 为 null / 空串时统一显示未知。
|
||||
///
|
||||
/// [deviceType] 是后端另一个字段(如 MC700 / 割草机器人),要排在
|
||||
/// 版本号(PRO / PLUS / STD)之前,并且优先于从 productModel 里解析出的系列:
|
||||
/// 后端明确给了机型就用它,没给才回退到 productModel 的解析结果。
|
||||
String labelOf(AppLocalizations l10n, {String? deviceType}) {
|
||||
final typeText = (deviceType ?? '').trim();
|
||||
// deviceType 若是纯数字编码(1/2/3)拿来展示没意义,回退到 productModel 解析结果
|
||||
final usableType = RegExp(r'^\d+$').hasMatch(typeText) ? '' : typeText;
|
||||
final head = usableType.isNotEmpty ? usableType : series;
|
||||
|
||||
if (raw.isEmpty && head.isEmpty) {
|
||||
return l10n.translate('device_list_v2.unknown');
|
||||
}
|
||||
if (head.isEmpty && edition == DeviceEdition.unknown) return raw;
|
||||
if (edition == DeviceEdition.unknown) return head;
|
||||
return '$head · ${editionLabelOf(l10n)}';
|
||||
}
|
||||
|
||||
/// 版本短文案:`PRO 旗舰版`;未知时为空
|
||||
String editionLabelOf(AppLocalizations l10n) => edition == DeviceEdition.unknown
|
||||
? ''
|
||||
: '${edition.name.toUpperCase()} ${l10n.translate('device_list_v2.edition_${edition.code}')}';
|
||||
|
||||
/// 搜索用关键字:原始值 + 系列 + 版本中英文
|
||||
String get searchText =>
|
||||
'$raw $series ${edition.name.toUpperCase()} ${edition.label} ${edition.name}'
|
||||
.toLowerCase();
|
||||
|
||||
/// 解析:兼容 MC700PRO / MC700-PRO / MC700 PRO / 长后缀 / 中文「旗舰版」
|
||||
static DeviceModelInfo parse(String? value) {
|
||||
final raw = (value ?? '').trim();
|
||||
if (raw.isEmpty) return empty;
|
||||
|
||||
final compact = raw.toUpperCase().replaceAll(RegExp(r'[\s\-_·]+'), '');
|
||||
final seriesMatch = RegExp(
|
||||
r'(MCAIR|RCH[A-Z]*|RCE[A-Z]*|MC\d{3})',
|
||||
).firstMatch(compact);
|
||||
final series = seriesMatch?.group(1) ?? '';
|
||||
|
||||
final DeviceEdition edition;
|
||||
if (compact.contains('PRO') || raw.contains('旗舰')) {
|
||||
edition = DeviceEdition.pro;
|
||||
} else if (compact.contains('PLUS') || raw.contains('智能')) {
|
||||
edition = DeviceEdition.plus;
|
||||
} else if (compact.contains('AIR') || raw.contains('轻享')) {
|
||||
edition = DeviceEdition.air;
|
||||
} else if (compact.contains('STD') || raw.contains('标准')) {
|
||||
edition = DeviceEdition.std;
|
||||
} else {
|
||||
edition = DeviceEdition.unknown;
|
||||
}
|
||||
|
||||
return DeviceModelInfo(raw: raw, series: series, edition: edition);
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,13 @@ abstract class BindDeviceRepository {
|
||||
int? siteId,
|
||||
int? userId,
|
||||
});
|
||||
|
||||
/// 批量解绑设备。
|
||||
///
|
||||
/// [scope] 指定从归属链的哪一级摘除(负责人/场站/组织),
|
||||
/// 由 UseCase 保证设备当前挂载层级与 scope 匹配后再下发。
|
||||
Future<Either<Failure, void>> unbindDevice({
|
||||
required List<String> deviceIds,
|
||||
required UnbindScope scope,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,3 +48,29 @@ class IsDeviceAtSiteUseCase {
|
||||
required int siteId,
|
||||
}) => _repository.isDeviceAtSite(deviceId: deviceId, siteId: siteId);
|
||||
}
|
||||
|
||||
/// 批量解绑设备用例(后端 /iot/device/unbind)
|
||||
///
|
||||
/// 归属层级:组织 → 场站 → 负责人,[scope] 需与设备当前挂载的层级一致,
|
||||
/// 传错会把设备从错误的层级摘除且不可逆,所以这里只做入参清理,不猜测 scope。
|
||||
class UnbindDeviceV2UseCase {
|
||||
final BindDeviceRepository _repository;
|
||||
UnbindDeviceV2UseCase(this._repository);
|
||||
|
||||
Future<Either<Failure, void>> call({
|
||||
required List<String> deviceIds,
|
||||
required UnbindScope scope,
|
||||
}) {
|
||||
// 去空串、去重(保留调用方顺序):空列表发给后端可能被当成“整个层级清空”
|
||||
final ids = <String>[];
|
||||
for (final raw in deviceIds) {
|
||||
final id = raw.trim();
|
||||
if (id.isEmpty || ids.contains(id)) continue;
|
||||
ids.add(id);
|
||||
}
|
||||
if (ids.isEmpty) {
|
||||
return Future.value(Left(Failure('请选择需要解绑的设备')));
|
||||
}
|
||||
return _repository.unbindDevice(deviceIds: ids, scope: scope);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user