Browse Source

update priority

dujunchen 6 ngày trước cách đây
mục cha
commit
5cbdccb50e

+ 4 - 8
api/panel/asterisk/meetme.go

@@ -1,18 +1,14 @@
 package asterisk
 
 import (
-	"errors"
 	"fmt"
 	"net/http"
 	"pbx-api-gin/api/model"
 	"pbx-api-gin/internal/app/ami/action"
-	amiModel "pbx-api-gin/internal/app/ami/model"
-	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/pkg/lfshook"
 	"strings"
 
 	"github.com/gin-gonic/gin"
-	"github.com/mitchellh/mapstructure"
 )
 
 // @tags Asterisk-MeetMe
@@ -23,7 +19,7 @@ import (
 // @Produce  json
 // @Success 200 {object} model.APIOK "请求成功"
 // @Router /ginapi/plugin-asterisk/meetme/list [get]
-func listMeetMe(ctx *gin.Context) {
+/*func listMeetMe(ctx *gin.Context) {
 	amiRooms, _ := action.ListRoomMeetMe(make(map[string]string))
 
 	var meets []model.MeetMe
@@ -50,7 +46,7 @@ func listMeetMe(ctx *gin.Context) {
 	}
 	ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: rooms})
 }
-
+*/
 // @tags Asterisk-MeetMe
 // @Summary 查看指定会议室
 // @Description 会议室信息
@@ -60,7 +56,7 @@ func listMeetMe(ctx *gin.Context) {
 // @Param conference query string true "会议室号"
 // @Success 200 {object} model.APIOK "请求成功"
 // @Router /ginapi/plugin-asterisk/meetme/room [get]
-func room(ctx *gin.Context) {
+/*func room(ctx *gin.Context) {
 	conference := ctx.Query("conference")
 	if conference == "" {
 		ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: errors.New("conference is empty").Error()})
@@ -93,7 +89,7 @@ func room(ctx *gin.Context) {
 	mapstructure.Decode(roomInfo, room)
 	ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: gin.H{"items": items, "room": room}})
 }
-
+*/
 // @tags Asterisk-MeetMe
 // @Summary 邀请会议
 // @Description 邀请会议

+ 68 - 5
internal/app/ami/action/call.go

@@ -8,6 +8,12 @@ import (
 	"time"
 )
 
+var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "2425", "2431", "2432", "2433", "2434", "2435", "2441", "2442", "2443", "2444",
+	"2445", "2451", "2452", "2453", "2454", "2455", "2461", "2462", "2463", "2464", "2465", "2471", "2472", "2473", "2474", "2475", "2481", "2482", "2483",
+	"2484", "2485", "2411", "2412"}
+
+var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
+
 // Hangup 挂断指定分机或通道
 func Hangup(channel string) {
 	lfshook.NewLogger().Infof("hangup extensions/channel %s", channel)
@@ -25,20 +31,77 @@ func Hangup(channel string) {
 	}
 }
 
-// Hangup 挂断所有分机
-func HangupAll() {
-	var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
+// Hangup 挂断所有分机,除指定分机和PAD
+func HangupAllExcept(caller string) {
+
 	//all PACU
 	for _, ret := range Pacus {
 		Hangup(ret)
 	}
 
-	Hangup("1411") //IO1
-	Hangup("1481") //IO8
+	switch caller {
+	case "2311":
+		Hangup("1411") //IO1
+		Hangup("1481") //IO8
+		//Hangup("2311") //ICP1
+		Hangup("2381") //ICP8
+	case "2381":
+		Hangup("1411") //IO1
+		Hangup("1481") //IO8
+		Hangup("2311") //ICP1
+		//Hangup("2381") //ICP8
+	case "1411":
+		//Hangup("1411") //IO1
+		Hangup("1481") //IO8
+		Hangup("2311") //ICP1
+		Hangup("2381") //ICP8
+	case "1481":
+		Hangup("1411") //IO1
+		//Hangup("1481") //IO8
+		Hangup("2311") //ICP1
+		Hangup("2381") //ICP8
+	case "":
+		Hangup("1411") //IO1
+		Hangup("1481") //IO8
+		Hangup("2311") //ICP1
+		Hangup("2381") //ICP8
+	}
+}
+
+// Hangup all ICP
+func HangupICP() {
 	Hangup("2311") //ICP1
 	Hangup("2381") //ICP8
 }
 
+// Hangup all IO
+func HangupIO() {
+	Hangup("1411") //IO1
+	Hangup("1481") //IO8
+}
+
+// Hangup all PACU
+func HangupAllPACU() {
+	//all PACU
+	for _, ret := range Pacus {
+		Hangup(ret)
+	}
+}
+
+// Hangup all PACU
+func HangupAllPAD() {
+	//all PAD
+	for _, ret := range Pads {
+		Hangup(ret)
+	}
+}
+
+// Hangup all calls
+func HangupAll() {
+
+	utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "hangup request all")
+}
+
 // Dial 拨打号码
 func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
 	chanel := fmt.Sprintf("%s/%s@default", "Local", src)

+ 108 - 35
internal/app/ami/action/index.go

@@ -17,8 +17,6 @@ import (
 
 var AminInstance *amigo.Amigo
 
-//type Operation func(src, dst string, whisper, bargein bool)
-
 func HandleAMI(event map[string]string) {
 	//lfshook.NewLogger().Infof("===start======%s", event["Event"])
 	//return if not actived
@@ -28,60 +26,100 @@ func HandleAMI(event map[string]string) {
 
 	switch event["Event"] {
 
-	case "UserEvent":
+	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" { //check manual PA priority
-			if priority.CheckPriority("ManuPa") {
-				HangupAll()
+
+		} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA; check manual PA priority
+			//check active signal  before PA
+			if active.CabNum == "1" && !active.Actived && event["CallerIDNum"] == "2311" {
+				Hangup(event["CallerIDNum"])
+			} else if active.CabNum == "8" && !active.Actived && event["CallerIDNum"] == "2381" {
+				Hangup(event["CallerIDNum"])
+			}
+
+			//PA & CPA interrupt others
+			if utils.IsICP(event["CallerIDNum"]) {
+				if priority.CheckPriority("ManuPa") {
+					HangupAllExcept(event["CallerIDNum"]) //hangup others if priority is higher
+				} else {
+					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
+				}
+			} else if utils.IsIO(event["CallerIDNum"]) { // CPA
+				if priority.CheckPriority("CPA") {
+					HangupAllExcept(event["CallerIDNum"]) //hangup others if priority is higher
+				} else {
+					Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
+				}
 			}
-		} else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //check cab cab priority
+		} else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab; check cab cab priority
+			//priority.RunningTypePriority = 3 PAD---PAD back to queue
+			//priority.RunningTypePriority = 4 CPA
+
 			if priority.CheckPriority("CabCab") {
-				HangupAll()
+				if event["CallerIDNum"] == "2311" { //cab1 call cab8
+					if ExtenStatus("2381") == "InUse" {
+						Hangup("2381")
+					}
+				} else {
+					if ExtenStatus("2311") == "InUse" { // cab8 call cab1
+						Hangup("2311")
+					}
+				}
 			}
 		}
 
 	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
-			priority.RunningType, _ = strconv.Atoi(priority.Priority.PADICP)
+			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADICP)
 			alstatus.PaStatus(event["CallerIDNum"], "PAD", "start")
 			alstatus.AlarmStatus(event["CallerIDNum"], "dial")
 		}
 
 	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
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
+			priority.RunningType = ""
+
 			alstatus.PaStatus(event["CallerIDName"], "EMG", "end")
 
 		} else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
+			priority.RunningType = ""
 			priority.SpecialVoice = 0
 			alstatus.PaStatus(event["CallerIDName"], "STN", "end")
 
 		} else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
