dujunchen 2 недель назад
Родитель
Сommit
bf2071b20d

+ 2 - 2
internal/app/ami/action/call.go

@@ -27,8 +27,8 @@ func Hangup(channel string) {
 
 // Dial 拨打号码
 func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
-	//chanel := fmt.Sprintf("%s/%s", callType, src)
-	chanel := fmt.Sprintf("Local/%s@pacu-ani-rule", src)
+	chanel := fmt.Sprintf("%s/%s@ani-rule", "Local", src)
+	//chanel := fmt.Sprintf("Local/%s@pacu-ani-rule", src)
 	action := map[string]string{
 		"Action":   "Originate",
 		"Channel":  chanel,

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

@@ -90,10 +90,10 @@ 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
 				go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule", "") // 1车ICP接听PAIU
 			}
 
-			alstatus.AlarmStatus(event["CallerIDName"], "connect", conn) // Alarm connected
 			/*
 				switch string(event["CallerIDNum"][2]) { // connect the pacu to pad acording to the pad number
 				case "1":

+ 4 - 1
internal/app/ami/action/playback.go

@@ -3,12 +3,13 @@ package action
 import (
 	"errors"
 	"fmt"
+	"pbx-api-gin/pkg/lfshook"
 	"strings"
 )
 
 func PlaybackPacu(filename string, count int, delay int, PaType string) (err error) {
 
-	Para := fmt.Sprintf("count=%d,filename=%s,delay=%d,priority=%s", count, strings.Replace(filename, ".wav", "", -1), delay, PaType)
+	Para := fmt.Sprintf("count=%d,filename=%s,delay=%d,priority=%s", count, strings.Replace(strings.Replace(filename, ".mp3", "", -1), ".wav", "", -1), delay, PaType)
 	Chan := ""
 
 	switch PaType {
@@ -34,6 +35,8 @@ func PlaybackPacu(filename string, count int, delay int, PaType string) (err err
 		"Variable": Para,
 	}
 
+	lfshook.NewLogger().Logger.Infof("===action : %+v", action)
+
 	res, _, err := AminInstance.Send(action)
 	if err != nil {
 		return err

+ 81 - 78
internal/app/stc/broadcast/stc-broadcast.go

@@ -13,7 +13,6 @@ import (
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	"pbx-api-gin/pkg/lfshook"
-	"strings"
 	"sync"
 	"time"
 )
@@ -69,31 +68,36 @@ func processPacket(packet []byte) {
 		Active([1]byte{packet[7]})
 	}
 
-	if active.Actived {
-		switch packet[5] {
-		case 0x01: // heartbeat
-			// handle heartbeat
-		case 0x02: // STN
-			StationAnn(packet)
-		case 0x05: // SPC
-			SpecialAnn(packet)
-		case 0x06: // EMG
-			EmgMsg(packet)
-		case 0x07: // STOP
-			AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
-		case 0x08: // DCS
-			DcsAnn(packet)
-		case 0x09: // SELF CHECK
-			SelfCheck(packet)
-		case 0x0a:
-			AlarmHandle(packet)
-		case 0x0b:
-			AlarmResetAll()
-		case 0x0c:
-			RecordStorageConf(packet[8:])
-		default:
-			fmt.Printf("Unknown command: %x\n", packet[5])
-		}
+	switch packet[5] {
+	case 0x01: // heartbeat
+		// handle heartbeat
+	case 0x02: // STN
+		lfshook.NewLogger().Infof("=====STN=========")
+		StationAnn(packet)
+	case 0x03: // ACTIVE
+
+		Active([1]byte{packet[8]})
+	case 0x05: // SPC
+		lfshook.NewLogger().Infof("=====SPC=========")
+		SpecialAnn(packet)
+	case 0x06: // EMG
+		lfshook.NewLogger().Infof("=====EMG=========")
+		EmgMsg(packet)
+	case 0x07: // STOP
+		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
+	case 0x08: // DCS
+		lfshook.NewLogger().Infof("=====DCS=========")
+		DcsAnn(packet)
+	case 0x09: // SELF CHECK
+		SelfCheck(packet)
+	case 0x0a:
+		AlarmHandle(packet)
+	case 0x0b:
+		AlarmResetAll()
+	case 0x0c:
+		RecordStorageConf(packet[8:])
+	default:
+		fmt.Printf("Unknown command: %x\n", packet[5])
 	}
 }
 
@@ -106,9 +110,6 @@ func StationAnn(data []byte) (err error) {
 	datalen := int(data[11])
 
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
-	filename = strings.ReplaceAll(filename, ".wav", "")
-	filename = strings.ReplaceAll(filename, ".mp3", "")
-
 	lfshook.NewLogger().Logger.Infof("=============Get filename  : %v", filename)
 
 	//update special voice
@@ -183,14 +184,15 @@ func SpecialAnn(data []byte) {
 	cycleCount := data[9]
 	datalen := int(data[10])
 
-	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
-
-	//update pa type
-	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "SPC"})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
-
+	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
+	/*
+		//update pa type
+		_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "SPC"})
+		if er != nil {
+			lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+		}
+	*/
+	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "SPC")
 	} else {
@@ -204,14 +206,15 @@ func EmgMsg(data []byte) {
 	cycleCount := data[9]
 	datalen := int(data[10])
 
-	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
-
-	//update pa type
-	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "EMG"})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
-
+	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
+	/*
+		//update pa type
+		_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "EMG"})
+		if er != nil {
+			lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+		}
+	*/
+	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "EMG")
 	} else {
@@ -236,11 +239,13 @@ func AnnStop(data [4]byte) {
 	for _, ext := range Pacus {
 		action.Hangup(ext)
 	}
-	//update pa type
-	_, er := mysql.DBOrmInstance.Cols("patype").In("exten", Pacus).Update(&model.Extension{PaType: ""})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
+	/*
+		//update pa type
+		_, er := mysql.DBOrmInstance.Cols("patype").In("exten", Pacus).Update(&model.Extension{PaType: ""})
+		if er != nil {
+			lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+		}
+	*/
 }
 
 // DCS 语音
@@ -249,14 +254,15 @@ func DcsAnn(data []byte) {
 	cycleCount := data[9]
 	datalen := int(data[10])
 
-	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-3)
-
-	//update pa type
-	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "DCS"})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
-
+	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
+	/*
+		//update pa type
+		_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "DCS"})
+		if er != nil {
+			lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+		}
+	*/
+	lfshook.NewLogger().Infof("======count:%x", cycleCount)
 	if int(cycleCount) == 255 {
 		action.PlaybackPacu(filename, 9999999, int(delay), "DCS")
 	} else {
@@ -272,13 +278,13 @@ func SelfCheck(data []byte) {
 	datalen := int(data[11])
 
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
-
-	//update pa type
-	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "CHK"})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
-
+	/*
+		//update pa type
+		_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "CHK"})
+		if er != nil {
+			lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+		}
+	*/
 	switch check {
 	case 0x01:
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
@@ -313,32 +319,28 @@ func AlarmHandle(data []byte) {
 	// 只对 handler == 0x01 做 2 秒去重
 	if handler == 0x01 {
 		if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
-			lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 2 seconds", exten)
+			lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
 			return // 已存在,说明在2秒窗口期内,直接丢弃
 		}
 
-		// 设置2秒后删除该 key,允许下次通过
-		time.AfterFunc(2*time.Second, func() {
+		// 设置4秒后删除该 key,允许下次通过
+		time.AfterFunc(4*time.Second, func() {
 			suppressedExts.Delete(key)
 			lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
 		})
 	}
 
-	// 设置1秒后删除该 key,允许下次通过
-	time.AfterFunc(1*time.Second, func() {
-		suppressedExts.Delete(key)
-		lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
-	})
-
 	switch handler {
 	case 0x01: //answer(ICP+Alarm+PACU)
 		//NotifyPaiu(exten, "answer")
 
 		lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
 		if active.CabNum == "1" {
-			action.Dial(PacuNum, "0402", "ani-rule", PacuNum, exten, "1") // PACU dial ICP
+			action.Dial("0402", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP
+			//action.Dial(PacuNum, "0402", "ani-rule", PacuNum, exten, "1") // PACU dial ICP
 		} else {
-			action.Dial(PacuNum, "0402", "ani-rule", PacuNum, exten, "8") // PACU dial ICP
+			action.Dial("0402", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP
+			//action.Dial(PacuNum, "0402", "ani-rule", PacuNum, exten, "8") // PACU dial ICP
 		}
 		//invite PACU join in
 		//action.Hangup("PACU")
@@ -353,12 +355,11 @@ func AlarmHandle(data []byte) {
 		lfshook.NewLogger().Logger.Infof("================OCC Answer PAD================:%s ", exten)
 	case 0x02: //hold  重新放回队列里面
 		NotifyPaiu(exten, "hold")
-
 		err := action.RedirectInQueue(exten, "0300", "default", "1")
 		if err != nil {
 			lfshook.NewLogger().Info(err)
 		}
-
+		action.Hangup("2311") //1 车接听
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
 		action.Hangup(exten)
@@ -416,6 +417,8 @@ func AlarmResetAll() {
 	for _, ext := range AlarmExts {
 		action.Hangup(ext.Extension)
 	}
+
+	action.Hangup("2311")
 }
 
 func RecordStorageConf(data []byte) {

+ 7 - 0
internal/app/stc/index.go

@@ -14,6 +14,13 @@ import (
 	"time"
 )
 
+const RemotePort = 10100
+const LocalPort = 10201
+
+// const RemoteAddr = "192.168.17.14"
+// const RemoteAddr = "10.0.0.51"
+const RemoteAddr = "10.0.11.11"
+
 func StartStcConnection(conn net.Conn) {
 
 	var connMux sync.Mutex // 保护 conn 的读写

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

@@ -9,6 +9,8 @@ import (
 	"pbx-api-gin/pkg/utils"
 )
 
+var AlarmHandling = 0
+
 func SendToStc(conn net.Conn, data []byte) {
 
 	_, err := conn.Write(data)