dujunchen 3 달 전
부모
커밋
1f5f8cd83d
6개의 변경된 파일540개의 추가작업 그리고 169개의 파일을 삭제
  1. 169 21
      internal/app/ami/action/call.go
  2. 298 119
      internal/app/ami/action/index.go
  3. 15 2
      internal/app/stc/active/index.go
  4. 27 5
      internal/app/stc/broadcast/stc-broadcast.go
  5. 24 22
      internal/app/stc/priority/index.go
  6. 7 0
      pkg/utils/utils.go

+ 169 - 21
internal/app/ami/action/call.go

@@ -8,7 +8,6 @@ import (
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 	"sort"
-	"strconv"
 	"strings"
 	"time"
 )
@@ -19,6 +18,8 @@ var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "242
 
 var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
 
+var Speakers = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181", "2311", "2381"}
+
 // Function triggered before no cab occupied signal interrupt
 func InActiveHangup() {
 	if active.ActivedCab == "" {
@@ -35,16 +36,6 @@ func InActiveHangup() {
 	}
 }
 
-// check EMG resume
-func CheckEmgResume() {
-	/*
-		time.AfterFunc(2*time.Second, func() {
-			if priority.CheckPriority("EMG") || priority.RunningType == "C2C" {
-				PlaybackPacu(strconv.Quote(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)
@@ -102,7 +93,7 @@ func HangupAllExcept(caller string) {
 // Hangup all ICP
 func HangupRunningTask(toRunTask string) {
 
-	lfshook.NewLogger().Infof("===HangupRunningTask=toRuntask=%s====   RunningTask:%s===", toRunTask, priority.RunningType)
+	lfshook.NewLogger().Infof("===HangupRunningTask=toRuntask=%s====   RunningTask:%s===chan:%s", toRunTask, priority.RunningType, priority.RunningPATaskChan)
 
 	//same type return
 	if toRunTask == priority.RunningType {
@@ -113,13 +104,28 @@ func HangupRunningTask(toRunTask string) {
 		}
 	}
 
+	//pad all  reset
 	if toRunTask == "AlarmHoldResetAll" {
-		Hangup(priority.RunningPATaskChan)
+		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
+	//}
+
 	if priority.RunningPATaskChan != "" {
 
 		if priority.RunningType == "C2C" { // Interrupt C2C task running,
@@ -158,7 +164,7 @@ func HangupRunningTask(toRunTask string) {
 
 						number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
 						active.NotifyPaiu(number, "hold")
-						HangupAllLocalChan()
+						//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)
@@ -186,7 +192,7 @@ func HangupRunningTask(toRunTask string) {
 				}
 				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.Microsecond * 200)
+					time.Sleep(time.Millisecond * 100)
 				}
 
 				//2. Hangup connected PAD
@@ -201,7 +207,9 @@ func HangupRunningTask(toRunTask string) {
 
 		default:
 			lfshook.NewLogger().Infof("===HangupRunningTask=default=== ")
-			Hangup(priority.RunningPATaskChan)
+			if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
+				Hangup(priority.RunningPATaskChan)
+			}
 			priority.CleanPriorityTag()
 		}
 	}
@@ -232,8 +240,10 @@ func HangupAllLocalChan() {
 	if err != nil {
 		lfshook.NewLogger().Errorf("CoreShowChannels %+v", err)
 	}
+
 	for _, ret := range chans {
-		if strings.Contains(ret.Channel, "Local") {
+		if strings.Contains(ret.Channel, "Local") && !strings.Contains(ret.Channel, "0502@default") {
+			lfshook.NewLogger().Infof("HangupAllLocalChan=====hangup========= %+v", ret)
 			Hangup(ret.Channel)
 		}
 	}
@@ -403,7 +413,7 @@ func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
 
 func SetPadTimer() {
 
-	toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey(priority.InterruptedPad)) // 获取之前打断的报警优先级
+	toRunpriority := priority.GetPriorityByKey(priority.InterruptedPad) // 获取之前打断的报警优先级
 	lfshook.NewLogger().Infof("==SetPadTimer====runing:%d==toRun:%d=", priority.RunningTypePriority, toRunpriority)
 
 	if priority.RunningTypePriority < toRunpriority || priority.RunningTypePriority == 0 {
@@ -436,11 +446,11 @@ func SetPadTimer() {
 
 					for _, caller := range resCaller.Entrys {
 						priority.ICPAnswer = 0
-						lfshook.NewLogger().Infof("====SetPadTimer==QueueTimer==2=")
-						lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
+						//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.Microsecond * 500)                                            //200 ms delay
+						time.Sleep(time.Millisecond * 100)                                            //200 ms delay
 					}
 				}
 			})
@@ -449,6 +459,7 @@ func SetPadTimer() {
 }
 
 func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
+
 	action := map[string]string{
 		"Action":     "ConfbridgeKick",
 		"Conference": confnum,
@@ -459,9 +470,146 @@ func ConfbridgeKick(confnum, channel string) (res map[string]string, err error)
 	if err != nil {
 		return nil, err
 	}
+	lfshook.NewLogger().Infof("=======ConfbridgeKick==%+v", res)
+
 	if res["Response"] != "Success" {
 		return nil, errors.New(res["Message"])
 	}
 
 	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"])
+		}
+
+		for _, confChan := range chans {
+			lfshook.NewLogger().Infof("======CPAConfbridgeKick==1=%+v", confChan)
+			if !strings.Contains(confChan, "PJSIP/1481") {
+				ConfbridgeKick(confnum, confChan)
+			}
+		}
+		return res, nil
+	}
+*/
+
+func CPAConfbridgeReinvite(confID string) {
+	lfshook.NewLogger().Infof("=====CPAConfbridgeReinvite==")
+
+	for _, ext := range Speakers {
+		ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
+	}
+}
+
+func EMGConfbridgeKick(confnum string) (res map[string]string, err error) {
+	lfshook.NewLogger().Infof("=====EMGConfbridgeKick==%s", confnum)
+	chans, err := ConfbridgeList(confnum)
+	if err != nil {
+		return nil, errors.New(res["Message"])
+	}
+
+	for _, confChan := range chans {
+		lfshook.NewLogger().Infof("====EMGConfbridgeKick==1=%+v", confChan)
+		if !strings.Contains(confChan, "0502@default") {
+			ConfbridgeKick(confnum, confChan)
+		}
+	}
+	return res, nil
+}
+
+func EMGConfbridgeReinvite(confID string) {
+	lfshook.NewLogger().Infof("=======EMGConfbridgeReinvite==")
+	time.Sleep(time.Millisecond * 800)
+	for _, ext := range Speakers {
+		ConfbridgeReinvite(ext, "call-speakers-emg", confID)
+	}
+
+}
+
+func ConfbridgeList(confnum string) (chans []string, err error) {
+
+	action := map[string]string{
+		"Action":     "ConfbridgeList",
+		"Conference": confnum,
+	}
+
+	res, events, err := AminInstance.Send(action)
+	if err != nil {
+		return nil, err
+	}
+	lfshook.NewLogger().Infof("===ConfbridgeList=res=%+v", res)
+
+	if res["Response"] == "Success" {
+		for _, event := range events {
+			if event.Data["Event"] == "ConfbridgeList" {
+				//lfshook.NewLogger().Infof("=======ConfbridgeList==%+v", event)
+				chans = append(chans, event.Data["Channel"])
+			}
+		}
+		return chans, nil
+	} else {
+		return nil, errors.New(res["Message"])
+	}
+}
+
+func ConfbridgeReinvite(src, context, confID string) {
+
+	if ExtenStatus(src) != "Idle" {
+		//lfshook.NewLogger().Infof("===============ext:%s==!Idle===========", src)
+		return
+	}
+
+	chanel := fmt.Sprintf("Local/%s@%s", src, context)
+	action := map[string]string{
+		"Action":   "Originate",
+		"Channel":  chanel,
+		"Exten":    "000",
+		"Context":  "confbridge-join",
+		"CallerID": fmt.Sprintf("%s<%s>", "", ""),
+		"Priority": "1",
+		"Variable": fmt.Sprintf("CBID=%s", confID),
+		"async":    "true",
+	}
+
+	lfshook.NewLogger().Infof("dial action %+v", action)
+	res, _, err := AminInstance.Send(action)
+	if err != nil {
+		lfshook.NewLogger().Errorf("%+v", err)
+	}
+	lfshook.NewLogger().Info(res)
+}
+
+func ICPConfbridgeReinvite(confID, paType string) {
+
+	switch paType {
+	case "PAD-OCC":
+		go DialICP("8", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("8", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "CPA":
+		go DialICP("2", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("2", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "EMG":
+		go DialICP("3", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("3", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "SPC":
+		go DialICP("6", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("6", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "STN":
+		go DialICP("4", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("4", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "DCS":
+		go DialICP("5", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("5", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "CHK":
+		go DialICP("10", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("10", "2381", "confbridge-join", confID, "8") //ICP8---call
+	case "VOL":
+		go DialICP("11", "2311", "confbridge-join", confID, "1") //ICP1---call
+		go DialICP("11", "2381", "confbridge-join", confID, "8") //ICP8---call
+
+	}
+}

+ 298 - 119
internal/app/ami/action/index.go

@@ -80,7 +80,7 @@ func HandleAMI(event map[string]string) {
 					}
 					for _, caller := range resCaller.Entrys {
 						lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
-						time.Sleep(time.Microsecond * 100)
+						time.Sleep(time.Millisecond * 100)
 						RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
 					}
 
@@ -113,7 +113,7 @@ func HandleAMI(event map[string]string) {
 
 								number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
 								active.NotifyPaiu(number, "hold")
-								HangupAllLocalChan()
+								//HangupAllLocalChan()
 
 							} else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
 								lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
@@ -123,7 +123,9 @@ func HandleAMI(event map[string]string) {
 					}
 					priority.InterruptedPad = priority.RunningType
 					HangupAllLocalChan()
-					Hangup(priority.RunningPATaskChan)
+					if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
+						Hangup(priority.RunningPATaskChan)
+					}
 					priority.CleanPriorityTag()
 					//HangupRunningTask("C2C")
 				} else if priority.RunningType == "PAD-OCC" {
@@ -138,14 +140,16 @@ func HandleAMI(event map[string]string) {
 		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
+					lfshook.NewLogger().Infof("=====UserEvent===event======PA start=======")
 					HangupRunningTask("PA") //PA interrupt other
+					priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.ManuPa)
 				} else {
 					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
 				}
@@ -178,7 +182,6 @@ func HandleAMI(event map[string]string) {
 				if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" || priority.RunningType == "PA" {
 					HangupRunningTask("C2C")
 					//Hangup the other ICP
-
 				} else {
 					lfshook.NewLogger().Infof("========CabCab  hangup other one====caller %s", event["CallerIDNum"])
 					if event["CallerIDNum"] == "2311" {
@@ -187,6 +190,7 @@ func HandleAMI(event map[string]string) {
 						Hangup("2311")
 					}
 				}
+				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
 			} else { // hangup caller; C2C start failed
 				lfshook.NewLogger().Infof("========CabCab  hangup caller====%s", event["CallerIDNum"])
 				Hangup(event["CallerIDNum"])
@@ -295,13 +299,14 @@ func HandleAMI(event map[string]string) {
 	case "Hangup":
 
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
-
 		//OCC answer PAD, hangup, redirect the next PAD to OCC
 		if utils.IsIO(event["CallerIDNum"]) && (event["ConnectedLineNum"] == "ano1" || event["ConnectedLineNum"] == "ano8") && event["Context"] == "default" {
 			lfshook.NewLogger().Infof("====Hangup OCC-PAD=====%+v", event)
 			// OCC hangup detected, hangup other running channels
 			HangupAllLocalChan()
-			Hangup(priority.RunningPATaskChan)
+			if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
+				Hangup(priority.RunningPATaskChan)
+			}
 
 			res, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
 			if res.Calls == "0" {             //OCC queue is empty
@@ -310,13 +315,25 @@ func HandleAMI(event map[string]string) {
 				priority.OCCAnswer = 0
 				priority.PADOccStart = 0
 
-				if priority.ResumeEmgPara.FileName != "" {
-					time.Sleep(time.Second)
-					CheckEmgResume()
+				if active.EMGCONFID != "" {
+					priority.RunningType = "EMG"
+					priority.RunningTypePriority = active.InfoEMG.Priority
+					priority.RunningPATaskChan = active.InfoEMG.RunChannel
+
+					time.Sleep(time.Millisecond * 300)
+					active.ICPCONBID = active.EMGCONFID
+					EMGConfbridgeReinvite(active.EMGCONFID)
+					return
+				}
+
+				if active.ICPCONBID != "" {
+					ConfbridgeKick(active.ICPCONBID, "all")
+					active.ICPCONBID = ""
 				}
 				break
 			} else { //OCC queue is not empty
 				//	HangupAllLocalChan()
+				time.Sleep(time.Millisecond * 300)
 				lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
 				if active.ActivedCab == "1" && ExtenStatus("1411") == "Idle" { //check active and OCC status
 					time.Sleep(time.Second)
@@ -386,14 +403,21 @@ func HandleAMI(event map[string]string) {
 						priority.PADStart = 0
 
 						priority.CleanPriorityTag()
-
-						if active.CONBID != "" {
-							ConfbridgeKick(active.CONBID, "all")
+						if active.EMGCONFID != "" {
+							priority.RunningType = "EMG"
+							priority.RunningTypePriority = active.InfoEMG.Priority
+							priority.RunningPATaskChan = active.InfoEMG.RunChannel
+							time.Sleep(time.Millisecond * 300)
+							active.ICPCONBID = active.EMGCONFID
+							EMGConfbridgeReinvite(active.EMGCONFID)
+							return
+						}
+						if active.ICPCONBID != "" {
+							ConfbridgeKick(active.ICPCONBID, "all")
+							active.ICPCONBID = ""
 						}
 					}
-					/*if priority.ResumeEmgPara.FileName != "" {
-						CheckEmgResume()
-					}*/
+
 					priority.ICPAnswer = 0
 					priority.OCCAnswer = 0
 					break
@@ -419,7 +443,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, _ := strconv.Atoi(priority.GetPriorityByKey("PAD-ICP"))
+				toRunpriority := priority.GetPriorityByKey("PAD-ICP")
 
 				//PAD press key
 				lfshook.NewLogger().Infof("===QueueCallerJoin===runing:%d=====toRun:=%d==Status:%s", priority.RunningTypePriority, toRunpriority, event["ChannelStateDesc"])
@@ -449,7 +473,7 @@ func HandleAMI(event map[string]string) {
 								lfshook.NewLogger().Infof("====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.Microsecond * 500)                                            //200 ms delay
+								time.Sleep(time.Millisecond * 100)                                            //200 ms delay
 							}
 						}
 					})
@@ -468,7 +492,8 @@ func HandleAMI(event map[string]string) {
 				HangupRunningTask("PAD-OCC") //PAD-OCC interrupt other
 				priority.OCCAnswer = 1
 
-				if active.ActivedCab == "1" /* && ExtenStatus("1411") == "Idle" */ { //check active and OCC status
+				time.Sleep(time.Millisecond * 300)
+				if active.ActivedCab == "1" && ExtenStatus("1411") == "Idle" { //check active and OCC status
 					/*if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
@@ -482,7 +507,7 @@ func HandleAMI(event map[string]string) {
 					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
 					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1")                     // PACUs dial OCC1
 
-				} else if active.ActivedCab == "8" /*&& ExtenStatus("1481") == "Idle" */ {
+				} else if active.ActivedCab == "8" && ExtenStatus("1481") == "Idle" {
 					/*if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
@@ -512,7 +537,14 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "EMG"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.EMG)
-				active.CONBID = event["Conference"]
+				//active.ICPCONBID = event["Conference"]
+				//active.ICPCONBTYP = "EMG"
+				active.EMGCONFID = event["Conference"]
+				//================================
+				active.InfoEMG.RunChannel = event["Channel"]
+				active.InfoEMG.Priority = priority.RunningTypePriority
+				active.InfoEMG.RunType = "EMG"
+
 				alstatus.PaStatus("", "EMG", "start")
 				return
 			}
@@ -522,7 +554,8 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "SPC"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.SPC)
-				active.CONBID = event["Conference"]
+				active.ICPCONBID = event["Conference"]
+				active.ICPCONBTYP = "SPC"
 				alstatus.PaStatus("", "SPC", "start")
 				return
 			}
@@ -532,7 +565,8 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "DCS"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.DCS)
-				active.CONBID = event["Conference"]
+				active.ICPCONBID = event["Conference"]
+				active.ICPCONBTYP = "DCS"
 				alstatus.PaStatus("", "DCS", "start")
 				return
 			}
@@ -542,7 +576,8 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "STN"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.STN)
-				active.CONBID = event["Conference"]
+				active.ICPCONBID = event["Conference"]
+				active.ICPCONBTYP = "STN"
 				alstatus.PaStatus("", "STN", "start")
 				return
 			}
@@ -552,7 +587,8 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "CHK"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CHK)
-				active.CONBID = event["Conference"]
+				active.ICPCONBID = event["Conference"]
+				active.ICPCONBTYP = "CHK"
 				alstatus.PaStatus("", "CHK", "start")
 				return
 			}
@@ -562,7 +598,8 @@ func HandleAMI(event map[string]string) {
 				priority.RunningType = "VOL"
 				//Pa status report
 				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.VOL)
-				active.CONBID = event["Conference"]
+				active.ICPCONBID = event["Conference"]
+				active.ICPCONBTYP = "VOL"
 				alstatus.PaStatus("", "VOL", "start")
 				return
 			}
@@ -570,25 +607,34 @@ func HandleAMI(event map[string]string) {
 
 		//get confbridge id for join back to confbridge
 		if event["Context"] == "pad-page-occ-icp" && utils.IsPAIU(event["CallerIDNum"]) {
-			active.CONBID = event["Conference"]
-		} else if event["Context"] == "cpa-rule" && utils.IsIO(event["CallerIDNum"]) {
-			active.CONBID = event["Conference"]
+			active.ICPCONBID = event["Conference"] //pad-occ
 		}
 
 		//Send PA start msg to STC
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
-			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
+
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.ManuPa)
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "PA"
+			active.ICPCONBID = event["Conference"] //cpa
+			active.ICPCONBTYP = "PA"
 			break
 		} else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
-			lfshook.NewLogger().Infof("====CPA status:%s=====", "start")
+
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CPA)
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
 			priority.RunningPATaskChan = event["Channel"]
 			priority.RunningType = "CPA"
+			//active.ICPCONBID = event["Conference"] //cpa icp
+			//active.ICPCONBTYP = "CPA"
+			active.CPACONFID = event["Conference"] //cpa
+
+			//=====================================
+			active.InfoCPA.RunChannel = event["Channel"]
+			active.InfoCPA.Priority = priority.RunningTypePriority
+			active.InfoCPA.RunType = "CPA"
+
 			return
 		}
 
@@ -636,85 +682,148 @@ func HandleAMI(event map[string]string) {
 	case "ConfbridgeLeave":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
+
 			SetPadTimer()
-			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			lfshook.NewLogger().Infof("====active.EMGCONFID:%s ====active.ICPCONBID:=%s", active.EMGCONFID, active.ICPCONBID)
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 		} else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
-			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
+
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 			//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		} else if event["CallerIDName"] == "EMG" && event["Exten"] == "0502" { // EMG broadcast hangup
+
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "EMG", "end")
-			priority.ResumeEmgPara = priority.BroadcastResumeParas{}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
-			}
+
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
+
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "STN", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
+
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "DCS", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
+
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "SPC", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "CHK", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 		} else if event["CallerIDName"] == "VOL" && event["Exten"] == "0513" {
 			SetPadTimer()
 			priority.CleanPriorityTag()
 			alstatus.PaStatus(event["CallerIDName"], "VOL", "end")
-			if priority.ResumeEmgPara.FileName != "" {
-				CheckEmgResume()
+
+			if active.EMGCONFID != "" {
+				priority.RunningType = "EMG"
+				priority.RunningTypePriority = active.InfoEMG.Priority
+				priority.RunningPATaskChan = active.InfoEMG.RunChannel
+				time.Sleep(time.Millisecond * 300)
+				active.ICPCONBID = active.EMGCONFID
+				EMGConfbridgeReinvite(active.EMGCONFID)
+				return
 			}
-			if active.CONBID != "" {
-				ConfbridgeKick(active.CONBID, "all")
+
+			if active.ICPCONBID != "" {
+				ConfbridgeKick(active.ICPCONBID, "all")
+				active.ICPCONBID = ""
 			}
 		}
 
@@ -734,31 +843,67 @@ func HandleAMI(event map[string]string) {
 
 			lfshook.NewLogger().Infof("===%s======%s", event["Event"], priority.RunningType)
 			//ICPs go back to confbridge
-			switch priority.RunningType {
-			case "PAD-OCC":
-				go DialICP("8", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("8", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "CPA":
-				go DialICP("2", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("2", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "EMG":
-				go DialICP("3", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("3", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "SPC":
-				go DialICP("6", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("6", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "STN":
-				go DialICP("4", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("4", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "DCS":
-				go DialICP("5", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("5", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "CHK":
-				go DialICP("10", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("10", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "VOL":
-				go DialICP("11", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("11", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			//ICPConfbridgeReinvite(active.ICPCONBID, active.ICPCONBTYP)
+
+			time.Sleep(time.Millisecond * 300)
+			//check cpa & emg & opa confbridge
+			if active.CPACONFID != "" && active.EMGCONFID != "" && priority.RunningTypePriority != 0 {
+				if priority.GetPriorityByKey("CPA") < priority.GetPriorityByKey("EMG") && priority.GetPriorityByKey("CPA") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+					active.CPACONFID = ""
+				} else if priority.GetPriorityByKey("EMG") < priority.GetPriorityByKey("CPA") && priority.GetPriorityByKey("EMG") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+					active.EMGCONFID = ""
+				} else if priority.RunningTypePriority < priority.GetPriorityByKey("EMG") && priority.GetPriorityByKey("CPA") > priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+					active.ICPCONBID = ""
+					active.ICPCONBTYP = ""
+				}
+
+				//check cpa & emg confbridge
+			} else if active.CPACONFID != "" && active.EMGCONFID != "" {
+				if priority.GetPriorityByKey("CPA") < priority.GetPriorityByKey("EMG") {
+					ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+					active.CPACONFID = ""
+				} else {
+					ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+					active.EMGCONFID = ""
+				}
+
+				//check  emg & opa confbridge
+			} else if active.EMGCONFID != "" && priority.RunningTypePriority != 0 {
+				if priority.GetPriorityByKey("EMG") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+					active.EMGCONFID = ""
+				} else {
+					ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+					active.ICPCONBID = ""
+					active.ICPCONBTYP = ""
+				}
+
+				//check  cpa & opa confbridge
+			} else if active.CPACONFID != "" && priority.RunningTypePriority != 0 {
+				if priority.GetPriorityByKey("CPA") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+					active.CPACONFID = ""
+				} else {
+					ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+					active.ICPCONBID = ""
+					active.ICPCONBTYP = ""
+				}
+			} else if active.CPACONFID != "" {
+
+				ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+				active.CPACONFID = ""
+			} else if active.EMGCONFID != "" {
+
+				ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+				active.EMGCONFID = ""
+			} else if priority.RunningTypePriority != 0 {
+
+				ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+				active.ICPCONBID = ""
+				active.ICPCONBTYP = ""
 			}
 		}
 
@@ -767,42 +912,76 @@ func HandleAMI(event map[string]string) {
 		//Cab Cab end
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
 			SetPadTimer()
-
+			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 			priority.RunningTypePriority = priority.TmpRunningTypePriority
-			priority.TmpRunningTypePriority = 0
 			priority.RunningType = priority.TmpRunningType
 
-			//ICPs go back to confbridge
-			switch priority.TmpRunningType {
-			case "PAD-OCC":
-				go DialICP("8", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("8", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "CPA":
-				go DialICP("2", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("2", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "EMG":
-				go DialICP("3", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("3", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "SPC":
-				go DialICP("6", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("6", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "STN":
-				go DialICP("4", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("4", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "DCS":
-				go DialICP("5", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("5", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "CHK":
-				go DialICP("10", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("10", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
-			case "VOL":
-				go DialICP("11", "2311", "confbridge-join", active.CONBID, "1") //ICP1---call
-				go DialICP("11", "2381", "confbridge-join", active.CONBID, "8") //ICP8---call
+			time.Sleep(time.Millisecond * 300)
+			//check cpa & emg & opa confbridge
+			if active.CPACONFID != "" && active.EMGCONFID != "" && priority.RunningTypePriority != 0 {
+				if priority.GetPriorityByKey("CPA") < priority.GetPriorityByKey("EMG") && priority.GetPriorityByKey("CPA") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+					active.CPACONFID = ""
+				} else if priority.GetPriorityByKey("EMG") < priority.GetPriorityByKey("CPA") && priority.GetPriorityByKey("EMG") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+					active.EMGCONFID = ""
+				} else if priority.RunningTypePriority < priority.GetPriorityByKey("EMG") && priority.GetPriorityByKey("CPA") > priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+					active.ICPCONBID = ""
+					active.ICPCONBTYP = ""
+				}
+
+				//check cpa & emg confbridge
+			} else if active.CPACONFID != "" && active.EMGCONFID != "" {
+				if priority.GetPriorityByKey("CPA") < priority.GetPriorityByKey("EMG") {
+					ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+					active.CPACONFID = ""
+				} else {
+					ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+					active.EMGCONFID = ""
+				}
+
+				//check  emg & opa confbridge
+			} else if active.EMGCONFID != "" && priority.RunningTypePriority != 0 {
+				if priority.GetPriorityByKey("EMG") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+					active.EMGCONFID = ""
+				} else {
+					ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+					active.ICPCONBID = ""
+					active.ICPCONBTYP = ""
+				}
+
+				//check  cpa & opa confbridge
+			} else if active.CPACONFID != "" && priority.RunningTypePriority != 0 {
+				if priority.GetPriorityByKey("CPA") < priority.RunningTypePriority {
+					ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+					active.CPACONFID = ""
+				} else {
+					ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+					active.ICPCONBID = ""
+					active.ICPCONBTYP = ""
+				}
+			} else if active.CPACONFID != "" {
+
+				ICPConfbridgeReinvite(active.CPACONFID, "CPA")
+				active.CPACONFID = ""
+			} else if active.EMGCONFID != "" {
+
+				ICPConfbridgeReinvite(active.EMGCONFID, "EMG")
+				active.EMGCONFID = ""
+			} else if priority.RunningTypePriority != 0 {
+
+				ICPConfbridgeReinvite(active.ICPCONBID, priority.RunningType)
+				active.ICPCONBID = ""
+				active.ICPCONBTYP = ""
 			}
 
+			//check other broadcast confbridge
+			//ICPs go back to confbridge
 			priority.TmpRunningType = ""
+			priority.TmpRunningTypePriority = 0
 
-			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 		}
 
 	case "ExtensionStatus":

+ 15 - 2
internal/app/stc/active/index.go

@@ -15,8 +15,21 @@ var Master = false
 
 var QueueTimer *time.Timer = nil
 
-//ICP join PAD-OCC confbridge id
-var CONBID = ""
+// 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) {

+ 27 - 5
internal/app/stc/broadcast/stc-broadcast.go

@@ -12,7 +12,9 @@ import (
 	"pbx-api-gin/internal/app/stc/priority"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
+	"pbx-api-gin/pkg/utils"
 	"strconv"
+	"strings"
 	"sync"
 	"time"
 )
@@ -216,7 +218,9 @@ func processPacket(packet []byte) {
 			action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
 
 			AlarmHandleTMS(packet)
-			active.QueueTimer.Stop()
+			if active.QueueTimer != nil {
+				active.QueueTimer.Stop()
+			}
 		} else {
 			alstatus.PaStatus("", "PAD-TMS", "refuse")
 		}
@@ -231,7 +235,10 @@ func processPacket(packet []byte) {
 		if priority.CheckPriority("PAD-ICP") {
 
 			action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
-			active.QueueTimer.Stop()
+			if active.QueueTimer != nil {
+				active.QueueTimer.Stop()
+			}
+
 			AlarmHandleICP(packet) //
 		} else {
 			alstatus.PaStatus("", "PAD-ICP", "refuse")
@@ -278,6 +285,12 @@ func Active(data [2]byte) {
 		}
 	}
 
+	if active.Master && !utils.IsAsteriskOn() {
+		utils.ExecCmd("/etc/init.d/asterisk", "start")
+	} else if !active.Master && utils.IsAsteriskOn() {
+		utils.ExecCmd("/etc/init.d/asterisk", "stop")
+	}
+
 	switch Signal {
 	case 0:
 
@@ -322,7 +335,6 @@ func EmgMsg(data []byte) {
 
 	if int(cycleCount) == 255 {
 		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(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
 	}
@@ -340,6 +352,11 @@ func AnnStop(data [4]byte) {
 		}
 	case 0x04:
 		if priority.RunningType == "EMG" {
+			if active.EMGCONFID != "" {
+				action.ConfbridgeKick(active.EMGCONFID, "all")
+				active.EMGCONFID = ""
+			}
+
 			action.HangupRunningTask("AnnStop") //STOP EMG
 		}
 	case 0x07:
@@ -480,14 +497,19 @@ func AlarmHandleICP(data []byte) {
 		if err != nil {
 			lfshook.NewLogger().Info(err)
 		}
-		action.HangupAllLocalChan()
+		if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
+			action.Hangup(priority.RunningPATaskChan)
+		}
+		action.HangupICP()
 
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
 		lfshook.NewLogger().Logger.Infof("=============STC== Hangup PAD=============== ")
 		action.Hangup(exten) //Pad
-		action.HangupAllLocalChan()
 		action.HangupICP()
+		if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
+			action.Hangup(priority.RunningPATaskChan)
+		}
 		priority.CleanPriorityTag()
 	}
 }

+ 24 - 22
internal/app/stc/priority/index.go

@@ -26,6 +26,7 @@ var PADOccStart = 0
 var PAStart = 0
 
 var InterruptedPad = ""
+var filePath = "/etc/asterisk/priority.conf"
 
 type BroadcastResumeParas struct {
 	FileName      string `json:"filename"`
@@ -34,8 +35,6 @@ type BroadcastResumeParas struct {
 	BroadcastType string `json:"broadcastType"`
 }
 
-var ResumeEmgPara BroadcastResumeParas
-
 type PriorityAll struct {
 	ManuPa string `json:"manualPa"`
 	CabCab string `json:"cabCab"`
@@ -54,7 +53,7 @@ type PriorityAll struct {
 var Priority PriorityAll
 
 func GetPriority() {
-	filePath := "/etc/asterisk/priority.conf"
+
 	_, err := os.Stat(filePath)
 	if err != nil {
 		logrus.Error(err)
@@ -80,36 +79,43 @@ func GetPriority() {
 	Priority.VOL = iniFile.Section("general").Key("VOL").Value()
 }
 
-func GetPriorityByKey(key string) string {
+func GetPriorityByKey(key string) int {
 
+	ret := ""
 	switch key {
 	case "VOL":
-		return Priority.VOL
+		ret = Priority.VOL
 	case "CHK":
-		return Priority.CHK
+		ret = Priority.CHK
 	case "STN":
-		return Priority.STN
+		ret = Priority.STN
 	case "DCS":
-		return Priority.DCS
+		ret = Priority.DCS
 	case "SPC":
-		return Priority.SPC
+		ret = Priority.SPC
 	case "EMG":
-		return Priority.EMG
+		ret = Priority.EMG
 	case "CPA":
-		return Priority.CPA
+		ret = Priority.CPA
 	case "PAD-OCC":
-		return Priority.PADOCC
+		ret = Priority.PADOCC
 	case "PAD-TMS":
-		return Priority.PADTMS
+		ret = Priority.PADTMS
 	case "PAD-ICP":
-		return Priority.PADICP
+		ret = Priority.PADICP
 	case "CabCab":
-		return Priority.CabCab
+		ret = Priority.CabCab
 	case "ManuPa":
-		return Priority.ManuPa
+		ret = Priority.ManuPa
 	default:
-		return ""
+		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
@@ -127,11 +133,7 @@ func CheckPriority(runType string) bool {
 	}
 
 	//Get the to run priority number in the config file
-	ret, err := strconv.Atoi(GetPriorityByKey(runType))
-	if err != nil {
-		lfshook.NewLogger().Logger.Infof("=========Check Pri GetPriorityByKey err:%+v", err)
-		return false
-	}
+	ret := GetPriorityByKey(runType)
 
 	//special same priority number task return true
 	if ret == RunningTypePriority {

+ 7 - 0
pkg/utils/utils.go

@@ -172,3 +172,10 @@ func IndexOf(sliceID []string, value string) int {
 	}
 	return -1
 }
+
+func IsAsteriskOn() bool {
+	//res, _, _ := ExecCmd("ps", "-e", "|grep asterisk")
+
+	//return res != ""
+	return true
+}