Browse Source

包含多个优先级的PAD超时计时器启动调整

dujunchen 3 weeks ago
parent
commit
c729a19b80

+ 93 - 22
internal/app/ami/action/call.go

@@ -6,6 +6,8 @@ import (
 	"pbx-api-gin/internal/app/stc/priority"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
+	"sort"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -109,29 +111,57 @@ func HangupRunningTask(toRunTask string) {
 		}
 	}
 
+	if toRunTask == "AlarmHoldResetAll" {
+		Hangup(priority.RunningPATaskChan)
+		priority.CleanPriorityTag()
+		HangupAllLocalChan()
+		return
+	}
+
 	if priority.RunningPATaskChan != "" {
 
+		if priority.C2CRuning == 1 { // Interrupt C2C task running,
+			if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
+				HangupICP()
+				//priority.CleanPriorityTag()
+			}
+		}
+
 		switch priority.RunningType {
 
 		case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
-			//lfshook.NewLogger().Infof("===HangupRunningTask=PAD=======%s==== ", priority.RunningType)
-			/*		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 {
-						exten := strings.Split(strings.Split(ret.Channel, "/")[1], "-")[0]
-						if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsPAIU(exten) {
-							//err := RedirectInQueue(ret.Channel, "0300", "default", "PAD")
-							err := Redirect(ret.Channel, "0300", "default", exten, "PAD")
-							if err != nil {
-								lfshook.NewLogger().Errorf("Redirect %+v", err)
-							}
+			//just in case
+			if toRunTask == "C2C" {
+				return
+			}
+
+			lfshook.NewLogger().Infof("===HangupRunningTask==hangup===PAD-ICP==%s==== ", priority.RunningType)
+			chans, err := CoreShowChannels()
+			if err != nil {
+				lfshook.NewLogger().Errorf("CoreShowChannels %+v", err)
+			}
+
+			//1. Redirect the connected PAD to 0300,hangup the other pad channel
+			for _, ret := range chans {
+
+				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")
+						if err != nil {
+							lfshook.NewLogger().Errorf("Redirect %+v", err)
 						}
+
+						number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
+						active.NotifyPaiu(number, "hold")
+						HangupAllLocalChan()
+					} else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
+						lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
+						Hangup(ret.Channel)
 					}
-			*/
+				}
+			}
+
 			//2. hangup task channel (ICP + PACU)
 			lfshook.NewLogger().Infof("===HangupRunningTask=2. hangup task channel === ")
 			HangupAllLocalChan()
@@ -165,12 +195,6 @@ func HangupRunningTask(toRunTask string) {
 				priority.CleanPriorityTag()
 			}
 
-		case "C2C": // Interrupt C2C task running,
-			if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
-				HangupICP()
-				priority.CleanPriorityTag()
-			}
-
 		default:
 			lfshook.NewLogger().Infof("===HangupRunningTask=default=== ")
 			Hangup(priority.RunningPATaskChan)
@@ -351,3 +375,50 @@ func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
 	lfshook.NewLogger().Info(res)
 	return err
 }
+
+func SetPadTimer() {
+
+	toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey("PAD-ICP"))
+	lfshook.NewLogger().Infof("==SetPadTimer====runing:%d==toRun:%d=", priority.RunningTypePriority, toRunpriority)
+	if priority.RunningTypePriority < toRunpriority || priority.RunningTypePriority == 0 {
+
+		//if active.QueueTimer == nil {
+		res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
+		if err != nil {
+			lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
+			return
+		}
+		if res.Calls != "0" {
+
+			lfshook.NewLogger().Infof("==SetPadTimer==QueueTimer===1====")
+			active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
+
+				res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
+				if err != nil {
+					lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
+					return
+				}
+
+				if res.Calls == "0" { // OCC queue empty
+					resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
+					if err != nil {
+						lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+						return
+					}
+					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("====SetPadTimer==QueueTimer==2=")
+						lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
+						//order by pos
+						RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
+						time.Sleep(time.Microsecond * 500)                                            //200 ms delay
+					}
+				}
+			})
+		}
+	}
+}

+ 91 - 55
internal/app/ami/action/index.go

