Przeglądaj źródła

update priority

dujunchen 1 tydzień temu
rodzic
commit
731f0cd70e

+ 14 - 0
internal/app/ami/action/call.go

@@ -25,6 +25,20 @@ func Hangup(channel string) {
 	}
 	}
 }
 }
 
 
+// Hangup 挂断所有分机
+func HangupAll() {
+	var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
+	//all PACU
+	for _, ret := range Pacus {
+		Hangup(ret)
+	}
+
+	Hangup("1411") //IO1
+	Hangup("1481") //IO8
+	Hangup("2311") //ICP1
+	Hangup("2381") //ICP8
+}
+
 // Dial 拨打号码
 // Dial 拨打号码
 func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
 func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
 	chanel := fmt.Sprintf("%s/%s@default", "Local", src)
 	chanel := fmt.Sprintf("%s/%s@default", "Local", src)

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

@@ -9,6 +9,7 @@ import (
 	"pbx-api-gin/internal/pkg/configs"
 	"pbx-api-gin/internal/pkg/configs"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 	"pbx-api-gin/pkg/utils"
+	"strconv"
 	"time"
 	"time"
 
 
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
@@ -21,7 +22,7 @@ var AminInstance *amigo.Amigo
 //type Operation func(src, dst string, whisper, bargein bool)
 //type Operation func(src, dst string, whisper, bargein bool)
 
 
 func HandleAMI(event map[string]string) {
 func HandleAMI(event map[string]string) {
-	lfshook.NewLogger().Infof("===start======%s", event["Event"])
+	//lfshook.NewLogger().Infof("===start======%s", event["Event"])
 	//return if not actived
 	//return if not actived
 	if !active.Actived {
 	if !active.Actived {
 		return
 		return
@@ -38,6 +39,7 @@ func HandleAMI(event map[string]string) {
 	case "Newchannel":
 	case "Newchannel":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0300" { // Alarm dial queue start; PAD dialing
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0300" { // Alarm dial queue start; PAD dialing
+			priority.RunningType, _ = strconv.Atoi(priority.Priority.PADICP)
 			alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 			alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 			alstatus.AlarmStatus(event["CallerIDNum"], "dial")
 			alstatus.AlarmStatus(event["CallerIDNum"], "dial")
 		}
 		}
@@ -45,18 +47,24 @@ func HandleAMI(event map[string]string) {
 	case "SoftHangupRequest": //pre-recored broadcast end
 	case "SoftHangupRequest": //pre-recored broadcast end
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if event["CallerIDName"] == "EMG" && event["Exten"] == "0502" { // EMG broadcast hangup
 		if event["CallerIDName"] == "EMG" && event["Exten"] == "0502" { // EMG broadcast hangup
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDName"], "EMG", "end")
 			alstatus.PaStatus(event["CallerIDName"], "EMG", "end")
 
 
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
+			priority.RunningType = 0
+			priority.SpecialVoice = 0
 			alstatus.PaStatus(event["CallerIDName"], "STN", "end")
 			alstatus.PaStatus(event["CallerIDName"], "STN", "end")
 
 
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDName"], "DCS", "end")
 			alstatus.PaStatus(event["CallerIDName"], "DCS", "end")
 
 
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDName"], "SPC", "end")
 			alstatus.PaStatus(event["CallerIDName"], "SPC", "end")
 
 
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDName"], "CHK", "end")
 			alstatus.PaStatus(event["CallerIDName"], "CHK", "end")
 		}
 		}
 
 
@@ -67,6 +75,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			if res.Calls == "0" {
 			if res.Calls == "0" {
 				priority.ICPAnswer = 0
 				priority.ICPAnswer = 0
+				priority.RunningType = 0
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				break
 				break
 			}
 			}
@@ -76,6 +85,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			if res.Calls == "0" {
 			if res.Calls == "0" {
 				priority.ICPAnswer = 0
 				priority.ICPAnswer = 0
+				priority.RunningType = 0
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				break
 				break
 			}
 			}
@@ -85,6 +95,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			if res.Calls == "0" {
 			if res.Calls == "0" {
 				priority.ICPAnswer = 0
 				priority.ICPAnswer = 0
+				priority.RunningType = 0
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				break
 				break
 			}
 			}
@@ -95,6 +106,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
 			res, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
 			if res.Calls == "0" {             //OCC queue is empty
 			if res.Calls == "0" {             //OCC queue is empty
 				priority.OCCAnswer = 0
 				priority.OCCAnswer = 0
+				priority.RunningType = 0
 				alstatus.OccPad("end")
 				alstatus.OccPad("end")
 				break
 				break
 			} else { //OCC queue is not empty
 			} else { //OCC queue is not empty
@@ -170,9 +182,11 @@ func HandleAMI(event map[string]string) {
 			if active.CabNum == "1" && active.Actived && extOCC1.Status == "Idle" { //check active and OCC status
 			if active.CabNum == "1" && active.Actived && extOCC1.Status == "Idle" { //check active and OCC status
 				priority.OCCAnswer = 1
 				priority.OCCAnswer = 1
 				alstatus.OccPad("start")
 				alstatus.OccPad("start")
+				priority.RunningType, _ = strconv.Atoi(priority.Priority.PADOCC)
 				Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDNum"], "1") // PACUs dial OCC1
 				Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDNum"], "1") // PACUs dial OCC1
 			} else if active.CabNum == "8" && active.Actived && extOCC8.Status == "Idle" {
 			} else if active.CabNum == "8" && active.Actived && extOCC8.Status == "Idle" {
 				priority.OCCAnswer = 1
 				priority.OCCAnswer = 1
+				priority.RunningType, _ = strconv.Atoi(priority.Priority.PADOCC)
 				alstatus.OccPad("start")
 				alstatus.OccPad("start")
 				Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", event["CallerIDNum"], "8") // PACUs dial OCC8
 				Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", event["CallerIDNum"], "8") // PACUs dial OCC8
 			}
 			}
@@ -182,12 +196,14 @@ func HandleAMI(event map[string]string) {
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
 			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
 			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
+			priority.RunningType, _ = strconv.Atoi(priority.Priority.ManuPa)
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
 			break
 			break
 		}
 		}
 
 
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
 			lfshook.NewLogger().Infof("====CPA status:%s=====", "start")
 			lfshook.NewLogger().Infof("====CPA status:%s=====", "start")
+			priority.RunningType, _ = strconv.Atoi(priority.Priority.CPA)
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
 			break
 			break
 		}
 		}
@@ -251,10 +267,12 @@ func HandleAMI(event map[string]string) {
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
 			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
 			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
 		}
 		}
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
 		}
 		}
 
 
@@ -262,28 +280,26 @@ func HandleAMI(event map[string]string) {
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab start
 		//Cab Cab start
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
+			priority.RunningType, _ = strconv.Atoi(priority.Priority.CabCab)
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
 		}
 		}
 
 
 	case "BridgeLeave":
 	case "BridgeLeave":
+		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab end
 		//Cab Cab end
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
+			priority.RunningType = 0
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 		}
 		}
 
 
 	case "ExtensionStatus":
 	case "ExtensionStatus":
 		lfshook.NewLogger().Infof("=========event:%s   status:%s", event["Event"], event["StatusText"])
 		lfshook.NewLogger().Infof("=========event:%s   status:%s", event["Event"], event["StatusText"])
 
 
