|
@@ -967,6 +967,102 @@ func getCorrelationChartInfoDetail(chartInfo *chartInfoModel.ChartInfoView, myCh
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// RefreshCrossVarietyChartInfo 刷新跨品种分析图表信息
|
|
|
+// @Tags 图库模块
|
|
|
+// @Summary 刷新跨品种分析图表信息
|
|
|
+// @Description 刷新跨品种分析图表信息
|
|
|
+// @Security ApiKeyAuth
|
|
|
+// @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
|
|
|
+// @Accept json
|
|
|
+// @Product json
|
|
|
+// @Param data body chartInfoModel.SaveChartInfoReq true "请求参数"
|
|
|
+// @Success 200 {string} string "操作成功"
|
|
|
+// @failure 400 {string} string "操作失败"
|
|
|
+// @Router /my_chart/cross_variety/refreshChartInfo [post]
|
|
|
+func RefreshCrossVarietyChartInfo(c *gin.Context) {
|
|
|
+ // 参数校验
|
|
|
+ var req chartInfoModel.RefreshChartInfoReq
|
|
|
+ if c.ShouldBind(&req) != nil {
|
|
|
+ response.Fail("参数异常", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartInfoId := req.ChartInfoId
|
|
|
+ if chartInfoId == 0 {
|
|
|
+ response.Fail("参数有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userInfo := user.GetInfoByClaims(c)
|
|
|
+ ok, _, err := user.GetAdminByUserInfo(userInfo)
|
|
|
+ if err != nil {
|
|
|
+ response.FailMsg("刷新失败", "RefreshChartInfo-获取系统用户信息失败"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !ok {
|
|
|
+ // 普通用户刷新频率限制-每个用户/图/天/2次
|
|
|
+ cacheKey := utils.HZ_CHART_LIB_DETAIL + "YB_REFRESH_LIMIT_" + strconv.Itoa(chartInfoId) + "_" + strconv.Itoa(int(userInfo.UserID))
|
|
|
+ countUserRefresh, _ := global.Redis.Get(context.TODO(), cacheKey).Int()
|
|
|
+ if countUserRefresh >= 2 {
|
|
|
+ response.Ok("目前已是最新数据", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ countUserRefresh += 1
|
|
|
+ now := time.Now()
|
|
|
+ today := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
|
|
|
+ sub := today.Sub(now)
|
|
|
+ _ = global.Redis.SetEX(context.TODO(), cacheKey, countUserRefresh, sub)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图表信息校验
|
|
|
+ chartInfo, err := chartInfoModel.GetChartInfoById(chartInfoId)
|
|
|
+ if err != nil {
|
|
|
+ if err == utils.ErrNoRow {
|
|
|
+ response.Fail("图表已被删除,无需刷新", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.FailMsg("刷新失败", "刷新失败, Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var config request.ChartConfigReq
|
|
|
+ err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
|
|
|
+ if err != nil {
|
|
|
+ response.FailMsg("解析跨品种分析配置失败", "解析跨品种分析配置失败, Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取关联的指标信息
|
|
|
+ _, _, edbInfoIdList, err := cross_variety.GetXYEdbIdList(config.TagX, config.TagY, config.VarietyList)
|
|
|
+ if err != nil {
|
|
|
+ response.FailMsg("获取指标信息失败", "刷新失败,获取指标信息失败, Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 刷新图表
|
|
|
+ //_ = correlation.ChartInfoRefresh(chartInfo.ChartInfoId)
|
|
|
+
|
|
|
+ err, errMsg := chart.EdbInfoRefreshAllFromBase(edbInfoIdList, false)
|
|
|
+ if err != nil {
|
|
|
+ errContent := fmt.Sprint("刷新图表关联指标信息失败 errMsg:", errMsg, "err: "+err.Error())
|
|
|
+ if global.CONFIG.Serve.RunMode == "release" {
|
|
|
+ go alarm_msg.SendAlarmMsg("刷新图表报错"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+errContent, 3)
|
|
|
+ //go services.SendEmail("弘则研报小程序-release-刷新图表报错", errContent, utils.EmailSendToUsers)
|
|
|
+ } else {
|
|
|
+ global.LOG.Info(errContent)
|
|
|
+ }
|
|
|
+
|
|
|
+ response.FailMsg("刷新失败", "刷新失败,获取指标信息失败, Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //清除图表缓存
|
|
|
+ {
|
|
|
+ key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
|
|
|
+ _ = global.Redis.Del(context.TODO(), key)
|
|
|
+ }
|
|
|
+ response.OkData("刷新成功", "", c)
|
|
|
+}
|
|
|
+
|
|
|
// RefreshCorrelationChartInfo 刷新相关性图表信息
|
|
|
// @Tags 图库模块
|
|
|
// @Summary 刷新图表信息
|