IHLightModel.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. //
  2. // IHLightModel.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/10.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyJSON
  10. ///操作
  11. struct Operation_Result {
  12. var code : HttpApiStatus?
  13. var msg : String?
  14. }
  15. ///操作
  16. class Operation_Info: NSObject {
  17. var result : Operation_Result?
  18. var isSuccess : Bool
  19. var status : HttpApiStatus?
  20. init(result:Operation_Result?, isSuccess:Bool, status:HttpApiStatus?) {
  21. self.result = result; self.isSuccess = isSuccess; self.status = status
  22. }
  23. static func fromJSON(_ json:JSON) -> Operation_Info? {
  24. let code = HttpApiStatus(rawValue: json["code"].stringValue)
  25. let msg = json["msg"].stringValue
  26. var result = Operation_Result()
  27. result.msg = msg
  28. result.code = code
  29. var isSuccess = false
  30. if code == .Success {
  31. isSuccess = true
  32. }
  33. return Operation_Info(result: result, isSuccess: isSuccess, status: code)
  34. }
  35. }
  36. struct DevData {
  37. var id :String?//
  38. var name :String?//设备名称
  39. var devType:String? //设备类型(1 lights,2 circadian lights,3 sensor,4 air purifiers)
  40. var status:String?//开关状态(0 关,1 开)(lights,circadian lights,air purifiers设备使用)
  41. var online:String?// 网络状态(0 离线,1 在线)(sensor 设备使用)
  42. var level:String?//开关等级(air purifiers设备使用)
  43. var light:String?//亮度值(lights,circadian lights 设备使用)
  44. var color:String?//色温值(lights,circadian lights 设备使用)
  45. var alarmStatus:String? //故障状态(0 正常,1 异常)
  46. var alarmInfo : String? //故障内容
  47. var number:String?//房间号
  48. var image:String? // 设备图片地址
  49. var deviceId:String? // 设备地址
  50. var floorId:String? //楼层id
  51. var roomId:String? //房间id
  52. var floor:String? // 楼层数
  53. var mode :String? // 设备型号-酒店(0 WE-L10,1 WE-L20,2 WE-CL10,3 WE-CL20)(lights,circadian lights设备使用)
  54. //设备型号-学校(教室灯 0=>EL-DP02-1200-LY,1=>EL-DP03-1200-LY,2=>EL-WKDP03-1200-LY,黑板灯 0=>EL-HZJ01-1200-LY)
  55. var type : String? //设备类型(4 教室灯,5 黑板灯,6 窗帘,7 面板):教室
  56. var brightness: String? //亮度 : 教室
  57. var gatewayId: String? //网关id
  58. }
  59. struct Dev_list_Result {
  60. var code : HttpApiStatus?
  61. var msg : String?
  62. var list : [DevData]?
  63. }
  64. class Dev_list_Info: NSObject {
  65. var result : Dev_list_Result?
  66. var isSuccess : Bool
  67. var status : HttpApiStatus?
  68. init(result:Dev_list_Result?, isSuccess:Bool, status:HttpApiStatus?) {
  69. self.result = result; self.isSuccess = isSuccess; self.status = status
  70. }
  71. static func fromJSON(_ json:JSON) -> Dev_list_Info? {
  72. let code = HttpApiStatus(rawValue: json["code"].stringValue)
  73. let msg = json["msg"].stringValue
  74. let data = json["data"]
  75. let list = data["list"]
  76. var mList = [DevData]()
  77. guard let lightlist = list.array else { return nil }
  78. for vJSON in lightlist {
  79. var light = DevData()
  80. light.id = vJSON["id"].stringValue
  81. light.name = vJSON["name"].stringValue
  82. light.devType = vJSON["devType"].stringValue
  83. light.status = vJSON["status"].stringValue
  84. light.online = vJSON["online"].stringValue
  85. light.level = vJSON["level"].stringValue
  86. light.light = vJSON["light"].stringValue
  87. light.color = vJSON["color"].stringValue
  88. light.alarmStatus = vJSON["alarmStatus"].stringValue
  89. light.alarmInfo = vJSON["alarmInfo"].stringValue
  90. light.number = vJSON["roomNumber"].stringValue
  91. light.image = vJSON["image"].stringValue
  92. light.floorId = vJSON["floorId"].stringValue
  93. light.deviceId = vJSON["deviceId"].stringValue
  94. light.roomId = vJSON["roomId"].stringValue
  95. light.floor = vJSON["floor"].stringValue
  96. light.mode = vJSON["model"].stringValue
  97. //下面是教室才有的
  98. light.type = vJSON["type"].stringValue
  99. light.brightness = vJSON["brightness"].stringValue
  100. light.gatewayId = vJSON["gatewayId"].stringValue
  101. mList.append(light)
  102. }
  103. var isSuccess = false
  104. if code == .Success {
  105. isSuccess = true
  106. }
  107. let result = Dev_list_Result(code: code, msg: msg, list: mList)
  108. return Dev_list_Info(result: result, isSuccess: isSuccess, status: code)
  109. }
  110. }
  111. struct LightData {
  112. var id : String? // 设备id Y
  113. var name : String? // 设备名称 Y
  114. var deviceId : String? // 设备ID Y
  115. var floor : String? // 楼层 Y
  116. var roomNumber : String? // 房间号 Y
  117. var voltage : String? // 电压 Y
  118. var current :String? // 电流 Y
  119. var brightness : Int? // 亮度值 Y
  120. var color : Int? //: 色温值 Y
  121. var power : String? //: 功率值 Y
  122. var status : String?
  123. var online : String? // : 在线状态(0 离线,1 在线) Y
  124. var alarmStatus : String? // 故障状态(0 正常,1 故障) Y
  125. var model :String? // 设备型号(0 WE-L10,1 WE-L20,2 WE-CL10,3 WE-CL20)(lights,circadian lights设备使用)
  126. // var type : String? //设备类型(4 教室灯,5 黑板灯,6 窗帘,7 面板)
  127. }
  128. struct Light_list_Result {
  129. var code : HttpApiStatus?
  130. var msg : String?
  131. var list : [LightData]?
  132. var total : String? // 设备总数 Y
  133. }
  134. class Light_list_Info: NSObject {
  135. var result : Light_list_Result?
  136. var isSuccess : Bool
  137. var status : HttpApiStatus?
  138. init(result:Light_list_Result?, isSuccess:Bool, status:HttpApiStatus?) {
  139. self.result = result; self.isSuccess = isSuccess; self.status = status
  140. }
  141. static func fromJSON(_ json:JSON) -> Light_list_Info? {
  142. let code = HttpApiStatus(rawValue: json["code"].stringValue)
  143. let msg = json["msg"].stringValue
  144. let data = json["data"]
  145. let list = data["list"]
  146. var mList = [LightData]()
  147. guard let lightlist = list.array else { return nil }
  148. for vJSON in lightlist {
  149. var light = LightData()
  150. light.id = vJSON["id"].stringValue
  151. light.name = vJSON["name"].stringValue
  152. light.deviceId = vJSON["deviceId"].stringValue
  153. light.floor = vJSON["floor"].stringValue
  154. light.roomNumber = vJSON["roomNumber"].stringValue
  155. light.voltage = vJSON["voltage"].stringValue
  156. light.current = vJSON["current"].stringValue
  157. light.brightness = vJSON["brightness"].intValue
  158. light.color = vJSON["color"].intValue
  159. light.status = vJSON["status"].stringValue
  160. light.power = vJSON["power"].stringValue
  161. light.online = vJSON["online"].stringValue
  162. light.alarmStatus = vJSON["alarmStatus"].stringValue
  163. light.model = vJSON["model"].stringValue
  164. mList.append(light)
  165. }
  166. var isSuccess = false
  167. if code == .Success {
  168. isSuccess = true
  169. }
  170. let total = json["total"].stringValue
  171. let result = Light_list_Result(code: code, msg: msg, list: mList,total: total)
  172. return Light_list_Info(result: result, isSuccess: isSuccess, status: code)
  173. }
  174. }
  175. //设备详情
  176. struct LightInfodata {
  177. var name : String? // 设备名称 Y
  178. var deviceId : String? // 设备ID Y
  179. var floorId : String? // 楼层 Y
  180. var roomId : String? // 房间id Y
  181. var light : Int? // 亮度值 // Y
  182. var color : Int? // 色温值 // Y
  183. var colorR : Int? // R色值 // Y
  184. var colorG : Int? // G色值 // Y
  185. var colorB : Int? // B色值 Y
  186. var alarmStatus : String? // 故障状态(0 正常,1 故障) Y
  187. var alarmInfo : String? // 故障信息 Y
  188. var status : String? // 路灯状态(0 关,1 开)
  189. var model :String? // 设备型号(0 WE-L10,1 WE-L20,2 WE-CL10,3 WE-CL20)(lights,circadian lights设备使用)
  190. }
  191. struct LightInfo_Result {
  192. var code : HttpApiStatus?
  193. var msg : String?
  194. var data : LightInfodata?
  195. }
  196. class LightInfo_Info: NSObject {
  197. var result : LightInfo_Result?
  198. var isSuccess : Bool
  199. var status : HttpApiStatus?
  200. init(result:LightInfo_Result?, isSuccess:Bool, status:HttpApiStatus?) {
  201. self.result = result; self.isSuccess = isSuccess; self.status = status
  202. }
  203. static func fromJSON(_ json:JSON) -> LightInfo_Info? {
  204. let code = HttpApiStatus(rawValue: json["code"].stringValue)
  205. let msg = json["msg"].stringValue
  206. let data = json["data"]
  207. var result = LightInfo_Result()
  208. result.msg = msg
  209. result.code = code
  210. let name = data["name"].stringValue
  211. let deviceId = data["deviceId"].stringValue
  212. let floorId = data["floorId"].stringValue
  213. let roomId = data["roomId"].stringValue
  214. let light = data["light"].intValue
  215. let color = data["color"].intValue
  216. let colorR = data["colorR"].intValue
  217. let colorG = data["colorG"].intValue
  218. let colorB = data["colorB"].intValue
  219. let alarmStatus = data["alarmStatus"].stringValue
  220. let alarmInfo = data["alarmInfo"].stringValue
  221. let status = data["status"].stringValue
  222. let model = data["model"].stringValue
  223. let lightdata = LightInfodata(name: name, deviceId: deviceId, floorId: floorId, roomId: roomId, light: light, color: color, colorR: colorR, colorG: colorG, colorB: colorB, alarmStatus: alarmStatus, alarmInfo: alarmInfo,status: status,model: model)
  224. result.data = lightdata
  225. var isSuccess = false
  226. if code == .Success {
  227. isSuccess = true
  228. }
  229. return LightInfo_Info(result: result, isSuccess: isSuccess, status: code)
  230. }
  231. }
  232. //设备日志信息
  233. struct ReportData {
  234. var dataList : [String]? // 数据列表 Y
  235. var dateList : [String]? // 时间列表 Y
  236. var timeList : [String]? //时间列表
  237. }
  238. struct Report_Result {
  239. var code : HttpApiStatus?
  240. var msg : String?
  241. var data : ReportData?
  242. }
  243. class Report_Info: NSObject {
  244. var result : Report_Result?
  245. var isSuccess : Bool
  246. var status : HttpApiStatus?
  247. init(result:Report_Result?, isSuccess:Bool, status:HttpApiStatus?) {
  248. self.result = result; self.isSuccess = isSuccess; self.status = status
  249. }
  250. static func fromJSON(_ json:JSON) -> Report_Info? {
  251. let code = HttpApiStatus(rawValue: json["code"].stringValue)
  252. let msg = json["msg"].stringValue
  253. let data = json["data"]
  254. var result = Report_Result()
  255. result.msg = msg
  256. result.code = code
  257. let dataList = data["dataList"]
  258. guard let _DataList = dataList.array else { return nil }
  259. var mDataList = [String]()
  260. for aData in _DataList {
  261. let dataStr = aData.stringValue
  262. mDataList.append(dataStr)
  263. }
  264. let dateList = data["dateList"]
  265. var mDateList = [String]()
  266. if let _DateList = dateList.array {
  267. for aDate in _DateList {
  268. let dateStr = aDate.stringValue
  269. mDateList.append(dateStr)
  270. }
  271. }
  272. let timeList = data["timeList"]
  273. var mTimeList = [String]()
  274. if let _TimeList = timeList.array {
  275. for aTime in _TimeList {
  276. let timeStr = aTime.stringValue
  277. mTimeList.append(timeStr)
  278. }
  279. }
  280. let lightListdata = ReportData(dataList: mDataList, dateList: mDateList,timeList: mTimeList)
  281. result.data = lightListdata
  282. var isSuccess = false
  283. if code == .Success {
  284. isSuccess = true
  285. }
  286. return Report_Info(result: result, isSuccess: isSuccess, status: code)
  287. }
  288. }