Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
package keyword
import (
"91porn-server/common/constant"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/l/searchlogmod"
"91porn-server/models/s/kwstatmod"
)
type TimeRange = timerange.TimeRange
func toKeywordIncDoc(realm constant.RealmType, data map[string]int64) []kwstatmod.KeywordIncDoc {
list := make([]kwstatmod.KeywordIncDoc, len(data))
i := 0
for k, v := range data {
word := k
count := v
list[i] = kwstatmod.KeywordIncDoc{
Realm: realm,
Word: word,
Count: count,
}
i++
}
return list
}
func GetIncDocList(timeRange TimeRange) ([]kwstatmod.KeywordIncDoc, error) {
incDocList := []kwstatmod.KeywordIncDoc{}
//综合关键字搜索数
complexKeywordCountMap, err := searchlogmod.GetKeywordCountMapByTime(timeRange.Head, timeRange.Tail, constant.SearchComplex)
if err != nil {
return nil, err
}
complexIncDocList := toKeywordIncDoc(constant.SearchComplex, complexKeywordCountMap)
incDocList = append(incDocList, complexIncDocList...)
//视屏关键字搜索数
vidKeywordCountMap, err := searchlogmod.GetKeywordCountMapByTime(timeRange.Head, timeRange.Tail, constant.SearchSP)
if err != nil {
return nil, err
}
videoIncDocList := toKeywordIncDoc(constant.SearchSP, vidKeywordCountMap)
incDocList = append(incDocList, videoIncDocList...)
//标签关键字搜索数
tagKeywordCountMap, err := searchlogmod.GetKeywordCountMapByTime(timeRange.Head, timeRange.Tail, constant.SearchTag)
if err != nil {
return nil, err
}
tagIncDocList := toKeywordIncDoc(constant.SearchTag, tagKeywordCountMap)
incDocList = append(incDocList, tagIncDocList...)
//用户关键字搜索数
userKeywordCountMap, err := searchlogmod.GetKeywordCountMapByTime(timeRange.Head, timeRange.Tail, constant.SearchUser)
if err != nil {
return nil, err
}
userIncDocList := toKeywordIncDoc(constant.SearchUser, userKeywordCountMap)
incDocList = append(incDocList, userIncDocList...)
return incDocList, nil
}
+72
View File
@@ -0,0 +1,72 @@
package keyword
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/kwstatmod"
"91porn-server/models/s/statrecordmod"
"91porn-server/skd/skdg"
)
// RunStat
func RunStat(defaultStatDate time.Time) {
log.Info("keyword stat running...")
defer log.Info("keyword stat finished...")
now := time.Now()
//从历史提交记录中获取上次记录时间
lastStatAt, err := statrecordmod.LastRecordTime(statrecordmod.KeywordStatJob, defaultStatDate) //第一次从默认记录时间开始统计
if err != nil {
log.Error("Keyword RunStat lastRecordTime faild!", log.E(err))
return
}
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
//拆分时间区间并依次提交,均衡数据库读写压力
for recentMinute.After(lastStatAt) {
end := lastStatAt.Add(statrecordmod.FiveMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
//此时的零日点
sumDate := timerange.LocDayRange(subTimeRange.Head).Head
//装配基础统计数据
incDocList, err := GetIncDocList(subTimeRange)
if err != nil {
log.Error("Keyword RunStat GetIncDocList faild!", log.E(err))
return
}
//提交数据
log.Info("keywordStat committing...", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
if err = commit(sumDate, subTimeRange.Tail, incDocList); err != nil {
log.Error("Keyword RunStat commit faild!", log.E(err))
return
}
log.Info("keywordStat committed.", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
lastStatAt = end
}
}
// commit 提交统计数据
func commit(sumDate time.Time, recordTime time.Time, incDocList []kwstatmod.KeywordIncDoc) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) (err error) {
if len(incDocList) != 0 {
if err = kwstatmod.ChangeStatTrans(trans, sumDate, recordTime, incDocList); err != nil {
return fmt.Errorf(" keyword commit ChangeStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err = statrecordmod.UpsertOneTrans(trans, statrecordmod.KeywordStatJob, recordTime); err != nil {
return fmt.Errorf(" keyword commit UpsertOneTrans faild!, err:%+v\n", err)
}
return
}, opt)
}
+29
View File
@@ -0,0 +1,29 @@
package kwrank
import (
"time"
"91porn-server/models/s/kwrankmod"
"91porn-server/models/s/kwstatmod"
)
type RankSetDoc = kwrankmod.RankSetDoc
func GetStatSetDocList(sumDate time.Time) ([]RankSetDoc, error) {
keywordCountMap, err := kwstatmod.KeywordCountMapBySumDate(sumDate)
if err != nil {
return nil, err
}
rankDocList := make([]RankSetDoc, len(keywordCountMap))
i := 0
for w, c := range keywordCountMap {
word := w
count := c
rankDocList[i] = RankSetDoc{
Word: &word,
Count: &count,
}
i++
}
return rankDocList, nil
}
+52
View File
@@ -0,0 +1,52 @@
package kwrank
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/kwrankmod"
"91porn-server/models/s/statrecordmod"
"91porn-server/skd/skdg"
)
// RunStat
func RunStat(defaultStatDate time.Time) {
log.Info("keyword rank stat running...")
defer log.Info("keyword rank stat finished...")
now := time.Now()
sumDate := timerange.LocDayRange(now).Head //获取零日点
//装配基础统计数据
setList, err := GetStatSetDocList(sumDate)
if err != nil {
log.Error("kwrank RunStat fillStatSetDoc faild!", log.E(err))
return
}
//提交数据
log.Info("keyword rank stat committing...", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
if err = commit(sumDate, recentMinute, setList); err != nil {
log.Error("kwrank RunStat commit faild!", log.E(err))
return
}
log.Info("keyword rank stat committed.", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
}
// commit 提交统计数据
func commit(sumDate time.Time, recordTime time.Time, setDocList []RankSetDoc) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) (err error) {
if len(setDocList) != 0 {
if err = kwrankmod.ChangeStatTrans(trans, sumDate, recordTime, setDocList); err != nil {
return fmt.Errorf("kwrank commit ChangeStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err = statrecordmod.UpsertOneTrans(trans, statrecordmod.KeywordRankStatJob, recordTime); err != nil {
return fmt.Errorf("kwrank commit UpsertOneTrans faild!, err:%+v\n", err)
}
return
}, opt)
}
+53
View File
@@ -0,0 +1,53 @@
package rank
import (
"time"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/hotstatmod"
"91porn-server/models/v/vidmod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// RunStat 统计实时排行榜
func RunStat() {
log.Info("rank stat running...")
defer log.Info("rank stat finished...")
now := time.Now()
sumDate := timerange.LocDayRange(now).Head
infos, err := vidmod.GetTotalNewsList()
if err != nil {
return
}
mNow := calNowHot(infos)
mYesterday, err := hotstatmod.GetYesterdayHotValue(sumDate)
if err != nil {
return
}
mLastWeek, err := hotstatmod.GetLastWeekHotValue(sumDate)
if err != nil {
return
}
mLastMonth, _ := hotstatmod.GetLastMonthHotValue(sumDate)
mDayli := make(map[primitive.ObjectID]int)
mWeek := make(map[primitive.ObjectID]int)
mMonth := make(map[primitive.ObjectID]int)
for vid, v := range mNow {
mDayli[vid] = v - mYesterday[vid]
mWeek[vid] = v - mLastWeek[vid]
mMonth[vid] = v - mLastMonth[vid]
}
//入库
_ = hotstatmod.UpdateInsertHotValue(sumDate, mDayli, mWeek, mMonth, mNow)
}
func calNowHot(infos []*vidmod.VideoModel) map[primitive.ObjectID]int {
mNow := make(map[primitive.ObjectID]int)
for _, v := range infos {
value := 1*v.FakePlayCount + 4*v.FakeLikeCount + 2*v.FakeCommentCount + v.FakeShareCount
mNow[v.ID] = value
}
return mNow
}
+138
View File
@@ -0,0 +1,138 @@
package rechorder
import (
"time"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statordermod"
"91porn-server/models/v/rchgordmod"
)
type RechargeOrderStateDoc = statordermod.RechargeOrderStateDoc
type RecOrderStateMap = statordermod.RecOrderStateMap
func fillRecOrderStatDocMap(sumDate time.Time, timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
//订单数 OrderCount
if err := fillRecOrderCount(timeRange, docMap); err != nil {
return err
}
//完成订单数 CompleteOrderCount
if err := fillRecCompleteOrderCount(timeRange, docMap); err != nil {
return err
}
//订单金额 OrderAmount
if err := fillRecOrderAmount(timeRange, docMap); err != nil {
return err
}
if err := fillRecCompleteOrderPayMoney(timeRange, docMap); err != nil {
return err
}
//用户已支付订单数
if err := fillRecPaidOrderCount(timeRange, docMap); err != nil {
return err
}
//用户已支付金额
return fillRecPaidMoney(timeRange, docMap)
}
// fillRecOrderCount fillRecOrderCount
func fillRecOrderCount(timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
orderCountMap, err := rchgordmod.ChannelOrderCountMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range orderCountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &RechargeOrderStateDoc{}
}
val := v
docM[channel].OrderCount = &val
}
return nil
}
// fillRecCompleteOrderCount fillRecCompleteOrderCount}
func fillRecCompleteOrderCount(timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
completeOrderCountMap, err := rchgordmod.ChannelCompleteOrderCountMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range completeOrderCountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &RechargeOrderStateDoc{}
}
val := v
docM[channel].CompleteOrderCount = &val
}
return nil
}
// fillRecOrderAmount fillRecOrderAmount
func fillRecOrderAmount(timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
orderAmountMap, err := rchgordmod.ChannelOrderMoneyMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range orderAmountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &RechargeOrderStateDoc{}
}
val := v
docM[channel].OrderAmount = &val
}
return nil
}
// fillRecCompleteOrderPayMoney fillRecCompleteOrderPayMoney
func fillRecCompleteOrderPayMoney(timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
payMoneyMap, err := rchgordmod.ChannelCompleteOrderPayMoneyMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range payMoneyMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &RechargeOrderStateDoc{}
}
val := v
docM[channel].CompleteOrderAmount = &val
}
return nil
}
// fillRecPaidOrderCount fillRecPaidOrderCount
func fillRecPaidOrderCount(timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
paiedOrderCountMap, err := rchgordmod.ChannelPaymentOrderCountMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range paiedOrderCountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &RechargeOrderStateDoc{}
}
val := v
docM[channel].PaidOrderCount = &val
}
return nil
}
// fillRecPaidMoney fillRecPaidMoney
func fillRecPaidMoney(timeRange timerange.TimeRange, docMap *RecOrderStateMap) error {
paiedMoneyMap, err := rchgordmod.ChannelPaymentMoneyMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range paiedMoneyMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &RechargeOrderStateDoc{}
}
val := v
docM[channel].PaidAmount = &val
}
return nil
}
+97
View File
@@ -0,0 +1,97 @@
package rechorder
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statordermod"
"91porn-server/models/s/statrecordmod"
"91porn-server/skd/skdg"
)
func RunStat(defaultStatDate time.Time) {
log.Info("rechorderStat stat running...")
defer log.Info("rechorderStat stat finished...")
now := time.Now()
//从历史提交记录中获取上次记录时间
lastStatAt, err := statrecordmod.LastRecordTime(statrecordmod.RechargeOrderStatJob, defaultStatDate) //第一次从默认记录时间开始统计
if err != nil {
log.Error("rechorder RunStat lastRecordTime faild!", log.E(err))
return
}
//过去几天的数据按一日为单位统计,帮助数据恢复
dayHead := timerange.LocDayRange(now).Head
for dayHead.After(lastStatAt) {
end := lastStatAt.AddDate(0, 0, 1)
//防止时间超出范围
if end.After(dayHead) {
end = dayHead
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err := statByTimeRange(subTimeRange); err != nil {
log.Error("rechorder RunStat statByTimeRange faild!", log.E(err))
return
}
lastStatAt = end
}
//当天的数据按照5分钟统计
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
//拆分时间区间并依次提交,控制数据库读写压力
for recentMinute.After(lastStatAt) {
end := lastStatAt.Add(statrecordmod.FiveMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err := statByTimeRange(subTimeRange); err != nil {
log.Error("rechorder RunStat statByTimeRange faild!", log.E(err))
return
}
lastStatAt = end
}
}
func statByTimeRange(timeRange timerange.TimeRange) error {
sumDate := timerange.LocDayRange(timeRange.Head).Head //获取此时的零日点
//装配渠道统计数据
recOrderStateMap := make(RecOrderStateMap)
if err := fillRecOrderStatDocMap(sumDate, timeRange, &recOrderStateMap); err != nil {
log.Error("rechorder RunStat fillRecOrderStatDocMap faild!", log.E(err))
return err
}
//提交渠道统计数据
log.Info("rechorderStat recharge committing...", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
if err := commitRec(sumDate, timeRange.Tail, recOrderStateMap); err != nil {
log.Error("rechorderStat RunStat commitRec faild!", log.E(err))
return err
}
log.Info("rechorderStat recharge committed.", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
return nil
}
// commit 提交订单统计数据
func commitRec(sumDate time.Time, recordTime time.Time, docMap RecOrderStateMap) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(docMap) != 0 {
if err := statordermod.ChangeRechargeStatTrans(trans, sumDate, recordTime, docMap); err != nil {
return fmt.Errorf("stat commitRec ChangeRechargeStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneTrans(trans, statrecordmod.RechargeOrderStatJob, recordTime); err != nil {
return fmt.Errorf("stat commitRec UpsertOneTrans faild!, err:%+v\n", err)
}
return nil
}, opt)
}
+91
View File
@@ -0,0 +1,91 @@
package statuser
import (
"time"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/l/payvidlgmod"
"91porn-server/models/s/statusermod"
"91porn-server/models/v/vidmod"
)
type TimeRange = timerange.TimeRange
type IncDoc = statusermod.IncDoc
type SetDoc = statusermod.SetDoc
type Itemtype = statusermod.Itemtype
const (
SetType string = "set"
IncType string = "inc"
)
type Method struct {
MethodType string
GetIncDocListMethod func(timeRange TimeRange) ([]IncDoc, error)
GetSetDocListMethod func(timeRange TimeRange) ([]SetDoc, error)
IncCommitMethod func(incDocList []IncDoc, name string, recordAt time.Time) error
SetCommitMethod func(setDocList []SetDoc, name string, recordAt time.Time) error
}
var methodMap = map[Itemtype]Method{
//视频收益
statusermod.VidIncome: {MethodType: IncType, GetIncDocListMethod: getIncomneDocList, IncCommitMethod: commitIncDoc},
//上传数量
statusermod.UploadCount: {MethodType: SetType, GetSetDocListMethod: getUploadCountDocList, SetCommitMethod: commitSetDoc},
}
func getIncomneDocList(timeRange TimeRange) ([]IncDoc, error) {
m, err := payvidlgmod.PublisherIncomeMapByTime(timeRange.Head, timeRange.Tail)
if err != nil {
return nil, err
}
list := make([]IncDoc, len(m))
i := 0
for uid, income := range m {
list[i] = IncDoc{
UID: uid,
Item: statusermod.VidIncome,
Count: income,
RecordAt: timeRange.Tail,
}
i++
}
return list, nil
}
func getUploadCountDocList(timeRange TimeRange) ([]SetDoc, error) {
mats := []vidmod.Matcher{
(&vidmod.StatusMatch{Status: vidmod.CheckPass}).New(),
(&vidmod.ReviewAtGTEAndLTMatch{GTE: &timeRange.Head, LT: &timeRange.Tail}).New(),
}
publisherIDs, err := vidmod.PublisherIDList(mats...)
if err != nil {
return nil, err
}
if len(publisherIDs) == 0 {
return nil, nil
}
mats = []vidmod.Matcher{
(&vidmod.StatusMatch{Status: vidmod.CheckPass}).New(),
(&vidmod.PublisherIDInMatch{PublisherIDList: publisherIDs}).New(),
}
m, err := vidmod.CountMapByPublisherID(mats...)
if err != nil {
return nil, err
}
list := make([]SetDoc, len(m))
i := 0
for uid, uploadCount := range m {
list[i] = SetDoc{
UID: uid,
Item: statusermod.UploadCount,
Count: uploadCount,
RecordAt: timeRange.Tail,
}
i++
}
return list, nil
}
+143
View File
@@ -0,0 +1,143 @@
package statuser
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statrecordmod"
"91porn-server/models/s/statusermod"
"91porn-server/skd/skdg"
)
func RunStat(defaultStatDate time.Time) {
log.Info("user stat running...")
defer log.Info("user stat finished...")
defaultTimeMap := map[string]time.Time{
string(statusermod.VidIncome): defaultStatDate,
string(statusermod.UploadCount): defaultStatDate,
}
//从历史提交记录中获取上次记录时间
lastStatAtMap, err := statrecordmod.LastRecordTimeMap(statrecordmod.UserStatJob, defaultTimeMap) //第一次从默认记录时间开始统计
if err != nil {
log.Error("user stat statuser LastRecordTimeMap faild!", log.E(err))
return
}
now := time.Now()
dayHead := timerange.LocDayRange(now).Head
for item, lastStatAt := range lastStatAtMap {
_lastStatAt := lastStatAt
//过去几天的数据按一日为单位统计,帮助数据恢复
for dayHead.After(_lastStatAt) {
end := _lastStatAt.AddDate(0, 0, 1)
//防止时间超出范围
if end.After(dayHead) {
end = dayHead
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: _lastStatAt,
Tail: end,
}
if err = statByTimeRange(item, subTimeRange); err != nil {
log.Error("user stat statuser statByTimeRange 1 faild!", log.E(err))
return
}
_lastStatAt = end
}
lastStatAtMap[item] = _lastStatAt
}
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
//拆分时间区间并依次提交,控制数据库读写压力
for item, lastStatAt := range lastStatAtMap {
_lastStatAt := lastStatAt
for recentMinute.After(_lastStatAt) {
end := _lastStatAt.Add(statrecordmod.FiveMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: _lastStatAt,
Tail: end,
}
if err = statByTimeRange(item, subTimeRange); err != nil {
log.Error("user stat statuser statByTimeRange 2 faild!", log.E(err))
return
}
_lastStatAt = end
}
lastStatAtMap[item] = _lastStatAt
}
}
func statByTimeRange(item string, timeRange timerange.TimeRange) error {
method, ok := methodMap[Itemtype(item)]
if !ok {
return nil
}
if method.MethodType == IncType {
//装配INC基础统计数据
incDocList, err := method.GetIncDocListMethod(timeRange)
if err != nil {
log.Error("user stat statByTimeRange GetIncDocListMethod faild!", log.Any("item", item), log.E(err))
return err
}
//提交Inc统计数据
log.Info("user stat statByTimeRange IncCommitMethod committing...", log.Any("item", item))
if err = method.IncCommitMethod(incDocList, item, timeRange.Tail); err != nil {
log.Error("user stat statByTimeRange IncCommitMethod faild!", log.Any("item", item), log.E(err))
return err
}
log.Info("user stat statByTimeRange IncCommitMethod committed.", log.Any("item", item))
} else if method.MethodType == SetType {
//装配SET基础统计数据
setDocList, err := method.GetSetDocListMethod(timeRange)
if err != nil {
log.Error("user stat statByTimeRange GetSetDocListMethod faild!", log.Any("item", item), log.E(err))
return err
}
//提交SET统计数据
log.Info("user stat statByTimeRange SetCommitMethod committing...", log.Any("item", item))
if err = method.SetCommitMethod(setDocList, item, timeRange.Tail); err != nil {
log.Error("user stat statByTimeRange SetCommitMethod faild!", log.Any("item", item), log.E(err))
return err
}
log.Info("user stat statByTimeRange SetCommitMethod committed.", log.Any("item", item))
}
return nil
}
func commitIncDoc(incDocList []IncDoc, item string, recordAt time.Time) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(incDocList) != 0 {
if err := statusermod.ChangeIncStatTrans(trans, incDocList); err != nil {
return fmt.Errorf("user stat commitCount ChangeIncStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneItemTrans(trans, statrecordmod.UserStatJob, item, recordAt); err != nil {
return fmt.Errorf("user stat commitIncDoc UpsertOneItemTrans faild!, err:%+v\n", err)
}
return nil
}, opt)
}
func commitSetDoc(setDocList []SetDoc, item string, recordAt time.Time) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(setDocList) != 0 {
err := statusermod.ChangeSetStatTrans(trans, setDocList)
if err != nil {
return fmt.Errorf("user stat commitCount ChangeSetStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneItemTrans(trans, statrecordmod.UserStatJob, item, recordAt); err != nil {
return fmt.Errorf("user stat commitSetDoc UpsertOneItemTrans faild!, item: %s+v, err:%+v\n", item, err)
}
return nil
}, opt)
}
+25
View File
@@ -0,0 +1,25 @@
package tagplay
import (
"91porn-server/common/timeutil/timerange"
"91porn-server/models/l/playlgmod"
"91porn-server/models/s/stattagplaymod"
)
type IncDoc = stattagplaymod.IncDoc
func GetTagPlayIncDocList(timeRange timerange.TimeRange) ([]IncDoc, error) {
playLogList, err := playlgmod.GetTagPlayByTimeRange(timeRange.Head, timeRange.Tail)
if err != nil {
return []IncDoc{}, err
}
tagPlayList := make([]IncDoc, len(playLogList))
for i, v := range playLogList {
tagPlayList[i] = IncDoc{
VideoID: v.GroupID.VideoID,
TagID: v.GroupID.TagID,
PlayCount: v.PlayCount,
}
}
return tagPlayList, nil
}
+71
View File
@@ -0,0 +1,71 @@
package tagplay
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statrecordmod"
"91porn-server/models/s/stattagplaymod"
"91porn-server/skd/skdg"
)
func RunStat(defaultStatDate time.Time) {
log.Info("tag play stat start...")
defer log.Info("tag play stat end...")
// 获取上次统计的记录时间
lastStatAt, err := statrecordmod.LastRecordTime(statrecordmod.TagPlayStatJob, defaultStatDate) //第一次从默认记录时间开始统计
if err != nil {
log.Error("tag play RunStat lastRecordTime faild!", log.E(err))
return
}
now := time.Now()
// 按照每个钟的5分钟刻度统计: 0,05,10,15,20,25,30,35,40,45,50,55
// 获取最近的时间刻度
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale)
for recentMinute.After(lastStatAt) {
end := lastStatAt.Add(statrecordmod.FiveMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
// 时间区间5分钟
subTimeRange := timerange.TimeRange{
Head: lastStatAt,
Tail: end,
}
//5分钟内的统计数据
incDocList, err := GetTagPlayIncDocList(subTimeRange)
if err != nil {
log.Error("tag play RunStat GetTagPlayList err!", log.E(err))
return
}
//每次循环都应提交
log.Info("tag play stat committing...")
if err = commit(incDocList, subTimeRange.Tail); err != nil {
log.Error("tag play RunStat commit err! ", log.E(err))
return
}
log.Info("tag play stat committed.")
// 统计数据
lastStatAt = end
}
}
func commit(statData []IncDoc, recordTime time.Time) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(statData) != 0 {
if err := stattagplaymod.ChangeStatTrans(trans, statData); err != nil {
return fmt.Errorf("tag play commit ChangeStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneTrans(trans, statrecordmod.TagPlayStatJob, recordTime); err != nil {
return fmt.Errorf("tag play commit UpsertOneTrans faild!, err:%+v\n", err)
}
return nil
}, opt)
}
+130
View File
@@ -0,0 +1,130 @@
package video
import (
"time"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/l/payvidlgmod"
"91porn-server/models/l/playlgmod"
"91porn-server/models/s/statvidmod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ObjectID = primitive.ObjectID
type TimeRange = timerange.TimeRange
type VideoStatIncDoc = statvidmod.VideoStatIncDoc
type VideoStatSetDoc = statvidmod.VideoStatSetDoc
type VideoStatDoc = statvidmod.VideoStatDoc
type VideoStatDocMap = statvidmod.VideoStatDocMap //ObjectID->VideoStatDoc
// fillPayCoin
func fillPayCoin(timeRange TimeRange, docMap *VideoStatDocMap) error {
incomeMap, err := payvidlgmod.PayCoinMapByTime(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for vid, v := range incomeMap {
if _, existed := docM[vid]; !existed {
docM[vid] = &VideoStatDoc{}
}
val := v
docM[vid].Income = &val
}
return nil
}
// fillPayCount
func fillPayCount(timeRange TimeRange, docMap *VideoStatDocMap) error {
payCountMap, err := payvidlgmod.PayCountMapByTime(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for vid, v := range payCountMap {
if _, existed := docM[vid]; !existed {
docM[vid] = &VideoStatDoc{}
}
val := v
docM[vid].PayCount = &val
}
return nil
}
// fillPlayCount
func fillPlayCount(timeRange TimeRange, docMap *VideoStatDocMap) error {
playCountMap, err := playlgmod.PlayCountMapByTime(timeRange.Head, timeRange.Tail, []int{0, 1, 2}) //0,免费 1付费 2.试看
if err != nil {
return err
}
docM := *docMap
for vid, v := range playCountMap {
if _, existed := docM[vid]; !existed {
docM[vid] = &VideoStatDoc{}
}
val := v
docM[vid].PlayCount = &val
}
return nil
}
// fillPayPlayCount
func fillPayPlayCount(timeRange TimeRange, docMap *VideoStatDocMap) error {
payPlayCountMap, err := playlgmod.PlayCountMapByTime(timeRange.Head, timeRange.Tail, []int{1}) //0,免费 1付费 2.试看
if err != nil {
return err
}
docM := *docMap
for vid, v := range payPlayCountMap {
if _, existed := docM[vid]; !existed {
docM[vid] = &VideoStatDoc{}
}
val := v
docM[vid].PayPlayCount = &val
}
return nil
}
func fillTax(timeRange TimeRange, docMap *VideoStatDocMap) error {
payPlayCountMap, err := payvidlgmod.TaxAmountMapByTime(timeRange.Head, timeRange.Tail) //0,免费 1付费 2.试看
if err != nil {
return err
}
docM := *docMap
for vid, v := range payPlayCountMap {
if _, existed := docM[vid]; !existed {
docM[vid] = &VideoStatDoc{}
}
val := v
docM[vid].Tax = &val
}
return nil
}
// fillStatDocMap
func fillStatDocMap(sumDate time.Time, timeRange TimeRange, docMap *VideoStatDocMap) error {
//收入
if err := fillPayCoin(timeRange, docMap); err != nil {
return err
}
//购买次数
if err := fillPayCount(timeRange, docMap); err != nil {
return err
}
//视屏播放次数
if err := fillPlayCount(timeRange, docMap); err != nil {
return err
}
//付费视屏播放次数
if err := fillPayPlayCount(timeRange, docMap); err != nil {
return err
}
//税
return fillTax(timeRange, docMap)
}
+97
View File
@@ -0,0 +1,97 @@
package video
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statrecordmod"
"91porn-server/models/s/statvidmod"
"91porn-server/skd/skdg"
)
func RunStat(defaultStatDate time.Time) {
log.Info("video stat running...")
defer log.Info("video stat finished...")
now := time.Now()
//从历史提交记录中获取上次记录时间
lastStatAt, err := statrecordmod.LastRecordTime(statrecordmod.VideoStatJob, defaultStatDate) //第一次从默认记录时间开始统计
if err != nil {
log.Error("video stat RunVideoStat lastRecordTime faild!", log.E(err))
return
}
//过去几天的数据按一日为单位统计,帮助数据恢复
dayHead := timerange.LocDayRange(now).Head
for dayHead.After(lastStatAt) {
end := lastStatAt.AddDate(0, 0, 1)
//防止时间超出范围
if end.After(dayHead) {
end = dayHead
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err = statByTimeRange(subTimeRange); err != nil {
log.Error("video RunStat statByTimeRange faild!", log.E(err))
return
}
lastStatAt = end
}
//当天的数据按照5分钟统计
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
//拆分时间区间并依次提交,控制数据库读写压力
for recentMinute.After(lastStatAt) {
end := lastStatAt.Add(statrecordmod.OneMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err = statByTimeRange(subTimeRange); err != nil {
log.Error("video RunStat statByTimeRange faild!", log.E(err))
return
}
lastStatAt = end
}
}
func statByTimeRange(timeRange timerange.TimeRange) error {
sumDate := timerange.LocDayRange(timeRange.Head).Head //获取此时的零日点
//装配基础统计数据
statDocMap := make(VideoStatDocMap)
if err := fillStatDocMap(sumDate, timeRange, &statDocMap); err != nil {
log.Error("video stat RunVideoStat fillStatDocMap faild!", log.E(err))
return err
}
//提交渠道统计数据
log.Info("videoStat committing...", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
if err := commit(sumDate, timeRange.Tail, statDocMap); err != nil {
log.Error("video stat RunVideoStat commit faild!", log.E(err))
return err
}
log.Info("videoStat committed.", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
return nil
}
// commit 提交统计数据
func commit(sumDate time.Time, recordTime time.Time, docMap VideoStatDocMap) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(docMap) != 0 {
if err := statvidmod.ChangeStatTrans(trans, sumDate, recordTime, docMap); err != nil {
return fmt.Errorf("video stat commit ChangeStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneTrans(trans, statrecordmod.VideoStatJob, recordTime); err != nil {
return fmt.Errorf("video stat commit UpsertOneTrans faild!, err:%+v\n", err)
}
return nil
}, opt)
}
+46
View File
@@ -0,0 +1,46 @@
package vidtotal
import (
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statvidmod"
"91porn-server/models/s/statvidtotalmod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ObjectID = primitive.ObjectID
type TimeRange = timerange.TimeRange
type VideoTotalIncDoc = statvidtotalmod.IncDoc
type VideoTotalIncDocMap = statvidtotalmod.IncDocMap
type RecordAtGTEAndLTMatch = statvidmod.RecordAtGTEAndLTMatch
func getVideoTotalIncDocMap(timeRange TimeRange) (VideoTotalIncDocMap, error) {
recordAtGTEAndLTMatch := RecordAtGTEAndLTMatch{GTE: &timeRange.Head, LT: &timeRange.Tail}
groupList, err := statvidmod.SumByRecordAt(recordAtGTEAndLTMatch)
if err != nil {
return nil, err
}
m := toVideoTotalIncDocMap(groupList)
return m, nil
}
func toVideoTotalIncDocMap(groupList []statvidmod.SumGroup) VideoTotalIncDocMap {
m := make(VideoTotalIncDocMap, len(groupList))
for _, v := range groupList {
_, ok := m[v.Vid]
if !ok {
m[v.Vid] = &VideoTotalIncDoc{}
}
doc := m[v.Vid]
doc.Income = v.Income
doc.PayCount = v.PayCount
doc.PlayCount = v.PlayCount
doc.PayPlayCount = v.PayPlayCount
doc.Tax = v.Tax
}
return m
}
+96
View File
@@ -0,0 +1,96 @@
package vidtotal
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statrecordmod"
"91porn-server/models/s/statvidtotalmod"
"91porn-server/skd/skdg"
)
func RunStat(defaultStatDate time.Time) {
log.Info("video total stat running...")
defer log.Info("video total stat finished...")
now := time.Now()
//从历史提交记录中获取上次记录时间
lastStatAt, err := statrecordmod.LastRecordTime(statrecordmod.VideoTotalStatJob, defaultStatDate) //第一次从默认记录时间开始统计
if err != nil {
log.Error("video total stat RunVideoStat lastRecordTime faild!", log.E(err))
return
}
//过去几天的数据按一日为单位统计,帮助数据恢复
dayHead := timerange.LocDayRange(now).Head
for dayHead.After(lastStatAt) {
end := lastStatAt.AddDate(0, 0, 1)
//防止时间超出范围
if end.After(dayHead) {
end = dayHead
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err = statByTimeRange(subTimeRange); err != nil {
log.Error("video total RunStat statByTimeRange faild!", log.E(err))
return
}
lastStatAt = end
}
//当天的数据按照5分钟统计
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
//拆分时间区间并依次提交,控制数据库读写压力
for recentMinute.After(lastStatAt) {
end := lastStatAt.Add(statrecordmod.FiveMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err = statByTimeRange(subTimeRange); err != nil {
log.Error("video total RunStat statByTimeRange faild!", log.E(err))
return
}
lastStatAt = end
}
}
func statByTimeRange(timeRange timerange.TimeRange) error {
//装配基础统计数据
statDocMap, err := getVideoTotalIncDocMap(timeRange)
if err != nil {
log.Error("video total stat RunVideoStat fillStatDocMap faild!", log.E(err))
return err
}
//提交视屏总计数据
log.Info("videoTotalStat committing...")
if err = commit(timeRange.Tail, statDocMap); err != nil {
log.Error("video total stat RunVideoStat commit faild!", log.E(err))
return err
}
log.Info("videoTotalStat committed.")
return nil
}
// commit 提交统计数据
func commit(recordTime time.Time, docMap VideoTotalIncDocMap) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(docMap) != 0 {
if err := statvidtotalmod.ChangeStatTrans(trans, recordTime, docMap); err != nil {
return fmt.Errorf("video total stat commit ChangeStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneTrans(trans, statrecordmod.VideoTotalStatJob, recordTime); err != nil {
return fmt.Errorf("video total stat commit UpsertOneTrans faild!, err:%+v\n", err)
}
return nil
}, opt)
}
+139
View File
@@ -0,0 +1,139 @@
package withorder
import (
"time"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statordermod"
"91porn-server/models/v/wdordmod"
)
type WithDrawOrderStateDoc = statordermod.WithDrawOrderStateDoc
type WitOrderStateMap = statordermod.WitOrderStateMap
func fillWitOrderStatDocMap(sumDate time.Time, timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
//订单数 OrderCount
if err := fillWitOrderCount(timeRange, docMap); err != nil {
return err
}
//完成订单数 CompleteOrderCount
if err := fillWitCompleteOrderCount(timeRange, docMap); err != nil {
return err
}
//订单金额 OrderAmount
if err := fillWitOrderAmount(timeRange, docMap); err != nil {
return err
}
//实际兑换金额 CompleteOrderAmount
if err := fillWitCompleteOrderPayAmount(timeRange, docMap); err != nil {
return err
}
//三方已出款订单数 fillWitPaiedOrderCount
if err := fillWitPaiedOrderCount(timeRange, docMap); err != nil {
return err
}
//三方已出款金额 fillWitPaiedMoney
return fillWitPaiedMoney(timeRange, docMap)
}
// fillWitOrderCount fillWitOrderCount
func fillWitOrderCount(timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
orderCountMap, err := wdordmod.ChannelOrderCountMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range orderCountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &WithDrawOrderStateDoc{}
}
val := v
docM[channel].OrderCount = &val
}
return nil
}
// fillWitCompleteOrderCount fillWitCompleteOrderCount
func fillWitCompleteOrderCount(timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
completeOrderCountMap, err := wdordmod.ChannelCompleteOrderCountMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range completeOrderCountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &WithDrawOrderStateDoc{}
}
val := v
docM[channel].CompleteOrderCount = &val
}
return nil
}
// fillWitOrderAmount fillWitOrderAmount
func fillWitOrderAmount(timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
orderAmountMap, err := wdordmod.ChannelOrderMoneyMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range orderAmountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &WithDrawOrderStateDoc{}
}
val := v
docM[channel].OrderAmount = &val
}
return nil
}
// fillWitCompleteOrderPayAmount fillWitCompleteOrderPayAmount
func fillWitCompleteOrderPayAmount(timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
completeOrderAmountMap, err := wdordmod.ChannelCompleteOrderPayMoneyMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range completeOrderAmountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &WithDrawOrderStateDoc{}
}
val := v
docM[channel].CompleteOrderAmount = &val
}
return nil
}
// fillWitPaiedOrderCount fillWitPaiedOrderCount
func fillWitPaiedOrderCount(timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
receivedOrderCountMap, err := wdordmod.ChannelReceivedOrderCountMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range receivedOrderCountMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &WithDrawOrderStateDoc{}
}
val := v
docM[channel].PaidOrderCount = &val
}
return nil
}
// fillWitPaiedMoney fillWitPaiedMoney
func fillWitPaiedMoney(timeRange timerange.TimeRange, docMap *WitOrderStateMap) error {
receivedMoneyMap, err := wdordmod.ChannelReceivedMoneyMap(timeRange.Head, timeRange.Tail)
if err != nil {
return err
}
docM := *docMap
for channel, v := range receivedMoneyMap {
if _, existed := docM[channel]; !existed {
docM[channel] = &WithDrawOrderStateDoc{}
}
val := v
docM[channel].PaidAmount = &val
}
return nil
}
+97
View File
@@ -0,0 +1,97 @@
package withorder
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/timeutil/timerange"
"91porn-server/models/s/statordermod"
"91porn-server/models/s/statrecordmod"
"91porn-server/skd/skdg"
)
func RunStat(defaultStatDate time.Time) {
log.Info("withorder stat running...")
defer log.Info("withorder stat finished...")
now := time.Now()
//从历史提交记录中获取上次记录时间
lastStatAt, err := statrecordmod.LastRecordTime(statrecordmod.WithdrawOrderStatJob, defaultStatDate) //第一次从默认记录时间开始统计
if err != nil {
log.Error("withorder RunStat lastRecordTime faild!", log.E(err))
return
}
//过去几天的数据按一日为单位统计,帮助数据恢复
dayHead := timerange.LocDayRange(now).Head
for dayHead.After(lastStatAt) {
end := lastStatAt.AddDate(0, 0, 1)
//防止时间超出范围
if end.After(dayHead) {
end = dayHead
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err = statByTimeRange(subTimeRange); err != nil {
log.Error("withorder RunStat statByTimeRange 1 faild!", log.E(err))
return
}
lastStatAt = end
}
//当天的数据按照5分钟统计
recentMinute := timerange.RecentMinute(now, statrecordmod.FiveMinuteScale) //对齐本次统计时间 Minute % frequency == 0
//拆分时间区间并依次提交,控制数据库读写压力
for recentMinute.After(lastStatAt) {
end := lastStatAt.Add(statrecordmod.FiveMinuteScale * time.Minute)
//防止时间超出范围
if end.After(recentMinute) {
end = recentMinute
}
subTimeRange := timerange.TimeRange{ //连续子切片
Head: lastStatAt,
Tail: end,
}
if err = statByTimeRange(subTimeRange); err != nil {
log.Error("withorder RunStat statByTimeRange 2 faild!", log.E(err))
return
}
lastStatAt = end
}
}
func statByTimeRange(timeRange timerange.TimeRange) error {
sumDate := timerange.LocDayRange(timeRange.Head).Head //获取此时的零日点
//装配渠道统计数据
witOrderStateMap := make(WitOrderStateMap)
if err := fillWitOrderStatDocMap(sumDate, timeRange, &witOrderStateMap); err != nil {
log.Error("withorder RunStat fillWitOrderStatDocMap faild!", log.E(err))
return err
}
//提交渠道统计数据
log.Info("withorderStat withdraw committing...", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
if err := commitWit(sumDate, timeRange.Tail, witOrderStateMap); err != nil {
log.Error("withorder RunStat commitWit faild!", log.E(err))
return err
}
log.Info("withorderStat withdraw committed.", log.Any("sumDate", sumDate), log.Any("location", sumDate.Location().String()))
return nil
}
// commit 提交订单统计数据
func commitWit(sumDate time.Time, recordTime time.Time, stateMap WitOrderStateMap) error {
opt := (&db.TransOpts{}).SetReEntry(10)
return skdg.StatDB.Trans(func(trans *db.MongoTool) error {
if len(stateMap) != 0 {
if err := statordermod.ChangeWithDrawStatTrans(trans, sumDate, recordTime, stateMap); err != nil {
return fmt.Errorf("stat commitWit ChangeWithDrawStatTrans faild!, err:%+v\n", err)
}
}
//提交本次修改记录
if err := statrecordmod.UpsertOneTrans(trans, statrecordmod.WithdrawOrderStatJob, recordTime); err != nil {
return fmt.Errorf("stat commitWit UpsertOneTrans faild!, err:%+v\n", err)
}
return nil
}, opt)
}