dujunchen 1 周之前
父节点
当前提交
09abd130a4
共有 4 个文件被更改,包括 112 次插入98 次删除
  1. 8 19
      internal/app/ami/action/index.go
  2. 8 11
      internal/app/index.go
  3. 65 67
      internal/app/stc/broadcast/stc-broadcast.go
  4. 31 1
      internal/app/stc/socket/index.go

+ 8 - 19
internal/app/ami/action/index.go

@@ -52,17 +52,11 @@ func HandleAMI(event map[string]string) {
 
 	case "UserEvent": // RCD filename; PA;CPA; CabCab
 		lfshook.NewLogger().Infof("========event:%s   File:%s", event["Event"], event["FILENAME"])
+
 		if event["UserEvent"] == "SetRecordFile" { //get  record file name
 			alstatus.SendRecordFile(event["FILENAME"], event["RecordType"])
 
 		} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
-			//check active signal  before PA; hangup if not actived
-			/*	if active.ActivedCab == "1" && event["CallerIDNum"] == "2311" {
-					Hangup(event["CallerIDNum"])
-				} else if active.ActivedCab == "8" && event["CallerIDNum"] == "2381" {
-					Hangup(event["CallerIDNum"])
-				}*/
-
 			//PA & CPA interrupt others
 			if utils.IsICP(event["CallerIDNum"]) {
 
@@ -79,13 +73,6 @@ func HandleAMI(event map[string]string) {
 
 			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
 				if priority.CheckPriority("CPA") {
-
-					//check active signal  before CPA; hangup if not actived
-					/*	if active.ActivedCab == "8" && event["CallerIDNum"] == "1411" {
-							Hangup(event["CallerIDNum"])
-						} else if active.ActivedCab == "1" && event["CallerIDNum"] == "1481" {
-							Hangup(event["CallerIDNum"])
-						}*/
 					if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
 						Hangup(event["CallerIDNum"])
 					}
@@ -297,7 +284,7 @@ func HandleAMI(event map[string]string) {
 					}
 
 					alstatus.AlarmStatus(event["CallerIDNum"], "connect")
-					go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
+					go RedirectInQueue(event["Channel"], "1481", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
 					go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8")    // PACUs dial OCC8
 				}
 			} else {
@@ -395,8 +382,9 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADICP)
 			go RedirectInQueue(event["ConnectedLineName"], "2311", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP1
 
-			go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "8") // PAD call ICP8
-
+			if ExtenStatus("2381") == "Idle" {
+				go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "8") // PAD call ICP8
+			}
 		}
 		if event["ConnectedLineNum"] == "ani8" && event["Exten"] == "0511" { //PAD ansered by ICP8; PACUs connected ICP8
 			lfshook.NewLogger().Infof("====PAD answered by ICP8:%s=====", event["ConnectedLineName"])
@@ -407,8 +395,9 @@ func HandleAMI(event map[string]string) {
 			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADICP)
 			go RedirectInQueue(event["ConnectedLineName"], "2381", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP8
 
-			go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "1") // PAD call ICP2
-
+			if ExtenStatus("2311") == "Idle" {
+				go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "1") // PAD call ICP1
+			}
 			break
 		}
 

+ 8 - 11
internal/app/index.go

