Browse Source

Merge branch 'debug' of http://8.136.199.33:3000/eta_server/eta_chart_lib into bzq/mini_conflict

zqbao 9 months ago
parent
commit
3b61fdacda

+ 6 - 1
controllers/chart.go

@@ -132,7 +132,6 @@ func (this *ChartController) ChartInfoDetail() {
 	if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
 		resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
 	}
-
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -482,6 +481,12 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (
 	chartInfo.ChartSource = strings.Join(sourceNameList, ",")
 	chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
 
+	// 单位
+	if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
+		chartInfo.Unit = yDataList[0].Unit
+		chartInfo.UnitEn = yDataList[0].UnitEn
+	}
+
 	resp.ChartInfo = chartInfo
 	resp.EdbInfoList = edbList
 	resp.XEdbIdValue = xEdbIdValue

+ 42 - 42
controllers/excel_info.go

@@ -184,48 +184,6 @@ func (this *ExcelInfoController) GetTableDetail() {
 	br.Data = resp
 }
 
-func refreshBalanceTable(excelDetail *excel3.ExcelInfo, lang string) (err error) {
-
-	edbInfoIds := make([]int, 0)
-	edbInfoIdExist := make(map[int]bool)
-	var result request.MixedTableReq
-	err = json.Unmarshal([]byte(excelDetail.Content), &result)
-	if err != nil {
-		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
-		return
-	}
-	newData, tmpErr, _ := excel2.GetMixedTableCellData(result, lang)
-	if tmpErr != nil {
-		err = tmpErr
-		return
-	}
-	if len(newData) > 0 {
-		for _, t := range newData {
-			for _, v := range t {
-				if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
-					edbInfoIdExist[v.EdbInfoId] = true
-					edbInfoIds = append(edbInfoIds, v.EdbInfoId)
-				}
-			}
-		}
-	}
-
-	// 清除缓存
-	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
-	if utils.Re == nil {
-		_ = utils.Rc.Delete(key)
-	}
-
-	if len(edbInfoIds) > 0 {
-		err, _ = data.EdbInfoRefreshAllFromBase(edbInfoIds, false)
-		if err != nil {
-			err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
-			return
-		}
-	}
-	return
-}
-
 // Refresh
 // @Title 刷新
 // @Description 刷新接口
@@ -341,3 +299,45 @@ func (this *ExcelInfoController) Refresh() {
 	br.Success = true
 	br.Msg = "刷新成功"
 }
+
+func refreshBalanceTable(excelDetail *excel3.ExcelInfo, lang string) (err error) {
+
+	edbInfoIds := make([]int, 0)
+	edbInfoIdExist := make(map[int]bool)
+	var result request.MixedTableReq
+	err = json.Unmarshal([]byte(excelDetail.Content), &result)
+	if err != nil {
+		err = fmt.Errorf("表格json转结构体失败,Err:" + err.Error())
+		return
+	}
+	newData, tmpErr, _ := excel2.GetMixedTableCellData(result, lang)
+	if tmpErr != nil {
+		err = tmpErr
+		return
+	}
+	if len(newData) > 0 {
+		for _, t := range newData {
+			for _, v := range t {
+				if v.EdbInfoId > 0 && !edbInfoIdExist[v.EdbInfoId] {
+					edbInfoIdExist[v.EdbInfoId] = true
+					edbInfoIds = append(edbInfoIds, v.EdbInfoId)
+				}
+			}
+		}
+	}
+
+	// 清除缓存
+	key := utils.HZ_CHART_LIB_EXCEL_TABLE_DETAIL + ":" + excelDetail.UniqueCode
+	if utils.Re == nil {
+		_ = utils.Rc.Delete(key)
+	}
+
+	if len(edbInfoIds) > 0 {
+		err, _ = data.EdbInfoRefreshAllFromBase(edbInfoIds, false)
+		if err != nil {
+			err = fmt.Errorf("刷新混合表格数据失败, Err: " + err.Error())
+			return
+		}
+	}
+	return
+}

+ 4 - 2
models/chart.go

