123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // IHClassRoomService.swift
- // Inhealth
- //
- // Created by weclouds on 2020/6/15.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- class IHClassRoomService: NSObject {
- static let share : IHClassRoomService = IHClassRoomService()
- var clientId : String?
-
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
-
- // 所有设备
- func getDeviceList( roomId:String,requstSuccess:@escaping (([ShoolDeviceList])->Void),requestFail:@escaping (()->Void)){
-
- g_school_dev_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, roomId: roomId, success: { (json) -> (Void) in
- let deviceList = Shool_Dev_List.fromJSON(json)
- let result = deviceList?.result
- if let roomlist = result?.list{
- requstSuccess(roomlist)
- }
- }, fail: requestFail)
- }
- //更换灯的位置
- // func chargeLight(infoList : [[String : String]],id : String, location : String,requstSuccess:@escaping ((Shool_Charge_Location)->Void),requestFail:@escaping (()->Void)) {
- // g_school_charge_locationHttpRequest(username, client_key: client_key, os: os, version: version, token: token, infoList: infoList, success: { (json) -> (Void) in
- // //要改
- //
- // }, fail: requestFail)
- // }
- //
-
- //更换灯的位置(_ json :JSON) ->(Void)
- func saveLight(infoList: [[String:String]],requstSuccess:@escaping ((_ data : String)->Void),requestFail:@escaping (()->Void)) {
-
-
- g_school_charge_locationHttpRequest(username, client_key: client_key, os: os, version: version, token: token, infoList: infoList, success: { (json) -> (Void) in
- //要改
- log.debug("位置\(json)")
- //json解释
- requstSuccess(json["code"].stringValue)
- }, fail: requestFail)
- }
-
- //窗帘的开关
- func curtainOnOff(id : String, status : String,requstSuccess:@escaping((_ data : String,String)->Void),requestFail:@escaping (()->Void)) {
- HUD.show(.progress)
- self.getWebSocketId(id : id, status : status, requestFail: requestFail, success: requstSuccess)
- }
-
- //获取websocket - clientId
- func getWebSocketId(id : String, status : String,requestFail:@escaping (()->Void),success:@escaping (_ msg : String,_ code : String)->()) {
- IHWebSocketManager.shareInstance().schoolDeviceOpation(isSchool: true) { (isSuccess, responeStr,code) in
- if isSuccess == 2 {
- log.debug("websocket窗帘返回的数据")
-
- g_showHUD(responeStr)
- HUD.hide(afterDelay: 1)
- success(responeStr,code)
- }else{
- // guard let clientId = responeStr else{return}
- //isSuccess == 1时,responeStr是clientId
- g_school_set_curtainHttpRequest(self.username, client_key: self.client_key, os: self.os
- , version: self.version, token: self.token, id: id, status: status, clientId:responeStr , success: { (json) -> (Void) in
- // log.debug("窗帘返回的数据\(json)")
- // success(json["msg"].stringValue)
- }, fail: requestFail)
- }
-
-
- }
- }
-
-
- //灯的全开/全关 模式类型(1 全开模式,2 全关模式,3 投影模式,4 自习模式,5 板书模式,7 上课模式,8 下课模式,9 午休模式)
- func setLights_on_off(roomId : String, type : String,success:@escaping (_ msg : String,_ code: String)->(),requestFail:@escaping (()->Void)) {
- HUD.show(.progress)
- // HUD.hide(afterDelay: 15) { (isSuccess) in // 15s超时提醒
- // g_showHUD("Request timeout")
- // }
-
- IHWebSocketManager.shareInstance().schoolDeviceOpation(isSchool: true) { (isSuccess, responeStr,code ) in
- if isSuccess == 2 {
- log.debug("websocket-开关返回的数据\(responeStr)")
- g_showHUD(responeStr)
- HUD.hide(afterDelay: 1)
- success(responeStr,code)
- }else{
- //isSuccess == 1时返回的是clientId
- g_school_set_offHttpRequest(self.username, client_key: self.client_key, os: self.os, version: self.version, token: self.token, roomId: roomId, type: type, clientId: responeStr, success: { (json) -> (Void) in
- log.debug("开关返回的数据")
- }, fail: requestFail)
- }
- }
- }
-
-
- //教室灯的整体色温 -- 暂时不用做
- func lightsColor(classDevices : [ShoolDeviceList]) {
- //循环给每个教室灯发命令
- let count = classDevices.count
- var index = 0
-
- IHWebSocketManager.shareInstance().schoolDeviceOpation(isSchool: true) { (isSuccess, responeStr,code) in
- if isSuccess == 2 {
- log.debug("websocket-教室灯的色温")
- self.loopSetlightColor(index: index, count: count, responeStr: responeStr, classDevices: classDevices)
-
- // success(responeStr ?? "")
- }else{
- // guard let clientId = responeStr else{return}
- //issuccess == 1时responeStr是clientId
- guard let id = classDevices[index].id else {return}
- guard var color = classDevices[index].color else {return}
- //色温 : 3000 - 6000 ,间隔 300
- guard var colorValue = Int(color) else {return}
- if colorValue < 6000{
- colorValue = colorValue + 300
- }
- if colorValue == 6000{
- colorValue = 3000
- }
- color = ("\(colorValue)")
- g_school_set_colorHttpRequest(self.username, client_key: self.client_key, os: self.os, version: self.version, token: self.token, id: id, color: color, clientId: responeStr, success: { (json) -> (Void) in
- log.debug("----")
- }) { () -> (Void) in
- log.debug("----")
- }
-
- index = index + 1
- }
-
- }
- }
-
- func loopSetlightColor(index : Int ,count : Int,responeStr:String? ,classDevices : [ShoolDeviceList]) {
- var index = index
- if index < count {
-
- IHWebSocketManager.shareInstance().schoolDeviceOpation(isSchool: true) { (isSuccess, responeStr,code) in
- if isSuccess == 2 {
- log.debug("websocket-教室灯的色温")
- self.loopSetlightColor(index: index, count: count, responeStr: responeStr, classDevices: classDevices)
-
- // success(responeStr ?? "")
- }
- //self.loopSetlightColor(index: index, count: count, responeStr: responeStr, classDevices: classDevices)
- }
- guard let clientId = responeStr else{return}
- guard let id = classDevices[index].id else {return}
- guard var color = classDevices[index].color else {return}
- //色温 : 3000 - 6000 ,间隔 300
- guard var colorValue = Int(color) else {return}
- if colorValue < 6000{
- colorValue = colorValue + 300
- }
- if colorValue == 6000{
- colorValue = 3000
- }
- color = ("\(colorValue)")
- g_school_set_colorHttpRequest(self.username, client_key: self.client_key, os: self.os, version: self.version, token: self.token, id: id, color: color, clientId: clientId, success: { (json) -> (Void) in
- log.debug("----")
- }) { () -> (Void) in
- log.debug("----")
- }
-
- index = index + 1
- }
- }
-
-
- //
- }
|