OOTaskAPI.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // OOTaskAPI.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/12/6.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum OOTaskAPI {
  12. // MARK:- 应用
  13. case getApplication
  14. case listApplicationWithPersonComplex
  15. case listApplicationWithPersonLike
  16. // MARK:- Task
  17. case taskDataSave(String,Dictionary<String,AnyObject>)
  18. case taskSaveAndSubmit(String,Dictionary<String,AnyObject>)
  19. case taskSubmitNeural(String, Dictionary<String, String>)
  20. case taskList(OOTaskPageParameter)
  21. case taskListFilter(String,String)
  22. case taskSubmit(String)
  23. case taskGetAttachmentInfo(String,String)
  24. case taskDownloadAttachment(String,String)
  25. case taskUpReplaceAttachment(String,String)
  26. case taskUploadAttachment(String)
  27. case taskCreateAvaiableIdentityById(String)
  28. // MARK:- TaskCompleted
  29. case taskedList(String,String)
  30. case taskedListFilter(String,String)
  31. case taskedDataById(String)
  32. case taskedGetAttachmentInfo(String,String)
  33. case taskedDownloadAttachment(String,String)
  34. // MARK:- Read
  35. case readSubmit(String)
  36. case readProcessing(String)
  37. case readList(String,String)
  38. case readListFilter(String,String)
  39. // MARK:- ReadCompleted
  40. case readedList(String,String)
  41. case readedListFilter(String,String)
  42. }
  43. // MARK:- 上下文实现
  44. extension OOTaskAPI:OOAPIContextCapable {
  45. var apiContextKey: String {
  46. return "x_processplatform_assemble_surface"
  47. }
  48. }
  49. // MARK: - 是否需要加入x-token访问头
  50. extension OOTaskAPI:OOAccessTokenAuthorizable {
  51. public var shouldAuthorize: Bool {
  52. return true
  53. }
  54. }
  55. // MARK: - Moya实现
  56. extension OOTaskAPI:TargetType{
  57. var baseURL: URL {
  58. let model = O2AuthSDK.shared.o2APIServer(context: .x_processplatform_assemble_surface)
  59. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  60. return URL(string: baseURLString)!
  61. }
  62. var path: String {
  63. switch self {
  64. case .taskList(let parameter):
  65. return "/jaxrs/task/list/\(parameter.pageParameter?.currentPageId ?? "(0)")/next/\(parameter.pageParameter?.countByPage ?? 20)"
  66. case .taskDataSave(let id,_):
  67. return "/jaxrs/data/work/\(id)"
  68. case .taskSaveAndSubmit(let id,_):
  69. return "/jaxrs/task/\(id)/processing"
  70. case .taskSubmitNeural(let id, _):
  71. return "jaxrs/task/\(id)/processing/neural"
  72. case .taskListFilter(let id, let count):
  73. return "/jaxrs/task/list/\(id)/next/\(count)/filter"
  74. case .taskSubmit(let id):
  75. return "/jaxrs/task/\(id)"
  76. case .taskGetAttachmentInfo(let attachId,let workId):
  77. return "/jaxrs/attachment/\(attachId)/work/\(workId)"
  78. case .taskDownloadAttachment(let attachId, let workId):
  79. return "/jaxrs/attachment/download/\(attachId)/work/\(workId)/stream/true"
  80. case .taskUpReplaceAttachment(let attachId, let workId):
  81. return "/jaxrs/attachment/update/\(attachId)/work/\(workId)"
  82. case .taskUploadAttachment(let workId):
  83. return "/jaxrs/attachment/upload/work/\(workId)"
  84. case .taskCreateAvaiableIdentityById(let processId):
  85. return "/jaxrs/process/list/available/identity/process/\(processId)"
  86. case .readList(let id, let count):
  87. return "/jaxrs/read/list/\(id)/next/\(count)"
  88. case .readListFilter(let id, let count):
  89. return "/jaxrs/read/list/\(id)/next/\(count)/filter"
  90. case .taskedList(let id, let count):
  91. return "/jaxrs/taskcompleted/list/\(id)/next/\(count)"
  92. case .taskedListFilter(let id, let count):
  93. return "/jaxrs/taskcompleted/list/\(id)/next/\(count)/filter"
  94. case .taskedDataById(let id):
  95. return "/jaxrs/taskcompleted/\(id)/reference"
  96. case .taskedGetAttachmentInfo(let attachId,let workCompletedId):
  97. return "/jaxrs/attachment/\(attachId)/work/\(workCompletedId)"
  98. case .taskedDownloadAttachment(let attachId, let workCompletedId):
  99. return "/jaxrs/attachment/download/\(attachId)/workcompleted/\(workCompletedId)"
  100. default:
  101. return ""
  102. }
  103. }
  104. var method: Moya.Method {
  105. switch self {
  106. case .taskDataSave(_, _):
  107. return .put
  108. case .taskSaveAndSubmit(_, _):
  109. return .post
  110. case .taskSubmitNeural(_,_):
  111. return .post
  112. default:
  113. return .get
  114. }
  115. }
  116. var sampleData: Data {
  117. return "".data(using: String.Encoding.utf8)!
  118. }
  119. var task: Task {
  120. switch self {
  121. case .taskDataSave(_, let param):
  122. return .requestParameters(parameters: param, encoding: JSONEncoding.default)
  123. case .taskSaveAndSubmit(_, let param):
  124. return .requestParameters(parameters: param, encoding: JSONEncoding.default)
  125. case .taskSubmitNeural(_, let param):
  126. return .requestParameters(parameters: param, encoding: JSONEncoding.default)
  127. default:
  128. return .requestPlain
  129. }
  130. }
  131. var headers: [String : String]? {
  132. return nil
  133. }
  134. }