@@ -1,7 +1,6 @@
 package app
 
 import (
-	"os/exec"
 	"pbx-api-gin/internal/app/ami/action"
 	"pbx-api-gin/internal/app/stc"
 	"pbx-api-gin/internal/app/stc/active"
@@ -17,10 +16,7 @@ func StartApp() {
 	//mysql.CreateDBInstance()
 
 	//Get cab number acording to IP
-	_, err := SetMasterCabNum()
-	if err != nil {
-		lfshook.NewLogger().Infof("Set Role and Cab Num err :%+v", err)
-	}
+	SetMasterCabNum()
 
 	lfshook.NewLogger().Infof("=================cab number:%s========Master:%+v===", active.CabNum, active.Master)
 
@@ -55,18 +51,19 @@ func StartApp() {
 }
 
 // Get eth0 IP
-func SetMasterCabNum() (string, error) {
-	cmd := "ip a |grep 10.0.11.11" //check Master IP
-
-	out, _ := exec.Command("bash", "-c", cmd).CombinedOutput()
+func SetMasterCabNum() {
 
+	ext, err := socket.IsIPExists("10.0.11.11")
+	if err != nil {
+		lfshook.NewLogger().Infof("Check IP :%+v", err)
+	}
 	// Init cab number and master role
-	if len(out) == 0 {
+	if !ext {
 		active.Master = false
 		active.CabNum = "8"
 	} else {
 		active.Master = true
 		active.CabNum = "1"
 	}
-	return string(out), nil
+
 }

+ 65 - 67
internal/app/stc/broadcast/stc-broadcast.go

@@ -15,9 +15,7 @@ import (
 	"pbx-api-gin/internal/app/stc/priority"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
-	"sort"
 	"strconv"
-	"strings"
 	"sync"
 	"time"
 
@@ -85,82 +83,82 @@ func processPacket(packet []byte) {
 
 	switch packet[5] {
 	case 0x01: //heartbeat
-
-		//PAD-OCC异常情况处理
-		if priority.OCCAnswer == 1 {
-			//定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
-			resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
-			if err != nil {
-				lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
-				return
-			}
-			if resCaller.Calls != "0" {
-				sort.Slice(resCaller.Entrys, func(i, j int) bool {
-					return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
-				})
-
-				for _, caller := range resCaller.Entrys {
-					priority.ICPAnswer = 0
-					lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
-					//order by pos
-					action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
-					time.Sleep(time.Microsecond * 200)                                                   //200 ms delay
+		/*
+			//PAD-OCC异常情况处理
+			if priority.OCCAnswer == 1 {
+				//定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
+				resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
+				if err != nil {
+					lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
+					return
+				}
+				if resCaller.Calls != "0" {
+					sort.Slice(resCaller.Entrys, func(i, j int) bool {
+						return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
+					})
+
+					for _, caller := range resCaller.Entrys {
+						priority.ICPAnswer = 0
+						lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
+						//order by pos
+						action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
+						time.Sleep(time.Microsecond * 200)                                                   //200 ms delay
+					}
 				}
-			}
 
-			//定时监测OCC  queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
-			res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
-			if err != nil {
-				lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
-				return
-			}
-			if res.Calls != "0" { //OCC queue is not empty
-				//	HangupAllLocalChan()
-				lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
-				if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
-					time.Sleep(time.Second)
-					PADChan := ""
-					for _, chanEntry := range res.Entrys {
-						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
-						if chanEntry.Position == "1" {
-							PADChan = chanEntry.Channel
-							break
+				//定时监测OCC  queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
+				res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
+				if err != nil {
+					lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
+					return
+				}
+				if res.Calls != "0" { //OCC queue is not empty
+					//	HangupAllLocalChan()
+					lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
+					if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
+						time.Sleep(time.Second)
+						PADChan := ""
+						for _, chanEntry := range res.Entrys {
+							lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
+							if chanEntry.Position == "1" {
+								PADChan = chanEntry.Channel
+								break
+							}
 						}
-					}
 
-					if PADChan != "" {
-						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-						go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
+						if PADChan != "" {
+							alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
+							go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
 
-						go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
-					} else {
-						lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
-					}
-					break
-				} else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
-					time.Sleep(time.Second)
-					PADChan := ""
-					for _, chanEntry := range res.Entrys {
-						lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
-						if chanEntry.Position == "1" {
-							PADChan = chanEntry.Channel
-							break
+							go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
+						} else {
+							lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+						}
+						break
+					} else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
+						time.Sleep(time.Second)
+						PADChan := ""
+						for _, chanEntry := range res.Entrys {
+							lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
+							if chanEntry.Position == "1" {
+								PADChan = chanEntry.Channel
+								break
+							}
 						}
-					}
 
-					if PADChan != "" {
-						alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
-						go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
+						if PADChan != "" {
+							alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
+							go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
 
-						go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
-					} else {
-						lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+							go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
+						} else {
+							lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
+						}
+						break
 					}
-					break
 				}
 			}
-		}
-
+		*/
 	case 0x02: // STN
 		if priority.CheckPriority("STN") {
 			action.HangupRunningTask("STN") //STN interrupt other

+ 31 - 1
internal/app/stc/socket/index.go

@@ -1,6 +1,9 @@
 package socket
 
-import "net"
+import (
+	"fmt"
+	"net"
+)
 
 var Conn net.Conn
 var Conn8 net.Conn
@@ -18,3 +21,30 @@ const RemoteAddr = "10.0.11.11"
 const RemoteAddr8 = "10.0.11.81"
 
 var ConnectedMaster bool
+
+func IsIPExists(targetIP string) (bool, error) {
+	// 解析目标 IP
+	ip := net.ParseIP(targetIP)
+	if ip == nil {
+		return false, fmt.Errorf("invalid IP address: %s", targetIP)
+	}
+
+	// 获取所有网络接口的地址
+	addrs, err := net.InterfaceAddrs()
+	if err != nil {
+		return false, err
+	}
+
+	// 遍历每个接口地址
+	for _, addr := range addrs {
+		// 只处理 IP 网络类型地址 (*net.IPNet)
+		if ipnet, ok := addr.(*net.IPNet); ok {
+			// 检查该网段是否包含目标 IP
+			if ipnet.Contains(ip) {
+				return true, nil
+			}
+		}
+	}
+
+	return false, nil
+}