+			priority.RunningType = ""
 			alstatus.PaStatus(event["CallerIDName"], "DCS", "end")
 
 		} else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
+			priority.RunningType = ""
 			alstatus.PaStatus(event["CallerIDName"], "SPC", "end")
 
 		} else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
+			priority.RunningType = ""
 			alstatus.PaStatus(event["CallerIDName"], "CHK", "end")
+		} else if event["CallerIDName"] == "VOL" && event["Exten"] == "0510" {
+			priority.RunningTypePriority = 0
+			priority.RunningType = ""
+			alstatus.PaStatus(event["CallerIDName"], "VOL", "end")
 		}
 
 	case "Hangup":
 
-		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsPACU(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) { // TMS-ICP answer PAD, hangup
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			if res.Calls == "0" {
 				priority.ICPAnswer = 0
-				priority.RunningType = 0
+				priority.RunningTypePriority = 0
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				break
 			}
@@ -91,7 +129,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			if res.Calls == "0" {
 				priority.ICPAnswer = 0
-				priority.RunningType = 0
+				priority.RunningTypePriority = 0
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				break
 			}
@@ -101,7 +139,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
 			if res.Calls == "0" {
 				priority.ICPAnswer = 0
-				priority.RunningType = 0
+				priority.RunningTypePriority = 0
 				alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 				break
 			}
@@ -112,7 +150,7 @@ func HandleAMI(event map[string]string) {
 			res, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
 			if res.Calls == "0" {             //OCC queue is empty
 				priority.OCCAnswer = 0
-				priority.RunningType = 0
+				priority.RunningTypePriority = 0
 				alstatus.OccPad("end")
 				break
 			} else { //OCC queue is not empty
@@ -161,16 +199,19 @@ func HandleAMI(event map[string]string) {
 		}
 
 		//first PAD caller goto OCC
+		//PACUs dial OCC;
+		//PAD chanspy(WqE) OCC;
+		//ICPs chanspy(qE) PAD;
 		if utils.IsPAIU(event["CallerIDNum"]) && event["Queue"] == "0301" && priority.OCCAnswer == 0 { // The first PAD to OCC ,caller is PAD
 			if active.CabNum == "1" && active.Actived && ExtenStatus("1411") == "Idle" { //check active and OCC status
 				priority.OCCAnswer = 1
 				alstatus.OccPad("start")
-				priority.RunningType, _ = strconv.Atoi(priority.Priority.PADOCC)              //Set running priority
+				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADOCC)      //Set running priority
 				Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", event["CallerIDNum"], "1") // PACUs dial OCC1
 				//Goto event=ConfbridgeJoin;OCC answer PAD
 			} else if active.CabNum == "8" && active.Actived && ExtenStatus("1481") == "Idle" {
 				priority.OCCAnswer = 1
-				priority.RunningType, _ = strconv.Atoi(priority.Priority.PADOCC) //Set running priority
+				priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.PADOCC) //Set running priority
 				alstatus.OccPad("start")
 				Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", event["CallerIDNum"], "8") // PACUs dial OCC8
 				//Goto event=ConfbridgeJoin;OCC answer PAD
@@ -179,20 +220,49 @@ func HandleAMI(event map[string]string) {
 
 	case "ConfbridgeJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		//Send PA start msg to STC
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
 			lfshook.NewLogger().Infof("====PA status:%s=====", "start")
-			priority.RunningType, _ = strconv.Atoi(priority.Priority.ManuPa)
+			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.ManuPa)
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
+			priority.RunningType = "PA"
 			break
-		}
-
-		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
+		} else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
 			lfshook.NewLogger().Infof("====CPA status:%s=====", "start")
-			priority.RunningType, _ = strconv.Atoi(priority.Priority.CPA)
+			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CPA)
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
+			priority.RunningType = "CPA"
 			break
 		}
 
