business_conf.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package models
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "fmt"
  6. "html"
  7. "time"
  8. )
  9. const (
  10. BusinessConfCompanyName = "CompanyName"
  11. BusinessConfCompanyWatermark = "CompanyWatermark"
  12. BusinessConfWatermarkChart = "WatermarkChart"
  13. )
  14. // FromSceneMap 数据源名称与数据源ID的对应关系
  15. var FromSceneMap = map[int]string{
  16. 1: "SmartReportSheetSize",
  17. 2: "ReportSheetSize",
  18. 3: "EnReportSheetSize",
  19. 4: "CnPptSheetSize",
  20. 5: "EnPptSheetSize",
  21. }
  22. // BusinessConf 商户配置表
  23. // type BusinessConf struct {
  24. // Id int `orm:"column(id);pk"`
  25. // ConfKey string `description:"配置Key"`
  26. // ConfVal string `description:"配置值"`
  27. // ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  28. // Necessary int `description:"是否必填:0-否;1-是"`
  29. // Remark string `description:"备注"`
  30. // CreateTime time.Time
  31. // }
  32. // BusinessConf 商户配置表
  33. type BusinessConf struct {
  34. Id int `gorm:"column:id;primaryKey" description:"配置ID" orm:"column(id);pk"`
  35. ConfKey string `gorm:"column:conf_key" description:"配置Key"`
  36. ConfVal string `gorm:"column:conf_val" description:"配置值"`
  37. ValType int `gorm:"column:val_type" description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  38. Necessary int `gorm:"column:necessary" description:"是否必填:0-否;1-是"`
  39. Remark string `gorm:"column:remark" description:"备注"`
  40. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  41. }
  42. // GetBusinessConf 获取商家配置
  43. func GetBusinessConf() (list map[string]string, err error) {
  44. list = make(map[string]string)
  45. var items []*BusinessConf
  46. o := global.DEFAULT_DmSQL
  47. sql := `SELECT * FROM business_conf`
  48. err = o.Raw(sql).Scan(&items).Error
  49. if err != nil {
  50. return
  51. }
  52. for _, v := range items {
  53. if v.ValType == 4 {
  54. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  55. continue
  56. }
  57. list[v.ConfKey] = v.ConfVal
  58. }
  59. return
  60. }
  61. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  62. o := global.DEFAULT_DmSQL
  63. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? `)
  64. err = o.Raw(sql, key).First(&item).Error
  65. return
  66. }
  67. // InitUseMongoConf
  68. // @Description:
  69. // @author: Roc
  70. // @datetime 2024-07-01 13:49:09
  71. func InitUseMongoConf() {
  72. useMongo, e := GetBusinessConfByKey("UseMongo")
  73. if e != nil {
  74. return
  75. }
  76. if useMongo.ConfVal == `true` {
  77. utils.UseMongo = true
  78. }
  79. }
  80. // func GetBusinessConf() (list map[string]string, err error) {
  81. // list = make(map[string]string)
  82. // var items []*BusinessConf
  83. // o := orm.NewOrm()
  84. // sql := `SELECT * FROM business_conf`
  85. // _, err = o.Raw(sql).QueryRows(&items)
  86. // if err != nil {
  87. // return
  88. // }
  89. // for _, v := range items {
  90. // if v.ValType == 4 {
  91. // list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  92. // continue
  93. // }
  94. // list[v.ConfKey] = v.ConfVal
  95. // }
  96. // return
  97. // }
  98. // func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  99. // o := orm.NewOrm()
  100. // sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  101. // err = o.Raw(sql, key).QueryRow(&item)
  102. // return
  103. // }
  104. // // InitUseMongoConf
  105. // // @Description:
  106. // // @author: Roc
  107. // // @datetime 2024-07-01 13:49:09
  108. // func InitUseMongoConf() {
  109. // useMongo, e := GetBusinessConfByKey("UseMongo")
  110. // if e != nil {
  111. // return
  112. // }
  113. // if useMongo.ConfVal == `true` {
  114. // utils.UseMongo = true
  115. // }
  116. // }