labour_repository.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import 'package:domain/entity/response/labour_request_edit_index_entity.dart';
  2. import 'package:domain/entity/response/labour_request_index_entity.dart';
  3. import 'package:domain/entity/response/labour_request_list_entity.dart';
  4. import 'package:domain/entity/response/labour_request_work_flow_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 LabourRepository extends GetxService {
  13. HttpProvider httpProvider;
  14. LabourRepository({required this.httpProvider});
  15. /// 获取用工请求的筛选选项
  16. Future<HttpResult<LabourRequestIndexEntity>> fetchLabourRequestIndex({
  17. CancelToken? cancelToken,
  18. }) async {
  19. final result = await httpProvider.requestNetResult(
  20. ApiConstants.apiLabourRequestIndex,
  21. cancelToken: cancelToken,
  22. );
  23. //根据返回的结果,封装原始数据为Bean/Entity对象
  24. if (result.isSuccess) {
  25. //重新赋值data或list
  26. final json = result.getDataJson();
  27. var data = LabourRequestIndexEntity.fromJson(json!);
  28. //重新赋值data或list
  29. return result.convert<LabourRequestIndexEntity>(data: data);
  30. }
  31. return result.convert();
  32. }
  33. /// 获取用工请求的主列表
  34. Future<HttpResult<LabourRequestListEntity>> fetchLabourRequestList(
  35. String? keyword,
  36. String? startDate,
  37. String? endDate,
  38. String? statusId,
  39. String? departmentId, {
  40. required int curPage,
  41. CancelToken? cancelToken,
  42. }) async {
  43. //参数
  44. Map<String, String> params = {};
  45. params["cur_page"] = curPage.toString();
  46. params["page_size"] = "20";
  47. if (!Utils.isEmpty(keyword)) {
  48. params["job_title"] = keyword!;
  49. }
  50. if (!Utils.isEmpty(startDate)) {
  51. params["job_start"] = startDate!;
  52. }
  53. if (!Utils.isEmpty(endDate)) {
  54. params["job_end"] = endDate!;
  55. }
  56. if (!Utils.isEmpty(statusId)) {
  57. params["co_status"] = statusId!;
  58. }
  59. if (!Utils.isEmpty(departmentId)) {
  60. params["co_department_id"] = departmentId!;
  61. }
  62. final result = await httpProvider.requestNetResult(
  63. ApiConstants.apiLabourRequestList,
  64. params: params,
  65. cancelToken: cancelToken,
  66. );
  67. //根据返回的结果,封装原始数据为Bean/Entity对象
  68. if (result.isSuccess) {
  69. //重新赋值data或list
  70. final json = result.getDataJson();
  71. var data = LabourRequestListEntity.fromJson(json!);
  72. //重新赋值data或list
  73. return result.convert<LabourRequestListEntity>(data: data);
  74. }
  75. return result.convert();
  76. }
  77. /// 根据ID获取主列表的Item数据,用于刷新Item
  78. Future<HttpResult<LabourRequestListEntity>> fetchItemByRequestId(
  79. String? requestId, {
  80. CancelToken? cancelToken,
  81. }) async {
  82. //参数
  83. Map<String, String> params = {};
  84. params["cur_page"] = "1";
  85. params["page_size"] = "1";
  86. if (!Utils.isEmpty(requestId)) {
  87. params["request_id"] = requestId!;
  88. }
  89. final result = await httpProvider.requestNetResult(
  90. ApiConstants.apiLabourRequestList,
  91. params: params,
  92. isShowLoadingDialog: true,
  93. cancelToken: cancelToken,
  94. );
  95. //根据返回的结果,封装原始数据为Bean/Entity对象
  96. if (result.isSuccess) {
  97. //重新赋值data或list
  98. final json = result.getDataJson();
  99. var data = LabourRequestListEntity.fromJson(json!);
  100. //重新赋值data或list
  101. return result.convert<LabourRequestListEntity>(data: data);
  102. }
  103. return result.convert();
  104. }
  105. /// 添加用工的选项
  106. Future<HttpResult<LabourRequestEditIndexEntity>> fetchLabourRequestAddOption({
  107. CancelToken? cancelToken,
  108. }) async {
  109. final result = await httpProvider.requestNetResult(
  110. ApiConstants.apiLabourRequestAddOption,
  111. isShowLoadingDialog: true,
  112. cancelToken: cancelToken,
  113. );
  114. //根据返回的结果,封装原始数据为Bean/Entity对象
  115. if (result.isSuccess) {
  116. //重新赋值data或list
  117. final json = result.getDataJson();
  118. var data = LabourRequestEditIndexEntity.fromJson(json!);
  119. //重新赋值data或list
  120. return result.convert<LabourRequestEditIndexEntity>(data: data);
  121. }
  122. return result.convert();
  123. }
  124. /// 添加用工请求发布
  125. Future<HttpResult> addLabourRequestSubmit(
  126. String? templateId,
  127. String? jobStart,
  128. String? jobEnd,
  129. String? departmentId,
  130. String? needNum, {
  131. CancelToken? cancelToken,
  132. }) async {
  133. //参数
  134. Map<String, String> params = {};
  135. params['template_id'] = templateId ?? "";
  136. params['job_start'] = jobStart ?? "";
  137. params['job_end'] = jobEnd ?? "";
  138. params['need_num'] = needNum ?? "";
  139. if (!Utils.isEmpty(departmentId)) {
  140. params["co_department_id"] = departmentId!;
  141. }
  142. final result = await httpProvider.requestNetResult(
  143. ApiConstants.apiLabourRequestAddSubmit,
  144. method: HttpMethod.POST,
  145. params: params,
  146. networkDebounce: true,
  147. isShowLoadingDialog: true,
  148. cancelToken: cancelToken,
  149. );
  150. //根据返回的结果,封装原始数据为Bean/Entity对象
  151. if (result.isSuccess) {
  152. //重新赋值data或list
  153. return result.convert();
  154. }
  155. return result.convert();
  156. }
  157. /// 用工的编辑详情
  158. Future<HttpResult<LabourRequestEditIndexEntity>> fetchLabourRequestEditDetail(
  159. String? requestId, {
  160. CancelToken? cancelToken,
  161. }) async {
  162. //参数
  163. Map<String, String> params = {};
  164. params['request_id'] = requestId ?? "";
  165. final result = await httpProvider.requestNetResult(
  166. ApiConstants.apiLabourRequestEditDetail,
  167. params: params,
  168. isShowLoadingDialog: true,
  169. cancelToken: cancelToken,
  170. );
  171. //根据返回的结果,封装原始数据为Bean/Entity对象
  172. if (result.isSuccess) {
  173. //重新赋值data或list
  174. final json = result.getDataJson();
  175. var data = LabourRequestEditIndexEntity.fromJson(json!);
  176. //重新赋值data或list
  177. return result.convert<LabourRequestEditIndexEntity>(data: data);
  178. }
  179. return result.convert();
  180. }
  181. /// 编辑用工请求发布
  182. Future<HttpResult> editLabourRequestSubmit(
  183. String? requestId,
  184. String? templateId,
  185. String? jobStart,
  186. String? jobEnd,
  187. String? departmentId,
  188. String? needNum, {
  189. CancelToken? cancelToken,
  190. }) async {
  191. //参数
  192. Map<String, String> params = {};
  193. params['request_id'] = requestId ?? "";
  194. params['template_id'] = templateId ?? "";
  195. params['job_start'] = jobStart ?? "";
  196. params['job_end'] = jobEnd ?? "";
  197. params['need_num'] = needNum ?? "";
  198. if (!Utils.isEmpty(departmentId)) {
  199. params["co_department_id"] = departmentId!;
  200. }
  201. final result = await httpProvider.requestNetResult(
  202. ApiConstants.apiLabourRequestEditSubmit,
  203. method: HttpMethod.POST,
  204. params: params,
  205. networkDebounce: true,
  206. isShowLoadingDialog: true,
  207. cancelToken: cancelToken,
  208. );
  209. //根据返回的结果,封装原始数据为Bean/Entity对象
  210. if (result.isSuccess) {
  211. //重新赋值data或list
  212. return result.convert();
  213. }
  214. return result.convert();
  215. }
  216. /// 撤回用工请求
  217. Future<HttpResult> recallLabourRequest(
  218. String? requestId, {
  219. CancelToken? cancelToken,
  220. }) async {
  221. //参数
  222. Map<String, String> params = {};
  223. params['request_id'] = requestId ?? "";
  224. final result = await httpProvider.requestNetResult(
  225. ApiConstants.apiLabourRequestRecall,
  226. method: HttpMethod.POST,
  227. params: params,
  228. networkDebounce: true,
  229. isShowLoadingDialog: true,
  230. cancelToken: cancelToken,
  231. );
  232. //根据返回的结果,封装原始数据为Bean/Entity对象
  233. if (result.isSuccess) {
  234. //重新赋值data或list
  235. return result.convert();
  236. }
  237. return result.convert();
  238. }
  239. /// 用工的审核详情工作流列表
  240. Future<HttpResult<LabourRequestWorkFlowEntity>> fetchLabourRequestWorkFlow(
  241. String? requestId, {
  242. CancelToken? cancelToken,
  243. }) async {
  244. //参数
  245. Map<String, String> params = {};
  246. if (!Utils.isEmpty(requestId)) {
  247. params["request_id"] = requestId!;
  248. }
  249. final result = await httpProvider.requestNetResult(
  250. ApiConstants.apiLabourRequestStateWorkFlow,
  251. params: params,
  252. cancelToken: cancelToken,
  253. );
  254. //根据返回的结果,封装原始数据为Bean/Entity对象
  255. if (result.isSuccess) {
  256. //重新赋值data或list
  257. final json = result.getDataJson();
  258. var data = LabourRequestWorkFlowEntity.fromJson(json!);
  259. //重新赋值data或list
  260. return result.convert<LabourRequestWorkFlowEntity>(data: data);
  261. }
  262. return result.convert();
  263. }
  264. }