package report_chapter_type

import (
	"context"
	jsoniter "github.com/json-iterator/go"
	"hongze/hongze_yb/global"
	model "hongze/hongze_yb/models/tables/report_chapter_type"
	"hongze/hongze_yb/utils"
	"time"
)
// GetEffectTypeID 获取缓存中的可用章节
func GetEffectTypeID() (chapterIds []int, err error ) {
	cacheKey := utils.HONGZEYB_ + "report_chapter_type:GetEffectTypeID"
	chapterIdsStr, _ := global.Redis.Get(context.TODO(), cacheKey).Result()
	if chapterIdsStr != "" {
		err = jsoniter.UnmarshalFromString(chapterIdsStr, &chapterIds)
		return
	}
	chapterIds, err = model.GetEffectTypeID()
	if err == nil && len(chapterIds) > 0 {
		chapterIdsStr, err = jsoniter.MarshalToString(chapterIds)
		if err != nil {
			return
		}
		_ = global.Redis.SetEX(context.TODO(), cacheKey, chapterIdsStr, 2*time.Hour)
	}
	return
}
