|
@@ -43,9 +43,11 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
// 指标信息map
|
|
|
edbInfoMap := make(map[int]*data_manage.EdbInfo)
|
|
|
// 日度指标数据map
|
|
|
- edbDataListMap := make(map[int]map[string]float64)
|
|
|
+ edbDayDataListMap := make(map[int]map[string]float64)
|
|
|
// 月度指标数据map
|
|
|
edbMonthDataListMap := make(map[int]map[string]float64)
|
|
|
+ // 日度指标数据map
|
|
|
+ edbDataListMap := make(map[int][]*data_manage.EdbDataList)
|
|
|
for _, edbInfo := range edbInfoList {
|
|
|
edbInfoMap[edbInfo.EdbInfoId] = edbInfo
|
|
|
|
|
@@ -61,19 +63,23 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
|
|
|
dateValMap := make(map[string]float64)
|
|
|
monthValMap := make(map[string]float64)
|
|
|
- for _, data := range dataList {
|
|
|
+ for _, tmpData := range dataList {
|
|
|
// 日度数据
|
|
|
- dateValMap[data.DataTime] = data.Value
|
|
|
+ dateValMap[tmpData.DataTime] = tmpData.Value
|
|
|
// 月度数据(取该月份的第一个数据)
|
|
|
- yearMonth := strings.Join(strings.Split(data.DataTime, "-")[0:2], "-")
|
|
|
+ yearMonth := strings.Join(strings.Split(tmpData.DataTime, "-")[0:2], "-")
|
|
|
if _, ok := monthValMap[yearMonth]; !ok {
|
|
|
- monthValMap[yearMonth] = data.Value
|
|
|
+ monthValMap[yearMonth] = tmpData.Value
|
|
|
}
|
|
|
}
|
|
|
- edbDataListMap[edbInfo.EdbInfoId] = dateValMap
|
|
|
+ edbDayDataListMap[edbInfo.EdbInfoId] = dateValMap
|
|
|
edbMonthDataListMap[edbInfo.EdbInfoId] = monthValMap
|
|
|
+ edbDataListMap[edbInfo.EdbInfoId] = dataList
|
|
|
}
|
|
|
|
|
|
+ // 单元格实际绑定的信息map
|
|
|
+ cellDataRelationMap := make(map[string]request.MixedTableCellDataReq, 0)
|
|
|
+
|
|
|
// 处理指定指标的日期
|
|
|
for k, row := range config {
|
|
|
for i, cell := range row {
|
|
@@ -86,10 +92,26 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
}
|
|
|
}
|
|
|
row[i] = cell
|
|
|
+
|
|
|
+ cellDataRelationMap[cell.Uid] = cell
|
|
|
}
|
|
|
config[k] = row
|
|
|
}
|
|
|
|
|
|
+ type BaseCalculate struct {
|
|
|
+ DataList []*data_manage.EdbDataList
|
|
|
+ Frequency string `description:"需要转换的频度"`
|
|
|
+ Formula interface{}
|
|
|
+ Calendar string `description:"公历/农历"`
|
|
|
+ MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
|
|
|
+ MoveFrequency string `description:"移动频度"`
|
|
|
+ FromFrequency string `description:"来源的频度"`
|
|
|
+ Source int `description:"1:累计值转月;2:累计值转季;3:同比值;4:同差值;5:N数值移动平均数计算;6:环比值;7:环差值;8:升频;9:降频;10:时间移位;11:超季节性;12:年化;13:累计值;14:累计值年初至今;15:指数修匀;16:日均值"`
|
|
|
+ }
|
|
|
+
|
|
|
+ // 指标计算的结果map
|
|
|
+ edbSourceDataMap := make(map[string]map[string]float64)
|
|
|
+
|
|
|
for k, row := range config {
|
|
|
for i, cell := range row {
|
|
|
switch cell.DataType {
|
|
@@ -107,7 +129,7 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
}
|
|
|
} else {
|
|
|
// 日度数据
|
|
|
- if dateValMap, ok := edbDataListMap[cell.EdbInfoId]; ok {
|
|
|
+ if dateValMap, ok := edbDayDataListMap[cell.EdbInfoId]; ok {
|
|
|
tmpDateValMap = dateValMap
|
|
|
}
|
|
|
|
|
@@ -116,6 +138,83 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
//cell.ShowValue = fmt.Sprint(val)
|
|
|
cell.ShowValue = utils.FormatTableDataShowValue(val)
|
|
|
}
|
|
|
+ case request.InsertEdbCalculateDataDT: // 指标类型
|
|
|
+ // 日期
|
|
|
+ relationConf, ok := cellRelationConfMap[cell.Uid]
|
|
|
+ if !ok {
|
|
|
+ // 日期关系配置不存在
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if relationConf.RelationDate.Key == `` {
|
|
|
+ // 日期关系配置未绑定
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ relationCell, ok := cellDataRelationMap[relationConf.RelationDate.Key]
|
|
|
+ if relationConf.RelationDate.Key == `` {
|
|
|
+ // 找不到对应日期的单元格
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ var tmpDataMap map[string]float64
|
|
|
+
|
|
|
+ key := utils.MD5(cell.Value)
|
|
|
+ tmpDataMap, ok = edbSourceDataMap[key]
|
|
|
+ if !ok {
|
|
|
+ // 对应的配置值
|
|
|
+ var tmpConfig request.CalculateConf
|
|
|
+ err = json.Unmarshal([]byte(cell.Value), &tmpConfig)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ tmpDataList, ok := edbDataListMap[tmpConfig.EdbInfoId]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ edbInfo, ok := edbInfoMap[tmpConfig.EdbInfoId]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ req2 := &BaseCalculate{
|
|
|
+ DataList: tmpDataList,
|
|
|
+ Frequency: tmpConfig.Frequency,
|
|
|
+ Formula: tmpConfig.Formula,
|
|
|
+ Calendar: tmpConfig.Calendar,
|
|
|
+ MoveType: tmpConfig.MoveType,
|
|
|
+ MoveFrequency: tmpConfig.MoveFrequency,
|
|
|
+ FromFrequency: edbInfo.Frequency,
|
|
|
+ Source: tmpConfig.Source,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用指标库去更新
|
|
|
+ reqJson, tmpErr := json.Marshal(req2)
|
|
|
+ if tmpErr != nil {
|
|
|
+ utils.FileLog.Error(fmt.Sprintf("计算失败1,配置信息;%s;错误原因:%s", cell.Value, tmpErr.Error()))
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ respItem, tmpErr := data.BaseCalculate(string(reqJson))
|
|
|
+ if tmpErr != nil {
|
|
|
+ utils.FileLog.Error(fmt.Sprintf("计算失败2,配置信息;%s;错误原因:%s", cell.Value, tmpErr.Error()))
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if respItem.Ret != 200 {
|
|
|
+ utils.FileLog.Error(fmt.Sprintf("计算失败3,配置信息;%s;原因:%s;错误原因:%s", cell.Value, respItem.Msg, respItem.ErrMsg))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ tmpDataMap = respItem.Data.DataMap
|
|
|
+ // 计算结果存一份,万一存在重复的计算方式,那么省的重新计算一下
|
|
|
+ edbSourceDataMap[key] = tmpDataMap
|
|
|
+ }
|
|
|
+
|
|
|
+ val := tmpDataMap[relationCell.DataTime]
|
|
|
+
|
|
|
+ cell.ShowValue = utils.FormatTableDataShowValue(val)
|
|
|
+ //
|
|
|
}
|
|
|
|
|
|
row[i] = cell
|