rpc.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. library fis_jsonrpc;
  2. import 'dart:collection';
  3. import 'package:fis_common/extensions/type.dart';
  4. import 'package:fis_common/logger/logger.dart';
  5. import 'client_base.dart';
  6. import 'interceptor.dart';
  7. import 'services/index.dart';
  8. export 'services/index.dart';
  9. export 'request.dart';
  10. export 'exception.dart';
  11. export 'interceptor.dart';
  12. export 'notifications/index.dart';
  13. typedef T ServiceBuilder<T extends JsonRpcClientBase>();
  14. const C_SHELL_RPC_DEFAULT_HOST = 'platform.fis.plus';
  15. /// JSON-RPC 代理
  16. class JsonRpcProxy {
  17. JsonRpcProxy({
  18. String? host,
  19. this.platformHost = C_SHELL_RPC_DEFAULT_HOST,
  20. }) {
  21. _currentHost = host ?? "unknown";
  22. }
  23. /// 宿主平台代理地址
  24. final String platformHost;
  25. /// 服务主机地址
  26. late String _currentHost;
  27. /// 服务主机协议
  28. late String _currentProtocol;
  29. /// 当前服务主机地址
  30. String get currentHostAddress => "$_currentProtocol://$_currentHost";
  31. HashMap<Type, dynamic> _serviceCache = HashMap();
  32. static PlatformService? _platformService;
  33. /* 服务代理设置 Start */
  34. /// 平台服务
  35. PlatformService get platform {
  36. if (_platformService == null)
  37. _platformService = PlatformService("http://$platformHost", timeout: 15000);
  38. return _platformService!;
  39. }
  40. LiveConsultationService get liveConsultation =>
  41. findService(() => new LiveConsultationService(currentHostAddress));
  42. AIDiagnosisService get aIDiagnosis =>
  43. findService(() => new AIDiagnosisService(currentHostAddress));
  44. AppletAPIService get appletAPI =>
  45. findService(() => new AppletAPIService(currentHostAddress));
  46. ASRService get aSR =>
  47. findService(() => new ASRService(currentHostAddress));
  48. AuthenticationService get authentication =>
  49. findService(() => new AuthenticationService(currentHostAddress));
  50. ChatMessageService get chatMessage =>
  51. findService(() => new ChatMessageService(currentHostAddress));
  52. ConnectService get connect =>
  53. findService(() => new ConnectService(currentHostAddress));
  54. DeployPlatformService get deployPlatform =>
  55. findService(() => new DeployPlatformService(currentHostAddress));
  56. DeviceService get device =>
  57. findService(() => new DeviceService(currentHostAddress));
  58. EducationService get education =>
  59. findService(() => new EducationService(currentHostAddress));
  60. EmailService get email =>
  61. findService(() => new EmailService(currentHostAddress));
  62. IdentityApplyService get identityApply =>
  63. findService(() => new IdentityApplyService(currentHostAddress));
  64. LabService get lab =>
  65. findService(() => new LabService(currentHostAddress));
  66. LoginService get login =>
  67. findService(() => new LoginService(currentHostAddress));
  68. OrganizationService get organization =>
  69. findService(() => new OrganizationService(currentHostAddress));
  70. PatientService get patient =>
  71. findService(() => new PatientService(currentHostAddress));
  72. PaymentService get payment =>
  73. findService(() => new PaymentService(currentHostAddress));
  74. PositionService get position =>
  75. findService(() => new PositionService(currentHostAddress));
  76. RankService get rank =>
  77. findService(() => new RankService(currentHostAddress));
  78. RecognitionService get recognition =>
  79. findService(() => new RecognitionService(currentHostAddress));
  80. RecordInfoService get recordInfo =>
  81. findService(() => new RecordInfoService(currentHostAddress));
  82. RegionService get region =>
  83. findService(() => new RegionService(currentHostAddress));
  84. RegisterService get register =>
  85. findService(() => new RegisterService(currentHostAddress));
  86. RemedicalService get remedical =>
  87. findService(() => new RemedicalService(currentHostAddress));
  88. ReportService get report =>
  89. findService(() => new ReportService(currentHostAddress));
  90. RoleService get role =>
  91. findService(() => new RoleService(currentHostAddress));
  92. SMSService get sMS =>
  93. findService(() => new SMSService(currentHostAddress));
  94. StorageService get storage =>
  95. findService(() => new StorageService(currentHostAddress));
  96. UpgradeService get upgrade =>
  97. findService(() => new UpgradeService(currentHostAddress));
  98. UserService get user =>
  99. findService(() => new UserService(currentHostAddress));
  100. VinnoIOTService get vinnoIOT =>
  101. findService(() => new VinnoIOTService(currentHostAddress));
  102. VinnoServerService get vinnoServer =>
  103. findService(() => new VinnoServerService(currentHostAddress));
  104. VitalHealthExamBookingService get vitalHealthExamBooking =>
  105. findService(() => new VitalHealthExamBookingService(currentHostAddress));
  106. VitalAnalyzeConfigService get vitalAnalyzeConfig =>
  107. findService(() => new VitalAnalyzeConfigService(currentHostAddress));
  108. VitalCompletionRecordService get vitalCompletionRecord =>
  109. findService(() => new VitalCompletionRecordService(currentHostAddress));
  110. VitalContractRecordService get vitalContractRecord =>
  111. findService(() => new VitalContractRecordService(currentHostAddress));
  112. VitalContractTemplateService get vitalContractTemplate =>
  113. findService(() => new VitalContractTemplateService(currentHostAddress));
  114. VitalDeviceService get vitalDevice =>
  115. findService(() => new VitalDeviceService(currentHostAddress));
  116. VitalDiagnosisService get vitalDiagnosis =>
  117. findService(() => new VitalDiagnosisService(currentHostAddress));
  118. VitalDictionaryService get vitalDictionary =>
  119. findService(() => new VitalDictionaryService(currentHostAddress));
  120. VitalDynamicTypeService get vitalDynamicType =>
  121. findService(() => new VitalDynamicTypeService(currentHostAddress));
  122. VitalExamService get vitalExam =>
  123. findService(() => new VitalExamService(currentHostAddress));
  124. VitalFollowUpService get vitalFollowUp =>
  125. findService(() => new VitalFollowUpService(currentHostAddress));
  126. VitalLabelService get vitalLabel =>
  127. findService(() => new VitalLabelService(currentHostAddress));
  128. VitalLoginService get vitalLogin =>
  129. findService(() => new VitalLoginService(currentHostAddress));
  130. VitalOperationLogService get vitalOperationLog =>
  131. findService(() => new VitalOperationLogService(currentHostAddress));
  132. VitalOrganizationService get vitalOrganization =>
  133. findService(() => new VitalOrganizationService(currentHostAddress));
  134. VitalPatientExtensionService get vitalPatientExtension =>
  135. findService(() => new VitalPatientExtensionService(currentHostAddress));
  136. VitalPatientService get vitalPatient =>
  137. findService(() => new VitalPatientService(currentHostAddress));
  138. VitalRegionService get vitalRegion =>
  139. findService(() => new VitalRegionService(currentHostAddress));
  140. VitalReportService get vitalReport =>
  141. findService(() => new VitalReportService(currentHostAddress));
  142. VitalResidenceService get vitalResidence =>
  143. findService(() => new VitalResidenceService(currentHostAddress));
  144. VitalRoleService get vitalRole =>
  145. findService(() => new VitalRoleService(currentHostAddress));
  146. VitalScheduleService get vitalSchedule =>
  147. findService(() => new VitalScheduleService(currentHostAddress));
  148. VitalServicePackService get vitalServicePack =>
  149. findService(() => new VitalServicePackService(currentHostAddress));
  150. VitalStatisticService get vitalStatistic =>
  151. findService(() => new VitalStatisticService(currentHostAddress));
  152. VitalSystemSettingService get vitalSystemSetting =>
  153. findService(() => new VitalSystemSettingService(currentHostAddress));
  154. VitalTeamRegionService get vitalTeamRegion =>
  155. findService(() => new VitalTeamRegionService(currentHostAddress));
  156. VitalTeamService get vitalTeam =>
  157. findService(() => new VitalTeamService(currentHostAddress));
  158. VitalTemplateService get vitalTemplate =>
  159. findService(() => new VitalTemplateService(currentHostAddress));
  160. VitalTownService get vitalTown =>
  161. findService(() => new VitalTownService(currentHostAddress));
  162. VitalUpgradeService get vitalUpgrade =>
  163. findService(() => new VitalUpgradeService(currentHostAddress));
  164. VitalUserFeatureService get vitalUserFeature =>
  165. findService(() => new VitalUserFeatureService(currentHostAddress));
  166. VitalUserPasswordService get vitalUserPassword =>
  167. findService(() => new VitalUserPasswordService(currentHostAddress));
  168. VitalUserService get vitalUser =>
  169. findService(() => new VitalUserService(currentHostAddress));
  170. /* 服务代理设置 End */
  171. /// 设置服务主机地址
  172. void setServerHost(String address, [bool useSSL = false]) {
  173. logger.i('JsonRpcProxy setServerHost :' + address);
  174. _currentProtocol = useSSL ? "https" : "http";
  175. _currentHost = address;
  176. }
  177. /// 添加拦截器
  178. void addInterceptor(JsonRpcInterceptor interceptor) =>
  179. jsonRpcInterceptHost.addInterceptor(interceptor);
  180. /// 清空缓存
  181. void clearCache() => _serviceCache.clear();
  182. /// 查找Service实例
  183. T findService<T extends JsonRpcClientBase>(ServiceBuilder<T> builder) {
  184. Type serviceType = typeOf<T>();
  185. if (!_serviceCache.containsKey(serviceType)) {
  186. _serviceCache[serviceType] = builder.call();
  187. }
  188. return _serviceCache[serviceType] as T;
  189. }
  190. }