stc-broadcast.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 priority.CheckPriority("STN") {
  146. action.HangupRunningTask("STN") //STN interrupt other
  147. StationAnn(packet)
  148. } else {
  149. alstatus.PaStatus("", "STN", "refuse")
  150. }
  151. case 0x05: // SPC
  152. if priority.CheckPriority("SPC") {
  153. action.HangupRunningTask("SPC") //SPC interrupt other
  154. SpecialAnn(packet)
  155. } else {
  156. alstatus.PaStatus("", "SPC", "refuse")
  157. }
  158. case 0x06: // EMG
  159. if priority.CheckPriority("EMG") {
  160. action.HangupRunningTask("EMG") //EMG interrupt other
  161. EmgMsg(packet)
  162. } else {
  163. alstatus.PaStatus("", "EMG", "refuse")
  164. }
  165. case 0x07: // STOP
  166. AnnStop([4]byte{packet[8], packet[9], packet[10], packet[11]})
  167. case 0x08: // DCS
  168. if priority.CheckPriority("DCS") {
  169. action.HangupRunningTask("DCS") //DCS interrupt other
  170. DcsAnn(packet)
  171. } else {
  172. alstatus.PaStatus("", "DCS", "refuse")
  173. }
  174. case 0x09: // SELF CHECK
  175. if priority.CheckPriority("CHK") {
  176. action.HangupRunningTask("CHK") //CHK interrupt other
  177. SelfCheck(packet)
  178. } else {
  179. alstatus.PaStatus("", "CHK", "refuse")
  180. }
  181. case 0x0a: // Tone-test
  182. if priority.CheckPriority("VOL") {
  183. action.HangupRunningTask("VOL") //VOL interrupt other
  184. ToneTest(packet)
  185. } else {
  186. alstatus.PaStatus("", "VOL", "refuse")
  187. }
  188. case 0x0e: //TMS answer PAD
  189. if priority.CheckPriority("PAD-TMS") {
  190. action.HangupRunningTask("PAD-TMS") //PAD-TMS interrupt other
  191. AlarmHandleTMS(packet)
  192. active.QueueTimer.Stop()
  193. } else {
  194. alstatus.PaStatus("", "PAD-TMS", "refuse")
  195. }
  196. case 0x0b: // reset all PAD
  197. AlarmHoldResetAll(packet[8]) // reset all pad
  198. case 0x0c: // recored config
  199. RecordStorageConf(packet[8:]) // RCD setting
  200. case 0x0d: // ICP answer PAD
  201. if priority.CheckPriority("PAD-ICP") {
  202. action.HangupRunningTask("PAD-ICP") //PAD-ICP interrupt other
  203. active.QueueTimer.Stop()
  204. AlarmHandleICP(packet) //
  205. } else {
  206. alstatus.PaStatus("", "PAD-ICP", "refuse")
  207. }
  208. default:
  209. fmt.Printf("Unknown command: %x\n", packet[5])
  210. }
  211. }
  212. // STN , 自动报站广播
  213. func StationAnn(data []byte) (err error) {
  214. specialVoice := int(data[8])
  215. delay := data[9]
  216. cycleCount := data[10]
  217. datalen := int(data[11])
  218. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  219. //set spc voice tag
  220. priority.SpecialVoice = specialVoice
  221. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "STN")
  222. return nil
  223. }
  224. // 激活信号
  225. func Active(data [2]byte) {
  226. //var info model.Sysinfo
  227. //active.Actived = true
  228. Signal := int(data[0])
  229. Master := int(data[1])
  230. //lfshook.NewLogger().Logger.Infof("Active data : %x", Signal)
  231. if !active.Master && active.CabNum == "8" { //slave role , check the Master data from STC
  232. if Master == 8 {
  233. active.Master = true
  234. }
  235. } else if !active.Master && active.CabNum == "1" {
  236. if Master == 1 {
  237. active.Master = true
  238. }
  239. }
  240. switch Signal {
  241. case 0:
  242. //lfshook.NewLogger().Logger.Infof("=================Inactive==================")
  243. active.ActivedCab = ""
  244. action.InActiveHangup()
  245. case 1:
  246. active.ActivedCab = "1"
  247. //lfshook.NewLogger().Logger.Infof("=================active===MC1===============")
  248. if active.CabNum == "8" { // local cab is MC1
  249. action.InActiveHangup()
  250. }
  251. case 8:
  252. active.ActivedCab = "8"
  253. //lfshook.NewLogger().Logger.Infof("=================active===MC8===============")
  254. if active.CabNum == "1" { //Local cab is MC8
  255. action.InActiveHangup()
  256. }
  257. }
  258. }
  259. // SPC ,特殊服务消息广播
  260. func SpecialAnn(data []byte) {
  261. delay := data[8]
  262. cycleCount := data[9]
  263. datalen := int(data[10])
  264. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  265. if int(cycleCount) == 255 {
  266. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "SPC")
  267. } else {
  268. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "SPC")
  269. }
  270. }
  271. // EMG ,紧急服务消息广播
  272. func EmgMsg(data []byte) {
  273. delay := data[8]
  274. cycleCount := data[9]
  275. datalen := int(data[10])
  276. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  277. if int(cycleCount) == 255 {
  278. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "EMG")
  279. priority.ResumeEmgPara = priority.BroadcastResumeParas{FileName: filename, Count: 99999999, Delay: int(delay), BroadcastType: "EMG"}
  280. } else {
  281. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "EMG")
  282. }
  283. }
  284. // 停止指定类型广播
  285. func AnnStop(data [4]byte) {
  286. //PaType := ""
  287. lfshook.NewLogger().Logger.Infof("=AnnStop Type %x", data[0])
  288. switch data[0] {
  289. case 0x03:
  290. if priority.RunningType == "DCS" {
  291. action.HangupRunningTask("") //STOP DCS
  292. }
  293. case 0x04:
  294. if priority.RunningType == "EMG" {
  295. action.HangupRunningTask("AnnStop") //STOP EMG
  296. }
  297. case 0x07:
  298. if priority.RunningType == "SPC" {
  299. action.HangupRunningTask("AnnStop") //STOP SPC
  300. }
  301. case 0x08:
  302. if priority.RunningType == "STN" {
  303. action.HangupRunningTask("AnnStop") //STOP STN
  304. }
  305. case 0x09:
  306. if priority.RunningType == "CHK" {
  307. action.HangupRunningTask("AnnStop") //STOP CHK
  308. }
  309. case 0x0a:
  310. if priority.RunningType == "VOL" {
  311. action.HangupRunningTask("AnnStop") //STOP VOL
  312. }
  313. default:
  314. action.HangupRunningTask("AnnStop")
  315. }
  316. }
  317. // DCS 语音
  318. func DcsAnn(data []byte) {
  319. delay := data[8]
  320. cycleCount := data[9]
  321. datalen := int(data[10])
  322. filename := msgdata.SubstrByRune(string(data[11:]), 0, datalen-4)
  323. if int(cycleCount) == 255 {
  324. action.PlaybackPacu(strconv.Quote(filename), 9999999, int(delay), "DCS")
  325. } else {
  326. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "DCS")
  327. }
  328. }
  329. // tone-test广播
  330. func ToneTest(data []byte) {
  331. check := data[8]
  332. delay := data[9]
  333. cycleCount := data[10]
  334. datalen := int(data[11])
  335. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  336. switch check {
  337. case 0x01: //start
  338. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "VOL")
  339. case 0x02: //stop
  340. //alstatus.PaStatus("", "VOL", "end")
  341. action.HangupAllExcept("")
  342. }
  343. }
  344. // 自检广播
  345. func SelfCheck(data []byte) {
  346. check := data[8]
  347. delay := data[9]
  348. //cycleCount := data[10]
  349. cycleCount := 0x32
  350. datalen := int(data[11])
  351. filename := msgdata.SubstrByRune(string(data[12:]), 0, datalen-4)
  352. switch check {
  353. case 0x01: //start
  354. action.PlaybackPacu(strconv.Quote(filename), int(cycleCount), int(delay), "CHK")
  355. case 0x02: //stop
  356. //Pa status report
  357. priority.CleanPriorityTag()
  358. //alstatus.PaStatus("", "CHK", "end")
  359. action.HangupAllExcept("")
  360. }
  361. }
  362. // 全局变量:记录正在抑制的 exten
  363. var (
  364. suppressedExts = sync.Map{} // map[string]struct{},值存在即表示被抑制
  365. //suppressionMu sync.Mutex // 保护初始化和清理操作(可选)
  366. )
  367. // suppressKey 生成用于抑制的 key(可以根据需求扩展)
  368. func suppressKey(exten string, handler byte) string {
  369. return fmt.Sprintf("%s_h%x", exten, handler)
  370. }
  371. // ICP操作乘客报警(根据激活信息判断转到1车还是8车================)
  372. func AlarmHandleICP(data []byte) {
  373. handler := data[8]
  374. carr := data[12]
  375. pos := data[13]
  376. exten := fmt.Sprintf("24%c%c", carr, pos)
  377. key := suppressKey(exten, handler)
  378. //Drop other handler in 2 sec
  379. //PACUs---call---->ICP1
  380. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  381. if handler == 0x01 {
  382. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  383. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  384. return
  385. }
  386. time.AfterFunc(4*time.Second, func() {
  387. suppressedExts.Delete(key)
  388. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  389. })
  390. }
  391. switch handler {
  392. case 0x01: //answer(ICP+Alarm+PACU)
  393. //NotifyPaiu(exten, "answer")
  394. priority.ICPAnswer = 1
  395. if priority.PADStart == 0 {
  396. alstatus.PaStatus(exten, "PAD", "start")
  397. priority.PADStart = 1
  398. }
  399. lfshook.NewLogger().Logger.Infof("================ICP Answer PAD================:%s ", exten)
  400. if active.ActivedCab == "1" {
  401. action.Dial("0402", "0511", "pad-rule-pacus", "ani1", exten, "1") // PACUs dial ICP1
  402. //goto ami event ConfbridgeJoin, ICP answer PAD
  403. } else if active.ActivedCab == "8" {
  404. action.Dial("0402", "0511", "pad-rule-pacus", "ani8", exten, "8") // PACUs dial ICP8
  405. //goto ami event ConfbridgeJoin, ICP answer PAD
  406. }
  407. case 0x02: //hold 重新放回队列里面
  408. NotifyPaiu(exten, "hold")
  409. err := action.RedirectInQueue(exten, "0300", "default", "1")
  410. if err != nil {
  411. lfshook.NewLogger().Info(err)
  412. }
  413. action.HangupAllLocalChan()
  414. case 0x03: //hangup
  415. //NotifyPaiu(exten, "hangup")
  416. action.Hangup(exten) //Pad
  417. action.HangupAllLocalChan()
  418. action.HangupICP()
  419. priority.CleanPriorityTag()
  420. }
  421. }
  422. // TMS操作乘客报警(根据激活信息判断转到1车还是8车================)
  423. func AlarmHandleTMS(data []byte) {
  424. handler := data[8]
  425. //extlen := data[9]
  426. carr := data[12]
  427. pos := data[13]
  428. exten := fmt.Sprintf("24%c%c", carr, pos)
  429. PacuNum := fmt.Sprintf("21%c%c", carr, pos)
  430. key := suppressKey(exten, handler)
  431. //Drop other handler in 2 sec
  432. // 只对 handler == 0x01 做 2 秒去重
  433. if handler == 0x01 {
  434. if _, loaded := suppressedExts.LoadOrStore(key, struct{}{}); loaded {
  435. lfshook.NewLogger().Logger.Infof("Suppressed duplicate ICP Alarm (handler=0x01) for exten: %s within 4 seconds", exten)
  436. return // 已存在,说明在2秒窗口期内,直接丢弃
  437. }
  438. // 设置4秒后删除该 key,允许下次通过
  439. time.AfterFunc(4*time.Second, func() {
  440. suppressedExts.Delete(key)
  441. lfshook.NewLogger().Logger.Debugf("Suppression released for key: %s", key)
  442. })
  443. }
  444. switch handler {
  445. case 0x01: //answer(ICP+Alarm+PACU)
  446. //PACU---call---->ICP1
  447. //PAD---->Chanspy(WEq)-->ICP1;PAD--->Call---->ICP2
  448. if priority.PADStart == 0 {
  449. alstatus.PaStatus(exten, "PAD", "start")
  450. priority.PADStart = 1
  451. }
  452. priority.ICPAnswer = 1
  453. lfshook.NewLogger().Logger.Infof("================TMS Answer PAD:%s===PACU:%s==========", exten, PacuNum)
  454. if action.ExtenStatus(PacuNum) == "Idle" {
  455. if active.ActivedCab == "1" {
  456. action.Dial("0403", PacuNum, "default", PacuNum, exten, "1") // PACU dial ICP1
  457. //goto ami event BridgeEnter, ICP8 whisper ICP1
  458. } else if active.ActivedCab == "8" {
  459. action.Dial("0403", PacuNum, "default", PacuNum, exten, "8") // PACU dial ICP8
  460. //goto ami event BridgeEnter, ICP1 whisper ICP8
  461. }
  462. } else {
  463. action.RedirectInQueue(exten, "0405", "default", exten) // PAD dial ICPs
  464. }
  465. case 0x02: //hold 重新放回队列里面
  466. NotifyPaiu(exten, "hold")
  467. err := action.RedirectInQueue(exten, "0300", "default", "1")
  468. if err != nil {
  469. lfshook.NewLogger().Info(err)
  470. }
  471. action.HangupAllLocalChan()
  472. case 0x03: //hangup
  473. //NotifyPaiu(exten, "hangup")
  474. action.Hangup(exten) //Pad
  475. action.HangupAllLocalChan()
  476. action.HangupICP()
  477. priority.CleanPriorityTag()
  478. }
  479. }
  480. // 挂断所有报警器
  481. func NotifyPaiu(Exten, Action string) {
  482. url := ""
  483. switch Action {
  484. case "answer":
  485. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=answer", Exten[2:])
  486. case "hold":
  487. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=hold", Exten[2:])
  488. case "hangup":
  489. url = fmt.Sprintf("http://10.0.24.%s/api/sipphone?action=hangup", Exten[2:])
  490. }
  491. lfshook.NewLogger().Logger.Infof("======Notify PAIU Alarm====:%+v ", url)
  492. resp, err := http.Get(url)
  493. if err != nil {
  494. lfshook.NewLogger().Logger.Infof("======Notify PAIU Alarm====:%+v ", err)
  495. return
  496. }
  497. defer resp.Body.Close()
  498. /*
  499. body, err := io.ReadAll(resp.Body)
  500. if err != nil {
  501. // 读取数据错误
  502. lfshook.NewLogger().Warn("ioutil ReadAll failed :", err.Error())
  503. return
  504. }
  505. fmt.Printf("状态码: %d\n", resp.StatusCode)
  506. fmt.Printf("响应内容: %s\n", body)
  507. */
  508. }
  509. // 挂断所有报警器
  510. func AlarmHoldResetAll(handler byte) {
  511. //all hold
  512. //hangup all actived PAD
  513. action.HangupAllPAD()
  514. //hangup running task
  515. if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-TMS" {
  516. action.HangupRunningTask("AlarmHoldResetAll") //Reset PAD ALL
  517. priority.CleanPriorityTag()
  518. }
  519. }
  520. func RecordStorageConf(data []byte) {
  521. var info model.RcdConf
  522. info.PadRcdEnable = strconv.Itoa(int(data[0]))
  523. info.PadRcdStorageDays = strconv.Itoa(int(data[1]))
  524. info.PaRcdStorageDays = strconv.Itoa(int(data[2]))
  525. info.CpaRcdStorageDays = strconv.Itoa(int(data[3]))
  526. info.PadRcdDelDays = strconv.Itoa(int(data[4]))
  527. info.PaRcdDelDays = strconv.Itoa(int(data[5]))
  528. info.CpaRcdDelDays = strconv.Itoa(int(data[6]))
  529. //info.OpaRcdStorageDays = int(data[7])
  530. //info.OpaRcdDelDays = int(data[8])
  531. //lfshook.NewLogger().Infof("=============Set record Conf : %+v", info)
  532. filePath := "/etc/asterisk/recording.conf"
  533. _, err := os.Stat(filePath)
  534. if err != nil {
  535. logrus.Error(err)
  536. return
  537. }
  538. iniFile, err := ini.Load(filePath)
  539. if err != nil {
  540. logrus.Error(err)
  541. return
  542. }
  543. iniFile.Section("general").Key("PADRCD").SetValue(info.PadRcdEnable)
  544. iniFile.Section("general").Key("PADRCDDAYS").SetValue(info.PadRcdStorageDays)
  545. iniFile.Section("general").Key("PARCDDAYS").SetValue(info.PaRcdStorageDays)
  546. iniFile.Section("general").Key("CPARCDDAYS").SetValue(info.CpaRcdStorageDays)
  547. iniFile.Section("general").Key("PADRCDDELDAYS").SetValue(info.PadRcdDelDays)
  548. iniFile.Section("general").Key("PARCDDELDAYS").SetValue(info.PaRcdDelDays)
  549. iniFile.Section("general").Key("CPARCDDELDAYS").SetValue(info.CpaRcdDelDays)
  550. iniFile.SaveTo(filePath)
  551. }