ソースを参照

ICP打断报警优先级修正

dujunchen 2 週間 前
コミット
7401a1f431

+ 8 - 5
internal/app/ami/action/call.go

@@ -105,6 +105,7 @@ func HangupRunningTask(toRunTask string) {
 
 	//same type return
 	if toRunTask == priority.RunningType {
+
 		if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
 			lfshook.NewLogger().Infof("===HangupRunningTask=ret==== ")
 			return
@@ -120,7 +121,7 @@ func HangupRunningTask(toRunTask string) {
 
 	if priority.RunningPATaskChan != "" {
 
-		if priority.C2CRuning == 1 { // Interrupt C2C task running,
+		if priority.RunningType == "C2C" { // Interrupt C2C task running,
 			if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
 				HangupICP()
 				//priority.CleanPriorityTag()
@@ -130,8 +131,10 @@ func HangupRunningTask(toRunTask string) {
 		switch priority.RunningType {
 
 		case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
+			priority.InterruptedPad = priority.RunningType
 			//just in case
-			if toRunTask == "C2C" {
+			if toRunTask == "C2C" { //deal in DTMF event
+				lfshook.NewLogger().Infof("===HangupRunningTask==C2C=return==== ")
 				return
 			}
 
@@ -174,7 +177,7 @@ func HangupRunningTask(toRunTask string) {
 				break
 
 			} else {
-
+				priority.InterruptedPad = priority.RunningType
 				//1. Redirect all the other pads in 0301 to 0300
 				resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
 				if err != nil {
@@ -378,11 +381,11 @@ func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
 
 func SetPadTimer() {
 
-	toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey("PAD-ICP"))
+	toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey(priority.InterruptedPad)) // 获取之前打断的报警优先级
 	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)

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

@@ -23,55 +23,111 @@ var AminInstance *amigo.Amigo
 var trainInfo = ""
 
 func HandleAMI(event map[string]string) {
-	//lfshook.NewLogger().Infof("===start======%s", event["Event"]
 
 	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) {
+	case "DTMFBegin": //ICP interrupt PAD
+		lfshook.NewLogger().Infof("=========%s====caller:%s=====digit:%s==", event["Event"], event["CallerIDNum"], event["Digit"])
+		if priority.RunningType != "PAD-ICP" && priority.RunningType != "PAD-TMS" && priority.RunningType != "PAD-OCC" {
+			break
+		}
+
+		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] != "" {
+
 			chans, err := CoreShowChannels()
 			if err != nil {
 				lfshook.NewLogger().Errorf("CoreShowChannels %+v", err)
 			}
 
-			//1. Redirect the connected PAD to 0300
-			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)
+			//PA interrupt PAD
+			if event["Digit"] == "#" {
+
+				//1. Redirect the connected PAD to 0300
+				if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
+					for _, ret := range chans {
+						//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")
+								if err != nil {
+									lfshook.NewLogger().Errorf("Redirect %+v", err)
+								}
+
+								number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
+								active.NotifyPaiu(number, "hold")
+								//HangupAllLocalChan()
 							}
+						}
+					}
 
-							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)
+					for _, ret := range chans {
+						//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=Chan===%+v==== ", ret.Channel)
+								Hangup(ret.Channel)
+							}
 						}
 					}
+					HangupRunningTask("PA")
+				} else if priority.RunningType == "PAD-OCC" {
+					//2. hangup connected PAD, and redirect all PADs in 0301 to 0300
+					priority.OCCAnswer = 0
+
+					resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
+					if err != nil {
+						lfshook.NewLogger().Infof("===QueueStatus==%+v", err)
+					}
+					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
+					}
+
+					/*	for _, ret := range chans {
+						//hangup pad call ICP channel
+						if utils.IsPAIU(ret.CallerIDNum) {
+							lfshook.NewLogger().Infof("===DTMFBegin=hangup=%+v==%s=== ", ret.Channel, ret.ChannelStateDesc)
+
+							if ret.ConnectedLineNum == "<unknown>" && ret.ChannelStateDesc != "Ring" { //redirect pad chanspy channel
+								Hangup(ret.Channel)
+							} else if utils.IsICP(ret.ConnectedLineNum) && ret.ChannelStateDesc == "Up" {
+								Hangup(ret.Channel)
+							}
+						}
+					}*/
+					HangupRunningTask("PA")
+					//HangupAllLocalChan()
 				}
-			} 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)
+			} else if event["Digit"] == "*" { //Cab cab interrupt PAD
+				lfshook.NewLogger().Infof("===Cab cab interrupt PAD====== ")
+				if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
+					for _, ret := range chans {
+
+						if utils.IsPAIU(ret.CallerIDNum) {
+							if ret.ConnectedLineNum == "<unknown>" && ret.ChannelStateDesc == "Up" { //redirect pad chanspy 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)
+							}
 						}
 					}
+					priority.InterruptedPad = priority.RunningType
+					HangupAllLocalChan()
+					Hangup(priority.RunningPATaskChan)
+					priority.CleanPriorityTag()
+					//HangupRunningTask("C2C")
+				} else if priority.RunningType == "PAD-OCC" {
+					HangupICP()
 				}
 			}
 		}
