business_conf.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package models
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "fmt"
  5. "html"
  6. "time"
  7. "github.com/beego/beego/v2/client/orm"
  8. )
  9. const (
  10. BusinessConfCompanyName = "CompanyName"
  11. BusinessConfCompanyWatermark = "CompanyWatermark"
  12. BusinessConfWatermarkChart = "WatermarkChart"
  13. BusinessConfIsOpenChartExpired = "IsOpenChartExpired" // 图表是否鉴权
  14. )
  15. // FromSceneMap 数据源名称与数据源ID的对应关系
  16. var FromSceneMap = map[int]string{
  17. 1: "SmartReportSheetSize",
  18. 2: "ReportSheetSize",
  19. 3: "EnReportSheetSize",
  20. 4: "CnPptSheetSize",
  21. 5: "EnPptSheetSize",
  22. }
  23. // BusinessConf 商户配置表
  24. type BusinessConf struct {
  25. Id int `orm:"column(id);pk"`
  26. ConfKey string `description:"配置Key"`
  27. ConfVal string `description:"配置值"`
  28. ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  29. Necessary int `description:"是否必填:0-否;1-是"`
  30. Remark string `description:"备注"`
  31. CreateTime time.Time
  32. }
  33. // GetBusinessConf 获取商家配置
  34. func GetBusinessConf() (list map[string]string, err error) {
  35. list = make(map[string]string)
  36. var items []*BusinessConf
  37. o := orm.NewOrm()
  38. sql := `SELECT * FROM business_conf`
  39. _, err = o.Raw(sql).QueryRows(&items)
  40. if err != nil {
  41. return
  42. }
  43. for _, v := range items {
  44. if v.ValType == 4 {
  45. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  46. continue
  47. }
  48. list[v.ConfKey] = v.ConfVal
  49. }
  50. return
  51. }
  52. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  53. o := orm.NewOrm()
  54. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  55. err = o.Raw(sql, key).QueryRow(&item)
  56. return
  57. }
  58. func GetBusinessConfByKeys(key []string) (list map[string]string, err error) {
  59. list = make(map[string]string)
  60. if len(key) == 0 {
  61. return
  62. }
  63. var items []*BusinessConf
  64. o := orm.NewOrm()
  65. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key IN (%s) `, utils.GetOrmInReplace(len(key)))
  66. _, err = o.Raw(sql, key).QueryRows(&items)
  67. for _, v := range items {
  68. if v.ValType == 4 {
  69. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  70. continue
  71. }
  72. list[v.ConfKey] = v.ConfVal
  73. }
  74. return
  75. }
  76. // InitUseMongoConf
  77. // @Description:
  78. // @author: Roc
  79. // @datetime 2024-07-01 13:49:09
  80. func InitUseMongoConf() {
  81. useMongo, e := GetBusinessConfByKey("UseMongo")
  82. if e != nil {
  83. return
  84. }
  85. if useMongo.ConfVal == `true` {
  86. utils.UseMongo = true
  87. }
  88. }