+		//set priority and send PA status msg
+		switch event["CallerIDName"] {
+		case "EMG":
+			alstatus.PaStatus(event["CallerIDNum"], "EMG", "start")
+			priority.RunningPATaskChan = event["Channel"]
+			priority.RunningType = "EMG"
+		case "SPC":
+			alstatus.PaStatus(event["CallerIDNum"], "SPC", "start")
+			priority.RunningPATaskChan = event["Channel"]
+			priority.RunningType = "SPC"
+		case "DCS":
+			alstatus.PaStatus(event["CallerIDNum"], "DCS", "start")
+			priority.RunningPATaskChan = event["Channel"]
+			priority.RunningType = "DCS"
+		case "STN":
+			alstatus.PaStatus(event["CallerIDNum"], "STN", "start")
+			priority.RunningPATaskChan = event["Channel"]
+			priority.RunningType = "STN"
+		case "CHK":
+			alstatus.PaStatus(event["CallerIDNum"], "CHK", "start")
+			priority.RunningPATaskChan = event["Channel"]
+			priority.RunningType = "CHK"
+		case "VOL":
+			alstatus.PaStatus(event["CallerIDNum"], "VOL", "start")
+			priority.RunningPATaskChan = event["Channel"]
+			priority.RunningType = "VOL"
+		}
+
 		//ICP answer PAD;
 		if event["ConnectedLineNum"] == "ani1" && event["Exten"] == "0511" { //PAD answered by ICP; PACUs connected ICP1
 			lfshook.NewLogger().Infof("====PAD answered by ICP1:%s=====", event["ConnectedLineName"])
@@ -242,37 +312,40 @@ func HandleAMI(event map[string]string) {
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
 			lfshook.NewLogger().Infof("====PA  status =====%s", "end")
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
 			alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
 		}
 		if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
 			lfshook.NewLogger().Infof("====CPA  status =====%s", "end")
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
 			alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
 		}
 
 	case "DialEnd":
