by Robin at 20240411

This commit is contained in:
Leufolium 2024-04-11 17:58:33 +08:00
parent 0dd9eb1360
commit 31903d0ed0
5 changed files with 82 additions and 1 deletions

View File

@ -3935,6 +3935,19 @@ func (m *Mongo) GetZoneById(ctx *gin.Context, id int64) (*dbstruct.Zone, error)
return zone, err
}
func (m *Mongo) RecordZoneStatisticsById(ctx *gin.Context, id int64, zoneMomentCount int64, imageCount int64, videoCount int64) error {
col := m.getColZone()
up := qmgo.M{
"$inc": qmgo.M{
"zone_moment_count": zoneMomentCount,
"image_count": imageCount,
"video_count": videoCount,
},
}
err := col.UpdateId(ctx, id, up)
return err
}
// 私密圈动态相关
func (m *Mongo) CreateZoneMoment(ctx *gin.Context, zonemoment *dbstruct.ZoneMoment) error {
col := m.getColZoneMoment()

View File

@ -2272,6 +2272,17 @@ func (s *Service) ApiCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
func (s *Service) ApiUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneMomentSrvOk
zonemoment, err := _DefaultZoneMoment.GetById(ctx, util.DerefInt64(req.Id))
if err != nil {
logger.Error("_DefaultZoneMoment GetById fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
if zonemoment == nil {
ec = errcode.ErrCodeZoneMomentNotExist
return
}
// 抹消审核信息,回退到初始
isReauditRequired := false
if req.ZoneMoment.MediaComp != nil && util.DerefInt64(req.ZoneMoment.MType) == consts.MediaTypeImg {
@ -2292,7 +2303,7 @@ func (s *Service) ApiUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
req.ZoneMoment.ManuallyReviewOperator = goproto.Int64(0) // 信息抹除
}
err := _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
err = _DefaultZoneMoment.OpUpdate(ctx, &zonemomentproto.OpUpdateReq{
BaseRequest: req.BaseRequest,
ZoneMoment: req.ZoneMoment,
})
@ -2307,6 +2318,19 @@ func (s *Service) ApiUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
return
}
// 回退空间内统计总数
if isReauditRequired {
id := util.DerefInt64(req.ZoneMoment.Id)
mediaCountInc := len(zonemoment.MediaComp.GetImageIds())
videoCountInc := len(zonemoment.MediaComp.GetVideoIds())
err := _DefaultZone.RecordStatisticsById(ctx, id, -1, -int64(mediaCountInc), -int64(videoCountInc))
if err != nil {
logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneSrvFail
return
}
}
// 添加审核任务
imageaudittasks := s.CreateZoneMomentImageAudit(ctx, req.ZoneMoment)
textaudittasks := s.CreateZoneMomentTextAudit(ctx, req.ZoneMoment)

View File

@ -108,6 +108,15 @@ func (p *Zone) OpUpdateByIdAndLastZoneMomentCt(ctx *gin.Context, req *zoneproto.
return nil
}
func (p *Zone) RecordStatisticsById(ctx *gin.Context, id int64, zoneMomentCount int64, imageCount int64, videoCount int64) error {
err := p.store.RecordZoneStatisticsById(ctx, id, zoneMomentCount, imageCount, videoCount)
if err != nil {
logger.Error("RecordZoneStatisticsById fail, err: %v", err)
return err
}
return err
}
func (p *Zone) GetById(ctx *gin.Context, id int64) (*dbstruct.Zone, error) {
zone, err := p.store.GetZoneById(ctx, id)
if err != nil {

View File

@ -3292,6 +3292,16 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
}
}
// 回退空间内统计总数
id := util.DerefInt64(req.Id)
mediaCountInc := len(zonemoment.MediaComp.GetImageIds())
videoCountInc := len(zonemoment.MediaComp.GetVideoIds())
err = _DefaultZone.RecordStatisticsById(ctx, id, -1, -int64(mediaCountInc), -int64(videoCountInc))
if err != nil {
logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneSrvFail
return
}
return
}
@ -3360,6 +3370,28 @@ func (s *Service) OpReviewZoneMoment(ctx *gin.Context, req *zonemomentproto.OpRe
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 增加空间内统计总数
for _, id := range req.ZoneMomentIds {
zonemoment, err := _DefaultZoneMoment.GetById(ctx, id)
if err != nil {
logger.Error("_DefaultZoneMoment GetById fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
if zonemoment == nil {
ec = errcode.ErrCodeZoneMomentNotExist
return
}
mediaCountInc := len(zonemoment.MediaComp.GetImageIds())
videoCountInc := len(zonemoment.MediaComp.GetVideoIds())
err = _DefaultZone.RecordStatisticsById(ctx, id, 1, int64(mediaCountInc), int64(videoCountInc))
if err != nil {
logger.Error("RecordStatisticsById fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneSrvFail
return
}
}
}
return

View File

@ -5,6 +5,9 @@ type Zone struct {
Mid *int64 `json:"mid" bson:"mid"` // 用户表id
Profile *string `json:"profile" bson:"profile"` // 空间简介
LastZoneMomentCt *int64 `json:"last_zone_moment_ct" bson:"last_zone_moment_ct"` // 最后空间动态创建时间
ZoneMomentCount *int64 `json:"zone_moment_count" bson:"zone_moment_count"` // 空间内动态总数
ImageCount *int64 `json:"image_count" bson:"image_count"` // 空间内图片总数
VideoCount *int64 `json:"video_count" bson:"video_count"` // 空间内视频总数
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记