| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- package com.grkj.iscs.util
- import com.grkj.iscs.MyApplication
- import com.grkj.iscs.model.Token
- import com.grkj.iscs.model.UrlConsts
- import com.grkj.iscs.model.vo.card.CardInfoRespVO
- import com.grkj.iscs.model.vo.dept.DeptListRespVO
- import com.grkj.iscs.model.vo.sop.SopInfoRespVO
- import com.grkj.iscs.model.vo.sop.SopPageRespVO
- import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
- import com.grkj.iscs.model.vo.ticket.TicketPageRespVO
- import com.grkj.iscs.model.vo.ticket.TicketTypeRespVO
- import com.grkj.iscs.model.vo.user.UserListRespVO
- /**
- * 网络请求
- */
- object NetApi {
- /**
- * 登录
- */
- fun login(username: String, password: String, callBack: (Boolean?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.SIGN_IN,
- false,
- mapOf(
- "username" to username,
- "password" to password
- ),
- { res, _, _ ->
- res?.let {
- val newToken = it.toBean(Token::class.java)
- newToken.saveToSp(MyApplication.instance!!.applicationContext)
- callBack.invoke(true)
- } ?: run {
- callBack.invoke(false)
- }
- }, isGet = false, isAuth = false)
- }
- /**
- * 退出登录
- */
- fun logout() {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.LOGOUT,
- false,
- mapOf<String, String>(),
- { res, _, _ ->
- SPUtils.clearLoginUser(MyApplication.instance!!.applicationContext)
- Token.clear(MyApplication.instance!!.applicationContext)
- }, isGet = true, isAuth = false
- )
- }
- /**
- * 刷卡登录
- */
- fun cardLogin(cardNfc: String, callBack: (Boolean?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.LOGIN_CARD,
- false,
- mapOf(
- "cardNfc" to cardNfc
- ),
- { res, _, _ ->
- res?.let {
- val newToken = it.toBean(Token::class.java)
- newToken.saveToSp(MyApplication.instance!!.applicationContext)
- callBack.invoke(true)
- } ?: run {
- callBack.invoke(false)
- }
- }, isGet = false, isAuth = false)
- }
- /**
- * 获取SOP分页
- */
- fun getSopPage(current: Int, size: Int, callBack: (SopPageRespVO?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.SOP_PAGE,
- false,
- mapOf(
- "current" to current,
- "size" to size
- ),
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true)
- }
- /**
- * 获取工作票类型
- */
- fun getTicketType(callBack: (MutableList<TicketTypeRespVO>?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.TICKET_TYPE,
- false,
- mapOf<String,String>(),
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true)
- }
- /**
- * 获取一个自动编号
- */
- fun getAutoCode(type: String, callBack: (String?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.AUTO_CODE + "/" +type,
- false,
- mapOf<String, String>(),
- { res, _, _ ->
- res?.let {
- callBack.invoke(it.toString())
- }
- }, isGet = true, isAuth = true)
- }
- /**
- * 获取SOP详情
- */
- fun getSopInfo(sopId: Long, callBack: (SopInfoRespVO?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.SOP_INFO,
- false,
- mapOf(
- "sopId" to sopId
- ),
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true)
- }
- /**
- * 获取用户列表
- */
- fun getUserList(pageNum: Int, pageSize: Int, callBack: (UserListRespVO?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.USER_LIST,
- false,
- mapOf(
- "pageNum" to pageNum,
- "pageSize" to pageSize
- ),
- { res, _, _ ->
- res?.let {
- callBack.invoke(it.toBean(UserListRespVO::class.java))
- }
- }, isGet = true, isAuth = true)
- }
- /**
- * 获取部门列表
- */
- fun getDeptList(pageNum: Int, pageSize: Int, callBack: (MutableList<DeptListRespVO>?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.DEPT_List,
- false,
- mapOf(
- "pageNum" to pageNum,
- "pageSize" to pageSize
- ),
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true
- )
- }
- /**
- * 创建工作票
- */
- fun createTicket() {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.CREATE_TICKET,
- false,
- mapOf<String, String>(),
- { res, _, _ ->
- res?.let {
- //TODO 创建工作票结果
- }
- }, isGet = false, isAuth = true
- )
- }
- /**
- * 获取工作票分页
- */
- fun getTicketPage(pageNum: Int, pageSize: Int, userId: Long, ticketStatus: Int?, callBack: (TicketPageRespVO?) -> Unit) {
- val map = mutableMapOf(
- "pageNum" to pageNum,
- "pageSize" to pageSize,
- "userId" to userId
- )
- if (ticketStatus != null) {
- map["ticketStatus"] = ticketStatus
- }
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.PAGE_TICKET,
- false,
- map,
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true
- )
- }
- /**
- * 获取作业票详细信息
- */
- fun getTicketDetail(ticketId: Long, callBack: (TicketDetailRespVO?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.DETAIL_TICKET,
- false,
- mapOf("ticketId" to ticketId),
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true
- )
- }
- /**
- * 获取刷卡信息
- */
- fun getCardInfo(callBack: (CardInfoRespVO?) -> Unit) {
- NetHttpManager.getInstance().doRequestNet(
- UrlConsts.CARD_INFO,
- false,
- mapOf<String, String>(),
- { res, _, _ ->
- res?.let {
- callBack.invoke(getRefBean(it))
- }
- }, isGet = true, isAuth = true
- )
- }
- }
|