فهرست منبع

报警器打断之后再转OCC的顺序问题修正,pad超时时间取值更新

root 3 هفته پیش
والد
کامیت
ce3f94ac32

+ 10 - 35
internal/app/ami/action/call.go

@@ -8,7 +8,6 @@ import (
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
-	"sort"
 	"strings"
 	"sync"
 	"time"
@@ -151,22 +150,6 @@ func InterruptRunningTask(toRunTask string) string {
 		}
 	}
 
-	/*if toRunTask == "C2C" { //当司机对讲打断业务为PA/PAD-ICP/PAD-TMS时,检测是否有EMG和CPA存在,存在则恢复播放
-		if taskName == "PA" || taskName == "PAD-ICP" || taskName == "PAD-TMS" {
-			//check resume
-			taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
-			if ok {
-				if taskName == "EMG" {
-					EMGConfbridgeReinvite(task.ConfbridgeID)
-				} else if taskName == "CPA" {
-					if CPAConfbridgeReinvite(task.ConfbridgeID) {
-						alstatus.PaStatus("", "CPA", "start")
-					}
-				}
-			}
-		}
-	}*/
-
 	utils.LoggerDebug.Printf("InterruptRunningTask  RunningTask:%+v", taskName)
 	//lfshook.NewLogger().Infof("InterruptRunningTask RunningTask:%+v  ", task)
 	//same type return
@@ -434,7 +417,7 @@ func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
 		"Variable": fmt.Sprintf("CAB=%s", callType),
 		"async":    "true",
 	}
-	lfshook.NewLogger().Infof("================dial action %+v", action)
+	//lfshook.NewLogger().Infof("================dial action %+v", action)
 	res, _, err := AminInstance.Send(action)
 	if err != nil {
 		lfshook.NewLogger().Errorf("%+v", err)
@@ -593,7 +576,7 @@ func SetPadTimer() {
 	}
 	if res.Calls != "0" {
 
-		utils.LoggerDebug.Printf("PAD SetPadTimer Set QueueTimer timeout 30s !")
+		utils.LoggerDebug.Printf("PAD SetPadTimer Set QueueTimer timeout %ds !", active.PADTimeout)
 		//active.SetTimer = true
 		//lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
 		if active.QueueTimer != nil {
@@ -622,7 +605,7 @@ func SetPadTimer() {
 			}
 
 			if res.Calls == "0" { // OCC queue empty
-				resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
+				/*resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
 				if err != nil {
 					lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
 					return
@@ -635,26 +618,18 @@ func SetPadTimer() {
 
 					for _, caller := range resCaller.Entrys {
 						priority.ICPAnswer = 0
-						//lfshook.NewLogger().Infof("====SetPadTimer==QueueTimer==2=")
-						//lfshook.NewLogger().Infof("Q300==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 _, ret := range alstatus.PadQueues {
+					//utils.LoggerDebug.Printf("PAD to OCC exten:%s", ret.Exten)
+					priority.ICPAnswer = 0
+					//order by pos
+					RedirectInQueue(ret.Exten, "0301", "queues-occ", ret.Exten) // redirect All ICP-PAD redirect to OCC queue
+					time.Sleep(time.Millisecond * 100)
 				}
-
-				//==============test info =====================
-				/*
-					time.Sleep(2 * time.Second)
-					occque, err1 := QueueStatus("0301", "") // check ICP queue, get entries
-					if err1 != nil {
-						lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
-						return
-					}
-
-					for _, caller := range occque.Entrys {
-						lfshook.NewLogger().Infof("Q301==SetPadTimer==Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
-					}*/
 			}
 		})
 	}

+ 9 - 3
internal/app/ami/action/index.go

