浏览代码

update ICP answer alarm

dujunchen 2 周之前
父节点
当前提交
6d848dabfd

+ 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

@@ -81,10 +81,10 @@ func HandleAMI(event map[string]string, conn net.Conn) {
 		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

+ 10 - 2
internal/app/mysql/index.go

@@ -1,14 +1,22 @@
 package mysql
 
 import (
+	"fmt"
+	"os"
+	"pbx-api-gin/internal/pkg/configs"
+	"pbx-api-gin/pkg/lfshook"
+	"syscall"
+
 	_ "github.com/go-sql-driver/mysql"
+	"github.com/sirupsen/logrus"
 	"xorm.io/xorm"
+	"xorm.io/xorm/log"
 )
 
 var DBOrmInstance *xorm.Engine
 
 func CreateDBInstance() {
-	/*var err error
+	var err error
 	// DBOrmInstance, err = xorm.NewEngine("sqlite3", "playcall.db")
 	url := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8",
 		configs.ConfigGlobal.MysqlDBUser,
@@ -41,5 +49,5 @@ func CreateDBInstance() {
 		}
 		DBOrmInstance.SetLogger(log.NewSimpleLogger(info))
 	}
-	*/
+
 }

+ 53 - 51
internal/app/stc/broadcast/stc-broadcast.go

@@ -12,7 +12,6 @@ import (
 	"pbx-api-gin/internal/app/mysql"
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	"pbx-api-gin/pkg/lfshook"
-	"strings"
 	"sync"
 	"time"
 )
@@ -70,16 +69,21 @@ func processPacket(packet []byte) {
 	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)
@@ -103,7 +107,6 @@ func StationAnn(data []byte) (err error) {
 	datalen := int(data[11])
 
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
-	filename = strings.Split(filename, ".")[0]
 	lfshook.NewLogger().Logger.Infof("=============Get filename  : %v", filename)
 	/*
 		//update special voice
@@ -138,14 +141,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 {
@@ -159,14 +163,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 {
@@ -191,11 +196,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 语音
@@ -204,14 +211,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 {
@@ -227,13 +235,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")
@@ -267,28 +275,22 @@ 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")
 
-		action.Dial(PacuNum, "0402", "ani-rule", PacuNum, exten, "PJSIP") // PACU dial ICP
+		action.Dial("0402", PacuNum, "default", PacuNum, exten, "PJSIP") // PACU dial ICP
 		lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
 		//invite PACU join in
 		//action.Hangup("PACU")
@@ -303,16 +305,14 @@ 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)
-
 		action.Hangup("2311") //1 车接听
 		//action.Hangup("2381") //8 车接听
 	}
@@ -364,6 +364,8 @@ func AlarmResetAll() {
 	for _, ext := range AlarmExts {
 		action.Hangup(ext.Extension)
 	}
+
+	action.Hangup("2311")
 }
 
 func RecordStorageConf(data []byte) {

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

@@ -17,8 +17,8 @@ import (
 const RemotePort = 10100
 const LocalPort = 10201
 
-//const RemoteAddr = "192.168.17.14"
-
+// const RemoteAddr = "192.168.17.14"
+// const RemoteAddr = "10.0.0.51"
 const RemoteAddr = "10.0.11.11"
 
 func StartStcConnection(conn net.Conn) {

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

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