x_attendance_assemble_control.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import 'package:get/get.dart';
  2. import '../models/index.dart';
  3. import '../services/index.dart';
  4. import '../utils/index.dart';
  5. import '../values/index.dart';
  6. ///
  7. /// 考勤服务
  8. ///
  9. class AttendanceAssembleControlService extends GetxService {
  10. static AttendanceAssembleControlService get to => Get.find();
  11. String baseUrl() {
  12. return O2ApiManager.instance
  13. .getModuleBaseUrl(O2DistributeModuleEnum.x_attendance_assemble_control) ??
  14. '';
  15. }
  16. /// 是否关闭旧考勤
  17. bool closeOldAttendance() {
  18. return SharedPreferenceService.to.getBool(SharedPreferenceService.v2AttendanceKey);
  19. }
  20. //////////// v2 ///////
  21. /// 考勤配置文件读取
  22. Future<AttendanceV2Config?> config() async {
  23. try {
  24. ApiResponse response =
  25. await O2HttpClient.instance.get('${baseUrl()}jaxrs/v2/config');
  26. return AttendanceV2Config.fromJson(response.data);
  27. } catch (err, stackTrace) {
  28. OLogger.e('配置文件读取失败', err, stackTrace);
  29. }
  30. return null;
  31. }
  32. ///
  33. /// 打卡
  34. ///
  35. Future<CheckInResponse?> checkInPostV2(CheckPost body) async {
  36. try {
  37. ApiResponse response =
  38. await O2HttpClient.instance.post('${baseUrl()}jaxrs/v2/mobile/check', body.toJson());
  39. return CheckInResponse.fromJson(response.data);
  40. } catch (err, stackTrace) {
  41. OLogger.e('打卡失败', err, stackTrace);
  42. }
  43. return null;
  44. }
  45. ///
  46. /// 打卡前获取打卡需要信息的请求.
  47. /// 包含了需要打卡的数据和工作场所列表等
  48. ///
  49. Future<PreCheckInData?> loadPreCheckInData() async {
  50. try {
  51. ApiResponse response =
  52. await O2HttpClient.instance.get('${baseUrl()}jaxrs/v2/mobile/check/pre');
  53. return PreCheckInData.fromJson(response.data);
  54. } catch (err, stackTrace) {
  55. OLogger.e('查询打卡记录失败', err, stackTrace);
  56. }
  57. return null;
  58. }
  59. /// 查询我的统计数据
  60. ///
  61. /// 根据[startDate]和[endDate]统计计算
  62. Future<AttendanceV2Statistic?> myStatistic(String startDate, String endDate) async {
  63. try {
  64. final body = AttendanceV2RequestStatistic(endDate: endDate, startDate: startDate);
  65. ApiResponse response =
  66. await O2HttpClient.instance.post('${baseUrl()}jaxrs/v2/my/statistic', body.toJson());
  67. return AttendanceV2Statistic.fromJson(response.data);
  68. } catch (err, stackTrace) {
  69. OLogger.e('查询打卡记录失败', err, stackTrace);
  70. }
  71. return null;
  72. }
  73. /// 分页查我的异常打卡数据列表
  74. Future<List<AttendanceV2Appeal>?> myAppealListByPage(int page, {int limit = O2.o2DefaultPageSize, Map<String, dynamic>? body}) async {
  75. try {
  76. Map<String, dynamic> data = {};
  77. if (body != null) {
  78. data = body;
  79. }
  80. ApiResponse response = await O2HttpClient.instance.post('${baseUrl()}jaxrs/v2/appeal/list/$page/size/$limit', data);
  81. var list = response.data == null ? [] : response.data as List;
  82. return list.map((d) => AttendanceV2Appeal.fromJson(d)).toList();
  83. } catch (err, stackTrace) {
  84. OLogger.e('查询异常打卡数据列表失败', err, stackTrace);
  85. }
  86. return null;
  87. }
  88. /// 检查是否能够申诉
  89. Future<ValueBoolData?> checkAppealEnable(String id) async {
  90. try {
  91. ApiResponse response = await O2HttpClient.instance.get('${baseUrl()}jaxrs/v2/appeal/$id/start/check');
  92. return ValueBoolData.fromJson(response.data);
  93. } catch (err, stackTrace) {
  94. OLogger.e('查询数据是否能够申诉失败', err, stackTrace);
  95. }
  96. return null;
  97. }
  98. /// 启动流程更新数据
  99. Future<ValueBoolData?> appealStartProcess(String id, String jobId) async {
  100. try {
  101. Map<String, dynamic> data = {
  102. "job": jobId
  103. };
  104. ApiResponse response = await O2HttpClient.instance.post('${baseUrl()}jaxrs/v2/appeal/$id/start/process', data);
  105. return ValueBoolData.fromJson(response.data);
  106. } catch (err, stackTrace) {
  107. OLogger.e('更新数据失败', err, stackTrace);
  108. }
  109. return null;
  110. }
  111. /// 还原数据状态 清空 job
  112. Future<ValueBoolData?> appealRestStatus(String id) async {
  113. try {
  114. ApiResponse response = await O2HttpClient.instance.get('${baseUrl()}jaxrs/v2/appeal/$id/reset/status');
  115. return ValueBoolData.fromJson(response.data);
  116. } catch (err, stackTrace) {
  117. OLogger.e('还原数据状态失败', err, stackTrace);
  118. }
  119. return null;
  120. }
  121. //////////////////////////////////////////////////
  122. ///
  123. /// 获取当天的打卡记录
  124. /// 包含了考勤配置信息
  125. ///
  126. Future<ScheduleInfo?> listMyRecords() async {
  127. try {
  128. ApiResponse response =
  129. await O2HttpClient.instance.get('${baseUrl()}jaxrs/attendancedetail/mobile/my');
  130. return ScheduleInfo.fromJson(response.data);
  131. } catch (err, stackTrace) {
  132. OLogger.e('查询打卡记录失败', err, stackTrace);
  133. }
  134. return null;
  135. }
  136. ///
  137. /// 查询工作打卡地点信息
  138. ///
  139. Future<List<WorkplaceInfo>?> listAllAttendanceWorkPlace() async {
  140. try {
  141. ApiResponse response =
  142. await O2HttpClient.instance.get('${baseUrl()}jaxrs/workplace/list/all');
  143. var list = response.data == null ? [] : response.data as List;
  144. return list.map((group) => WorkplaceInfo.fromJson(group)).toList();
  145. } catch (err, stackTrace) {
  146. OLogger.e('查询工作打卡地点信息失败', err, stackTrace);
  147. }
  148. return null;
  149. }
  150. /// 打卡
  151. Future<IdData?> checkInPost(MobileCheckPost body) async {
  152. try {
  153. ApiResponse response =
  154. await O2HttpClient.instance.post('${baseUrl()}jaxrs/attendancedetail/mobile/recive', body.toJson());
  155. return IdData.fromJson(response.data);
  156. } catch (err, stackTrace) {
  157. OLogger.e('打卡失败', err, stackTrace);
  158. }
  159. return null;
  160. }
  161. }