dujunchen 3 mesiacov pred
rodič
commit
f64fc9de04

+ 160 - 146
internal/app/ami/action/call.go

@@ -23,16 +23,10 @@ var Speakers = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171",
 // Function triggered before no cab occupied signal interrupt
 func InActiveHangup() {
 	if active.ActivedCab == "" {
-		switch priority.RunningType {
-		case "PA":
-			HangupRunningTask("InActiveHangup")
-		case "CPA":
-			HangupRunningTask("InActiveHangup")
-		case "VOL":
-			HangupRunningTask("InActiveHangup")
-		case "PAD-OCC":
-			HangupRunningTask("InActiveHangup")
-		}
+		HangupTask("PA")
+		HangupTask("CPA")
+		HangupTask("VOL")
+		HangupTask("PAD-OCC")
 	}
 }
 
@@ -90,129 +84,144 @@ func HangupAllExcept(caller string) {
 	}
 }
 
-// Hangup all ICP
-func HangupRunningTask(toRunTask string) {
+// Hangup task
+func HangupTask(TaskName string) {
+
+	taskInfo, ok := priority.RegistryTask.Get(TaskName)
+	if ok {
+		HangupAllLocalChan()
+		ConfbridgeKick(taskInfo.ConfbridgeID, "all")
+		Hangup(taskInfo.RunChannel)
+	}
+}
 
-	lfshook.NewLogger().Infof("===HangupRunningTask=toRuntask=%s====   RunningTask:%s===chan:%s", toRunTask, priority.RunningType, priority.RunningPATaskChan)
+// interrupt the running task
+func InterruptRunningTask(toRunTask string) {
 
-	//same type return
-	if toRunTask == priority.RunningType {
+	taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask()
+	if !ok {
+		return
+	}
+
+	lfshook.NewLogger().Infof("===InterruptRunningTask=toRuntask=%s==RunningTask:%s===chan:%s", toRunTask, taskName, task.RunChannel)
 
+	//same type return
+	if toRunTask == taskName {
 		if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
-			lfshook.NewLogger().Infof("===HangupRunningTask=ret==== ")
+			lfshook.NewLogger().Infof("===InterruptRunningTask=ret==== ")
 			return
 		}
 	}
 
 	//pad all  reset
 	if toRunTask == "AlarmHoldResetAll" {
-		if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
-			Hangup(priority.RunningPATaskChan)
-		}
-		priority.CleanPriorityTag()
 		HangupAllLocalChan()
 		return
 	}
 
-	//kick EMG member
-	if active.EMGCONFID != "" {
-		EMGConfbridgeKick(active.EMGCONFID)
-		return
-	}
-
-	//kick CPA member
-	//if active.CPACONFID != "" {
-	//	CPAConfbridgeKick(active.CPACONFID)
-	//	return
-	//}
+	switch task.RunType {
+	case "CPA":
+		//kick CPA members
+		taskTmp, ok := priority.RegistryTask.Get("CPA")
+		if ok {
+			CPAConfbridgeKick(taskTmp.ConfbridgeID)
+		}
 
-	if priority.RunningPATaskChan != "" {
+	case "EMG":
+		//kick EMG members
+		taskTmp, ok := priority.RegistryTask.Get("EMG")
+		if ok {
+			EMGConfbridgeKick(taskTmp.ConfbridgeID)
+		}
 
-		if priority.RunningType == "C2C" { // Interrupt C2C task running,
-			if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
-				HangupICP()
-				//priority.CleanPriorityTag()
-			}
+	case "C2C": // Interrupt C2C task running,
+		if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
+			HangupICP()
+			return
 		}
 
-		switch priority.RunningType {
+	case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
+		priority.InterruptedPad = "PAD-ICP"
 
-		case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
-			priority.InterruptedPad = priority.RunningType
-			//just in case
-			if toRunTask == "C2C" { //deal in DTMF event
-				lfshook.NewLogger().Infof("===HangupRunningTask==C2C=return==== ")
-				return
-			}
+		lfshook.NewLogger().Infof("===InterruptRunningTask==hangup===PAD-ICP==%s==== ", task.RunType)
+		chans, err := CoreShowChannels()
+		if err != nil {
+			lfshook.NewLogger().Errorf("CoreShowChannels %+v", err)
+		}
 
-			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 {
+			// Redirect the connected PAD to 0300
+			if utils.IsPAIU(ret.CallerIDNum) {
+				if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
+					err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
+					if err != nil {
+						lfshook.NewLogger().Errorf("Redirect %+v", err)
+					}
+
+					number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
+					active.NotifyPaiu(number, "hold")
+					//HangupAllLocalChan()
+				}
 			}
+		}
 
-			//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", "queues-icp-redirect", "", "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)
-					}
+		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)
 				}
 			}