-		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab start
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
-			priority.RunningType, _ = strconv.Atoi(priority.Priority.CabCab)
+			priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
 		}
 
 	case "BridgeLeave":
-		lfshook.NewLogger().Infof("=========%s", event["Event"])
+		//lfshook.NewLogger().Infof("=========%s", event["Event"])
 		//Cab Cab end
 		if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
-			priority.RunningType = 0
+			priority.RunningTypePriority = 0
 			alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
 		}
 
 	case "ExtensionStatus":
-		lfshook.NewLogger().Infof("=========event:%s  Ext:%s status:%s ", event["Event"], event["extension"], event["StatusText"])
+		//lfshook.NewLogger().Infof("=========event:%s  Ext:%s status:%s ", event["Event"], event["Exten"], event["StatusText"])
 
 		//update extension status
 		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
 			if len(event["Exten"]) > 3 && utils.IsPAIU(event["Exten"]) {
+				alstatus.ExtenStatMap[event["Exten"]] = event["StatusText"]
+
+				//lfshook.NewLogger().Infof("======Extension Map : %+v==============", alstatus.ExtenStatMap)
 				alstatus.AlarmStatus(event["Exten"], event["StatusText"]) // PAD idle + unavailable
 			}
 		}

+ 9 - 13
internal/app/ami/model/cdr.go

@@ -24,17 +24,13 @@ type Cdr struct {
 }
 
 type RcdConf struct {
-	PadRcdEnable      int `xorm:"pad_rcd_enable" json:"padRcdEnable"`
-	PadRcdStorageDays int `xorm:"pad_rcdstorage_days" json:"padRcdStorageDays"`
-	PaRcdStorageDays  int `xorm:"pa_rcdstorage_days" json:"paRcdStorageDays"`
-	CpaRcdStorageDays int `xorm:"cpa_rcdstorage_days" json:"cpaRcdStorageDays"`
-	OpaRcdStorageDays int `xorm:"opa_rcdstorage_days" json:"opaRcdStorageDays"`
-	PadRcdDelDays     int `xorm:"pad_rcd_del" json:"pad_rcd_del_days"`
-	PaRcdDelDays      int `xorm:"pa_rcd_del" json:"pa_rcd_del_days"`
-	CpaRcdDelDays     int `xorm:"cpa_rcd_del" json:"cpa_rcd_del_days"`
-	OpaRcdDelDays     int `xorm:"opa_rcd_del" json:"opa_rcd_del_days"`
-}
-
-func (*RcdConf) TableName() string {
-	return "t_record_conf"
+	PadRcdEnable      string `json:"padRcdEnable"`
+	PadRcdStorageDays string `json:"padRcdStorageDays"`
+	PaRcdStorageDays  string `json:"paRcdStorageDays"`
+	CpaRcdStorageDays string `json:"cpaRcdStorageDays"`
+	OpaRcdStorageDays string `json:"opaRcdStorageDays"`
+	PadRcdDelDays     string `json:"pad_rcd_del_days"`
+	PaRcdDelDays      string `json:"pa_rcd_del_days"`
+	CpaRcdDelDays     string `json:"cpa_rcd_del_days"`
+	OpaRcdDelDays     string `json:"opa_rcd_del_days"`
 }

