删除数据上报逻辑

移除 pub/dataReport、reportser、srv_report、上报定时任务及 eventmod 事件表,
以及注册/登录/点赞/收藏/评论/解锁/订单/上下架等处的上报调用和 reportSdkConfig 配置下发。

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-29 11:42:33 +08:00
co-authored by Claude Opus 5.5
parent 6894ded6c8
commit 717962defb
31 changed files with 9 additions and 1903 deletions
+6 -7
View File
@@ -21,13 +21,12 @@ import (
func Info(ctx *gin.Context) {
configInfo := configser.GetConfigInfo()
resp := &proto.ConfigInfoResp{
NewAddressInfo: configser.GetNewAddress(),
Config: configInfo,
Advitise: configser.GetAdvitise(),
SeoInfo: configser.GetSiteSeoInfo(),
SeoNavInfo: configser.GetNavSeoInfo(),
NavPageList: configser.GetNavPageList(),
ReportSDKConfig: configInfo.ReportSDKConfig,
NewAddressInfo: configser.GetNewAddress(),
Config: configInfo,
Advitise: configser.GetAdvitise(),
SeoInfo: configser.GetSiteSeoInfo(),
SeoNavInfo: configser.GetNavSeoInfo(),
NavPageList: configser.GetNavPageList(),
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
-3
View File
@@ -38,7 +38,6 @@ type ConfigInfo struct {
DHDescription string `json:"dhDescription" bson:"dhDescription"` // 导航SEO描述
DHSiteName string `json:"dhSiteName" bson:"dhSiteName"` // 导航SEO网站名称
ActressBackGround string `json:"actressBackGround" bson:"actressBackGround"` // 女优通用背景图
ReportSDKConfig string `json:"reportSdkConfig"` // 数据上报SDK域名配置
WatermarkImage string `json:"watermarkImage"` // 图片水印文件
CustomerServiceHost string `json:"customerServiceHost"` // 在线客服
ChannelCode string `json:"channelCode"` // 渠道码
@@ -66,8 +65,6 @@ type ConfigInfoResp struct {
SeoNavInfo SeoNavInfo `json:"seoNavInfo"`
// 导航页线路集合
NavPageList []NavPageItem `json:"navPageList"`
// 数据上报SDK域名配置
ReportSDKConfig string `json:"reportSdkConfig"`
}
// SeoNavInfo 导航SEO信息
-3
View File
@@ -107,9 +107,6 @@ type GlobalCfgEx struct {
AppCode string `yaml:"appCode"` // 应用 code
AesKey string `yaml:"aesKey"` // 数据解密KEY
} `yaml:"adCenter"`
DataReport struct {
Url string `yaml:"url"`
} `yaml:"dataReport"`
LsjMediaConf struct {
AppId string `yaml:"appId"`
ApiKey string `yaml:"apiKey"`
-5
View File
@@ -20,7 +20,6 @@ import (
"videoweb/pub/common/log"
"videoweb/pub/common/srvversion"
"videoweb/pub/common/tgbot"
"videoweb/pub/dataReport"
"videoweb/pub/esmanager"
"videoweb/pub/models"
"videoweb/pub/mongos"
@@ -72,10 +71,6 @@ func Run(args []string) {
}
initData()
ipstatsync.StartSync()
dataReport.Init(dataReport.Config{
ApiUrl: appg.Conf.DataReport.Url,
RunMod: appg.Conf.RunMod,
})
initHttpServer()
//tgbot.SendToProgram("启动", "app启动完毕")
-6
View File
@@ -5,7 +5,6 @@ import (
"strings"
"time"
"videoweb/app/appg"
"videoweb/app/service/reportser"
"videoweb/pub/common/enum/consts"
"videoweb/pub/common/log"
"videoweb/pub/common/srvdef"
@@ -211,8 +210,6 @@ func Register(ctx context.Context, guestUserId int64, accountNo, email, password
if serr != nil {
return nil, serr
}
reportser.ReportUserRegister(guest, ua, ip, "username")
reportser.ReportUserLogin(guest, ua, ip, pubdef.LoginTypeAccount)
return toLoginResp(ctx, guest, token, true), nil
}
}
@@ -269,8 +266,6 @@ func Register(ctx context.Context, guestUserId int64, accountNo, email, password
if serr != nil {
return nil, serr
}
reportser.ReportUserRegister(user, ua, ip, "username")
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeAccount)
return toLoginResp(ctx, user, token, false), nil
}
@@ -333,7 +328,6 @@ func Login(ctx context.Context, account, password string, ua useragent.UA, ip, c
bson.M{usermod.FN.User.Id: user.Id},
bson.M{"$set": setDoc},
)
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeAccount)
return toLoginResp(ctx, user, token, true), nil
}
-3
View File
@@ -9,7 +9,6 @@ import (
"videoweb/app/middleware/reptilerecord"
"videoweb/app/middleware/visit"
"videoweb/app/service/configser"
"videoweb/app/service/reportser"
"videoweb/pub/common/log"
"videoweb/pub/common/netutil"
"videoweb/pub/common/srvdef"
@@ -138,9 +137,7 @@ func GuestLogin(ctx context.Context, userId int64, ip string, req *GuestLoginReq
resp.IsNewUser = isNewUser
if isNewUser {
visit.RecordDailyVisit(ctx, user.Id, ua, ip)
reportser.ReportUserRegister(user, ua, ip, "deviceid")
}
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeDevice)
return resp, nil
}
+1 -9
View File
@@ -8,7 +8,6 @@ import (
"unicode/utf8"
"videoweb/app/api/proto"
"videoweb/app/service/configser"
"videoweb/app/service/reportser"
"videoweb/pub/common/enum/redisconst"
"videoweb/pub/common/log"
"videoweb/pub/common/netutil"
@@ -126,15 +125,8 @@ func SendComment(ctx context.Context, userId int64, ip string, req *proto.Commen
log.Error("评论发布后更新短剧热度失败", log.Any("短剧ID", playletId), log.Any("评论信息", info), log.E(err))
return err
}
chapterId := int64(0)
if req.ObjectType == ObjectTypePlayletChapter {
chapterId = req.ObjectId
}
reportser.ReportPlayletComment(ctx, user, playletId, chapterId, text)
} else if req.ObjectType == ObjectTypeVideo {
reportser.ReportVideoComment(ctx, user, req.ObjectId, text)
}
// app端发布评论先进入待审核状态,不立即增加业务对象评论数;后台审核通过时再统一同步 countComment
// app端发布评论先进入待审核状态,不立即增加短剧/剧集评论数;后台审核通过时再统一同步 countComment。
return nil
}
-4
View File
@@ -11,7 +11,6 @@ import (
"videoweb/pub/common/log"
"videoweb/pub/common/netutil"
"videoweb/pub/common/srvdef"
"videoweb/pub/dataReport"
"videoweb/pub/models/announcementmod"
"videoweb/pub/models/cfg"
"videoweb/pub/models/ipblackmod"
@@ -59,7 +58,6 @@ func init() {
func Start() {
ctx := context.Background()
dataReport.StartSDKConfigCron()
UpdateConfigInfo(ctx)
UpdateAdvitiseData(ctx)
updateIpBlack()
@@ -153,7 +151,6 @@ func UpdateConfigInfo(ctx context.Context) {
config.DHSiteName = sysCfg.DHSiteName
config.DHTitle = sysCfg.DHTitle
config.ActressBackGround = netutil.MergeURL(sysCfg.ImgAppCdn, sysCfg.ActressBackGround)
config.ReportSDKConfig = dataReport.GetSDKDomainConfig()
config.WatermarkImage = sysCfg.WatermarkImage
config.CustomerServiceHost = sysCfg.CustomerServiceHost
config.ChannelCode = sysCfg.ChannelCode
@@ -560,7 +557,6 @@ func GetVideoTagCategoryDataList() []proto.VideoTagCategoryData {
return rsl
}
func Stop() {
dataReport.StopSDKConfigCron()
skdCron.Stop()
}
-14
View File
@@ -11,7 +11,6 @@ import (
"videoweb/app/api/proto"
"videoweb/app/service/configser"
"videoweb/app/service/playletcache"
"videoweb/app/service/reportser"
"videoweb/app/service/videoser"
"videoweb/pub/common/enum/redisconst"
"videoweb/pub/common/log"
@@ -914,9 +913,6 @@ func SetLike(ctx context.Context, userId int64, req *proto.PlayletLikeSetReq) (*
IsLike: operateStatusByFlag(*req.IsLike),
CountLike: countLike,
}
if changed {
reportser.ReportPlayletLike(ctx, userId, req.Id, resp.IsLike)
}
return resp, nil
}
@@ -936,9 +932,6 @@ func SetCollect(ctx context.Context, userId int64, req *proto.PlayletCollectSetR
IsCollect: operateStatusByFlag(*req.IsCollect),
CountCollect: countCollect,
}
if changed {
reportser.ReportPlayletCollect(ctx, userId, req.Id, resp.IsCollect)
}
return resp, nil
}
@@ -988,9 +981,6 @@ func SetChapterLike(ctx context.Context, userId int64, req *proto.PlayletChapter
IsLike: operateStatusByFlag(*req.IsLike),
CountLike: countLike,
}
if changed {
reportser.ReportPlayletChapterLike(ctx, userId, chapter.PlayletId, req.ChapterId, resp.IsLike)
}
return resp, nil
}
@@ -1010,9 +1000,6 @@ func SetChapterCollect(ctx context.Context, userId int64, req *proto.PlayletChap
IsCollect: operateStatusByFlag(*req.IsCollect),
CountCollect: countCollect,
}
if changed {
reportser.ReportPlayletChapterCollect(ctx, userId, chapter.PlayletId, req.ChapterId, resp.IsCollect)
}
return resp, nil
}
@@ -1274,7 +1261,6 @@ func UnlockChapter(ctx context.Context, userId int64, req *proto.PlayletChapterU
return nil, srvdef.New(srvdef.DBTransaction, "解锁失败,请稍后重试", "解锁失败,请稍后重试")
}
updatePlayletChapterUnlockStatsAsync(chapter.PlayletId, chapter.Id)
reportser.ReportPlayletUnlock(ctx, user, playlet, chapter, chapter.SingleCoins, user.Recharge, balanceAfter, orderNo)
return playletChapterUnlockResp(chapter, balanceAfter, -chapter.SingleCoins), nil
}
-52
View File
@@ -2,19 +2,11 @@ package rechargeser
import (
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"videoweb/app/service/rechargeser/jiahua"
"videoweb/pub/common/log"
"videoweb/pub/common/srvdef"
"videoweb/pub/common/useragent"
"videoweb/pub/dataReport"
"videoweb/pub/models/eventmod"
"videoweb/pub/models/rechargepackagemod"
"videoweb/pub/models/usermod"
"videoweb/pub/models/vipordermod"
@@ -104,8 +96,6 @@ func CreateOrder(ctx context.Context,
return nil, serr
}
go reportOrderCreated(ctx, order, pkg, userId, ip)
return &SubmitOrderResp{
TradeNo: tradeNo,
PayUrl: payInfo.PayUrl,
@@ -138,45 +128,3 @@ func GetOrderHistory(ctx context.Context, userId int64, page, pageSize int64) (v
func GetUserInfo(ctx context.Context, userId int64) (*usermod.User, *srvdef.SrvErr) {
return usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
}
func reportOrderCreated(ctx context.Context, order *vipordermod.VipOrder, pkg *rechargepackagemod.RechargePackage, userId int64, ip string) {
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
districtCode := ""
if user != nil {
districtCode = user.DistrictCode
}
ua := useragent.UA{SysType: order.SysType}
eventId := newEventId(pubdef.TrackerAppId(), user.Id, order.TradeNo, order.CreatedAt.Unix())
commonField := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderCreated, districtCode, ua, strconv.FormatInt(user.Id, 10), ip)
commonField.Payload = dataReport.JsonRawMessage(&dataReport.OrderCreatedEvent{
OrderID: order.TradeNo,
OrderType: "vip_subscription",
ProductID: strconv.FormatInt(pkg.Id, 10),
ProductName: pkg.Name,
Amount: dataReport.JsonNumber(order.Amount),
Currency: "CNY",
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
})
eventData, _ := json.Marshal(commonField)
if err := eventmod.InsertOneEvent(ctx, &eventmod.Event{
EventId: commonField.EventID,
EventType: commonField.Event,
Data: string(eventData),
Status: eventmod.Default,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}); err != nil {
log.Error("reportOrderCreated InsertOneEvent failed",
log.Any("tradeNo", order.TradeNo), log.E(err))
}
}
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
h := md5.New()
h.Write([]byte(input))
return hex.EncodeToString(h.Sum(nil))
}
-530
View File
@@ -1,530 +0,0 @@
package reportser
import (
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"videoweb/app/service/playletcache"
"videoweb/pub/common"
"videoweb/pub/common/enum/consts"
"videoweb/pub/common/ipaddr"
"videoweb/pub/common/log"
"videoweb/pub/common/useragent"
"videoweb/pub/dataReport"
"videoweb/pub/models/eventmod"
"videoweb/pub/models/playletchaptermod"
"videoweb/pub/models/playletmod"
"videoweb/pub/models/usermod"
"videoweb/pub/models/videoinformationmod"
"videoweb/pub/pubdef"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
const (
videoContentTypeVideo = "video"
)
// ReportUserRegister 用户注册事件
func ReportUserRegister(user *usermod.User, ua useragent.UA, ip, registerType string) {
if user == nil {
return
}
if registerType == "" {
registerType = "deviceid"
}
ua = fillUserUA(user, ua)
createAt := user.CreatedAt
if !user.RegisterTime.IsZero() {
createAt = user.RegisterTime
}
eventId := newEventId(pubdef.TrackerAppId(), user.Id, "", createAt.Unix())
event := dataReport.NewCommonField(eventId, dataReport.EventTypeUserRegister, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
event.Payload = dataReport.JsonRawMessage(&dataReport.UserRegisterEvent{
Type: registerType,
CreateTime: dataReport.JsonNumber(createAt.Unix()),
})
insertEvent(event)
}
// ReportUserLogin 用户登录事件
func ReportUserLogin(user *usermod.User, ua useragent.UA, ip string, loginType pubdef.LoginType) {
if user == nil {
return
}
ua = fillUserUA(user, ua)
createTime := time.Now().Unix()
eventId := newEventId(pubdef.TrackerAppId(), user.Id, "", createTime)
event := dataReport.NewCommonField(eventId, dataReport.EventTypeUserLogin, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
event.Payload = dataReport.JsonRawMessage(&dataReport.UserLoginEvent{
Type: loginTypeEventValue(loginType),
})
insertEvent(event)
}
// ReportPlayletLike 短剧点赞
func ReportPlayletLike(ctx context.Context, userId, playletId, flag int64) {
reportDramaEvent(ctx, userId, playletId, 0, dataReport.EventTypeDramaLike, flag, "")
}
// ReportVideoLike 视频点赞
func ReportVideoLike(ctx context.Context, userId, videoId, flag int64) {
reportVideoEvent(ctx, userId, videoId, dataReport.EventTypeVideoLike, flag)
}
// ReportPlayletCollect 短剧收藏
func ReportPlayletCollect(ctx context.Context, userId, playletId, flag int64) {
reportDramaEvent(ctx, userId, playletId, 0, dataReport.EventTypeDramaCollect, flag, "")
}
// ReportVideoCollect 视频收藏
func ReportVideoCollect(ctx context.Context, userId, videoId, flag int64) {
reportVideoEvent(ctx, userId, videoId, dataReport.EventTypeVideoCollect, flag)
}
// ReportVideoComment 视频评论
func ReportVideoComment(ctx context.Context, user *usermod.User, videoId int64, content string) {
if user == nil || videoId <= 0 {
return
}
pub := buildVideoPub(ctx, videoId)
if pub.VideoID == "" {
return
}
ua, ip := uaAndIPFromCtx(ctx)
ua = fillUserUA(user, ua)
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeVideoComment, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCommentEvent{
VideoEventPub: pub,
CommentContent: content,
})
insertEvent(event)
}
// ReportPlayletChapterLike 短剧剧集点赞
func ReportPlayletChapterLike(ctx context.Context, userId, playletId, chapterId, flag int64) {
reportDramaEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeDramaLike, flag, "")
}
// ReportPlayletChapterCollect 短剧剧集收藏
func ReportPlayletChapterCollect(ctx context.Context, userId, playletId, chapterId, flag int64) {
reportDramaEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeDramaCollect, flag, "")
}
// ReportPlayletComment 短剧/剧集评论
func ReportPlayletComment(ctx context.Context, user *usermod.User, playletId, chapterId int64, content string) {
if user == nil || playletId <= 0 {
return
}
pub := buildDramaPub(ctx, playletId, chapterId)
if pub.DramaID == "" {
return
}
ua, ip := uaAndIPFromCtx(ctx)
ua = fillUserUA(user, ua)
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeDramaComment, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCommentEvent{
DramaEventPub: pub,
CommentContent: content,
})
insertEvent(event)
}
// ReportPlayletUnlock 短剧剧集金币解锁:同时上报金币消耗和购买
func ReportPlayletUnlock(ctx context.Context, user *usermod.User, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount, balanceBefore, balanceAfter int64, orderNo string) {
if user == nil || playlet == nil || chapter == nil || amount <= 0 {
return
}
if full, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}); err == nil && full != nil {
user = full
}
ua, ip := uaAndIPFromCtx(ctx)
ua = fillUserUA(user, ua)
productId := strconv.FormatInt(chapter.Id, 10)
productName := playletUnlockProductName(playlet, chapter)
reportCoinConsume(user, ua, ip, productId, productName, amount, balanceBefore, balanceAfter, KeyPlayletUnlock, orderNo)
reportDramaPurchase(user, ua, ip, playlet, chapter, amount, orderNo)
}
// ReportPlayletStatusChange 短剧上下架,复用 video_status_change
func ReportPlayletStatusChange(playlet *playletmod.Playlet, flag int64) {
if playlet == nil || playlet.Id == 0 || flag == 0 {
return
}
typeID, typeName := resolvePlayletType(playlet)
event := dataReport.NewCommonField("", dataReport.EventTypeVideoStatusChange, "", useragent.UA{}, "", "")
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoStatusChangeEvent{
MediaId: playletMediaId(playlet),
VideoID: strconv.FormatInt(playlet.Id, 10),
VideoTitle: playlet.Title,
VideoTypeID: typeID,
VideoTypeName: typeName,
Flag: dataReport.JsonNumber(flag),
})
insertEvent(event)
}
// PlayletStatusFlag 短剧上下架映射上报 flag:1上架 2下架
func PlayletStatusFlag(status playletmod.Status) int64 {
switch status {
case playletmod.StatusUp:
return 1
case playletmod.StatusDown:
return 2
default:
return 0
}
}
func reportDramaEvent(ctx context.Context, userId, playletId, chapterId int64, eventType string, flag int64, content string) {
if userId <= 0 || playletId <= 0 {
return
}
user, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
if err != nil || user == nil {
return
}
pub := buildDramaPub(ctx, playletId, chapterId)
if pub.DramaID == "" {
return
}
ua, ip := uaAndIPFromCtx(ctx)
ua = fillUserUA(user, ua)
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), eventType, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
switch eventType {
case dataReport.EventTypeDramaLike:
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaLikeEvent{
DramaEventPub: pub,
Flag: dataReport.JsonNumber(flag),
})
case dataReport.EventTypeDramaCollect:
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCollectEvent{
DramaEventPub: pub,
Flag: dataReport.JsonNumber(flag),
})
case dataReport.EventTypeDramaComment:
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCommentEvent{
DramaEventPub: pub,
CommentContent: content,
})
default:
return
}
insertEvent(event)
}
func reportVideoEvent(ctx context.Context, userId, videoId int64, eventType string, flag int64) {
if userId <= 0 || videoId <= 0 {
return
}
user, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
if err != nil || user == nil {
return
}
pub := buildVideoPub(ctx, videoId)
if pub.VideoID == "" {
return
}
ua, ip := uaAndIPFromCtx(ctx)
ua = fillUserUA(user, ua)
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), eventType, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
switch eventType {
case dataReport.EventTypeVideoLike:
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoLikeEvent{
VideoEventPub: pub,
Flag: dataReport.JsonNumber(flag),
})
case dataReport.EventTypeVideoCollect:
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCollectEvent{
VideoEventPub: pub,
Flag: dataReport.JsonNumber(flag),
})
default:
return
}
insertEvent(event)
}
func reportCoinConsume(user *usermod.User, ua useragent.UA, ip, productId, productName string, amount, balanceBefore, balanceAfter int64, reason Key, orderId string) {
if user == nil || amount == 0 {
return
}
if productId == "" {
if productName == "" {
productName = "金币消耗"
}
productId = md5String(productName)
}
createTime := time.Now().Unix()
eventId := newEventId(pubdef.TrackerAppId(), user.Id, orderId, createTime)
event := dataReport.NewCommonField(eventId, dataReport.EventTypeCoinConsume, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
event.Payload = dataReport.JsonRawMessage(&dataReport.CoinConsumeEvent{
ProductID: productId,
ProductName: productName,
CoinConsumeAmount: dataReport.JsonNumber(amount),
CoinBalanceBefore: dataReport.JsonNumber(balanceBefore),
CoinBalanceAfter: dataReport.JsonNumber(balanceAfter),
ConsumeReasonKey: reason.Key(),
ConsumeReasonName: reason.Name(),
CreateTime: dataReport.JsonNumber(createTime),
OrderId: orderId,
})
insertEvent(event)
}
func reportDramaPurchase(user *usermod.User, ua useragent.UA, ip string, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount int64, orderId string) {
pub := playletToDramaPub(playlet, chapter)
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeDramaPurchase, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaPurchaseEvent{
DramaEventPub: pub,
CoinQuantity: dataReport.JsonNumber(amount),
OrderID: orderId,
UnlockType: dataReport.DramaUnlockTypeCoin,
})
insertEvent(event)
}
func buildDramaPub(ctx context.Context, playletId, chapterId int64) dataReport.DramaEventPub {
playlet, err := playletmod.FindOnePlaylet(ctx, bson.M{playletmod.FN.Playlet.Id: playletId}, options.FindOne().SetProjection(bson.D{
{Key: playletmod.FN.Playlet.Id, Value: 1},
{Key: playletmod.FN.Playlet.Title, Value: 1},
{Key: playletmod.FN.Playlet.ThemeIds, Value: 1},
{Key: playletmod.FN.Playlet.TagIds, Value: 1},
{Key: playletmod.FN.Playlet.TotalEpisode, Value: 1},
}))
if err != nil || playlet == nil {
return dataReport.DramaEventPub{}
}
var chapter *playletchaptermod.PlayletChapter
if chapterId > 0 {
chapter, _ = playletchaptermod.FindOnePlayletChapter(ctx, bson.M{playletchaptermod.FN.PlayletChapter.Id: chapterId}, options.FindOne().SetProjection(bson.D{
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
{Key: playletchaptermod.FN.PlayletChapter.PlayletId, Value: 1},
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
{Key: playletchaptermod.FN.PlayletChapter.MediaTime, Value: 1},
}))
}
return playletToDramaPub(playlet, chapter)
}
func buildVideoPub(ctx context.Context, videoId int64) dataReport.VideoEventPub {
video, err := videoinformationmod.FindOneVideoInformationWithOptions(ctx, bson.M{videoinformationmod.FN.VideoInformation.Id: videoId}, options.FindOne().SetProjection(bson.D{
{Key: videoinformationmod.FN.VideoInformation.Id, Value: 1},
{Key: videoinformationmod.FN.VideoInformation.Title, Value: 1},
{Key: videoinformationmod.FN.VideoInformation.MediaType, Value: 1},
{Key: videoinformationmod.FN.VideoInformation.Video.FileId, Value: 1},
{Key: videoinformationmod.FN.VideoInformation.Video.TaskId, Value: 1},
{Key: videoinformationmod.FN.VideoInformation.SyncId, Value: 1},
}))
if err != nil || video == nil {
return dataReport.VideoEventPub{}
}
return videoToVideoPub(video)
}
func videoToVideoPub(video *videoinformationmod.VideoInformation) dataReport.VideoEventPub {
if video == nil {
return dataReport.VideoEventPub{}
}
mediaId := video.Video.FileId
if mediaId == "" {
mediaId = video.Video.TaskId
}
if mediaId == "" {
mediaId = video.SyncId
}
return dataReport.VideoEventPub{
MediaId: mediaId,
VideoID: strconv.FormatInt(video.Id, 10),
VideoTitle: video.Title,
VideoTypeID: strconv.FormatInt(int64(video.MediaType), 10),
VideoTypeName: videoMediaTypeName(video.MediaType),
VideoContentType: videoContentTypeVideo,
}
}
func playletToDramaPub(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) dataReport.DramaEventPub {
if playlet == nil {
return dataReport.DramaEventPub{}
}
typeID, typeName := resolvePlayletType(playlet)
tagKey, tagName := resolvePlayletTags(playlet.TagIds)
episode := int64(1)
duration := int64(0)
if chapter != nil && chapter.Id > 0 {
if chapter.CurrentEpisode > 0 {
episode = chapter.CurrentEpisode
}
duration = chapter.MediaTime
}
return dataReport.DramaEventPub{
DramaID: strconv.FormatInt(playlet.Id, 10),
DramaTitle: playlet.Title,
Episode: dataReport.JsonNumber(episode),
TotalEpisode: dataReport.JsonNumber(playlet.TotalEpisode),
DramaTypeID: typeID,
DramaTypeName: typeName,
DramaContentType: dataReport.DramaContentTypeShortDrama,
DramaTagKey: tagKey,
DramaTagName: tagName,
DramaDuration: dataReport.JsonNumber(duration),
}
}
func videoMediaTypeName(mediaType videoinformationmod.MediaType) string {
switch mediaType {
case videoinformationmod.MediaType_Video:
return "视频"
case videoinformationmod.MediaType_Collection:
return "合集"
case videoinformationmod.MediaType_Advitise:
return "广告"
case videoinformationmod.MediaType_VideoV2:
return "视频"
default:
return "视频"
}
}
func playletUnlockProductName(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) string {
title := ""
if playlet != nil {
title = playlet.Title
}
if chapter == nil {
return title
}
if chapter.Title != "" {
if title == "" {
return chapter.Title
}
return fmt.Sprintf("%s %s", title, chapter.Title)
}
if chapter.CurrentEpisode > 0 {
if title == "" {
return fmt.Sprintf("第%d集", chapter.CurrentEpisode)
}
return fmt.Sprintf("%s 第%d集", title, chapter.CurrentEpisode)
}
return title
}
func playletMediaId(playlet *playletmod.Playlet) string {
if playlet == nil || playlet.MediaCenterId == 0 {
return ""
}
return strconv.FormatUint(uint64(playlet.MediaCenterId), 10)
}
func resolvePlayletType(playlet *playletmod.Playlet) (string, string) {
if playlet == nil || len(playlet.ThemeIds) == 0 {
return "default", "默认分类"
}
id := playlet.ThemeIds[0]
if id <= 0 {
return "default", "默认分类"
}
name := strings.TrimSpace(playletcache.ThemeNameMap([]int64{id})[id])
if name == "" {
name = "默认分类"
}
return strconv.FormatInt(id, 10), name
}
func resolvePlayletTags(ids []int64) (string, string) {
keys := make([]string, 0, len(ids))
for _, id := range ids {
if id > 0 {
keys = append(keys, strconv.FormatInt(id, 10))
}
}
if len(keys) == 0 {
return "default", "默认标签"
}
nameMap := playletcache.TagNameMap(ids)
names := make([]string, 0, len(keys))
for _, id := range ids {
if id <= 0 {
continue
}
name := strings.TrimSpace(nameMap[id])
if name == "" {
name = strconv.FormatInt(id, 10)
}
names = append(names, name)
}
return strings.Join(keys, ","), strings.Join(names, ",")
}
func uaAndIPFromCtx(ctx context.Context) (useragent.UA, string) {
gc, ok := ctx.(*gin.Context)
if !ok {
if v := ctx.Value(consts.CtxUA); v != nil {
if ua, ok := v.(useragent.UA); ok {
return ua, ""
}
}
return useragent.UA{}, ""
}
ua, _ := common.GetUA(gc)
return ua, ipaddr.ResolveClientIP(gc)
}
func fillUserUA(user *usermod.User, ua useragent.UA) useragent.UA {
if user == nil {
return ua
}
if ua.DevID == "" {
ua.DevID = user.DevID
}
if ua.DevType == "" {
ua.DevType = user.Device
}
if ua.SysType == "" {
ua.SysType = user.SysType
}
return ua
}
func loginTypeEventValue(loginType pubdef.LoginType) string {
switch loginType {
case pubdef.LoginTypeAccount:
return "username"
case pubdef.LoginTypeEmail:
return "email"
default:
return "deviceid"
}
}
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
return md5String(input)
}
func md5String(input string) string {
h := md5.New()
h.Write([]byte(input))
return hex.EncodeToString(h.Sum(nil))
}
func insertEvent(event dataReport.CommonField) {
b, _ := json.Marshal(event)
if err := eventmod.InsertOneEvent(context.Background(), &eventmod.Event{
EventId: event.EventID,
EventType: event.Event,
Data: string(b),
Status: eventmod.Default,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}); err != nil {
log.Error("reportser insertEvent failed", log.Any("eventType", event.Event), log.Any("eventId", event.EventID), log.E(err))
}
}
-21
View File
@@ -1,21 +0,0 @@
package reportser
type Key string
const (
KeyPlayletUnlock Key = "playlet_unlock" // 短剧剧集解锁
KeyCoinConsume Key = "coin_consume" // 金币消耗
)
var keyMap = map[Key]string{
KeyPlayletUnlock: "短剧解锁",
KeyCoinConsume: "金币消耗",
}
func (p Key) Name() string {
return keyMap[p]
}
func (p Key) Key() string {
return string(p)
}
+2 -7
View File
@@ -6,7 +6,6 @@ import (
"strings"
"videoweb/app/api/proto"
"videoweb/app/service/configser"
"videoweb/app/service/reportser"
"videoweb/pub/common/log"
"videoweb/pub/common/netutil"
"videoweb/pub/common/srvdef"
@@ -255,9 +254,7 @@ func SetLike(ctx context.Context, userId int64, req *proto.VideoLikeSetReq) (*pr
IsLike: videoOperateStatusByFlag(*req.IsLike),
CountLike: countLike,
}
if changed {
reportser.ReportVideoLike(ctx, userId, req.Id, resp.IsLike)
}
_ = changed
return resp, nil
}
@@ -277,9 +274,7 @@ func SetCollect(ctx context.Context, userId int64, req *proto.VideoCollectSetReq
IsCollect: videoOperateStatusByFlag(*req.IsCollect),
CountCollect: countCollect,
}
if changed {
reportser.ReportVideoCollect(ctx, userId, req.Id, resp.IsCollect)
}
_ = changed
return resp, nil
}