OOAttendanceAPI.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // OOAttendanceAPI.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2018/5/16.
  6. // Copyright © 2018年 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum OOAttendanceAPI {
  12. case attendanceDetailCheckIn(OOAttandanceMobileCheckinForm) //打卡
  13. case myAttendanceDetailMobileByPage(CommonPageModel,OOAttandanceMobileQueryBean) //获取打卡数据
  14. case myWorkplace //我的打卡地点列表
  15. case addWorkplace(OOAttandanceNewWorkPlace) //增加打卡地点
  16. case delWorkplace(String) //删除打卡地点
  17. case attendanceAdmin //是否可以设置打卡地点
  18. case checkinCycle(String,String) //考勤周期
  19. case checkinTotalForMonth(OOAttandanceTotalBean) //考勤统计
  20. case checkinAnalyze(OOAttandanceTotalBean) //考勤分析
  21. case listMyRecord //当前用户当前的打卡情况和班次
  22. }
  23. // MARK:- 上下文实现
  24. extension OOAttendanceAPI:OOAPIContextCapable {
  25. var apiContextKey: String {
  26. return "x_attendance_assemble_control"
  27. }
  28. }
  29. // MARK: - 是否需要加入x-token访问头
  30. extension OOAttendanceAPI:OOAccessTokenAuthorizable {
  31. public var shouldAuthorize: Bool {
  32. return true
  33. }
  34. }
  35. extension OOAttendanceAPI:TargetType {
  36. var baseURL: URL {
  37. let model = O2AuthSDK.shared.o2APIServer(context: .x_attendance_assemble_control)
  38. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  39. return URL(string: baseURLString)!
  40. }
  41. var path: String {
  42. switch self {
  43. case .addWorkplace(_):
  44. return "/jaxrs/workplace"
  45. case .attendanceAdmin:
  46. return "/jaxrs/attendanceadmin/list/all"
  47. case .attendanceDetailCheckIn(_):
  48. return "/jaxrs/attendancedetail/mobile/recive"
  49. case .delWorkplace(let id):
  50. return "/jaxrs/workplace/\(id)"
  51. case .myAttendanceDetailMobileByPage(let model, _):
  52. return "/jaxrs/attendancedetail/mobile/filter/list/page/1/count/\(model.pageSize)"
  53. case .myWorkplace:
  54. return "/jaxrs/workplace/list/all"
  55. case .checkinCycle(let year, let month):
  56. return "/jaxrs/attendancestatisticalcycle/cycleDetail/\(year)/\(month)"
  57. case .checkinTotalForMonth(_):
  58. return "/jaxrs/attendancedetail/filter/list"
  59. case .checkinAnalyze(let bean):
  60. return "/jaxrs/statisticshow/person/\(bean.q_empName!)/\(bean.q_year!)/\(bean.q_month!)"
  61. case .listMyRecord:
  62. return "/jaxrs/attendancedetail/mobile/my"
  63. }
  64. }
  65. var method: Moya.Method {
  66. switch self {
  67. case .addWorkplace(_):
  68. return .post
  69. case .attendanceAdmin:
  70. return .get
  71. case .attendanceDetailCheckIn(_):
  72. return .post
  73. case .delWorkplace(_):
  74. return .delete
  75. case .myAttendanceDetailMobileByPage(_, _):
  76. return .put
  77. case .myWorkplace:
  78. return .get
  79. case .checkinCycle(_, _):
  80. return .get
  81. case .checkinTotalForMonth(_):
  82. return .put
  83. case .checkinAnalyze(_):
  84. return .get
  85. case .listMyRecord:
  86. return .get
  87. }
  88. }
  89. var sampleData: Data {
  90. return "".data(using: String.Encoding.utf8)!
  91. }
  92. var task: Task {
  93. switch self {
  94. case .addWorkplace(let bean):
  95. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  96. case .attendanceAdmin:
  97. return .requestPlain
  98. case .attendanceDetailCheckIn(let bean):
  99. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  100. case .delWorkplace(_):
  101. return .requestPlain
  102. case .myAttendanceDetailMobileByPage(_,let bean):
  103. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  104. case .myWorkplace:
  105. return .requestPlain
  106. case .checkinCycle(_,_):
  107. return .requestPlain
  108. case .checkinTotalForMonth(let bean):
  109. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  110. case .checkinAnalyze(_):
  111. return .requestPlain
  112. case .listMyRecord:
  113. return .requestPlain
  114. }
  115. }
  116. var headers: [String : String]? {
  117. return nil
  118. }
  119. }