浏览代码

1.去掉录音文件路径中的特殊字符;2.报警器超时计时器停止和接听标记设置优化

dujunchen 2 周之前
父节点
当前提交
cb9ceff522

+ 12 - 9
internal/app/ami/action/call.go

@@ -2,9 +2,11 @@ package action
 
 import (
 	"fmt"
+	"pbx-api-gin/internal/app/stc/active"
 	"pbx-api-gin/internal/app/stc/priority"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -17,14 +19,15 @@ var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "21
 
 // Function triggered before no cab occupied signal interrupt
 func InActiveHangup() {
-
-	switch priority.RunningType {
-	case "PA":
-		HangupRunningTask("")
-	case "CPA":
-		HangupRunningTask("")
-	case "VOL":
-		HangupRunningTask("")
+	if active.ActivedCab == "" {
+		switch priority.RunningType {
+		case "PA":
+			HangupRunningTask("InActiveHangup")
+		case "CPA":
+			HangupRunningTask("InActiveHangup")
+		case "VOL":
+			HangupRunningTask("InActiveHangup")
+		}
 	}
 }
 
@@ -33,7 +36,7 @@ func CheckEmgResume() {
 
 	time.AfterFunc(2*time.Second, func() {
 		if priority.CheckPriority("EMG") || priority.RunningType == "C2C" {
-			PlaybackPacu(priority.ResumeEmgPara.FileName, priority.ResumeEmgPara.Count, priority.ResumeEmgPara.Delay, priority.ResumeEmgPara.BroadcastType)
+			PlaybackPacu(strconv.Quote(priority.ResumeEmgPara.FileName), priority.ResumeEmgPara.Count, priority.ResumeEmgPara.Delay, priority.ResumeEmgPara.BroadcastType)
 		}
 	})
 }

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

@@ -19,11 +19,7 @@ import (
 var AminInstance *amigo.Amigo
 
 func HandleAMI(event map[string]string) {
-	//lfshook.NewLogger().Infof("===start======%s", event["Event"])
-	//return if not actived
-	if !active.Actived {
-		return
-	}
+	//lfshook.NewLogger().Infof("===start======%s", event["Event"]
 
 	switch event["Event"] {
 
@@ -34,14 +30,19 @@ func HandleAMI(event map[string]string) {
 
 		} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
 			//check active signal  before PA; hangup if not actived
-			if active.CabNum == "1" && !active.Actived && event["CallerIDNum"] == "2311" {
-				Hangup(event["CallerIDNum"])
-			} else if active.CabNum == "8" && !active.Actived && event["CallerIDNum"] == "2381" {
-				Hangup(event["CallerIDNum"])
-			}
+			/*	if active.ActivedCab == "1" && event["CallerIDNum"] == "2311" {
+					Hangup(event["CallerIDNum"])
+				} else if active.ActivedCab == "8" && event["CallerIDNum"] == "2381" {
+					Hangup(event["CallerIDNum"])
+				}*/
 
 			//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
@@ -53,9 +54,12 @@ func HandleAMI(event map[string]string) {
 				if priority.CheckPriority("CPA") {
 
 					//check active signal  before CPA; hangup if not actived
-					if active.CabNum == "1" && !active.Actived && event["CallerIDNum"] == "1411" {
-						Hangup(event["CallerIDNum"])
-					} else if active.CabNum == "8" && !active.Actived && event["CallerIDNum"] == "1481" {
+					/*	if active.ActivedCab == "8" && event["CallerIDNum"] == "1411" {
+							Hangup(event["CallerIDNum"])
+						} else if active.ActivedCab == "1" && event["CallerIDNum"] == "1481" {
+							Hangup(event["CallerIDNum"])
+						}*/
+					if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
 						Hangup(event["CallerIDNum"])
 					}
 
@@ -105,8 +109,9 @@ func HandleAMI(event map[string]string) {
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsPAIU(event["CallerIDNum"]) && !strings.Contains(event["Channel"], "Local") { // PAD hangup, check if PAD all end, send PAD end status
 
-			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
-			if res.Calls == "0" {
+			res, _ := QueueStatus("0300", "")  // check ICP queue ,if empty PAD end
+			res1, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
+			if res.Calls == "0" && res1.Calls == "0" {
 				//priority.CleanPriorityTag()
 				//HangupAllLocalChan()
 				if priority.PADStart == 1 {
@@ -116,7 +121,8 @@ func HandleAMI(event map[string]string) {
 				/*if priority.ResumeEmgPara.FileName != "" {
 					CheckEmgResume()
 				}*/
-				//priority.ICPAnswer = 0
+				priority.ICPAnswer = 0
+				priority.OCCAnswer = 0
 				break
 			}
 		}
@@ -128,6 +134,7 @@ func HandleAMI(event map[string]string) {
 			if res.Calls == "0" {             //OCC queue is empty
 				priority.CleanPriorityTag()
 				alstatus.OccPad("end")
+				priority.OCCAnswer = 0
 
 				if priority.ResumeEmgPara.FileName != "" {
 					time.Sleep(time.Second)
@@ -138,11 +145,11 @@ func HandleAMI(event map[string]string) {
 			} else { //OCC queue is not empty
 				HangupAllLocalChan()
 
-				if active.CabNum == "1" && active.Actived && ExtenStatus("1411") == "Idle" { //check active and OCC status
+				if active.ActivedCab == "1" && ExtenStatus("1411") == "Idle" { //check active and OCC status
 					time.Sleep(time.Second)
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDName"], "1") // PACUs dial OCC1
 					//goto ConfbridgeJoin, OCC1 answer PAD
-				} else if active.CabNum == "8" && active.Actived && ExtenStatus("1481") == "Idle" {
+				} else if active.ActivedCab == "8" && ExtenStatus("1481") == "Idle" {
 					time.Sleep(time.Second)
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", event["CallerIDName"], "8") // PACUs dial OCC8
 					//goto ConfbridgeJoin, OCC8 answer PAD
@@ -161,28 +168,38 @@ func HandleAMI(event map[string]string) {
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Queue"] == "0300" { // Alarm join the queue, PAD in the queue
 			alstatus.AlarmStatus(event["CallerIDNum"], "queue") //send status to STC
 
-			time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
-				if priority.ICPAnswer == 0 { //ICP did not answer any
+			ICPQueue, err := QueueStatus("0300", "") // check ICP queue, get entries
+			if err != nil {
+				lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+				return
+			}
 
+			if priority.ICPAnswer == 0 && ICPQueue.Calls == "1" { //ICP did not answer any first call to the ICP queue ; Ready to Set Occ Queue Timer
+				lfshook.NewLogger().Infof("====SET TM===calls:%s", ICPQueue.Calls)
+				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)
 						return
 					}
-					if res.Calls == "0" { // OCC queue empty
 
+					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
 						}
-
 						for _, caller := range resCaller.Entrys {
+							priority.ICPAnswer = 0
+							lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s===", caller.CallerIDNum)
 							go RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
 						}
 					}
-				}
-			})
+				})
+			}
+
 			break
 		}
 
@@ -191,21 +208,24 @@ func HandleAMI(event map[string]string) {
 		//PAD chanspy(WqE) OCC;
 		//ICPs chanspy(qE) PAD;
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Queue"] == "0301" && priority.OCCAnswer == 0 { // The first PAD to OCC ,caller is PAD
+
 			if priority.CheckPriority("PAD-OCC") {
 				HangupRunningTask("PAD-OCC") //PAD-OCC interrupt other
 				priority.OCCAnswer = 1
 
-				if active.CabNum == "1" && active.Actived && ExtenStatus("1411") == "Idle" { //check active and OCC status
+				if active.ActivedCab == "1" && ExtenStatus("1411") == "Idle" { //check active and OCC status
 					if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
+						alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 					}
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDNum"], "1") // PACUs dial OCC1
 					//Goto event=ConfbridgeJoin;OCC answer PAD
-				} else if active.CabNum == "8" && active.Actived && ExtenStatus("1481") == "Idle" {
+				} else if active.ActivedCab == "8" && ExtenStatus("1481") == "Idle" {
 					if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
+						alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 					}
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", event["CallerIDNum"], "8") // PACUs dial OCC8
 					//Goto event=ConfbridgeJoin;OCC answer PAD
@@ -288,7 +308,7 @@ func HandleAMI(event map[string]string) {
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "CPA"
-			break
+			return
 		}
 
 		//ICP answer PAD;
@@ -321,7 +341,7 @@ func HandleAMI(event map[string]string) {
 		if event["ConnectedLineNum"] == "ano1" && event["Exten"] == "0512" && utils.IsPAIU(event["ConnectedLineName"]) { //PAD answered by OCC; PACUs connected IO1
 			lfshook.NewLogger().Infof("====PAD answered by OCC1:%s=====", event["ConnectedLineName"])
 			alstatus.AlarmStatus(event["ConnectedLineName"], "connect")
-			priority.OCCAnswer = 1
+
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "PAD-OCC"
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADOCC)
@@ -343,7 +363,7 @@ func HandleAMI(event map[string]string) {
 		if event["ConnectedLineNum"] == "ano8" && event["Exten"] == "0512" && utils.IsPAIU(event["ConnectedLineName"]) { //PAD ansered by OCC8; PACUs connected IO8
 			lfshook.NewLogger().Infof("====PAD answered by OCC8:%s=====", event["ConnectedLineName"])
 			alstatus.AlarmStatus(event["ConnectedLineName"], "connect")
-			priority.OCCAnswer = 1
+
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "PAD-OCC"
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADOCC)
@@ -470,10 +490,10 @@ func HandleAMI(event map[string]string) {
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "PAD-TMS"
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADTMS)
-			if active.CabNum == "1" && active.Actived {
+			if active.ActivedCab == "1" {
 				go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
 				go Dial("0403", event["CallerIDName"], "chanspy-rule", "2381", "2381", "8")   //ICP8---chanspy----PAD
-			} else if active.CabNum == "8" && active.Actived {
+			} else if active.ActivedCab == "8" {
 				go RedirectInQueue(event["CallerIDName"], "2381", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP8
 				go Dial("0403", event["CallerIDName"], "chanspy-rule", "2311", "2311", "1")   //ICP1---chanspy----PAD
 			}

+ 1 - 1
internal/app/index.go

@@ -35,7 +35,7 @@ func StartApp() {
 	lfshook.NewLogger().Infof("=================cab number:%s===========", active.CabNum)
 
 	//init the active status
-	active.Actived = true
+	active.ActivedCab = ""
 
 	//get priority
 	priority.GetPriority()

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

@@ -1,9 +1,13 @@
 package active
 
+import "time"
+
 // var ActiveCab string
 var CabNum string
-var Actived bool
+var ActivedCab = "1"
 
 var Master bool
 
+var QueueTimer *time.Timer = nil
+
 //var ActivedMC int

+ 31 - 34
internal/app/stc/broadcast/stc-broadcast.go

@@ -71,9 +71,9 @@ func processPacket(packet []byte) {
 	}
 
 	//for recv data log debug
-	if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
-		lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
-	}
+	//if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
+	lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
+	//}
 
 	//check if the cmd type is avtive
 	if packet[5] == 0x03 { // ACTIVE
@@ -140,6 +140,7 @@ func processPacket(packet []byte) {
 		if priority.CheckPriority("PAD-TMS") {
 			action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
 			AlarmHandleTMS(packet)
+			active.QueueTimer.Stop()
 		} else {
 			alstatus.PaStatus("", "PAD-TMS", "refuse")
 		}
@@ -154,7 +155,8 @@ func processPacket(packet []byte) {
 		if priority.CheckPriority("PAD-ICP") {
 
 			action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
-			AlarmHandleICP(packet)              //
+			active.QueueTimer.Stop()
+			AlarmHandleICP(packet) //
 		} else {
 			alstatus.PaStatus("", "PAD-ICP", "refuse")
 		}
@@ -177,7 +179,7 @@ func StationAnn(data []byte) (err error) {
 	//set spc voice tag
 	priority.SpecialVoice = specialVoice
 
-	action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
+	action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "STN")
 	return nil
 }
 
@@ -193,26 +195,21 @@ func Active(data [1]byte) {
 	case 0:
 
 		//lfshook.NewLogger().Logger.Infof("=================Inactive==================")
-		active.Actived = false
+		active.ActivedCab = ""
 		action.InActiveHangup()
 
 	case 1:
-
+		active.ActivedCab = "1"
 		//lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
-		if active.CabNum == "1" { // local cab is MC1
-			active.Actived = true
-		} else {
-			active.Actived = false
+		if active.CabNum == "8" { // local cab is MC1
 			action.InActiveHangup()
 		}
 
 	case 8:
 
+		active.ActivedCab = "8"
 		//lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
-		if active.CabNum == "8" { //Local cab is MC8
-			active.Actived = true
-		} else {
-			active.Actived = false
+		if active.CabNum == "1" { //Local cab is MC8
 			action.InActiveHangup()
 		}
 	}
@@ -228,9 +225,9 @@ func SpecialAnn(data []byte) {
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 
 	if int(cycleCount) == 255 {
-		action.PlaybackPacu(filename, 9999999, int(delay), "SPC")
+		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
 	} else {
-		action.PlaybackPacu(filename, int(cycleCount), int(delay), "SPC")
+		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SPC")
 	}
 }
 
@@ -243,10 +240,10 @@ func EmgMsg(data []byte) {
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 
 	if int(cycleCount) == 255 {
-		action.PlaybackPacu(filename, 9999999, int(delay), "EMG")
+		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
 		priority.ResumeEmgPara = priority.BroadcastResumeParas{FileName: filename, Count: 99999999, Delay: int(delay), BroadcastType: "EMG"}
 	} else {
-		action.PlaybackPacu(filename, int(cycleCount), int(delay), "EMG")
+		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
 	}
 }
 
@@ -262,26 +259,26 @@ func AnnStop(data [4]byte) {
 		}
 	case 0x04:
 		if priority.RunningType == "EMG" {
-			action.HangupRunningTask("") //STOP EMG
+			action.HangupRunningTask("AnnStop") //STOP EMG
 		}
 	case 0x07:
 		if priority.RunningType == "SPC" {
-			action.HangupRunningTask("") //STOP SPC
+			action.HangupRunningTask("AnnStop") //STOP SPC
 		}
 	case 0x08:
 		if priority.RunningType == "STN" {
-			action.HangupRunningTask("") //STOP STN
+			action.HangupRunningTask("AnnStop") //STOP STN
 		}
 	case 0x09:
 		if priority.RunningType == "CHK" {
-			action.HangupRunningTask("") //STOP CHK
+			action.HangupRunningTask("AnnStop") //STOP CHK
 		}
 	case 0x0a:
 		if priority.RunningType == "VOL" {
-			action.HangupRunningTask("") //STOP VOL
+			action.HangupRunningTask("AnnStop") //STOP VOL
 		}
 	default:
-		action.HangupRunningTask("")
+		action.HangupRunningTask("AnnStop")
 	}
 }
 
@@ -294,9 +291,9 @@ func DcsAnn(data []byte) {
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 
 	if int(cycleCount) == 255 {
-		action.PlaybackPacu(filename, 9999999, int(delay), "DCS")
+		action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
 	} else {
-		action.PlaybackPacu(filename, int(cycleCount), int(delay), "DCS")
+		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
 	}
 }
 
@@ -312,7 +309,7 @@ func ToneTest(data []byte) {
 
 	switch check {
 	case 0x01: //start
-		action.PlaybackPacu(filename, int(cycleCount), int(delay), "VOL")
+		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
 
 	case 0x02: //stop
 
@@ -334,7 +331,7 @@ func SelfCheck(data []byte) {
 	switch check {
 	case 0x01: //start
 
-		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
+		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
 	case 0x02: //stop
 
 		//Pa status report
@@ -385,10 +382,10 @@ func AlarmHandleICP(data []byte) {
 		//NotifyPaiu(exten, "answer")
 		priority.ICPAnswer = 1
 		lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
-		if active.CabNum == "1" && active.Actived {
+		if active.ActivedCab == "1" {
 			action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
 			//goto ami event ConfbridgeJoin, ICP answer PAD
-		} else if active.CabNum == "8" && active.Actived {
+		} else if active.ActivedCab == "8" {
 			action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
 			//goto ami event ConfbridgeJoin, ICP answer PAD
 		}
@@ -445,10 +442,10 @@ func AlarmHandleTMS(data []byte) {
 		priority.ICPAnswer = 1
 		lfshook.NewLogger().Logger.Infof("================TMS Answer PAD:%s===PACU:%s==========", exten, PacuNum)
 		if action.ExtenStatus(PacuNum) == "Idle" {
-			if active.CabNum == "1" && active.Actived {
+			if active.ActivedCab == "1" {
 				action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
 				//goto ami event BridgeEnter, ICP8 whisper ICP1
-			} else if active.CabNum == "8" && active.Actived {
+			} else if active.ActivedCab == "8" {
 				action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
 				//goto ami event BridgeEnter, ICP1 whisper ICP8
 			}
@@ -516,7 +513,7 @@ func AlarmHoldResetAll(handler byte) {
 
 	//hangup running task
 	if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-TMS" {
-		action.HangupRunningTask("") //Reset PAD ALL
+		action.HangupRunningTask("AlarmHoldResetAll") //Reset PAD ALL
 		priority.CleanPriorityTag()
 	}
 }