|
@@ -0,0 +1,107 @@
|
|
|
+package business_conf
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
+ "hongze/hongze_open_api/utils"
|
|
|
+ "html"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ BusinessConfMap map[string]string
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ BusinessConfIsOpenChartExpired = "IsOpenChartExpired" // 是否开启图表有效期鉴权/报告禁止复制
|
|
|
+ BusinessConfReportChartExpiredTime = "ReportChartExpiredTime" // 图表有效期鉴权时间,单位:分钟
|
|
|
+ BusinessConfOssUrlReplace = "OssUrlReplace" // OSS地址替换-兼容内网客户用
|
|
|
+)
|
|
|
+
|
|
|
+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;autoIncrement"` //`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 GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("eta")
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
|
|
|
+
|
|
|
+ err = o.Raw(sql, key).QueryRow(&item)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetBusinessConf 获取商家配置
|
|
|
+func GetBusinessConf() (list map[string]string, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("eta")
|
|
|
+ list = make(map[string]string)
|
|
|
+
|
|
|
+ var items []*BusinessConf
|
|
|
+ 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 InitBusinessConf() {
|
|
|
+ var e error
|
|
|
+ BusinessConfMap, e = GetBusinessConf()
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图表有效期的过期时间
|
|
|
+ if BusinessConfMap[BusinessConfReportChartExpiredTime] != "" {
|
|
|
+ reportChartExpiredTime, _ := strconv.Atoi(BusinessConfMap[BusinessConfReportChartExpiredTime])
|
|
|
+ if reportChartExpiredTime <= 0 {
|
|
|
+ reportChartExpiredTime = 30
|
|
|
+ }
|
|
|
+ utils.BusinessConfReportChartExpiredTime = time.Duration(reportChartExpiredTime) * time.Minute
|
|
|
+ } else {
|
|
|
+ utils.BusinessConfReportChartExpiredTime = 30 * time.Minute
|
|
|
+ }
|
|
|
+
|
|
|
+}
|