-		status := &model.Extension{
-			Extension: event["Exten"],
-			Status:    event["StatusText"],
-		}
-		_, err := mysql.DBOrmInstance.Where("exten = ?", status.Extension).Cols("status").Update(status)
-		if err != nil {
-			lfshook.NewLogger().Infof("update extension status err : %+v", err.Error())
-		}
+		//update extension status
+		alstatus.ExtenStatMap[event["Exten"]] = event["StatusText"]
+
 		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
 		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
-			if len(event["Exten"]) > 3 {
+			if len(event["Exten"]) > 3 && utils.IsPAIU(event["Exten"]) {
 				alstatus.AlarmStatus(event["Exten"], event["StatusText"]) // PAD idle + unavailable
 				alstatus.AlarmStatus(event["Exten"], event["StatusText"]) // PAD idle + unavailable
 			}
 			}
 		}
 		}

+ 4 - 0
internal/app/index.go

@@ -7,6 +7,7 @@ import (
 	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/stc"
 	"pbx-api-gin/internal/app/stc"
 	"pbx-api-gin/internal/app/stc/active"
 	"pbx-api-gin/internal/app/stc/active"
+	"pbx-api-gin/internal/app/stc/priority"
 	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/internal/app/stc/socket"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/utils"
 	"pbx-api-gin/pkg/utils"
@@ -32,6 +33,9 @@ func StartApp() {
 
 
 	//init the active status
 	//init the active status
 	active.Actived = true
 	active.Actived = true
+	//get priority
+	priority.GetPriority()
+
 	// 启动带有重连机制的连接管理协程MC1
 	// 启动带有重连机制的连接管理协程MC1
 	go stc.StartStcConnection(socket.Conn, "1")
 	go stc.StartStcConnection(socket.Conn, "1")
 
 

+ 125 - 68
internal/app/stc/broadcast/stc-broadcast.go

@@ -7,14 +7,15 @@ import (
 	"io"
 	"io"
 	"net"
 	"net"
 	"net/http"
 	"net/http"
-	"pbx-api-gin/api/panel/asterisk"
 	"pbx-api-gin/internal/app/ami/action"
 	"pbx-api-gin/internal/app/ami/action"
 	"pbx-api-gin/internal/app/ami/model"
 	"pbx-api-gin/internal/app/ami/model"
 	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/stc/active"
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	msgdata "pbx-api-gin/internal/app/stc/data"
+	"pbx-api-gin/internal/app/stc/priority"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	alstatus "pbx-api-gin/internal/app/stc/sendstatus"
 	"pbx-api-gin/pkg/lfshook"
 	"pbx-api-gin/pkg/lfshook"
+	"strconv"
 	"sync"
 	"sync"
 	"time"
 	"time"
 )
 )
@@ -79,26 +80,63 @@ func processPacket(packet []byte) {
 	}
 	}
 
 
 	switch packet[5] {
 	switch packet[5] {
+	case 0x01:
+		break
+
 	case 0x02: // STN
 	case 0x02: // STN
-		StationAnn(packet)
+		if priority.CheckPriority("STN") {
+			action.HangupAll()
+			StationAnn(packet)
+		}
+
 	case 0x05: // SPC
 	case 0x05: // SPC
-		SpecialAnn(packet)
+		if priority.CheckPriority("SPC-TMS") {
+			action.HangupAll()
+			SpecialAnn(packet)
+		}
+
 	case 0x06: // EMG
 	case 0x06: // EMG
 		EmgMsg(packet)
 		EmgMsg(packet)
+
 	case 0x07: // STOP
 	case 0x07: // STOP
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
+
 	case 0x08: // DCS
 	case 0x08: // DCS
-		DcsAnn(packet)
+		if priority.CheckPriority("DCS") {
+			action.HangupAll()
+			DcsAnn(packet)
+		}
+
 	case 0x09: // SELF CHECK
 	case 0x09: // SELF CHECK
-		SelfCheck(packet)
+		if priority.CheckPriority("CHK") {
+			action.HangupAll()
+			SelfCheck(packet)
+		}
+
+	case 0x10: // SELF CHECK
+		if priority.CheckPriority("CHK") {
+			action.HangupAll()
+			VolumeAdjust(packet)
+		}
+
 	case 0x0a:
 	case 0x0a:
-		AlarmHandleTMS(packet)
+		if priority.CheckPriority("PAD-TMS") {
+			action.HangupAll()
+			AlarmHandleTMS(packet)
+		}
+
 	case 0x0b:
 	case 0x0b:
 		AlarmHoldResetAll(packet[8])
 		AlarmHoldResetAll(packet[8])
+
 	case 0x0c:
 	case 0x0c:
 		RecordStorageConf(packet[8:])
 		RecordStorageConf(packet[8:])
+
 	case 0x0d:
 	case 0x0d:
-		AlarmHandleICP(packet)
+		if priority.CheckPriority("PAD-ICP") {
+			action.HangupAll()
+			AlarmHandleICP(packet)
+		}
+
 	default:
 	default:
 		fmt.Printf("Unknown command: %x\n", packet[5])
 		fmt.Printf("Unknown command: %x\n", packet[5])
 	}
 	}
