From 1b2769d4299c6d18e09bdf54f481c06b001bb383 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Thu, 16 May 2024 23:18:24 +0800 Subject: [PATCH 1/8] add log --- library/middleware/logger.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/middleware/logger.go b/library/middleware/logger.go index 76ec9a1b..347b355e 100644 --- a/library/middleware/logger.go +++ b/library/middleware/logger.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/gin-gonic/gin" "service/library/logger" + "strings" "time" ) @@ -91,7 +92,9 @@ func LoggerMiddleware(conf gin.LoggerConfig) gin.HandlerFunc { bodyStr = string(body.([]byte)) } logger.Info("%s params: %s", formatter(param), bodyStr) - //logger.Info("%s response: %s", formatter(param), blw.body.String()) + if strings.Contains(param.Path, "is_there_a_new_version_available") { + logger.Info("%s response: %s", formatter(param), blw.body.String()) + } //logger.WithCtx(c.Request.Context()).Info("%s params: %s", formatter(param), bodyStr) //if accessConf.LogResponseEnabled { From c976b01e8ab26ff30a9e0c743907cbe62a204977 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Thu, 16 May 2024 23:33:37 +0800 Subject: [PATCH 2/8] vercmp --- app/mix/controller/config_op.go | 2 +- app/mix/service/configservice.go | 29 +++++++++++++ library/sutil/sutil.go | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 library/sutil/sutil.go diff --git a/app/mix/controller/config_op.go b/app/mix/controller/config_op.go index 01daf725..6ca3a051 100644 --- a/app/mix/controller/config_op.go +++ b/app/mix/controller/config_op.go @@ -45,7 +45,7 @@ func OpGetSupportWxIdList(ctx *gin.Context) { func OpIsThereANewVersionAvailable(ctx *gin.Context) { req := ctx.MustGet("client_req").(*base.BaseRequest) - result, version, ec := service.DefaultConfigService.OpIsThereANewVersionAvailable(ctx, req) + result, version, ec := service.DefaultConfigService.OpIsThereANewVersionAvailableV2(ctx, req) if ec != errcode.ErrCodeOk { logger.Error("OpIsThereANewVersionAvailable fail, ec: %v", ec) ReplyErrCodeMsg(ctx, ec) diff --git a/app/mix/service/configservice.go b/app/mix/service/configservice.go index c2f7974d..415a5a62 100644 --- a/app/mix/service/configservice.go +++ b/app/mix/service/configservice.go @@ -6,8 +6,10 @@ import ( "service/api/consts" "service/api/errcode" "service/apollostruct" + "service/bizcommon/util" "service/library/apollo" "service/library/logger" + "service/library/sutil" "strconv" "strings" @@ -149,6 +151,33 @@ func (s *ConfigService) OpIsThereANewVersionAvailable(ctx *gin.Context, baseRequ return } +func (s *ConfigService) OpIsThereANewVersionAvailableV2(ctx *gin.Context, baseRequest *base.BaseRequest) (result bool, version *apollostruct.Version, ec errcode.ErrCode) { + ec = errcode.ErrCodeOk + result = false + + var key string + if baseRequest.DevType == consts.DevType_Android { + key = consts.AndroidKey + } else if baseRequest.DevType == consts.DevType_Ios { + key = consts.IosKey + } + ver := &apollostruct.Version{} + err := apollo.GetJson(key, ver, apollo.ApolloOpts().SetNamespace("version")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + ec = errcode.ErrCodeApolloReadFail + return + } + logger.Info("apollo_ver, %v", util.ToJson(ver)) + + verCmp := sutil.NewVersionCmp(baseRequest.Version) + if verCmp.Lt(ver.Version) { + result = true + version = ver + } + return +} + func (s *ConfigService) OpGetUploadMediaFailConfigList(ctx *gin.Context) (uploadMediaFailConfigMap map[string]int64, ec errcode.ErrCode) { ec = errcode.ErrCodeOk diff --git a/library/sutil/sutil.go b/library/sutil/sutil.go new file mode 100644 index 00000000..d919d841 --- /dev/null +++ b/library/sutil/sutil.go @@ -0,0 +1,70 @@ +// Copyright 2014 The sutil Author. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sutil + +import ( + "fmt" + "strings" + //"crypto/sha1" +) + +type VersionCmp struct { + ver string +} + +func NewVersionCmp(ver string) *VersionCmp { + v := &VersionCmp{} + + v.ver = v.fmtver(ver) + return v +} + +func (m *VersionCmp) fmtver(ver string) string { + pvs := strings.Split(ver, ".") + + rv := "" + for _, pv := range pvs { + rv += fmt.Sprintf("%020s", pv) + } + + return rv + +} + +func (m *VersionCmp) Min() string { + return m.fmtver("0") +} + +func (m *VersionCmp) Max() string { + return m.fmtver("99999999999999999999") +} + +func (m *VersionCmp) Lt(ver string) bool { + return m.ver < m.fmtver(ver) +} + +func (m *VersionCmp) Lte(ver string) bool { + return m.ver <= m.fmtver(ver) +} + +func (m *VersionCmp) Gt(ver string) bool { + return m.ver > m.fmtver(ver) +} + +func (m *VersionCmp) Gte(ver string) bool { + return m.ver >= m.fmtver(ver) +} + +func (m *VersionCmp) Eq(ver string) bool { + return m.ver == m.fmtver(ver) +} + +func (m *VersionCmp) Ne(ver string) bool { + return m.ver != m.fmtver(ver) +} + +func (m *VersionCmp) GetFormatVersion() string { + return m.ver +} From 61f06ac60ddf0c580133e235a140841ad81d3b00 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Thu, 16 May 2024 23:49:13 +0800 Subject: [PATCH 3/8] fix --- app/mix/controller/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 280caffa..2c9b5d88 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -201,7 +201,7 @@ func Init(r *gin.Engine) { // 是否有新版本 apiVersion := r.Group("/api/version", PrepareToC()) - apiVersion.POST("is_there_a_new_version_available", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpIsThereANewVersionAvailable) + apiVersion.POST("is_there_a_new_version_available", middleware.JSONParamValidator(base.BaseRequest{}), OpIsThereANewVersionAvailable) // 上传媒体失败配置 apiUploadMediaFailConfig := r.Group("/api/upload_media_fail_config", PrepareToC()) From 6a1db908d2390aa88860b71865a56034db06b5e1 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Fri, 17 May 2024 14:08:15 +0800 Subject: [PATCH 4/8] fix --- app/mix/service/logic/vas.go | 3 +++ dbstruct/media.go | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 0a1bc919..02d2b7b4 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -2986,6 +2986,9 @@ func (v *Vas) refundZoneMoment(ctx *gin.Context, order *dbstruct.Order, req *vas return err } + // 减购买人数 + _ = v.store.DecZoneMomentBuyerCnt(ctx, zid, momentId) + return nil } diff --git a/dbstruct/media.go b/dbstruct/media.go index e278a9b0..6b4f5e71 100644 --- a/dbstruct/media.go +++ b/dbstruct/media.go @@ -141,10 +141,10 @@ func NewVideoFromJson(item any) (vid *Video, err error) { err = errors.New("invalid video object with null md5") return } - if vid.Dur == 0 { - err = errors.New("invalid video object with zero dur") - return - } + //if vid.Dur == 0 { + // err = errors.New("invalid video object with zero dur") + // return + //} if vid.Fmt == "" { err = errors.New("invalid video object with null fmt") return From 52e8d60715e1a0043455f3e446cee5788380500c Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 17 May 2024 18:42:03 +0800 Subject: [PATCH 5/8] by Robin at 20240517 --- app/mix/service/utilservice.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 6cdfa407..0c458c1b 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -931,6 +931,10 @@ func (s *Service) utilUnThumbsZoneMoment(ctx *gin.Context, req *zonemomentproto. // 加密未解锁身份的动态 func (s *Service) utilEncryptInaccessibleZoneMoment(vo *zonemomentproto.ApiZoneMomentVO) { + if vo.GetIsCreatingPaidText() == consts.IsCreatingPaidText_Yes { + vo.Text = goproto.String(vo.GetText()[:len(vo.GetText())-len(vo.GetPaidText())]) + vo.PaidText = nil + } if vo.GetMType() == consts.MediaTypeImg { imageIds := vo.MediaComp.GetImageIds() mediaVisibleRange := vo.GetMediaVisibleRange() @@ -944,9 +948,6 @@ func (s *Service) utilEncryptInaccessibleZoneMoment(vo *zonemomentproto.ApiZoneM imageIds = imageIds[:mediaVisibleRange] vo.MediaComp.ImageIds = util.Int64Slice(imageIds) } - if vo.GetIsCreatingPaidText() == consts.IsCreatingPaidText_Yes { - vo.Text = goproto.String(vo.GetText()[:len(vo.GetText())-len(vo.GetPaidText())]) - } } // 填充动态是否解锁 From f0198e6e715e0905988e2a016a320e237d5c04b6 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 17 May 2024 18:57:41 +0800 Subject: [PATCH 6/8] by Robin at 20240517 --- app/mix/dao/mysql_zone.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mix/dao/mysql_zone.go b/app/mix/dao/mysql_zone.go index 0686c5bb..5cda2e4f 100644 --- a/app/mix/dao/mysql_zone.go +++ b/app/mix/dao/mysql_zone.go @@ -521,7 +521,7 @@ func (m *Mysql) GetLastHourZoneProfit(ctx *gin.Context, tx *sqlx.Tx, st, et int6 func (m *Mysql) GetLastHourZoneRefund(ctx *gin.Context, tx *sqlx.Tx, st, et int64) (list []*dbstruct.ZoneProfit, err error) { var sql strings.Builder - sql.WriteString(fmt.Sprintf("t1.uid as mid, t1.oid1 as zid, count(1) as num, sum(t1.pay_amount) as amount from %s t1 join %s t2 on t1.id = t2.order_id", TableOrder, TableVasZoneRefundHis)) + sql.WriteString(fmt.Sprintf("select t1.uid as mid, t1.oid1 as zid, count(1) as num, sum(t1.pay_amount) as amount from %s t1 join %s t2 on t1.id = t2.order_id", TableOrder, TableVasZoneRefundHis)) sql.WriteString(fmt.Sprintf(" where t2.ct >=%d and t2.ct<=%d and t1.ct <%d group by t1.uid, t1.oid1", st, et, st)) list = make([]*dbstruct.ZoneProfit, 0) if tx != nil { From 853d231a9f3ad02c50c62099e21bcf62f45e82a8 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Sat, 18 May 2024 00:12:54 +0800 Subject: [PATCH 7/8] by Robin at 20240518 --- .../proto/daily_statement_zone_info_vo_op.go | 19 +++++++ app/mix/service/service.go | 29 ++++++++++- app/mix/service/utilservice.go | 8 ++- app/mix/service/xxljob_tasks.go | 3 ++ dbstruct/daily_statement_zone_info.go | 51 +++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_vo_op.go diff --git a/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_vo_op.go b/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_vo_op.go new file mode 100644 index 00000000..288cdd85 --- /dev/null +++ b/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_vo_op.go @@ -0,0 +1,19 @@ +package proto + +import ( + streamerproto "service/api/proto/streamer/proto" + "service/dbstruct" +) + +type OpDailyStatementZoneInfoVO struct { + *dbstruct.DailyStatementZoneInfo + StreamerExt *streamerproto.OpListExtVO `json:"streamer_ext"` +} + +func (vo *OpDailyStatementZoneInfoVO) CopyStreamerExt(streamerExt streamerproto.StreamerExtVO) { + if streamerExt != nil { + if apiStreamerExt, ok := streamerExt.(*streamerproto.OpListExtVO); ok { + vo.StreamerExt = apiStreamerExt + } + } +} diff --git a/app/mix/service/service.go b/app/mix/service/service.go index e60c713e..8789e194 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3893,13 +3893,40 @@ func (s *Service) OpZoneUnlockCollaborators(ctx *gin.Context, req *zoneproto.OpZ } // DailyStatementZoneInfo -func (s *Service) OpGetDailyStatementZoneInfoList(ctx *gin.Context, req *daily_statement_zone_info_proto.OpListReq) (list []*dbstruct.DailyStatementZoneInfo, ec errcode.ErrCode) { +func (s *Service) OpGetDailyStatementZoneInfoList(ctx *gin.Context, req *daily_statement_zone_info_proto.OpListReq) (volist []*daily_statement_zone_info_proto.OpDailyStatementZoneInfoVO, ec errcode.ErrCode) { ec = errcode.ErrCodeDailyStatementZoneInfoSrvOk + + volist = make([]*daily_statement_zone_info_proto.OpDailyStatementZoneInfoVO, 0) + list, err := _DefaultDailyStatementZoneInfo.OpList(ctx, req) if err != nil { logger.Error("OpGetDailyStatementZoneInfoList fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeDailyStatementZoneInfoSrvFail return } + + midSet := make(map[int64]*dbstruct.Moment) + mids := make([]int64, 0) + for _, dailyStatementZoneInfo := range list { + mid := dailyStatementZoneInfo.GetMid() + if midSet[mid] == nil { + midSet[mid] = &dbstruct.Moment{} + mids = append(mids, mid) + } + volist = append(volist, &daily_statement_zone_info_proto.OpDailyStatementZoneInfoVO{ + DailyStatementZoneInfo: dailyStatementZoneInfo, + }) + } + + mp, err := s.utilGetStreamerExtMapByMids(ctx, mids, consts.InterfaceType_Op) + if err != nil { + logger.Error("utilGetStreamerExtMapByMids fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeStreamerSrvFail + return + } + for _, vo := range volist { + vo.CopyStreamerExt(mp[vo.DailyStatementZoneInfo.GetMid()]) + } + return } diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 0c458c1b..c2d7e351 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -1977,8 +1977,11 @@ func (s *Service) utilAssembleDailyStatementZoneInfo(zoneprofits, zonerefunds [] zidZrMp[zonerefund.GetZid()] = zonerefund dlystmt := &dbstruct.DailyStatementZoneInfo{ Zid: zonerefund.Zid, + Mid: zonerefund.Mid, RefundAmount: zonerefund.Amount, RefunderAmount: zonerefund.Num, + StartTime: goproto.Int64(st), + EndTime: goproto.Int64(et), } zidDlystmtMp[zonerefund.GetZid()] = dlystmt list = append(list, dlystmt) @@ -1990,7 +1993,10 @@ func (s *Service) utilAssembleDailyStatementZoneInfo(zoneprofits, zonerefunds [] if !ok { //没有相关信息,写入一个 dlystmt = &dbstruct.DailyStatementZoneInfo{ - Zid: zoneprofit.Zid, + Zid: zoneprofit.Zid, + Mid: zoneprofit.Mid, + StartTime: goproto.Int64(st), + EndTime: goproto.Int64(et), } zidDlystmtMp[zoneprofit.GetZid()] = dlystmt list = append(list, dlystmt) diff --git a/app/mix/service/xxljob_tasks.go b/app/mix/service/xxljob_tasks.go index f5d5c017..2dc30724 100644 --- a/app/mix/service/xxljob_tasks.go +++ b/app/mix/service/xxljob_tasks.go @@ -169,6 +169,9 @@ func (s *CronService) CreateDailyStatement(ctx context.Context, param *xxl.RunRe return fmt.Sprintf("_DefaultDailyStatementZoneInfo OpCreateBatch fail : %v", err) } dailyStatementZoneInfos := DefaultService.utilAssembleDailyStatementZoneInfo(zoneprofits, zonerefunds, startTimeStamp, endTimeStamp) + for _, dailyStatementZoneInfo := range dailyStatementZoneInfos { + dailyStatementZoneInfo.Fill() + } err = _DefaultDailyStatementZoneInfo.OpCreateBatch(&gin.Context{}, &daily_statement_zone_infoproto.OpCreateBatchReq{ DailyStatementZoneInfos: dailyStatementZoneInfos, }) diff --git a/dbstruct/daily_statement_zone_info.go b/dbstruct/daily_statement_zone_info.go index fabae2e8..d285accd 100644 --- a/dbstruct/daily_statement_zone_info.go +++ b/dbstruct/daily_statement_zone_info.go @@ -1,7 +1,12 @@ package dbstruct +import ( + goproto "google.golang.org/protobuf/proto" +) + type DailyStatementZoneInfo struct { Id *int64 `json:"id" bson:"_id"` // 每日报表id + Mid *int64 `json:"mid" bson:"mid"` // mid Zid *int64 `json:"zid" bson:"zid"` // 空间id EntrantNum *int64 `json:"entrant_num" bson:"entrant_num"` // 上小时新增空间进入人数(不含退款) TotalAmount *int64 `json:"total_amount" bson:"total_amount"` // 上小时总入账 @@ -17,6 +22,13 @@ type DailyStatementZoneInfo struct { DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 } +func (p *DailyStatementZoneInfo) GetMid() int64 { + if p != nil && p.Mid != nil { + return *p.Mid + } + return 0 +} + func (p *DailyStatementZoneInfo) GetTotalAmount() int64 { if p != nil && p.TotalAmount != nil { return *p.TotalAmount @@ -30,3 +42,42 @@ func (p *DailyStatementZoneInfo) GetEntrantNum() int64 { } return 0 } + +func (p *DailyStatementZoneInfo) Fill() { + if p == nil { + return + } + if p.Mid == nil { + p.Mid = goproto.Int64(0) + } + if p.Zid == nil { + p.Zid = goproto.Int64(0) + } + if p.EntrantNum == nil { + p.EntrantNum = goproto.Int64(0) + } + if p.TotalAmount == nil { + p.TotalAmount = goproto.Int64(0) + } + if p.AdmissionAmount == nil { + p.AdmissionAmount = goproto.Int64(0) + } + if p.ZoneMomentAmount == nil { + p.ZoneMomentAmount = goproto.Int64(0) + } + if p.SuperfanshipAmount == nil { + p.SuperfanshipAmount = goproto.Int64(0) + } + if p.RefundAmount == nil { + p.RefundAmount = goproto.Int64(0) + } + if p.RefunderAmount == nil { + p.RefunderAmount = goproto.Int64(0) + } + if p.StartTime == nil { + p.StartTime = goproto.Int64(0) + } + if p.EndTime == nil { + p.EndTime = goproto.Int64(0) + } +} From 6ff619e386409bcb0d74defd2b766be1d00767aa Mon Sep 17 00:00:00 2001 From: Leufolium Date: Sat, 18 May 2024 00:34:20 +0800 Subject: [PATCH 8/8] 1 --- .../proto/daily_statement_zone_info_op.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_op.go b/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_op.go index 287111ad..f3af8768 100644 --- a/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_op.go +++ b/api/proto/daily_statement_zone_info/proto/daily_statement_zone_info_op.go @@ -57,9 +57,9 @@ type OpListReq struct { } type OpListData struct { - List []*dbstruct.DailyStatementZoneInfo `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*OpDailyStatementZoneInfoVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type OpListResp struct {