other_repository.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/log_utils.dart';
  10. import 'package:shared/utils/util.dart';
  11. import '../constants/api_constants.dart';
  12. import '../entity/response/labour_report_v_n_entity.dart';
  13. import '../entity/response/staff_report_v_n_entity.dart';
  14. /// 报表与其他的相关数据
  15. class OtherRepository extends GetxService {
  16. HttpProvider httpProvider;
  17. OtherRepository({required this.httpProvider});
  18. // 雇主的设备列表
  19. Future<HttpResult<DeviceListEntity>> fetchDeviceList({
  20. required int curPage,
  21. CancelToken? cancelToken,
  22. }) async {
  23. //参数
  24. Map<String, String> params = {};
  25. params["cur_page"] = curPage.toString();
  26. params["page_size"] = "10";
  27. final result = await httpProvider.requestNetResult(
  28. ApiConstants.apiDeviceList,
  29. params: params,
  30. cancelToken: cancelToken,
  31. );
  32. //根据返回的结果,封装原始数据为Bean/Entity对象
  33. if (result.isSuccess) {
  34. //重新赋值data或list
  35. final json = result.getDataJson();
  36. var data = DeviceListEntity.fromJson(json!);
  37. //重新赋值data或list
  38. return result.convert<DeviceListEntity>(data: data);
  39. }
  40. return result.convert();
  41. }
  42. //财务报表
  43. Future<HttpResult<FianceReportEntity>> fetchReportFiance(
  44. String? startDate,
  45. String? endDate, {
  46. CancelToken? cancelToken,
  47. }) async {
  48. //参数
  49. Map<String, String> params = {};
  50. if (Utils.isNotEmpty(startDate)) {
  51. params["start_date"] = startDate!;
  52. }
  53. if (Utils.isNotEmpty(endDate)) {
  54. params["end_date"] = endDate!;
  55. }
  56. final result = await httpProvider.requestNetResult(
  57. ApiConstants.apiReportFiance,
  58. params: params,
  59. cancelToken: cancelToken,
  60. );
  61. //根据返回的结果,封装原始数据为Bean/Entity对象
  62. if (result.isSuccess) {
  63. //重新赋值data或list
  64. final json = result.getDataJson();
  65. var data = FianceReportEntity.fromJson(json!);
  66. //重新赋值data或list
  67. return result.convert<FianceReportEntity>(data: data);
  68. }
  69. return result.convert();
  70. }
  71. //用工报表
  72. Future<HttpResult<LabourReportEntity>> fetchReportLabour(
  73. String? startDate,
  74. String? endDate, {
  75. CancelToken? cancelToken,
  76. }) async {
  77. //参数
  78. Map<String, String> params = {};
  79. if (Utils.isNotEmpty(startDate)) {
  80. params["start_date"] = startDate!;
  81. }
  82. if (Utils.isNotEmpty(endDate)) {
  83. params["end_date"] = endDate!;
  84. }
  85. final result = await httpProvider.requestNetResult(
  86. ApiConstants.apiReportLabour,
  87. params: params,
  88. cancelToken: cancelToken,
  89. );
  90. //根据返回的结果,封装原始数据为Bean/Entity对象
  91. if (result.isSuccess) {
  92. //重新赋值data或list
  93. final json = result.getDataJson();
  94. var data = LabourReportEntity.fromJson(json!);
  95. //重新赋值data或list
  96. return result.convert<LabourReportEntity>(data: data);
  97. }
  98. return result.convert();
  99. }
  100. //员工请求报表
  101. Future<HttpResult<StaffRequestReportEntity?>> fetchReportStaffRequest(
  102. String? startDate,
  103. String? endDate, {
  104. CancelToken? cancelToken,
  105. }) async {
  106. //参数
  107. Map<String, String> params = {};
  108. if (Utils.isNotEmpty(startDate)) {
  109. params["start_date"] = startDate!;
  110. }
  111. if (Utils.isNotEmpty(endDate)) {
  112. params["end_date"] = endDate!;
  113. }
  114. final result = await httpProvider.requestNetResult(
  115. ApiConstants.apiReportStaffRequest,
  116. params: params,
  117. cancelToken: cancelToken,
  118. );
  119. if (result.isSuccess) {
  120. var jsonList = result.getListJson();
  121. var list = jsonList?.map((e) {
  122. if (e is Map<String, dynamic>) {
  123. return StaffRequestReportEntity.fromJson(e);
  124. } else {
  125. return null;
  126. }
  127. }).toList();
  128. return result.convert<StaffRequestReportEntity?>(list: list);
  129. }
  130. return result.convert<StaffRequestReportEntity>();
  131. }
  132. /// 越南的员工报表
  133. Future<HttpResult<StaffReportVNEntity>> fetchStaffReportVN(
  134. String? startDate,
  135. String? endDate, {
  136. CancelToken? cancelToken,
  137. }) async {
  138. //参数
  139. Map<String, String> params = {};
  140. if (Utils.isNotEmpty(startDate)) {
  141. params["start_date"] = startDate!;
  142. }
  143. if (Utils.isNotEmpty(endDate)) {
  144. params["end_date"] = endDate!;
  145. }
  146. final result = await httpProvider.requestNetResult(
  147. ApiConstants.apiReportStaffRequest,
  148. params: params,
  149. cancelToken: cancelToken,
  150. );
  151. //根据返回的结果,封装原始数据为Bean/Entity对象
  152. if (result.isSuccess) {
  153. //重新赋值data或list
  154. final json = result.getDataJson();
  155. var data = StaffReportVNEntity.fromJson(json!);
  156. //重新赋值data或list
  157. return result.convert<StaffReportVNEntity>(data: data);
  158. }
  159. return result.convert();
  160. }
  161. /// 越南的用工报表
  162. Future<HttpResult<LabourReportVNEntity>> fetchReportLabourVN(
  163. String? startDate,
  164. String? endDate, {
  165. CancelToken? cancelToken,
  166. }) async {
  167. //参数
  168. Map<String, String> params = {};
  169. if (Utils.isNotEmpty(startDate)) {
  170. params["start_date"] = startDate!;
  171. }
  172. if (Utils.isNotEmpty(endDate)) {
  173. params["end_date"] = endDate!;
  174. }
  175. final result = await httpProvider.requestNetResult(
  176. ApiConstants.apiReportLabour,
  177. params: params,
  178. cancelToken: cancelToken,
  179. );
  180. //根据返回的结果,封装原始数据为Bean/Entity对象
  181. if (result.isSuccess) {
  182. //重新赋值data或list
  183. final json = result.getDataJson();
  184. var data = LabourReportVNEntity.fromJson(json!);
  185. //重新赋值data或list
  186. return result.convert<LabourReportVNEntity>(data: data);
  187. }
  188. return result.convert();
  189. }
  190. }