浏览代码

update PAD-OCC

dujunchen 1 周之前
父节点
当前提交
4baa0c639d
共有 2 个文件被更改,包括 91 次插入61 次删除
  1. 15 60
      internal/app/ami/action/index.go
  2. 76 1
      internal/app/stc/broadcast/stc-broadcast.go

+ 15 - 60
internal/app/ami/action/index.go

@@ -23,19 +23,24 @@ func HandleAMI(event map[string]string) {
 	//lfshook.NewLogger().Infof("===start======%s", event["Event"]
 
 	switch event["Event"] {
-	case "DTMFBegin":
+
+	case "DTMFBegin": //ICP interrupt PAD
 		if utils.IsICP(event["CallerIDNum"]) {
-			exten := strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0]
+			exten := strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0] //get ICP exten number
 			if utils.IsICP(exten) {
 				chans, err := CoreShowChannels()
 				if err != nil {
 					lfshook.NewLogger().Errorf("CoreShowChannels %+v", err)
 				}
-				lfshook.NewLogger().Infof("===HangupRunningTask=PAD1=======%+v==== ", chans)
+
 				//1. Redirect the connected PAD to 0300
 				for _, ret := range chans {
-
-					if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsPAIU(exten) {
+					//lfshook.NewLogger().Infof("===HangupRunningTask=PAD1====Chans-ret===%+v==== ", ret)
+					if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) { //hangup pad call ICP channel
+						//lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
+						Hangup(ret.Channel)
+					} else if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
+						//lfshook.NewLogger().Infof("===Redirect=Chan===%+v==== ", ret.Channel)
 						err := Redirect(ret.Channel, "0300", "default", exten, "PAD")
 						if err != nil {
 							lfshook.NewLogger().Errorf("Redirect %+v", err)
@@ -228,7 +233,6 @@ func HandleAMI(event map[string]string) {
 
 				active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
 
-					//lfshook.NewLogger().Infof("==Afterfunc to=OCC-QueueStatus=")
 					res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
 					if err != nil {
 						lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
@@ -278,33 +282,9 @@ func HandleAMI(event map[string]string) {
 						}
 					}
 
-					/*res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
-					if err != nil {
-						lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
-						return
-					}
-
-					lfshook.NewLogger().Infof("===OCC-QueueStatus= res=%+v", res)
-
-					PADChan := ""
-					for _, chanEntry := range res.Entrys {
-						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
-						if chanEntry.Position == "1" {
-							PADChan = chanEntry.Channel
-							break
-						}
-					}
-					*/
-					//if PADChan != "" {
-					//alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
 					alstatus.AlarmStatus(event["CallerIDNum"], "connect")
 					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
-					//go RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
-
-					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
-					//	} else {
-					//	lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
-					//}
+					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1")    // PACUs dial OCC1
 
 				} else if active.ActivedCab == "8" /*&& ExtenStatus("1481") == "Idle" */ {
 					if priority.PADOccStart == 0 {
@@ -315,29 +295,10 @@ func HandleAMI(event map[string]string) {
 							priority.PADStart = 1
 						}
 					}
-					/*		res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
-							if err != nil {
-								lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
-								return
-							}
-							PADChan := ""
-							for _, chanEntry := range res.Entrys {
-								lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
-								if chanEntry.Position == "1" {
-									PADChan = chanEntry.Channel
-									break
-								}
-							}
-					*/
-					//if PADChan != "" {
-					//alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-					//go RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs);goto confbrdigeIoin
+
 					alstatus.AlarmStatus(event["CallerIDNum"], "connect")
 					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
-					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8")    // PACUs dial OCC1
-					//} else {
-					//	lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
-					//}
+					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8")    // PACUs dial OCC8
 				}
 			} else {
 				lfshook.NewLogger().Infof("====PAD-OCC Priority false===")
@@ -460,12 +421,6 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADOCC)
 			break
 		}
-	case "ChanSpyStart":
-		lfshook.NewLogger().Infof("=========event:%s   callerid:%s   SpyeeConnectedLineName:%s  SpyerExten:%s", event["Event"], event["CallerIDNum"], event["SpyeeConnectedLineName"], event["SpyerExten"])
-		//PAD answered by OCC; ICPs chanspy PAD
-		//if utils.IsPAIU(event["SpyeeConnectedLineName"]) && utils.IsIO(event["SpyerExten"]) { // check if it is PAD whisper IO/OCC
-		//go Dial("0404", event["SpyeeConnectedLineName"], "chanspy-rule", "ano", "ano", "") //ICPs chanspy PAD
-		//}
 
 	case "ConfbridgeLeave":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
@@ -567,10 +522,10 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADTMS)
 			if active.ActivedCab == "1" {
 				go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
-				go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8")   //ICP8---call----PAD
+				go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8")  //ICP8---call----PAD
 			} else if active.ActivedCab == "8" {
 				go RedirectInQueue(event["CallerIDName"], "2381", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP8
-				go Dial("0403", event["CallerIDName"], "call-pad-rule", "2311", "2311", "1")   //ICP1---call----PAD
+				go Dial("0403", event["CallerIDName"], "call-pad-rule", "2311", "2311", "1")  //ICP1---call----PAD
 			}
 		} else if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0405" { // PAD connect ICP-TMS;PACU not available
 

+ 76 - 1
internal/app/stc/broadcast/stc-broadcast.go

@@ -15,7 +15,9 @@ import (
 	"pbx-api-gin/internal/app/stc/priority"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
+	"sort"
 	"strconv"
+	"strings"
 	"sync"
 	"time"
 
@@ -84,7 +86,80 @@ func processPacket(packet []byte) {
 	switch packet[5] {
 	case 0x01: //heartbeat
 
-		break
+		//PAD-OCC异常情况处理
+		if priority.OCCAnswer == 1 {
+			//定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
+			resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
+			if err != nil {
+				lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+				return
+			}
+			if resCaller.Calls != "0" {
+				sort.Slice(resCaller.Entrys, func(i, j int) bool {
+					return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
+				})
+
+				for _, caller := range resCaller.Entrys {
+					priority.ICPAnswer = 0
+					lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
+					//order by pos
+					action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
+					time.Sleep(time.Microsecond * 200)                                                   //200 ms delay
+				}
+			}
+
+			//定时监测OCC  queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
+			res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
+			if err != nil {
+				lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
+				return
+			}
+			if res.Calls != "0" { //OCC queue is not empty
+				//	HangupAllLocalChan()
+				lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
+				if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
+					time.Sleep(time.Second)
+					PADChan := ""
+					for _, chanEntry := range res.Entrys {
+						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
+						if chanEntry.Position == "1" {
+							PADChan = chanEntry.Channel
+							break
+						}
+					}
+
+					if PADChan != "" {
+						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
+						go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
+
+						go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
+					} else {
+						lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+					}
+					break
+				} else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
+					time.Sleep(time.Second)
+					PADChan := ""
+					for _, chanEntry := range res.Entrys {
+						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
+						if chanEntry.Position == "1" {
+							PADChan = chanEntry.Channel
+							break
+						}
+					}
+
+					if PADChan != "" {
+						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
+						go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
+
+						go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
+					} else {
+						lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+					}
+					break
+				}
+			}
+		}
 
 	case 0x02: // STN
 		if priority.CheckPriority("STN") {