+ 140 - 87
internal/app/stc/broadcast/stc-broadcast.go

@@ -7,9 +7,9 @@ import (
 	"io"
 	"net"
 	"net/http"
+	"os"
 	"pbx-api-gin/internal/app/ami/action"
 	"pbx-api-gin/internal/app/ami/model"
-	"pbx-api-gin/internal/app/mysql"
 	"pbx-api-gin/internal/app/stc/active"
 	msgdata "pbx-api-gin/internal/app/stc/data"
 	"pbx-api-gin/internal/app/stc/priority"
@@ -18,9 +18,10 @@ import (
 	"strconv"
 	"sync"
 	"time"
-)
 
-var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
+	"github.com/sirupsen/logrus"
+	"gopkg.in/ini.v1"
+)
 
 func HandleStcCmd(ctx context.Context, conn net.Conn) {
 
@@ -85,56 +86,82 @@ func processPacket(packet []byte) {
 
 	case 0x02: // STN
 		if priority.CheckPriority("STN") {
-			action.HangupAll()
+			action.HangupICP()
+			if len(priority.RunningPATaskChan) > 0 {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
 			StationAnn(packet)
 		}
 
 	case 0x05: // SPC
-		if priority.CheckPriority("SPC-TMS") {
-			action.HangupAll()
+		if priority.CheckPriority("SPC") {
+			action.HangupICP()
+			if len(priority.RunningPATaskChan) > 0 {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
 			SpecialAnn(packet)
 		}
 
 	case 0x06: // EMG
-		EmgMsg(packet)
-
+		if priority.CheckPriority("EMG") {
+			action.HangupICP()
+			if len(priority.RunningPATaskChan) > 0 {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+			EmgMsg(packet)
+		}
 	case 0x07: // STOP
 		AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
 
 	case 0x08: // DCS
 		if priority.CheckPriority("DCS") {
-			action.HangupAll()
+			action.HangupICP()
+			if len(priority.RunningPATaskChan) > 0 {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
 			DcsAnn(packet)
 		}
 
 	case 0x09: // SELF CHECK
 		if priority.CheckPriority("CHK") {
-			action.HangupAll()
+			action.HangupICP()
+			if len(priority.RunningPATaskChan) > 0 {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
 			SelfCheck(packet)
 		}
 
-	case 0x10: // SELF CHECK
-		if priority.CheckPriority("CHK") {
-			action.HangupAll()
+	case 0x10: // VOLUME Adjust
+		if priority.CheckPriority("VOL") {
+			action.HangupICP()
+			if len(priority.RunningPATaskChan) > 0 {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
 			VolumeAdjust(packet)
 		}
 
 	case 0x0a:
 		if priority.CheckPriority("PAD-TMS") {
-			action.HangupAll()
+			action.HangupAllExcept("")
 			//AlarmHandleTMS(packet)
 			AlarmHandleICP(packet) //for test
 		}
 
 	case 0x0b:
-		AlarmHoldResetAll(packet[8])
+		AlarmHoldResetAll(packet[8]) // reset all pad
 
 	case 0x0c:
-		RecordStorageConf(packet[8:])
+		RecordStorageConf(packet[8:]) // RCD setting
 
 	case 0x0d:
 		if priority.CheckPriority("PAD-ICP") {
-			action.HangupAll()
+			action.HangupAllExcept("")
 			AlarmHandleICP(packet)
 		}
 
@@ -157,7 +184,7 @@ func StationAnn(data []byte) (err error) {
 	priority.SpecialVoice = specialVoice
 
 	//Pa status report
-	priority.RunningType, _ = strconv.Atoi(priority.Priority.STN)
+	priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.STN)
 	alstatus.PaStatus("", "STN", "start")
 
 	action.PlaybackPacu(filename, int(cycleCount), int(delay), "STN")
@@ -236,7 +263,7 @@ func SpecialAnn(data []byte) {
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 
 	//Pa status report
-	priority.RunningType, _ = strconv.Atoi(priority.Priority.SPCTMS)
+	priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.SPC)
 	alstatus.PaStatus("", "SPC", "start")
 
 	if int(cycleCount) == 255 {
@@ -255,7 +282,7 @@ func EmgMsg(data []byte) {
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 
 	//Pa status report
-	priority.RunningType, _ = strconv.Atoi(priority.Priority.EMGTMS)
+	priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.EMG)
 	alstatus.PaStatus("", "EMG", "start")
 
 	if int(cycleCount) == 255 {
@@ -268,24 +295,55 @@ func EmgMsg(data []byte) {
 // 停止指定类型广播
 func AnnStop(data [4]byte) {
 
-	PaType := ""
-
+	//PaType := ""
+	lfshook.NewLogger().Logger.Infof("==priority.RunningType:%s======priority.RunningPATaskChan:%s=============", priority.RunningType, priority.RunningPATaskChan)
 	switch data[0] {
 	case 0x03:
-		PaType = "DCS"
+		if priority.RunningType == "DCS" {
+			if priority.RunningPATaskChan != "" {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+		}
 	case 0x04:
-		PaType = "EMG"
+		if priority.RunningType == "EMG" {
+			if priority.RunningPATaskChan != "" {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+		}
 	case 0x07:
-		PaType = "SPC"
+		if priority.RunningType == "SPC" {
+			if priority.RunningPATaskChan != "" {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+		}
 	case 0x08:
-		PaType = "STN"
+		if priority.RunningType == "STN" {
+			if priority.RunningPATaskChan != "" {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+		}
 	case 0x09:
-		PaType = "CHK"
+		if priority.RunningType == "CHK" {
+			if priority.RunningPATaskChan != "" {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+		}
+	case 0x10:
+		if priority.RunningType == "VOL" {
+			if priority.RunningPATaskChan != "" {
+				action.Hangup(priority.RunningPATaskChan)
+				priority.RunningPATaskChan = ""
+			}
+		}
 	}
 
-	priority.RunningType = 0
-	alstatus.PaStatus("", PaType, "end")
-	action.HangupAll()
+	//alstatus.PaStatus("", PaType, "end")
+	//action.HangupAllExcept("")
 
 }
 
@@ -298,7 +356,7 @@ func DcsAnn(data []byte) {
 	filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
 
 	//Pa status report
-	priority.RunningType, _ = strconv.Atoi(priority.Priority.DCS)
+	priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.DCS)
 	alstatus.PaStatus("", "DCS", "start")
 
 	if int(cycleCount) == 255 {
@@ -322,13 +380,13 @@ func VolumeAdjust(data []byte) {
 	case 0x01: //start
 
 		//Pa status report
-		priority.RunningType, _ = strconv.Atoi(priority.Priority.CHK)
+		priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CHK)
 		alstatus.PaStatus("", "VOL", "start")
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "VOL")
 	case 0x02: //stop
 
 		alstatus.PaStatus("", "VOL", "end")
-		action.HangupAll()
+		action.HangupAllExcept("")
 	}
 }
 
@@ -346,15 +404,15 @@ func SelfCheck(data []byte) {
 	case 0x01: //start
 
 		//Pa status report
-		priority.RunningType, _ = strconv.Atoi(priority.Priority.CHK)
+		priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CHK)
 		alstatus.PaStatus("", "CHK", "start")
 		action.PlaybackPacu(filename, int(cycleCount), int(delay), "CHK")
 	case 0x02: //stop
 
 		//Pa status report
-		priority.RunningType = 0
+		priority.RunningTypePriority = 0
 		alstatus.PaStatus("", "CHK", "end")
-		action.HangupAll()
+		action.HangupAllExcept("")
 	}
 }
 
@@ -418,11 +476,10 @@ func AlarmHandleICP(data []byte) {
 
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
-		/*		action.Hangup(exten)  //Pad
-				action.Hangup("2311") //1 车接听
-				action.Hangup("2381") //8 车接听
-		*/
-		action.HangupAll()
+		action.Hangup(exten)  //Pad
+		action.Hangup("2311") //1 车接听
+		action.Hangup("2381") //8 车接听
+
 	}
 }
 
@@ -484,11 +541,9 @@ func AlarmHandleTMS(data []byte) {
 
 	case 0x03: //hangup
 		//NotifyPaiu(exten, "hangup")
-		/*action.Hangup(exten)  //PAD
+		action.Hangup(exten)  //PAD
 		action.Hangup("2311") //1 车接听
 		action.Hangup("2381") //8 车接听
-		*/
-		action.HangupAll()
 	}
 }
 
@@ -526,67 +581,65 @@ func NotifyPaiu(Exten, Action string) {
 }
 
 // 挂断所有报警器
-func AlarmHoldResetAll(data byte) {
-
-	var AlarmExts []model.Extension
-
-	er := mysql.DBOrmInstance.Where("dev_type = ? and status != ?", "PAIU", "Idle").Find(&AlarmExts)
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
-	}
+func AlarmHoldResetAll(handler byte) {
 
 	//all hold
-	if data == 1 {
-		for _, ext := range AlarmExts {
-			err := action.RedirectInQueue(ext.Extension, "0300", "default", "1")
-			if err != nil {
-				lfshook.NewLogger().Info(err)
-			}
-		}
 
-		if active.CabNum == "1" && active.Actived {
-			action.Hangup("2311")                   //1 车接听
-			alstatus.AlarmStatus("0000", "allhold") //send all hold status
-		} else if active.CabNum == "8" && active.Actived {
-			action.Hangup("2381")                   //8 车接听
-			alstatus.AlarmStatus("0000", "allhold") // send all hold status
-		}
-	} else if data == 2 { //all reset
-		for _, ext := range AlarmExts {
-			action.Hangup(ext.Extension)
+	//hangup all actived PAD
+	for ext, stat := range alstatus.ExtenStatMap {
+		if stat != "Idle" && stat != "Unavailable" {
+			action.Hangup(ext)
 		}
+	}
 
-		if active.CabNum == "1" && active.Actived {
-			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") // send all reset status
-		}
+	if active.CabNum == "1" && active.Actived {
+		action.Hangup("2311") //1 车接听
+		action.Hangup("1411")
+		alstatus.AlarmStatus("0000", "allreset") //send all reset status
+	} else if active.CabNum == "8" && active.Actived {
+		action.Hangup("2381") //8 车接听
+		action.Hangup("1481")
+		alstatus.AlarmStatus("0000", "allreset") // send all reset status
 	}
+
 }
 
 func RecordStorageConf(data []byte) {
 
 	var info model.RcdConf
 
-	info.PadRcdEnable = int(data[0])
-	info.PadRcdStorageDays = int(data[1])
-	info.PaRcdStorageDays = int(data[2])
-	info.CpaRcdStorageDays = int(data[3])
+	info.PadRcdEnable = strconv.Itoa(int(data[0]))
+	info.PadRcdStorageDays = strconv.Itoa(int(data[1]))
+	info.PaRcdStorageDays = strconv.Itoa(int(data[2]))
+	info.CpaRcdStorageDays = strconv.Itoa(int(data[3]))
 
-	info.PadRcdDelDays = int(data[4])
-	info.PaRcdDelDays = int(data[5])
-	info.CpaRcdDelDays = int(data[6])
+	info.PadRcdDelDays = strconv.Itoa(int(data[4]))
+	info.PaRcdDelDays = strconv.Itoa(int(data[5]))
+	info.CpaRcdDelDays = strconv.Itoa(int(data[6]))
 	//info.OpaRcdStorageDays = int(data[7])
 	//info.OpaRcdDelDays = int(data[8])
 
 	//lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
 
-	//update record config
-	_, er := mysql.DBOrmInstance.AllCols().Update(&info)
-	if er != nil {
-		lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+	filePath := "/etc/asterisk/recording.conf"
+	_, err := os.Stat(filePath)
+	if err != nil {
+		logrus.Error(err)
+		return
+	}
+	iniFile, err := ini.Load(filePath)
+	if err != nil {
+		logrus.Error(err)
+		return
 	}
 
+	iniFile.Section("general").Key("PADRCD").SetValue(info.PadRcdEnable)
+	iniFile.Section("general").Key("PADRCDDAYS").SetValue(info.PadRcdStorageDays)
+	iniFile.Section("general").Key("PARCDDAYS").SetValue(info.PaRcdStorageDays)
+	iniFile.Section("general").Key("CPARCDDAYS").SetValue(info.CpaRcdStorageDays)
+	iniFile.Section("general").Key("PADRCDDELDAYS").SetValue(info.PadRcdDelDays)
+	iniFile.Section("general").Key("PARCDDELDAYS").SetValue(info.PaRcdDelDays)
+	iniFile.Section("general").Key("CPARCDDELDAYS").SetValue(info.CpaRcdDelDays)
+	iniFile.SaveTo(filePath)
+
 }

+ 20 - 16
internal/app/stc/priority/index.go

@@ -2,6 +2,7 @@ package priority
 
 import (
 	"os"
+	"pbx-api-gin/pkg/lfshook"
 	"strconv"
 
 	"github.com/sirupsen/logrus"
@@ -10,8 +11,10 @@ import (
 
 var ICPAnswer = 0
 var OCCAnswer = 0
-var RunningType = 0
+var RunningTypePriority = 0
+var RunningType = ""
 var SpecialVoice = 0
+var RunningPATaskChan = ""
 
 type PriorityAll struct {
 	ManuPa string `json:"manualPa"`
@@ -20,8 +23,8 @@ type PriorityAll struct {
 	PADTMS string `json:"padTms"`
 	PADOCC string `json:"padOcc"`
 	CPA    string `json:"cpa"`
-	EMGTMS string `json:"emgTms"`
-	SPCTMS string `json:"spcTms"`
+	EMG    string `json:"emg"`
+	SPC    string `json:"spc"`
 	DCS    string `json:"dcs"`
 	STN    string `json:"stn"`
 	CHK    string `json:"chk"`
@@ -42,17 +45,17 @@ func GetPriority() {
 		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.CHK = iniFile.Section("general").Key("CHK").Value()
+	Priority.STN = iniFile.Section("general").Key("STN").Value()
+	Priority.DCS = iniFile.Section("general").Key("DCS").Value()
+	Priority.SPC = iniFile.Section("general").Key("SPC").Value()
+	Priority.EMG = iniFile.Section("general").Key("EMG").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()
+	Priority.PADOCC = iniFile.Section("general").Key("PAD-OCC").Value()
+	Priority.PADTMS = iniFile.Section("general").Key("PAD-TMS").Value()
+	Priority.PADICP = iniFile.Section("general").Key("PAD-ICP").Value()
+	Priority.CabCab = iniFile.Section("general").Key("CabCab").Value()
+	Priority.ManuPa = iniFile.Section("general").Key("ManuPa").Value()
 }
 
 func GetPriorityByKey(key string) string {
@@ -73,13 +76,14 @@ func GetPriorityByKey(key string) string {
 
 // check priority , if the running priority is lowwer than the to run priority
 func CheckPriority(runType string) bool {
+	lfshook.NewLogger().Logger.Infof("=========Check Pri runType:%s====RunningTypePriority:%d============", runType, RunningTypePriority)
 	//check special voice
 	if SpecialVoice == 1 {
 		return false
 	}
 
 	//no any runing task
-	if RunningType == 0 {
+	if RunningTypePriority == 0 {
 		return true
 	}
 
@@ -89,9 +93,9 @@ func CheckPriority(runType string) bool {
 		logrus.Error(err)
 		return false
 	}
-
+	lfshook.NewLogger().Logger.Infof("=========Check Pri GetPriorityByKey:%d============", ret)
 	//if the running task priority is lowwer
-	if ret < RunningType && ret != 0 {
+	if ret < RunningTypePriority && ret != 0 {
 		return true
 	}
 	return false

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

@@ -12,6 +12,10 @@ import (
 
 var ExtenStatMap map[string]string
 
+func init() {
+	ExtenStatMap = make(map[string]string)
+}
+
 func SendToStc(conn net.Conn, data []byte) {
 
 	_, err := conn.Write(data)
@@ -125,6 +129,8 @@ func PaStatus(src string, patype string, operation string) {
 		protocol.Data[1] = 0x08
 	case "CHK": //自检
 		protocol.Data[1] = 0x09
+	case "VOL": //自检
+		protocol.Data[1] = 0x10
 	}
 
 	//操作类型