Browse Source

wip:离线

wangshan 6 months ago
parent
commit
5c65a7ad19
2 changed files with 12 additions and 9 deletions
  1. 4 4
      marketanalysis/common.go
  2. 8 5
      marketanalysis/marketanalysis.go

+ 4 - 4
marketanalysis/common.go

@@ -665,10 +665,10 @@ func Rest(res esV7.Aggregations, thisRow *marketTime) {
 	}
 	}
 }
 }
 
 
-func GetMonthData(sTime, eTime time.Time) (bool, string) {
+func GetMonthData(isOffline bool, sTime, eTime time.Time) (bool, string) {
 	var _b bool
 	var _b bool
 	//整月多取一个月进行环比
 	//整月多取一个月进行环比
-	if SEMonth(sTime, eTime) {
+	if !isOffline && SEMonth(sTime, eTime) {
 		_b = true
 		_b = true
 		sTime = sTime.AddDate(0, -1, 0)
 		sTime = sTime.AddDate(0, -1, 0)
 	}
 	}
@@ -711,10 +711,10 @@ func getMonthRange(t time.Time, isStart bool) time.Time {
 	return time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location())
 	return time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location())
 }
 }
 
 
-func GetYearData(sTime, eTime time.Time) (bool, string) {
+func GetYearData(isOffline bool, sTime, eTime time.Time) (bool, string) {
 	var _b bool
 	var _b bool
 	//整月多取一个月进行环比
 	//整月多取一个月进行环比
-	if sTime.Month() == 1 && sTime.Day() == 1 && eTime.Month() == 12 && eTime.Day() == 31 {
+	if !isOffline && sTime.Month() == 1 && sTime.Day() == 1 && eTime.Month() == 12 && eTime.Day() == 31 {
 		_b = true
 		_b = true
 		sTime = sTime.AddDate(-1, 0, 0)
 		sTime = sTime.AddDate(-1, 0, 0)
 	}
 	}

+ 8 - 5
marketanalysis/marketanalysis.go

@@ -1023,6 +1023,7 @@ func (a *AnalysisEntity) MarketTime() (map[string]interface{}, error) {
 		sql                   []string
 		sql                   []string
 		monthB, yearB         bool
 		monthB, yearB         bool
 		MonthRange, YearRange string
 		MonthRange, YearRange string
+		isOffline             = a.Offline == 1
 	)
 	)
 	sql = append(sql, fmt.Sprintf(aggsMarketAnalysis, "thismarket", fmt.Sprintf(`{"key":"%s","from":%d,"to":%d}`, "market", a.FormatParam.STime, a.FormatParam.ETime)))
 	sql = append(sql, fmt.Sprintf(aggsMarketAnalysis, "thismarket", fmt.Sprintf(`{"key":"%s","from":%d,"to":%d}`, "market", a.FormatParam.STime, a.FormatParam.ETime)))
 	n_stime := a.FormatParam.STime
 	n_stime := a.FormatParam.STime
@@ -1036,10 +1037,10 @@ func (a *AnalysisEntity) MarketTime() (map[string]interface{}, error) {
 		sql = append(sql, fmt.Sprintf(aggsMarketAnalysis, "oldmarket", fmt.Sprintf(`{"key":"%s","from":%d,"to":%d}`, "market", n_stime, a.FormatParam.STime)))
 		sql = append(sql, fmt.Sprintf(aggsMarketAnalysis, "oldmarket", fmt.Sprintf(`{"key":"%s","from":%d,"to":%d}`, "market", n_stime, a.FormatParam.STime)))
 	}
 	}
 
 
-	if time.Unix(a.FormatParam.STime, 0).AddDate(0, 1, 0).Unix() < time.Unix(a.FormatParam.ETime, 0).Unix() {
+	if isOffline || time.Unix(a.FormatParam.STime, 0).AddDate(0, 1, 0).Unix() < time.Unix(a.FormatParam.ETime, 0).Unix() {
 		var mon_time, year_time int64
 		var mon_time, year_time int64
 		stime, etime := time.Unix(a.FormatParam.STime, 0), time.Unix(a.FormatParam.ETime, 0)
 		stime, etime := time.Unix(a.FormatParam.STime, 0), time.Unix(a.FormatParam.ETime, 0)
-		monthB, MonthRange = GetMonthData(stime, etime)
+		monthB, MonthRange = GetMonthData(isOffline, stime, etime)
 		sql = append(sql, fmt.Sprintf(projectTimeDistribution, "monthtime", MonthRange))
 		sql = append(sql, fmt.Sprintf(projectTimeDistribution, "monthtime", MonthRange))
 		if monthB {
 		if monthB {
 			mon_time = stime.AddDate(0, -1, 0).Unix()
 			mon_time = stime.AddDate(0, -1, 0).Unix()
@@ -1047,7 +1048,7 @@ func (a *AnalysisEntity) MarketTime() (map[string]interface{}, error) {
 			mon_time = a.FormatParam.STime
 			mon_time = a.FormatParam.STime
 		}
 		}
 		//年度数据
 		//年度数据
-		yearB, YearRange = GetYearData(stime, etime)
+		yearB, YearRange = GetYearData(isOffline, stime, etime)
 		sql = append(sql, fmt.Sprintf(projectTimeDistribution, "yeartime", YearRange))
 		sql = append(sql, fmt.Sprintf(projectTimeDistribution, "yeartime", YearRange))
 		if yearB {
 		if yearB {
 			year_time = stime.AddDate(-1, 0, 0).Unix()
 			year_time = stime.AddDate(-1, 0, 0).Unix()
@@ -1062,8 +1063,10 @@ func (a *AnalysisEntity) MarketTime() (map[string]interface{}, error) {
 			n_stime = year_time
 			n_stime = year_time
 		}
 		}
 	}
 	}
-
-	n_mae.FormatParam.STime = n_stime
+	//非离线
+	if !isOffline {
+		n_mae.FormatParam.STime = n_stime
+	}
 	finalSql := fmt.Sprintf(n_mae.GetCommonQuerySqlWithAggs(), strings.Join(sql, ","))
 	finalSql := fmt.Sprintf(n_mae.GetCommonQuerySqlWithAggs(), strings.Join(sql, ","))
 	log.Printf("final MarketScaleRefineQuery sql: %s", finalSql)
 	log.Printf("final MarketScaleRefineQuery sql: %s", finalSql)
 	rMap := make(map[string]interface{})
 	rMap := make(map[string]interface{})