123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- library fis_jsonrpc;
- import 'dart:collection';
- import 'package:fis_common/extensions/type.dart';
- import 'package:fis_common/logger/logger.dart';
- import 'client_base.dart';
- import 'interceptor.dart';
- import 'services/index.dart';
- export 'services/index.dart';
- export 'request.dart';
- export 'exception.dart';
- export 'interceptor.dart';
- export 'notifications/index.dart';
- typedef T ServiceBuilder<T extends JsonRpcClientBase>();
- const C_SHELL_RPC_DEFAULT_HOST = 'platform.fis.plus';
- /// JSON-RPC 代理
- class JsonRpcProxy {
- JsonRpcProxy({
- String? host,
- this.platformHost = C_SHELL_RPC_DEFAULT_HOST,
- }) {
- _currentHost = host ?? "unknown";
- }
- /// 宿主平台代理地址
- final String platformHost;
- /// 服务主机地址
- late String _currentHost;
- /// 当前服务主机地址
- String get currentHostAddress => "http://$_currentHost";
- HashMap<Type, dynamic> _serviceCache = HashMap();
- static PlatformService? _platformService;
- /* 服务代理设置 Start */
- /// 平台服务
- PlatformService get platform {
- if (_platformService == null)
- _platformService = PlatformService("http://$platformHost");
- return _platformService!;
- }
- LiveConsultationService get liveConsultation =>
- findService(() => new LiveConsultationService(currentHostAddress));
- AIDiagnosisService get aIDiagnosis =>
- findService(() => new AIDiagnosisService(currentHostAddress));
- ASRService get aSR =>
- findService(() => new ASRService(currentHostAddress));
- AuthenticationService get authentication =>
- findService(() => new AuthenticationService(currentHostAddress));
- ConnectService get connect =>
- findService(() => new ConnectService(currentHostAddress));
- DeployPlatformService get deployPlatform =>
- findService(() => new DeployPlatformService(currentHostAddress));
- DeviceService get device =>
- findService(() => new DeviceService(currentHostAddress));
- EducationService get education =>
- findService(() => new EducationService(currentHostAddress));
- EmailService get email =>
- findService(() => new EmailService(currentHostAddress));
- IdentityApplyService get identityApply =>
- findService(() => new IdentityApplyService(currentHostAddress));
- LoginService get login =>
- findService(() => new LoginService(currentHostAddress));
- OrganizationService get organization =>
- findService(() => new OrganizationService(currentHostAddress));
- PatientService get patient =>
- findService(() => new PatientService(currentHostAddress));
- PaymentService get payment =>
- findService(() => new PaymentService(currentHostAddress));
- PositionService get position =>
- findService(() => new PositionService(currentHostAddress));
- RankService get rank =>
- findService(() => new RankService(currentHostAddress));
- RecordInfoService get recordInfo =>
- findService(() => new RecordInfoService(currentHostAddress));
- RegionService get region =>
- findService(() => new RegionService(currentHostAddress));
- RemedicalService get remedical =>
- findService(() => new RemedicalService(currentHostAddress));
- ReportService get report =>
- findService(() => new ReportService(currentHostAddress));
- RoleService get role =>
- findService(() => new RoleService(currentHostAddress));
- SMSService get sMS =>
- findService(() => new SMSService(currentHostAddress));
- StorageService get storage =>
- findService(() => new StorageService(currentHostAddress));
- UpgradeService get upgrade =>
- findService(() => new UpgradeService(currentHostAddress));
- UserService get user =>
- findService(() => new UserService(currentHostAddress));
- VinnoServerService get vinnoServer =>
- findService(() => new VinnoServerService(currentHostAddress));
- /* 服务代理设置 End */
- /// 设置服务主机地址
- void setServerHost(String address) {
- logger.i('JsonRpcProxy setServerHost :' + address);
- _currentHost = address;
- }
- /// 添加拦截器
- void addInterceptor(JsonRpcInterceptor interceptor) =>
- jsonRpcInterceptHost.addInterceptor(interceptor);
- /// 清空缓存
- void clearCache() => _serviceCache.clear();
- /// 查找Service实例
- T findService<T extends JsonRpcClientBase>(ServiceBuilder<T> builder) {
- Type serviceType = typeOf<T>();
- if (!_serviceCache.containsKey(serviceType)) {
- _serviceCache[serviceType] = builder.call();
- }
- return _serviceCache[serviceType] as T;
- }
- }
|