x_organization_assemble_control.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import 'dart:math';
  2. import 'package:dio/dio.dart';
  3. import 'package:get/get.dart';
  4. import '../models/index.dart';
  5. import '../utils/index.dart';
  6. import '../values/index.dart';
  7. ///
  8. ///组织人员服务
  9. ///
  10. class OrganizationControlService extends GetxService {
  11. static OrganizationControlService get to => Get.find();
  12. //
  13. String baseUrl() {
  14. return O2ApiManager.instance.getModuleBaseUrl(
  15. O2DistributeModuleEnum.x_organization_assemble_control) ?? '';
  16. }
  17. ///人员头像地址
  18. String iconUrl(String? person) {
  19. if (person == null || person.isEmpty) {
  20. return '';
  21. }
  22. final r = Random();
  23. final s = r.nextInt(1000);
  24. return '${baseUrl()}jaxrs/person/$person/icon?$s';
  25. }
  26. /// 组织对象查询
  27. /// jaxrs/unit/list/like
  28. ///
  29. Future<List<O2Unit>?> unitSearch(String key) async {
  30. try {
  31. var body = {
  32. "key": key
  33. };
  34. ApiResponse response =
  35. await O2HttpClient.instance.put('${baseUrl()}jaxrs/unit/list/like', body);
  36. var list = response.data == null ? [] : response.data as List;
  37. return list.map((i) => O2Unit.fromJson(i)).toList();
  38. } catch (err, stackTrace) {
  39. OLogger.e('搜索组织失败', err, stackTrace);
  40. }
  41. return null;
  42. }
  43. /// 用户对象查询
  44. /// jaxrs/person/list/like
  45. ///
  46. Future<List<O2Person>?> personSearch(String key, {CancelToken? cancelToken}) async {
  47. try {
  48. var body = {
  49. "key": key
  50. };
  51. ApiResponse response =
  52. await O2HttpClient.instance.put('${baseUrl()}jaxrs/person/list/like', body, cancelToken: cancelToken);
  53. var list = response.data == null ? [] : response.data as List;
  54. return list.map((i) => O2Person.fromJson(i)).toList();
  55. } catch (err, stackTrace) {
  56. OLogger.e('搜索用户失败', err, stackTrace);
  57. }
  58. return null;
  59. }
  60. /// 用户对象查询
  61. /// jaxrs/person/{person}
  62. ///
  63. Future<O2Person?> person(String person) async {
  64. try {
  65. ApiResponse response =
  66. await O2HttpClient.instance.get('${baseUrl()}jaxrs/person/$person');
  67. return O2Person.fromJson(response.data);
  68. } catch (err, stackTrace) {
  69. OLogger.e('查询用户对象失败', err, stackTrace);
  70. }
  71. return null;
  72. }
  73. ///顶级组织
  74. ///jaxrs/unit/list/top
  75. ///
  76. Future<List<O2Unit>?> unitTopList() async {
  77. try {
  78. ApiResponse response =
  79. await O2HttpClient.instance.get('${baseUrl()}jaxrs/unit/list/top');
  80. var list = response.data == null ? [] : response.data as List;
  81. return list.map((group) => O2Unit.fromJson(group)).toList();
  82. } catch (err, stackTrace) {
  83. OLogger.e('查询顶级组织失败', err, stackTrace);
  84. }
  85. return null;
  86. }
  87. ///
  88. /// 下级组织列表
  89. /// jaxrs/unit/list/{UnitDistinguishedName}/sub/direct
  90. ///
  91. Future<List<O2Unit>?> unitListWithParent(String parentUnit) async {
  92. try {
  93. ApiResponse response =
  94. await O2HttpClient.instance.get('${baseUrl()}jaxrs/unit/list/$parentUnit/sub/direct');
  95. var list = response.data == null ? [] : response.data as List;
  96. return list.map((group) => O2Unit.fromJson(group)).toList();
  97. } catch (err, stackTrace) {
  98. OLogger.e('查询下级组织列表失败', err, stackTrace);
  99. }
  100. return null;
  101. }
  102. ///
  103. /// 组织下身份列表
  104. ////jaxrs/identity/list/unit/{UnitDistinguishedName}
  105. Future<List<O2Identity>?> identityListWithUnit(String unit) async {
  106. try {
  107. ApiResponse response =
  108. await O2HttpClient.instance.get('${baseUrl()}jaxrs/identity/list/unit/$unit');
  109. var list = response.data == null ? [] : response.data as List;
  110. return list.map((group) => O2Identity.fromJson(group)).toList();
  111. } catch (err, stackTrace) {
  112. OLogger.e('查询组织下身份列表失败', err, stackTrace);
  113. }
  114. return null;
  115. }
  116. ///
  117. /// 列示人员的所有身份信息
  118. /// jaxrs/identity/list/person/
  119. ///
  120. Future<List<O2Identity>?> identityListByPerson(String person) async {
  121. try {
  122. ApiResponse response =
  123. await O2HttpClient.instance.get('${baseUrl()}jaxrs/identity/list/person/$person');
  124. var list = response.data == null ? [] : response.data as List;
  125. return list.map((i) => O2Identity.fromJson(i)).toList();
  126. } catch (err, stackTrace) {
  127. OLogger.e('列示人员的所有身份信息失败', err, stackTrace);
  128. }
  129. return null;
  130. }
  131. ///
  132. /// 根据请求id返回组织列表
  133. /// @param body {"unitList":[]}
  134. ///
  135. Future<List<O2Unit>?> unitList(List<String> unitList) async {
  136. try {
  137. final body = {
  138. 'unitList': unitList
  139. };
  140. ApiResponse response =
  141. await O2HttpClient.instance.post('${baseUrl()}jaxrs/unit/list', body);
  142. var list = response.data == null ? [] : response.data as List;
  143. return list.map((group) => O2Unit.fromJson(group)).toList();
  144. } catch (err, stackTrace) {
  145. OLogger.e('根据请求id返回组织失败', err, stackTrace);
  146. }
  147. return null;
  148. }
  149. ///
  150. /// 根据组织类型查询组织, 如果没有组织类型 用上面两个接口 ,有组织类型就用这个接口
  151. /// body:{"type":"一级部门","unitList":[]}
  152. ///
  153. Future<List<O2Unit>?> unitListByType(String type) async {
  154. try {
  155. final body = {
  156. 'type': type
  157. };
  158. ApiResponse response =
  159. await O2HttpClient.instance.post('${baseUrl()}jaxrs/unit/list', body);
  160. var list = response.data == null ? [] : response.data as List;
  161. return list.map((group) => O2Unit.fromJson(group)).toList();
  162. } catch (err, stackTrace) {
  163. OLogger.e('组织类型查询组织失败', err, stackTrace);
  164. }
  165. return null;
  166. }
  167. /// 分页查询 群组列表
  168. ///
  169. /// [lastId] 传入列表最后一个对象的id, 第一页传默认 O2.o2DefaultPageFirstKey
  170. /// [limit] 每页数量
  171. Future<List<O2Group>?> getGroupListByPage(String lastId, { int limit = O2.o2DefaultPageSize}) async {
  172. try {
  173. ApiResponse response =
  174. await O2HttpClient.instance.get('${baseUrl()}jaxrs/group/list/$lastId/next/$limit');
  175. var list = response.data == null ? [] : response.data as List;
  176. return list.map((group) => O2Group.fromJson(group)).toList();
  177. } catch (err, stackTrace) {
  178. OLogger.e('查询群组列表失败', err, stackTrace);
  179. }
  180. return null;
  181. }
  182. }