package base_config

import (
	"context"
	"fmt"
	"hongze/hongze_yb/global"
	"hongze/hongze_yb/models/tables/business_conf"
	"hongze/hongze_yb/utils"
	"html"
	"time"
)

func GetBusinessConfDisclaimer() (disclaimer string, err error) {
	cacheKey := utils.HONGZEYB_ + "business_conf:disclaimer"
	disclaimer, _ = global.Redis.Get(context.TODO(), cacheKey).Result()
	if disclaimer != "" {
		disclaimer = html.UnescapeString(disclaimer)
		return
	}
	obj := new(business_conf.BusinessConf)
	item, err := obj.GetItemByConfKey("Disclaimer")
	if err != nil {
		err = fmt.Errorf("GetBusinessConfDisclaimer err:%v", err)
		return
	}
	if item.Id <= 0 {
		err = fmt.Errorf("研报声明未配置")
		return
	}
	disclaimer = item.ConfVal
	_ = global.Redis.Set(context.TODO(), cacheKey, disclaimer, 24*time.Hour)
	disclaimer = html.UnescapeString(disclaimer)
	return
}

// CheckIsOpenChartExpired
// @Description: 判断是否开启图表授权
// @author: Roc
// @datetime 2025-01-07 16:51:34
// @return isOpenChartExpired bool
// @return err error
func CheckIsOpenChartExpired() (isOpenChartExpired bool, err error) {
	obj := new(business_conf.BusinessConf)
	item, err := obj.GetItemByConfKey("IsOpenChartExpired")
	if err != nil {
		err = fmt.Errorf("checkBusinessConfIsOpenChartExpired err:%v", err)
		return
	}
	if item.Id <= 0 {
		return
	}
	if item.ConfVal == `true` {
		isOpenChartExpired = true
	}

	return
}
