浏览代码

优化报警器状态反馈机制

dujunchen 2 周之前
父节点
当前提交
82ac1ada1e
共有 2 个文件被更改,包括 43 次插入37 次删除
  1. 34 36
      internal/app/ami/action/index.go
  2. 9 1
      internal/app/stc/broadcast/stc-broadcast.go

+ 34 - 36
internal/app/ami/action/index.go

@@ -8,7 +8,6 @@ import (
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 	"strconv"
-	"strings"
 	"time"
 
 	"github.com/sirupsen/logrus"
@@ -93,39 +92,9 @@ func HandleAMI(event map[string]string) {
 			}
 		}
 
-	case "Newchannel":
-		//lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0300" { // Alarm dial queue start; PAD dialing
-			if priority.PADStart == 0 {
-				priority.PADStart = 1
-				alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
-			}
-
-			alstatus.AlarmStatus(event["CallerIDNum"], "dial")
-		}
-
 	case "Hangup":
 
 		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
-			res1, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
-			if res.Calls == "0" && res1.Calls == "0" {
-				//priority.CleanPriorityTag()
-				//HangupAllLocalChan()
-				if priority.PADStart == 1 {
-					alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
-					priority.PADStart = 0
-				}
-				/*if priority.ResumeEmgPara.FileName != "" {
-					CheckEmgResume()
-				}*/
-				priority.ICPAnswer = 0
-				priority.OCCAnswer = 0
-				break
-			}
-		}
 
 		//OCC answer PAD, hangup, redirect the next PAD to OCC
 		if (event["CallerIDNum"] == "ano1" || event["CallerIDNum"] == "ano8") && utils.IsIO(event["ConnectedLineNum"]) && utils.IsPAIU(event["CallerIDName"]) {
@@ -140,7 +109,6 @@ func HandleAMI(event map[string]string) {
 					time.Sleep(time.Second)
 					CheckEmgResume()
 				}
-
 				break
 			} else { //OCC queue is not empty
 				HangupAllLocalChan()
@@ -149,14 +117,38 @@ func HandleAMI(event map[string]string) {
 					time.Sleep(time.Second)
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDName"], "1") // PACUs dial OCC1
 					//goto ConfbridgeJoin, OCC1 answer PAD
+					break
 				} 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
+					break
 				}
 			}
 		}
 
+		if utils.IsPAIU(event["CallerIDNum"]) { // PAD hangup, check if PAD all end, send PAD end status
+
+			res, _ := QueueStatus("0300", "")  // check ICP queue ,if empty PAD end
+			res1, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
+
+			lfshook.NewLogger().Infof("==calls:%s===calls1:%s====", res.Calls, res1.Calls)
+			if res.Calls == "0" && res1.Calls == "0" {
+				//priority.CleanPriorityTag()
+				//HangupAllLocalChan()
+				if priority.PADStart == 1 {
+					alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
+					priority.PADStart = 0
+				}
+				/*if priority.ResumeEmgPara.FileName != "" {
+					CheckEmgResume()
+				}*/
+				priority.ICPAnswer = 0
+				priority.OCCAnswer = 0
+				break
+			}
+		}
+
 	case "QueueCallerJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if priority.OCCAnswer == 1 && event["Queue"] == "0300" { //New PAD Goto the OCC queue in the first time, if OCC answered
@@ -175,10 +167,10 @@ 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
-				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=")
+					//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)
@@ -217,7 +209,10 @@ func HandleAMI(event map[string]string) {
 					if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
-						alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
+						if priority.PADStart == 0 {
+							alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
+							priority.PADStart = 1
+						}
 					}
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDNum"], "1") // PACUs dial OCC1
 					//Goto event=ConfbridgeJoin;OCC answer PAD
@@ -225,7 +220,10 @@ func HandleAMI(event map[string]string) {
 					if priority.PADOccStart == 0 {
 						alstatus.OccPad("start")
 						priority.PADOccStart = 1
-						alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
+						if priority.PADStart == 0 {
+							alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
+							priority.PADStart = 1
+						}
 					}
 					Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", event["CallerIDNum"], "8") // PACUs dial OCC8
 					//Goto event=ConfbridgeJoin;OCC answer PAD

+ 9 - 1
internal/app/stc/broadcast/stc-broadcast.go

@@ -139,6 +139,7 @@ func processPacket(packet []byte) {
 	case 0x0e: //TMS answer PAD
 		if priority.CheckPriority("PAD-TMS") {
 			action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
+
 			AlarmHandleTMS(packet)
 			active.QueueTimer.Stop()
 		} else {
@@ -381,6 +382,10 @@ func AlarmHandleICP(data []byte) {
 	case 0x01: //answer(ICP+Alarm+PACU)
 		//NotifyPaiu(exten, "answer")
 		priority.ICPAnswer = 1
+		if priority.PADStart == 0 {
+			alstatus.PaStatus(exten, "PAD", "start")
+			priority.PADStart = 1
+		}
 		lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
 		if active.ActivedCab == "1" {
 			action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
@@ -438,7 +443,10 @@ func AlarmHandleTMS(data []byte) {
 		//PACU---call---->ICP1
 		//PAD---->Chanspy(WEq)-->ICP1
 		//ICP2--->spy(Eq)---->PAD
-
+		if priority.PADStart == 0 {
+			alstatus.PaStatus(exten, "PAD", "start")
+			priority.PADStart = 1
+		}
 		priority.ICPAnswer = 1
 		lfshook.NewLogger().Logger.Infof("================TMS Answer PAD:%s===PACU:%s==========", exten, PacuNum)
 		if action.ExtenStatus(PacuNum) == "Idle" {