3 Commits c1358f864c ... a619ada7fd

Autore SHA1 Messaggio Data
  dujunchen a619ada7fd update record conf and self check broadcast 1 mese fa
  dujunchen 64c9485c1c update record conf 1 mese fa
  dujunchen d7aac5ab92 fix active action 1 mese fa

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

@@ -17,15 +17,6 @@ import (
 
 var AminInstance *amigo.Amigo
 
-const pacu1 = "2111"
-const pacu2 = "2121"
-const pacu3 = "2131"
-const pacu4 = "2141"
-const pacu5 = "2151"
-const pacu6 = "2161"
-const pacu7 = "2171"
-const pacu8 = "2181"
-
 //type Operation func(src, dst string, whisper, bargein bool)
 
 func HandleAMI(event map[string]string) {
@@ -70,17 +61,17 @@ func HandleAMI(event map[string]string) {
 		}
 
 	case "ExtensionStatus":
-		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
-			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())
-			}
+		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())
+		}
+		if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
 			if len(event["Exten"]) > 3 {
 				alstatus.AlarmStatus(event["Exten"], event["StatusText"], conn) // Alarm idle + unavailable
 			}

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

@@ -20,7 +20,7 @@ func PlaybackPacu(filename string, count int, delay int, PaType string) (err err
 	case "DCS":
 		Chan = "Local/0504" //dc-rule
 	case "CHK":
-		Chan = "Local/0503" //paging pacu
+		Chan = "Local/0510" //paging pacu
 	case "EMG":
 		Chan = "Local/0502" //emg-rule
 	}

+ 17 - 1
internal/app/ami/model/cdr.go

@@ -1,6 +1,6 @@
 package model
 
-//Cdr 通话记录
+// Cdr 通话记录
 type Cdr struct {
 	AnswerTime         string `xorm:"AnswerTime"`
 	BillableSeconds    string `xorm:"BillableSeconds"`
@@ -22,3 +22,19 @@ type Cdr struct {
 	Timestamp          string `xorm:"Timestamp"`
 	UniqueID           string `xorm:"UniqueID"`
 }
+
+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"
+}

+ 2 - 0
internal/app/index.go

@@ -30,6 +30,8 @@ func StartApp() {
 	}
 	lfshook.NewLogger().Infof("=================cab number:%s===========", active.CabNum)
 
+	//init the active status
+	active.Actived = true
 	// 启动带有重连机制的连接管理协程MC1
 	go stc.StartStcConnection(socket.Conn, "1")
 

+ 103 - 74
internal/app/stc/broadcast/stc-broadcast.go

@@ -41,12 +41,9 @@ func HandleStcCmd(ctx context.Context, conn net.Conn) {
 					}
 					return
 				}
