diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index cf0ad7e1a..f6f58396b 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -1756,36 +1756,42 @@ func queryCommitAction(start_unix int64, end_unix int64, actionType int64) (map[ var indexTotal int64 indexTotal = 0 for { - sess.Select("id,user_id,op_type,act_user_id,created_unix").Table("action").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) - actionList := make([]*Action, 0) - sess.Find(&actionList) - + //sess.Select("id,user_id,op_type,act_user_id,created_unix").Table("action").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) + //actionList := make([]*Action, 0) + //sess.Find(&actionList) + actionList, err := sess.QueryInterface("select id,user_id,op_type,act_user_id,created_unix from public.action where " + cond + " order by id asc limit " + fmt.Sprint(PAGE_SIZE) + " offset " + fmt.Sprint(indexTotal)) + if err != nil { + log.Info("error:" + err.Error()) + continue + } log.Info("query action size=" + fmt.Sprint(len(actionList))) for _, actionRecord := range actionList { - if int64(actionRecord.OpType) == actionType { - if _, ok := resultMap[actionRecord.UserID]; !ok { - resultMap[actionRecord.UserID] = 1 + userId := convertInterfaceToInt64(actionRecord["user_id"]) + if convertInterfaceToInt64(actionRecord["op_type"]) == actionType { + if _, ok := resultMap[userId]; !ok { + resultMap[userId] = 1 } else { - resultMap[actionRecord.UserID] += 1 + resultMap[userId] += 1 } } - key := getDate(actionRecord.CreatedUnix) - if _, ok := mostActiveMap[actionRecord.UserID]; !ok { + created_unix := timeutil.TimeStamp(convertInterfaceToInt64(actionRecord["created_unix"])) + key := getDate(created_unix) + if _, ok := mostActiveMap[userId]; !ok { tmpMap := make(map[string]int) tmpMap[key] = 1 - mostActiveMap[actionRecord.UserID] = tmpMap + mostActiveMap[userId] = tmpMap } else { - mostActiveMap[actionRecord.UserID][key] = getMapKeyStringValue(key, mostActiveMap[actionRecord.UserID]) + 1 + mostActiveMap[userId][key] = getMapKeyStringValue(key, mostActiveMap[userId]) + 1 } - utcTime := actionRecord.CreatedUnix.AsTime() + utcTime := created_unix.AsTime() hour := utcTime.Hour() if hour >= 0 && hour <= 5 { key = "hour_hour" - if getMapKeyStringValue(key, mostActiveMap[actionRecord.UserID]) < hour { - mostActiveMap[actionRecord.UserID][key] = hour - mostActiveMap[actionRecord.UserID]["hour_day"] = utcTime.Day() - mostActiveMap[actionRecord.UserID]["hour_month"] = int(utcTime.Month()) - mostActiveMap[actionRecord.UserID]["hour_year"] = utcTime.Year() + if getMapKeyStringValue(key, mostActiveMap[userId]) < hour { + mostActiveMap[userId][key] = hour + mostActiveMap[userId]["hour_day"] = utcTime.Day() + mostActiveMap[userId]["hour_month"] = int(utcTime.Month()) + mostActiveMap[userId]["hour_year"] = utcTime.Year() } } } @@ -1797,6 +1803,21 @@ func queryCommitAction(start_unix int64, end_unix int64, actionType int64) (map[ return resultMap, mostActiveMap } + +func convertInterfaceToInt64(obj interface{}) int64 { + switch obj.(type) { + case int8: + return int64(obj.(int8)) + case int16: + return int64(obj.(int16)) + case int32: + return int64(obj.(int32)) + case int64: + return obj.(int64) + } + return 0 +} + func getDate(createTime timeutil.TimeStamp) string { return createTime.Format("2006-01-02") }