+		}
 
-			//2. hangup task channel (ICP + PACU)
-			lfshook.NewLogger().Infof("===HangupRunningTask=2. hangup task channel === ")
-			HangupAllLocalChan()
-			//HangupICP()
-			priority.CleanPriorityTag()
+		priority.RegistryTask.StopAndUnregister("PAD-ICP")
+		priority.RegistryTask.StopAndUnregister("PAD-TMS")
+		//2. hangup task channel (ICP + PACU)
+		lfshook.NewLogger().Infof("===InterruptRunningTask=2. hangup task channel === ")
+		HangupAllLocalChan()
+		HangupICP()
 
-		case "PAD-OCC": // Interrupt PAD-OCC task running,
+	case "PAD-OCC": // Interrupt PAD-OCC task running,
 
-			if toRunTask == "C2C" {
-				break
+		if toRunTask == "C2C" {
+			HangupICP()
+			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 {
-					lfshook.NewLogger().Infof("===QueueStatus==%+v", err)
-				}
-				for _, caller := range resCaller.Entrys {
-					go RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
-					time.Sleep(time.Millisecond * 100)
-				}
+		} else {
+			priority.InterruptedPad = "PAD-OCC"
+			priority.OCCAnswer = 0
 
-				//2. Hangup connected PAD
-				lfshook.NewLogger().Infof("===HangupRunningTask=Hangup connected PAD=== ")
-				Hangup(priority.RunningPATaskChan)
-
-				//3. Hangup OI & ICP
-				HangupIO()
-				HangupAllLocalChan()
-				priority.CleanPriorityTag()
+			resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
+			if err != nil {
+				lfshook.NewLogger().Infof("===QueueStatus==%+v", err)
 			}
-
-		default:
-			lfshook.NewLogger().Infof("===HangupRunningTask=default=== ")
-			if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
-				Hangup(priority.RunningPATaskChan)
+			for _, caller := range resCaller.Entrys {
+				lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
+				time.Sleep(time.Millisecond * 50)
+				RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
 			}
-			priority.CleanPriorityTag()
+
+			priority.RegistryTask.StopAndUnregister("PAD-OCC")
+			//2. Hangup connected PAD
+			lfshook.NewLogger().Infof("===InterruptRunningTask=Hangup connected PAD=== ")
+			Hangup(task.RunChannel)
+
+			//3. Hangup OI & ICP
+			HangupIO()
+			HangupAllLocalChan()
 		}
+
+	default:
+		lfshook.NewLogger().Infof("===InterruptRunningTask=default=== ")
+		//if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
+		//	Hangup(priority.RunningPATaskChan)
+		//}
+		Hangup(task.RunChannel)
+		ConfbridgeKick(task.ConfbridgeID, "all")
 	}
+
 }
 
 // Hangup all ICP
@@ -413,49 +422,56 @@ func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
 
 func SetPadTimer() {
 
-	toRunpriority := priority.GetPriorityByKey(priority.InterruptedPad) // 获取之前打断的报警优先级
-	lfshook.NewLogger().Infof("==SetPadTimer====runing:%d==toRun:%d=", priority.RunningTypePriority, toRunpriority)
+	toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) // 获取之前打断的报警优先级
+	//toRunpriority := priority.GetPriorityByKey("PAD-ICP")
 