-				if active.Actived { // check actived or not
-					// 将新读取的数据追加到缓冲区
-					buf.Write(tmp[:n])
-				} else {
-					break
-				}
+
+				// 将新读取的数据追加到缓冲区
+				buf.Write(tmp[:n])
 			}
 			// 尝试从缓冲区中提取完整数据包
 			for {
@@ -67,10 +64,22 @@ func processPacket(packet []byte) {
 		fmt.Println("Invalid packet length")
 		return
 	}
-	lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
+
+	//for test
+	if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
+		lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
+	}
+
 	//check if the cmd type is avtive
 	if packet[5] == 0x03 { // ACTIVE
-		Active([1]byte{packet[7]})
+		Active([1]byte{packet[8]})
+		return
+	}
+
+	//check if actived
+	if !active.Actived {
+		lfshook.NewLogger().Logger.Infof("===========Inactived  retrun==============")
+		return
 	}
 
 	switch packet[5] {
@@ -79,9 +88,8 @@ func processPacket(packet []byte) {
 	case 0x02: // STN
 		lfshook.NewLogger().Infof("=====STN=========")
 		StationAnn(packet)
-	case 0x03: // ACTIVE
-
-		Active([1]byte{packet[8]})
+	//case 0x03: // ACTIVE
+	//	Active([1]byte{packet[8]})
 	case 0x05: // SPC
 		lfshook.NewLogger().Infof("=====SPC=========")
 		SpecialAnn(packet)
@@ -131,56 +139,63 @@ func StationAnn(data []byte) (err error) {
 // 激活信号
 func Active(data [1]byte) {
 
-	var info model.Sysinfo
-
-	Num := int(data[0])
-	lfshook.NewLogger().Logger.Infof("Active data : %x", Num)
-
-	switch Num { // 设置全局的激活信号,并通过协议(待定)通知终端注册到对应的激活主机上
-	case 0:
-		lfshook.NewLogger().Logger.Infof("=================Inactive==================")
-		info.Name = "cab_active"
-		info.Value = "0"
+	//var info model.Sysinfo
+	active.Actived = true
+	//Num := int(data[0])
+	//lfshook.NewLogger().Logger.Infof("Active data : %x", Num)
+	/*
+		   switch Num { // 设置全局的激活信号,并通过协议(待定)通知终端注册到对应的激活主机上
+		   case 0:
 
-		_, er := mysql.DBOrmInstance.Where("name = ?", "cab_active").Update(&info)
-		if er != nil {
-			lfshook.NewLogger().Logger.Infof("update sysinfo err : %+v", er.Error())
-			return
-		}
-	case 1:
-		lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
-		if active.CabNum == "1" { // local cab is MC1
-			info.Name = "cab_active"
-			info.Value = "1"
-			active.Actived = true
-		} else {
-			info.Name = "cab_active"
-			info.Value = "0"
-			active.Actived = false
-		}
-		_, er := mysql.DBOrmInstance.Where("name = ?", "cab_active").Update(&info)
-		if er != nil {
-			lfshook.NewLogger().Logger.Infof("update sysinfo err : %+v", er.Error())
-			return
-		}
-	case 8:
-		lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
-		if active.CabNum == "8" { //Local cab is MC8
-			info.Name = "cab_active"
-			info.Value = "1"
-			active.Actived = true
-		} else {
-			info.Name = "cab_active"
-			info.Value = "0"
+		   	lfshook.NewLogger().Logger.Infof("=================Inactive==================")
+		   	info.Name = "cab_active"
+		   	info.Value = "0"
 			active.Actived = false
-		}
 
-		_, er := mysql.DBOrmInstance.Where("name = ?", "cab_active").Update(&info)
-		if er != nil {
-			lfshook.NewLogger().Logger.Infof("update sysinfo err : %+v", er.Error())
-			return
-		}
-	}
+		   	_, er := mysql.DBOrmInstance.Where("name = ?", "cab_active").Update(&info)
+		   	if er != nil {
+		   		lfshook.NewLogger().Logger.Infof("update sysinfo err : %+v", er.Error())
+		   		return
+		   	}
+
+		   case 1:
+
+		   	lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
+		   	if active.CabNum == "1" { // local cab is MC1
+		   		info.Name = "cab_active"
+		   		info.Value = "1"
+		   		active.Actived = true
+		   	} else {
+		   		info.Name = "cab_active"
+		   		info.Value = "0"
+		   		active.Actived = false
+		   	}
+		   	_, er := mysql.DBOrmInstance.Where("name = ?", "cab_active").Update(&info)
+		   	if er != nil {
+		   		lfshook.NewLogger().Logger.Infof("update sysinfo err : %+v", er.Error())
+		   		return
+		   	}
+
+		   case 8:
+
+		   		lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
+		   		if active.CabNum == "8" { //Local cab is MC8
+		   			info.Name = "cab_active"
+		   			info.Value = "1"
+		   			active.Actived = true
+		   		} else {
+		   			info.Name = "cab_active"
+		   			info.Value = "0"
+		   			active.Actived = false
+		   		}
+
+		   		_, er := mysql.DBOrmInstance.Where("name = ?", "cab_active").Update(&info)
+		   		if er != nil {
+		   			lfshook.NewLogger().Logger.Infof("update sysinfo err : %+v", er.Error())
+		   			return
+		   		}
+		   	}
+	*/
 }
 
 // SPC ,特殊服务消息广播
@@ -300,6 +315,8 @@ func SelfCheck(data []byte) {
 		for _, ext := range Pacus {
 			asterisk.Hangup(ext)
 		}
+		asterisk.Hangup("2311")
+		asterisk.Hangup("2381")
 	}
 }
 
@@ -354,15 +371,15 @@ func AlarmHandle(data []byte) {
 		lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
 		if infoExt.Status == "Idle" {
 			if active.CabNum == "1" && active.Actived {
-				action.Dial("0402", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP
+				action.Dial("0402", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP MC1
 			} else if active.CabNum == "8" && active.Actived {
-				action.Dial("0402", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP
+				action.Dial("0402", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP MC8
 			}
 		} else {
 			if active.CabNum == "1" && active.Actived {
-				action.RedirectInQueue(exten, "0402", "default", "1") // PACU dial ICP
+				action.RedirectInQueue(exten, "0402", "default", "1") // PAD dial ICP MC1
 			} else if active.CabNum == "8" && active.Actived {
-				action.RedirectInQueue(exten, "0402", "default", "8") // PACU dial ICP
+				action.RedirectInQueue(exten, "0402", "default", "8") // PAD dial ICP MC8
 			}
 		}
 
@@ -426,7 +443,7 @@ func AlarmResetAll() {
 
 	var AlarmExts []model.Extension
 
-	er := mysql.DBOrmInstance.Where("dev_type = ?", "PAIU").Find(&AlarmExts)
+	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())
 	}
@@ -435,22 +452,34 @@ func AlarmResetAll() {
 		action.Hangup(ext.Extension)
 	}
 
-	action.Hangup("2311")
+	if active.CabNum == "1" && active.Actived {
+		action.Hangup("2311") //1 车接听
+	} else if active.CabNum == "8" && active.Actived {
+		action.Hangup("2381") //8 车接听
+	}
 }
 
 func RecordStorageConf(data []byte) {
-	/*padRcd := data[0]
-	padRcdStorage := data[1]
-	paRcdStorage := data[2]
-	cpaRcdStorage := data[3]
-	padRcdDel := data[4]
-	PaRcdDel := data[5]
-	cpaRcdDel := data[6]
 
-	//update pa type
-	_, er := mysql.DBOrmInstance.In("exten", Pacus).Update(&model.Extension{PaType: "CHK"})
+	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.PadRcdDelDays = int(data[4])
+	info.PaRcdDelDays = int(data[5])
+	info.CpaRcdDelDays = 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())
 	}
-	*/
+
 }