@@ -10,7 +10,6 @@ import (
 	"pbx-api-gin/internal/pkg/configs"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
-	"sort"
 	"strings"
 	"time"
 
@@ -463,7 +462,7 @@ func HandleAMI(event map[string]string) {
 
 		if utils.IsPAIU(event["CallerIDNum"]) { // PAD hangup, check if PAD all end, send PAD end status
 
-			utils.LoggerDebug.Printf("===event:=====%+v======", event)
+			//utils.LoggerDebug.Printf("===event:=====%+v======", event)
 			number := strings.Split(strings.Split(event["Channel"], "-")[0], "/")[1]
 
 			//lfshook.NewLogger().Infof("===hangup PAD ===NUM:%s=================listAllTask:%+v===", number, priority.RegistryTask.ListAll())
@@ -602,7 +601,7 @@ func HandleAMI(event map[string]string) {
 					}
 
 					if res.Calls == "0" { // OCC queue empty
-						resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
+						/*resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
 						if err != nil {
 							lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
 							return
@@ -622,6 +621,13 @@ func HandleAMI(event map[string]string) {
 								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 _, ret := range alstatus.PadQueues {
+							priority.ICPAnswer = 0
+							//order by pos
+							RedirectInQueue(ret.Exten, "0301", "queues-occ", ret.Exten) // redirect All ICP-PAD redirect to OCC queue
+							time.Sleep(time.Millisecond * 100)
 						}
 					}
 				})

+ 2 - 2
internal/app/stc/broadcast/stc-broadcast.go

@@ -403,7 +403,7 @@ func processPacket(packet []byte) {
 		AlarmHoldResetAll(packet[8]) // reset all pad
 
 	case 0x0c: // Set PAD timeout
-		//lfshook.NewLogger().Logger.Infof("==type 0x0c===Get data from STC ====%x", packet)
+		//lfshook.NewLogger().Logger.Infof("==type PADTimeout 0x0c===Get data from STC ====%x", packet)
 		PadTimeOutSetting(packet[8:]) // timeout setting
 
 		getInfofromSTC(packet[8:])
@@ -479,7 +479,7 @@ func processPacket(packet []byte) {
 
 func PadTimeOutSetting(data []byte) {
 
-	Seconds := data[7]
+	Seconds := data[0]
 	if Seconds != 0 {
 		active.PADTimeout = int(Seconds)
 		//lfshook.NewLogger().Logger.Infof("=========Set PAD Timeout seconds to %d ! ============", active.PADTimeout)

+ 47 - 0
internal/app/stc/sendstatus/status.go

@@ -7,8 +7,46 @@ import (
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/pkg/utils"
+	"time"
 )
 
+type PADQueue struct {
+	Exten      string    `json:"exten"`
+	ActiveTime time.Time `json:"activeTime"`
+}
+
+var PadQueues []PADQueue
+
+// 删除某个报警器
+func removeAllByExten(queues []PADQueue, target string) []PADQueue {
+	result := make([]PADQueue, 0, len(queues))
+	for _, q := range queues {
+		if q.Exten != target {
+			result = append(result, q)
+		}
+	}
+	return result
+}
+
+// 添加报警器
+func addExtenToQueue(queues []PADQueue, target string) []PADQueue {
+
+	var padInfo = PADQueue{Exten: target, ActiveTime: time.Now()}
+
+	for _, q := range queues {
+		if q.Exten == target {
+			return queues
+		}
+	}
+	queues = append(queues, padInfo)
+	return queues
+}
+
+// 初始化pad队列
+func init() {
+	PadQueues = make([]PADQueue, 0)
+}
+
 func SendToStc(conn net.Conn, data []byte) {
 
 	_, err := conn.Write(data)
@@ -71,6 +109,15 @@ func AlarmStatus(exten string, status string) {
 		protocol.Data[2] = 0
 	}
 
+	//将pad存储到队列中
+	if protocol.Data[2] == 0x03 { //排队状态
+		PadQueues = addExtenToQueue(PadQueues, exten)
+		utils.LoggerDebug.Printf("PAD:%s add to queue", exten)
+	} else if protocol.Data[2] == 0x01 { //空闲状态
+		utils.LoggerDebug.Printf("PAD:%s del from queue", exten)
+		PadQueues = removeAllByExten(PadQueues, exten)
+	}
+
 	encoded, errEn := protocol.Encode()
 	if errEn != nil {
 		fmt.Println("Encode error:", errEn)