Browse Source

修改时间本地时间

kobe6258 3 weeks ago
parent
commit
8b13e1c9b8

+ 1 - 1
controllers/data_manage/chart_info.go

@@ -1312,7 +1312,7 @@ func (this *ChartInfoController) PreviewChartInfoDetail() {
 			//v.Source = tmpV.Source
 			// 得到指标更新的最新的年份
 			if req.DateType == utils.DateTypeNYears && v.LatestDate != "" {
-				lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
+				lastDateT, tErr := time.ParseInLocation(utils.FormatDate, v.LatestDate,time.Local)
 				if tErr != nil {
 					br.Msg = "获取失败"
 					br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()

+ 10 - 10
services/data/chart_info.go

@@ -959,7 +959,7 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
 	//根据数据确定最早的年份,和最近年份
 	//根据横轴的日期,汇总所有的年份
 	startDate := dataList[0].DataTime
-	startDateT, tmpErr := time.Parse(utils.FormatDate, startDate)
+	startDateT, tmpErr := time.ParseInLocation(utils.FormatDate, startDate,time.Local)
 	if tmpErr != nil {
 		err = tmpErr
 		return
@@ -967,7 +967,7 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
 	startYear := startDateT.Year()
 	//获取数据的最新日期
 	lastDate := dataList[length-1].DataTime
-	lastDateT, tmpErr := time.Parse(utils.FormatDate, lastDate)
+	lastDateT, tmpErr := time.ParseInLocation(utils.FormatDate, lastDate,time.Local)
 	if tmpErr != nil {
 		err = tmpErr
 		return
@@ -993,13 +993,13 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
 		name := fmt.Sprintf("%s_%s", startStr, endStr)
 		showName := fmt.Sprintf("%d_%d", currentStartYear, currentEndYear)
 
-		startT, tEr := time.Parse(utils.FormatDate, startStr)
+		startT, tEr := time.ParseInLocation(utils.FormatDate, startStr,time.Local)
 		if tEr != nil {
 			err = tEr
 			return
 		}
 
-		endT, tEr := time.Parse(utils.FormatDate, endStr)
+		endT, tEr := time.ParseInLocation(utils.FormatDate, endStr,time.Local)
 		if tEr != nil {
 			err = tEr
 			return
@@ -1045,7 +1045,7 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
 	}
 
 	for _, v := range dataList {
-		dataTimeT, _ := time.Parse(utils.FormatDate, v.DataTime)
+		dataTimeT, _ := time.ParseInLocation(utils.FormatDate, v.DataTime,time.Local)
 		year := dataTimeT.Year()
 		newItemDate := dataTimeT.AddDate(nowYear-year, 0, 0)
 		for k, dateItem := range dataMap {
@@ -1060,7 +1060,7 @@ func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latest
 				if jumpYear == 1 {
 					//计算前一年最大的日期, 只补齐数据到去年
 					beforeYearMaxDate := fmt.Sprintf("%d-12-31", dateItem.StartDate.Year())
-					beforeYearMaxDateT, _ := time.Parse(utils.FormatDate, beforeYearMaxDate)
+					beforeYearMaxDateT, _ := time.ParseInLocation(utils.FormatDate, beforeYearMaxDate,time.Local)
 					if dataTimeT.Before(beforeYearMaxDateT) || dataTimeT == beforeYearMaxDateT {
 						newItemDate = dataTimeT.AddDate(nowYear-year-1, 0, 0)
 					} else {
@@ -1168,7 +1168,7 @@ func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, late
 	//获取数据的最新日期
 	lastDate := result.List[length-1].Items[itemLength-1].DataTime
 	maxY := result.List[length-1].Year
-	lastDateT, tmpErr := time.Parse(utils.FormatDate, lastDate)
+	lastDateT, tmpErr := time.ParseInLocation(utils.FormatDate, lastDate,time.Local)
 	if tmpErr != nil {
 		err = tmpErr
 		return
@@ -1195,13 +1195,13 @@ func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, late
 		endStr := fmt.Sprintf("%d-%s", currentEndYear, xEndDate)
 		showName := fmt.Sprintf("%d_%d", currentStartYear, currentEndYear)
 
-		startT, tEr := time.Parse(utils.FormatDate, startStr)
+		startT, tEr := time.ParseInLocation(utils.FormatDate, startStr,time.Local)
 		if tEr != nil {
 			err = tEr
 			return
 		}
 
-		endT, tEr := time.Parse(utils.FormatDate, endStr)
+		endT, tEr := time.ParseInLocation(utils.FormatDate, endStr,time.Local)
 		if tEr != nil {
 			err = tEr
 			return
@@ -1294,7 +1294,7 @@ func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, late
 				DataTimestamp: item.DataTimestamp,
 				Value:         item.Value,
 			}
-			dataTimeT, _ := time.Parse(utils.FormatDate, item.DataTime)
+			dataTimeT, _ := time.ParseInLocation(utils.FormatDate, item.DataTime,time.Local)
 			// year := dataTimeT.Year()
 			// newItemDate := dataTimeT.AddDate(nowYear-year, 0, 0)
 			// timestamp := newItemDate.UnixNano() / 1e6

+ 7 - 7
services/data/chart_info_excel_balance.go

@@ -132,7 +132,7 @@ func addBalanceExcelChart(req request.AddBalanceTableChartReq, sysUserId int, sy
 	req.ChartName = strings.Trim(req.ChartName, " ")
 	if req.ChartName == "" {
 		errMsg = "请填写图表名称!"
-		err = fmt.Errorf(errMsg) 
+		err = fmt.Errorf(errMsg)
 		isSendEmail = false
 		return
 	}
@@ -850,7 +850,7 @@ func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDa
 		} else {
 			if v.EdbInfoType == 0 && v.LeadUnit != "" && v.LeadValue > 0 { //领先指标
 				var startTimeRealTemp time.Time
-				startDateParse, _ := time.Parse(utils.FormatDate, startDate)
+				startDateParse, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
 				switch v.LeadUnit {
 				case "天":
 					startTimeRealTemp = startDateParse.AddDate(0, 0, -v.LeadValue)
@@ -892,7 +892,7 @@ func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDa
 		//fmt.Println("line 1011 chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
 		calendarPreYear := 0
 		if calendar == "农历" {
-			newStartDateReal, e := time.Parse(utils.FormatDate, startDateReal)
+			newStartDateReal, e := time.ParseInLocation(utils.FormatDate, startDateReal, time.Local)
 			if e != nil {
 				err = fmt.Errorf("时间解析 time.Parse(%s, %s) error: %v", utils.FormatDate, startDateReal, e)
 				return
@@ -950,7 +950,7 @@ func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDa
 		}
 
 		if chartType == 2 && item.IsAxis == 1 {
-			latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
+			latestDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
 			if tmpErr != nil {
 				//item.DataList = dataList
 				item.IsNullData = true
@@ -1034,7 +1034,7 @@ func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDa
 			// nowYear := time.Now().Year()
 			newDataList := make([]*data_manage.EdbDataList, 0)
 			for _, v := range dataList {
-				dataTime, e := time.Parse(utils.FormatDate, v.DataTime)
+				dataTime, e := time.ParseInLocation(utils.FormatDate, v.DataTime,time.Local)
 				if e != nil {
 					err = errors.New("季节性图处理右轴指标数据转换日期失败,Err:" + e.Error())
 					return
@@ -1043,8 +1043,8 @@ func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDa
 				// year := dataTimeT.Year()
 				// newItemDate := dataTimeT.AddDate(nowYear-year, 0, 0)
 				// v.DataTimestamp = newItemDate.UnixNano() / 1e6
-				seasonXStartDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXStartDateWithYear)
-				seasonXEndDateWithYearT, _ := time.Parse(utils.FormatDate, seasonXEndDateWithYear)
+				seasonXStartDateWithYearT, _ := time.ParseInLocation(utils.FormatDate, seasonXStartDateWithYear,time.Local)
+				seasonXEndDateWithYearT, _ := time.ParseInLocation(utils.FormatDate, seasonXEndDateWithYear,time.Local)
 				if dataTime.Equal(seasonXStartDateWithYearT) || (dataTime.After(seasonXStartDateWithYearT) && dataTime.Before(seasonXEndDateWithYearT)) || dataTime.Equal(seasonXEndDateWithYearT) {
 					newDataList = append(newDataList, v)
 				}

+ 1 - 1
utils/common.go

@@ -1812,7 +1812,7 @@ func GetDateByDateTypeV2(dateType int, tmpStartDate, tmpEndDate string, startYea
 			startDate = startDate + "-01"
 		}
 		if strings.Count(endDate, "-") == 1 {
-			endTime, err := time.Parse(FormatYearMonthDate, endDate)
+			endTime, err := time.ParseInLocation(FormatYearMonthDate, endDate,time.Local)
 			if err != nil {
 				return
 			}