Browse Source

单元格日期处理

xyxie 1 năm trước cách đây
mục cha
commit
cf8a07a290

+ 8 - 4
controllers/data_manage/edb_info.go

@@ -4540,6 +4540,7 @@ func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
 		br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
 		return
 	}
+
 	if currDate == `` {
 		currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
 		if err != nil {
@@ -4550,9 +4551,12 @@ func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
 	} else {
 		if strings.Count(currDate, "-") == 1 {
 			currDate = currDate + "-01"
-			//dateType = "month"
-		} else if strings.Count(currDate, "-") == 0 {
-			currDate = currDate + "-01-01"
+			// 查找这个月早的时间作为起始时间
+			for _, v := range dataList {
+				if v.DataTime >= currDate {
+					currDate = v.DataTime
+				}
+			}
 		}
 	}
 	currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
@@ -4569,7 +4573,7 @@ func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
 		br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
 		return
 	}
-	// todo 如果list 是空值,是否默认返回最新的记录
+	// 这个日期不存在的话直接返回空数组
 	resp := data_manage.BeforeAndAfterDateDataResp{
 		List: list,
 		Date: currDate,

+ 15 - 6
controllers/data_manage/excel/mixed_table.go

@@ -204,7 +204,7 @@ func (c *ExcelInfoController) CalculateData() {
 		num = lenDate
 	}
 
-	dataListResp := make([]*data_manage.EdbDataList, 0)
+	//dataListResp := make([]*data_manage.EdbDataList, 0)
 
 	var newDate string
 	if req.DataTime == `` { //选择前移几期数
@@ -214,6 +214,15 @@ func (c *ExcelInfoController) CalculateData() {
 		}
 	} else {
 		newDate = req.DataTime //选择表格中的日期
+		if strings.Count(newDate, "-") == 1 {
+			newDate = newDate + "-01"
+			// 查找这个月早的时间作为起始时间
+			for _, v := range respItem.Data.DateList {
+				if v >= newDate {
+					newDate = v
+				}
+			}
+		}
 	}
 	// 开始做日期变换
 	newDate, err = excel2.HandleMixTableDateChange(newDate, requestBody)
@@ -232,16 +241,16 @@ func (c *ExcelInfoController) CalculateData() {
 			if date == newDate {
 				finalVal = val
 			}
-			dataListResp = append(dataListResp, &data_manage.EdbDataList{
+			/*dataListResp = append(dataListResp, &data_manage.EdbDataList{
 				Value:    val,
 				DataTime: date,
-			})
+			})*/
 		}
 	} else {
 		// todo 如果选择了表格中的日期应该如何处理
 		if val, ok := respItem.Data.DataMap[newDate]; ok {
 			finalVal = val
-			for i, tmpDate := range respItem.Data.DateList {
+			/*for i, tmpDate := range respItem.Data.DateList {
 				if tmpDate == newDate {
 					if i+3 <= lenDate {
 						t1Date := respItem.Data.DateList[i+2]
@@ -291,11 +300,11 @@ func (c *ExcelInfoController) CalculateData() {
 						}
 					}
 				}
-			}
+			}*/
 		}
 	}
 	resp := data_manage.BeforeAndAfterDateDataResp{
-		List:      dataListResp,
+		//List:      dataListResp,
 		Date:      newDate,
 		ShowValue: utils.FormatTableDataShowValue(finalVal),
 	}

+ 1 - 1
services/data/edb_data.go

@@ -368,7 +368,7 @@ func GetEdbBeforeAndAfterDateData(targetDate string, dataList []*data_manage.Edb
 	startIndex := 0
 	endIndex := 0
 	for index, v := range dataList {
-		if v.DataTime >= targetDate {
+		if v.DataTime == targetDate {
 			if index+2 > maxIndex {
 				endIndex = maxIndex
 			} else if index+1 > maxIndex {

+ 29 - 14
services/data/excel/mixed_table.go

@@ -73,7 +73,7 @@ func GetMixedTableCellData(mixedTableReq request.MixedTableReq) (newMixedTableCe
 	// 日度指标数据map
 	edbDayDataListMap := make(map[int]map[string]float64)
 	// 月度指标数据map
-	edbMonthDataListMap := make(map[int]map[string]float64)
+	edbMonthDataListMap := make(map[int]map[string]string)
 	// 日度指标数据map
 	edbDataListMap := make(map[int][]*data_manage.EdbDataList)
 	for _, edbInfo := range edbInfoList {
@@ -90,18 +90,19 @@ func GetMixedTableCellData(mixedTableReq request.MixedTableReq) (newMixedTableCe
 		}
 
 		dateValMap := make(map[string]float64)
-		monthValMap := make(map[string]float64)
+		monthDateMap := make(map[string]string)
 		for _, tmpData := range dataList {
 			// 日度数据
 			dateValMap[tmpData.DataTime] = tmpData.Value
 			// 月度数据(取该月份的第一个数据)
 			yearMonth := strings.Join(strings.Split(tmpData.DataTime, "-")[0:2], "-")
-			if _, ok := monthValMap[yearMonth]; !ok {
-				monthValMap[yearMonth] = tmpData.Value
+			if _, ok := monthDateMap[yearMonth]; !ok {
+				// 存最早的时间
+				monthDateMap[yearMonth] = tmpData.DataTime
 			}
 		}
 		edbDayDataListMap[edbInfo.EdbInfoId] = dateValMap
-		edbMonthDataListMap[edbInfo.EdbInfoId] = monthValMap
+		edbMonthDataListMap[edbInfo.EdbInfoId] = monthDateMap
 		edbDataListMap[edbInfo.EdbInfoId] = dataList
 	}
 
@@ -242,22 +243,36 @@ func GetMixedTableCellData(mixedTableReq request.MixedTableReq) (newMixedTableCe
 					} else {
 						tmpDateList := strings.Split(cell.DataTime, "-")
 						tmpDateValMap := make(map[string]float64)
+						var newDate string
 						if len(tmpDateList) == 2 {
 							//月度数据
-							if dateValMap, ok := edbMonthDataListMap[cell.EdbInfoId]; ok {
-								tmpDateValMap = dateValMap
+							if dateMap, ok1 := edbMonthDataListMap[cell.EdbInfoId]; ok1 {
+								if d, ok2 := dateMap[cell.DataTime]; ok2 {
+									newDate = d
+								}
 							}
 						} else {
 							// 日度数据
-							if dateValMap, ok := edbDayDataListMap[cell.EdbInfoId]; ok {
-								tmpDateValMap = dateValMap
-							}
+							newDate = cell.DataTime
+						}
+						// 日期变换后才能确定最后的时间
+						//做期数前移动和日期变换
+						if !strings.Contains(cell.Value, "{") {
+							cell.Value = ""
+						}
 
+						newDate, err = HandleMixTableDateChange(newDate, cell.Value)
+						if err != nil {
+							return
 						}
-						if val, ok2 := tmpDateValMap[cell.DataTime]; ok2 {
-							//cell.ShowValue = fmt.Sprint(val)
-							cellKeyVal[cell.Uid] = val
-							cell.ShowValue = utils.FormatTableDataShowValue(val)
+
+						if dateValMap, ok3 := edbDayDataListMap[cell.EdbInfoId]; ok3 {
+							tmpDateValMap = dateValMap
+							if val, ok2 := tmpDateValMap[cell.DataTime]; ok2 {
+								//cell.ShowValue = fmt.Sprint(val)
+								cellKeyVal[cell.Uid] = val
+								cell.ShowValue = utils.FormatTableDataShowValue(val)
+							}
 						}
 					}
 				}