Explorar el Código

update cab1 or cab8 socket send

dujunchen hace 1 semana
padre
commit
f92e63ce28

+ 14 - 14
internal/app/ami/action/index.go

@@ -44,61 +44,61 @@ func HandleAMI(event map[string]string) {
 	/*case "DialBegin":
 	lfshook.NewLogger().Infof("=========%s", event["Event"])
 	if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["DestCallerIDNum"]) {
-		alstatus.AlarmStatus(event["CallerIDNum"], "dial", conn) // Alarm dial ICP start
+		alstatus.AlarmStatus(event["CallerIDNum"], "dial") // Alarm dial ICP start
 	}
 	*/
 	case "Newchannel":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0300" { // Alarm dial queue start; PAD dialing
-			alstatus.PaStatus(event["CallerIDNum"], "PAD", "start", conn)
-			alstatus.AlarmStatus(event["CallerIDNum"], "dial", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
+			alstatus.AlarmStatus(event["CallerIDNum"], "dial")
 		}
 
 	case "Hangup":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["Exten"]) { // Alarm dial queue start; PAD dialing
-			alstatus.PaStatus(event["CallerIDNum"], "PAD", "end", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 		}
 
 	case "QueueCallerJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsPAIU(event["CallerIDNum"]) { // Alarm join the queue, PAD in the queue
-			alstatus.AlarmStatus(event["CallerIDNum"], "queue", conn)
+			alstatus.AlarmStatus(event["CallerIDNum"], "queue")
 		}
 
 	case "ConfbridgeJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
 			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
-			alstatus.PaStatus(event["CallerIDNum"], "PA", "start", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
 		}
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0500" { //CPA start
 			lfshook.NewLogger().Infof("====CPA status:%s=====", "start")
-			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
 		}
 
 	case "ConfbridgeLeave":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
 			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
-			alstatus.PaStatus(event["CallerIDNum"], "PA", "end", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
 		}
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0500" { //CPA end
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
-			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
 		}
 
 	case "DialEnd":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab start
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
-			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
 		}
 
 	case "BridgeLeave":
 		//Cab Cab end
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
-			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end", conn)
+			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 		}
 
 	case "ExtensionStatus":
@@ -114,7 +114,7 @@ func HandleAMI(event map[string]string) {
 		}
 		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
 			if len(event["Exten"]) > 3 {
-				alstatus.AlarmStatus(event["Exten"], event["StatusText"], conn) // PAD idle + unavailable
+				alstatus.AlarmStatus(event["Exten"], event["StatusText"]) // PAD idle + unavailable
 			}
 		}
 
@@ -123,12 +123,12 @@ func HandleAMI(event map[string]string) {
 		if utils.IsPACU(event["CallerIDNum"]) {
 			if utils.IsPAIU(event["CallerIDName"]) { //relate to PACU Dial ICP caller name in AlarmHandle
 				lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s   Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
-				alstatus.AlarmStatus(event["CallerIDName"], "connect", conn)          // Alarm connected
+				alstatus.AlarmStatus(event["CallerIDName"], "connect")                // Alarm connected
 				go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule", "") // 1车ICP接听PAIU
 			}
 		} else if utils.IsPAIU(event["CallerIDNum"]) { //No PACU available in the cab
 			lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s   Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
-			alstatus.AlarmStatus(event["CallerIDName"], "connect", conn) // Alarm connected
+			alstatus.AlarmStatus(event["CallerIDName"], "connect") // Alarm connected
 		}
 	}
 

+ 12 - 50
internal/app/stc/broadcast/stc-broadcast.go

