Roc 2 years ago
parent
commit
ea36eb5e50
5 changed files with 94 additions and 0 deletions
  1. 17 0
      controllers/base_auth.go
  2. 39 0
      models/chart.go
  3. 36 0
      models/chart_edb_mapping.go
  4. 1 0
      models/db.go
  5. 1 0
      utils/constants.go

+ 17 - 0
controllers/base_auth.go

@@ -16,6 +16,13 @@ import (
 
 var apiLog *log.Log
 
+type AfterHandle func(bodyByte []byte) error
+
+// AfterHandlerUrlMap 结束后待处理的url
+var AfterHandlerUrlMap = map[string][]AfterHandle{
+	"/edbapi/wind/refresh": {models.DeleteChartInfoDataRedis}, //指标刷新接口
+}
+
 func init() {
 	if utils.RunMode == "release" {
 		logDir := `/data/rdlucklog/` + utils.APP_NAME_EN
@@ -61,6 +68,16 @@ func (this *BaseAuthController) Prepare() {
 }
 
 func (c *BaseAuthController) ServeJSON(encoding ...bool) {
+	// 方法处理完后,需要后置处理的业务逻辑
+	//if handlerList, ok := AfterHandlerUrlMap[c.Ctx.Request.URL.Path]; ok {
+	//	for _, handler := range handlerList {
+	//		handler(c.Ctx.Input.RequestBody)
+	//	}
+	//}
+
+	//所有请求都做这么个处理吧,目前这边都是做编辑、刷新逻辑处理(新增的话,并没有指标id,不会有影响)
+	models.DeleteChartInfoDataRedis(c.Ctx.Input.RequestBody)
+
 	var (
 		hasIndent   = false
 		hasEncoding = false

+ 39 - 0
models/chart.go

@@ -0,0 +1,39 @@
+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 {
+			err = 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
+}

+ 36 - 0
models/chart_edb_mapping.go

@@ -0,0 +1,36 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type ChartEdbMapping struct {
+	ChartEdbMappingId int       `orm:"column(chart_edb_mapping_id);pk"`
+	ChartInfoId       int       `description:"图表id"`
+	EdbInfoId         int       `description:"指标id"`
+	CreateTime        time.Time `description:"创建时间"`
+	ModifyTime        time.Time `description:"修改时间"`
+	UniqueCode        string    `description:"唯一编码"`
+	MaxData           float64   `description:"上限"`
+	MinData           float64   `description:"下限"`
+	IsOrder           bool      `description:"true:正序,false:逆序"`
+	IsAxis            int       `description:"true:左轴,false:右轴"`
+	EdbInfoType       int       `description:"true:标准指标,false:领先指标"`
+	LeadValue         int       `description:"领先值"`
+	LeadUnit          string    `description:"领先单位"`
+	ChartStyle        string    `description:"图表类型"`
+	ChartColor        string    `description:"颜色"`
+	ChartWidth        float64   `description:"线条大小"`
+}
+
+// GetChartEdbMappingListByEdbInfoId 根据指标id获取关联图表列表
+func GetChartEdbMappingListByEdbInfoId(edbInfoId int) (list []*ChartEdbMapping, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT *
+             FROM chart_edb_mapping AS a
+			 WHERE edb_info_id=? 
+             ORDER BY chart_edb_mapping_id ASC `
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&list)
+	return
+}

+ 1 - 0
models/db.go

@@ -40,5 +40,6 @@ func init() {
 		new(EdbInfoCalculateMapping),
 		new(EdbPythonCode),
 		new(EdbDataPython),
+		new(ChartEdbMapping),
 	)
 }

+ 1 - 0
utils/constants.go

@@ -99,4 +99,5 @@ const (
 	CACHE_EDB_DATA_ADD     = "CACHE_EDB_DATA_ADD_"
 	CACHE_EDB_DATA_REFRESH = "CACHE_EDB_DATA_REFRESH_"
 	CACHE_WIND_URL         = "CACHE_WIND_URL"
+	CACHE_CHART_INFO_DATA  = "chart:info:data:" //图表数据
 )