| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- import 'dart:convert';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import '../../core/data/api_cache.dart';
- import '../../core/navigation/host_app_channel.dart';
- import '../../core/network/api_client.dart';
- import '../../shared/models/pagination_model.dart';
- import '../../app.dart';
- import '../expense_apply/expense_apply_api.dart';
- export '../expense_apply/expense_apply_api.dart'
- show DepartmentItem, EmployeeItem;
- import 'vehicle_apply_model.dart';
- import 'vehicle_report_model.dart';
- final vehicleApplyApiProvider = Provider<VehicleApplyApi>(
- (ref) => VehicleApplyApi(ref.read(apiClientProvider)),
- );
- class VehicleApplyApi {
- final ApiClient _client;
- final _cache = ApiCache(
- keyPrefix:
- '${HostAppChannel.sn}_${HostAppChannel.compNo}_${HostAppChannel.usr}',
- );
- VehicleApplyApi(this._client);
- /// 清除所有基础资料缓存(picker 下拉刷新时调用)。
- void clearRefCache() => _cache.clear();
- /// 用车申请列表(分页)
- Future<PaginatedData<VehicleApplyModel>> fetchList({
- String status = '',
- String keyword = '',
- String startDate = '',
- String endDate = '',
- String usr = '',
- String sortDir = 'DESC',
- int page = 1,
- int size = 20,
- }) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetVehicleApplyList',
- queryParameters: {
- 'status': status,
- 'keyword': keyword,
- 'startDate': startDate,
- 'endDate': endDate,
- 'usr': usr,
- 'sortDir': sortDir,
- 'page': page,
- 'size': size,
- },
- );
- return PaginatedData.fromJson(response.data!, VehicleApplyModel.fromJson);
- }
- /// 用车申请详情
- Future<VehicleApplyModel> fetchDetail(String billNo) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetVehicleApplyDetail',
- queryParameters: {'billNo': billNo},
- );
- return VehicleApplyModel.fromJson(response.data!);
- }
- /// 提交/保存,返回申请单号
- Future<String?> submit(Map<String, dynamic> data) async {
- final response = await _client.post<Map<String, dynamic>>(
- '/OA/BillSave',
- data: {
- 'erpCategory': 'MasterService',
- 'billId': 'YC',
- 'procId': '',
- 'data': data,
- },
- );
- final resData = response.data;
- if (resData == null) return null;
- final resultData = resData['resultData'];
- if (resultData is Map<String, dynamic>) {
- final bilNo = resultData['BIL_NO'] as String?;
- if (bilNo != null && bilNo.isNotEmpty) return bilNo;
- }
- if (resultData is String && resultData.isNotEmpty) {
- try {
- final parsed = json.decode(resultData) as Map<String, dynamic>;
- final bilNo = parsed['BIL_NO'] as String?;
- if (bilNo != null && bilNo.isNotEmpty) return bilNo;
- } catch (_) {}
- }
- final rootBilNo = resData['BIL_NO'] as String?;
- if (rootBilNo != null && rootBilNo.isNotEmpty) return rootBilNo;
- return null;
- }
- /// 还车登记(billId="YC",IS_RETURN="T")
- Future<String?> submitReturn(
- String billNo,
- Map<String, dynamic> returnData,
- ) async {
- final response = await _client.post<Map<String, dynamic>>(
- '/OA/BillSave',
- data: {
- 'erpCategory': 'MasterService',
- 'billId': 'YC',
- 'procId': '',
- 'data': {
- 'HeadData': {
- 'YC_NO': billNo,
- 'IS_RETURN': 'T',
- 'RETURN_TIME': returnData['returnTime'],
- 'ODOMETER_END': returnData['odometerEnd'],
- 'AMTN': returnData['amtn'],
- 'REMARK': returnData['remark'],
- 'USR_CHECK': returnData['usrCheck'],
- },
- },
- },
- );
- final resData = response.data;
- if (resData == null) return null;
- final resultData = resData['resultData'];
- if (resultData is Map<String, dynamic>) {
- final bilNo = resultData['BIL_NO'] as String?;
- if (bilNo != null && bilNo.isNotEmpty) return bilNo;
- }
- if (resultData is String && resultData.isNotEmpty) {
- try {
- final parsed = json.decode(resultData) as Map<String, dynamic>;
- final bilNo = parsed['BIL_NO'] as String?;
- if (bilNo != null && bilNo.isNotEmpty) return bilNo;
- } catch (_) {}
- }
- return null;
- }
- /// 提交审核流
- Future<bool> shSubmit({
- required String bilNo,
- required String bilDd,
- String dep = '',
- String rem = '',
- String usr = '',
- bool isCancel = false,
- }) async {
- try {
- final response = await _client.post<Map<String, dynamic>>(
- '/OA/SHSubmit',
- data: {
- 'erpCategory': 'MasterService',
- 'bilId': 'YC',
- 'bilNo': bilNo,
- 'bilDd': bilDd,
- 'dep': dep,
- 'rem': rem,
- 'usr': usr,
- 'isCancel': isCancel,
- },
- );
- return response.data?['code'] == 0;
- } catch (_) {
- return false;
- }
- }
- /// 获取用户对指定程序的权限
- Future<Map<String, dynamic>> getUserRights(String pgm) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetUserRights',
- queryParameters: {
- 'compNo': HostAppChannel.compNo,
- 'usrId': HostAppChannel.usr,
- 'pgm': pgm,
- },
- );
- return response.data!;
- }
- /// 获取审核配置
- Future<Map<String, dynamic>> getBillAuditConfig(String bilId) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetBillAuditConfig',
- queryParameters: {'bilId': bilId},
- );
- return response.data!;
- }
- /// 获取单据状态(billId="YC")
- Future<Map<String, dynamic>> getBillStatus(String billNo) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetBillStatus',
- queryParameters: {'billId': 'YC', 'billNo': billNo},
- );
- return response.data!;
- }
- /// 用车报表汇总
- Future<VehicleReportSummary> getVehicleReportSummary({
- String startDate = '',
- String endDate = '',
- }) async {
- final params = <String, dynamic>{};
- if (startDate.isNotEmpty) params['startDate'] = startDate;
- if (endDate.isNotEmpty) params['endDate'] = endDate;
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetVehicleReportSummary',
- queryParameters: params,
- );
- return VehicleReportSummary.fromJson(response.data!);
- }
- /// 用车报表月度数据
- Future<List<VehicleMonthlyItem>> getVehicleReportMonthly({
- String startDate = '',
- String endDate = '',
- }) async {
- final params = <String, dynamic>{};
- if (startDate.isNotEmpty) params['startDate'] = startDate;
- if (endDate.isNotEmpty) params['endDate'] = endDate;
- final response = await _client.get<dynamic>(
- '/OA/GetVehicleReportMonthly',
- queryParameters: params,
- );
- final list =
- (response.data as List<dynamic>?)
- ?.map((e) => VehicleMonthlyItem.fromJson(e as Map<String, dynamic>))
- .toList() ??
- [];
- return list;
- }
- /// 用车报表下属对比
- Future<List<VehicleSubordinateItem>> getVehicleSubordinateReport({
- String startDate = '',
- String endDate = '',
- }) async {
- final params = <String, dynamic>{};
- if (startDate.isNotEmpty) params['startDate'] = startDate;
- if (endDate.isNotEmpty) params['endDate'] = endDate;
- final response = await _client.get<dynamic>(
- '/OA/GetVehicleSubordinateReport',
- queryParameters: params,
- );
- final list =
- (response.data as List<dynamic>?)
- ?.map(
- (e) => VehicleSubordinateItem.fromJson(e as Map<String, dynamic>),
- )
- .toList() ??
- [];
- return list;
- }
- /// 用车报表明细(分页)
- Future<Map<String, dynamic>> getVehicleReportDetail({
- String startDate = '',
- String endDate = '',
- int page = 1,
- int size = 20,
- }) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetVehicleReportDetail',
- queryParameters: {
- if (startDate.isNotEmpty) 'startDate': startDate,
- if (endDate.isNotEmpty) 'endDate': endDate,
- 'page': page,
- 'size': size,
- },
- );
- return response.data!;
- }
- /// 用车报表表身明细(分页)
- Future<Map<String, dynamic>> getVehicleBodyReport({
- String startDate = '',
- String endDate = '',
- int page = 1,
- int size = 20,
- }) async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetVehicleBodyReport',
- queryParameters: {
- if (startDate.isNotEmpty) 'startDate': startDate,
- if (endDate.isNotEmpty) 'endDate': endDate,
- 'page': page,
- 'size': size,
- },
- );
- return response.data!;
- }
- /// 部门查询
- Future<List<DepartmentItem>> getDepartments({
- String keyword = '',
- bool onlyActive = true,
- int page = 1,
- int size = 100,
- }) async {
- final cacheKey = 'getDepartments_${keyword}_${onlyActive}_$page';
- return _cache.getOrFetch(cacheKey, () async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetDepartments',
- queryParameters: {
- 'keyword': keyword,
- 'onlyActive': onlyActive,
- 'page': page,
- 'size': size,
- },
- );
- final list = (response.data?['list'] as List<dynamic>?) ?? [];
- return list
- .map((e) => DepartmentItem.fromJson(e as Map<String, dynamic>))
- .toList();
- });
- }
- /// 员工查询
- Future<List<EmployeeItem>> getEmployees({
- String keyword = '',
- String salNo = '',
- int page = 1,
- int size = 100,
- }) async {
- final cacheKey = 'getEmployees_${keyword}_${salNo}_$page';
- return _cache.getOrFetch(cacheKey, () async {
- final response = await _client.get<Map<String, dynamic>>(
- '/OA/GetEmployees',
- queryParameters: {
- 'keyword': keyword,
- 'salNo': salNo,
- 'page': page,
- 'size': size,
- },
- );
- final list = (response.data?['list'] as List<dynamic>?) ?? [];
- return list
- .map((e) => EmployeeItem.fromJson(e as Map<String, dynamic>))
- .toList();
- });
- }
- }
|