-	if priority.RunningTypePriority < toRunpriority || priority.RunningTypePriority == 0 {
-
-		res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
-		if err != nil {
-			lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
+	_, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
+	if ok {
+		lfshook.NewLogger().Infof("==SetPadTimer====runing:%d==toRun:%d=", taskTmp.Priority, toRunPadpriority)
+		if taskTmp.Priority < toRunPadpriority { //higher priority task running ,do not set timer
 			return
 		}
-		if res.Calls != "0" {
+	}
+
+	res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
+	if err != nil {
+		lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
+		return
+	}
 
-			lfshook.NewLogger().Infof("==SetPadTimer==QueueTimer===1====")
-			active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
+	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
+			}
 
-				res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
+			if res.Calls == "0" { // OCC queue empty
+				resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
 				if err != nil {
-					lfshook.NewLogger().Infof("===OCC-QueueStatus==%+v", err)
+					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
+				})
 
-				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("==SetPadTimer==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.Millisecond * 100)                                            //200 ms delay
-					}
+				for _, caller := range resCaller.Entrys {
+					priority.ICPAnswer = 0
+					//lfshook.NewLogger().Infof("====SetPadTimer==QueueTimer==2=")
+					lfshook.NewLogger().Infof("==SetPadTimer==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.Millisecond * 100)                                            //200 ms delay
 				}
-			})
-		}
+			}
+		})
 	}
+
 }
 
 func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
@@ -479,23 +495,21 @@ func ConfbridgeKick(confnum, channel string) (res map[string]string, err error)
 	return res, nil
 }
 
