library fis_jsonrpc; import 'dart:collection'; import 'dart:convert'; import 'package:fis_common/extensions/type.dart'; import 'package:fis_common/logger/logger.dart'; import 'package:fis_jsonrpc/encrpyt.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(); 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; /// 服务主机协议 late String _currentProtocol; /// 当前服务主机地址 String get currentHostAddress => "$_currentProtocol://$_currentHost"; HashMap _serviceCache = HashMap(); static PlatformService? _platformService; /// 请求加密配置 JsonRpcEncryptConfig get requestEncryptConfig => JsonRpcClientBase.requestEncryptConfig; set requestEncryptConfig(JsonRpcEncryptConfig config) { JsonRpcClientBase.requestEncryptConfig = config; final cfgJson = jsonEncode(config.toJson()); logger.i("JsonRpcProxy - set RequestEncryptConfig: $cfgJson."); } /// 响应加密配置 JsonRpcEncryptConfig get responseEncryptConfig => JsonRpcClientBase.responseEncryptConfig; set responseEncryptConfig(JsonRpcEncryptConfig config) { JsonRpcClientBase.responseEncryptConfig = config; final cfgJson = jsonEncode(config.toJson()); logger.i("JsonRpcProxy - set ResponseEncryptConfig: $cfgJson."); } /* 服务代理设置 Start */ /// 平台服务 PlatformService get platform { if (_platformService == null) _platformService = PlatformService("http://$platformHost", timeout: 15000); return _platformService!; } ResearchEditionService get researchEdition => findService(() => new ResearchEditionService(currentHostAddress)); LiveConsultationService get liveConsultation => findService(() => new LiveConsultationService(currentHostAddress)); AIDiagnosisService get aIDiagnosis => findService(() => new AIDiagnosisService(currentHostAddress)); AppletAPIService get appletAPI => findService(() => new AppletAPIService(currentHostAddress)); ASRService get aSR => findService(() => new ASRService(currentHostAddress)); AuthenticationService get authentication => findService(() => new AuthenticationService(currentHostAddress)); ChatMessageService get chatMessage => findService(() => new ChatMessageService(currentHostAddress)); ConnectService get connect => findService(() => new ConnectService(currentHostAddress)); DeployPlatformService get deployPlatform => findService(() => new DeployPlatformService(currentHostAddress)); DeviceService get device => findService(() => new DeviceService(currentHostAddress)); DongleService get dongle => findService(() => new DongleService(currentHostAddress)); EducationService get education => findService(() => new EducationService(currentHostAddress)); EmailService get email => findService(() => new EmailService(currentHostAddress)); IdentityApplyService get identityApply => findService(() => new IdentityApplyService(currentHostAddress)); LabService get lab => findService(() => new LabService(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)); RecognitionService get recognition => findService(() => new RecognitionService(currentHostAddress)); RecordInfoService get recordInfo => findService(() => new RecordInfoService(currentHostAddress)); RegionService get region => findService(() => new RegionService(currentHostAddress)); RegisterService get register => findService(() => new RegisterService(currentHostAddress)); RemedicalService get remedical => findService(() => new RemedicalService(currentHostAddress)); RemoteUltrasoundService get remoteUltrasound => findService(() => new RemoteUltrasoundService(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)); TaskService get task => findService(() => new TaskService(currentHostAddress)); UltrasoundReportService get ultrasoundReport => findService(() => new UltrasoundReportService(currentHostAddress)); UpgradeService get upgrade => findService(() => new UpgradeService(currentHostAddress)); UserService get user => findService(() => new UserService(currentHostAddress)); VinnoIOTService get vinnoIOT => findService(() => new VinnoIOTService(currentHostAddress)); VinnoServerService get vinnoServer => findService(() => new VinnoServerService(currentHostAddress)); VitalHealthExamBookingService get vitalHealthExamBooking => findService(() => new VitalHealthExamBookingService(currentHostAddress)); ExamService get exam => findService(() => new ExamService(currentHostAddress)); VitalAnalyzeConfigService get vitalAnalyzeConfig => findService(() => new VitalAnalyzeConfigService(currentHostAddress)); VitalCompletionRecordService get vitalCompletionRecord => findService(() => new VitalCompletionRecordService(currentHostAddress)); VitalContractRecordService get vitalContractRecord => findService(() => new VitalContractRecordService(currentHostAddress)); VitalContractTemplateService get vitalContractTemplate => findService(() => new VitalContractTemplateService(currentHostAddress)); VitalDeviceService get vitalDevice => findService(() => new VitalDeviceService(currentHostAddress)); VitalDiagnosisService get vitalDiagnosis => findService(() => new VitalDiagnosisService(currentHostAddress)); VitalDictionaryService get vitalDictionary => findService(() => new VitalDictionaryService(currentHostAddress)); VitalDynamicTypeService get vitalDynamicType => findService(() => new VitalDynamicTypeService(currentHostAddress)); VitalElectrocardiogramService get vitalElectrocardiogram => findService(() => new VitalElectrocardiogramService(currentHostAddress)); VitalExamService get vitalExam => findService(() => new VitalExamService(currentHostAddress)); VitalFacturyPostHistoryService get vitalFacturyPostHistory => findService(() => new VitalFacturyPostHistoryService(currentHostAddress)); VitalFacturyUserService get vitalFacturyUser => findService(() => new VitalFacturyUserService(currentHostAddress)); VitalFollowUpService get vitalFollowUp => findService(() => new VitalFollowUpService(currentHostAddress)); VitalLabelService get vitalLabel => findService(() => new VitalLabelService(currentHostAddress)); VitalLoginService get vitalLogin => findService(() => new VitalLoginService(currentHostAddress)); VitalOperationLogService get vitalOperationLog => findService(() => new VitalOperationLogService(currentHostAddress)); VitalOrganizationService get vitalOrganization => findService(() => new VitalOrganizationService(currentHostAddress)); VitalPatientExtensionService get vitalPatientExtension => findService(() => new VitalPatientExtensionService(currentHostAddress)); VitalPatientService get vitalPatient => findService(() => new VitalPatientService(currentHostAddress)); VitalPrescriptionService get vitalPrescription => findService(() => new VitalPrescriptionService(currentHostAddress)); VitalRegionService get vitalRegion => findService(() => new VitalRegionService(currentHostAddress)); VitalReportService get vitalReport => findService(() => new VitalReportService(currentHostAddress)); VitalResidenceService get vitalResidence => findService(() => new VitalResidenceService(currentHostAddress)); VitalRoleService get vitalRole => findService(() => new VitalRoleService(currentHostAddress)); VitalScheduleService get vitalSchedule => findService(() => new VitalScheduleService(currentHostAddress)); VitalServicePackService get vitalServicePack => findService(() => new VitalServicePackService(currentHostAddress)); VitalStatisticService get vitalStatistic => findService(() => new VitalStatisticService(currentHostAddress)); VitalSystemSettingService get vitalSystemSetting => findService(() => new VitalSystemSettingService(currentHostAddress)); VitalTeamRegionService get vitalTeamRegion => findService(() => new VitalTeamRegionService(currentHostAddress)); VitalTeamService get vitalTeam => findService(() => new VitalTeamService(currentHostAddress)); VitalTemplateService get vitalTemplate => findService(() => new VitalTemplateService(currentHostAddress)); VitalTownService get vitalTown => findService(() => new VitalTownService(currentHostAddress)); VitalUpgradeService get vitalUpgrade => findService(() => new VitalUpgradeService(currentHostAddress)); VitalUserFeatureService get vitalUserFeature => findService(() => new VitalUserFeatureService(currentHostAddress)); VitalUserPasswordService get vitalUserPassword => findService(() => new VitalUserPasswordService(currentHostAddress)); VitalUserService get vitalUser => findService(() => new VitalUserService(currentHostAddress)); /* 服务代理设置 End */ /// 设置服务主机地址 void setServerHost(String address, [bool useSSL = false]) { logger.i('JsonRpcProxy setServerHost :' + address); _currentProtocol = useSSL ? "https" : "http"; _currentHost = address; } /// 添加拦截器 void addInterceptor(JsonRpcInterceptor interceptor) => jsonRpcInterceptHost.addInterceptor(interceptor); /// 清空缓存 void clearCache() => _serviceCache.clear(); /// 查找Service实例 T findService(ServiceBuilder builder) { Type serviceType = typeOf(); if (!_serviceCache.containsKey(serviceType)) { _serviceCache[serviceType] = builder.call(); } return _serviceCache[serviceType] as T; } }