@@ -14,7 +14,6 @@ import (
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
-	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/pkg/lfshook"
 	"sync"
 	"time"
@@ -135,12 +134,7 @@ func StationAnn(data []byte) (err error) {
 	}
 
 	//Pa status report
-	if active.Actived && active.CabNum == "1" {
-		alstatus.PaStatus("", "STN", "start", socket.Conn)
-	}
-	if active.Actived && active.CabNum == "8" {
-		alstatus.PaStatus("", "STN", "start", socket.Conn8)
-	}
+	alstatus.PaStatus("", "STN", "start")
 
 	action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
 	return nil
@@ -224,12 +218,7 @@ func SpecialAnn(data []byte) {
 	}
 
 	//Pa status report
-	if active.Actived && active.CabNum == "1" {
-		alstatus.PaStatus("", "SPC", "start", socket.Conn)
-	}
-	if active.Actived && active.CabNum == "8" {
-		alstatus.PaStatus("", "SPC", "start", socket.Conn8)
-	}
+	alstatus.PaStatus("", "SPC", "start")
 
 	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
@@ -254,12 +243,7 @@ func EmgMsg(data []byte) {
 	}
 
 	//Pa status report
-	if active.Actived && active.CabNum == "1" {
-		alstatus.PaStatus("", "EMG", "start", socket.Conn)
-	}
-	if active.Actived && active.CabNum == "8" {
-		alstatus.PaStatus("", "EMG", "start", socket.Conn8)
-	}
+	alstatus.PaStatus("", "EMG", "start")
 
 	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
@@ -272,15 +256,8 @@ func EmgMsg(data []byte) {
 // 停止指定类型广播
 func AnnStop(data [4]byte) {
 
-	var conn net.Conn
 	RunningType := ""
 
-	if active.Actived && active.CabNum == "1" {
-		conn = socket.Conn
-	} else if active.Actived && active.CabNum == "8" {
-		conn = socket.Conn8
-	}
-
 	switch data[0] {
 	case 0x03:
 		RunningType = "DCS"
@@ -294,7 +271,7 @@ func AnnStop(data [4]byte) {
 		RunningType = "CHK"
 	}
 
-	alstatus.PaStatus("", RunningType, "end", conn)
+	alstatus.PaStatus("", RunningType, "end")
 
 	for _, ext := range Pacus {
 		action.Hangup(ext)
@@ -324,12 +301,7 @@ func DcsAnn(data []byte) {
 
 	//lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	//Pa status report
-	if active.Actived && active.CabNum == "1" {
-		alstatus.PaStatus("", "DCS", "start", socket.Conn)
-	}
-	if active.Actived && active.CabNum == "8" {
-		alstatus.PaStatus("", "DCS", "start", socket.Conn8)
-	}
+	alstatus.PaStatus("", "DCS", "start")
 
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "DCS")
@@ -340,6 +312,7 @@ func DcsAnn(data []byte) {
 
 // 自检广播
 func SelfCheck(data []byte) {
+
 	check := data[8]
 	delay := data[9]
 	cycleCount := data[10]
@@ -357,23 +330,12 @@ func SelfCheck(data []byte) {
 	case 0x01: //start
 
 		//Pa status report
-		if active.Actived && active.CabNum == "1" {
-			alstatus.PaStatus("", "CHK", "start", socket.Conn)
-		}
-		if active.Actived && active.CabNum == "8" {
-			alstatus.PaStatus("", "CHK", "start", socket.Conn8)
-		}
-
+		alstatus.PaStatus("", "CHK", "start")
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
 	case 0x02: //stop
 
 		//Pa status report
-		if active.Actived && active.CabNum == "1" {
-			alstatus.PaStatus("", "CHK", "end", socket.Conn)
-		}
-		if active.Actived && active.CabNum == "8" {
-			alstatus.PaStatus("", "CHK", "end", socket.Conn8)
-		}
+		alstatus.PaStatus("", "CHK", "end")
 
 		for _, ext := range Pacus {
 			asterisk.Hangup(ext)
@@ -516,11 +478,11 @@ func AlarmResetAll() {
 	}
 
 	if active.CabNum == "1" && active.Actived {
-		action.Hangup("2311")                                 //1 车接听
-		alstatus.AlarmStatus("0000", "allreset", socket.Conn) //send all reset status
+		action.Hangup("2311")                    //1 车接听
+		alstatus.AlarmStatus("0000", "allreset") //send all reset status
 	} else if active.CabNum == "8" && active.Actived {
-		action.Hangup("2381")                                  //8 车接听
-		alstatus.AlarmStatus("0000", "allreset", socket.Conn8) // send all reset status
+		action.Hangup("2381")                    //8 车接听
+		alstatus.AlarmStatus("0000", "allreset") // send all reset status
 	}
 }
 

+ 13 - 6
internal/app/stc/sendstatus/status.go

@@ -5,6 +5,7 @@ import (
 	"net"
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
+	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 )
@@ -22,7 +23,7 @@ func SendToStc(conn net.Conn, data []byte) {
 }
 
 // report alarm status to STC
-func AlarmStatus(exten string, status string, conn net.Conn) {
+func AlarmStatus(exten string, status string) {
 
 	//check exten if it is a alarm exten
 	if !utils.IsPAIU(exten) { // if not alarm device , return
@@ -74,14 +75,16 @@ func AlarmStatus(exten string, status string, conn net.Conn) {
 		return
 	}
 	//check if actived
-	if active.Actived {
-		lfshook.NewLogger().Logger.Infof("===AlarmStatus=ext:%s===carr:%x==========pos:%x=========status:%x", exten, protocol.Data[0], protocol.Data[1], protocol.Data[2])
-		SendToStc(conn, encoded)
+	lfshook.NewLogger().Logger.Infof("===AlarmStatus=ext:%s===carr:%x==========pos:%x=========status:%x", exten, protocol.Data[0], protocol.Data[1], protocol.Data[2])
+	if active.Actived && active.CabNum == "1" {
+		SendToStc(socket.Conn, encoded)
+	} else if active.Actived && active.CabNum == "8" {
+		SendToStc(socket.Conn8, encoded)
 	}
 }
 
 // report broadcast status to STC
-func PaStatus(src string, patype string, operation string, conn net.Conn) {
+func PaStatus(src string, patype string, operation string) {
 
 	protocol := msgdata.NewProtocol()
 	protocol.MessageID = 0x22
@@ -140,5 +143,9 @@ func PaStatus(src string, patype string, operation string, conn net.Conn) {
 		return
 	}
 
-	SendToStc(conn, encoded)
+	if active.Actived && active.CabNum == "1" {
+		SendToStc(socket.Conn, encoded)
+	} else if active.Actived && active.CabNum == "8" {
+		SendToStc(socket.Conn8, encoded)
+	}
 }