business_conf.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. var FromSceneMap = map[int]string{
  15. 1: "SmartReportSheetSize",
  16. 2: "ReportSheetSize",
  17. 3: "EnReportSheetSize",
  18. 4: "CnPptSheetSize",
  19. 5: "EnPptSheetSize",
  20. }
  21. type BusinessConf struct {
  22. Id int `gorm:"column:id;primaryKey" description:"配置ID" orm:"column(id);pk"`
  23. ConfKey string `gorm:"column:conf_key" description:"配置Key"`
  24. ConfVal string `gorm:"column:conf_val" description:"配置值"`
  25. ValType int `gorm:"column:val_type" description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  26. Necessary int `gorm:"column:necessary" description:"是否必填:0-否;1-是"`
  27. Remark string `gorm:"column:remark" description:"备注"`
  28. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  29. }
  30. func GetBusinessConf() (list map[string]string, err error) {
  31. list = make(map[string]string)
  32. var items []*BusinessConf
  33. o := global.DEFAULT_DmSQL
  34. sql := `SELECT * FROM business_conf`
  35. err = o.Raw(sql).Scan(&items).Error
  36. if err != nil {
  37. return
  38. }
  39. for _, v := range items {
  40. if v.ValType == 4 {
  41. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  42. continue
  43. }
  44. list[v.ConfKey] = v.ConfVal
  45. }
  46. return
  47. }
  48. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  49. o := global.DEFAULT_DmSQL
  50. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? `)
  51. err = o.Raw(sql, key).First(&item).Error
  52. return
  53. }
  54. func InitUseMongoConf() {
  55. useMongo, e := GetBusinessConfByKey("UseMongo")
  56. if e != nil {
  57. return
  58. }
  59. if useMongo.ConfVal == `true` {
  60. utils.UseMongo = true
  61. }
  62. }