Selaa lähdekoodia

1.激活信号改变对当前任务和即将执行的任务操作;2.循环播放的EMG广播在打断之后恢复播放

dujunchen 3 tuntia sitten
vanhempi
commit
fde42f960a

+ 24 - 0
internal/app/ami/action/call.go

@@ -6,6 +6,7 @@ import (
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 	"strings"
+	"time"
 )
 
 var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "2425", "2431", "2432", "2433", "2434", "2435", "2441", "2442", "2443", "2444",
@@ -14,6 +15,29 @@ var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "242
 
 var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
 
+// Function triggered before no cab occupied signal interrupt
+func InActiveHangup() {
+
+	switch priority.RunningType {
+	case "PA":
+		HangupRunningTask("")
+	case "CPA":
+		HangupRunningTask("")
+	case "VOL":
+		HangupRunningTask("")
+	}
+}
+
+// check EMG resume
+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)
+		}
+	})
+}
+
 // Hangup 挂断指定分机或通道
 func Hangup(channel string) {
 	lfshook.NewLogger().Infof("hangup extensions/channel %s", channel)

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

@@ -32,7 +32,7 @@ func HandleAMI(event map[string]string) {
 			alstatus.SendRecordFile(event["FILENAME"], event["RecordType"])
 
 		} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
-			//check active signal  before PA
+			//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" {
@@ -50,6 +50,14 @@ func HandleAMI(event map[string]string) {
 
 			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
 				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" {
+						Hangup(event["CallerIDNum"])
+					}
+
 					//hangup others if priority is higher
 					if priority.RunningType != "C2C" {
 						HangupRunningTask("CPA") //CPA interrupt other
@@ -92,26 +100,33 @@ func HandleAMI(event map[string]string) {
 		if event["CallerIDName"] == "EMG" && event["Exten"] == "0502" { // EMG broadcast hangup
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "EMG", "end")
+			priority.ResumeEmgPara = priority.BroadcastResumeParas{}
 
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "STN", "end")
+			CheckEmgResume()
 
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "DCS", "end")
+			CheckEmgResume()
 
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "SPC", "end")
+			CheckEmgResume()
 
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "CHK", "end")
+			CheckEmgResume()
 
-		} else if event["CallerIDName"] == "VOL" && event["Exten"] == "0510" {
+		} else if event["CallerIDName"] == "VOL" && event["Exten"] == "0513" {
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "VOL", "end")
+			CheckEmgResume()
+
 		}
 
 	case "Hangup":
