Browse Source

Merge pull request '用户运营统计分页功能调试问题修改。' (#868) from zouap_static into V20211115

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/868
Reviewed-by: lewis <747342561@qq.com>
pull/873/head
lewis 3 years ago
parent
commit
ef23db7115
2 changed files with 24 additions and 4 deletions
  1. +22
    -4
      models/user_business_analysis.go
  2. +2
    -0
      routers/repo/user_data_analysis.go

+ 22
- 4
models/user_business_analysis.go View File

@@ -142,6 +142,24 @@ func QueryUserStaticData(startTime int64, endTime int64) []*UserBusinessAnalysis
return userBusinessAnalysisReturnList return userBusinessAnalysisReturnList
} }


func getLastCountDate() int64 {
statictisSess := xStatistic.NewSession()
defer statictisSess.Close()
statictisSess.Limit(1, 0)
userBusinessAnalysisList := make([]*UserBusinessAnalysis, 0)
if err := statictisSess.Table("user_business_analysis").OrderBy("count_date desc").Limit(1, 0).
Find(&userBusinessAnalysisList); err == nil {
for _, userRecord := range userBusinessAnalysisList {
return userRecord.CountDate - 10000
}
} else {
log.Info("query error." + err.Error())
}
currentTimeNow := time.Now()
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
return pageStartTime.Unix()
}

func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBusinessAnalysis, int64) { func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBusinessAnalysis, int64) {


log.Info("query startTime =" + fmt.Sprint(opts.StartTime) + " endTime=" + fmt.Sprint(opts.EndTime)) log.Info("query startTime =" + fmt.Sprint(opts.StartTime) + " endTime=" + fmt.Sprint(opts.EndTime))
@@ -149,8 +167,8 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus
defer statictisSess.Close() defer statictisSess.Close()


currentTimeNow := time.Now() currentTimeNow := time.Now()
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location())
pageStartTime := getLastCountDate()
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).Unix()


var cond = builder.NewCond() var cond = builder.NewCond()
if len(opts.UserName) > 0 { if len(opts.UserName) > 0 {
@@ -159,10 +177,10 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus
) )
} }
cond = cond.And( cond = cond.And(
builder.Gte{"count_date": pageStartTime.Unix()},
builder.Gte{"count_date": pageStartTime},
) )
cond = cond.And( cond = cond.And(
builder.Lte{"count_date": pageEndTime.Unix()},
builder.Lte{"count_date": pageEndTime},
) )


count, err := statictisSess.Where(cond).Count(new(UserBusinessAnalysis)) count, err := statictisSess.Where(cond).Count(new(UserBusinessAnalysis))


+ 2
- 0
routers/repo/user_data_analysis.go View File

@@ -68,8 +68,10 @@ func QueryUserStaticDataPage(ctx *context.Context) {
if IsReturnFile { if IsReturnFile {
//writer exec file. //writer exec file.
xlsx := excelize.NewFile() xlsx := excelize.NewFile()
xlsx.DeleteSheet("Sheet1")
sheetName := ctx.Tr("user.static.sheetname") sheetName := ctx.Tr("user.static.sheetname")
index := xlsx.NewSheet(sheetName) index := xlsx.NewSheet(sheetName)

dataHeader := map[string]string{ dataHeader := map[string]string{
"A1": ctx.Tr("user.static.id"), "A1": ctx.Tr("user.static.id"),
"B1": ctx.Tr("user.static.name"), "B1": ctx.Tr("user.static.name"),


Loading…
Cancel
Save