-/*
-	func CPAConfbridgeKick(confnum string) (res map[string]string, err error) {
-		lfshook.NewLogger().Infof("=======CPAConfbridgeKick==%s", confnum)
-		chans, err := ConfbridgeList(confnum)
-		if err != nil {
-			return nil, errors.New(res["Message"])
-		}
+func CPAConfbridgeKick(confnum string) (res map[string]string, err error) {
+	lfshook.NewLogger().Infof("=======CPAConfbridgeKick==%s", confnum)
+	chans, err := ConfbridgeList(confnum)
+	if err != nil {
+		return nil, errors.New(res["Message"])
+	}
 
-		for _, confChan := range chans {
-			lfshook.NewLogger().Infof("======CPAConfbridgeKick==1=%+v", confChan)
-			if !strings.Contains(confChan, "PJSIP/1481") {
-				ConfbridgeKick(confnum, confChan)
-			}
+	for _, confChan := range chans {
+		lfshook.NewLogger().Infof("======CPAConfbridgeKick==1=%+v", confChan)
+		if !strings.Contains(confChan, "PJSIP/1481") {
+			ConfbridgeKick(confnum, confChan)
 		}
-		return res, nil
 	}
-*/
+	return res, nil
+}
 
 func CPAConfbridgeReinvite(confID string) {
 	lfshook.NewLogger().Infof("=====CPAConfbridgeReinvite==")

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 441 - 475
internal/app/ami/action/index.go


+ 0 - 16
internal/app/stc/active/index.go

@@ -15,22 +15,6 @@ var Master = false
 
 var QueueTimer *time.Timer = nil
 
-// ICP join PAD-OCC confbridge id
-var ICPCONBID = "" //for cab cab interrupt
-var ICPCONBTYP = ""
-
-var EMGCONFID = "" //for other broadcast interrupt
-var CPACONFID = "" //for CPA interrupt
-
-type TaskInfo struct {
-	RunChannel string `json:"runChannel"`
-	RunType    string `json:"runType"`
-	Priority   int    `json:"priority"`
-}
-
-var InfoEMG TaskInfo
-var InfoCPA TaskInfo
-
 // 挂断所有报警器
 func NotifyPaiu(Exten, Action string) {
 	url := ""

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

@@ -14,7 +14,6 @@ import (
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 	"strconv"
-	"strings"
 	"sync"
 	"time"
 )
@@ -159,7 +158,7 @@ func processPacket(packet []byte) {
 	case 0x02: // STN
 		if active.ActivedCab != "" {
 			if priority.CheckPriority("STN") {
-				action.HangupRunningTask("STN") //STN interrupt other
+				action.InterruptRunningTask("STN") //STN interrupt other
 				StationAnn(packet)
 			} else {
 				alstatus.PaStatus("", "STN", "refuse")
@@ -168,7 +167,7 @@ func processPacket(packet []byte) {
 	case 0x05: // SPC
 		if active.ActivedCab != "" {
 			if priority.CheckPriority("SPC") {
-				action.HangupRunningTask("SPC") //SPC interrupt other
+				action.InterruptRunningTask("SPC") //SPC interrupt other
 				SpecialAnn(packet)
 			} else {
 				alstatus.PaStatus("", "SPC", "refuse")
@@ -177,7 +176,7 @@ func processPacket(packet []byte) {
 	case 0x06: // EMG
 		if active.ActivedCab != "" {
 			if priority.CheckPriority("EMG") {
-				action.HangupRunningTask("EMG") //EMG interrupt other
+				action.InterruptRunningTask("EMG") //EMG interrupt other
 				EmgMsg(packet)
 			} else {
 				alstatus.PaStatus("", "EMG", "refuse")
@@ -189,7 +188,7 @@ func processPacket(packet []byte) {
 	case 0x08: // DCS
 		if active.ActivedCab != "" {
 			if priority.CheckPriority("DCS") {
-				action.HangupRunningTask("DCS") //DCS interrupt other
+				action.InterruptRunningTask("DCS") //DCS interrupt other
 				DcsAnn(packet)
 			} else {
 				alstatus.PaStatus("", "DCS", "refuse")
@@ -198,7 +197,7 @@ func processPacket(packet []byte) {
 	case 0x09: // SELF CHECK
 		if active.ActivedCab != "" {
 			if priority.CheckPriority("CHK") {
-				action.HangupRunningTask("CHK") //CHK interrupt other
+				action.InterruptRunningTask("CHK") //CHK interrupt other
 				SelfCheck(packet)
 			} else {
 				alstatus.PaStatus("", "CHK", "refuse")
@@ -207,7 +206,7 @@ func processPacket(packet []byte) {
 	case 0x0a: // Tone-test
 		if active.ActivedCab != "" {
 			if priority.CheckPriority("VOL") {
-				action.HangupRunningTask("VOL") //VOL interrupt other
+				action.InterruptRunningTask("VOL") //VOL interrupt other
 				ToneTest(packet)
 			} else {
 				alstatus.PaStatus("", "VOL", "refuse")
@@ -215,7 +214,7 @@ func processPacket(packet []byte) {
 		}
 	case 0x0e: //TMS answer PAD
 		if priority.CheckPriority("PAD-TMS") {
-			action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
+			action.InterruptRunningTask("PAD-TMS") //PAD-TMS interrupt other
 
 			AlarmHandleTMS(packet)
 			if active.QueueTimer != nil {
@@ -234,7 +233,7 @@ func processPacket(packet []byte) {
 	case 0x0d: // ICP answer PAD
 		if priority.CheckPriority("PAD-ICP") {
 
-			action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
+			action.InterruptRunningTask("PAD-ICP") //PAD-ICP interrupt other
 			if active.QueueTimer != nil {
 				active.QueueTimer.Stop()
 			}
@@ -343,40 +342,35 @@ func EmgMsg(data []byte) {
 // 停止指定类型广播
 func AnnStop(data [4]byte) {
 
-	//PaType := ""
-	lfshook.NewLogger().Logger.Infof("=AnnStop Type  %x", data[0])
+	lfshook.NewLogger().Logger.Infof("=========AnnStop Type  %x", data[0])
+
 	switch data[0] {
 	case 0x03:
-		if priority.RunningType == "DCS" {
-			action.HangupRunningTask("") //STOP DCS
-		}
+
+		action.HangupTask("DCS") //STOP DCS
+
 	case 0x04:
-		if priority.RunningType == "EMG" {
-			if active.EMGCONFID != "" {
-				action.ConfbridgeKick(active.EMGCONFID, "all")
-				active.EMGCONFID = ""
-			}
 
-			action.HangupRunningTask("AnnStop") //STOP EMG
-		}
+		action.HangupTask("EMG") //STOP EMG
+
 	case 0x07:
-		if priority.RunningType == "SPC" {
-			action.HangupRunningTask("AnnStop") //STOP SPC
-		}
+
+		action.HangupTask("SPC") //STOP SPC
+
 	case 0x08:
-		if priority.RunningType == "STN" {
-			action.HangupRunningTask("AnnStop") //STOP STN
-		}
+
+		action.HangupTask("STN") //STOP STN
+
 	case 0x09:
-		if priority.RunningType == "CHK" {
-			action.HangupRunningTask("AnnStop") //STOP CHK
-		}
+
+		action.HangupTask("CHK") //STOP CHK
+
 	case 0x0a:
-		if priority.RunningType == "VOL" {
-			action.HangupRunningTask("AnnStop") //STOP VOL
-		}
+
+		action.HangupTask("VOL") //STOP VOL
+
 	default:
-		action.HangupRunningTask("AnnStop")
+		action.InterruptRunningTask("")
 	}
 }
 
@@ -430,9 +424,6 @@ func SelfCheck(data []byte) {
 
 		action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
 	case 0x02: //stop
-
-		//Pa status report
-		//priority.CleanPriorityTag()
 		action.HangupAllExcept("")
 	}
 }
@@ -497,20 +488,16 @@ func AlarmHandleICP(data []byte) {
 		if err != nil {
 			lfshook.NewLogger().Info(err)
 		}
-		if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
-			action.Hangup(priority.RunningPATaskChan)
-		}
-		action.HangupICP()
+		action.InterruptRunningTask("")
+		//action.HangupICP()
 
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
 		lfshook.NewLogger().Logger.Infof("=============STC== Hangup PAD=============== ")
 		action.Hangup(exten) //Pad
-		action.HangupICP()
-		if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
-			action.Hangup(priority.RunningPATaskChan)
-		}
-		priority.CleanPriorityTag()
+		//action.HangupICP()
+
+		action.InterruptRunningTask("")
 	}
 }
 
@@ -575,23 +562,17 @@ func AlarmHandleTMS(data []byte) {
 		action.Hangup(exten) //Pad
 		action.HangupAllLocalChan()
 		action.HangupICP()
-		priority.CleanPriorityTag()
 	}
 }
 
 // 挂断所有报警器
 func AlarmHoldResetAll(handler byte) {
 
-	//all hold
-
 	//hangup all actived PAD
 	action.HangupAllPAD()
 
 	//hangup running task
-	if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-TMS" {
-		action.HangupRunningTask("AlarmHoldResetAll") //Reset PAD ALL
-		priority.CleanPriorityTag()
-	}
+	action.InterruptRunningTask("AlarmHoldResetAll") //Reset PAD ALL
 }
 
 /*

+ 77 - 96
internal/app/stc/priority/index.go

@@ -12,45 +12,43 @@ import (
 var ICPAnswer = 0
 var OCCAnswer = 0
 
-var RunningTypePriority = 0
-var RunningType = ""
-var RunningPATaskChan = ""
-
-var TmpRunningTypePriority = 0
-var TmpRunningType = ""
-
 var SpecialVoice = 0
 
 var PADStart = 0
 var PADOccStart = 0
-var PAStart = 0
 
 var InterruptedPad = ""
 var filePath = "/etc/asterisk/priority.conf"
 
-type BroadcastResumeParas struct {
-	FileName      string `json:"filename"`
-	Count         int    `json:"count"`
-	Delay         int    `json:"delay"`
-	BroadcastType string `json:"broadcastType"`
+type TaskInfo struct {
+	RunChannel   string `json:"runChannel"`
+	LocalChan    string `json:"localChan"`
+	RunType      string `json:"runType"`
+	Priority     int    `json:"priority"`
+	ConfbridgeID string `json:"confbridgeID"`
+	Running      bool
+}
+
+type TaskPriority struct {
+	Priority int `json:"priority"`
 }
 
-type PriorityAll struct {
-	ManuPa string `json:"manualPa"`
-	CabCab string `json:"cabCab"`
-	PADICP string `json:"padIcp"`
-	PADTMS string `json:"padTms"`
-	PADOCC string `json:"padOcc"`
-	CPA    string `json:"cpa"`
-	EMG    string `json:"emg"`
-	SPC    string `json:"spc"`
-	DCS    string `json:"dcs"`
-	STN    string `json:"stn"`
-	CHK    string `json:"chk"`
-	VOL    string `json:"vol"`
+type Tasks struct {
+	PA     TaskPriority `json:"pa"`
+	C2C    TaskPriority `json:"c2c"`
+	PADICP TaskPriority `json:"padicp"`
+	PADTMS TaskPriority `json:"padtms"`
+	PADOCC TaskPriority `json:"padocc"`
+	CPA    TaskPriority `json:"cpa"`
+	EMG    TaskPriority `json:"emg"`
+	SPC    TaskPriority `json:"spc"`
+	DCS    TaskPriority `json:"dcs"`
+	STN    TaskPriority `json:"stn"`
+	CHK    TaskPriority `json:"chk"`
+	VOL    TaskPriority `json:"vol"`
 }
 
-var Priority PriorityAll
+var AllTasks Tasks
 
 func GetPriority() {
 
@@ -65,116 +63,99 @@ func GetPriority() {
 		return
 	}
 
-	Priority.CHK = iniFile.Section("general").Key("CHK").Value()
-	Priority.STN = iniFile.Section("general").Key("STN").Value()
-	Priority.DCS = iniFile.Section("general").Key("DCS").Value()
-	Priority.SPC = iniFile.Section("general").Key("SPC").Value()
-	Priority.EMG = iniFile.Section("general").Key("EMG").Value()
-	Priority.CPA = iniFile.Section("general").Key("CPA").Value()
-	Priority.PADOCC = iniFile.Section("general").Key("PAD-OCC").Value()
-	Priority.PADTMS = iniFile.Section("general").Key("PAD-TMS").Value()
-	Priority.PADICP = iniFile.Section("general").Key("PAD-ICP").Value()
-	Priority.CabCab = iniFile.Section("general").Key("CabCab").Value()
-	Priority.ManuPa = iniFile.Section("general").Key("ManuPa").Value()
-	Priority.VOL = iniFile.Section("general").Key("VOL").Value()
+	AllTasks.CHK.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("CHK").Value())
+	AllTasks.STN.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("STN").Value())
+	AllTasks.DCS.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("DCS").Value())
+	AllTasks.SPC.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("SPC").Value())
+	AllTasks.EMG.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("EMG").Value())
+	AllTasks.CPA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("CPA").Value())
+	AllTasks.PADOCC.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PAD-OCC").Value())
+	AllTasks.PADTMS.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PAD-TMS").Value())
+	AllTasks.PADICP.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("PAD-ICP").Value())
+	AllTasks.C2C.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("CabCab").Value())
+	AllTasks.PA.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("ManuPa").Value())
+	AllTasks.VOL.Priority, _ = strconv.Atoi(iniFile.Section("general").Key("VOL").Value())
+
 }
 
 func GetPriorityByKey(key string) int {
 
-	ret := ""
 	switch key {
 	case "VOL":
-		ret = Priority.VOL
+		return AllTasks.VOL.Priority
 	case "CHK":
-		ret = Priority.CHK
+		return AllTasks.CHK.Priority
 	case "STN":
-		ret = Priority.STN
+		return AllTasks.STN.Priority
 	case "DCS":
-		ret = Priority.DCS
+		return AllTasks.DCS.Priority
 	case "SPC":
-		ret = Priority.SPC
+		return AllTasks.SPC.Priority
 	case "EMG":
-		ret = Priority.EMG
+		return AllTasks.EMG.Priority
 	case "CPA":
-		ret = Priority.CPA
+		return AllTasks.CPA.Priority
 	case "PAD-OCC":
-		ret = Priority.PADOCC
+		return AllTasks.PADOCC.Priority
 	case "PAD-TMS":
-		ret = Priority.PADTMS
+		return AllTasks.PADTMS.Priority
 	case "PAD-ICP":
-		ret = Priority.PADICP
+		return AllTasks.PADICP.Priority
 	case "CabCab":
-		ret = Priority.CabCab
+		return AllTasks.C2C.Priority
 	case "ManuPa":
-		ret = Priority.ManuPa
+		return AllTasks.PA.Priority
 	default:
-		ret = ""
-	}
-	retPriority, err := strconv.Atoi(ret)
-	if err != nil {
 		return 0
 	}
-
-	return retPriority
 }
 
 // check priority , if the running priority is lowwer than the to run priority
 func CheckPriority(runType string) bool {
-	//return true
-	lfshook.NewLogger().Logger.Infof("=========Check Pri runType:%s====RunningTypePriority:%d====SpecialVoice:%d========", runType, RunningTypePriority, SpecialVoice)
+
 	//Check special voice can not interrupt
 	if SpecialVoice == 1 {
 		return false
 	}
 
-	//No any runing task now
-	if RunningTypePriority == 0 {
-		return true
-	}
-
 	//Get the to run priority number in the config file
-	ret := GetPriorityByKey(runType)
+	toRunpriority := GetPriorityByKey(runType)
 
-	//special same priority number task return true
-	if ret == RunningTypePriority {
-		switch runType {
-		case "PAD-ICP":
-			return true
-		case "PAD-TMS":
+	runingtaskName, taskRuning, ok := RegistryTask.HighestPriorityRunningTask()
+	if ok {
+		lfshook.NewLogger().Logger.Infof("=====CheckPriority runType:%s======SpecialVoice:%d===toRunpriority:%d==runingtaskpri:%d===", runType, SpecialVoice, toRunpriority, taskRuning.Priority)
+		//if the running task priority is lowwer
+		if toRunpriority < taskRuning.Priority && toRunpriority != 0 {
 			return true
-			/*	case "VOL":
-					return true
-				case "CHK":
-					return true*/
+
+		} else if toRunpriority == taskRuning.Priority {
+
+			switch runType {
+			case "PAD-ICP":
+				return true
+			case "PAD-TMS":
+				return true
+				/*	case "VOL":
+						return true
+					case "CHK":
+						return true*/
+			}
 		}
-	}
 
-	//if the running task priority is lowwer
-	if ret < RunningTypePriority && ret != 0 {
-		return true
-	} else {
-		//C2C run together with other task except ..
-		if RunningType == "C2C" {
+		if runingtaskName == "C2C" {
 			if runType != "PA" && runType != "PAD-ICP" && runType != "PAD-TMS" && runType != "C2C" {
 				return true
 			}
 		} else if runType == "C2C" {
-			if RunningType != "PA" && RunningType != "PAD-ICP" && RunningType != "PAD-TMS" && RunningType != "C2C" {
+			if runingtaskName != "PA" && runingtaskName != "PAD-ICP" && runingtaskName != "PAD-TMS" && runingtaskName != "C2C" {
 				return true
 			}
 		}
-	}
-	return false
-}
 
-// Clean all priority tag
-func CleanPriorityTag() {
-	lfshook.NewLogger().Logger.Infof("=========CleanPriorityTag===============")
+	} else {
+		//No any runing task now
+		return true
+	}
 
-	ICPAnswer = 0
-	OCCAnswer = 0
-	RunningTypePriority = 0
-	RunningType = ""
-	SpecialVoice = 0
-	RunningPATaskChan = ""
+	return false
 }

+ 100 - 0
internal/app/stc/priority/task.go

@@ -0,0 +1,100 @@
+package priority
+
+import (
+	"sync"
+)
+
+// 全局导出变量:所有导入 pro 包的代码均可直接使用 pro.Registry
+var RegistryTask = NewTaskRegistry()
+
+// TaskRegistry:线程安全的任务注册表,仅保存 Running==true 的任务
+type TaskRegistry struct {
+	mu sync.RWMutex
+	m  map[string]TaskInfo // key: task name (e.g., "PA", "C2C", "DTMF")
+}
+
+// NewTaskRegistry 创建新注册表
+func NewTaskRegistry() *TaskRegistry {
+	return &TaskRegistry{
+		m: make(map[string]TaskInfo),
+	}
+}
+
+// Register 启动并注册一个任务(仅当 Running == true 时才存入)
+func (r *TaskRegistry) Register(name string, t TaskInfo) {
+	if !t.Running {
+		return // 不注册未运行的任务
+	}
+	r.mu.Lock()
+	defer r.mu.Unlock()
+	r.m[name] = t
+}
+
+// StopAndUnregister 标记任务为停止,并立即从注册表中删除(推荐在任务结束时调用)
+func (r *TaskRegistry) StopAndUnregister(name string) {
+	r.mu.Lock()
+	defer r.mu.Unlock()
+	delete(r.m, name)
+}
+
+// UpdateStatus 更新任务状态;若设为 false,则自动删除(满足你“任务结束即删除”的需求)
+func (r *TaskRegistry) UpdateStatus(name string, newStatus bool) {
+	r.mu.Lock()
+	defer r.mu.Unlock()
+
+	if !newStatus {
+		delete(r.m, name) // 自动清理:Running=false → 移除
+		return
+	}
+
+	// 若 newStatus == true,尝试更新或插入(需原 task info 完整)
+	if t, ok := r.m[name]; ok {
+		t.Running = true
+		r.m[name] = t
+	} else {
+		// 如果没有旧记录,但你要“重新启用”,需外部提供完整 TaskInfo → 建议用 Register()
+	}
+}
+
+// Get 获取指定任务(nil if not found or not running)
+func (r *TaskRegistry) Get(name string) (TaskInfo, bool) {
+	r.mu.RLock()
+	defer r.mu.RUnlock()
+	t, ok := r.m[name]
+	return t, ok && t.Running
+}
+
+// ListAll 返回所有当前运行中的任务副本(安全遍历)
+func (r *TaskRegistry) ListAll() []TaskInfo {
+	r.mu.RLock()
+	defer r.mu.RUnlock()
+	list := make([]TaskInfo, 0, len(r.m))
+	for _, t := range r.m {
+		if t.Running { // 冗余检查,确保一致性
+			list = append(list, t)
+		}
+	}
+	return list
+}
+
+// HighestPriorityRunningTask returns the task with smallest Priority value,
+// which means highest scheduling priority (e.g., Priority=0 > 1 > 10).
+// Returns (key, task, found). If no task exists, found is false.
+func (r *TaskRegistry) HighestPriorityRunningTask() (string, TaskInfo, bool) {
+
+	r.mu.RLock()
+	defer r.mu.RUnlock()
+
+	var bestKey string
+	var best TaskInfo
+	found := false
+
+	for key, task := range r.m {
+		if !found || task.Priority < best.Priority {
+			bestKey = key
+			best = task
+			found = true
+		}
+	}
+	return bestKey, best, found
+}