123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- //
- // IHEquipmentSeachManager.swift
- // Inhealth
- //
- // Created by weclouds on 2020/1/13.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- let kNotifactionIHEquipmentSeachManagerAfterDeleteEquipment = "kNotifactionIHEquipmentSeachManagerAfterDeleteEquipment"
- let kNotifactionIHEquipmentSeachManagerReloadSeachListData = "kNotifactionIHEquipmentSeachManagerReloadSeachListData"
- class IHEquipmentSeachManager:
- NSObject,IHViewManagerProtocolDelegate {
- var currentIndex :Int? = 0
- var hotelId : String?
- var devType: String? = "0"
- private var page = 1
- lazy var mainView: IHEquipmentSearchView = {[unowned self] in
- let mainView = IHEquipmentSearchView(frame: self.vc!.view.bounds)
- mainView.delegate = self
- return mainView
- }()
- // private var vc = UIViewController()
- private weak var vc : UIViewController?
-
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- createUI()
- NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(kNotifactionIHEquipmentSeachManagerReloadSeachListData), object: nil)
-
- }
- @objc func reloadData(_ notif:Notification){
- let dict = notif.object as! [String:Any]
- let devicelist = dict["devDataList"] as? [DevData]
- let gatewaylist = dict["gatewayList"] as? [GatewayData]
- if let list = devicelist {
- mainView.devDataList = list
- }
- if let list1 = gatewaylist {
- mainView.gatewayList = list1
- }
-
- }
- func createUI() {
- mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT )
- mainView.target = self.vc as? IHEquipmentSeachVCtr
- self.vc?.view.addSubview(mainView)
- self.vc?.navigationBarTitle = "查找设备"
- let searchVC = self.vc as! IHEquipmentSeachVCtr
- mainView.devDataList = searchVC.devDataList
- mainView.gatewayList = searchVC.gatewayList
- mainView.currentIndex = searchVC.currentIndex
-
- }
- }
- extension IHEquipmentSeachManager{
- //查找学校的设备(包括网关)
- private func searchSchoolDevice(keywords : String?){
- var i = 0
- HUD.flash(.progress, onView: nil, delay: 8) { (_) in
- HUD.flash(.label("请求超时"), delay: 0.8)
- }
- IHEquipmentService.share.getSchoolDevList(hotelId: Intermediate.hotelId, buildId: Intermediate.buildId, floorId:nil,roomId: nil, page:self.page , type: "4", keywords: keywords, requestSuccess: { (devList) in
- log.debug("---获取整个学校---\(devList)")
- if self.page == 1{
- self.mainView.searchSchoolAndHotelList = devList
- }else{
- self.mainView.searchSchoolAndHotelList = self.mainView.searchSchoolAndHotelList! + devList
- }
-
- i += 1
- if i == 2{
- HUD.hide()
- self.mainView.endReflesh()
- self.mainView.reloadAll = true
- }
-
- }) {
- HUD.hide()
- }
-
- IHGatewayService.share.getGatewayList(buildId: Intermediate.buildId,page: "\(self.page)", keywords: keywords, requestSuccess: { (gatewayList) in
- log.debug("---获取所有的网关---\(gatewayList)")
- if self.page == 1{
- self.mainView.searchGatewayList = gatewayList
- }else{
- self.mainView.searchGatewayList = self.mainView.searchGatewayList! + gatewayList
- }
-
- i += 1
- if i == 2{
- HUD.hide()
- self.mainView.endReflesh()
- self.mainView.reloadAll = true
- }
-
- }) {
- HUD.hide()
- }
- }
- //查找酒店的设备(包括网关)
- private func searchHotelDevice(keywords : String?){
- HUD.flash(.progress, onView: nil, delay: 8) { (_) in
- HUD.flash(.label("请求超时"), delay: 0.8)
- }
- var i = 0
- IHRoomListService.share.getDeviceList(Intermediate.hotelId, buildId: Intermediate.buildId, floorId: nil, roomId: nil, devType: "0", keywords: keywords, requestSuccess: { (deviceList) in
- log.debug("---获取酒店所有的设备---\(deviceList)")
- if self.page == 1{
- self.mainView.searchSchoolAndHotelList = deviceList
- }else{
- self.mainView.searchSchoolAndHotelList = self.mainView.searchSchoolAndHotelList! + deviceList
- }
-
- i += 1
- if i == 2{
- HUD.hide()
- self.mainView.endReflesh()
- self.mainView.reloadAll = true
- }
-
- }) {
- HUD.hide()
- }
- IHGatewayService.share.getGatewayList(buildId: Intermediate.buildId, page: "\(self.page)", keywords: keywords, requestSuccess: { (gatewayList) in
- log.debug("---获取所有的网关---\(gatewayList)")
- if self.page == 1{
- self.mainView.searchGatewayList = gatewayList
- }else{
- self.mainView.searchGatewayList = self.mainView.searchGatewayList! + gatewayList
- }
-
- i += 1
- if i == 2{
- HUD.hide()
- self.mainView.endReflesh()
- self.mainView.reloadAll = true
- }
-
- }) {
- HUD.hide()
- }
- }
- }
- //extension IHEquipmentSeachManager : IHEquipmentSearchViewDelegate{
- // func searchDevice(_ keyWords: String?) {
- // let searchVC = self.vc as? IHEquipmentSeachVCtr
- // if searchVC?.isSchool == "1"{
- // //学校
- // self.searchSchoolDevice(keywords: keyWords)
- // }else{
- // //酒店
- // self.searchHotelDevice(keywords: keyWords)
- // }
- // }
- //}
- //IHEquipmentSearchViewDelegate IHEquipmentlistViewDelegate
- extension IHEquipmentSeachManager: IHEquipmentSearchViewDelegate{
-
- //查找设备(包括网关)
- func searchDevice(_ keyWords: String?) {
- let searchVC = self.vc as? IHEquipmentSeachVCtr
- if searchVC?.isSchool == "1"{
- //学校
- self.searchSchoolDevice(keywords: keyWords)
- }else{
- //酒店
- self.searchHotelDevice(keywords: keyWords)
- }
- }
-
-
- //下拉刷新
- func tableviewHeaderEsReloadData(keywords: String?) {
- self.page = 1
- searchDevice(keywords)
- }
- //上拉刷新
- func tableviewBottonEsgetMoreData(keywords: String?) {
- self.page += 1
- searchDevice(keywords)
- }
- // //选择楼层
- // func selectFloorRoom(_ index : Int,floorId: String?, roomId: String?) {
- //
- // }
- // //选择房间
- // func selectFloorRoom(floorId: String) {
- //
- // }
-
- // func tableviewHeaderEsReloadData() {
- // mainView.endReflesh()
- // }
- //
- // func tableviewBottonEsgetMoreData(_index: Int) {
- // log.debug("查找:\(_index)")
- // mainView.endReflesh()
- // }
-
- func gatewayDelegate(_ gateway: GatewayData, segmentIndex: Int) {
- //删除网关
- IHGatewayService.share.delegateGateway(gateway.id!, requestSuccess: {
- // if isSuccess == true {
- //删除成功 刷新数据
- let dict = ["devId":gateway.id,"segmentIndex":"\(segmentIndex)"]
-
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHEquipmentSeachManagerAfterDeleteEquipment), object: dict)
- //self.requiest(self.hotelId, devType: "\(segmentIndex)")
- self.vc?.navigationController?.popViewController(animated: false)
- //}
- }) {
-
- }
- }
-
- func equipmentListSelected(_ gateway: GatewayData?) {
- //点击网关
- let gatewayVC = IHGatewayDetailVCtr()
- gatewayVC.gateway = gateway
- self.vc?.navigationController?.pushViewController(gatewayVC, animated: true)
- }
- func equipmentListSelected(_ devData: DevData?){
- //点击设备
- let searchVC = self.vc as? IHEquipmentSeachVCtr
- if let data = devData {
- if searchVC?.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 : "HCL light"
- }
- roomLight.dataSource = data
- self.vc?.navigationController?.pushViewController(roomLight, animated: true)
- }
-
- }
- }
- }
- // func equipmentListSelected(_ devData: DevData?) {
- // //返回页面页面之后再跳转
- // self.vc?.navigationController?.popViewController(animated: false, {
- // if let data = devData {
- // self.gotoDetail(data)
- // }
- // })
- //
- // }
-
- func gotoDetail(_ data:DevData) {
- let searchVC = self.vc as! IHEquipmentSeachVCtr
- let lastVC = searchVC.lastVC
- // self.mainView.searchController?.isActive = false
- 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"
- lastVC?.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
- lastVC?.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
- lastVC?.navigationController?.pushViewController(roomLight, animated: true)
- }
- }
-
- func gatewayUpdate(_ gateway: GatewayData,segmentIndex: Int) {
- //网关升级
- let updateVc = IHGatewayUPdateVCtr()
- updateVc.gateway = gateway
- self.vc?.navigationController?.pushViewController(updateVc, animated: true)
- }
-
- func gatewaySetting(_ gateway: GatewayData, segmentIndex: 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) {
- let searchVC = self.vc as? IHEquipmentSeachVCtr
- if searchVC?.isSchool == "0" {
- //原来的网关
- 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) {
- //左滑 - 设备(历史)
- let searchVC = self.vc as? IHEquipmentSeachVCtr
- if searchVC?.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) {
- //删除-设备
- let searchVC = self.vc as? IHEquipmentSeachVCtr
- if searchVC?.isSchool == "0"{
- //灯,senor,air
- IHEquipmentService.share.deleteEquimemnt(devType, devId: devId) { (isSuccess) in
- if isSuccess == true {
- //删除成功 刷新数据
- let dict = ["devId":devId,"segmentIndex":"\(segmentIndex)"]
-
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHEquipmentSeachManagerAfterDeleteEquipment), object: dict)
- //self.requiest(self.hotelId, devType: "\(segmentIndex)")
- self.vc?.navigationController?.popViewController(animated: false)
- }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
- let dict = ["devId":devId,"segmentIndex":"\(segmentIndex)"]
-
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHEquipmentSeachManagerAfterDeleteEquipment), object: dict)
- //self.requiest(self.hotelId, devType: "\(segmentIndex)")
- self.vc?.navigationController?.popViewController(animated: false)
- }
- }else{
- HUD.flash(.label(msg!), delay: 0.2)
- }
- }
- }
- }
-
- }
-
-
- func equipmentlistViewdidSelectedItemAt(_ index: Int) {
- currentIndex = index
- }
-
- 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("空气净化器无历史数据")
- }
- }
- }
|