IHPermissionService.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // IHPermissionService.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/23.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyJSON
  10. class IHPermissionService: NSObject {
  11. static let share: IHPermissionService = {
  12. let share = IHPermissionService()
  13. return share
  14. }()
  15. override init() {
  16. }
  17. func getUserPermissInfo() {
  18. log.debug("getUserPermissInfo")
  19. var deviceArr = [String]()
  20. let username = AppShare.username
  21. let token = AppShare.token
  22. let os = AppShare.os
  23. let version = AppShare.version
  24. let client_key = AppShare.client_key
  25. let userId = AppShare.mLoginData?.id
  26. g_user_get_user_permissionHttpRequest(username, client_key: client_key, os: os, version: version, token: token, userId: userId!, success: { (json) -> (Void) in
  27. let mPermissionInfo = Permission_Info.fromJSON(json)
  28. let result = mPermissionInfo?.result
  29. if let rootNodes = result?.rootNodes,let airPurifierAuth = result?.airPurifierAuth,let sensorAuth = result?.sensorAuth,let lightAuth = result?.lightAuth,let cirLight = result?.cirLight{
  30. log.debug("rootNodes - \(rootNodes)")
  31. if airPurifierAuth == "0" {
  32. deviceArr.append("Air Purifier")
  33. }
  34. if sensorAuth == "0" {
  35. deviceArr.append("Sensor")
  36. }
  37. if lightAuth == "0" {
  38. deviceArr.append("Light")
  39. }
  40. if cirLight == "0" {
  41. deviceArr.append("Circadian light")
  42. }
  43. // requestSuccess!(rootNodes,deviceArr)
  44. }
  45. }) { () -> (Void) in
  46. // requestFail()
  47. }
  48. }
  49. func getUserPermissInfo(_ requestSuccess:(([IHTreeTableViewNode],[String]?)->Void)?,requestFail:@escaping (()->Void)) {
  50. log.debug("getUserPermissInfo")
  51. var deviceArr = [String]()
  52. let username = AppShare.username
  53. let token = AppShare.token
  54. let os = AppShare.os
  55. let version = AppShare.version
  56. let client_key = AppShare.client_key
  57. let userId = AppShare.mLoginData?.id
  58. g_user_get_user_permissionHttpRequest(username, client_key: client_key, os: os, version: version, token: token, userId: userId!, success: { (json) -> (Void) in
  59. let mPermissionInfo = Permission_Info.fromJSON(json)
  60. let result = mPermissionInfo?.result
  61. if let rootNodes = result?.rootNodes,let airPurifierAuth = result?.airPurifierAuth,let sensorAuth = result?.sensorAuth,let lightAuth = result?.lightAuth,let cirLight = result?.cirLight{
  62. log.debug("rootNodes - \(rootNodes)")
  63. if airPurifierAuth == "0" {
  64. deviceArr.append("Air Purifier")
  65. }
  66. if sensorAuth == "0" {
  67. deviceArr.append("Sensor")
  68. }
  69. if lightAuth == "0" {
  70. deviceArr.append("Light")
  71. }
  72. if cirLight == "0" {
  73. deviceArr.append("Circadian light")
  74. }
  75. requestSuccess!(rootNodes,deviceArr)
  76. }
  77. }) { () -> (Void) in
  78. requestFail()
  79. }
  80. }
  81. }