package controllers import ( "encoding/json" "eta/eta_index_lib/models" "eta/eta_index_lib/utils" "fmt" "time" ) // BaseFromTradeAnalysisController 持仓分析指标 type BaseFromTradeAnalysisController struct { BaseAuthController } // EdbRefresh // @Title 指标库刷新 // @Description 指标库刷新 // @Success 200 {object} models.RefreshEdbInfoReq // @router /edb/refresh [post] func (this *BaseFromTradeAnalysisController) EdbRefresh() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() var req models.RefreshEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.EdbCode == "" { br.Msg = "请输入指标编码!" br.ErrMsg = "请输入指标编码,指标编码为空" return } if req.EdbInfoId < 0 { br.Msg = "请输入指标ID!" br.ErrMsg = "请输入指标ID" return } thsOb := new(models.EdbThsHf) source := thsOb.GetSource() subSource := thsOb.GetSubSource() cacheKey := fmt.Sprintf("%s_%d_%d_%s", utils.CACHE_EDB_DATA_REFRESH, source, subSource, req.EdbCode) if utils.Rc.IsExist(cacheKey) { br.Ret = 501 br.Success = true br.Msg = "系统处理中,请稍后重试" return } utils.Rc.SetNX(cacheKey, 1, 1*time.Minute) defer func() { _ = utils.Rc.Delete(cacheKey) }() // 获取指标详情 //edbInfo, e := models.GetEdbInfoByEdbCode(source, req.EdbCode) //if e != nil { // br.Msg = "指标不存在" // br.ErrMsg = fmt.Sprintf("指标不存在, %v", e) // return //} // //// 获取指标关联信息 //baseMapping := new(models.BaseFromEdbMapping) //{ // ob := new(models.BaseFromEdbMapping) // cond := fmt.Sprintf(" AND %s = ? AND %s = ? AND %s = ?", ob.Cols().EdbCode, ob.Cols().Source, ob.Cols().SubSource) // pars := make([]interface{}, 0) // pars = append(pars, req.EdbCode, thsOb.GetSource(), thsOb.GetSubSource()) // mapping, e := ob.GetItemByCondition(cond, pars, "") // if e != nil { // br.Msg = "刷新失败" // br.ErrMsg = fmt.Sprintf("指标关联信息有误, %v", e) // return // } // baseMapping = mapping //} // //// 刷新指标 //if e = thsOb.Refresh(edbInfo, baseMapping, req.StartDate); e != nil { // br.Msg = "刷新指标失败" // br.ErrMsg = fmt.Sprintf("刷新指标失败, %v", e) // return //} // //// 更新指标最值 //if e = thsOb.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo); e != nil { // br.Msg = "刷新指标失败" // br.ErrMsg = fmt.Sprintf("更新指标最值失败, %v", e) // return //} // 更新ES //go logic.UpdateEs(edbInfo.EdbInfoId) br.Ret = 200 br.Success = true br.Msg = "操作成功" }