package models import ( "eta/eta_task/global" "eta/eta_task/utils" "fmt" "html" "time" ) var ( BusinessConfMap map[string]string ) const ( BusinessConfUseXf = "UseXf" BusinessConfXfAppid = "XfAppid" BusinessConfXfApiKey = "XfApiKey" BusinessConfXfApiSecret = "XfApiSecret" BusinessConfXfVcn = "XfVcn" BusinessConfEnPptCoverImgs = "EnPptCoverImgs" BusinessConfEsIndexNameExcel = "EsIndexNameExcel" // ES索引名称-表格 BusinessConfEsIndexNameDataSource = "EsIndexNameDataSource" // ES索引名称-数据源 BusinessConfSyncDataEsDaily = "SyncDataEsDaily" // 每日同步数据源ES开关 ) // BusinessConf 商户配置表 type BusinessConf struct { Id int `gorm:"column:id;primaryKey;autoIncrement"` 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 } func (m *BusinessConf) TableName() string { return "business_conf" } // GetBusinessConf 获取商家配置 func GetBusinessConf() (list map[string]string, err error) { list = make(map[string]string) var items []*BusinessConf sql := `SELECT * FROM business_conf` err = global.DbMap[utils.DbNameMaster].Raw(sql).Find(&items).Error 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 (m *BusinessConf) GetItemByConfKey(key string) (item *BusinessConf, err error) { o := global.DbMap[utils.DbNameMaster] sql := fmt.Sprintf(`SELECT * FROM %s WHERE conf_key = ? LIMIT 1`, m.TableName()) err = o.Raw(sql, key).First(&item).Error return } type EdbStopRefreshRule struct { IsOpen int `description:"是否开启自动禁用1,开启,0未开启"` BaseIndexStopDays int `description:"数据源间隔天数未加入指标库则停用"` EdbStopDays int `description:"指标库间隔天数未引用则停用"` } func InitBusinessConf() { var e error BusinessConfMap, e = GetBusinessConf() if e != nil { return } // ES索引名称 if BusinessConfMap[BusinessConfEsIndexNameExcel] != "" { utils.EsExcelIndexName = BusinessConfMap[BusinessConfEsIndexNameExcel] } if BusinessConfMap[BusinessConfEsIndexNameDataSource] != "" { utils.EsDataSourceIndexName = BusinessConfMap[BusinessConfEsIndexNameDataSource] } }