123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- package models
- import (
- "eta_gn/eta_task/global"
- "eta_gn/eta_task/utils"
- "fmt"
- "html"
- "strings"
- "time"
- )
- const (
- BusinessConfUseXf = "UseXf"
- BusinessConfXfAppid = "XfAppid"
- BusinessConfXfApiKey = "XfApiKey"
- BusinessConfXfApiSecret = "XfApiSecret"
- BusinessConfXfVcn = "XfVcn"
- BusinessConfEnPptCoverImgs = "EnPptCoverImgs"
- BusinessOpenOaMsg = "OpenOaMsg" // 是否开启OA消息推送
- BusinessOaReportHost = "OaReportHost" // OA推送跳转报告Host
- )
- // BusinessConf 商户配置表
- type BusinessConf struct {
- Id int `gorm:"column:id;primaryKey"` // `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
- }
- func (m *BusinessConf) TableName() string {
- return "business_conf"
- }
- func (m *BusinessConf) PrimaryId() string {
- return "id"
- }
- func (m *BusinessConf) Create() (err error) {
- //o := orm.NewOrmUsingDB("eta")
- //id, err := o.Insert(m)
- //if err != nil {
- // return
- //}
- //m.Id = int(id)
- err = global.DmSQL["eta"].Create(m).Error
- return
- }
- func (m *BusinessConf) CreateMulti(items []*BusinessConf) (err error) {
- if len(items) == 0 {
- return
- }
- //o := orm.NewOrmUsingDB("eta")
- //_, err = o.InsertMulti(len(items), items)
- err = global.DmSQL["eta"].CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- func (m *BusinessConf) Update(cols []string) (err error) {
- //o := orm.NewOrmUsingDB("eta")
- //_, err = o.Update(m, cols...)
- err = global.DmSQL["eta"].Select(cols).Updates(m).Error
- return
- }
- func (m *BusinessConf) Del() (err error) {
- //o := orm.NewOrmUsingDB("eta")
- //sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- //_, err = o.Raw(sql, m.Id).Exec()
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- err = global.DmSQL["eta"].Exec(sql, m.Id).Error
- return
- }
- func (m *BusinessConf) GetItemById(id int) (item *BusinessConf, err error) {
- //o := orm.NewOrmUsingDB("eta")
- //sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- //err = o.Raw(sql, id).QueryRow(&item)
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- err = global.DmSQL["eta"].Raw(sql, id).Find(&item).Error
- return
- }
- func (m *BusinessConf) GetItemByCondition(condition string, pars []interface{}) (item *BusinessConf, err error) {
- //o := orm.NewOrmUsingDB("eta")
- //sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
- //err = o.Raw(sql, pars).QueryRow(&item)
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
- err = global.DmSQL["eta"].Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *BusinessConf) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- //o := orm.NewOrmUsingDB("eta")
- //sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- //err = o.Raw(sql, pars).QueryRow(&count)
- sql := fmt.Sprintf(`SELECT COUNT(1) AS count FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = global.DmSQL["eta"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *BusinessConf) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BusinessConf, err error) {
- //o := orm.NewOrmUsingDB("eta")
- //fields := strings.Join(fieldArr, ",")
- //if len(fieldArr) == 0 {
- // fields = `*`
- //}
- //order := `ORDER BY create_time DESC`
- //if orderRule != "" {
- // order = ` ORDER BY ` + orderRule
- //}
- //sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- //_, err = o.Raw(sql, pars).QueryRows(&items)
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error
- return
- }
- func (m *BusinessConf) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BusinessConf, err error) {
- //o := orm.NewOrmUsingDB("eta")
- //fields := strings.Join(fieldArr, ",")
- //if len(fieldArr) == 0 {
- // fields = `*`
- //}
- //order := `ORDER BY create_time DESC`
- //if orderRule != "" {
- // order = ` ORDER BY ` + orderRule
- //}
- //sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
- //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
- pars = append(pars, startSize, pageSize)
- err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetBusinessConf 获取商家配置
- func GetBusinessConf() (list map[string]string, err error) {
- list = make(map[string]string)
- var items []*BusinessConf
- //o := orm.NewOrmUsingDB("eta")
- //sql := `SELECT * FROM business_conf`
- //_, err = o.Raw(sql).QueryRows(&items)
- //if err != nil {
- // return
- //}
- sql := `SELECT * FROM business_conf`
- err = global.DmSQL["eta"].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
- }
- // BusinessConfUpdate 更新配置
- type BusinessConfUpdate struct {
- ConfKey string
- ConfVal string
- }
- //// UpdateBusinessConfMulti 批量修改配置
- //func UpdateBusinessConfMulti(items []BusinessConfUpdate) (err error) {
- // o := orm.NewOrmUsingDB("eta")
- // p, err := o.Raw("UPDATE business_conf SET conf_val = ? WHERE conf_key = ?").Prepare()
- // if err != nil {
- // return
- // }
- // defer func() {
- // _ = p.Close()
- // }()
- // for _, v := range items {
- // _, err = p.Exec(v.ConfVal, v.ConfKey)
- // if err != nil {
- // return
- // }
- // }
- // return
- //}
- func (m *BusinessConf) GetItemByConfKey(key string) (item *BusinessConf, err error) {
- //o := orm.NewOrmUsingDB("eta")
- //sql := fmt.Sprintf(`SELECT * FROM %s WHERE conf_key = ? LIMIT 1`, m.TableName())
- //err = o.Raw(sql, key).QueryRow(&item)
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE conf_key = ? LIMIT 1`, m.TableName())
- err = global.DmSQL["eta"].Raw(sql, key).First(&item).Error
- return
- }
- type EdbStopRefreshRule struct {
- IsOpen int `description:"是否开启自动禁用1,开启,0未开启"`
- BaseIndexStopDays int `description:"数据源间隔天数未加入指标库则停用"`
- EdbStopDays int `description:"指标库间隔天数未引用则停用"`
- }
- func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
- sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
- err = global.DmSQL["eta"].Raw(sql, key).First(&item).Error
- return
- }
|