dujunchen 2 달 전
부모
커밋
1ccbb5e659

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

@@ -28,12 +28,22 @@ func InActiveHangup() {
 		HangupTask("CPA")
 		HangupTask("VOL")
 		HangupTask("PAD-OCC")
+	} else {
+		HangupTask("PA")
+		HangupTask("PAD-OCC")
+		HangupTask("CPA")
+		HangupTask("EMG")
+		HangupTask("SPC")
+		HangupTask("DCS")
+		HangupTask("STN")
+		HangupTask("CHK")
+		HangupTask("VOL")
 	}
 }
 
 // Hangup 挂断指定分机或通道
 func Hangup(channel string) {
-	lfshook.NewLogger().Infof("hangup extensions/channel %s", channel)
+	lfshook.NewLogger().Infof("Hangup extensions/channel :%s", channel)
 	if !utils.IsChannel(channel) {
 		channel = fmt.Sprintf(`/^(PJ)?SIP\/%s-.*$/`, channel)
 	}
@@ -42,7 +52,7 @@ func Hangup(channel string) {
 		"Action":  "hangup",
 		"Channel": channel,
 	}
-	lfshook.NewLogger().Infof("hangup action %+v", action)
+	//lfshook.NewLogger().Infof("hangup action :%+v", action)
 	if _, _, err := AminInstance.Send(action); err != nil {
 		lfshook.NewLogger().Errorf("Hangup %+v", err)
 	}
@@ -87,7 +97,22 @@ func HangupAllExcept(caller string) {
 
 // Hangup task
 func HangupTask(TaskName string) {
-	lfshook.NewLogger().Infof("HangupTask TaskName:%s ", TaskName)
+	lfshook.NewLogger().Infof("HangupTask Check TaskName:%s ", TaskName)
+
+	if TaskName == "PAD-OCC" {
+		resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
+		if err != nil {
+			lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
+			return
+		}
+		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
+		}
+
+	}
+
 	taskInfo, ok := priority.RegistryTask.Get(TaskName)
 	if ok {
 		HangupAllLocalChan()
@@ -103,7 +128,7 @@ func InterruptRunningTask(toRunTask string) {
 	var taskName string
 	var ok bool
 
-	lfshook.NewLogger().Infof("InterruptRunningTask toRuntask=%s RunningTask:%s ", toRunTask, taskName)
+	lfshook.NewLogger().Infof("InterruptRunningTask toRuntask:%s RunningTask:%s ", toRunTask, taskName)
 
 	if toRunTask != "PA" && toRunTask != "PAD-ICP" && toRunTask != "PAD-TMS" { // ignore C2C
 		taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask1()
@@ -317,7 +342,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)
@@ -478,6 +503,11 @@ func SetPadTimer() {
 		active.SetTimer = true
 		active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
 
+			//if both not active , return
+			if active.ActivedCab == "" {
+				return
+			}
+
 			res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
 			if err != nil {
 				lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)

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

@@ -388,6 +388,11 @@ func HandleAMI(event map[string]string) {
 				active.SetTimer = true
 				active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
 
+					//if both not active , return
+					if active.ActivedCab == "" {
+						return
+					}
+
 					res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
 					if err != nil {
 						lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
@@ -980,8 +985,10 @@ func HandleAMI(event map[string]string) {
 			} else if active.ActivedCab == "8" {
 				go RedirectInQueue(event["CallerIDName"], "2381", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP8
 				go Dial("0403", event["CallerIDName"], "call-pad-rule", "2311", "2311", "1")  //ICP1---call----PAD
+			} else if active.ActivedCab == "" {
+				go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
+				go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8")  //ICP8---call----PAD
 			}
-
 		} else if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0405" { // PAD connect ICP-TMS;PACU not available
 
 			//=============================
@@ -1009,7 +1016,7 @@ func StartAMI(connectOKCallBack func(), handleEvents []func(event map[string]str
 		Username: configs.ConfigGlobal.AsteriskAMIUser,
 		Password: configs.ConfigGlobal.AsteriskAMISecret,
 		LogLevel: logrus.ErrorLevel}
-	lfshook.NewLogger().Infof("ami setting: %+v", settings)
+	//lfshook.NewLogger().Infof("ami setting: %+v", settings)
 	AminInstance = amigo.New(settings, lfshook.NewLogger())
 	AminInstance.EventOn(func(payload ...interface{}) {
 		// lfshook.NewLogger().Infof("ami event on %+v", payload[0])
@@ -1023,7 +1030,7 @@ func StartAMI(connectOKCallBack func(), handleEvents []func(event map[string]str
 
 	})
 	AminInstance.ConnectOn(func(payload ...interface{}) {
-		lfshook.NewLogger().Infof("ami connect on %+v", payload[0])
+		//lfshook.NewLogger().Infof("ami connect on %+v", payload[0])
 		if payload[0] == pkg.Connect_OK {
 
 			connectOKCallBack()

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

@@ -18,6 +18,8 @@ import (
 	"time"
 )
 
+var tagLog = 0
+
 func HandleStcCmd(ctx context.Context, conn net.Conn) {
 
 	for {
@@ -72,9 +74,13 @@ func processPacket(packet []byte) {
 
 	//check if Master role
 	if !active.Master {
-		//lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
+		if tagLog == 0 {
+			lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data !=============")
+			tagLog = 1
+		}
 		return
 	}
+	tagLog = 0
 
 	switch packet[5] {
 	case 0x01: //heartbeat
@@ -236,15 +242,26 @@ func Active(data [2]byte) {
 
 	switch Signal {
 	case 0:
-		active.ActivedCab = ""
-		action.InActiveHangup()
+
+		if active.ActivedCab != "" {
+			active.ActivedCab = ""
+			action.InActiveHangup()
+		}
 
 	case 1:
-		active.ActivedCab = "1"
+		//active signal from 8 to 1
+		if active.ActivedCab == "8" || active.ActivedCab == "" {
+			active.ActivedCab = "1"
+			action.InActiveHangup()
+		}
 
 	case 8:
+		//active signal from 1 to 8
+		if active.ActivedCab == "1" || active.ActivedCab == "" {
+			active.ActivedCab = "8"
+			action.InActiveHangup()
+		}
 
-		active.ActivedCab = "8"
 	}
 }
 
@@ -485,6 +502,8 @@ func AlarmHandleTMS(data []byte) {
 			} else if active.ActivedCab == "8" {
 				action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
 				//goto ami event BridgeEnter, ICP1 whisper ICP8
+			} else if active.ActivedCab == "" { // No cab occupied
+				action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
 			}
 		} else {
 			action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs

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

@@ -110,7 +110,7 @@ func CreateConnection(RemoteCab string) (net.Conn, error) {
 				//lfshook.NewLogger().Logger.Infof("========Connect server err :%+v", err)
 				return nil, err
 			}
-			lfshook.NewLogger().Logger.Infof("Connect success :%s:%d", socket.RemoteAddr, socket.RemotePort)
+			lfshook.NewLogger().Logger.Infof("Connect success MC1:%s:%d", socket.RemoteAddr, socket.RemotePort)
 			return conn, nil
 		} else { //in cab 8
 			dialer := &net.Dialer{
@@ -125,7 +125,7 @@ func CreateConnection(RemoteCab string) (net.Conn, error) {
 				//lfshook.NewLogger().Logger.Infof("========Connect server err :%+v", err)
 				return nil, err
 			}
-			lfshook.NewLogger().Logger.Infof("Connect success :%s:%d", socket.RemoteAddr, socket.RemotePort)
+			lfshook.NewLogger().Logger.Infof("Connect success MC1:%s:%d", socket.RemoteAddr, socket.RemotePort)
 			return conn, nil
 		}
 	} else { // connect to MC8

+ 3 - 4
internal/app/stc/sendstatus/status.go

@@ -17,7 +17,7 @@ func SendToStc(conn net.Conn, data []byte) {
 		fmt.Println("send msg err:", err)
 		conn.Close()
 	}
-	lfshook.NewLogger().Logger.Infof("==send==data:==%x", data)
+	//lfshook.NewLogger().Logger.Infof("SendToStc data:%x", data)
 }
 
 // report alarm status to STC
@@ -78,7 +78,7 @@ func AlarmStatus(exten string, status string) {
 		return
 	}
 	//check if actived
-	lfshook.NewLogger().Logger.Infof("===AlarmStatus=ext:%s===carr:%x==========pos:%x=========status:%x", exten, protocol.Data[0], protocol.Data[1], protocol.Data[2])
+	lfshook.NewLogger().Logger.Infof("PAD number:%s carr:%x pos:%x status:%x", exten, protocol.Data[0], protocol.Data[1], protocol.Data[2])
 
 	if socket.Conn != nil {
 		SendToStc(socket.Conn, encoded)
@@ -97,7 +97,7 @@ func PaStatus(src string, patype string, operation string) {
 	if !active.Master {
 		return
 	}
-	lfshook.NewLogger().Logger.Infof("===PAStatus=Startext:%s=== type:%s=========action:%s", src, patype, operation)
+	lfshook.NewLogger().Logger.Infof("PA Status ext:%s type:%s status:%s", src, patype, operation)
 	protocol := msgdata.NewProtocol()
 	protocol.MessageID = 0x22
 	protocol.DataLength = 0x04
@@ -262,5 +262,4 @@ func SendRecordFile(filename, rcdtype string) {
 	if socket.Conn8 != nil {
 		SendToStc(socket.Conn8, encoded)
 	}
-
 }