stc-broadcast.go 18 KB

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