business_conf.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "html"
  6. "strings"
  7. "time"
  8. )
  9. const (
  10. BusinessConfUseXf = "UseXf"
  11. BusinessConfXfAppid = "XfAppid"
  12. BusinessConfXfApiKey = "XfApiKey"
  13. BusinessConfXfApiSecret = "XfApiSecret"
  14. BusinessConfXfVcn = "XfVcn"
  15. BusinessConfEnPptCoverImgs = "EnPptCoverImgs"
  16. BusinessConfIsReportApprove = "IsReportApprove"
  17. BusinessConfReportApproveType = "ReportApproveType"
  18. BusinessConfCompanyName = "CompanyName"
  19. BusinessConfCompanyWatermark = "CompanyWatermark"
  20. BusinessConfWatermarkChart = "WatermarkChart"
  21. BusinessConfLoginSmsTpId = "LoginSmsTpId"
  22. BusinessConfLoginSmsGjTpId = "LoginSmsGjTpId"
  23. BusinessConfSmsJhgnAppKey = "SmsJhgnAppKey"
  24. BusinessConfSmsJhgjAppKey = "SmsJhgjAppKey"
  25. BusinessConfLdapHost = "LdapHost"
  26. BusinessConfLdapBase = "LdapBase"
  27. BusinessConfLdapPort = "LdapPort"
  28. BusinessConfEmailClient = "EmailClient"
  29. BusinessConfEmailServerHost = "EmailServerHost"
  30. BusinessConfEmailServerPort = "EmailServerPort"
  31. BusinessConfEmailSender = "EmailSender"
  32. BusinessConfEmailSenderUserName = "EmailSenderUserName"
  33. BusinessConfEmailSenderPassword = "EmailSenderPassword"
  34. BusinessConfSmsClient = "SmsClient"
  35. BusinessConfNanHuaSmsAppKey = "NanHuaSmsAppKey"
  36. BusinessConfNanHuaSmsAppSecret = "NanHuaSmsAppSecret"
  37. BusinessConfNanHuaSmsApiHost = "NanHuaSmsApiHost"
  38. BusinessConfLoginSmsTplContent = "LoginSmsTplContent"
  39. BusinessConfLoginEmailTemplateSubject = "LoginEmailTemplateSubject"
  40. BusinessConfLoginEmailTemplateContent = "LoginEmailTemplateContent"
  41. BusinessConfLdapBindUserSuffix = "LdapBindUserSuffix"
  42. BusinessConfLdapUserFilter = "LdapUserFilter"
  43. BusinessConfTencentApiSecretId = "TencentApiSecretId" // 腾讯云API-密钥对
  44. BusinessConfTencentApiSecretKey = "TencentApiSecretKey" // 腾讯云API-密钥对
  45. BusinessConfTencentApiRecTaskCallbackUrl = "TencentApiRecTaskCallbackUrl" // 腾讯云API-语音识别回调地址
  46. BusinessConfSmsJhgjVariable = "SmsJhgjVariable" // 聚合国际短信变量
  47. BusinessConfEdbStopRefreshRule = "EdbStopRefreshRule" // 是否停止指标刷新规则
  48. )
  49. const (
  50. BusinessConfReportApproveTypeEta = "eta"
  51. BusinessConfReportApproveTypeOther = "other"
  52. BusinessConfClientFlagNanHua = "nhqh" // 南华标记
  53. BusinessConfEmailClientSmtp = "smtp" // 普通邮箱标记
  54. )
  55. // FromSceneMap 数据源名称与数据源ID的对应关系
  56. var FromSceneMap = map[int]string{
  57. 1: "SmartReportSheetSize",
  58. 2: "ReportSheetSize",
  59. 3: "EnReportSheetSize",
  60. 4: "CnPptSheetSize",
  61. 5: "EnPptSheetSize",
  62. }
  63. // BusinessConf 商户配置表
  64. type BusinessConf struct {
  65. Id int `orm:"column(id);pk"`
  66. ConfKey string `description:"配置Key"`
  67. ConfVal string `description:"配置值"`
  68. ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  69. Necessary int `description:"是否必填:0-否;1-是"`
  70. Remark string `description:"备注"`
  71. CreateTime time.Time
  72. }
  73. func (m *BusinessConf) TableName() string {
  74. return "business_conf"
  75. }
  76. func (m *BusinessConf) PrimaryId() string {
  77. return "id"
  78. }
  79. func (m *BusinessConf) Create() (err error) {
  80. o := orm.NewOrm()
  81. id, err := o.Insert(m)
  82. if err != nil {
  83. return
  84. }
  85. m.Id = int(id)
  86. return
  87. }
  88. func (m *BusinessConf) CreateMulti(items []*BusinessConf) (err error) {
  89. if len(items) == 0 {
  90. return
  91. }
  92. o := orm.NewOrm()
  93. _, err = o.InsertMulti(len(items), items)
  94. return
  95. }
  96. func (m *BusinessConf) Update(cols []string) (err error) {
  97. o := orm.NewOrm()
  98. _, err = o.Update(m, cols...)
  99. return
  100. }
  101. func (m *BusinessConf) Del() (err error) {
  102. o := orm.NewOrm()
  103. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  104. _, err = o.Raw(sql, m.Id).Exec()
  105. return
  106. }
  107. func (m *BusinessConf) GetItemById(id int) (item *BusinessConf, err error) {
  108. o := orm.NewOrm()
  109. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  110. err = o.Raw(sql, id).QueryRow(&item)
  111. return
  112. }
  113. func (m *BusinessConf) GetItemByCondition(condition string, pars []interface{}) (item *BusinessConf, err error) {
  114. o := orm.NewOrm()
  115. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  116. err = o.Raw(sql, pars).QueryRow(&item)
  117. return
  118. }
  119. func (m *BusinessConf) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  120. o := orm.NewOrm()
  121. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  122. err = o.Raw(sql, pars).QueryRow(&count)
  123. return
  124. }
  125. func (m *BusinessConf) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BusinessConf, err error) {
  126. o := orm.NewOrm()
  127. fields := strings.Join(fieldArr, ",")
  128. if len(fieldArr) == 0 {
  129. fields = `*`
  130. }
  131. order := `ORDER BY create_time DESC`
  132. if orderRule != "" {
  133. order = ` ORDER BY ` + orderRule
  134. }
  135. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  136. _, err = o.Raw(sql, pars).QueryRows(&items)
  137. return
  138. }
  139. func (m *BusinessConf) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BusinessConf, err error) {
  140. o := orm.NewOrm()
  141. fields := strings.Join(fieldArr, ",")
  142. if len(fieldArr) == 0 {
  143. fields = `*`
  144. }
  145. order := `ORDER BY create_time DESC`
  146. if orderRule != "" {
  147. order = ` ORDER BY ` + orderRule
  148. }
  149. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  150. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  151. return
  152. }
  153. // GetBusinessConf 获取商家配置
  154. func GetBusinessConf() (list map[string]string, err error) {
  155. list = make(map[string]string)
  156. var items []*BusinessConf
  157. o := orm.NewOrm()
  158. sql := `SELECT * FROM business_conf`
  159. _, err = o.Raw(sql).QueryRows(&items)
  160. if err != nil {
  161. return
  162. }
  163. for _, v := range items {
  164. if v.ValType == 4 {
  165. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  166. continue
  167. }
  168. list[v.ConfKey] = v.ConfVal
  169. }
  170. return
  171. }
  172. // BusinessConfUpdate 更新配置
  173. type BusinessConfUpdate struct {
  174. ConfKey string
  175. ConfVal string
  176. }
  177. // UpdateBusinessConfMulti 批量修改配置
  178. func UpdateBusinessConfMulti(items []BusinessConfUpdate) (err error) {
  179. o := orm.NewOrm()
  180. p, err := o.Raw("UPDATE business_conf SET conf_val = ? WHERE conf_key = ?").Prepare()
  181. if err != nil {
  182. return
  183. }
  184. defer func() {
  185. _ = p.Close()
  186. }()
  187. for _, v := range items {
  188. _, err = p.Exec(v.ConfVal, v.ConfKey)
  189. if err != nil {
  190. return
  191. }
  192. }
  193. return
  194. }
  195. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  196. o := orm.NewOrm()
  197. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  198. err = o.Raw(sql, key).QueryRow(&item)
  199. return
  200. }
  201. type BusinessConfSingleSaveReq struct {
  202. ConfKey string `description:"配置Key"`
  203. ConfVal string `description:"配置值"`
  204. }
  205. type EdbStopRefreshRule struct {
  206. IsOpen int `description:"是否开启自动禁用1,开启,0未开启"`
  207. BaseIndexStopDays int `description:"数据源间隔天数未加入指标库则停用"`
  208. EdbStopDays int `description:"指标库间隔天数未引用则停用"`
  209. }
  210. type BusinessConfSingleResp struct {
  211. ConfVal string
  212. }