123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package models
- import (
- "eta/eta_chart_lib/utils"
- "fmt"
- "html"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- const (
- BusinessConfCompanyName = "CompanyName"
- BusinessConfCompanyWatermark = "CompanyWatermark"
- BusinessConfWatermarkChart = "WatermarkChart"
- )
- // FromSceneMap 数据源名称与数据源ID的对应关系
- var FromSceneMap = map[int]string{
- 1: "SmartReportSheetSize",
- 2: "ReportSheetSize",
- 3: "EnReportSheetSize",
- 4: "CnPptSheetSize",
- 5: "EnPptSheetSize",
- }
- // BusinessConf 商户配置表
- type BusinessConf struct {
- Id int `orm:"column(id);pk"`
- ConfKey string `description:"配置Key"`
- ConfVal string `description:"配置值"`
- ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
- Necessary int `description:"是否必填:0-否;1-是"`
- Remark string `description:"备注"`
- CreateTime time.Time
- }
- // GetBusinessConf 获取商家配置
- func GetBusinessConf() (list map[string]string, err error) {
- list = make(map[string]string)
- var items []*BusinessConf
- o := orm.NewOrm()
- sql := `SELECT * FROM business_conf`
- _, err = o.Raw(sql).QueryRows(&items)
- if err != nil {
- return
- }
- for _, v := range items {
- if v.ValType == 4 {
- list[v.ConfKey] = html.UnescapeString(v.ConfVal)
- continue
- }
- list[v.ConfKey] = v.ConfVal
- }
- return
- }
- func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
- o := orm.NewOrm()
- sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
- err = o.Raw(sql, key).QueryRow(&item)
- return
- }
- func GetBusinessConfByKeys(key []string) (list map[string]string, err error) {
- list = make(map[string]string)
- if len(key) == 0 {
- return
- }
- var items []*BusinessConf
- o := orm.NewOrm()
- sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key IN (%s) `, utils.GetOrmInReplace(len(key)))
- _, err = o.Raw(sql, key).QueryRows(&items)
- for _, v := range items {
- if v.ValType == 4 {
- list[v.ConfKey] = html.UnescapeString(v.ConfVal)
- continue
- }
- list[v.ConfKey] = v.ConfVal
- }
- return
- }
- // InitUseMongoConf
- // @Description:
- // @author: Roc
- // @datetime 2024-07-01 13:49:09
- func InitUseMongoConf() {
- useMongo, e := GetBusinessConfByKey("UseMongo")
- if e != nil {
- return
- }
- if useMongo.ConfVal == `true` {
- utils.UseMongo = true
- }
- }
|