@@ -45,8 +45,8 @@ type ChartInfo struct {
 	Right2Max         string    `description:"图表右侧2最大值"`
 	MinMaxSave        int       `description:"是否手动保存过上下限:0-否;1-是"`
 	Source            int       `description:"1:ETA图库;2:商品价格曲线"`
-	Unit              string    `description:"中文单位名称"`
-	UnitEn            string    `description:"英文单位名称"`
+	UnitEn            string    `description:"英文图表单位"`
+	Unit              string    `description:"图表单位"`
 	ExtraConfig       string    `description:"图表额外配置,json数据" json:"-"`
 	ChartSource       string    `description:"图表来源str"`
 	ChartSourceEn     string    `description:"图表来源(英文)"`
@@ -305,6 +305,8 @@ type YData struct {
 	M              []int           `description:"对应开始日期的间隔值" json:"-"`
 	NameList       []string        `description:"每个值对应的名称"`
 	EnNameList     []string        `description:"每个值对应的英文名称"`
+	Unit           string          `description:"中文单位名称"`
+	UnitEn         string          `description:"英文单位名称"`
 }
 
 // RollingCorrelationChartDataResp 滚动相关性图

+ 2 - 0
models/data_manage/chart_info.go

@@ -62,6 +62,8 @@ type BarChartInfoReq struct {
 	EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
 	DateList      []BarChartInfoDateReq    `description:"日期配置"`
 	Sort          BarChartInfoSortReq      `description:"排序"`
+	Unit          string                   `description:"中文单位名称"`
+	UnitEn        string                   `description:"英文单位名称"`
 }
 
 // BarChartInfoEdbItemReq 柱方图预览请求数据(指标相关)

+ 6 - 0
services/data/chart_info.go

@@ -138,6 +138,12 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
 				}
 			}
 		}
+
+		for k := range yDataList {
+			yDataList[k].Unit = barChartConf.Unit
+			yDataList[k].UnitEn = barChartConf.UnitEn
+		}
+
 	case 10: // 截面散点图
 		sectionScatterConf := extraConfig.(data_manage.SectionScatterReq)
 		xEdbIdValue, dataResp, err = GetSectionScatterChartData(mappingList, edbDataListMap, sectionScatterConf)

+ 2 - 0
services/data/correlation/chart_info.go

@@ -275,6 +275,8 @@ func GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB *models.ChartEdbInfo
 				return
 			}
 			changeDataList = tmpNewChangeDataList
+
+			// 那么A指标不管是高频,或者同频,那么就直接赋值A指标吧
 			baseDataList = aDataList
 			for _, v := range baseDataList {
 				baseDataMap[v.DataTime] = v.Value

+ 65 - 12
services/data/future_good/chart_info.go

@@ -321,6 +321,29 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
 // BarChartData 柱方图的数据处理
 func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingList []*future_good.FutureGoodEdbInfo, edbDataListMap map[int][]*models.EdbDataList, barChartInfoDateList []data_manage.BarChartInfoDateReq, regionType, latestDate string) (edbIdList []int, yDataList []models.YData, err error) {
 	// 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
+	// 现货指标数据map
+	baseEdbDataMap := make(map[string]float64)
+	for edbInfoId, edbDataList := range edbDataListMap {
+		if edbInfoId == edbInfoMapping.EdbInfoId {
+			for _, edbData := range edbDataList {
+				baseEdbDataMap[edbData.DataTime] = edbData.Value
+			}
+		}
+	}
+
+	// 期货指标数据map
+	futureGoodEdbDataMap := make(map[int]map[string]float64)
+	for edbInfoId, edbDataList := range edbDataListMap {
+		if edbInfoId == edbInfoMapping.EdbInfoId {
+			continue
+		}
+		edbDateData := make(map[string]float64)
+		for _, edbData := range edbDataList {
+			edbDateData[edbData.DataTime] = edbData.Value
+		}
+		futureGoodEdbDataMap[edbInfoId] = edbDateData
+	}
+
 	edbDataMap := make(map[int]map[string]float64)
 	for edbInfoId, edbDataList := range edbDataListMap {
 		edbDateData := make(map[string]float64)
@@ -374,7 +397,7 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 		xEdbInfoIdList := make([]int, 0)    // 当前数据的指标id列表
 
 		// 现货指标
-		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[edbInfoMapping.EdbInfoId], edbDataMap[edbInfoMapping.EdbInfoId])
+		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[edbInfoMapping.EdbInfoId], baseEdbDataMap, futureGoodEdbDataMap)
 		if tmpErr != nil {
 			err = tmpErr
 			return
@@ -387,8 +410,13 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 			noDataIdList = append(noDataIdList, edbInfoMapping.EdbInfoId)
 			noDataIdMap[edbInfoMapping.EdbInfoId] = edbInfoMapping.EdbInfoId
 		}
-		currMonth := findDateTime.Month() // 当前月份
-		currYear := findDateTime.Year()   // 当前年份
+		//currMonth := findDateTime.Month() // 当前月份
+		//currYear := findDateTime.Year()   // 当前年份
+
+		// 用实际日期的月份作为基准,往前推12个月(2024-5-13 16:26:43修改)
+		currMonth := realDateTime.Month() // 当前月份
+		currYear := realDateTime.Year()   // 当前年份
+
 		xEdbInfoIdList = append(xEdbInfoIdList, edbInfoMapping.EdbInfoId)
 		mList := make([]int, 0) // 间隔月份
 		indexList := make([]int, 0)
@@ -427,7 +455,7 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 			//}
 			//tmpRealDateTime := findDateTime	// 按照配置找到的日期
 			tmpRealDateTime := realDateTime // 实际现货的日期
