NetApi.kt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package com.grkj.iscs.util
  2. import com.grkj.iscs.MyApplication
  3. import com.grkj.iscs.model.Token
  4. import com.grkj.iscs.model.UrlConsts
  5. import com.grkj.iscs.model.vo.card.CardInfoRespVO
  6. import com.grkj.iscs.model.vo.dept.DeptListRespVO
  7. import com.grkj.iscs.model.vo.sop.SopInfoRespVO
  8. import com.grkj.iscs.model.vo.sop.SopPageRespVO
  9. import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
  10. import com.grkj.iscs.model.vo.ticket.TicketPageRespVO
  11. import com.grkj.iscs.model.vo.ticket.TicketTypeRespVO
  12. import com.grkj.iscs.model.vo.user.UserListRespVO
  13. /**
  14. * 网络请求
  15. */
  16. object NetApi {
  17. /**
  18. * 登录
  19. */
  20. fun login(username: String, password: String, callBack: (Boolean?) -> Unit) {
  21. NetHttpManager.getInstance().doRequestNet(
  22. UrlConsts.SIGN_IN,
  23. false,
  24. mapOf(
  25. "username" to username,
  26. "password" to password
  27. ),
  28. { res, _, _ ->
  29. res?.let {
  30. val newToken = it.toBean(Token::class.java)
  31. newToken.saveToSp(MyApplication.instance!!.applicationContext)
  32. callBack.invoke(true)
  33. } ?: run {
  34. callBack.invoke(false)
  35. }
  36. }, isGet = false, isAuth = false)
  37. }
  38. /**
  39. * 退出登录
  40. */
  41. fun logout() {
  42. NetHttpManager.getInstance().doRequestNet(
  43. UrlConsts.LOGOUT,
  44. false,
  45. mapOf<String, String>(),
  46. { res, _, _ ->
  47. SPUtils.clearLoginUser(MyApplication.instance!!.applicationContext)
  48. Token.clear(MyApplication.instance!!.applicationContext)
  49. }, isGet = true, isAuth = false
  50. )
  51. }
  52. /**
  53. * 刷卡登录
  54. */
  55. fun cardLogin(cardNfc: String, callBack: (Boolean?) -> Unit) {
  56. NetHttpManager.getInstance().doRequestNet(
  57. UrlConsts.LOGIN_CARD,
  58. false,
  59. mapOf(
  60. "cardNfc" to cardNfc
  61. ),
  62. { res, _, _ ->
  63. res?.let {
  64. val newToken = it.toBean(Token::class.java)
  65. newToken.saveToSp(MyApplication.instance!!.applicationContext)
  66. callBack.invoke(true)
  67. } ?: run {
  68. callBack.invoke(false)
  69. }
  70. }, isGet = false, isAuth = false)
  71. }
  72. /**
  73. * 获取SOP分页
  74. */
  75. fun getSopPage(current: Int, size: Int, callBack: (SopPageRespVO?) -> Unit) {
  76. NetHttpManager.getInstance().doRequestNet(
  77. UrlConsts.SOP_PAGE,
  78. false,
  79. mapOf(
  80. "current" to current,
  81. "size" to size
  82. ),
  83. { res, _, _ ->
  84. res?.let {
  85. callBack.invoke(getRefBean(it))
  86. }
  87. }, isGet = true, isAuth = true)
  88. }
  89. /**
  90. * 获取工作票类型
  91. */
  92. fun getTicketType(callBack: (MutableList<TicketTypeRespVO>?) -> Unit) {
  93. NetHttpManager.getInstance().doRequestNet(
  94. UrlConsts.TICKET_TYPE,
  95. false,
  96. mapOf<String,String>(),
  97. { res, _, _ ->
  98. res?.let {
  99. callBack.invoke(getRefBean(it))
  100. }
  101. }, isGet = true, isAuth = true)
  102. }
  103. /**
  104. * 获取一个自动编号
  105. */
  106. fun getAutoCode(type: String, callBack: (String?) -> Unit) {
  107. NetHttpManager.getInstance().doRequestNet(
  108. UrlConsts.AUTO_CODE + "/" +type,
  109. false,
  110. mapOf<String, String>(),
  111. { res, _, _ ->
  112. res?.let {
  113. callBack.invoke(it.toString())
  114. }
  115. }, isGet = true, isAuth = true)
  116. }
  117. /**
  118. * 获取SOP详情
  119. */
  120. fun getSopInfo(sopId: Long, callBack: (SopInfoRespVO?) -> Unit) {
  121. NetHttpManager.getInstance().doRequestNet(
  122. UrlConsts.SOP_INFO,
  123. false,
  124. mapOf(
  125. "sopId" to sopId
  126. ),
  127. { res, _, _ ->
  128. res?.let {
  129. callBack.invoke(getRefBean(it))
  130. }
  131. }, isGet = true, isAuth = true)
  132. }
  133. /**
  134. * 获取用户列表
  135. */
  136. fun getUserList(pageNum: Int, pageSize: Int, callBack: (UserListRespVO?) -> Unit) {
  137. NetHttpManager.getInstance().doRequestNet(
  138. UrlConsts.USER_LIST,
  139. false,
  140. mapOf(
  141. "pageNum" to pageNum,
  142. "pageSize" to pageSize
  143. ),
  144. { res, _, _ ->
  145. res?.let {
  146. callBack.invoke(it.toBean(UserListRespVO::class.java))
  147. }
  148. }, isGet = true, isAuth = true)
  149. }
  150. /**
  151. * 获取部门列表
  152. */
  153. fun getDeptList(pageNum: Int, pageSize: Int, callBack: (MutableList<DeptListRespVO>?) -> Unit) {
  154. NetHttpManager.getInstance().doRequestNet(
  155. UrlConsts.DEPT_List,
  156. false,
  157. mapOf(
  158. "pageNum" to pageNum,
  159. "pageSize" to pageSize
  160. ),
  161. { res, _, _ ->
  162. res?.let {
  163. callBack.invoke(getRefBean(it))
  164. }
  165. }, isGet = true, isAuth = true
  166. )
  167. }
  168. /**
  169. * 创建工作票
  170. */
  171. fun createTicket() {
  172. NetHttpManager.getInstance().doRequestNet(
  173. UrlConsts.CREATE_TICKET,
  174. false,
  175. mapOf<String, String>(),
  176. { res, _, _ ->
  177. res?.let {
  178. //TODO 创建工作票结果
  179. }
  180. }, isGet = false, isAuth = true
  181. )
  182. }
  183. /**
  184. * 获取工作票分页
  185. */
  186. fun getTicketPage(pageNum: Int, pageSize: Int, userId: Long, ticketStatus: Int?, callBack: (TicketPageRespVO?) -> Unit) {
  187. val map = mutableMapOf(
  188. "pageNum" to pageNum,
  189. "pageSize" to pageSize,
  190. "userId" to userId
  191. )
  192. if (ticketStatus != null) {
  193. map["ticketStatus"] = ticketStatus
  194. }
  195. NetHttpManager.getInstance().doRequestNet(
  196. UrlConsts.PAGE_TICKET,
  197. false,
  198. map,
  199. { res, _, _ ->
  200. res?.let {
  201. callBack.invoke(getRefBean(it))
  202. }
  203. }, isGet = true, isAuth = true
  204. )
  205. }
  206. /**
  207. * 获取作业票详细信息
  208. */
  209. fun getTicketDetail(ticketId: Long, callBack: (TicketDetailRespVO?) -> Unit) {
  210. NetHttpManager.getInstance().doRequestNet(
  211. UrlConsts.DETAIL_TICKET,
  212. false,
  213. mapOf("ticketId" to ticketId),
  214. { res, _, _ ->
  215. res?.let {
  216. callBack.invoke(getRefBean(it))
  217. }
  218. }, isGet = true, isAuth = true
  219. )
  220. }
  221. /**
  222. * 获取刷卡信息
  223. */
  224. fun getCardInfo(callBack: (CardInfoRespVO?) -> Unit) {
  225. NetHttpManager.getInstance().doRequestNet(
  226. UrlConsts.CARD_INFO,
  227. false,
  228. mapOf<String, String>(),
  229. { res, _, _ ->
  230. res?.let {
  231. callBack.invoke(getRefBean(it))
  232. }
  233. }, isGet = true, isAuth = true
  234. )
  235. }
  236. }