@@ -79,8 +135,70 @@ func HandleAMI(event map[string]string) {
 	case "UserEvent": // RCD filename; PA;CPA; CabCab
 		lfshook.NewLogger().Infof("========event:%s   File:%s", event["Event"], event["FILENAME"])
 
-		//Get  record file name ,encode and upload
-		if event["UserEvent"] == "SetRecordFile" {
+		if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
+			//PA & CPA interrupt others
+			if utils.IsICP(event["CallerIDNum"]) {
+				//priority.PAStart = 1
+				if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
+					Hangup(event["CallerIDNum"])
+				}
+
+				if priority.CheckPriority("ManuPa") {
+					//hangup others if priority is higher
+					HangupRunningTask("PA") //PA interrupt other
+				} else {
+					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
+				}
+
+			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
+				if priority.CheckPriority("CPA") {
+					if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
+						Hangup(event["CallerIDNum"])
+					} else if active.ActivedCab == "1" && event["CallerIDNum"] == "1411" {
+						Hangup(event["CallerIDNum"])
+					} else if active.ActivedCab == "8" && event["CallerIDNum"] == "1481" {
+						Hangup(event["CallerIDNum"])
+					}
+
+					//hangup others if priority is higher
+					if priority.RunningType != "" {
+						HangupRunningTask("CPA") //CPA interrupt other
+					} else {
+						//call to ICP ; can not stop calling ICP
+						lfshook.NewLogger().Info("==Running CabCab , CPA start call ICP(ICP is on the phone)=====")
+					}
+				} else {
+					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
+				}
+			}
+		} else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab start; check cab cab priority
+
+			if priority.CheckPriority("CabCab") { // interrupt OCC-PAD
+				//C2C start PAD interrupt
+				if priority.RunningType == "PAD-OCC" {
+
+					//Hangup the other ICP
+					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"])
+				Hangup(event["CallerIDNum"])
+			}
+
+			//Get  record file name ,encode and upload
+		} else if event["UserEvent"] == "SetRecordFile" {
 
 			if configs.ConfigGlobal.ProcessRecord != "yes" {
 				break
@@ -136,7 +254,7 @@ func HandleAMI(event map[string]string) {
 					file := strings.Replace(filepath, ".wav", "", -1)
 					DstFile = fmt.Sprintf("%s-encrypted.wav", file)
 
-					lfshook.NewLogger().Infof("===========Bin file====%s", DstFile)
+					lfshook.NewLogger().Infof("Bin file====%s", DstFile)
 					err = utils.AudioFileEncode(DstFile, filepath)
 					if err != nil {
 						lfshook.NewLogger().Infof("Encode file: %s err: %+v", DstFile, err)
@@ -177,68 +295,6 @@ func HandleAMI(event map[string]string) {
 				lfshook.NewLogger().Infof("No files to upload!!!")
 				break
 			}
-
-		} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
-			//PA & CPA interrupt others
-			if utils.IsICP(event["CallerIDNum"]) {
-
-				if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
-					Hangup(event["CallerIDNum"])
-				}
-
-				if priority.CheckPriority("ManuPa") {
-					//hangup others if priority is higher
-					HangupRunningTask("PA") //PA interrupt other
-				} else {
-					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
-				}
-
-			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
-				if priority.CheckPriority("CPA") {
-					if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
-						Hangup(event["CallerIDNum"])
-					} else if active.ActivedCab == "1" && event["CallerIDNum"] == "1411" {
-						Hangup(event["CallerIDNum"])
-					} else if active.ActivedCab == "8" && event["CallerIDNum"] == "1481" {
-						Hangup(event["CallerIDNum"])
-					}
-
-					//hangup others if priority is higher
-					if priority.RunningType != "" {
-						HangupRunningTask("CPA") //CPA interrupt other
-					} else {
-						//call to ICP ; can not stop calling ICP
-						lfshook.NewLogger().Info("==Running CabCab , CPA start call ICP(ICP is on the phone)=====")
-					}
-				} else {
-					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
-				}
-			}
-		} 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 {
-
-					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"])
-				Hangup(event["CallerIDNum"])
-			}
 		}
 
 	case "Hangup":
