business_conf.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package models
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  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. // 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. // InitUseMongoConf
  58. // @Description:
  59. // @author: Roc
  60. // @datetime 2024-07-01 13:49:09
  61. func InitUseMongoConf() {
  62. useMongo, e := GetBusinessConfByKey("UseMongo")
  63. if e != nil {
  64. return
  65. }
  66. if useMongo.ConfVal == `true` {
  67. utils.UseMongo = true
  68. }
  69. }