@@ -90,6 +90,14 @@ func GetSummaryStatisticByDateCount(dates []string) (int64, error) { | |||
return total, err | |||
} | |||
func GetAllSummaryStatisticByTime(beginTime time.Time, endTime time.Time) ([]*SummaryStatistic, error) { | |||
summaryStatistics := make([]*SummaryStatistic, 0) | |||
err := xStatistic.Asc("created_unix").Where("created_unix>=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10)).Find(&summaryStatistics) | |||
return summaryStatistics, err | |||
} | |||
func GetSummaryStatisticByTime(beginTime time.Time, endTime time.Time, page int, pageSize int) ([]*SummaryStatistic, error) { | |||
summaryStatistics := make([]*SummaryStatistic, 0) | |||
err := xStatistic.Asc("created_unix").Limit(pageSize+1, (page-1)*pageSize).Where("created_unix>=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10)).Find(&summaryStatistics) | |||
@@ -97,6 +105,12 @@ func GetSummaryStatisticByTime(beginTime time.Time, endTime time.Time, page int, | |||
return summaryStatistics, err | |||
} | |||
func GetAllSummaryStatisticByDates(dates []string) ([]*SummaryStatistic, error) { | |||
summaryStatistics := make([]*SummaryStatistic, 0) | |||
err := xStatistic.Asc("created_unix").In("date", dates).Find(&summaryStatistics) | |||
return summaryStatistics, err | |||
} | |||
func GetSummaryStatisticByDates(dates []string, page int, pageSize int) ([]*SummaryStatistic, error) { | |||
summaryStatistics := make([]*SummaryStatistic, 0) | |||
err := xStatistic.Asc("created_unix").In("date", dates).Limit(pageSize+1, (page-1)*pageSize).Find(&summaryStatistics) | |||
@@ -90,8 +90,6 @@ type ProjectSummaryData struct { | |||
type ProjectSummaryPeriodData struct { | |||
RecordBeginTime string `json:"recordBeginTime"` | |||
PageSize int `json:"pageSize"` | |||
TotalPage int `json:"totalPage"` | |||
TotalCount int64 `json:"totalCount"` | |||
PageRecords []*ProjectSummaryBaseData `json:"pageRecords"` | |||
} | |||
@@ -152,20 +150,12 @@ func GetProjectsSummaryData(ctx *context.Context) { | |||
queryType := ctx.QueryTrim("type") | |||
page := ctx.QueryInt("page") | |||
if page <= 0 { | |||
page = 1 | |||
} | |||
pageSize := ctx.QueryInt("pagesize") | |||
if pageSize <= 0 { | |||
pageSize = DEFAULT_PAGE_SIZE | |||
} | |||
var count int64 | |||
if queryType == "all" || queryType == "current_year" { | |||
dates := getEndOfMonthDates(beginTime, endTime) | |||
count, _ = models.GetSummaryStatisticByDateCount(dates) | |||
stats, err := models.GetSummaryStatisticByDates(dates, page, pageSize) | |||
stats, err := models.GetAllSummaryStatisticByDates(dates) | |||
if err != nil { | |||
log.Warn("can not get summary data", err) | |||
} else { | |||
@@ -184,7 +174,7 @@ func GetProjectsSummaryData(ctx *context.Context) { | |||
} else { | |||
count, _ = models.GetSummaryStatisticByTimeCount(beginTime, endTime) | |||
stats, err := models.GetSummaryStatisticByTime(beginTime, endTime, page, pageSize) | |||
stats, err := models.GetAllSummaryStatisticByTime(beginTime, endTime) | |||
if err != nil { | |||
log.Warn("can not get summary data", err) | |||
} else { | |||
@@ -203,9 +193,7 @@ func GetProjectsSummaryData(ctx *context.Context) { | |||
} | |||
projectSummaryPeriodData := ProjectSummaryPeriodData{ | |||
TotalCount: count - 1, | |||
TotalPage: getTotalPage(count-1, pageSize), | |||
RecordBeginTime: recordBeginTime.Format(DATE_FORMAT), | |||
PageSize: pageSize, | |||
PageRecords: datas, | |||
} | |||