package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "fmt" "html" "strings" "time" ) var ( BusinessConfMap map[string]string ) const ( BusinessConfUseXf = "UseXf" BusinessConfXfAppid = "XfAppid" BusinessConfXfApiKey = "XfApiKey" BusinessConfXfApiSecret = "XfApiSecret" BusinessConfXfVcn = "XfVcn" BusinessConfEnPptCoverImgs = "EnPptCoverImgs" BusinessConfIsReportApprove = "IsReportApprove" BusinessConfIsBIApprove = "IsBIApprove" BusinessConfReportApproveType = "ReportApproveType" BusinessConfCompanyName = "CompanyName" BusinessConfCompanyWatermark = "CompanyWatermark" BusinessConfWatermarkChart = "WatermarkChart" BusinessConfLoginSmsTpId = "LoginSmsTpId" BusinessConfLoginSmsGjTpId = "LoginSmsGjTpId" BusinessConfSmsJhgnAppKey = "SmsJhgnAppKey" BusinessConfSmsJhgjAppKey = "SmsJhgjAppKey" BusinessConfLdapHost = "LdapHost" BusinessConfLdapBase = "LdapBase" BusinessConfLdapPort = "LdapPort" BusinessConfEmailClient = "EmailClient" BusinessConfEmailServerHost = "EmailServerHost" BusinessConfEmailServerPort = "EmailServerPort" BusinessConfEmailSender = "EmailSender" BusinessConfEmailSenderUserName = "EmailSenderUserName" BusinessConfEmailSenderPassword = "EmailSenderPassword" BusinessConfSmsClient = "SmsClient" BusinessConfNanHuaSmsAppKey = "NanHuaSmsAppKey" BusinessConfNanHuaSmsAppSecret = "NanHuaSmsAppSecret" BusinessConfNanHuaSmsApiHost = "NanHuaSmsApiHost" BusinessConfLoginSmsTplContent = "LoginSmsTplContent" BusinessConfLoginEmailTemplateSubject = "LoginEmailTemplateSubject" BusinessConfLoginEmailTemplateContent = "LoginEmailTemplateContent" BusinessConfLdapBindUserSuffix = "LdapBindUserSuffix" BusinessConfLdapUserFilter = "LdapUserFilter" BusinessConfTencentApiSecretId = "TencentApiSecretId" // 腾讯云API-密钥对 BusinessConfTencentApiSecretKey = "TencentApiSecretKey" // 腾讯云API-密钥对 BusinessConfTencentApiRecTaskCallbackUrl = "TencentApiRecTaskCallbackUrl" // 腾讯云API-语音识别回调地址 BusinessConfSmsJhgjVariable = "SmsJhgjVariable" // 聚合国际短信变量 BusinessConfEdbStopRefreshRule = "EdbStopRefreshRule" // 是否停止指标刷新规则 BusinessConfOuterReportApiUrl = "OuterReportApiUrl" // 智力共享-报告API地址 IgnoreEdbApproveUserId = `IgnoreEdbApproveUserId` // 忽略指标审批用户id集合 IgnoreChartApproveUserId = `IgnoreChartApproveUserId` //忽略图表审批用户id集合 ) const ( BusinessConfReportApproveTypeEta = "eta" BusinessConfReportApproveTypeOther = "other" BusinessConfClientFlagNanHua = "nhqh" // 南华标记 BusinessConfEmailClientSmtp = "smtp" // 普通邮箱标记 ) // FromSceneMap 数据源名称与数据源ID的对应关系 var FromSceneMap = map[int]string{ 1: "SmartReportSheetSize", 2: "ReportSheetSize", 3: "EnReportSheetSize", 4: "CnPptSheetSize", 5: "EnPptSheetSize", } // BusinessConf 商户配置表 type BusinessConf struct { Id int `gorm:"column:id;primaryKey"` //`orm:"column(id);pk" gorm:"primaryKey" ` ConfKey string `gorm:"column:conf_key"` //`description:"配置Key"` ConfVal string `gorm:"column:conf_val"` //`description:"配置值"` ValType int `gorm:"column:val_type"` //`description:"1-字符串;2-数值;3-字符串数组;4-富文本;"` Necessary int `gorm:"column:necessary"` //`description:"是否必填:0-否;1-是"` Remark string `gorm:"column:remark"` // `description:"备注"` CreateTime time.Time `gorm:"column:create_time"` } func (m *BusinessConf) TableName() string { return "business_conf" } func (m *BusinessConf) PrimaryId() string { return "id" } func (m *BusinessConf) Create() (err error) { err = global.DEFAULT_DmSQL.Create(m).Error return } func (m *BusinessConf) CreateMulti(items []*BusinessConf) (err error) { if len(items) == 0 { return } err = global.DEFAULT_DmSQL.CreateInBatches(items, utils.MultiAddNum).Error return } func (m *BusinessConf) Update(cols []string) (err error) { err = global.DEFAULT_DmSQL.Select(cols).Updates(m).Error return } func (m *BusinessConf) Del() (err error) { sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = global.DEFAULT_DmSQL.Exec(sql, m.Id).Error return } func (m *BusinessConf) GetItemById(id int) (item *BusinessConf, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = global.DEFAULT_DmSQL.Raw(sql, id).Find(&item).Error return } func (m *BusinessConf) GetItemByCondition(condition string, pars []interface{}) (item *BusinessConf, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&item).Error return } func (m *BusinessConf) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error return } func (m *BusinessConf) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BusinessConf, err error) { 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.DEFAULT_DmSQL.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) { 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) pars = append(pars, pageSize) err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error return } // GetBusinessConf 获取商家配置 func GetBusinessConf() (list map[string]string, err error) { list = make(map[string]string) var items []*BusinessConf sql := `SELECT * FROM business_conf` err = global.DEFAULT_DmSQL.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) { tx := global.DEFAULT_DmSQL.Begin() for _, v := range items { err = tx.Exec("UPDATE business_conf SET conf_val = ? WHERE conf_key = ?", v.ConfVal, v.ConfKey).Error if err != nil { tx.Rollback() return } } tx.Commit() return } func GetBusinessConfByKey(key string) (item *BusinessConf, err error) { sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`) err = global.DEFAULT_DmSQL.Raw(sql, key).First(&item).Error return } type BusinessConfSingleSaveReq struct { ConfKey string `description:"配置Key"` ConfVal string `description:"配置值"` } type EdbStopRefreshRule struct { IsOpen int `description:"是否开启自动禁用1,开启,0未开启"` BaseIndexStopDays int `description:"数据源间隔天数未加入指标库则停用"` EdbStopDays int `description:"指标库间隔天数未引用则停用"` } type BusinessConfSingleResp struct { ConfVal string } // 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 } } func InitBusinessConf() { var e error BusinessConfMap, e = GetBusinessConf() if e != nil { return } }