stc-broadcast.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. package broadcast
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io"
  7. "net"
  8. "net/http"
  9. "os"
  10. "pbx-api-gin/internal/app/ami/action"
  11. "pbx-api-gin/internal/app/ami/model"
  12. "pbx-api-gin/internal/app/stc/active"
  13. msgdata "pbx-api-gin/internal/app/stc/data"
  14. "pbx-api-gin/internal/app/stc/priority"
  15. alstatus "pbx-api-gin/internal/app/stc/sendstatus"
  16. "pbx-api-gin/pkg/lfshook"
  17. "strconv"
  18. "sync"
  19. "time"
  20. "github.com/sirupsen/logrus"
  21. "gopkg.in/ini.v1"
  22. )
  23. func HandleStcCmd(ctx context.Context, conn net.Conn) {
  24. for {
  25. select {
  26. case <-ctx.Done():
  27. return
  28. default:
  29. var buf bytes.Buffer
  30. tmp := make([]byte, 1024)
  31. if conn != nil {
  32. n, err := conn.Read(tmp)
  33. if err != nil {
  34. if err != io.EOF {
  35. conn.Close()
  36. }
  37. return
  38. }
  39. buf.Write(tmp[:n])
  40. }
  41. for {
  42. packet, err := msgdata.ExtractPacket(&buf)
  43. if err != nil {
  44. break
  45. }
  46. go processPacket(packet)
  47. }
  48. }
  49. }
  50. }
  51. // 处理单个数据包(原 switch 逻辑迁移过来)
  52. func processPacket(packet []byte) {
  53. if len(packet) < 6 {
  54. fmt.Println("Invalid packet length")
  55. return
  56. }
  57. //for recv data log debug
  58. //if packet[5] != 0x03 && packet[5] != 0x0c && packet[5] != 0x01 {
  59. lfshook.NewLogger().Logger.Infof("Get data from STC ===============:%x", packet)
  60. //}
  61. //check if the cmd type is avtive
  62. if packet[5] == 0x03 { // ACTIVE
  63. Active([2]byte{packet[8], packet[9]})
  64. return
  65. }
  66. //check if Master role
  67. if !active.Master {
  68. lfshook.NewLogger().Logger.Infof("=========Not Master Role Ignore data=============")
  69. return
  70. }
  71. switch packet[5] {
  72. case 0x01: //heartbeat
  73. /*
  74. //PAD-OCC异常情况处理
  75. if priority.OCCAnswer == 1 {
  76. //定时监测ICP queue 转到OCC queue, 避免异常情形下PAD进入ICP queue之后无法被接听
  77. resCaller, err := action.QueueStatus("0300", "") // check ICP queue, get entries
  78. if err != nil {
  79. lfshook.NewLogger().Infof("==ICP=QueueStatus==%+v", err)
  80. return
  81. }
  82. if resCaller.Calls != "0" {
  83. sort.Slice(resCaller.Entrys, func(i, j int) bool {
  84. return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
  85. })
  86. for _, caller := range resCaller.Entrys {
  87. priority.ICPAnswer = 0
  88. lfshook.NewLogger().Infof("====Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
  89. //order by pos
  90. action.RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
  91. time.Sleep(time.Microsecond * 200) //200 ms delay
  92. }
  93. }
  94. //定时监测OCC queue, 避免异常情况下PAD 在OCC queue里面不能自动转到OCC
  95. res, err := action.QueueStatus("0301", "") // check OCC queue ,if empty PAD end
  96. if err != nil {
  97. lfshook.NewLogger().Infof("==OCC=QueueStatus==%+v", err)
  98. return
  99. }
  100. if res.Calls != "0" { //OCC queue is not empty
  101. // HangupAllLocalChan()
  102. lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
  103. if active.ActivedCab == "1" && action.ExtenStatus("1411") == "Idle" { //check active and OCC status
  104. time.Sleep(time.Second)
  105. PADChan := ""
  106. for _, chanEntry := range res.Entrys {
  107. lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
  108. if chanEntry.Position == "1" {
  109. PADChan = chanEntry.Channel
  110. break
  111. }
  112. }
  113. if PADChan != "" {
  114. alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
  115. go action.RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", "1") //PAD Page(OCC+ICPs)
  116. go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
  117. } else {
  118. lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
  119. }
  120. break
  121. } else if active.ActivedCab == "8" && action.ExtenStatus("1481") == "Idle" {
  122. time.Sleep(time.Second)
  123. PADChan := ""
  124. for _, chanEntry := range res.Entrys {
  125. lfshook.NewLogger().Infof("====PAD answered by OCC1 pos:%s===chan:%s=", chanEntry.Position, chanEntry.Channel)
  126. if chanEntry.Position == "1" {
  127. PADChan = chanEntry.Channel
  128. break
  129. }
  130. }
  131. if PADChan != "" {
  132. alstatus.AlarmStatus(strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0], "connect")
  133. go action.RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", "8") //PAD Page(OCC+ICPs)
  134. go action.Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
  135. } else {
  136. lfshook.NewLogger().Infof("===OCC-QueueStatus==PADCchan NULL")
  137. }
  138. break
  139. }
  140. }
  141. }
  142. */
  143. break
  144. case 0x02: // STN
  145. if active.ActivedCab != "" {
  146. if priority.CheckPriority("STN") {
  147. action.HangupRunningTask("STN") //STN interrupt other
  148. StationAnn(packet)
  149. } else {
  150. alstatus.PaStatus("", "STN", "refuse")
  151. }
  152. }
  153. case 0x05: // SPC
  154. if active.ActivedCab != "" {
  155. if priority.CheckPriority("SPC") {
  156. action.HangupRunningTask("SPC") //SPC interrupt other
  157. SpecialAnn(packet)
  158. } else {
  159. alstatus.PaStatus("", "SPC", "refuse")
  160. }
  161. }
  162. case 0x06: // EMG
  163. if active.ActivedCab != "" {
  164. if priority.CheckPriority("EMG") {
  165. action.HangupRunningTask("EMG") //EMG interrupt other
  166. EmgMsg(packet)
  167. } else {
  168. alstatus.PaStatus("", "EMG", "refuse")
  169. }
  170. }
  171. case 0x07: // STOP
  172. AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
  173. case 0x08: // DCS
  174. if active.ActivedCab != "" {
  175. if priority.CheckPriority("DCS") {
  176. action.HangupRunningTask("DCS") //DCS interrupt other
  177. DcsAnn(packet)
  178. } else {
  179. alstatus.PaStatus("", "DCS", "refuse")
  180. }
  181. }
  182. case 0x09: // SELF CHECK
  183. if active.ActivedCab != "" {
  184. if priority.CheckPriority("CHK") {
  185. action.HangupRunningTask("CHK") //CHK interrupt other
  186. SelfCheck(packet)
  187. } else {
  188. alstatus.PaStatus("", "CHK", "refuse")
  189. }
  190. }
  191. case 0x0a: // Tone-test
  192. if active.ActivedCab != "" {
  193. if priority.CheckPriority("VOL") {
  194. action.HangupRunningTask("VOL") //VOL interrupt other
  195. ToneTest(packet)
  196. } else {
  197. alstatus.PaStatus("", "VOL", "refuse")
  198. }
  199. }
  200. case 0x0e: //TMS answer PAD
  201. if priority.CheckPriority("PAD-TMS") {
  202. action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
  203. AlarmHandleTMS(packet)
  204. active.QueueTimer.Stop()
  205. } else {
  206. alstatus.PaStatus("", "PAD-TMS", "refuse")
  207. }
  208. case 0x0b: // reset all PAD
  209. AlarmHoldResetAll(packet[8]) // reset all pad
  210. case 0x0c: // recored config
  211. RecordStorageConf(packet[8:]) // RCD setting
  212. case 0x0d: // ICP answer PAD
  213. if priority.CheckPriority("PAD-ICP") {
  214. action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
  215. active.QueueTimer.Stop()
  216. AlarmHandleICP(packet) //
  217. } else {
  218. alstatus.PaStatus("", "PAD-ICP", "refuse")
  219. }
  220. default:
  221. fmt.Printf("Unknown command: %x\n", packet[5])
  222. }
  223. }
  224. // STN , 自动报站广播
  225. func StationAnn(data []byte) (err error) {
  226. specialVoice := int(data[8])
  227. delay := data[9]
  228. cycleCount := data[10]
  229. datalen := int(data[11])
  230. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  231. //set spc voice tag
  232. priority.SpecialVoice = specialVoice
  233. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "STN")
  234. return nil
  235. }
  236. // 激活信号
  237. func Active(data [2]byte) {
  238. //var info model.Sysinfo
  239. //active.Actived = true
  240. Signal := int(data[0])
  241. Master := int(data[1])
  242. //lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
  243. if !active.Master && active.CabNum == "8" { //slave role , check the Master data from STC
  244. if Master == 8 {
  245. active.Master = true
  246. }
  247. } else if !active.Master && active.CabNum == "1" {
  248. if Master == 1 {
  249. active.Master = true
  250. }
  251. }
  252. switch Signal {
  253. case 0:
  254. //lfshook.NewLogger().Logger.Infof("=================Inactive==================")
  255. active.ActivedCab = ""
  256. action.InActiveHangup()
  257. case 1:
  258. active.ActivedCab = "1"
  259. //lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
  260. case 8:
  261. active.ActivedCab = "8"
  262. //lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
  263. }
  264. }
  265. // SPC ,特殊服务消息广播
  266. func SpecialAnn(data []byte) {
  267. delay := data[8]
  268. cycleCount := data[9]
  269. datalen := int(data[10])
  270. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  271. if int(cycleCount) == 255 {
  272. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
  273. } else {
  274. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SPC")
  275. }
  276. }
  277. // EMG ,紧急服务消息广播
  278. func EmgMsg(data []byte) {
  279. delay := data[8]
  280. cycleCount := data[9]
  281. datalen := int(data[10])
  282. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  283. if int(cycleCount) == 255 {
  284. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
  285. priority.ResumeEmgPara = priority.BroadcastResumeParas{FileName: filename, Count: 99999999, Delay: int(delay), BroadcastType: "EMG"}
  286. } else {
  287. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
  288. }
  289. }
  290. // 停止指定类型广播
  291. func AnnStop(data [4]byte) {
  292. //PaType := ""
  293. lfshook.NewLogger().Logger.Infof("=AnnStop Type %x", data[0])
  294. switch data[0] {
  295. case 0x03:
  296. if priority.RunningType == "DCS" {
  297. action.HangupRunningTask("") //STOP DCS
  298. }
  299. case 0x04:
  300. if priority.RunningType == "EMG" {
  301. action.HangupRunningTask("AnnStop") //STOP EMG
  302. }
  303. case 0x07:
  304. if priority.RunningType == "SPC" {
  305. action.HangupRunningTask("AnnStop") //STOP SPC
  306. }
  307. case 0x08:
  308. if priority.RunningType == "STN" {
  309. action.HangupRunningTask("AnnStop") //STOP STN
  310. }
  311. case 0x09:
  312. if priority.RunningType == "CHK" {
  313. action.HangupRunningTask("AnnStop") //STOP CHK
  314. }
  315. case 0x0a:
  316. if priority.RunningType == "VOL" {
  317. action.HangupRunningTask("AnnStop") //STOP VOL
  318. }
  319. default:
  320. action.HangupRunningTask("AnnStop")
  321. }
  322. }
  323. // DCS 语音
  324. func DcsAnn(data []byte) {
  325. delay := data[8]
  326. cycleCount := data[9]
  327. datalen := int(data[10])
  328. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  329. if int(cycleCount) == 255 {
  330. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
  331. } else {
  332. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
  333. }
  334. }
  335. // tone-test广播
  336. func ToneTest(data []byte) {
  337. check := data[8]
  338. delay := data[9]
  339. cycleCount := data[10]
  340. datalen := int(data[11])
  341. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  342. switch check {
  343. case 0x01: //start
  344. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
  345. case 0x02: //stop
  346. //alstatus.PaStatus("", "VOL", "end")
  347. action.HangupAllExcept("")
  348. }
  349. }
  350. // 自检广播
  351. func SelfCheck(data []byte) {
  352. check := data[8]
  353. delay := data[9]
  354. //cycleCount := data[10]
  355. cycleCount := 0x32
  356. datalen := int(data[11])
  357. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  358. switch check {
  359. case 0x01: //start
  360. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
  361. case 0x02: //stop
  362. //Pa status report
  363. priority.CleanPriorityTag()
  364. //alstatus.PaStatus("", "CHK", "end")
  365. action.HangupAllExcept("")
  366. }
  367. }
  368. // 全局变量:记录正在抑制的 exten
  369. var (
  370. suppressedExts = sync.Map{} // map[string]struct{},值存在即表示被抑制
  371. //suppressionMu sync.Mutex // 保护初始化和清理操作(可选)
  372. )
  373. // suppressKey 生成用于抑制的 key(可以根据需求扩展)
  374. func suppressKey(exten string, handler byte) string {
  375. return fmt.Sprintf("%s_h%x", exten, handler)
  376. }
  377. // ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
  378. func AlarmHandleICP(data []byte) {
  379. handler := data[8]
  380. carr := data[12]
  381. pos := data[13]
  382. exten := fmt.Sprintf("24%c%c", carr, pos)
  383. key := suppressKey(exten, handler)
  384. //Drop other handler in 2 sec
  385. //PACUs---call---->ICP1
  386. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  387. if handler == 0x01 {
  388. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  389. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  390. return
  391. }
  392. time.AfterFunc(4*time.Second, func() {
  393. suppressedExts.Delete(key)
  394. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  395. })
  396. }
  397. switch handler {
  398. case 0x01: //answer(ICP+Alarm+PACU)
  399. //NotifyPaiu(exten, "answer")
  400. priority.ICPAnswer = 1
  401. if priority.PADStart == 0 {
  402. alstatus.PaStatus(exten, "PAD", "start")
  403. priority.PADStart = 1
  404. }
  405. lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
  406. if active.ActivedCab == "1" {
  407. action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
  408. //goto ami event ConfbridgeJoin, ICP answer PAD
  409. } else if active.ActivedCab == "8" {
  410. action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
  411. //goto ami event ConfbridgeJoin, ICP answer PAD
  412. }
  413. case 0x02: //hold 重新放回队列里面
  414. NotifyPaiu(exten, "hold")
  415. err := action.RedirectInQueue(exten, "0300", "default", "1")
  416. if err != nil {
  417. lfshook.NewLogger().Info(err)
  418. }
  419. action.HangupAllLocalChan()
  420. case 0x03: //hangup
  421. //NotifyPaiu(exten, "hangup")
  422. action.Hangup(exten) //Pad
  423. action.HangupAllLocalChan()
  424. action.HangupICP()
  425. priority.CleanPriorityTag()
  426. }
  427. }
  428. // TMS操作乘客报警(根据激活信息判断转到1车还是8车================)
  429. func AlarmHandleTMS(data []byte) {
  430. handler := data[8]
  431. //extlen := data[9]
  432. carr := data[12]
  433. pos := data[13]
  434. exten := fmt.Sprintf("24%c%c", carr, pos)
  435. PacuNum := fmt.Sprintf("21%c%c", carr, pos)
  436. key := suppressKey(exten, handler)
  437. //Drop other handler in 2 sec
  438. // 只对 handler == 0x01 做 2 秒去重
  439. if handler == 0x01 {
  440. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  441. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  442. return // 已存在,说明在2秒窗口期内,直接丢弃
  443. }
  444. // 设置4秒后删除该 key,允许下次通过
  445. time.AfterFunc(4*time.Second, func() {
  446. suppressedExts.Delete(key)
  447. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  448. })
  449. }
  450. switch handler {
  451. case 0x01: //answer(ICP+Alarm+PACU)
  452. //PACU---call---->ICP1
  453. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  454. if priority.PADStart == 0 {
  455. alstatus.PaStatus(exten, "PAD", "start")
  456. priority.PADStart = 1
  457. }
  458. priority.ICPAnswer = 1
  459. lfshook.NewLogger().Logger.Infof("================TMS Answer PAD:%s===PACU:%s==========", exten, PacuNum)
  460. if action.ExtenStatus(PacuNum) == "Idle" {
  461. if active.ActivedCab == "1" {
  462. action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
  463. //goto ami event BridgeEnter, ICP8 whisper ICP1
  464. } else if active.ActivedCab == "8" {
  465. action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
  466. //goto ami event BridgeEnter, ICP1 whisper ICP8
  467. }
  468. } else {
  469. action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
  470. }
  471. case 0x02: //hold 重新放回队列里面
  472. NotifyPaiu(exten, "hold")
  473. err := action.RedirectInQueue(exten, "0300", "default", "1")
  474. if err != nil {
  475. lfshook.NewLogger().Info(err)
  476. }
  477. action.HangupAllLocalChan()
  478. case 0x03: //hangup
  479. //NotifyPaiu(exten, "hangup")
  480. action.Hangup(exten) //Pad
  481. action.HangupAllLocalChan()
  482. action.HangupICP()
  483. priority.CleanPriorityTag()
  484. }
  485. }
  486. // 挂断所有报警器
  487. func NotifyPaiu(Exten, Action string) {
  488. url := ""
  489. switch Action {
  490. case "answer":
  491. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=answer", Exten[2:])
  492. case "hold":
  493. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=hold", Exten[2:])
  494. case "hangup":
  495. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=hangup", Exten[2:])
  496. }
  497. lfshook.NewLogger().Logger.Infof("======Notify PAIU Alarm====:%+v ", url)
  498. resp, err := http.Get(url)
  499. if err != nil {
  500. lfshook.NewLogger().Logger.Infof("======Notify PAIU Alarm====:%+v ", err)
  501. return
  502. }
  503. defer resp.Body.Close()
  504. /*
  505. body, err := io.ReadAll(resp.Body)
  506. if err != nil {
  507. // 读取数据错误
  508. lfshook.NewLogger().Warn("ioutil ReadAll failed :", err.Error())
  509. return
  510. }
  511. fmt.Printf("状态码: %d\n", resp.StatusCode)
  512. fmt.Printf("响应内容: %s\n", body)
  513. */
  514. }
  515. // 挂断所有报警器
  516. func AlarmHoldResetAll(handler byte) {
  517. //all hold
  518. //hangup all actived PAD
  519. action.HangupAllPAD()
  520. //hangup running task
  521. if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-TMS" {
  522. action.HangupRunningTask("AlarmHoldResetAll") //Reset PAD ALL
  523. priority.CleanPriorityTag()
  524. }
  525. }
  526. func RecordStorageConf(data []byte) {
  527. var info model.RcdConf
  528. info.PadRcdEnable = strconv.Itoa(int(data[0]))
  529. info.PadRcdStorageDays = strconv.Itoa(int(data[1]))
  530. info.PaRcdStorageDays = strconv.Itoa(int(data[2]))
  531. info.CpaRcdStorageDays = strconv.Itoa(int(data[3]))
  532. info.PadRcdDelDays = strconv.Itoa(int(data[4]))
  533. info.PaRcdDelDays = strconv.Itoa(int(data[5]))
  534. info.CpaRcdDelDays = strconv.Itoa(int(data[6]))
  535. //info.OpaRcdStorageDays = int(data[7])
  536. //info.OpaRcdDelDays = int(data[8])
  537. //lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
  538. filePath := "/etc/asterisk/recording.conf"
  539. _, err := os.Stat(filePath)
  540. if err != nil {
  541. logrus.Error(err)
  542. return
  543. }
  544. iniFile, err := ini.Load(filePath)
  545. if err != nil {
  546. logrus.Error(err)
  547. return
  548. }
  549. iniFile.Section("general").Key("PADRCD").SetValue(info.PadRcdEnable)
  550. iniFile.Section("general").Key("PADRCDDAYS").SetValue(info.PadRcdStorageDays)
  551. iniFile.Section("general").Key("PARCDDAYS").SetValue(info.PaRcdStorageDays)
  552. iniFile.Section("general").Key("CPARCDDAYS").SetValue(info.CpaRcdStorageDays)
  553. iniFile.Section("general").Key("PADRCDDELDAYS").SetValue(info.PadRcdDelDays)
  554. iniFile.Section("general").Key("PARCDDELDAYS").SetValue(info.PaRcdDelDays)
  555. iniFile.Section("general").Key("CPARCDDELDAYS").SetValue(info.CpaRcdDelDays)
  556. iniFile.SaveTo(filePath)
  557. }