business_conf.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package models
  2. import (
  3. "eta/eta_chart_lib/global"
  4. "eta/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. Id int `gorm:"column:id;primaryKey"`
  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. sql := `SELECT * FROM business_conf`
  38. err = global.DEFAULT_DB.Raw(sql).Find(&items).Error
  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. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  53. err = global.DEFAULT_DB.Raw(sql, key).First(&item).Error
  54. return
  55. }
  56. func GetBusinessConfByKeys(key []string) (list map[string]string, err error) {
  57. list = make(map[string]string)
  58. if len(key) == 0 {
  59. return
  60. }
  61. var items []*BusinessConf
  62. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key IN (?) `)
  63. err = global.DEFAULT_DB.Raw(sql, key).Find(&items).Error
  64. for _, v := range items {
  65. if v.ValType == 4 {
  66. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  67. continue
  68. }
  69. list[v.ConfKey] = v.ConfVal
  70. }
  71. return
  72. }
  73. // InitUseMongoConf
  74. // @Description:
  75. // @author: Roc
  76. // @datetime 2024-07-01 13:49:09
  77. func InitUseMongoConf() {
  78. useMongo, e := GetBusinessConfByKey("UseMongo")
  79. if e != nil {
  80. return
  81. }
  82. if useMongo.ConfVal == `true` {
  83. utils.UseMongo = true
  84. }
  85. }