business_conf.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. )
  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. // GetBusinessConf 获取商家配置
  33. func GetBusinessConf() (list map[string]string, err error) {
  34. list = make(map[string]string)
  35. var items []*BusinessConf
  36. o := orm.NewOrm()
  37. sql := `SELECT * FROM business_conf`
  38. _, err = o.Raw(sql).QueryRows(&items)
  39. if err != nil {
  40. return
  41. }
  42. for _, v := range items {
  43. if v.ValType == 4 {
  44. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  45. continue
  46. }
  47. list[v.ConfKey] = v.ConfVal
  48. }
  49. return
  50. }
  51. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  52. o := orm.NewOrm()
  53. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  54. err = o.Raw(sql, key).QueryRow(&item)
  55. return
  56. }
  57. func GetBusinessConfByKeys(key []string) (list map[string]string, err error) {
  58. list = make(map[string]string)
  59. if len(key) == 0 {
  60. return
  61. }
  62. var items []*BusinessConf
  63. o := orm.NewOrm()
  64. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key IN (%s) `, utils.GetOrmInReplace(len(key)))
  65. _, err = o.Raw(sql, key).QueryRows(&items)
  66. for _, v := range items {
  67. if v.ValType == 4 {
  68. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  69. continue
  70. }
  71. list[v.ConfKey] = v.ConfVal
  72. }
  73. return
  74. }
  75. // InitUseMongoConf
  76. // @Description:
  77. // @author: Roc
  78. // @datetime 2024-07-01 13:49:09
  79. func InitUseMongoConf() {
  80. useMongo, e := GetBusinessConfByKey("UseMongo")
  81. if e != nil {
  82. return
  83. }
  84. if useMongo.ConfVal == `true` {
  85. utils.UseMongo = true
  86. }
  87. }