@@ -28,7 +28,7 @@ func HandleAMI(event map[string]string) {
 	switch event["Event"] {
 
 	case "DTMFBegin": //ICP interrupt PAD-ICP
-
+		lfshook.NewLogger().Infof("=========%s============", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) {
 			//exten := strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0] //get ICP exten number
 			//if utils.IsICP(exten) {
@@ -38,23 +38,39 @@ func HandleAMI(event map[string]string) {
 			}
 
 			//1. Redirect the connected PAD to 0300
-			for _, ret := range chans {
-				//lfshook.NewLogger().Infof("===HangupRunningTask=PAD1====Chans-ret===%+v==== ", ret)
-				//hangup pad call ICP channel
-				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")
-						if err != nil {
-							lfshook.NewLogger().Errorf("Redirect %+v", err)
+			if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
+				for _, ret := range chans {
+					//lfshook.NewLogger().Infof("===HangupRunningTask=PAD1====Chans-ret===%+v==== ", ret)
+					//hangup pad call ICP channel
+					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")
+							if err != nil {
+								lfshook.NewLogger().Errorf("Redirect %+v", err)
+							}
+
+							number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
+							active.NotifyPaiu(number, "hold")
+							HangupAllLocalChan()
+						} else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
+							lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
+							Hangup(ret.Channel)
+						}
+					}
+				}
+			} else if priority.RunningType == "PAD-OCC" {
+				//2. Redirect the connected PAD to 0300
+				for _, ret := range chans {
+					//hangup pad call ICP channel
+					if utils.IsPAIU(ret.CallerIDNum) {
+						lfshook.NewLogger().Infof("===DTMFBegin==hangup=%+v==== ", ret.Channel)
+						if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
+							Hangup(ret.Channel)
+							HangupAllLocalChan()
+						} else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
+							Hangup(ret.Channel)
 						}
-
-						number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
-						active.NotifyPaiu(number, "hold")
-						HangupAllLocalChan()
-					} else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
-						lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
-						Hangup(ret.Channel)
 					}
 				}
 			}
@@ -188,7 +204,7 @@ func HandleAMI(event map[string]string) {
 					}
 
 					//hangup others if priority is higher
-					if priority.RunningType != "C2C" {
+					if priority.RunningType != "" {
 						HangupRunningTask("CPA") //CPA interrupt other
 					} else {
 						//call to ICP ; can not stop calling ICP
@@ -201,22 +217,23 @@ func HandleAMI(event map[string]string) {
 		} else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab start; check cab cab priority
 
 			if priority.CheckPriority("CabCab") {
+				//C2C start PAD interrupt
+				if priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" || priority.RunningType == "CPA" {
+
+					//Hangup the other ICP
+					lfshook.NewLogger().Infof("========CabCab  hangup other one====caller %s", event["CallerIDNum"])
+
+					if event["CallerIDNum"] == "2311" {
+						Hangup("2381")
+					} else {
+						Hangup("2311")
+					}
+
+				} else {
 
-				if priority.RunningType == "PA" || priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
 					lfshook.NewLogger().Infof("=======HangupRunningTask====%s", event["CallerIDNum"])
 					HangupRunningTask("C2C") //C2C interrupt other
-					//	} else if priority.RunningType == "CPA" {
 
-				} else {
-					//Hangup the other ICP
-					lfshook.NewLogger().Infof("========CabCab  hangup other one====%s", event["CallerIDNum"])
-					if priority.RunningType != "" {
-						if event["CallerIDNum"] == "2311" {
-							Hangup("2381")
-						} else {
-							Hangup("2311")
-						}
-					}
 				}
 			} else { // hangup caller; C2C start failed
 				lfshook.NewLogger().Infof("========CabCab  hangup caller====%s", event["CallerIDNum"])
@@ -313,6 +330,7 @@ func HandleAMI(event map[string]string) {
 					//priority.CleanPriorityTag()
 					//HangupAllLocalChan()
 					if priority.PADStart == 1 {
+						SetPadTimer()
 						alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 						priority.PADStart = 0
 
@@ -346,34 +364,41 @@ func HandleAMI(event map[string]string) {
 			}
 
 			if priority.ICPAnswer == 0 && ICPQueue.Calls == "1" { //ICP did not answer any first call to the ICP queue ; Ready to Set Occ Queue Timer
+				toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey("PAD-ICP"))
 
-				active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
+				//PAD press key
+				lfshook.NewLogger().Infof("===QueueCallerJoin=====runing:%d=====toRun:=%d==", priority.RunningTypePriority, toRunpriority)
+				if priority.RunningTypePriority > toRunpriority || priority.RunningTypePriority == 0 {
 
-					res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
-					if err != nil {
-						lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
-						return
-					}
+					active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
 
-					if res.Calls == "0" { // OCC queue empty
-						resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
+						res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
 						if err != nil {
-							lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+							lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
 							return
 						}
-						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
-							RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
-							time.Sleep(time.Microsecond * 500)                                            //200 ms delay
+
+						if res.Calls == "0" { // OCC queue empty
+							resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
+							if err != nil {
+								lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+								return
+							}
+							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("====QueueCallerJoin==QueueTimer===%s", event["Event"])
+								lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
+								//order by pos
+								RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
+								time.Sleep(time.Microsecond * 500)                                            //200 ms delay
+							}
 						}
-					}
-				})
+					})
+				}
 			}
 
 			break