@@ -114,14 +152,11 @@ func StationAnn(data []byte) (err error) {
 
 
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
 
 
-	//update stn voice
-	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{Special: specialVoice, PaType: "STN"})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-		return er
-	}
+	//set spc voice tag
+	priority.SpecialVoice = specialVoice
 
 
 	//Pa status report
 	//Pa status report
+	priority.RunningType, _ = strconv.Atoi(priority.Priority.STN)
 	alstatus.PaStatus("", "STN", "start")
 	alstatus.PaStatus("", "STN", "start")
 
 
 	action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
 	action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
@@ -199,13 +234,8 @@ func SpecialAnn(data []byte) {
 
 
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 	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())
-	}
-
 	//Pa status report
 	//Pa status report
+	priority.RunningType, _ = strconv.Atoi(priority.Priority.SPCTMS)
 	alstatus.PaStatus("", "SPC", "start")
 	alstatus.PaStatus("", "SPC", "start")
 
 
 	if int(cycleCount) == 255 {
 	if int(cycleCount) == 255 {
@@ -223,13 +253,8 @@ func EmgMsg(data []byte) {
 
 
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 	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())
-	}
-
 	//Pa status report
 	//Pa status report
+	priority.RunningType, _ = strconv.Atoi(priority.Priority.EMGTMS)
 	alstatus.PaStatus("", "EMG", "start")
 	alstatus.PaStatus("", "EMG", "start")
 
 
 	if int(cycleCount) == 255 {
 	if int(cycleCount) == 255 {
@@ -242,32 +267,34 @@ func EmgMsg(data []byte) {
 // 停止指定类型广播
 // 停止指定类型广播
 func AnnStop(data [4]byte) {
 func AnnStop(data [4]byte) {
 
 
-	RunningType := ""
+	PaType := ""
 
 
 	switch data[0] {
 	switch data[0] {
 	case 0x03:
 	case 0x03:
-		RunningType = "DCS"
+		PaType = "DCS"
 	case 0x04:
 	case 0x04:
-		RunningType = "EMG"
+		PaType = "EMG"
 	case 0x07:
 	case 0x07:
-		RunningType = "SPC"
+		PaType = "SPC"
 	case 0x08:
 	case 0x08:
-		RunningType = "STN"
+		PaType = "STN"
 	case 0x09:
 	case 0x09:
-		RunningType = "CHK"
+		PaType = "CHK"
 	}
 	}
 
 
-	alstatus.PaStatus("", RunningType, "end")
-
-	for _, ext := range Pacus {
-		action.Hangup(ext)
-	}
-
-	//update pa type
-	_, er := mysql.DBOrmInstance.Cols("patype").Where("pa_type = ?", RunningType).Update(&model.Extension{PaType: ""})
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
+	priority.RunningType = 0
+	alstatus.PaStatus("", PaType, "end")
+	/*
+		for _, ext := range Pacus {
+			action.Hangup(ext)
+		}
+		//update pa type
+		_, er := mysql.DBOrmInstance.Cols("patype").Where("pa_type = ?", RunningType).Update(&model.Extension{PaType: ""})
+		if er != nil {
+			lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+		}
+	*/
+	action.HangupAll()
 
 
 }
 }
 
 
@@ -279,13 +306,8 @@ func DcsAnn(data []byte) {
 
 
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 	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())
-	}
-
 	//Pa status report
 	//Pa status report
+	priority.RunningType, _ = strconv.Atoi(priority.Priority.DCS)
 	alstatus.PaStatus("", "DCS", "start")
 	alstatus.PaStatus("", "DCS", "start")
 
 
 	if int(cycleCount) == 255 {
 	if int(cycleCount) == 255 {
@@ -295,8 +317,8 @@ func DcsAnn(data []byte) {
 	}
 	}
 }
 }
 
 
-// 自检广播
-func SelfCheck(data []byte) {
+// 调音广播
+func VolumeAdjust(data []byte) {
 
 
 	check := data[8]
 	check := data[8]
 	delay := data[9]
 	delay := data[9]
@@ -305,28 +327,59 @@ func SelfCheck(data []byte) {
 
 
 	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
 	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())
+	switch check {
+	case 0x01: //start
+
+		//Pa status report
+		priority.RunningType, _ = strconv.Atoi(priority.Priority.CHK)
+		alstatus.PaStatus("", "VOL", "start")
+		action.PlaybackPacu(filename, int(cycleCount), int(delay), "VOL")
+	case 0x02: //stop
+
+		/*		//Pa status report
+				priority.RunningType = 0
+				alstatus.PaStatus("", "VOL", "end")
+
+				for _, ext := range Pacus {
+					asterisk.Hangup(ext)
+				}
+				asterisk.Hangup("2311")
+				asterisk.Hangup("2381")
+		*/
+		action.HangupAll()
 	}
 	}
+}
+
+// 自检广播
+func SelfCheck(data []byte) {
+
+	check := data[8]
+	delay := data[9]
+	cycleCount := data[10]
+	datalen := int(data[11])
+
+	filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
 
 
 	switch check {
 	switch check {
 	case 0x01: //start
 	case 0x01: //start
 
 
 		//Pa status report
 		//Pa status report
+		priority.RunningType, _ = strconv.Atoi(priority.Priority.CHK)
 		alstatus.PaStatus("", "CHK", "start")
 		alstatus.PaStatus("", "CHK", "start")
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
 	case 0x02: //stop
 	case 0x02: //stop
 
 
 		//Pa status report
 		//Pa status report
+		priority.RunningType = 0
 		alstatus.PaStatus("", "CHK", "end")
 		alstatus.PaStatus("", "CHK", "end")
-
-		for _, ext := range Pacus {
-			asterisk.Hangup(ext)
-		}
-		asterisk.Hangup("2311")
-		asterisk.Hangup("2381")
+		/*
+			for _, ext := range Pacus {
+				asterisk.Hangup(ext)
+			}
+			asterisk.Hangup("2311")
+			asterisk.Hangup("2381")
+		*/
+		action.HangupAll()
 	}
 	}
 }
 }
 
 
@@ -385,10 +438,11 @@ func AlarmHandleICP(data []byte) {
 
 
 	case 0x03: //hangup
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
 		//NotifyPaiu(exten, "hangup")
-		action.Hangup(exten)  //Pad
-		action.Hangup("2311") //1 车接听
-		action.Hangup("2381") //8 车接听
-
+		/*		action.Hangup(exten)  //Pad
+				action.Hangup("2311") //1 车接听
+				action.Hangup("2381") //8 车接听
+		*/
+		action.HangupAll()
 	}
 	}
 }
 }
 
 
