root 4 дней назад
Родитель
Сommit
2170f4dccf

+ 84 - 57
internal/app/ami/action/call.go

@@ -150,8 +150,25 @@ func InterruptRunningTask(toRunTask string) string {
 			return ""
 		}
 	}
+
+	/*if toRunTask == "C2C" { //当司机对讲打断业务为PA/PAD-ICP/PAD-TMS时,检测是否有EMG和CPA存在,存在则恢复播放
+		if taskName == "PA" || taskName == "PAD-ICP" || taskName == "PAD-TMS" {
+			//check resume
+			taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
+			if ok {
+				if taskName == "EMG" {
+					EMGConfbridgeReinvite(task.ConfbridgeID)
+				} else if taskName == "CPA" {
+					if CPAConfbridgeReinvite(task.ConfbridgeID) {
+						alstatus.PaStatus("", "CPA", "start")
+					}
+				}
+			}
+		}
+	}*/
+
 	utils.LoggerDebug.Printf("InterruptRunningTask  RunningTask:%+v", taskName)
-	lfshook.NewLogger().Infof("InterruptRunningTask RunningTask:%+v  ", task)
+	//lfshook.NewLogger().Infof("InterruptRunningTask RunningTask:%+v  ", task)
 	//same type return
 	if toRunTask == taskName {
 		if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" || toRunTask == "PAD-OCC" {
@@ -251,7 +268,7 @@ func InterruptRunningTask(toRunTask string) string {
 
 		priority.InterruptedPad = "PAD-ICP"
 
-		lfshook.NewLogger().Infof("InterruptRunningTask interrupt PAD-ICP/PAD-TMS ,Running type :%s !", task.RunType)
+		//lfshook.NewLogger().Infof("InterruptRunningTask interrupt PAD-ICP/PAD-TMS ,Running type :%s !", task.RunType)
 
 		chans, err := CoreShowChannels()
 		if err != nil {
@@ -263,7 +280,7 @@ func InterruptRunningTask(toRunTask string) string {
 		for _, ret := range chans {
 			// Redirect the connected PAD to 0300
 			if utils.IsPAIU(ret.CallerIDNum) {
-				lfshook.NewLogger().Infof("====interrupt PAD ==== %+v ", ret)
+				//lfshook.NewLogger().Infof("====interrupt PAD ==== %+v ", ret)
 
 				if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
 					err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
@@ -271,7 +288,7 @@ func InterruptRunningTask(toRunTask string) string {
 						lfshook.NewLogger().Infof("InterruptRunningTask Redirect err:%+v", err)
 						return taskName
 					}
-					lfshook.NewLogger().Infof("====interrupt PAD =1111=== %+v ", ret)
+					//lfshook.NewLogger().Infof("====interrupt PAD =1111=== %+v ", ret)
 					number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
 					active.NotifyPaiu(number, "hold")
 					//HangupAllLocalChan()
@@ -283,12 +300,12 @@ func InterruptRunningTask(toRunTask string) string {
 			//hangup pad call ICP channel
 			if utils.IsPAIU(ret.CallerIDNum) {
 				if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
-					lfshook.NewLogger().Infof("Hangup PAD Channel :%+v", ret.Channel)
+					//lfshook.NewLogger().Infof("Hangup PAD Channel :%+v", ret.Channel)
 					Hangup(ret.Channel)
 				}
 			}
 		}
-
+		alstatus.PaStatus("", "PAD", "end")
 		priority.RegistryTask.StopAndUnregister("PAD-ICP")
 		priority.RegistryTask.StopAndUnregister("PAD-TMS")
 		//2. hangup task channel (ICP + PACU)
@@ -296,25 +313,6 @@ func InterruptRunningTask(toRunTask string) string {
 		HangupAllLocalChan()
 		HangupICP()
 
-		//pad end
-		if priority.PADStart == 1 {
-			alstatus.PaStatus("", "PAD", "end")
-			priority.PADStart = 0
-
-			//check resume
-			taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
-			if ok {
-				if taskName == "EMG" {
-					EMGConfbridgeReinvite(task.ConfbridgeID)
-					//alstatus.PaStatus("", "EMG", "start")
-				} else if taskName == "CPA" {
-					if CPAConfbridgeReinvite(task.ConfbridgeID) {
-						alstatus.PaStatus("", "CPA", "start")
-					}
-				}
-			}
-		}
-
 	case "PAD-OCC": // Interrupt PAD-OCC task running,
 
 		if toRunTask == "C2C" {
@@ -356,9 +354,10 @@ func InterruptRunningTask(toRunTask string) string {
 			//occ pad end
 			if priority.PADOccStart == 1 {
 				alstatus.OccPad("end")
+				alstatus.PaStatus("", "PAD", "end")
 				priority.PADOccStart = 0
+				priority.OCCAnswer = 0
 			}
-
 		}
 
 	default:
@@ -573,18 +572,18 @@ func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
 
 func SetPadTimer() {
 
-	toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) //Get PAD priori 获取之前打断的报警优先级
-	//toRunpriority := priority.GetPriorityByKey("PAD-ICP")
-
+	//toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) //Get PAD priori 获取之前打断的报警优先级
+	toRunPadpriority := priority.GetPriorityByKey("PAD-ICP")
 	_, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
 	if ok {
-		lfshook.NewLogger().Infof("PAD SetPadTimer runing priority:%d toRun priority:%d", taskTmp.Priority, toRunPadpriority)
 		if taskTmp.Priority < toRunPadpriority { //higher priority task running ,do not set timer
+			utils.LoggerDebug.Printf("PAD SetPadTimer runing priority:%d toRun priority:%d , return !", taskTmp.Priority, toRunPadpriority)
 			return
 		}
 	}
 
-	res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
+	utils.LoggerDebug.Printf("PAD SetPadTimer check 0300")
+	res, err := QueueStatus("0300", "")
 	if err != nil {
 		lfshook.NewLogger().Infof("QueueStatus err%+v", err)
 		return
@@ -594,7 +593,7 @@ func SetPadTimer() {
 	}
 	if res.Calls != "0" {
 
-		lfshook.NewLogger().Infof("PAD SetPadTimer Set QueueTimer timeout 30s !")
+		utils.LoggerDebug.Printf("PAD SetPadTimer Set QueueTimer timeout 30s !")
 		//active.SetTimer = true
 		//lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
 		if active.QueueTimer != nil {
@@ -700,24 +699,47 @@ func CPAConfbridgeKick(confnum string) (res map[string]string, err error) {
 }
 
 func CPAConfbridgeReinvite(confID string) bool {
-
+	time.Sleep(time.Millisecond * 100)
 	utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , resume CPA .")
 
-	if priority.PAInterrupt == 1 {
-		utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , Get PA Interrupt PAInterrupt == 1 return !")
+	/*if priority.TaskCreating == "" || priority.CABInterrupt == 1 { //高优先级被cabcab打断,或者高优先级直接挂断
+
+		for _, ext := range Speakers {
+			if utils.IsICP(ext) {
+				if priority.CABInterrupt == 0 {
+					utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , Get CABCAB Interrupt resume CPA , ignore %s continue .", ext)
+					continue
+				}
+			}
+
+			ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
+		}
+	} else {
+		utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , Interrupt by other ,return !")
 		return false
 	}
+	return true*/
 
-	time.Sleep(time.Millisecond * 100)
-	for _, ext := range Speakers {
-		if utils.IsICP(ext) {
-			if priority.CABInterrupt == 1 {
-				utils.LoggerDebug.Printf("CPA CPAConfbridgeReinvite , Get PA/CABCAB Interrupt resume CPA , ignore %s continue .", ext)
-				continue
+	if priority.PAInterrupt == 1 { // PA 打断标签判断
+		utils.LoggerDebug.Printf("CPA ConfbridgeReinvite , PA ready to go , return !")
+		return false
+	} else if priority.CABInterrupt == 1 { //CABCAB 打断标签判断
+		for _, ext := range Speakers { //高优先级被cabcab打断,或者高优先级直接挂断
+			if utils.IsICP(ext) {
+				if priority.CABInterrupt == 1 {
+					utils.LoggerDebug.Printf("CPA ConfbridgeReinvite , Get CABCAB Interrupt resume CPA , ignore %s continue .", ext)
+					continue
+				}
 			}
+			ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
+		}
+	} else if priority.TaskCreating != "" {
+		utils.LoggerDebug.Printf("CPA ConfbridgeReinvite , other PA ready to go , return !")
+		return false
+	} else {
+		for _, ext := range Speakers {
+			ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
 		}
-
-		ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
 	}
 	return true
 }
@@ -738,24 +760,29 @@ func EMGConfbridgeKick(confnum string) (res map[string]string, err error) {
 }
 
 func EMGConfbridgeReinvite(confID string) {
-
+	time.Sleep(time.Millisecond * 100)
 	utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , resume EMG .")
 
-	if priority.PAInterrupt == 1 {
-		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , Get PA Interrupt PAInterrupt == 1 return !")
+	if priority.PAInterrupt == 1 { // PA 打断标签判断
+		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , PA ready to go , return !")
 		return
-	}
-
-	time.Sleep(time.Millisecond * 100)
-	for _, ext := range Speakers {
-		if utils.IsICP(ext) {
-			if priority.CABInterrupt == 1 {
-				utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , Get CABCAB Interrupt resume EMG , ignore %s continue .", ext)
-				continue
+	} else if priority.CABInterrupt == 1 { //CABCAB 打断标签判断
+		for _, ext := range Speakers { //高优先级被cabcab打断,或者高优先级直接挂断
+			if utils.IsICP(ext) {
+				if priority.CABInterrupt == 1 {
+					utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , Get CABCAB Interrupt resume EMG , ignore %s continue .", ext)
+					continue
+				}
 			}
+			ConfbridgeReinvite(ext, "call-speakers-emg", confID)
+		}
+	} else if priority.TaskCreating != "" {
+		utils.LoggerDebug.Printf("EMG ConfbridgeReinvite , other PA ready to go , return !")
+		return
+	} else {
+		for _, ext := range Speakers {
+			ConfbridgeReinvite(ext, "call-speakers-emg", confID)
 		}
-
-		ConfbridgeReinvite(ext, "call-speakers-emg", confID)
 	}
 }
 
@@ -812,7 +839,7 @@ func ConfbridgeReinvite(src, context, confID string) {
 
 func ICPConfbridgeReinvite(confID, paType string) {
 
-	if priority.CABInterrupt == 1 || priority.PAInterrupt == 1 {
+	if priority.CABInterrupt == 1 || priority.CABInterrupt == 1 {
 		utils.LoggerDebug.Printf("ICPConfbridgeReinvite, Get PA/CABCAB Interrupt resume %s faild .", paType)
 		return
 	}

+ 31 - 54
internal/app/ami/action/index.go

@@ -73,7 +73,6 @@ func HandleAMI(event map[string]string) {
 					Hangup(event["CallerIDNum"])
 				}
 
-				priority.PAInterrupt = 0
 				WaitTaskCreate("PA", event["CallerIDNum"])
 
 				if priority.CheckPriority("ManuPa") {
@@ -353,6 +352,7 @@ func HandleAMI(event map[string]string) {
 			if res.Calls == "0" { //OCC queue is empty
 				utils.LoggerDebug.Printf("Check PAD-OCC queue no PAD now ! Send PAD-OCC end to STC .")
 
+				alstatus.PaStatus("", "PAD", "end")
 				alstatus.OccPad("end")
 				priority.OCCAnswer = 0
 				priority.PADOccStart = 0
@@ -463,11 +463,12 @@ func HandleAMI(event map[string]string) {
 
 		if utils.IsPAIU(event["CallerIDNum"]) { // PAD hangup, check if PAD all end, send PAD end status
 
+			utils.LoggerDebug.Printf("===event:=====%+v======", event)
 			number := strings.Split(strings.Split(event["Channel"], "-")[0], "/")[1]
 
-			lfshook.NewLogger().Infof("===hangup PAD ===NUM:%s=================listAllTask:%+v===", number, priority.RegistryTask.ListAll())
+			//lfshook.NewLogger().Infof("===hangup PAD ===NUM:%s=================listAllTask:%+v===", number, priority.RegistryTask.ListAll())
 
-			if utils.IsPAIU(number) { //pad and io hangup
+			if utils.IsPAIU(number) { //pad hangup
 
 				//clean confbridge & clean task info
 				//PAD-ICP
@@ -484,58 +485,31 @@ func HandleAMI(event map[string]string) {
 					priority.RegistryTask.StopAndUnregister("PAD-TMS")
 				}
 
-				//PAD-OCC
-				taskTmp, ok = priority.RegistryTask.Get("PAD-OCC")
-				if ok {
-					ConfbridgeKick(taskTmp.ConfbridgeID, "all")
-					priority.RegistryTask.StopAndUnregister("PAD-OCC")
-				}
+				if event["Context"] == "chanspy-rule-whisper" {
+					alstatus.PaStatus("", "PAD", "end")
 
-				lfshook.NewLogger().Infof("===hangup PAD ===NUM:%s========2222=========listAllTask:%+v===", number, priority.RegistryTask.ListAll())
-				//Check PAD END
-				res, _ := QueueStatus("0300", "")  // check ICP queue ,if empty PAD end
-				res1, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
-				if res == nil || res1 == nil {
-					utils.LoggerDebug.Printf("PAD Hangup , check ICP|OCC queue return nil, exit.")
-					return
-				}
-				lfshook.NewLogger().Infof("===Hangup  PAD====== ICP Queue calls:%s  OCC Queue calls:%s", res.Calls, res1.Calls)
-				if res.Calls == "0" && res1.Calls == "0" {
-
-					if priority.PADStart == 1 {
-						//SetPadTimer()
-						alstatus.PaStatus("", "PAD", "end")
-						priority.PADStart = 0
-						//priority.PADTMSStart = 0
-
-						//check resume
-						taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
-						if ok {
-							if taskName == "EMG" {
-								EMGConfbridgeReinvite(task.ConfbridgeID)
-								//alstatus.PaStatus("", "EMG", "start")
-							} else if taskName == "CPA" {
-								if CPAConfbridgeReinvite(task.ConfbridgeID) {
-									alstatus.PaStatus("", "CPA", "start")
-								}
-							}
-						}
+					res, _ := QueueStatus("0301", "") // check ICP queue ,if empty PAD end
+					if res == nil {
+						utils.LoggerDebug.Printf("Check PAD-OCC queue , return nill . exit !")
+						return
 					}
 
-					priority.ICPAnswer = 0
-					priority.OCCAnswer = 0
-					break
+					if res.Calls == "0" {
+						priority.ICPAnswer = 0
+					} //ICP queue is empty ,clean tag
 				}
 
-				//check resume
-				taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
-				if ok {
-					if taskName == "EMG" {
-						EMGConfbridgeReinvite(task.ConfbridgeID)
-						//alstatus.PaStatus("", "EMG", "start")
-					} else if taskName == "CPA" {
-						if CPAConfbridgeReinvite(task.ConfbridgeID) {
-							alstatus.PaStatus("", "CPA", "start")
+				if priority.OCCAnswer == 0 { // not OCC-PAD
+					//check resume
+					taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
+					if ok {
+						if taskName == "EMG" {
+							EMGConfbridgeReinvite(task.ConfbridgeID)
+							//alstatus.PaStatus("", "EMG", "start")
+						} else if taskName == "CPA" {
+							if CPAConfbridgeReinvite(task.ConfbridgeID) {
+								alstatus.PaStatus("", "CPA", "start")
+							}
 						}
 					}
 				}
@@ -551,6 +525,8 @@ func HandleAMI(event map[string]string) {
 				utils.LoggerDebug.Printf("C2C : Clean priority.TaskCreating = '' !")
 				priority.TaskCreating = ""
 			}
+			SetPadTimer()
+
 			//check resume
 			taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
 			if ok {
@@ -589,7 +565,7 @@ 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 := priority.GetPriorityByKey("PAD-ICP")
 
-				time.Sleep(time.Millisecond * 500) //wait high priority task start
+				//time.Sleep(time.Millisecond * 500) //wait high priority task start
 				_, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
 				if ok {
 					//lfshook.NewLogger().Infof("=1==QueueCallerJoin===runing:%d=====toRun:=%d==Status:%s", taskTmp, toRunpriority, event["ChannelStateDesc"])
@@ -944,6 +920,7 @@ func HandleAMI(event map[string]string) {
 				priority.TaskCreating = ""
 			}
 
+			priority.PAInterrupt = 0 //清除标记
 			//check PAD timer
 			if priority.AllTasks.PADOCC.Priority > priority.AllTasks.PA.Priority {
 				if active.QueueTimer != nil {
@@ -1380,11 +1357,11 @@ func HandleAMI(event map[string]string) {
 
 				alstatus.OccPad("start")
 				priority.PADOccStart = 1
-			}
+				//}
 
-			if priority.PADStart == 0 {
+				//if priority.PADStart == 0 {
 				alstatus.PaStatus("", "PAD", "start")
-				priority.PADStart = 1
+				//priority.PADStart = 1
 			}
 		}
 

+ 10 - 8
internal/app/stc/broadcast/stc-broadcast.go

@@ -772,10 +772,11 @@ func AlarmHandleICP(data []byte) {
 	case 0x01: //answer(ICP+Alarm+PACU)
 		//NotifyPaiu(exten, "answer")
 		priority.ICPAnswer = 1
-		if priority.PADStart == 0 {
-			alstatus.PaStatus("", "PAD", "start")
-			priority.PADStart = 1
-		}
+		//if priority.PADStart == 0 {
+		alstatus.PaStatus("", "PAD", "start")
+		priority.InterruptedPad = ""
+		//	priority.PADStart = 1
+		//}
 		utils.LoggerDebug.Printf("ICP Answer PAD:%s .", exten)
 
 		if active.ActivedCab == "1" {
@@ -825,10 +826,11 @@ func AlarmHandleTMS(data []byte) {
 	case 0x01: //answer(ICP+Alarm+PACU)
 		//PACU---call---->ICP1
 		//PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
-		if priority.PADStart == 0 {
-			alstatus.PaStatus("", "PAD", "start")
-			priority.PADStart = 1
-		}
+		//if priority.PADStart == 0 {
+		alstatus.PaStatus("", "PAD", "start")
+		priority.InterruptedPad = ""
+		//priority.PADStart = 1
+		//}
 		priority.ICPAnswer = 1
 		utils.LoggerDebug.Printf("TMS Answer PAD:%s 	PACU:%s", exten, PacuNum)
 

+ 4 - 4
internal/app/stc/priority/index.go

@@ -16,8 +16,8 @@ var OCCAnswer = 0
 var SpecialVoice = 0
 
 // PAD是否发起
-var PADStart = 0
-var PADTMSStart = 0
+// var PADStart = 0
+// var PADTMSStart = 0
 var PADOccStart = 0
 
 // 是否有任务正在创建
@@ -26,9 +26,9 @@ var TaskCreating = ""
 // 被打断的PAD类型
 var InterruptedPad = ""
 
-// 是否有PAD/CABCAB打断其他(DTMF */#)
-var PAInterrupt = 0
+// 是否有CABCAB/PA打断其他(DTMF #/*)
 var CABInterrupt = 0
+var PAInterrupt = 0
 
 var filePath = "/etc/asterisk/priority.conf"