o2_api_manager.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. import 'dart:convert' show json;
  2. import 'dart:math';
  3. import 'package:dio/dio.dart' as dio;
  4. import 'package:app_settings/app_settings.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:get/get.dart';
  7. import 'package:jpush_flutter/jpush_flutter.dart';
  8. import '../../environment_config.dart';
  9. import '../index.dart';
  10. ///
  11. /// 全局工具类
  12. /// 全局使用的对象,包含请求API 当前登录用户 当前绑定服务器 等等
  13. ///
  14. class O2ApiManager {
  15. static final O2ApiManager instance = O2ApiManager._internal();
  16. factory O2ApiManager() => instance;
  17. O2ApiManager._internal();
  18. // 当前服务器信息
  19. O2CloudServer? _o2CloudServer;
  20. // 当前连接服务器的center信息
  21. CenterServerInfo? _centerServerInfo;
  22. // 当前登录用户信息
  23. O2Person? _o2user;
  24. // 当前登录用户的组织列表
  25. final List<O2Unit> _myUnitList = [];
  26. // 当前服务器tokenName
  27. String tokenName = O2.defaultTokenName;
  28. // 演示版本使用 服务器列表
  29. List<O2CloudServer> _sampleServerList = List.empty();
  30. // 极光推送 对象
  31. final JPush _jpush = JPush();
  32. // 极光生成的设备id
  33. String _jpushRegistrationID = "";
  34. O2CloudServer? get o2CloudServer {
  35. if (_o2CloudServer == null) {
  36. String unit = SharedPreferenceService.to
  37. .getString(SharedPreferenceService.unitSpKey);
  38. OLogger.d("当前保存的unit: $unit");
  39. if (unit.isNotEmpty) {
  40. _o2CloudServer = O2CloudServer.fromJson(O2Utils.parseStringToJson(unit));
  41. }
  42. }
  43. return _o2CloudServer;
  44. }
  45. CenterServerInfo? get centerServerInfo {
  46. if (_centerServerInfo == null) {
  47. String centerJson = SharedPreferenceService.to
  48. .getString(SharedPreferenceService.centerServerSpKey);
  49. if (centerJson.isNotEmpty) {
  50. _centerServerInfo = CenterServerInfo.fromJson(O2Utils.parseStringToJson(centerJson));
  51. tokenName = _centerServerInfo?.tokenName ?? O2.defaultTokenName;
  52. }
  53. }
  54. return _centerServerInfo;
  55. }
  56. O2Person? get o2User => _o2user;
  57. ({String name, String distinguishedName, String token}) me() {
  58. if (_o2user == null) {
  59. return (name: '', distinguishedName: '', token: '');
  60. }
  61. return (name: _o2user?.name ?? '', distinguishedName: _o2user?.distinguishedName ?? '', token: _o2user?.token ?? '');
  62. }
  63. List<O2Unit> get myUnitList => _myUnitList;
  64. ///
  65. ///极光推送初始化
  66. ///
  67. Future<void> jpushInit() async {
  68. try {
  69. _jpush.setup(
  70. appKey: O2.jPushAppKey, //你自己应用的 AppKey
  71. channel: O2.jPushAppChannel,
  72. production: EnvironmentConfig.isRelease(),
  73. debug: !EnvironmentConfig.isRelease(),
  74. );
  75. // Platform messages may fail, so we use a try/catch PlatformException.
  76. } catch (err, stackTrace) {
  77. OLogger.e('极光推送初始化失败', err, stackTrace);
  78. }
  79. }
  80. /// ios 申请推送权限
  81. void _jpushAuthorityIos() {
  82. _jpush.applyPushAuthority(const NotificationSettingsIOS(
  83. sound: true,
  84. alert: true,
  85. badge: true));
  86. OLogger.d('申请IOS通知权限!');
  87. }
  88. /// 检查 app 是否开启了通知权限
  89. Future<void> jpushCheckIsNotificationEnabled() async {
  90. if (!GetPlatform.isMobile) {
  91. return;
  92. }
  93. if (GetPlatform.isIOS) {
  94. _jpushAuthorityIos();
  95. } else {
  96. final enable = await _jpush.isNotificationEnabled();
  97. OLogger.i('检测 app 是否开启通知权限 $enable');
  98. if (!enable) {
  99. _gotoNotificationSetting();
  100. }
  101. }
  102. }
  103. /// 去系统通知设置页面
  104. void _gotoNotificationSetting() {
  105. final context = Get.context;
  106. if (context!=null) {
  107. O2UI.showConfirm(context, 'common_notification_not_enable_confirm'.tr , okPressed: () => AppSettings.openNotificationSettings());
  108. }
  109. }
  110. /// 清除通知和角标
  111. void jpushClearNotifyBadge() {
  112. _jpush.clearAllNotifications(); // 清除通知
  113. _jpush.setBadge(0); // 清除角标
  114. }
  115. Future<void> sendLocalNotification(
  116. int notificationId, String title, String content) async {
  117. final localNotification = LocalNotification(
  118. id: notificationId,
  119. title: title,
  120. buildId: 1,
  121. content: content,
  122. fireTime: DateTime.now(),
  123. );
  124. _jpush.sendLocalNotification(localNotification).then((res) {
  125. OLogger.i('发送通知失败 $res');
  126. }).catchError((e) {
  127. OLogger.e('发送通知失败 $e');
  128. });
  129. }
  130. /// 极光推送 远程获取设备id
  131. /// 如果极光的 appkey 和包名不匹配 这里获取 id 会卡住 rid 不返回结果
  132. Future<String> getJPushDeviceIdRemote() async {
  133. // 本地存储是否已经有deviceId
  134. String deviceId = SharedPreferenceService.to
  135. .getString(SharedPreferenceService.jpushDeviceIdSpKey);
  136. if (deviceId.isEmpty) {
  137. var rid = await _jpush.getRegistrationID();
  138. if (rid.isNotEmpty) {
  139. _jpushRegistrationID = rid;
  140. SharedPreferenceService.to.putString(
  141. SharedPreferenceService.jpushDeviceIdSpKey, _jpushRegistrationID);
  142. }
  143. OLogger.i("极光推送 get registration id : $_jpushRegistrationID");
  144. } else {
  145. _jpushRegistrationID = deviceId;
  146. }
  147. return _jpushRegistrationID;
  148. }
  149. // 极光推送 设备id
  150. String get deviceID => _jpushRegistrationID;
  151. ///
  152. ///是否管理员
  153. ///
  154. bool isAdministrator() {
  155. if (_o2user == null) {
  156. return false;
  157. }
  158. List<String>? roles = _o2user!.roleList;
  159. if (roles != null && roles.isNotEmpty) {
  160. return roles.where((element) {
  161. if (element.contains('@')) {
  162. var first = element.split('@')[0];
  163. return ((first.toLowerCase() == 'manager' ||
  164. 'CRMManager'.toLowerCase() == first.toLowerCase()));
  165. } else {
  166. return ((element.toLowerCase() == 'manager' ||
  167. 'CRMManager'.toLowerCase() == element.toLowerCase()));
  168. }
  169. }).isNotEmpty;
  170. }
  171. return false;
  172. }
  173. //
  174. O2Person? loadUserFromSP() {
  175. String pJson =
  176. SharedPreferenceService.to.getString(SharedPreferenceService.userSpKey);
  177. if (pJson.isNotEmpty) {
  178. O2Person user = O2Person.fromJson(O2Utils.parseStringToJson(pJson));
  179. _o2user = user;
  180. return user;
  181. }
  182. return null;
  183. }
  184. //初始化当前登录用户信息 登录成功后调用
  185. Future<void> setupUser(O2Person user) async {
  186. await SharedPreferenceService.to.putStringToJsonStringify(
  187. SharedPreferenceService.userSpKey, user.toJson());
  188. _o2user = user;
  189. loadCurrentUserUnitList();
  190. }
  191. /// 加载当前用户的组织列表
  192. Future<void> loadCurrentUserUnitList() async {
  193. _myUnitList.clear();
  194. List<String> ids = [];
  195. if (_o2user?.identityList?.isNotEmpty == true) {
  196. for (var element in _o2user!.identityList!) {
  197. if (element.unit?.isNotEmpty == true) {
  198. ids.add(element.unit!);
  199. }
  200. }
  201. }
  202. if (ids.isNotEmpty) {
  203. final list = await OrganizationControlService.to.unitList(ids);
  204. if (list != null && list.isNotEmpty) {
  205. _myUnitList.addAll(list);
  206. }
  207. }
  208. }
  209. /// 清除用户信息 登出的时候使用
  210. Future<void> cleanUser() async {
  211. await SharedPreferenceService.to
  212. .putString(SharedPreferenceService.userSpKey, '');
  213. _o2user = null;
  214. _myUnitList.clear();
  215. }
  216. ///
  217. /// 设置O2OA服务器连接配置信息
  218. ///
  219. Future<void> putO2UnitJson2SP(O2CloudServer unit) async {
  220. await SharedPreferenceService.to
  221. .putStringToJsonStringify(SharedPreferenceService.unitSpKey, unit);
  222. _o2CloudServer = unit;
  223. }
  224. ///
  225. ///绑定sample服务器 并且重新加载APP
  226. ///
  227. Future putSampleUnitServerAndReload() async {
  228. var cloud = O2CloudServer(
  229. id: 'sample',
  230. name: 'sample.o2oa.net',
  231. centerHost: 'sample.o2oa.net',
  232. centerContext: '/x_program_center',
  233. centerPort: 443,
  234. httpProtocol: 'https');
  235. await O2ApiManager.instance.putO2UnitJson2SP(cloud);
  236. Get.offNamed(O2OARoutes.splash);
  237. }
  238. ///
  239. ///清除绑定信息 重新绑定用
  240. ///
  241. Future<void> cleanO2UnitAndSp() async {
  242. await SharedPreferenceService.to
  243. .putString(SharedPreferenceService.unitSpKey, '');
  244. _o2CloudServer = null;
  245. }
  246. /// 读取o2oa服务器配置信息
  247. Future<String?> _loadServersJsonFile() async {
  248. return await rootBundle.loadString('assets/json/servers.json');
  249. }
  250. /// app 默认配置的服务器地址信息
  251. Future<O2CloudServer?> readAssetsServerJson() async {
  252. String? unitJson = await _loadServersJsonFile();
  253. if (unitJson != null) {
  254. Iterable l = json.decode(unitJson);
  255. List<O2CloudServer> list = List<O2CloudServer>.from(l.map((e) => O2CloudServer.fromJson(e)));
  256. return list.isEmpty ? null : list.first;
  257. }
  258. return null;
  259. }
  260. /// 获取O2OA服务器连接配置信息
  261. /// 查询存储在 sp 中的配置信息,如果没有
  262. /// 直连模式就直接读取 assets/json/servers.json 中的配置, 否则按照默认的绑定模式来
  263. Future<bool> loadO2UnitFromSP() async {
  264. String unit = SharedPreferenceService.to
  265. .getString(SharedPreferenceService.unitSpKey);
  266. OLogger.i("读取到服务器信息: $unit");
  267. if (unit.isNotEmpty) {
  268. _o2CloudServer = O2CloudServer.fromJson(O2Utils.parseStringToJson(unit));
  269. return true;
  270. }
  271. OLogger.e('没有服务器配置信息。。。。');
  272. if (EnvironmentConfig.isDirectConnectMode()) {
  273. OLogger.i("直接连接 模式========");
  274. // 本地没有数据 读取servers.json配置文件
  275. O2CloudServer? server = await readAssetsServerJson();
  276. if (server != null) {
  277. _sampleServerList = [server];
  278. _o2CloudServer = server;
  279. putO2UnitJson2SP(server);
  280. return true;
  281. } else {
  282. OLogger.i("servers.json 读取失败,没有数据!");
  283. return false;
  284. }
  285. }
  286. OLogger.i("bind 模式========");
  287. return false;
  288. }
  289. ///
  290. /// 设置当前连接的O2OA center服务器 以及 application服务器的信息
  291. /// @param centerServerJson
  292. ///
  293. Future<void> putCenterServerJson2SP(String centerServerJson) async {
  294. await SharedPreferenceService.to
  295. .putString(SharedPreferenceService.centerServerSpKey, centerServerJson);
  296. if (centerServerJson.isNotEmpty) {
  297. _centerServerInfo =
  298. CenterServerInfo.fromJson(O2Utils.parseStringToJson(centerServerJson));
  299. tokenName = _centerServerInfo?.tokenName ?? O2.defaultTokenName;
  300. }
  301. }
  302. /// 处理 代理地址
  303. String _urlTransfer2Mapping(String url) {
  304. if (_o2CloudServer == null) {
  305. return url;
  306. }
  307. final urlMapping = _o2CloudServer!.urlMapping;
  308. if (urlMapping == null || urlMapping.isEmpty) {
  309. return url;
  310. }
  311. try {
  312. Map<String, dynamic> urlMap = O2Utils.parseStringToJson(urlMapping);
  313. for (var element in urlMap.entries) {
  314. final key = element.key;
  315. final value = element.value;
  316. if (url.contains(key) && value is String) {
  317. url = url.replaceAll(key, value);
  318. }
  319. }
  320. return url;
  321. } on Exception {
  322. return url;
  323. }
  324. }
  325. ///
  326. /// 获取当前连接的O2OA 中心服务器地址
  327. ///
  328. String? getCenterBaseUrl() {
  329. if (_o2CloudServer == null) {
  330. return null;
  331. }
  332. String? context = _o2CloudServer!.centerContext;
  333. if (context == null || context.isEmpty) {
  334. return null;
  335. }
  336. String url = '${_getProtocol()}://${_o2CloudServer!.centerHost}:${_o2CloudServer!.centerPort}/$context/';
  337. if (context.contains('/')) {
  338. url = '${_getProtocol()}://${_o2CloudServer!.centerHost}:${_o2CloudServer!.centerPort}$context/';
  339. }
  340. return _urlTransfer2Mapping(url);
  341. }
  342. /// web 服务器根地址 比如 http://app.o2oa.net:80
  343. String? webBaseUrl() {
  344. if (_centerServerInfo == null) {
  345. return null;
  346. }
  347. var web = _centerServerInfo?.webServer;
  348. var port = 80;
  349. var host = '';
  350. if (web != null) {
  351. port = web.port ?? 80;
  352. host = web.host ?? '';
  353. }
  354. if (_centerServerInfo?.standalone == true) {
  355. port = _o2CloudServer?.centerPort ?? 80;
  356. host = _o2CloudServer?.centerHost ?? '';
  357. }
  358. String url = "${_getProtocol()}://$host:$port";
  359. return _urlTransfer2Mapping(url);
  360. }
  361. /// http https
  362. String _getProtocol() {
  363. return _o2CloudServer == null
  364. ? 'http'
  365. : _o2CloudServer?.httpProtocol ?? 'http';
  366. }
  367. ///
  368. /// web服务器host
  369. /// 返回比如: dd.o2oa.net | 192.168.1.11
  370. String getWebHost() {
  371. var web = _centerServerInfo?.webServer;
  372. var host = '';
  373. if (web != null) {
  374. host = web.host ?? "";
  375. }
  376. if (_centerServerInfo?.standalone == true) {
  377. host = _o2CloudServer?.centerHost ?? '';
  378. }
  379. return host;
  380. }
  381. /// config.json 配置文件读取的内容
  382. Map<String, dynamic>? configJsonData;
  383. /// 获取前端配置文件
  384. /// /x_desktop/res/config/config.json
  385. Future<Map<String, dynamic>?> getWebConfigJson() async {
  386. if (configJsonData != null) {
  387. return configJsonData;
  388. }
  389. final web = webBaseUrl();
  390. if (web != null) {
  391. String url = "$web/x_desktop/res/config/config.json";
  392. url = _urlTransfer2Mapping(url);
  393. configJsonData = await _loadWebConfigJsonData(url);
  394. }
  395. return configJsonData;
  396. }
  397. /// 请求在线 app 版本信息
  398. Future<Map<String, dynamic>?> _loadWebConfigJsonData(String jsonUrl) async {
  399. try {
  400. final r = Random();
  401. final s = r.nextInt(1000); // 添加一个随机数 防止缓存
  402. String url = '$jsonUrl?t=$s';
  403. dio.Response<dynamic> response = await O2HttpClient.instance.getOuter(url);
  404. return response.data;
  405. } catch (err, stackTrace) {
  406. OLogger.e('读取 config.json 配置', err, stackTrace);
  407. }
  408. return null;
  409. }
  410. ///工作表单URL草稿模式 draft对象
  411. String? getProcessDraftUrl(String draft) {
  412. if (_centerServerInfo == null) {
  413. return null;
  414. }
  415. final web = webBaseUrl();
  416. if (web != null) {
  417. String url = "$web/x_desktop/workmobilewithaction.html?draft=$draft";
  418. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  419. if (isDebugger) {
  420. url += "&debugger";
  421. }
  422. return _urlTransfer2Mapping(url);
  423. }
  424. return null;
  425. }
  426. ///工作表单URL 草稿模式 draftId
  427. String? getProcessDraftUrlById(String draftId) {
  428. if (_centerServerInfo == null) {
  429. return null;
  430. }
  431. final web = webBaseUrl();
  432. if (web != null) {
  433. String url = "$web/x_desktop/workmobilewithaction.html?draftId=$draftId";
  434. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  435. if (isDebugger) {
  436. url += "&debugger";
  437. }
  438. return _urlTransfer2Mapping(url);
  439. }
  440. return null;
  441. }
  442. String? getAttendanceCheckUrl() {
  443. if (_centerServerInfo == null) {
  444. return null;
  445. }
  446. final web = webBaseUrl();
  447. if (web != null) {
  448. String url = "$web/x_desktop/appMobile.html?app=attendancev2&option={\"route\":\"mobile\"}";
  449. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  450. if (isDebugger) {
  451. url += "&debugger";
  452. }
  453. return _urlTransfer2Mapping(url);
  454. }
  455. return null;
  456. }
  457. ///
  458. ///工作表单URL
  459. ///
  460. String? getWorkUrl(String workId) {
  461. if (_centerServerInfo == null) {
  462. return null;
  463. }
  464. final web = webBaseUrl();
  465. if (web != null) {
  466. String url = "$web/x_desktop/workmobilewithaction.html?workid=$workId";
  467. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  468. if (isDebugger) {
  469. url += "&debugger";
  470. }
  471. return _urlTransfer2Mapping(url);
  472. }
  473. return null;
  474. }
  475. ///
  476. ///工作表单URL
  477. ///
  478. String? getWorkUrlInPC(String workId) {
  479. if (_centerServerInfo == null) {
  480. return null;
  481. }
  482. final web = webBaseUrl();
  483. if (web != null) {
  484. String url = "$web/x_desktop/work.html?workid=$workId";
  485. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  486. if (isDebugger) {
  487. url += "&debugger";
  488. }
  489. return _urlTransfer2Mapping(url);
  490. }
  491. return null;
  492. }
  493. ///
  494. ///已完成的工作表单URL
  495. ///
  496. String? getWorkCompletedUrl(String workcompletedId) {
  497. final web = webBaseUrl();
  498. if (web != null) {
  499. String url = "$web/x_desktop/workmobilewithaction.html?workcompletedid=$workcompletedId";
  500. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  501. if (isDebugger) {
  502. url += "&debugger";
  503. }
  504. return _urlTransfer2Mapping(url);
  505. }
  506. return null;
  507. }
  508. ///
  509. /// 门户应用地址
  510. ///
  511. String? getPortalUrl(String portalId, {String? pageId, String? portalParameters}) {
  512. final web = webBaseUrl();
  513. if (web != null) {
  514. String url = "$web/x_desktop/portalmobile.html?id=$portalId";
  515. if (pageId?.isNotEmpty == true) {
  516. url += "&page=$pageId";
  517. }
  518. if (portalParameters?.isNotEmpty == true) {
  519. url += "&parameters=$portalParameters";
  520. }
  521. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  522. if (isDebugger) {
  523. url += "&debugger";
  524. }
  525. return _urlTransfer2Mapping(url);
  526. }
  527. return null;
  528. }
  529. ///
  530. /// cms 文档地址
  531. ///
  532. String? getCmsDocumentUrl(String documentId) {
  533. final web = webBaseUrl();
  534. if (web != null) {
  535. String url = "$web/x_desktop/cmsdocMobile.html?id=$documentId";
  536. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  537. if (isDebugger) {
  538. url += "&debugger";
  539. }
  540. return _urlTransfer2Mapping(url);
  541. }
  542. return null;
  543. }
  544. ///
  545. /// cms 文档地址 可以编辑的
  546. ///
  547. String? getCmsDocumentEditUrl(String documentId) {
  548. final web = webBaseUrl();
  549. if (web != null) {
  550. String url = "$web/x_desktop/cmsdocmobilewithaction.html?id=$documentId";
  551. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  552. if (isDebugger) {
  553. url += "&debugger";
  554. }
  555. return _urlTransfer2Mapping(url);
  556. }
  557. return null;
  558. }
  559. ///
  560. /// bbs 主题地址
  561. ///
  562. String? getBBSSubjectUrl(String documentId) {
  563. final web = webBaseUrl();
  564. if (web != null) {
  565. String url = "$web/x_desktop/forumdocMobile.html?id=$documentId&page=1";
  566. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  567. if (isDebugger) {
  568. url += "&debugger";
  569. }
  570. return _urlTransfer2Mapping(url);
  571. }
  572. return null;
  573. }
  574. /// 热图图片地址
  575. ///
  576. /// http://host:port/x_file_assemble_control/jaxrs/file/${pId}/download/stream
  577. String? getHotPictureUrl(String pid) {
  578. final fileBaseUrl =
  579. getModuleBaseUrl(O2DistributeModuleEnum.x_file_assemble_control);
  580. if (fileBaseUrl == null) {
  581. return null;
  582. }
  583. String url = '${fileBaseUrl}jaxrs/file/$pid/download/stream';
  584. return _urlTransfer2Mapping(url);
  585. }
  586. /// 门户icon地址
  587. String? getPortalIconUrl(String portalId) {
  588. final portalBaseUrl =
  589. getModuleBaseUrl(O2DistributeModuleEnum.x_portal_assemble_surface);
  590. if (portalBaseUrl == null) {
  591. return null;
  592. }
  593. String url = '${portalBaseUrl}jaxrs/portal/$portalId/icon';
  594. return _urlTransfer2Mapping(url);
  595. }
  596. /// 文件地址
  597. String getFileURL(String? fileId) {
  598. //http://dev.o2oa.net:20020/x_file_assemble_control/jaxrs/file/b871a896-93f7-4245-8e5a-100fd4a67d9d/download/stream
  599. String? baseUrl =
  600. getModuleBaseUrl(O2DistributeModuleEnum.x_file_assemble_control);
  601. if (fileId != null &&
  602. fileId != 'null' &&
  603. fileId.isNotEmpty &&
  604. baseUrl != null &&
  605. baseUrl.isNotEmpty) {
  606. String url = '${baseUrl}jaxrs/file/$fileId/download/stream';
  607. return _urlTransfer2Mapping(url);
  608. } else {
  609. return '';
  610. }
  611. }
  612. /// 获取websocket地址
  613. String? websocketUrl() {
  614. var serverInfo =
  615. _centerServerInfo?.assembles?.x_message_assemble_communicate;
  616. if (serverInfo == null) {
  617. return null;
  618. }
  619. String tokenName = O2ApiManager.instance.tokenName;
  620. String token = O2ApiManager.instance.o2User?.token ?? '';
  621. if (tokenName.isEmpty || token.isEmpty) {
  622. return null;
  623. }
  624. String protocol = _getProtocol() == 'https' ? 'wss' : 'ws';
  625. var port = serverInfo.port;
  626. var host = serverInfo.host;
  627. if (_centerServerInfo?.standalone == true) {
  628. port = _o2CloudServer?.centerPort;
  629. host = _o2CloudServer?.centerHost;
  630. }
  631. String url =
  632. "$protocol://$host:$port${serverInfo.context}/ws/collaboration?$tokenName=$token";
  633. return _urlTransfer2Mapping(url);
  634. }
  635. ///
  636. /// 获取模块的url地址
  637. ///
  638. String? getModuleBaseUrl(O2DistributeModuleEnum module) {
  639. if (_centerServerInfo == null) {
  640. return null;
  641. }
  642. ModuleServerInfo? serverInfo;
  643. switch (module) {
  644. case O2DistributeModuleEnum.x_file_assemble_control:
  645. serverInfo = _centerServerInfo?.assembles?.x_file_assemble_control;
  646. break;
  647. case O2DistributeModuleEnum.x_meeting_assemble_control:
  648. serverInfo = _centerServerInfo?.assembles?.x_meeting_assemble_control;
  649. break;
  650. case O2DistributeModuleEnum.x_attendance_assemble_control:
  651. serverInfo =
  652. _centerServerInfo?.assembles?.x_attendance_assemble_control;
  653. break;
  654. case O2DistributeModuleEnum.x_bbs_assemble_control:
  655. serverInfo = _centerServerInfo?.assembles?.x_bbs_assemble_control;
  656. break;
  657. case O2DistributeModuleEnum.x_hotpic_assemble_control:
  658. serverInfo = _centerServerInfo?.assembles?.x_hotpic_assemble_control;
  659. break;
  660. case O2DistributeModuleEnum.x_processplatform_service_processing:
  661. serverInfo =
  662. _centerServerInfo?.assembles?.x_processplatform_service_processing;
  663. break;
  664. case O2DistributeModuleEnum.x_processplatform_assemble_bam:
  665. serverInfo =
  666. _centerServerInfo?.assembles?.x_processplatform_assemble_bam;
  667. break;
  668. case O2DistributeModuleEnum.x_cms_assemble_control:
  669. serverInfo = _centerServerInfo?.assembles?.x_cms_assemble_control;
  670. break;
  671. case O2DistributeModuleEnum.x_organization_assemble_control:
  672. serverInfo =
  673. _centerServerInfo?.assembles?.x_organization_assemble_control;
  674. break;
  675. case O2DistributeModuleEnum.x_organization_assemble_custom:
  676. serverInfo =
  677. _centerServerInfo?.assembles?.x_organization_assemble_custom;
  678. break;
  679. case O2DistributeModuleEnum.x_processplatform_assemble_surface:
  680. serverInfo =
  681. _centerServerInfo?.assembles?.x_processplatform_assemble_surface;
  682. break;
  683. case O2DistributeModuleEnum.x_organization_assemble_express:
  684. serverInfo =
  685. _centerServerInfo?.assembles?.x_organization_assemble_express;
  686. break;
  687. case O2DistributeModuleEnum.x_organization_assemble_personal:
  688. serverInfo =
  689. _centerServerInfo?.assembles?.x_organization_assemble_personal;
  690. break;
  691. case O2DistributeModuleEnum.x_component_assemble_control:
  692. serverInfo = _centerServerInfo?.assembles?.x_component_assemble_control;
  693. break;
  694. case O2DistributeModuleEnum.x_processplatform_assemble_designer:
  695. serverInfo =
  696. _centerServerInfo?.assembles?.x_processplatform_assemble_designer;
  697. break;
  698. case O2DistributeModuleEnum.x_organization_assemble_authentication:
  699. serverInfo = _centerServerInfo
  700. ?.assembles?.x_organization_assemble_authentication;
  701. break;
  702. case O2DistributeModuleEnum.x_portal_assemble_surface:
  703. serverInfo = _centerServerInfo?.assembles?.x_portal_assemble_surface;
  704. break;
  705. case O2DistributeModuleEnum.x_calendar_assemble_control:
  706. serverInfo = _centerServerInfo?.assembles?.x_calendar_assemble_control;
  707. break;
  708. case O2DistributeModuleEnum.x_mind_assemble_control:
  709. serverInfo = _centerServerInfo?.assembles?.x_mind_assemble_control;
  710. break;
  711. case O2DistributeModuleEnum.x_teamwork_assemble_control:
  712. serverInfo = _centerServerInfo?.assembles?.x_teamwork_assemble_control;
  713. break;
  714. case O2DistributeModuleEnum.x_wcrm_assemble_control:
  715. serverInfo = _centerServerInfo?.assembles?.x_wcrm_assemble_control;
  716. break;
  717. case O2DistributeModuleEnum.x_jpush_assemble_control:
  718. serverInfo = _centerServerInfo?.assembles?.x_jpush_assemble_control;
  719. break;
  720. case O2DistributeModuleEnum.x_message_assemble_communicate:
  721. serverInfo =
  722. _centerServerInfo?.assembles?.x_message_assemble_communicate;
  723. break;
  724. case O2DistributeModuleEnum.x_organizationPermission:
  725. serverInfo = _centerServerInfo?.assembles?.x_organizationPermission;
  726. break;
  727. case O2DistributeModuleEnum.x_pan_assemble_control:
  728. serverInfo = _centerServerInfo?.assembles?.x_pan_assemble_control;
  729. break;
  730. case O2DistributeModuleEnum.x_query_assemble_surface:
  731. serverInfo = _centerServerInfo?.assembles?.x_query_assemble_surface;
  732. break;
  733. case O2DistributeModuleEnum.x_app_packaging_client_assemble_control:
  734. serverInfo = _centerServerInfo?.assembles?.x_app_packaging_client_assemble_control;
  735. break;
  736. }
  737. if (serverInfo == null) {
  738. return null;
  739. }
  740. var port = serverInfo.port;
  741. var host = serverInfo.host;
  742. if (_centerServerInfo?.standalone == true) {
  743. port = _o2CloudServer?.centerPort;
  744. host = _o2CloudServer?.centerHost;
  745. }
  746. String url =
  747. "${_getProtocol()}://$host:$port${serverInfo.context}/";
  748. return _urlTransfer2Mapping(url);
  749. }
  750. }