-			tmpFindDataValue, tmpIsFind := edbDataMap[futureGoodMapping.FutureGoodEdbInfoId][tmpRealDateTime.Format(utils.FormatDate)]
+			tmpFindDataValue, tmpIsFind := futureGoodEdbDataMap[futureGoodMapping.FutureGoodEdbInfoId][tmpRealDateTime.Format(utils.FormatDate)]
 			yDataMap[futureGoodMapping.FutureGoodEdbInfoId] = tmpFindDataValue
 
 			findDataList = append(findDataList, tmpFindDataValue)
@@ -509,7 +537,7 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 }
 
 // GetNeedDateData 获取合约内需要的日期数据
-func GetNeedDateData(needDateTime time.Time, dataList []*models.EdbDataList, edbDataMap map[string]float64) (findDateTime time.Time, findDataValue float64, isFind bool, err error) {
+func GetNeedDateData(needDateTime time.Time, dataList []*models.EdbDataList, edbDataMap map[string]float64, allEdbDataMap map[int]map[string]float64) (findDateTime time.Time, findDataValue float64, isFind bool, err error) {
 	//dataList := edbDataListMap[edbInfoId] //指标的所有数据值
 	if len(dataList) <= 0 {
 		// 没有数据的指标id
@@ -522,18 +550,43 @@ func GetNeedDateData(needDateTime time.Time, dataList []*models.EdbDataList, edb
 		return
 	}
 
+	// 该日期存在数据的期货指标的最小数量,目前是现货和期货各1个,总共2个
+	maxCount := 1
+
 	for tmpDateTime := needDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
 		tmpDate := tmpDateTime.Format(utils.FormatDate)
-		if tmpValue, ok := edbDataMap[tmpDate]; ok { //如果能找到数据,那么就返回
-			// 数据为0,也直接返回,做无值处理
-			if tmpValue == 0 {
-				return
+		tmpValue, ok := edbDataMap[tmpDate]
+		if !ok {
+			continue
+		}
+
+		// 该日期存在数据的指标数量
+		count := 0
+
+		for _, currEdbDataMap := range allEdbDataMap {
+			_, tmpIsFind := currEdbDataMap[tmpDate]
+			if tmpIsFind {
+				count++
+				if count >= maxCount {
+					continue
+				}
 			}
-			findDateTime, _ = time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
-			findDataValue = tmpValue
-			isFind = true
+		}
+
+		// 该日期存在数据的期货指标数量小于2个,那么要继续往前找
+		if count < maxCount {
+			continue
+		}
+
+		//如果能找到数据,那么就返回
+		// 数据为0,也直接返回,做无值处理
+		if tmpValue == 0 {
 			return
 		}
+		findDateTime, _ = time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
+		findDataValue = tmpValue
+		isFind = true
+		return
 	}
 
 	return

+ 30 - 34
services/excel/lucky_sheet.go

@@ -460,23 +460,21 @@ func handleTableDataList(tableDataList [][]LuckySheetDataValue, luckySheetDataCo
 		flag = false
 		//尾部
 		deleteBottomRowIndexList := make([]int, 0)
-		if len(tableDataList) > 1 {
-			for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
-				isDelete := true
-				for _, v := range tableDataList[rowIndex] {
-					if v.Monitor != `` {
-						isDelete = false
-						flag = true
-						break
-					}
-				}
-				if flag {
+		for rowIndex := lenRow - 1; rowIndex > removeTopRow; rowIndex-- {
+			isDelete := true
+			for _, v := range tableDataList[rowIndex] {
+				if v.Monitor != `` {
+					isDelete = false
+					flag = true
 					break
 				}
-				if isDelete {
-					deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
-					removeBottomRow++
-				}
+			}
+			if flag {
+				break
+			}
+			if isDelete {
+				deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
+				removeBottomRow++
 			}
 		}
 
@@ -528,28 +526,26 @@ func handleTableDataList(tableDataList [][]LuckySheetDataValue, luckySheetDataCo
 		flag = false
 		//右边
 		deleteTailColumnIndexList := make([]int, 0)
-		// 数据要大于1列才会处理
-		if lenColumn > 1 {
-			for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
-				isDelete := true
-				for _, v := range tableDataList {
-					//如果一列都没有,说明是上面几行是空行,没有数据
-					if len(v) <= 0 {
-						continue
-					}
-					if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
-						isDelete = false
-						flag = true
-						break
-					}
+		// 数据第1列不处理
+		for columnIndex := lenColumn - 1; columnIndex > removeLeftColumn; columnIndex-- {
+			isDelete := true
+			for _, v := range tableDataList {
+				//如果一列都没有,说明是上面几行是空行,没有数据
+				if len(v) <= 0 {
+					continue
 				}
-				if flag {
+				if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
+					isDelete = false
+					flag = true
 					break
 				}
-				if isDelete {
-					deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
-					removeRightColumn++
-				}
+			}
+			if flag {
+				break
+			}
+			if isDelete {
+				deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
+				removeRightColumn++
 			}
 		}