Browse Source

1.ICP被打断之后重新拉回原来业务中;2PAD被重新放回队列中排在队首

dujunchen 2 weeks ago
parent
commit
5fb01dc065

+ 42 - 2
internal/app/ami/action/call.go

@@ -1,6 +1,7 @@
 package action
 
 import (
+	"errors"
 	"fmt"
 	"pbx-api-gin/internal/app/stc/active"
 	"pbx-api-gin/internal/app/stc/priority"
@@ -150,7 +151,7 @@ func HangupRunningTask(toRunTask string) {
 				if utils.IsPAIU(ret.CallerIDNum) {
 					if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
 						//lfshook.NewLogger().Infof("===Redirect=Chan===%+v==== ", ret.Channel)
-						err := Redirect(ret.Channel, "0300", "default", "", "PAD")
+						err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
 						if err != nil {
 							lfshook.NewLogger().Errorf("Redirect %+v", err)
 						}
@@ -184,7 +185,7 @@ func HangupRunningTask(toRunTask string) {
 					lfshook.NewLogger().Infof("===QueueStatus==%+v", err)
 				}
 				for _, caller := range resCaller.Entrys {
-					go RedirectInQueue(caller.CallerIDNum, "0300", "default", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
+					go RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
 					time.Sleep(time.Microsecond * 200)
 				}
 
@@ -272,6 +273,27 @@ func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
 	lfshook.NewLogger().Info(res)
 }
 
+// Dial 拨打号码
+func DialICP(src, dst, dialrule, callerID, callerName string) {
+	chanel := fmt.Sprintf("%s/%s@call-icp", "Local", src)
+	action := map[string]string{
+		"Action":   "Originate",
+		"Channel":  chanel,
+		"Exten":    dst,
+		"Context":  dialrule,
+		"CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
+		"Priority": "1",
+		"Variable": fmt.Sprintf("CBID=%s", callerID),
+		"async":    "true",
+	}
+	lfshook.NewLogger().Infof("dial action %+v", action)
+	res, _, err := AminInstance.Send(action)
+	if err != nil {
+		lfshook.NewLogger().Errorf("%+v", err)
+	}
+	lfshook.NewLogger().Info(res)
+}
+
 // 获取分机状态
 func ExtenStatus(exten string) (Status string) {
 	action := map[string]string{
@@ -425,3 +447,21 @@ func SetPadTimer() {
 		}
 	}
 }
+
+func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
+	action := map[string]string{
+		"Action":     "ConfbridgeKick",
+		"Conference": confnum,
+		"Channel":    channel,
+	}
+
+	res, _, err = AminInstance.Send(action)
+	if err != nil {
+		return nil, err
+	}
+	if res["Response"] != "Success" {
+		return nil, errors.New(res["Message"])
+	}
+
+	return res, nil
+}

+ 107 - 20
internal/app/ami/action/index.go

@@ -48,7 +48,7 @@ func HandleAMI(event map[string]string) {
 						//hangup pad call ICP channel
 						if utils.IsPAIU(ret.CallerIDNum) {
 							if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
-								err := Redirect(ret.Channel, "0300", "default", "", "PAD")
+								err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
 								if err != nil {
 									lfshook.NewLogger().Errorf("Redirect %+v", err)
 								}
@@ -81,7 +81,7 @@ func HandleAMI(event map[string]string) {
 					for _, caller := range resCaller.Entrys {
 						lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
 						time.Sleep(time.Microsecond * 100)
-						RedirectInQueue(caller.CallerIDNum, "0300", "default", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
+						RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
 					}
 
 					/*	for _, ret := range chans {
@@ -106,7 +106,7 @@ func HandleAMI(event map[string]string) {
 
 						if utils.IsPAIU(ret.CallerIDNum) {
 							if ret.ConnectedLineNum == "<unknown>" && ret.ChannelStateDesc == "Up" { //redirect pad chanspy channel
-								err := Redirect(ret.Channel, "0300", "default", "", "PAD")
+								err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
 								if err != nil {
 									lfshook.NewLogger().Errorf("Redirect %+v", err)
 								}
@@ -175,22 +175,17 @@ func HandleAMI(event map[string]string) {
 
 			if priority.CheckPriority("CabCab") { // interrupt OCC-PAD
 				//C2C start PAD interrupt
-				if priority.RunningType == "PAD-OCC" {
-
+				if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" || priority.RunningType == "PA" {
+					HangupRunningTask("C2C")
 					//Hangup the other ICP
+
+				} else {
 					lfshook.NewLogger().Infof("========CabCab  hangup other one====caller %s", event["CallerIDNum"])
-					//HangupICP()
 					if event["CallerIDNum"] == "2311" {
 						Hangup("2381")
 					} else {
 						Hangup("2311")
 					}
-
-				} else {
-
-					lfshook.NewLogger().Infof("=======HangupRunningTask====%s", event["CallerIDNum"])
-					HangupRunningTask("C2C") //C2C interrupt other
-
 				}
 			} else { // hangup caller; C2C start failed
 				lfshook.NewLogger().Infof("========CabCab  hangup caller====%s", event["CallerIDNum"])
@@ -391,6 +386,10 @@ func HandleAMI(event map[string]string) {
 						priority.PADStart = 0
 
 						priority.CleanPriorityTag()
+
+						if active.CONBID != "" {
+							ConfbridgeKick(active.CONBID, "all")
+						}
 					}
 					/*if priority.ResumeEmgPara.FileName != "" {
 						CheckEmgResume()
@@ -513,6 +512,7 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "EMG"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.EMG)
+				active.CONBID = event["Conference"]
 				alstatus.PaStatus("", "EMG", "start")
 				return
 			}
@@ -522,6 +522,7 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "SPC"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.SPC)
+				active.CONBID = event["Conference"]
 				alstatus.PaStatus("", "SPC", "start")
 				return
 			}
@@ -531,6 +532,7 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "DCS"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.DCS)
+				active.CONBID = event["Conference"]
 				alstatus.PaStatus("", "DCS", "start")
 				return
 			}
@@ -540,6 +542,7 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "STN"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.STN)
+				active.CONBID = event["Conference"]
 				alstatus.PaStatus("", "STN", "start")
 				return
 			}
@@ -549,6 +552,7 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "CHK"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CHK)
+				active.CONBID = event["Conference"]
 				alstatus.PaStatus("", "CHK", "start")
 				return
 			}
@@ -558,11 +562,19 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "VOL"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.VOL)
+				active.CONBID = event["Conference"]
 				alstatus.PaStatus("", "VOL", "start")
 				return
 			}
 		}
 
+		//get confbridge id for join back to confbridge
+		if event["Context"] == "pad-page-occ-icp" && utils.IsPAIU(event["CallerIDNum"]) {
+			active.CONBID = event["Conference"]
+		} else if event["Context"] == "cpa-rule" && utils.IsIO(event["CallerIDNum"]) {
+			active.CONBID = event["Conference"]
+		}
+
 		//Send PA start msg to STC
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
 			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
@@ -631,7 +643,9 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		} else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
 			SetPadTimer()
@@ -640,14 +654,18 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 			//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		} else if event["CallerIDName"] == "EMG" && event["Exten"] == "0502" { // EMG broadcast hangup
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "EMG", "end")
 			priority.ResumeEmgPara = priority.BroadcastResumeParas{}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
@@ -655,7 +673,9 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
@@ -663,7 +683,9 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
@@ -671,7 +693,9 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
@@ -679,7 +703,9 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
-
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		} else if event["CallerIDName"] == "VOL" && event["Exten"] == "0513" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
@@ -687,6 +713,9 @@ func HandleAMI(event map[string]string) {
 			if priority.ResumeEmgPara.FileName != "" {
 				CheckEmgResume()
 			}
+			if active.CONBID != "" {
+				ConfbridgeKick(active.CONBID, "all")
+			}
 		}
 
 	case "DialEnd":
@@ -701,6 +730,36 @@ func HandleAMI(event map[string]string) {
 			priority.RunningType = "C2C"
 
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
+		} else if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "NOANSWER" {
+
+			lfshook.NewLogger().Infof("===%s======%s", event["Event"], priority.RunningType)
+			//ICPs go back to confbridge
+			switch priority.RunningType {
+			case "PAD-OCC":
+				go DialICP("8", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("8", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "CPA":
+				go DialICP("2", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("2", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "EMG":
+				go DialICP("3", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("3", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "SPC":
+				go DialICP("6", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("6", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "STN":
+				go DialICP("4", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("4", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "DCS":
+				go DialICP("5", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("5", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "CHK":
+				go DialICP("10", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("10", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "VOL":
+				go DialICP("11", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("11", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			}
 		}
 
 	case "BridgeLeave":
@@ -711,8 +770,36 @@ func HandleAMI(event map[string]string) {
 
 			priority.RunningTypePriority = priority.TmpRunningTypePriority
 			priority.TmpRunningTypePriority = 0
-
 			priority.RunningType = priority.TmpRunningType
+
+			//ICPs go back to confbridge
+			switch priority.TmpRunningType {
+			case "PAD-OCC":
+				go DialICP("8", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("8", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "CPA":
+				go DialICP("2", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("2", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "EMG":
+				go DialICP("3", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("3", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "SPC":
+				go DialICP("6", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("6", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "STN":
+				go DialICP("4", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("4", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "DCS":
+				go DialICP("5", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("5", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "CHK":
+				go DialICP("10", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("10", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			case "VOL":
+				go DialICP("11", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
+				go DialICP("11", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			}
+
 			priority.TmpRunningType = ""
 
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")

+ 2 - 1
internal/app/stc/active/index.go

@@ -15,7 +15,8 @@ var Master = false
 
 var QueueTimer *time.Timer = nil
 
-//var ActivedMC int
+//ICP join PAD-OCC confbridge id
+var CONBID = ""
 
 // 挂断所有报警器
 func NotifyPaiu(Exten, Action string) {

+ 2 - 2
internal/app/stc/broadcast/stc-broadcast.go

@@ -476,7 +476,7 @@ func AlarmHandleICP(data []byte) {
 
 	case 0x02: //hold  重新放回队列里面
 		active.NotifyPaiu(exten, "hold")
-		err := action.RedirectInQueue(exten, "0300", "default", "1")
+		err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
 		if err != nil {
 			lfshook.NewLogger().Info(err)
 		}
@@ -542,7 +542,7 @@ func AlarmHandleTMS(data []byte) {
 
 	case 0x02: //hold  重新放回队列里面
 		active.NotifyPaiu(exten, "hold")
-		err := action.RedirectInQueue(exten, "0300", "default", "1")
+		err := action.RedirectInQueue(exten, "0300", "queues-icp-redirect", "1")
 		if err != nil {
 			lfshook.NewLogger().Info(err)
 		}