package controllers import ( "encoding/json" "eta_gn/eta_chart_lib/models" "eta_gn/eta_chart_lib/utils" "fmt" "time" ) // TableController 表格 type TableController struct { BaseAuthController } // TableInfoDetail // @Title 获取表格详情 // @Description 获取表格详情接口 // @Param UniqueCode query string true "表格唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc" // @Success 200 {object} data_manage.TableInfoDetailResp // @router /detail [get] func (this *TableController) TableInfoDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() uniqueCode := this.GetString("UniqueCode") if uniqueCode == "" { br.Msg = "参数错误" br.ErrMsg = "参数错误,uniqueCode is empty" return } key := utils.HZ_TABLE_LIB_DETAIL + uniqueCode resp := new(models.TableInfoDetailResp) //判断是否有缓存 if utils.Re == nil { if utils.Re == nil && utils.Rc.IsExist(key) { if data, err1 := utils.Rc.RedisBytes(key); err1 == nil { err := json.Unmarshal(data, &resp) if err == nil && resp != nil { br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp fmt.Println("source redis") return } } } } tableInfo, err := models.GetTableInfoByUniqueCode(uniqueCode) if err != nil { if utils.IsErrNoRow(err) { br.Msg = "该表格已被删除,请刷新页面" br.ErrMsg = "该表格已被删除,请刷新页面,Err:" + err.Error() return } br.Msg = "获取失败" br.ErrMsg = "获取表格信息失败,Err:" + err.Error() return } dataList, err := models.GetTableDataListByTableInfoId(tableInfo.TableInfoId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取表格数据失败,Err:" + err.Error() return } resp.TableInfo = tableInfo resp.TableDataList = dataList if utils.Re == nil { data, _ := json.Marshal(resp) utils.Rc.Put(key, data, 10*time.Minute) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }