package models

import (
	"encoding/json"
	"fmt"
	"hongze/hongze_edb_lib/utils"
)

type EdbInfoReq struct {
	EdbInfoId int `description:"图表id,新增时传0"`
}

// DeleteChartInfoDataRedis 清除图表缓存
func DeleteChartInfoDataRedis(bodyByte []byte) (err error) {
	var req EdbInfoReq
	err = json.Unmarshal(bodyByte, &req)
	if err != nil {
		return
	}
	if req.EdbInfoId > 0 {
		list, tmpErr := GetChartEdbMappingListByEdbInfoId(req.EdbInfoId)
		if tmpErr != nil {
			err = tmpErr
			return
		}

		// 删除图表的id
		for _, v := range list {
			_ = utils.Rc.Delete(GetChartInfoDataKey(v.ChartInfoId))
		}
	}
	return
}

// GetChartInfoDataKey 获取图表缓存的key
func GetChartInfoDataKey(chartInfoId int) string {
	key := fmt.Sprint(utils.CACHE_CHART_INFO_DATA, chartInfoId)
	return key
}
