import 'package:domain/entity/response/labour_request_edit_index_entity.dart'; import 'package:domain/entity/response/labour_request_index_entity.dart'; import 'package:domain/entity/response/labour_request_list_entity.dart'; import 'package:domain/entity/response/labour_request_work_flow_entity.dart'; import 'package:get/get.dart'; import 'package:plugin_platform/dio_export.dart'; import 'package:plugin_platform/http/http_provider.dart'; import 'package:plugin_platform/http/http_result.dart'; import 'package:shared/utils/util.dart'; import '../constants/api_constants.dart'; /// 用工请求相关 class LabourRepository extends GetxService { HttpProvider httpProvider; LabourRepository({required this.httpProvider}); /// 获取用工请求的筛选选项 Future> fetchLabourRequestIndex({ CancelToken? cancelToken, }) async { final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestIndex, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = LabourRequestIndexEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 获取用工请求的主列表 Future> fetchLabourRequestList( String? keyword, String? startDate, String? endDate, String? statusId, String? departmentId, { required int curPage, CancelToken? cancelToken, }) async { //参数 Map params = {}; params["cur_page"] = curPage.toString(); params["page_size"] = "20"; if (!Utils.isEmpty(keyword)) { params["job_title"] = keyword!; } if (!Utils.isEmpty(startDate)) { params["job_start"] = startDate!; } if (!Utils.isEmpty(endDate)) { params["job_end"] = endDate!; } if (!Utils.isEmpty(statusId)) { params["co_status"] = statusId!; } if (!Utils.isEmpty(departmentId)) { params["co_department_id"] = departmentId!; } final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestList, params: params, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = LabourRequestListEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 根据ID获取主列表的Item数据,用于刷新Item Future> fetchItemByRequestId( String? requestId, { CancelToken? cancelToken, }) async { //参数 Map params = {}; params["cur_page"] = "1"; params["page_size"] = "1"; if (!Utils.isEmpty(requestId)) { params["request_id"] = requestId!; } final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestList, params: params, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = LabourRequestListEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 添加用工的选项 Future> fetchLabourRequestAddOption({ CancelToken? cancelToken, }) async { final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestAddOption, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = LabourRequestEditIndexEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 添加用工请求发布 Future addLabourRequestSubmit( String? templateId, String? jobStart, String? jobEnd, String? departmentId, String? needNum, { CancelToken? cancelToken, }) async { //参数 Map params = {}; params['template_id'] = templateId ?? ""; params['job_start'] = jobStart ?? ""; params['job_end'] = jobEnd ?? ""; params['need_num'] = needNum ?? ""; if (!Utils.isEmpty(departmentId)) { params["co_department_id"] = departmentId!; } final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestAddSubmit, method: HttpMethod.POST, params: params, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list return result.convert(); } return result.convert(); } /// 用工的编辑详情 Future> fetchLabourRequestEditDetail( String? requestId, { CancelToken? cancelToken, }) async { //参数 Map params = {}; params['request_id'] = requestId ?? ""; final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestEditDetail, params: params, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = LabourRequestEditIndexEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 编辑用工请求发布 Future editLabourRequestSubmit( String? requestId, String? templateId, String? jobStart, String? jobEnd, String? departmentId, String? needNum, { CancelToken? cancelToken, }) async { //参数 Map params = {}; params['request_id'] = requestId ?? ""; params['template_id'] = templateId ?? ""; params['job_start'] = jobStart ?? ""; params['job_end'] = jobEnd ?? ""; params['need_num'] = needNum ?? ""; if (!Utils.isEmpty(departmentId)) { params["co_department_id"] = departmentId!; } final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestEditSubmit, method: HttpMethod.POST, params: params, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list return result.convert(); } return result.convert(); } /// 撤回用工请求 Future recallLabourRequest( String? requestId, { CancelToken? cancelToken, }) async { //参数 Map params = {}; params['request_id'] = requestId ?? ""; final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestRecall, method: HttpMethod.POST, params: params, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list return result.convert(); } return result.convert(); } /// 用工的审核详情工作流列表 Future> fetchLabourRequestWorkFlow( String? requestId, { CancelToken? cancelToken, }) async { //参数 Map params = {}; if (!Utils.isEmpty(requestId)) { params["request_id"] = requestId!; } final result = await httpProvider.requestNetResult( ApiConstants.apiLabourRequestStateWorkFlow, params: params, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = LabourRequestWorkFlowEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } }