other_repository.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'package:domain/entity/response/device_list_entity.dart';
  2. import 'package:domain/entity/response/fiance_report_entity.dart';
  3. import 'package:domain/entity/response/labour_report_entity.dart';
  4. import 'package:domain/entity/response/staff_request_report_entity.dart';
  5. import 'package:get/get.dart';
  6. import 'package:plugin_platform/dio_export.dart';
  7. import 'package:plugin_platform/http/http_provider.dart';
  8. import 'package:plugin_platform/http/http_result.dart';
  9. import 'package:shared/utils/util.dart';
  10. import '../constants/api_constants.dart';
  11. /// 报表与其他的相关数据
  12. class OtherRepository extends GetxService {
  13. HttpProvider httpProvider;
  14. OtherRepository({required this.httpProvider});
  15. // 雇主的设备列表
  16. Future<HttpResult<DeviceListEntity>> fetchDeviceList({
  17. required int curPage,
  18. CancelToken? cancelToken,
  19. }) async {
  20. //参数
  21. Map<String, String> params = {};
  22. params["cur_page"] = curPage.toString();
  23. params["page_size"] = "10";
  24. final result = await httpProvider.requestNetResult(
  25. ApiConstants.apiDeviceList,
  26. params: params,
  27. cancelToken: cancelToken,
  28. );
  29. //根据返回的结果,封装原始数据为Bean/Entity对象
  30. if (result.isSuccess) {
  31. //重新赋值data或list
  32. final json = result.getDataJson();
  33. var data = DeviceListEntity.fromJson(json!);
  34. //重新赋值data或list
  35. return result.convert<DeviceListEntity>(data: data);
  36. }
  37. return result.convert();
  38. }
  39. //财务报表
  40. Future<HttpResult<FianceReportEntity>> fetchReportFiance(
  41. String? startDate,
  42. String? endDate, {
  43. CancelToken? cancelToken,
  44. }) async {
  45. //参数
  46. Map<String, String> params = {};
  47. if (Utils.isEmpty(startDate)) {
  48. params["start_date"] = startDate!;
  49. }
  50. if (Utils.isEmpty(endDate)) {
  51. params["end_date"] = endDate!;
  52. }
  53. final result = await httpProvider.requestNetResult(
  54. ApiConstants.apiReportFiance,
  55. params: params,
  56. cancelToken: cancelToken,
  57. );
  58. //根据返回的结果,封装原始数据为Bean/Entity对象
  59. if (result.isSuccess) {
  60. //重新赋值data或list
  61. final json = result.getDataJson();
  62. var data = FianceReportEntity.fromJson(json!);
  63. //重新赋值data或list
  64. return result.convert<FianceReportEntity>(data: data);
  65. }
  66. return result.convert();
  67. }
  68. //用工报表
  69. Future<HttpResult<LabourReportEntity>> fetchReportLabour(
  70. String? startDate,
  71. String? endDate, {
  72. CancelToken? cancelToken,
  73. }) async {
  74. //参数
  75. Map<String, String> params = {};
  76. if (Utils.isEmpty(startDate)) {
  77. params["start_date"] = startDate!;
  78. }
  79. if (Utils.isEmpty(endDate)) {
  80. params["end_date"] = endDate!;
  81. }
  82. final result = await httpProvider.requestNetResult(
  83. ApiConstants.apiReportLabour,
  84. params: params,
  85. cancelToken: cancelToken,
  86. );
  87. //根据返回的结果,封装原始数据为Bean/Entity对象
  88. if (result.isSuccess) {
  89. //重新赋值data或list
  90. final json = result.getDataJson();
  91. var data = LabourReportEntity.fromJson(json!);
  92. //重新赋值data或list
  93. return result.convert<LabourReportEntity>(data: data);
  94. }
  95. return result.convert();
  96. }
  97. //员工请求报表
  98. Future<HttpResult<StaffRequestReportEntity?>> fetchReportStaffRequest(
  99. String? startDate,
  100. String? endDate, {
  101. CancelToken? cancelToken,
  102. }) async {
  103. //参数
  104. Map<String, String> params = {};
  105. if (Utils.isEmpty(startDate)) {
  106. params["start_date"] = startDate!;
  107. }
  108. if (Utils.isEmpty(endDate)) {
  109. params["end_date"] = endDate!;
  110. }
  111. final result = await httpProvider.requestNetResult(
  112. ApiConstants.apiReportStaffRequest,
  113. params: params,
  114. cancelToken: cancelToken,
  115. );
  116. if (result.isSuccess) {
  117. var jsonList = result.getListJson();
  118. var list = jsonList?.map((e) {
  119. if (e is Map<String, dynamic>) {
  120. return StaffRequestReportEntity.fromJson(e);
  121. } else {
  122. return null;
  123. }
  124. }).toList();
  125. return result.convert<StaffRequestReportEntity?>(list: list);
  126. }
  127. return result.convert<StaffRequestReportEntity>();
  128. }
  129. }