浏览代码

获取用户信息接口&支持单独修改服务名

melon.yin 3 年之前
父节点
当前提交
48174ca0fd
共有 5 个文件被更改,包括 90 次插入3 次删除
  1. 10 3
      lib/client_base.dart
  2. 4 0
      lib/rpc.dart
  3. 2 0
      lib/services/index.dart
  4. 31 0
      lib/services/user.dart
  5. 43 0
      lib/services/user.m.dart

+ 10 - 3
lib/client_base.dart

@@ -12,8 +12,10 @@ class JsonRpcClientBase {
   /// 服务主机地址
   final String host;
 
+  late String _serviceName;
+
   /// 服务名称
-  final String serviceName;
+  String get serviceName => _serviceName;
 
   /// 自定义Http header
   final Map<String, String>? headers;
@@ -27,10 +29,15 @@ class JsonRpcClientBase {
 
   JsonRpcClientBase(
     this.host,
-    this.serviceName, {
+    String serviceName, {
     this.headers,
     this.timeout,
-  });
+  }) {
+    _serviceName = serviceName;
+  }
+
+  /// 设置服务名
+  void setServiceName(String name) => _serviceName = name;
 
   /// 请求RPC method
   @protected

+ 4 - 0
lib/rpc.dart

@@ -57,6 +57,10 @@ class JsonRpcProxy {
   RemedicalService get remedical =>
       findService(() => new RemedicalService(currentHostAddress));
 
+  /// 用户服务
+  UserService get user =>
+      findService(() => new UserService(currentHostAddress));
+
   /* 服务代理设置 End */
 
   /// 设置服务主机地址

+ 2 - 0
lib/services/index.dart

@@ -4,3 +4,5 @@ export 'platform.dart';
 export 'platform.m.dart';
 export 'remedical.dart';
 export 'remedical.m.dart';
+export 'user.dart';
+export 'user.m.dart';

+ 31 - 0
lib/services/user.dart

@@ -0,0 +1,31 @@
+import 'dart:core';
+
+import 'package:fiscommon/json_convert.dart';
+import 'package:fisjsonrpc/base_model.dart';
+import 'package:fisjsonrpc/client_base.dart';
+
+import 'user.m.dart';
+
+/// 用户服务
+class UserService extends JsonRpcClientBase {
+  UserService(
+    String host, {
+    String serviceName = "IUserService",
+    Map<String, String>? headers,
+    int? timeout,
+  }) : super(
+          host,
+          serviceName,
+          headers: headers,
+          timeout: timeout,
+        ) {
+    /// 注册响应实体反序列化处理器
+  }
+
+  /// 获取用户信息
+  Future<UserInfo> getUserInfoAsync(String userCode, String sessionId) async {
+    var rpcRst = await call("GetUserInfoAsync", [userCode, sessionId]);
+    var result = UserInfo.fromJson(rpcRst as Map<String, dynamic>);
+    return result;
+  }
+}

+ 43 - 0
lib/services/user.m.dart

@@ -0,0 +1,43 @@
+class UserInfo {
+  UserInfo({
+    required this.userCode,
+    required this.userName,
+    this.phone,
+    this.email,
+    this.nickName,
+    this.fullName,
+    this.headImageToken,
+    this.organizationCode,
+    this.authorityGroups = const [],
+    this.bindDevices = const [],
+    this.score = 0,
+  });
+
+  final String userCode;
+  final String userName;
+  final String? phone;
+  final String? email;
+  final String? nickName;
+  final String? fullName;
+  final String? headImageToken;
+  final String? organizationCode;
+  final List<String> authorityGroups;
+  final List<String> bindDevices;
+  final double score;
+
+  factory UserInfo.fromJson(Map<String, dynamic> map) {
+    return UserInfo(
+      userCode: map['UserCode'],
+      userName: map['UserName'],
+      phone: map['Phone'],
+      email: map['Email'],
+      nickName: map['NickName'],
+      fullName: map['FullName'],
+      headImageToken: map['HeadImageToken'],
+      organizationCode: map['OrganizationCode'],
+      score: map['Score'],
+      authorityGroups: (map['AuthorityGroups'] as List).cast<String>(),
+      bindDevices: (map['BindDevices'] as List).cast<String>(),
+    );
+  }
+}