123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- 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<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;
- /// 服务主机协议
- late String _currentProtocol;
- /// 当前服务主机地址
- String get currentHostAddress => "$_currentProtocol://$_currentHost";
- HashMap<Type, dynamic> _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<T extends JsonRpcClientBase>(ServiceBuilder<T> builder) {
- Type serviceType = typeOf<T>();
- if (!_serviceCache.containsKey(serviceType)) {
- _serviceCache[serviceType] = builder.call();
- }
- return _serviceCache[serviceType] as T;
- }
- }
|