facility_repository.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import 'dart:typed_data';
  2. import 'package:domain/entity/feedback_detail_entity.dart';
  3. import 'package:domain/entity/form_option_entity.dart';
  4. import 'package:plugin_basic/constants/app_constant.dart';
  5. import 'package:plugin_platform/platform_export.dart';
  6. import 'package:plugin_platform/http/dio_engine.dart';
  7. import 'package:plugin_platform/http/http_result.dart';
  8. import 'package:riverpod_annotation/riverpod_annotation.dart';
  9. import 'package:shared/utils/date_time_utils.dart';
  10. import 'package:shared/utils/log_utils.dart';
  11. import 'package:shared/utils/util.dart';
  12. import '../constants/api_constants.dart';
  13. import 'package:flutter_riverpod/flutter_riverpod.dart';
  14. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  15. import '../entity/facility_book_entity.dart';
  16. import '../entity/facility_index_entity.dart';
  17. import '../entity/facility_page_entity.dart';
  18. import '../entity/form_content_entity.dart';
  19. import '../entity/form_detail_entity.dart';
  20. import '../entity/form_list_entity.dart';
  21. import '../entity/form_submitted_page_entity.dart';
  22. import '../entity/id_name_entity.dart';
  23. part 'facility_repository.g.dart';
  24. @Riverpod(keepAlive: true)
  25. FacilityRepository facilityRepository(Ref ref) {
  26. final dioEngine = ref.watch(dioEngineProvider);
  27. return FacilityRepository(dioEngine: dioEngine);
  28. }
  29. /*
  30. * 设施的数据仓库
  31. */
  32. class FacilityRepository {
  33. DioEngine dioEngine;
  34. FacilityRepository({required this.dioEngine});
  35. /// 获取设施可申请的列表
  36. Future<HttpResult<FacilityIndexEntity>> fetchFacilityList({
  37. CancelToken? cancelToken,
  38. }) async {
  39. final result = await dioEngine.requestNetResult(
  40. ApiConstants.apiFacilityList,
  41. method: HttpMethod.GET,
  42. cancelToken: cancelToken,
  43. );
  44. if (result.isSuccess) {
  45. final jsonList = result.getListJson();
  46. //获取List数据 需要转换一次
  47. var list = jsonList
  48. ?.map((value) {
  49. if (value is Map<String, dynamic>) {
  50. return FacilityIndexEntity.fromJson(value);
  51. } else {
  52. return null;
  53. }
  54. })
  55. .where((item) => item != null)
  56. .cast<FacilityIndexEntity>()
  57. .toList();
  58. return result.convert<FacilityIndexEntity>(list: list);
  59. }
  60. return result.convert<FacilityIndexEntity>();
  61. }
  62. /// 获取设施的指定日期的表
  63. Future<HttpResult<FacilityBookEntity>> fetchFacilityDateDetail({
  64. required String? id,
  65. required DateTime? date,
  66. CancelToken? cancelToken,
  67. }) async {
  68. Map<String, String> params = {};
  69. params['type_id'] = id ?? "";
  70. if (date != null) {
  71. params['date'] = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  72. }
  73. final result = await dioEngine.requestNetResult(
  74. ApiConstants.apiFacilityDate,
  75. params: params,
  76. method: HttpMethod.GET,
  77. cancelToken: cancelToken,
  78. );
  79. if (result.isSuccess) {
  80. final json = result.getDataJson();
  81. var data = FacilityBookEntity.fromJson(json!);
  82. return result.convert<FacilityBookEntity>(data: data);
  83. }
  84. return result.convert();
  85. }
  86. /// 预约设施
  87. Future<HttpResult<FacilityDetail>> submitBooking({
  88. required String? periodId,
  89. required DateTime date,
  90. CancelToken? cancelToken,
  91. }) async {
  92. Map<String, String> params = {};
  93. params["period_id"] = periodId ?? "";
  94. params["date"] = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  95. final result = await dioEngine.requestNetResult(
  96. ApiConstants.apiFacilityBook,
  97. params: params,
  98. method: HttpMethod.POST,
  99. isShowLoadingDialog: true,
  100. networkDebounce: true,
  101. cancelToken: cancelToken,
  102. );
  103. if (result.isSuccess) {
  104. final json = result.getDataJson();
  105. var data = FacilityDetail.fromJson(json!);
  106. return result.convert<FacilityDetail>(data: data);
  107. }
  108. return result.convert();
  109. }
  110. /// 获取已经申请的设施可用列表
  111. Future<HttpResult<FacilityPageEntity>> fetchFacilityActiveList({
  112. required int curPage,
  113. CancelToken? cancelToken,
  114. }) async {
  115. Map<String, String> params = {};
  116. params['page'] = curPage.toString();
  117. params['limit'] = "10";
  118. final result = await dioEngine.requestNetResult(
  119. ApiConstants.apiFacilityActiveList,
  120. params: params,
  121. method: HttpMethod.GET,
  122. cancelToken: cancelToken,
  123. );
  124. if (result.isSuccess) {
  125. final json = result.getDataJson();
  126. var data = FacilityPageEntity.fromJson(json!);
  127. return result.convert<FacilityPageEntity>(data: data);
  128. }
  129. return result.convert();
  130. }
  131. /// 获取已经申请的设施押金列表
  132. Future<HttpResult<FacilityPageEntity>> fetchFacilityDepositList({
  133. required int curPage,
  134. CancelToken? cancelToken,
  135. }) async {
  136. Map<String, String> params = {};
  137. params['page'] = curPage.toString();
  138. params['limit'] = "10";
  139. final result = await dioEngine.requestNetResult(
  140. ApiConstants.apiFacilityDepositList,
  141. params: params,
  142. method: HttpMethod.GET,
  143. cancelToken: cancelToken,
  144. );
  145. if (result.isSuccess) {
  146. final json = result.getDataJson();
  147. var data = FacilityPageEntity.fromJson(json!);
  148. return result.convert<FacilityPageEntity>(data: data);
  149. }
  150. return result.convert();
  151. }
  152. /// 获取已经申请的设施历史列表
  153. Future<HttpResult<FacilityPageEntity>> fetchFacilityHistoryList({
  154. required int curPage,
  155. CancelToken? cancelToken,
  156. }) async {
  157. Map<String, String> params = {};
  158. params['page'] = curPage.toString();
  159. params['limit'] = "10";
  160. final result = await dioEngine.requestNetResult(
  161. ApiConstants.apiFacilityHistoryList,
  162. params: params,
  163. method: HttpMethod.GET,
  164. cancelToken: cancelToken,
  165. );
  166. if (result.isSuccess) {
  167. final json = result.getDataJson();
  168. var data = FacilityPageEntity.fromJson(json!);
  169. return result.convert<FacilityPageEntity>(data: data);
  170. }
  171. return result.convert();
  172. }
  173. /// 获取预约Booking的详情
  174. Future<HttpResult<FacilityDetail>> fetchFacilityBookingDetail({
  175. required String? id,
  176. CancelToken? cancelToken,
  177. }) async {
  178. Map<String, String> params = {};
  179. params['id'] = id ?? "";
  180. final result = await dioEngine.requestNetResult(
  181. ApiConstants.apiFacilityBookingDetail,
  182. params: params,
  183. isShowLoadingDialog: true,
  184. networkDebounce: true,
  185. method: HttpMethod.GET,
  186. cancelToken: cancelToken,
  187. );
  188. if (result.isSuccess) {
  189. final json = result.getDataJson();
  190. var data = FacilityDetail.fromJson(json!);
  191. return result.convert<FacilityDetail>(data: data);
  192. }
  193. return result.convert();
  194. }
  195. }