Sfoglia il codice sorgente

Merge branch 'eta/1.3.1' into debug

Roc 1 anno fa
parent
commit
3dae290dbe

+ 96 - 0
controller/chart/chart_common.go

@@ -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  刷新图表信息

+ 42 - 8
controller/chart/chart_info.go

@@ -17,6 +17,7 @@ import (
 	"hongze/hongze_yb/models/tables/yb_my_chart"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/chart"
+	"hongze/hongze_yb/services/chart/cross_variety"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"io/ioutil"
@@ -410,14 +411,47 @@ func RefreshChartInfo(c *gin.Context) {
 		return
 	}
 
-	// 刷新图表
-	if err = chart.ChartInfoRefreshV2(chartInfo.ChartInfoId); err != nil {
-		errContent := fmt.Sprint("ErrMsg: 刷新图表关联指标信息失败, " + 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)
+	if chartInfo.Source == utils.CHART_SOURCE_CROSS_HEDGING {
+		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
+		}
+	} else {
+		// 刷新图表
+		if err = chart.ChartInfoRefreshV2(chartInfo.ChartInfoId); err != nil {
+			errContent := fmt.Sprint("ErrMsg: 刷新图表关联指标信息失败, " + 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)
+			}
 		}
 	}
 

+ 1 - 2
models/tables/chart_tag/query.go

@@ -2,7 +2,6 @@ package chart_tag
 
 import (
 	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/utils"
 )
 
 // GetTagListByIdList
@@ -18,7 +17,7 @@ func GetTagListByIdList(idList []int) (items []*ChartTag, err error) {
 		return
 	}
 
-	sql := `SELECT * FROM chart_tag WHERE 1 = 1 AND chart_tag_id in (` + utils.GetOrmInReplace(num) + `)`
+	sql := `SELECT * FROM chart_tag WHERE 1 = 1 AND chart_tag_id in (?)`
 	err = global.MYSQL["data"].Raw(sql, idList).Find(&items).Error
 
 	return

+ 1 - 2
models/tables/chart_tag_variety/query.go

@@ -2,7 +2,6 @@ package chart_tag_variety
 
 import (
 	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/utils"
 )
 
 // GetChartTagVarietyListByTagAndVariety
@@ -18,7 +17,7 @@ func GetChartTagVarietyListByTagAndVariety(chartTagId int, varietyIdList []int)
 	if num <= 0 {
 		return
 	}
-	sql := `SELECT * FROM chart_tag_variety WHERE chart_tag_id = ? AND chart_variety_id in (` + utils.GetOrmInReplace(num) + `) `
+	sql := `SELECT * FROM chart_tag_variety WHERE chart_tag_id = ? AND chart_variety_id in (?) `
 	err = global.MYSQL["data"].Raw(sql, chartTagId, varietyIdList).Find(&items).Error
 
 	return

+ 1 - 2
models/tables/chart_variety/query.go

@@ -2,7 +2,6 @@ package chart_variety
 
 import (
 	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/utils"
 )
 
 // GetVarietyListByIdList
@@ -17,7 +16,7 @@ func GetVarietyListByIdList(idList []int) (items []*ChartVariety, err error) {
 	if num <= 0 {
 		return
 	}
-	sql := ` SELECT * FROM chart_variety WHERE 1 = 1 AND chart_variety_id in (` + utils.GetOrmInReplace(num) + `)`
+	sql := ` SELECT * FROM chart_variety WHERE 1 = 1 AND chart_variety_id in (?)`
 	err = global.MYSQL["data"].Raw(sql, idList).Find(&items).Error
 
 	return

+ 9 - 13
services/media.go

@@ -1,19 +1,15 @@
 package services
 
-import (
-	"github.com/tosone/minimp3"
-)
-
 // GetMP3PlayDuration 获取MP3的时长
 func GetMP3PlayDuration(mp3Data []byte) (seconds int, err error) {
-	dec, _, err := minimp3.DecodeFull(mp3Data)
-	if err != nil {
-		return 0, err
-	}
-	if dec.Kbps <= 0 {
-		return 0, err
-	}
-	// 音乐时长 = (文件大小(byte) - 128(ID3信息)) * 8(to bit) / (码率(kbps b:bit) * 1000)(kilo bit to bit)
-	seconds = (len(mp3Data) - 128) * 8 / (dec.Kbps * 1000)
+	//dec, _, err := minimp3.DecodeFull(mp3Data)
+	//if err != nil {
+	//	return 0, err
+	//}
+	//if dec.Kbps <= 0 {
+	//	return 0, err
+	//}
+	//// 音乐时长 = (文件大小(byte) - 128(ID3信息)) * 8(to bit) / (码率(kbps b:bit) * 1000)(kilo bit to bit)
+	//seconds = (len(mp3Data) - 128) * 8 / (dec.Kbps * 1000)
 	return seconds, nil
 }