labour_repository.dart 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. String? salaryBy,
  132. String? amount, {
  133. CancelToken? cancelToken,
  134. }) async {
  135. //参数
  136. Map<String, String> params = {};
  137. params['template_id'] = templateId ?? "";
  138. params['job_start'] = jobStart ?? "";
  139. params['job_end'] = jobEnd ?? "";
  140. params['need_num'] = needNum ?? "";
  141. if (!Utils.isEmpty(departmentId)) {
  142. params["co_department_id"] = departmentId!;
  143. }
  144. params['salary_by'] = salaryBy ?? "";
  145. if (!Utils.isEmpty(amount)) {
  146. params["amount"] = amount!;
  147. }
  148. final result = await httpProvider.requestNetResult(
  149. ApiConstants.apiLabourRequestAddSubmit,
  150. method: HttpMethod.POST,
  151. params: params,
  152. networkDebounce: true,
  153. isShowLoadingDialog: true,
  154. cancelToken: cancelToken,
  155. );
  156. //根据返回的结果,封装原始数据为Bean/Entity对象
  157. if (result.isSuccess) {
  158. //重新赋值data或list
  159. return result.convert();
  160. }
  161. return result.convert();
  162. }
  163. /// 用工的编辑详情
  164. Future<HttpResult<LabourRequestEditIndexEntity>> fetchLabourRequestEditDetail(
  165. String? requestId, {
  166. CancelToken? cancelToken,
  167. }) async {
  168. //参数
  169. Map<String, String> params = {};
  170. params['request_id'] = requestId ?? "";
  171. final result = await httpProvider.requestNetResult(
  172. ApiConstants.apiLabourRequestEditDetail,
  173. params: params,
  174. isShowLoadingDialog: true,
  175. cancelToken: cancelToken,
  176. );
  177. //根据返回的结果,封装原始数据为Bean/Entity对象
  178. if (result.isSuccess) {
  179. //重新赋值data或list
  180. final json = result.getDataJson();
  181. var data = LabourRequestEditIndexEntity.fromJson(json!);
  182. //重新赋值data或list
  183. return result.convert<LabourRequestEditIndexEntity>(data: data);
  184. }
  185. return result.convert();
  186. }
  187. /// 编辑用工请求发布
  188. Future<HttpResult> editLabourRequestSubmit(
  189. String? requestId,
  190. String? templateId,
  191. String? jobStart,
  192. String? jobEnd,
  193. String? departmentId,
  194. String? needNum,
  195. String? salaryBy,
  196. String? amount, {
  197. CancelToken? cancelToken,
  198. }) async {
  199. //参数
  200. Map<String, String> params = {};
  201. params['request_id'] = requestId ?? "";
  202. params['template_id'] = templateId ?? "";
  203. params['job_start'] = jobStart ?? "";
  204. params['job_end'] = jobEnd ?? "";
  205. params['need_num'] = needNum ?? "";
  206. if (!Utils.isEmpty(departmentId)) {
  207. params["co_department_id"] = departmentId!;
  208. }
  209. params['salary_by'] = salaryBy ?? "";
  210. if (!Utils.isEmpty(amount)) {
  211. params["amount"] = amount!;
  212. }
  213. final result = await httpProvider.requestNetResult(
  214. ApiConstants.apiLabourRequestEditSubmit,
  215. method: HttpMethod.POST,
  216. params: params,
  217. networkDebounce: true,
  218. isShowLoadingDialog: true,
  219. cancelToken: cancelToken,
  220. );
  221. //根据返回的结果,封装原始数据为Bean/Entity对象
  222. if (result.isSuccess) {
  223. //重新赋值data或list
  224. return result.convert();
  225. }
  226. return result.convert();
  227. }
  228. /// 撤回用工请求
  229. Future<HttpResult> recallLabourRequest(
  230. String? requestId, {
  231. CancelToken? cancelToken,
  232. }) async {
  233. //参数
  234. Map<String, String> params = {};
  235. params['request_id'] = requestId ?? "";
  236. final result = await httpProvider.requestNetResult(
  237. ApiConstants.apiLabourRequestRecall,
  238. method: HttpMethod.POST,
  239. params: params,
  240. networkDebounce: true,
  241. isShowLoadingDialog: true,
  242. cancelToken: cancelToken,
  243. );
  244. //根据返回的结果,封装原始数据为Bean/Entity对象
  245. if (result.isSuccess) {
  246. //重新赋值data或list
  247. return result.convert();
  248. }
  249. return result.convert();
  250. }
  251. /// 用工的审核详情工作流列表
  252. Future<HttpResult<LabourRequestWorkFlowEntity>> fetchLabourRequestWorkFlow(
  253. String? requestId, {
  254. CancelToken? cancelToken,
  255. }) async {
  256. //参数
  257. Map<String, String> params = {};
  258. if (!Utils.isEmpty(requestId)) {
  259. params["request_id"] = requestId!;
  260. }
  261. final result = await httpProvider.requestNetResult(
  262. ApiConstants.apiLabourRequestStateWorkFlow,
  263. params: params,
  264. cancelToken: cancelToken,
  265. );
  266. //根据返回的结果,封装原始数据为Bean/Entity对象
  267. if (result.isSuccess) {
  268. //重新赋值data或list
  269. final json = result.getDataJson();
  270. var data = LabourRequestWorkFlowEntity.fromJson(json!);
  271. //重新赋值data或list
  272. return result.convert<LabourRequestWorkFlowEntity>(data: data);
  273. }
  274. return result.convert();
  275. }
  276. }