@@ -446,9 +500,11 @@ func AlarmHandleTMS(data []byte) {
 
 
 	case 0x03: //hangup
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
 		//NotifyPaiu(exten, "hangup")
-		action.Hangup(exten)  //PAD
+		/*action.Hangup(exten)  //PAD
 		action.Hangup("2311") //1 车接听
 		action.Hangup("2311") //1 车接听
 		action.Hangup("2381") //8 车接听
 		action.Hangup("2381") //8 车接听
+		*/
+		action.HangupAll()
 	}
 	}
 }
 }
 
 
@@ -495,6 +551,7 @@ func AlarmHoldResetAll(data byte) {
 		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
 		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
 	}
 	}
 
 
+	//all hold
 	if data == 1 {
 	if data == 1 {
 		for _, ext := range AlarmExts {
 		for _, ext := range AlarmExts {
 			err := action.RedirectInQueue(ext.Extension, "0300", "default", "1")
 			err := action.RedirectInQueue(ext.Extension, "0300", "default", "1")
@@ -510,7 +567,7 @@ func AlarmHoldResetAll(data byte) {
 			action.Hangup("2381")                   //8 车接听
 			action.Hangup("2381")                   //8 车接听
 			alstatus.AlarmStatus("0000", "allhold") // send all hold status
 			alstatus.AlarmStatus("0000", "allhold") // send all hold status
 		}
 		}
-	} else if data == 2 {
+	} else if data == 2 { //all reset
 		for _, ext := range AlarmExts {
 		for _, ext := range AlarmExts {
 			action.Hangup(ext.Extension)
 			action.Hangup(ext.Extension)
 		}
 		}
@@ -537,8 +594,8 @@ func RecordStorageConf(data []byte) {
 	info.PadRcdDelDays = int(data[4])
 	info.PadRcdDelDays = int(data[4])
 	info.PaRcdDelDays = int(data[5])
 	info.PaRcdDelDays = int(data[5])
 	info.CpaRcdDelDays = int(data[6])
 	info.CpaRcdDelDays = int(data[6])
-	info.OpaRcdStorageDays = int(data[7])
-	info.OpaRcdDelDays = int(data[8])
+	//info.OpaRcdStorageDays = int(data[7])
+	//info.OpaRcdDelDays = int(data[8])
 
 
 	//lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
 	//lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
 
 

+ 93 - 1
internal/app/stc/priority/index.go

@@ -1,6 +1,98 @@
 package priority
 package priority
 
 
+import (
+	"os"
+	"strconv"
+
+	"github.com/sirupsen/logrus"
+	"gopkg.in/ini.v1"
+)
+
 var ICPAnswer = 0
 var ICPAnswer = 0
 var OCCAnswer = 0
 var OCCAnswer = 0
+var RunningType = 0
+var SpecialVoice = 0
+
+type PriorityAll struct {
+	ManuPa string `json:"manualPa"`
+	CabCab string `json:"cabCab"`
+	PADICP string `json:"padIcp"`
+	PADTMS string `json:"padTms"`
+	PADOCC string `json:"padOcc"`
+	CPA    string `json:"cpa"`
+	EMGTMS string `json:"emgTms"`
+	SPCTMS string `json:"spcTms"`
+	DCS    string `json:"dcs"`
+	STN    string `json:"stn"`
+	CHK    string `json:"chk"`
+}
+
+var Priority PriorityAll
+
+func GetPriority() {
+	filePath := "/etc/asterisk/priority.conf"
+	_, err := os.Stat(filePath)
+	if err != nil {
+		logrus.Error(err)
+		return
+	}
+	iniFile, err := ini.Load(filePath)
+	if err != nil {
+		logrus.Error(err)
+		return
+	}
+
+	Priority.CHK = iniFile.Section("general").Key("ManuPa").Value()
+	Priority.STN = iniFile.Section("general").Key("CabCab").Value()
+	Priority.DCS = iniFile.Section("general").Key("PAD-ICP").Value()
+	Priority.SPCTMS = iniFile.Section("general").Key("PAD-TMS").Value()
+	Priority.EMGTMS = iniFile.Section("general").Key("PAD-OCC").Value()
+	Priority.CPA = iniFile.Section("general").Key("CPA").Value()
+	Priority.PADOCC = iniFile.Section("general").Key("EMG-TMS").Value()
+	Priority.PADTMS = iniFile.Section("general").Key("SPC-TMS").Value()
+	Priority.PADICP = iniFile.Section("general").Key("DCS").Value()
+	Priority.CabCab = iniFile.Section("general").Key("STN").Value()
+	Priority.ManuPa = iniFile.Section("general").Key("CHK").Value()
+}
+
+func GetPriorityByKey(key string) string {
+	filePath := "/etc/asterisk/priority.conf"
+	_, err := os.Stat(filePath)
+	if err != nil {
+		logrus.Error(err)
+		return ""
+	}
+	iniFile, err := ini.Load(filePath)
+	if err != nil {
+		logrus.Error(err)
+		return ""
+	}
+
+	return iniFile.Section("general").Key(key).Value()
+}
+
+// check priority , if the running priority is lowwer than the to run priority
+func CheckPriority(runType string) bool {
+	//check special voice
+	if SpecialVoice == 1 {
+		return false
+	}
+
+	//no any runing task
+	if RunningType == 0 {
+		return true
+	}
+
+	//get the priority to run in the config file
+	ret, err := strconv.Atoi(GetPriorityByKey(runType))
+	if err != nil {
+		logrus.Error(err)
+		return false
+	}
 
 
-//path = "/etc/asterisk/priority.conf"
+	//if the running task priority is lowwer
+	if ret < RunningType && ret != 0 {
+		return true
+	}
+	return false
+}

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

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