123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915 |
- //
- // IHEquipmentlistManager.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/18.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- class IHEquipmentlistManager: NSObject ,IHViewManagerProtocolDelegate{
- var hotelId : String?
- var devType: String? = "0"
- var devDataList:[DevData]?
- var gatewayList :[GatewayData]?
- var currentIndex:Int? = 0
- var schoolPage = 1
- var isSchool : String = "0"
- private var manager_currentFloorId : String?
- private var manager_currentRoomId : String?
- // let searchVc = IHEquipmentSeachVCtr()
- lazy var mainView: IHEquipmentlistView = {
- let mainView = IHEquipmentlistView()
- mainView.delegate = self
- return mainView
- }()
- //http://www.iotena-web.com/upload/image/hotel_avatar.jpg
- // private var vc = UIViewController()
-
- private weak var vc : UIViewController?
-
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- if Intermediate.hotelId == ""{
- createUI()
- }else{
- schoolOrHotel(hotelId: Intermediate.hotelId )
- }
- }
-
-
- //先知道是否学校
- func schoolOrHotel(hotelId:String) {
- IHEquipmentService.share.getSchoolOrHotelInfo(hotelId: hotelId, requestSuccess: { (isSchool) in
- self.isSchool = isSchool
- self.schoolPage = 1
- self.createUI()
- }) {
- log.debug("-学校失败--")
- }
- }
-
- override init() {
- super.init()
- NotificationCenter.default.addObserver(self, selector: #selector(reloadAddressNotify), name: NSNotification.Name(kNotificationIHAddressControllerReloadAddress), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(reloadAddressNotify), name: NSNotification.Name(kNotificationIHAddressControllerReloadAddress), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(refreshData), name: NSNotification.Name(kNotificationIHNewEquipmentManagerEditEquipmentReload), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(refreshData), name: NSNotification.Name(kNotifactionIHEquipmentSeachManagerAfterDeleteEquipment), object: nil)
-
- //刷新学校列表
- NotificationCenter.default.addObserver(self, selector: #selector(refreshSchoolData), name: NSNotification.Name(kNotificationReloadEquipmentInfo), object: nil)
- }
-
- @objc func refreshSchoolData(noti : Notification){
-
- self.equipmentDidSelectedItemAt(self.currentIndex!,floorId : manager_currentFloorId,roomId:manager_currentRoomId)
- }
-
- @objc func reloadAddressNotify() {
- var title = Intermediate.hotelName
- if Intermediate.buildName != "所有" {
- title = "\(Intermediate.hotelName) · \(Intermediate.buildName)"
- }
- self.vc?.navigationBarTitle = title
-
- getSchoolOrHotel(hotelId: Intermediate.hotelId)
-
- }
-
- //再次获取是否学校
- func getSchoolOrHotel(hotelId:String) {
- IHEquipmentService.share.getSchoolOrHotelInfo(hotelId: hotelId, requestSuccess: { (isSchool) in
- self.isSchool = isSchool
-
- if self.isSchool == "1" {
- let type = "\(self.currentIndex!)"
- if type == "0"{
- //全部
- self.devType = "4"
- }
- if type == "1"{
- //教室灯
- self.devType = "0"
- }
- if type == "2"{
- //黑板灯
- self.devType = "1"
- }
- if type == "3"{
- //面板
- self.devType = "3"
- }
- if type == "4"{
- //窗帘
- self.devType = "2"
- }
- if type == "5"{
- //窗帘
- self.devType = "5"
- }
- self.mainView.isSchool = true
- self.mainView.currentFloorId = nil
- self.mainView.currentRoomId = nil
- self.manager_currentFloorId = nil
- self.manager_currentRoomId = nil
- self.mainView.floorBtn?.setTitle("所有", for: .normal)
- self.mainView.roomBtn?.setTitle("所有", for: .normal)
- self.mainView.classRoomList = nil
- self.schoolPage = 1
- let group = DispatchGroup()
- let queue1 = DispatchQueue(label: "getAllFloors")
- queue1.async {
- //获取楼层
- self.getAllFloors()
- }
-
- let queue2 = DispatchQueue(label: "getAllData")
- queue2.async {
- //获取所有的数据
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: nil,roomId:nil, type: self.devType!)
- }
- group.notify(queue: DispatchQueue.main) {
- DispatchQueue.main.async {
- g_showSuccess()
- }
-
- }
-
-
- }else{
- // 酒店
- self.mainView.isSchool = false
- self.requiest(Intermediate.hotelId,devType: "0", completion: nil)
-
- self.hotelId = Intermediate.hotelId
-
- // self.requiest(self.hotelId, devType: devType!, completion: nil)
- self.requiest(self.hotelId, devType: "\(self.currentIndex!)", completion: nil)
-
- }
- }) {
- HUD.show(.label("网络出错"))
- log.debug("-学校失败--")
- }
- }
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- func createUI() {
- mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - KTabbarHeight)
- self.vc?.view.addSubview(mainView)
-
- setNavigationBar()
-
- if self.isSchool == "1" {
- //判断学校
- mainView.isSchool = true
- //获取所有的楼层
- getAllFloors()
- }else{
- mainView.isSchool = false
- }
- HUD.show(.progress)
-
- if Intermediate.hotelId == "" {
- IHAddressService.share.getFirstHotel { (hotelId, hotelName) in
-
- self.vc?.navigationBarTitle = hotelName
- self.hotelId = hotelId
- self.requiest(hotelId, devType: "0" , completion: nil )
- }
- }else{
- self.vc?.navigationBarTitle = Intermediate.hotelName
- self.hotelId = Intermediate.hotelId
- if(self.isSchool == "0"){
- //酒店
- self.requiest(hotelId, devType: "0" , completion: nil)
- }else{
- //学校
- // 设备类型(4 教室灯,5 黑板灯,6 窗帘,7 面板)
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: nil,roomId: nil,type:"4")
- }
-
-
- }
- }
- //获取学校的相应设备
- func getSchoolDevList(hotelId : String?,builId : String?,floorId : String?,roomId:String?,type : String) {
- if type != "5" {
- IHEquipmentService.share.getSchoolDevList(hotelId: hotelId, buildId: builId, floorId:floorId,roomId: roomId, page: self.schoolPage, type: type, keywords: nil, requestSuccess: { (devList) in
- log.debug("---获取整个学校---\(devList)")
- HUD.hide()
- self.mainView.endReflesh()
- if self.schoolPage == 1{
- self.mainView.devDataList = devList
- }else{
- self.mainView.devDataList = self.mainView.devDataList! + devList
- }
- //传给搜索的vc
- self.devDataList = self.mainView.devDataList
- }) {
-
- }
- }
- if type == "5"{
- //获取网关
- self.getGateWayInfo(buildId: Intermediate.buildId,page:"\(self.schoolPage)", keywords: nil)
- }
-
- }
-
- //获取网关相关的信息
- func getGateWayInfo(buildId: String,page : String,keywords:String?){
- IHGatewayService.share.getGatewayList(buildId: Intermediate.buildId,page : page, keywords: keywords, requestSuccess: { (list) in
- //[GatewayData]
- self.gatewayList = list
- //self.mainView.totalGateWayList = list
- //self.mainView.gatewayList = list
- HUD.hide()
- //停止更新
- self.mainView.endReflesh()
- if self.schoolPage == 1{
- self.mainView.gatewayList = list
- }else{
- self.mainView.gatewayList = self.mainView.gatewayList! + list
- }
-
- // //第一次或所有的按键都是all
- // if self.mainView.floorValue == "所有" && self.mainView.classRoomValue == "所有"{
- // self.mainView.totalGateWayList = list
- // self.mainView.gatewayList = list
- //
- // }
- // //选择了楼层与教室之后的每个按键
- // if self.mainView.isFilter == true{
- // var gateways = [GatewayData]()
- // for value in list {
- // if value.floor! == self.mainView.floorValue && value.roomNumber! == self.mainView.classRoomValue && self.mainView.classRoomValue != "所有"{
- // gateways.append(value)
- // }
- //
- // if value.floor! == self.mainView.floorValue && self.mainView.classRoomValue == "所有"{
- // gateways.append(value)
- // }
- // }
- // self.mainView.gatewayList = gateways
- // }
- //
- //
- // HUD.hide()
- }) {
- HUD.hide()
- }
- }
-
- func requiest(_ hotelId:String?,devType:String,completion:(([DevData])->Void)?) {
- let queue = DispatchQueue(label: "com.custom.thread.requiest", qos: DispatchQoS.default, attributes: DispatchQueue.Attributes.concurrent)
- //队列
- let group = DispatchGroup()
- var deviceList:[DevData]? = nil
- var gatewayList :[GatewayData]? = nil
- queue.async(group: group, qos: .default, flags: []) {
- group.enter()
- if devType != "5"{//节省网络资源 需要同时请求的时候才处理
- //devType: 设备类型(0 全部,1 lights,2 circadian lights,3 sensor,4 air purifiers)
- IHRoomListService.share.getDeviceList(hotelId, buildId: Intermediate.buildId
- , floorId: nil, roomId: nil, devType:devType,keywords : nil , requestSuccess: { (list) in
- group.leave()
- deviceList = list
- // HUD.hide()
- }) {
- deviceList = nil
- group.leave()
- }
- }else{
- deviceList = nil
- group.leave()
- }
- }
- // 请求网关列表
- queue.async(group: group, qos: .default, flags: []) {
- group.enter()
- if devType == "0" || devType == "5"{
- if Intermediate.buildId != "" {
- IHGatewayService.share.getGatewayList(buildId: Intermediate.buildId,page: "\(self.schoolPage)", keywords: nil, requestSuccess: { (list) in
- gatewayList = list
- group.leave()
- }) {
- gatewayList = nil
- group.leave()
- }
- }else{
- gatewayList = nil
- group.leave()
- }
- }else{
- gatewayList = nil
- group.leave()
- }
- //回到主线程
- group.notify(queue: DispatchQueue.main) {
- HUD.hide()
- self.mainView.endReflesh()
- if let list = deviceList{
- self.mainView.devDataList = list
- self.devDataList = list
- if let block = completion {
- block(list)
- }
-
- }
- self.gatewayList = gatewayList
- if self.schoolPage == 1{
- self.mainView.gatewayList = self.gatewayList
- }else{
- self.mainView.gatewayList = self.mainView.gatewayList! + self.gatewayList!
- }
- let dict = ["devDataList":deviceList as Any,"gatewayList":gatewayList as Any] as [String : Any]
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHEquipmentSeachManagerReloadSeachListData), object: dict)
-
- }
- }
- }
- func setNavigationBar() {
- //导航栏的渲染方式
- let leftItem = UIBarButtonItem(image: UIImage(named: "定位")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(hotelSelected))
- self.vc?.navigationItem.leftBarButtonItem = leftItem
- let addItem = UIBarButtonItem(image: UIImage(named: "新增")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
- let refreshItem = UIBarButtonItem(image: UIImage(named: "刷新")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(refreshData))
- let serachItem = UIBarButtonItem(image: UIImage(named: "搜索")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(searchAction))
- self.vc?.navigationItem.rightBarButtonItems = [refreshItem,addItem,serachItem]
- }
-
-
- @objc func hotelSelected() {
-
- let picker = IHHotelPickerVCtr.shareInstance
- self.vc?.navigationController?.pushViewController(picker, animated: true)
- }
-
- @objc func mapAction1(){
- log.debug("点击了")
- let newEquipment = IHNewEquipmentVCtr()
- newEquipment.navigationBarTitle = "新增设备"
- //区分是否是学校
- newEquipment.isSchool = self.isSchool
- if let gatewayList = self.gatewayList{
- newEquipment.gatewayList = gatewayList
- }
- newEquipment.roomStyle = .equipmentList
- self.vc?.navigationController?.pushViewController(newEquipment, animated: true)
-
- }
-
- @objc func searchAction() {
- let searchVc = IHEquipmentSeachVCtr()
- searchVc.isSchool = self.isSchool
-
- // searchVc.devDataList = self.devDataList
- // searchVc.gatewayList = self.gatewayList
- // searchVc.lastVC = (self.vc as! IHEquipmentVCtr)
- // searchVc.currentIndex = currentIndex
- self.vc?.navigationController?.pushViewController(searchVc, animated: false)
- }
-
- @objc func refreshData() {
- HUD.show(.progress)
- if self.isSchool == "1"{
- //type:设备类型(0 教室灯,1 黑板灯,2 窗帘,3 面板,4 全部类型)
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: manager_currentFloorId,roomId: manager_currentRoomId,type:self.devType!)
- }else{
- self.requiest(self.hotelId, devType: devType ?? "0", completion: nil)
- }
- }
- }
- extension IHEquipmentlistManager:IHAddressControllerDelegate,IHEquipmentlistViewDelegate{
-
- //选择每个 标题
- func equipmentlistViewdidSelectedItemAt(_ index: Int, floorId: String?, roomId: String?) {
- HUD.show(.progress)
- self.devType = "\(index)"
- self.schoolPage = 1
- if self.isSchool == "1" {
- //学校
- // 设备类型(0 教室灯,1 黑板灯,2 窗帘,3 面板,4 全部类型)
- // ui: 全部,教室灯,黑板灯,面板,窗帘,网关
- //4: index=0, 0: index=1,1: index=2, 2: index=3
- let type = "\(index)"
- if type == "0"{
- //全部
- self.devType = "4"
- }
- if type == "1"{
- //教室灯
- self.devType = "0"
- }
- if type == "2"{
- //黑板灯
- self.devType = "1"
- }
- if type == "3"{
- //面板
- self.devType = "3"
- }
- if type == "4"{
- //窗帘
- self.devType = "2"
- }
- if type == "5"{
- //网关
- self.devType = "5"
- }
- self.manager_currentFloorId = floorId
- self.manager_currentRoomId = roomId
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: floorId,roomId: roomId,type:self.devType!)
- }else{
- //酒店
- self.requiest(self.hotelId, devType: devType!, completion: nil)
- }
-
- self.currentIndex = index
- }
-
-
- //下拉刷新
- func tableviewHeaderEsReloadData(floorId: String?, roomId: String?) {
- if self.isSchool == "1" {
- self.schoolPage = 1
- self.manager_currentFloorId = floorId
- self.manager_currentRoomId = roomId
- self.tableviewRefresh(floorId: floorId, roomId: roomId)
- }else{
- //warning
- self.mainView.endReflesh()
- }
- }
-
- //上拉刷新
- func tableviewBottonEsgetMoreData(floorId: String?, roomId: String?) {
- if isSchool == "1"{
- self.schoolPage += 1
- self.manager_currentFloorId = floorId
- self.manager_currentRoomId = roomId
- tableviewRefresh(floorId: floorId, roomId: roomId)
- }else{
- //warning
- self.mainView.endReflesh()
- }
-
- }
-
- //选择楼层的房间
- func selectFloorRoom(_ index: Int,floorId: String?, roomId: String?) {
- self.schoolPage = 1
- self.currentIndex = index
- self.manager_currentFloorId = floorId
- self.manager_currentRoomId = roomId
- //队列
- let group = DispatchGroup()
- var queue1 : DispatchQueue?
- if roomId == nil{
- //选择房间
- queue1 = DispatchQueue(label: "getRooms")
- queue1?.async {
- IHEquipmentService.share.getFloorRoom(floorId: floorId!){(floorRoomInfo) in
- let result = floorRoomInfo.result
- self.mainView.floorRoomList = result?.roomList
- }
- }
- }
-
- let queue2 = DispatchQueue(label: "getAllRoomsData")
- queue2.async{
- let type = "\(index)"
- if type == "0"{
- //全部
- self.devType = "4"
- }
- if type == "1"{
- //教室灯
- self.devType = "0"
- }
- if type == "2"{
- //黑板灯
- self.devType = "1"
- }
- if type == "3"{
- //面板
- self.devType = "3"
- }
- if type == "4"{
- //窗帘
- self.devType = "2"
- }
- if type == "5"{
- //网关
- self.devType = "5"
- }
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: floorId,roomId: roomId,type:self.devType!)
- }
- group.notify(queue: DispatchQueue.main) {
- g_showSuccess()
- }
- }
- //上下拉刷新
- private func tableviewRefresh(floorId : String?,roomId : String?){
- let type = "\(self.currentIndex!)"
- if type == "0"{
- //全部
- self.devType = "4"
- }
- if type == "1"{
- //教室灯
- self.devType = "0"
- }
- if type == "2"{
- //黑板灯
- self.devType = "1"
- }
- if type == "3"{
- //面板
- self.devType = "3"
- }
- if type == "4"{
- //窗帘
- self.devType = "2"
- }
- if type == "5"{
- //网关
- self.devType = "5"
- }
- self.mainView.isSchool = true
- self.manager_currentFloorId = floorId
- self.manager_currentRoomId = roomId
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: floorId,roomId: roomId, type: self.devType!)
-
- }
-
- func equipmentListSelected(_ gateway: GatewayData?) {
- //点击网关
- let gatewayVC = IHGatewayDetailVCtr()
- gatewayVC.gateway = gateway
- self.vc?.navigationController?.pushViewController(gatewayVC, animated: true)
- }
-
- func equipmentListSelected(_ devData: DevData?) {
- if let data = devData {
- if isSchool == "1"{
- //学校
- // 4 教室灯,5 黑板灯,6 窗帘,7 面板
- if data.type == "4" || data.type == "5"{
- //灯
- let roomLight = IHLampControlVCtr()
- roomLight.dataSource = data
- roomLight.isClassRoom = true
- var light = ShoolDeviceList()
- light.id = data.id
- light.type = data.type
- light.status = data.status
- light.light = data.brightness
- light.color = data.color
- light.model = data.mode!
- light.gatewayId = data.gatewayId
- roomLight.shoolDevice = light
-
- self.vc?.navigationController?.pushViewController(roomLight, animated: true)
- }
- if data.type == "6"{
-
- HUD.flash(.label("还没开放--窗帘"), delay: 0.5)
- }
- if data.type == "7"{
- HUD.flash(.label("还没开放--面板"), delay: 0.5)
-
- }
-
- }else{
- //酒店
- if data.devType == "3" {
- let sensor = IHSensorVCtr()
- sensor.devId = data.id
- sensor.dataSource = data
- sensor.navigationBarTitle = (data.name?.isBlanck == false && data.name != nil) ? data.name : "Sensor"
- self.vc?.navigationController?.pushViewController(sensor, animated: true)
- }else if data.devType == "4"{
- let air = IHAirVCtr()
- air.navigationBarTitle = (data.name?.isBlanck == false && data.name != nil) ? data.name : "Air purifier"
- air.purifierId = data.id
- air.dataSource = data
- self.vc?.navigationController?.pushViewController(air, animated: true)
- }else{
- let roomLight = IHLampControlVCtr()
- if data.devType == "1" {
- roomLight.lampName = (data.name?.isBlanck == false && data.name != nil) ? data.name : "Light"
- }else if data.devType == "2"{
- roomLight.lampName = (data.name?.isBlanck == false && data.name != nil) ? data.name : "Circadian light"
- }
- roomLight.dataSource = data
- self.vc?.navigationController?.pushViewController(roomLight, animated: true)
- }
-
- }
- }
-
- }
- //删除网关
- func gatewayDelegate(_ gateway: GatewayData, segmentIndex: Int) {
- IHGatewayService.share.delegateGateway(gateway.id!, requestSuccess: {
- //删除失败
- if self.isSchool == "1"{
- //学校
- self.getGateWayInfo(buildId: Intermediate.buildId, page: "1", keywords: nil)
- }else{
- //酒店
- self.requiest(self.hotelId, devType: "\(segmentIndex)", completion: nil)
- }
-
- }) {
-
- }
- }
-
- func gatewayUpdate(_ gateway: GatewayData,segmentIndex: Int) {
- let updateVc = IHGatewayUPdateVCtr()
- updateVc.gateway = gateway
- self.vc?.navigationController?.pushViewController(updateVc, animated: true)
- log.debug("网关升级")
- }
- func gatewaySetting(_ gateway: GatewayData, segmentIndex setmentIndex: Int) {
- log.debug("网关设置")
- let eqment = IHNewEquipmentVCtr()
- eqment.roomStyle = .gatewayEdit
- eqment.gateway = gateway
- eqment.navigationBarTitle = gateway.network_name
- self.vc?.navigationController?.pushViewController(eqment, animated: true)
- }
-
- func equipmentSetting(_ devData: DevData, segmentIndex: Int) {
- if isSchool != "1" {
- //原来的
- let eqment = IHNewEquipmentVCtr()
- eqment.roomStyle = .equipmentEdit
- eqment.devData = devData
- eqment.navigationBarTitle = devData.name
- self.vc?.navigationController?.pushViewController(eqment, animated: true)
- }else{
- //4 教室灯,5 黑板灯,6 窗帘,7 面板
- if devData.type == "4" || devData.type == "5" {
- let classLightVC = IHClassLightSettingCtr()
- classLightVC.roomStyle = .equipmentEdit
- classLightVC.devData = devData
- classLightVC.navigationBarTitle = devData.name
- self.vc?.navigationController?.pushViewController(classLightVC, animated: true)
-
- }else if devData.type == "6" {
- let classCurtainVC = IHCurtainSettingCtr()
- classCurtainVC.roomStyle = .equipmentEdit
- classCurtainVC.devData = devData
- classCurtainVC.navigationBarTitle = devData.name
- self.vc?.navigationController?.pushViewController(classCurtainVC, animated: true)
- }else {
-
- let classPanelVC = IHPanelSettingCtr()
- classPanelVC.roomStyle = .equipmentEdit
- classPanelVC.devData = devData
- classPanelVC.navigationBarTitle = devData.name
- self.vc?.navigationController?.pushViewController(classPanelVC, animated: true)
- }
- }
-
- }
-
- func equipmentHistory(_ devData: DevData, segmentIndex: Int) {
- if isSchool == "0" {
- if devData.devType == "1" || devData.devType == "2" {
- getLampHistory(devData)
- }else if devData.devType == "3"{
- getSensorHistory(devData)
- }else if devData.devType == "4"{
- getPurifierHistory(devData)
- }
- }else{
- HUD.flash(.label("还未开放"), delay: 0.8)
- }
-
- }
- //删除设备
- func equipmentListDeleteDevice(_ devType: String, devId: String,segmentIndex: Int) {
- log.debug("删除设备")
- if isSchool != "1" {
- // devType: 设备类型(0 全部,1 lights,2 circadian lights,3 sensor,4 air purifiers)
- //灯,senor,air
- IHEquipmentService.share.deleteEquimemnt(devType, devId: devId) { (isSuccess) in
- if isSuccess == true {
- //删除失败
- self.requiest(self.hotelId, devType: "\(segmentIndex)", completion: nil)
- }else{
-
- }
- }
-
- }else{
- //学校
- IHEquipmentService.share.delSchoolDevice(lightId: devId) { (msg, code) in
- if let code = code{
- if(code == "0000"){
- HUD.flash(.label("删除成功"), onView: nil, delay: 0.2) { (_) in
- //warning
- //self.equipmentlistViewdidSelectedItemAt(self.currentIndex!)
- self.equipmentDidSelectedItemAt(self.currentIndex!, floorId: self.manager_currentFloorId, roomId: self.manager_currentRoomId)
- }
- }else{
- HUD.flash(.label(msg!), delay: 0.2)
- }
- }
- }
- }
- }
-
-
- func equipmentDidSelectedItemAt(_ index: Int,floorId : String?,roomId:String?) {
- //选择标题
- HUD.show(.progress)
- self.devType = "\(index)"
- self.schoolPage = 1
- if self.isSchool == "1" {
- //学校
- // 设备类型(0 教室灯,1 黑板灯,2 窗帘,3 面板,4 全部类型)
- // ui: 全部,教室灯,黑板灯,面板,窗帘,网关
- //4: index=0, 0: index=1,1: index=2, 2: index=3
- let type = "\(index)"
- if type == "0"{
- //全部
- self.devType = "4"
- }
- if type == "1"{
- //教室灯
- self.devType = "0"
- }
- if type == "2"{
- //黑板灯
- self.devType = "1"
- }
- if type == "3"{
- //面板
- self.devType = "3"
- }
- if type == "4"{
- //窗帘
- self.devType = "2"
- }
- if type == "5"{
- //网关
- self.devType = "5"
- }
- //warning
- self.getSchoolDevList(hotelId: Intermediate.hotelId, builId: Intermediate.buildId,floorId: floorId,roomId: roomId,type:self.devType!)
- }else{
- //酒店
- self.requiest(self.hotelId, devType: devType!, completion: nil)
- }
-
- self.currentIndex = index
- }
-
- func selectedAddress(address: String, addressID: String) {
- HUD.show(.progress)
- Intermediate.hotelId = addressID
- Intermediate.hotelName = address
- self.vc?.navigationBarTitle = address
- self.hotelId = addressID
- self.requiest(self.hotelId, devType: devType!, completion: nil)
- }
- }
- extension IHEquipmentlistManager{
- //获取所有的楼层
- private func getAllFloors(){
- //getAreaFloorNav
- DispatchQueue.main.async {
- HUD.flash(.progress, onView: nil, delay: 8) { (_) in
- HUD.flash(.label("请求超时"), delay: 0.8)
- }
- }
-
- IHEquipmentService.share.getAreaFloorNav(buildId: Intermediate.buildId) { (areaFloorInfo) in
- let result = areaFloorInfo.result
-
- self.mainView.areaFloorList = result?.floorList
- }
- }
-
- func getLampHistory(_ devData: DevData) {
- let devId = devData.id
- HUD.show(.progress)
- HUD.hide(afterDelay: 20) { (isSuccess) in
- if isSuccess == true{
- g_showHUD("请求超时")
- }
- }
- var energy_consumption : ReportData?
- var lighting_use_schedule :ReportData?
- let queue = DispatchQueue(label: "com.custom.thread", qos: DispatchQoS.default, attributes: DispatchQueue.Attributes.concurrent)
- let group = DispatchGroup()
-
- queue.async(group: group, qos: .default, flags: []) {
- group.enter()
- IHRoomLightService.share.getLampReport(devId!, dateType: "0", dataType: "0", date: nil, requestSuccess: { (data) in
- group.leave()
- energy_consumption = data
- }) {
- group.leave()
- energy_consumption = nil
- }
- }
-
- queue.async(group: group, qos: .default, flags: []) {
- group.enter()
- IHRoomLightService.share.getLampReport(devId!, dateType: "0", dataType: "1", date: nil, requestSuccess: { (data) in
- group.leave()
- lighting_use_schedule = data
- }) {
- group.leave()
- lighting_use_schedule = nil
- }
- }
- //回到主线程
- group.notify(queue: DispatchQueue.main) {
- HUD.hide()
-
- if energy_consumption != nil || lighting_use_schedule != nil{
- let history = IHRoomLightHistoryVCtr()
- history.devId = devData.id
- history.devType = devData.devType
- let lampHistory = (energy_consumption:energy_consumption,lighting_use_schedule:lighting_use_schedule) as! (energy_consumption: ReportData, lighting_use_schedule: ReportData)
- history.lampHistory = lampHistory
- self.vc?.navigationController?.pushViewController(history, animated: true)
-
- }else{
- g_showHUD("无数据")
- }
-
- }
- }
-
- func getSensorHistory( _ devData: DevData){
- log.debug("点击了")
-
- HUD.show(.progress)
- HUD.hide(afterDelay: 20) { (isSuccess) in
- if isSuccess == true{
- g_showHUD("请求超时")
- }
- }
- let historyvc = IHRoomLightHistoryVCtr()
-
- historyvc.devId = devData.id
- historyvc.devType = "3"
- IHSensorService.share.getSensorHistory(devData.id!, date_type: "0", requestSuccess: { (history) in
- HUD.hide()
- historyvc.sensorHistory = history
- self.vc?.navigationController?.pushViewController(historyvc, animated: true)
- }) {
- g_showHUD("感应器无历史数据")
- }
- }
-
-
- func getPurifierHistory(_ devData:DevData) {
- HUD.show(.progress)
- HUD.hide(afterDelay: 20) { (isSuccess) in
- if isSuccess == true{
- g_showHUD("请求超时")
- }
- }
- let historyvc = IHRoomLightHistoryVCtr()
-
- historyvc.devId = devData.id
- historyvc.devType = "4"
- IHAirService.share.getPurifierReport(devData.id!, dateType: "0", date: nil, requestSuccess: { (history) in
- HUD.hide()
- historyvc.purifierHistroy = history
- self.vc?.navigationController?.pushViewController(historyvc, animated: true)
- }) {
- g_showHUD("空气净化器无历史数据")
- }
- }
- }
|