|
|
|
@ -6,17 +6,27 @@ import 'package:problem_check_system/app/features/enterprise/data/model/enterpri |
|
|
|
/// 这个模型专门用于与远程 API 进行数据交互。 |
|
|
|
/// 这个模型专门用于与远程 API 进行数据交互。 |
|
|
|
/// 它的字段和结构【严格匹配】服务器 API 定义的 JSON 格式。 |
|
|
|
/// 它的字段和结构【严格匹配】服务器 API 定义的 JSON 格式。 |
|
|
|
class EnterpriseDto { |
|
|
|
class EnterpriseDto { |
|
|
|
|
|
|
|
final String id; |
|
|
|
|
|
|
|
final DateTime creationTime; |
|
|
|
|
|
|
|
final String creatorId; |
|
|
|
|
|
|
|
final DateTime lastModificationTime; |
|
|
|
|
|
|
|
final String lastModifierId; |
|
|
|
final String companyName; |
|
|
|
final String companyName; |
|
|
|
final String companyType; |
|
|
|
final String companyType; |
|
|
|
final String? companyScope; |
|
|
|
final String? companyScope; |
|
|
|
final String? mainPrincipalName; |
|
|
|
final String? mainPrincipalName; |
|
|
|
final String? mainPrincipalPhone; |
|
|
|
final String? mainPrincipalPhone; |
|
|
|
final String? securityPrincipalName; // API 中没有,但最好加上以保持对称 |
|
|
|
final String? securityPrincipalName; |
|
|
|
final String? securityPrincipalPhone; // API 中没有,但最好加上以保持对称 |
|
|
|
final String? securityPrincipalPhone; |
|
|
|
final String? companyAddress; |
|
|
|
final String? companyAddress; |
|
|
|
final String? detail; // 对应 majorHazardsDescription |
|
|
|
final String? detail; |
|
|
|
|
|
|
|
|
|
|
|
const EnterpriseDto({ |
|
|
|
const EnterpriseDto({ |
|
|
|
|
|
|
|
required this.id, |
|
|
|
|
|
|
|
required this.creationTime, |
|
|
|
|
|
|
|
required this.creatorId, |
|
|
|
|
|
|
|
required this.lastModificationTime, |
|
|
|
|
|
|
|
required this.lastModifierId, |
|
|
|
required this.companyName, |
|
|
|
required this.companyName, |
|
|
|
required this.companyType, |
|
|
|
required this.companyType, |
|
|
|
this.companyScope, |
|
|
|
this.companyScope, |
|
|
|
@ -33,6 +43,11 @@ class EnterpriseDto { |
|
|
|
/// 这个转换逻辑是这个类的核心职责。 |
|
|
|
/// 这个转换逻辑是这个类的核心职责。 |
|
|
|
factory EnterpriseDto.fromModel(EnterpriseModel model) { |
|
|
|
factory EnterpriseDto.fromModel(EnterpriseModel model) { |
|
|
|
return EnterpriseDto( |
|
|
|
return EnterpriseDto( |
|
|
|
|
|
|
|
id: model.id, |
|
|
|
|
|
|
|
creationTime: model.creationTime, |
|
|
|
|
|
|
|
creatorId: "", //todo 需要在企业模型中添加创建时间 |
|
|
|
|
|
|
|
lastModificationTime: model.lastModifiedTime, |
|
|
|
|
|
|
|
lastModifierId: "", // todo需要在企业模型中添修改用户id |
|
|
|
companyName: model.name, |
|
|
|
companyName: model.name, |
|
|
|
companyType: model.type, |
|
|
|
companyType: model.type, |
|
|
|
companyScope: model.scale, |
|
|
|
companyScope: model.scale, |
|
|
|
@ -43,9 +58,48 @@ class EnterpriseDto { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 将 DTO 对象转换为可以发送给服务器的 JSON (Map) 格式。 |
|
|
|
// ======================================================================= |
|
|
|
|
|
|
|
// 新增方法 |
|
|
|
|
|
|
|
// ======================================================================= |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// [新增] fromJson 工厂构造函数:从 JSON Map 创建 EnterpriseDto 实例。 |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
/// 当从服务器接收到 JSON 数据时,调用此方法将其转换为 Dart 对象。 |
|
|
|
|
|
|
|
factory EnterpriseDto.fromJson(Map<String, dynamic> json) { |
|
|
|
|
|
|
|
return EnterpriseDto( |
|
|
|
|
|
|
|
// 必须存在的字段 |
|
|
|
|
|
|
|
id: json['id'] as String, |
|
|
|
|
|
|
|
creationTime: DateTime.parse(json['creationTime'] as String), |
|
|
|
|
|
|
|
creatorId: json['creatorId'] as String, |
|
|
|
|
|
|
|
lastModificationTime: DateTime.parse( |
|
|
|
|
|
|
|
json['lastModificationTime'] as String, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
lastModifierId: json['lastModifierId'] as String, |
|
|
|
|
|
|
|
companyName: json['companyName'] as String, |
|
|
|
|
|
|
|
companyType: json['companyType'] as String, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 可选字段 |
|
|
|
|
|
|
|
companyScope: json['companyScope'] as String?, |
|
|
|
|
|
|
|
mainPrincipalName: json['mainPrincipalName'] as String?, |
|
|
|
|
|
|
|
mainPrincipalPhone: json['mainPrincipalPhone'] as String?, |
|
|
|
|
|
|
|
securityPrincipalName: json['securityPrincipalName'] as String?, |
|
|
|
|
|
|
|
securityPrincipalPhone: json['securityPrincipalPhone'] as String?, |
|
|
|
|
|
|
|
companyAddress: json['companyAddress'] as String?, |
|
|
|
|
|
|
|
detail: json['detail'] as String?, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// [新增] toJson 方法:将 EnterpriseDto 实例转换为 JSON Map。 |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
/// 当需要将数据发送到服务器时,调用此方法将其转换为 JSON 格式。 |
|
|
|
Map<String, dynamic> toJson() { |
|
|
|
Map<String, dynamic> toJson() { |
|
|
|
final originalMap = { |
|
|
|
final jsonMap = { |
|
|
|
|
|
|
|
'id': id, |
|
|
|
|
|
|
|
// 使用 toIso8601String() 是将 DateTime 转换为标准化字符串的最佳实践 |
|
|
|
|
|
|
|
'creationTime': creationTime.toIso8601String(), |
|
|
|
|
|
|
|
'creatorId': creatorId, |
|
|
|
|
|
|
|
'lastModificationTime': lastModificationTime.toIso8601String(), |
|
|
|
|
|
|
|
'lastModifierId': lastModifierId, |
|
|
|
'companyName': companyName, |
|
|
|
'companyName': companyName, |
|
|
|
'companyType': companyType, |
|
|
|
'companyType': companyType, |
|
|
|
'companyScope': companyScope, |
|
|
|
'companyScope': companyScope, |
|
|
|
@ -56,6 +110,6 @@ class EnterpriseDto { |
|
|
|
'companyAddress': companyAddress, |
|
|
|
'companyAddress': companyAddress, |
|
|
|
'detail': detail, |
|
|
|
'detail': detail, |
|
|
|
}; |
|
|
|
}; |
|
|
|
return originalMap.withoutNullOrEmptyValues; |
|
|
|
return jsonMap.withoutNullOrEmptyValues; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|