@@ -543,6 +568,7 @@ func HandleAMI(event map[string]string) {
 	case "ConfbridgeLeave":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
+			SetPadTimer()
 			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
@@ -552,6 +578,7 @@ func HandleAMI(event map[string]string) {
 
 		} else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
+			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
 			if priority.ResumeEmgPara.FileName != "" {
@@ -560,11 +587,13 @@ func HandleAMI(event map[string]string) {
 
 			//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{}
 
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
+			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "STN", "end")
 			if priority.ResumeEmgPara.FileName != "" {
@@ -572,6 +601,7 @@ func HandleAMI(event map[string]string) {
 			}
 
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
+			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "DCS", "end")
 			if priority.ResumeEmgPara.FileName != "" {
@@ -579,6 +609,7 @@ func HandleAMI(event map[string]string) {
 			}
 
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
+			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "SPC", "end")
 			if priority.ResumeEmgPara.FileName != "" {
@@ -586,6 +617,7 @@ func HandleAMI(event map[string]string) {
 			}
 
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
+			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "CHK", "end")
 			if priority.ResumeEmgPara.FileName != "" {
@@ -593,6 +625,7 @@ func HandleAMI(event map[string]string) {
 			}
 
 		} else if event["CallerIDName"] == "VOL" && event["Exten"] == "0513" {
+			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "VOL", "end")
 			if priority.ResumeEmgPara.FileName != "" {
@@ -604,8 +637,9 @@ func HandleAMI(event map[string]string) {
 		//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab start
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
-			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
-			priority.RunningType = "C2C"
+			//priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
+			//priority.RunningType = "C2C"
+			priority.C2CRuning = 1
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
 		}
 
@@ -613,8 +647,10 @@ func HandleAMI(event map[string]string) {
 		//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab end
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
-			priority.RunningTypePriority = 0
-			priority.RunningType = ""
+			SetPadTimer()
+			//priority.RunningTypePriority = 0
+			//priority.RunningType = ""
+			priority.C2CRuning = 0
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 		}
 

+ 3 - 6
internal/app/stc/broadcast/stc-broadcast.go

@@ -237,8 +237,8 @@ func processPacket(packet []byte) {
 			alstatus.PaStatus("", "PAD-ICP", "refuse")
 		}
 
-	default:
-		fmt.Printf("Unknown command: %x\n", packet[5])
+		//default:
+		//fmt.Printf("Unknown command: %x\n", packet[5])
 	}
 }
 
@@ -393,8 +393,6 @@ func ToneTest(data []byte) {
 		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
 
 	case 0x02: //stop
-
-		//alstatus.PaStatus("", "VOL", "end")
 		action.HangupAllExcept("")
 	}
 }
@@ -417,8 +415,7 @@ func SelfCheck(data []byte) {
 	case 0x02: //stop
 
 		//Pa status report
-		priority.CleanPriorityTag()
-		//alstatus.PaStatus("", "CHK", "end")
+		//priority.CleanPriorityTag()
 		action.HangupAllExcept("")
 	}
 }

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

@@ -17,6 +17,7 @@ var SpecialVoice = 0
 var RunningPATaskChan = ""
 var PADStart = 0
 var PADOccStart = 0
+var C2CRuning = 0
 
 type BroadcastResumeParas struct {
 	FileName      string `json:"filename"`
@@ -143,7 +144,7 @@ func CheckPriority(runType string) bool {
 		return true
 	} else {
 		//C2C run together with other task except ..
-		if RunningType == "C2C" {
+		if C2CRuning == 1 {
 			if runType != "PA" && runType != "PAD-ICP" && runType != "PAD-TMS" && runType != "C2C" {
 				return true
 			}