index.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package priority
  2. import (
  3. "os"
  4. "pbx-api-gin/pkg/lfshook"
  5. "strconv"
  6. "github.com/sirupsen/logrus"
  7. "gopkg.in/ini.v1"
  8. )
  9. var ICPAnswer = 0
  10. var OCCAnswer = 0
  11. var RunningTypePriority = 0
  12. var RunningType = ""
  13. var SpecialVoice = 0
  14. var RunningPATaskChan = ""
  15. type PriorityAll struct {
  16. ManuPa string `json:"manualPa"`
  17. CabCab string `json:"cabCab"`
  18. PADICP string `json:"padIcp"`
  19. PADTMS string `json:"padTms"`
  20. PADOCC string `json:"padOcc"`
  21. CPA string `json:"cpa"`
  22. EMG string `json:"emg"`
  23. SPC string `json:"spc"`
  24. DCS string `json:"dcs"`
  25. STN string `json:"stn"`
  26. CHK string `json:"chk"`
  27. }
  28. var Priority PriorityAll
  29. func GetPriority() {
  30. filePath := "/etc/asterisk/priority.conf"
  31. _, err := os.Stat(filePath)
  32. if err != nil {
  33. logrus.Error(err)
  34. return
  35. }
  36. iniFile, err := ini.Load(filePath)
  37. if err != nil {
  38. logrus.Error(err)
  39. return
  40. }
  41. Priority.CHK = iniFile.Section("general").Key("CHK").Value()
  42. Priority.STN = iniFile.Section("general").Key("STN").Value()
  43. Priority.DCS = iniFile.Section("general").Key("DCS").Value()
  44. Priority.SPC = iniFile.Section("general").Key("SPC").Value()
  45. Priority.EMG = iniFile.Section("general").Key("EMG").Value()
  46. Priority.CPA = iniFile.Section("general").Key("CPA").Value()
  47. Priority.PADOCC = iniFile.Section("general").Key("PAD-OCC").Value()
  48. Priority.PADTMS = iniFile.Section("general").Key("PAD-TMS").Value()
  49. Priority.PADICP = iniFile.Section("general").Key("PAD-ICP").Value()
  50. Priority.CabCab = iniFile.Section("general").Key("CabCab").Value()
  51. Priority.ManuPa = iniFile.Section("general").Key("ManuPa").Value()
  52. }
  53. func GetPriorityByKey(key string) string {
  54. filePath := "/etc/asterisk/priority.conf"
  55. _, err := os.Stat(filePath)
  56. if err != nil {
  57. logrus.Error(err)
  58. return ""
  59. }
  60. iniFile, err := ini.Load(filePath)
  61. if err != nil {
  62. logrus.Error(err)
  63. return ""
  64. }
  65. return iniFile.Section("general").Key(key).Value()
  66. }
  67. // check priority , if the running priority is lowwer than the to run priority
  68. func CheckPriority(runType string) bool {
  69. lfshook.NewLogger().Logger.Infof("=========Check Pri runType:%s====RunningTypePriority:%d============", runType, RunningTypePriority)
  70. //check special voice
  71. if SpecialVoice == 1 {
  72. return false
  73. }
  74. //no any runing task
  75. if RunningTypePriority == 0 {
  76. return true
  77. }
  78. //get the priority to run in the config file
  79. ret, err := strconv.Atoi(GetPriorityByKey(runType))
  80. if err != nil {
  81. logrus.Error(err)
  82. return false
  83. }
  84. lfshook.NewLogger().Logger.Infof("=========Check Pri GetPriorityByKey:%d============", ret)
  85. //if the running task priority is lowwer
  86. if ret < RunningTypePriority && ret != 0 {
  87. return true
  88. }
  89. return false
  90. }