@@ -367,8 +423,8 @@ func HandleAMI(event map[string]string) {
 				toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey("PAD-ICP"))
 
 				//PAD press key
-				lfshook.NewLogger().Infof("===QueueCallerJoin=====runing:%d=====toRun:=%d==", priority.RunningTypePriority, toRunpriority)
-				if priority.RunningTypePriority > toRunpriority || priority.RunningTypePriority == 0 {
+				lfshook.NewLogger().Infof("===QueueCallerJoin===runing:%d=====toRun:=%d==Status:%s", priority.RunningTypePriority, toRunpriority, event["ChannelStateDesc"])
+				if (priority.RunningTypePriority > toRunpriority || priority.RunningTypePriority == 0) && event["ChannelStateDesc"] != "Up" {
 
 					active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
 
@@ -637,9 +693,13 @@ 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.C2CRuning = 1
+
+			priority.TmpRunningTypePriority = priority.RunningTypePriority
+			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
+
+			priority.TmpRunningType = priority.RunningType
+			priority.RunningType = "C2C"
+
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
 		}
 
@@ -648,9 +708,13 @@ func HandleAMI(event map[string]string) {
 		//Cab Cab end
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
 			SetPadTimer()
-			//priority.RunningTypePriority = 0
-			//priority.RunningType = ""
-			priority.C2CRuning = 0
+
+			priority.RunningTypePriority = priority.TmpRunningTypePriority
+			priority.TmpRunningTypePriority = 0
+
+			priority.RunningType = priority.TmpRunningType
+			priority.TmpRunningType = ""
+
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 		}
 

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

@@ -28,7 +28,7 @@ func StartStcConnection(conn net.Conn, cab string) {
 		conn1, err = CreateConnection(cab)
 		if err != nil || conn1 == nil {
 			time.Sleep(2 * time.Second)
-			lfshook.NewLogger().Logger.Infof("===========Reconnecting====To Cab:%s=======", cab)
+			//lfshook.NewLogger().Logger.Infof("===========Reconnecting====To Cab:%s=======", cab)
 			continue
 		}
 

+ 11 - 3
internal/app/stc/priority/index.go

@@ -11,13 +11,21 @@ import (
 
 var ICPAnswer = 0
 var OCCAnswer = 0
+
 var RunningTypePriority = 0
 var RunningType = ""
-var SpecialVoice = 0
 var RunningPATaskChan = ""
+
+var TmpRunningTypePriority = 0
+var TmpRunningType = ""
+
+var SpecialVoice = 0
+
 var PADStart = 0
 var PADOccStart = 0
-var C2CRuning = 0
+var PAStart = 0
+
+var InterruptedPad = ""
 
 type BroadcastResumeParas struct {
 	FileName      string `json:"filename"`
@@ -144,7 +152,7 @@ func CheckPriority(runType string) bool {
 		return true
 	} else {
 		//C2C run together with other task except ..
-		if C2CRuning == 1 {
+		if RunningType == "C2C" {
 			if runType != "PA" && runType != "PAD-ICP" && runType != "PAD-TMS" && runType != "C2C" {
 				return true
 			}

+ 1 - 2
pkg/utils/file.go

@@ -9,7 +9,6 @@ import (
 	"os/exec"
 	"path/filepath"
 	"pbx-api-gin/internal/pkg/configs"
-	"pbx-api-gin/pkg/lfshook"
 	"strconv"
 	"strings"
 )
@@ -113,7 +112,7 @@ func ConvertAndSegmentWAV(inputFile string, outputPrefix string) ([]string, erro
 	// 解析输出,提取所有生成的文件名
 	files := extractFilenamesFromFFmpegOutput(outputPrefix)
 
-	lfshook.NewLogger().Infof("=============== found after convert outfiles %+v ", files)
+	//lfshook.NewLogger().Infof("found after convert outfiles %+v ", files)
 	return files, nil
 }