x_bbs_assemble_control.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import 'dart:io';
  2. import 'package:get/get.dart';
  3. import '../models/index.dart';
  4. import '../utils/index.dart';
  5. import '../values/index.dart';
  6. ///
  7. /// 论坛服务
  8. ///
  9. class BBSAssembleControlService extends GetxService {
  10. static BBSAssembleControlService get to => Get.find();
  11. String baseUrl() {
  12. return O2ApiManager.instance
  13. .getModuleBaseUrl(O2DistributeModuleEnum.x_bbs_assemble_control) ??
  14. '';
  15. }
  16. ///
  17. /// 论坛附件下载地址
  18. ///
  19. String getBBSAttachmentURL( String attachmentId) {
  20. return "${baseUrl()}jaxrs/attachment/download/$attachmentId/stream/true";
  21. }
  22. /// 板块权限查询.
  23. Future<SectionPermissionInfo?> sectionPermission(String sectionId) async {
  24. try {
  25. ApiResponse response =
  26. await O2HttpClient.instance.get('${baseUrl()}jaxrs/permission/section/$sectionId');
  27. return SectionPermissionInfo.fromJson(response.data);
  28. } catch (err, stackTrace) {
  29. OLogger.e('查询板块权限失败', err, stackTrace);
  30. }
  31. return null;
  32. }
  33. /// 主题帖子权限查询.
  34. Future<SubjectPermissionInfo?> subjectPermission(String subjectId) async {
  35. try {
  36. ApiResponse response =
  37. await O2HttpClient.instance.get('${baseUrl()}jaxrs/permission/subject/$subjectId');
  38. return SubjectPermissionInfo.fromJson(response.data);
  39. } catch (err, stackTrace) {
  40. OLogger.e('查询主题帖子权限失败', err, stackTrace);
  41. }
  42. return null;
  43. }
  44. /// 板块对象查询
  45. Future<SectionInfoList?> getSectionInfo(String sectionId) async {
  46. try {
  47. ApiResponse response =
  48. await O2HttpClient.instance.get('${baseUrl()}jaxrs/section/$sectionId');
  49. return SectionInfoList.fromJson(response.data);
  50. } catch (err, stackTrace) {
  51. OLogger.e('查询板块失败', err, stackTrace);
  52. }
  53. return null;
  54. }
  55. /// 获取登录者可以访问到的所有ForumInfo的信息列表.
  56. Future<List<ForumInfo>?> mobileFormuInfoAllList() async {
  57. try {
  58. ApiResponse response =
  59. await O2HttpClient.instance.get('${baseUrl()}jaxrs/mobile/view/all');
  60. var list = response.data == null ? [] : response.data as List;
  61. return list.map((group) => ForumInfo.fromJson(group)).toList();
  62. } catch (err, stackTrace) {
  63. OLogger.e('查询ForumInfo列表失败', err, stackTrace);
  64. }
  65. return null;
  66. }
  67. ///
  68. /// 分页查询主题列表
  69. ///
  70. Future<List<SubjectInfo>?> subjectListByPage(String sectionId, int page, {int limit = O2.o2DefaultPageSize, bool withTopSubject = true}) async {
  71. try {
  72. Map<String, dynamic> data = {
  73. "withTopSubject": withTopSubject,
  74. "sectionId": sectionId
  75. };
  76. ApiResponse response = await O2HttpClient.instance
  77. .put('${baseUrl()}jaxrs/subject/filter/list/page/$page/count/$limit', data);
  78. var list = response.data == null ? [] : response.data as List;
  79. return list.map((group) => SubjectInfo.fromJson(group)).toList();
  80. } catch (err, stackTrace) {
  81. OLogger.e('查询主题列表失败', err, stackTrace);
  82. }
  83. return null;
  84. }
  85. ///
  86. /// 上传文件.
  87. ///
  88. Future<IdData?> uploadAttachment(String subjectId, File file) async {
  89. try {
  90. ApiResponse response =
  91. await O2HttpClient.instance.postUploadFile('${baseUrl()}jaxrs/attachment/upload/subject/$subjectId', file, body: {'site': subjectId});
  92. return IdData.fromJson(response.data);
  93. } catch (err, stackTrace) {
  94. OLogger.e('上传附件失败', err, stackTrace);
  95. }
  96. return null;
  97. }
  98. /// 发帖
  99. Future<IdData?> subjectPublish(SubjectInfo post) async {
  100. try {
  101. ApiResponse response =
  102. await O2HttpClient.instance.post('${baseUrl()}jaxrs/user/subject', post.toJson());
  103. return IdData.fromJson(response.data);
  104. } catch (err, stackTrace) {
  105. OLogger.e('发帖失败', err, stackTrace);
  106. }
  107. return null;
  108. }
  109. /// 删除帖子.
  110. Future<IdData?> deleteSubject(String subjectId) async {
  111. try {
  112. ApiResponse response =
  113. await O2HttpClient.instance.delete('${baseUrl()}jaxrs/user/subject/$subjectId');
  114. return IdData.fromJson(response.data);
  115. } catch (err, stackTrace) {
  116. OLogger.e('删除帖子失败', err, stackTrace);
  117. }
  118. return null;
  119. }
  120. ///
  121. /// 回复帖子
  122. ///
  123. Future<IdData?> replaySubject(ReplyFormJson post) async {
  124. try {
  125. ApiResponse response =
  126. await O2HttpClient.instance.post('${baseUrl()}jaxrs/user/reply', post.toJson());
  127. return IdData.fromJson(response.data);
  128. } catch (err, stackTrace) {
  129. OLogger.e('回复帖子失败', err, stackTrace);
  130. }
  131. return null;
  132. }
  133. ///
  134. /// 回复对象.
  135. ///
  136. Future<SubjectReplyInfoJson?> getReplyInfo(String replyId) async {
  137. try {
  138. ApiResponse response =
  139. await O2HttpClient.instance.get('${baseUrl()}jaxrs/reply/$replyId');
  140. return SubjectReplyInfoJson.fromJson(response.data);
  141. } catch (err, stackTrace) {
  142. OLogger.e('查询回复失败', err, stackTrace);
  143. }
  144. return null;
  145. }
  146. }