@@ -123,6 +138,7 @@ func HandleAMI(event map[string]string) {
 			if res.Calls == "0" {
 				priority.CleanPriorityTag()
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
+				CheckEmgResume()
 				//priority.ICPAnswer = 0
 				break
 			}
@@ -134,6 +150,7 @@ func HandleAMI(event map[string]string) {
 			if res.Calls == "0" {
 				priority.CleanPriorityTag()
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
+				CheckEmgResume()
 				//priority.ICPAnswer = 0
 				break
 			}
@@ -145,6 +162,7 @@ func HandleAMI(event map[string]string) {
 			if res.Calls == "0" {
 				priority.CleanPriorityTag()
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
+				CheckEmgResume()
 				//priority.ICPAnswer = 0
 				break
 			}
@@ -157,6 +175,7 @@ func HandleAMI(event map[string]string) {
 			if res.Calls == "0" {             //OCC queue is empty
 				priority.CleanPriorityTag()
 				alstatus.OccPad("end")
+				CheckEmgResume()
 				//priority.OCCAnswer = 0
 				break
 			} else { //OCC queue is not empty
@@ -188,12 +207,14 @@ func HandleAMI(event map[string]string) {
 					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("===QueueStatus==%+v", err)
+							lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+							return
 						}
 
 						for _, caller := range resCaller.Entrys {
@@ -261,7 +282,7 @@ func HandleAMI(event map[string]string) {
 			priority.RunningType = "SPC"
 			//Pa status report
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.SPC)
-			alstatus.PaStatus("", "EMG", "start")
+			alstatus.PaStatus("", "SPC", "start")
 
 		case "DCS":
 			alstatus.PaStatus(event["CallerIDNum"], "DCS", "start")
@@ -269,7 +290,7 @@ func HandleAMI(event map[string]string) {
 			priority.RunningType = "DCS"
 			//Pa status report
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.DCS)
-			alstatus.PaStatus("", "EMG", "start")
+			alstatus.PaStatus("", "DCS", "start")
 
 		case "STN":
 			alstatus.PaStatus(event["CallerIDNum"], "STN", "start")
@@ -287,7 +308,7 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CHK)
 			alstatus.PaStatus("", "CHK", "start")
 
-		case "VOL":
+		case "VOL": // tone-test
 			alstatus.PaStatus(event["CallerIDNum"], "VOL", "start")
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "VOL"
@@ -359,11 +380,15 @@ func HandleAMI(event map[string]string) {
 			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
+			CheckEmgResume()
+
 		}
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
+			CheckEmgResume()
+
 		}
 
 	case "DialEnd":

+ 21 - 12
internal/app/stc/broadcast/stc-broadcast.go

@@ -85,7 +85,7 @@ func processPacket(packet []byte) {
 		break
 
 	case 0x02: // STN
-		if priority.CheckPriority("STN") {
+		if priority.CheckPriority("STN") && active.Actived {
 			action.HangupRunningTask("STN") //STN interrupt other
 			StationAnn(packet)
 		} else {
@@ -93,7 +93,7 @@ func processPacket(packet []byte) {
 		}
 
 	case 0x05: // SPC
-		if priority.CheckPriority("SPC") {
+		if priority.CheckPriority("SPC") && active.Actived {
 			action.HangupRunningTask("SPC") //SPC interrupt other
 			SpecialAnn(packet)
 		} else {
@@ -101,7 +101,7 @@ func processPacket(packet []byte) {
 		}
 
 	case 0x06: // EMG
-		if priority.CheckPriority("EMG") {
+		if priority.CheckPriority("EMG") && active.Actived {
 			action.HangupRunningTask("EMG") //EMG interrupt other
 			EmgMsg(packet)
 		} else {
@@ -111,7 +111,7 @@ func processPacket(packet []byte) {
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
 
 	case 0x08: // DCS
-		if priority.CheckPriority("DCS") {
+		if priority.CheckPriority("DCS") && active.Actived {
 			action.HangupRunningTask("DCS") //DCS interrupt other
 			DcsAnn(packet)
 		} else {
@@ -119,17 +119,22 @@ func processPacket(packet []byte) {
 		}
 
 	case 0x09: // SELF CHECK
-		if priority.CheckPriority("CHK") {
+		if priority.CheckPriority("CHK") && active.Actived {
 			action.HangupRunningTask("CHK") //CHK interrupt other
 			SelfCheck(packet)
 		} else {
 			alstatus.PaStatus("", "CHK", "refuse")
 		}
 
-	case 0x10: // VOLUME Adjust
-		if priority.CheckPriority("VOL") {
+	case 0x10: // Tone-test
+		if priority.CheckPriority("VOL") && active.Actived {
+			//check active signal  before VOL
+			if !active.Actived {
+				break
+			}
+
 			action.HangupRunningTask("VOL") //VOL interrupt other
-			VolumeAdjust(packet)
+			ToneTest(packet)
 		} else {
 			alstatus.PaStatus("", "VOL", "refuse")
 		}
@@ -193,6 +198,7 @@ func Active(data [1]byte) {
 
 		//lfshook.NewLogger().Logger.Infof("=================Inactive==================")
 		active.Actived = false
+		action.InActiveHangup()
 
 	case 1:
 
@@ -201,6 +207,7 @@ func Active(data [1]byte) {
 			active.Actived = true
 		} else {
 			active.Actived = false
+			action.InActiveHangup()
 		}
 
 	case 8:
@@ -210,6 +217,7 @@ func Active(data [1]byte) {
 			active.Actived = true
 		} else {
 			active.Actived = false
+			action.InActiveHangup()
 		}
 	}
 }
@@ -240,6 +248,7 @@ func EmgMsg(data []byte) {
 
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(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")
 	}
@@ -293,8 +302,8 @@ func DcsAnn(data []byte) {
 	}
 }
 
-// 调音广播
-func VolumeAdjust(data []byte) {
+// tone-test广播
+func ToneTest(data []byte) {
 
 	check := data[8]
 	delay := data[9]
@@ -309,7 +318,7 @@ func VolumeAdjust(data []byte) {
 
 	case 0x02: //stop
 
-		alstatus.PaStatus("", "VOL", "end")
+		//alstatus.PaStatus("", "VOL", "end")
 		action.HangupAllExcept("")
 	}
 }
@@ -332,7 +341,7 @@ func SelfCheck(data []byte) {
 
 		//Pa status report
 		priority.CleanPriorityTag()
-		alstatus.PaStatus("", "CHK", "end")
+		//alstatus.PaStatus("", "CHK", "end")
 		action.HangupAllExcept("")
 	}
 }

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

@@ -16,6 +16,15 @@ var RunningType = ""
 var SpecialVoice = 0
 var RunningPATaskChan = ""
 
+type BroadcastResumeParas struct {
+	FileName      string `json:"filename"`
+	Count         int    `json:"count"`
+	Delay         int    `json:"delay"`
+	BroadcastType string `json:"broadcastType"`
+}
+
+var ResumeEmgPara BroadcastResumeParas
+
 type PriorityAll struct {
 	ManuPa string `json:"manualPa"`
 	CabCab string `json:"cabCab"`
@@ -61,19 +70,35 @@ func GetPriority() {
 }
 
 func GetPriorityByKey(key string) string {
-	filePath := "/etc/asterisk/priority.conf"
-	_, err := os.Stat(filePath)
-	if err != nil {
-		logrus.Error(err)
-		return ""
-	}
-	iniFile, err := ini.Load(filePath)
-	if err != nil {
-		logrus.Error(err)
+
+	switch key {
+	case "VOL":
+		return Priority.VOL
+	case "CHK":
+		return Priority.CHK
+	case "STN":
+		return Priority.STN
+	case "DCS":
+		return Priority.DCS
+	case "SPC":
+		return Priority.SPC
+	case "EMG":
+		return Priority.EMG
+	case "CPA":
+		return Priority.CPA
+	case "PAD-OCC":
+		return Priority.PADOCC
+	case "PAD-TMS":
+		return Priority.PADTMS
+	case "PAD-ICP":
+		return Priority.PADICP
+	case "CabCab":
+		return Priority.CabCab
+	case "ManuPa":
+		return Priority.ManuPa
+	default:
 		return ""
 	}
-
-	return iniFile.Section("general").Key(key).Value()
 }
 
 // check priority , if the running priority is lowwer than the to run priority

+ 1 - 1
internal/app/stc/sendstatus/status.go

@@ -127,7 +127,7 @@ func PaStatus(src string, patype string, operation string) {
 		protocol.Data[1] = 0x08
 	case "CHK": //自检
 		protocol.Data[1] = 0x09
-	case "VOL": //音量调节
+	case "VOL": //音调条件
 		protocol.Data[1] = 0x0a
 	}