by Robin at 20240501

This commit is contained in:
Leufolium 2024-05-01 01:04:50 +08:00
parent 07aff915c0
commit 6158600853
2 changed files with 138 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package proto
import (
"service/api/consts"
"service/bizcommon/util"
"service/library/validator"
)
@ -9,10 +10,42 @@ func (p *OpCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) {
params = make([]*validator.JsonParam, 0)
params = append(params, validator.NewInt64PtrParam("请确认创建动态的所属空间id", p.ZoneMoment.Zid))
params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.ZoneMoment.Status))
params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.ZoneMoment.CType))
params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体类型!", p.ZoneMoment.MType))
params = append(params, validator.NewStringPtrParam("请确认创建动态的文案!", p.Text))
params = append(params, validator.NewStructPtrParam("请确认创建动态的媒体!", p.MediaComp))
switch util.DerefInt64(p.ZoneMoment.CType) {
case consts.ZoneMomentCType_Paid:
params = append(params, validator.NewInt64PtrParam("请确认创建动态的文字可见范围!", p.ZoneMoment.TextVisibleRange))
params = append(params, validator.NewInt64PtrParam("请确认创建动态的价格!", p.ZoneMoment.Price))
switch util.DerefInt64(p.ZoneMoment.MType) {
case consts.MediaTypeImg:
params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体可见范围!", p.ZoneMoment.MediaVisibleRange))
case consts.MediaTypeVideo:
params = append(params, validator.NewInt64PtrParam("请确认创建动态是否要模糊封面!", p.ZoneMoment.IsBlurringCover))
}
}
return
}
func (p *OpUpdateReq) ProvideNotNullValue() (params []*validator.JsonParam) {
params = make([]*validator.JsonParam, 0)
params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.ZoneMoment.CType))
params = append(params, validator.NewInt64PtrParam("请确认创建动态的媒体类型!", p.ZoneMoment.MType))
switch util.DerefInt64(p.ZoneMoment.CType) {
case consts.ZoneMomentCType_Paid:
if p.Text != nil {
params = append(params, validator.NewStringPtrParam("请确认创建动态的文案!", p.Text))
}
if p.MediaComp != nil {
params = append(params, validator.NewStructPtrParam("请确认创建动态的媒体!", p.MediaComp))
}
}
return
}

View File

@ -3255,23 +3255,89 @@ func (s *Service) OpCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpCr
req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建
req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetImageIds())))
} else {
req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Passed) // 视频贴默认已通过
req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.VideoModeration_Created)
req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetVideoIds())))
}
req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建
req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审
_, err := _DefaultZoneMoment.OpCreate(ctx, req)
momentId, err := _DefaultZoneMoment.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 添加审核任务
imageaudittasks := s.CreateZoneMomentImageAudit(ctx, req.ZoneMoment)
textaudittasks := s.CreateZoneMomentTextAudit(ctx, req.ZoneMoment)
videomoderationtasks := s.CreateZoneMomentVideoModeration(ctx, req.ZoneMoment)
imageaudit.AddTasks(imageaudittasks)
textaudit.AddTasks(textaudittasks)
videomoderation.AddTasks(videomoderationtasks)
// 设置价格
if req.ZoneMoment.GetCType() == consts.ZoneMomentCType_Paid {
err = _DefaultVas.UpdateZoneMomentPrice(ctx, &vasproto.UpdateZoneMomentPriceReq{
ZoneMomentPrice: &dbstruct.ZoneMomentPrice{
MomentId: momentId,
Zid: *req.ZoneMoment.Zid,
Mid: *req.ZoneMoment.Mid,
Price: *req.ZoneMoment.Price,
},
})
if err != nil {
logger.Error("UpdateZoneMomentPrice fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
}
return
}
func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneMomentSrvOk
err := _DefaultZoneMoment.OpUpdate(ctx, req)
zonemoment, err := _DefaultZoneMoment.GetById(ctx, req.ZoneMoment.GetId())
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
}
zmStatus := zonemoment.GetStatus()
// 抹消审核信息,回退到初始
isReauditRequired := false
if req.ZoneMoment.MediaComp != nil && req.ZoneMoment.GetMType() == consts.MediaTypeImg {
isReauditRequired = true
req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.ImageAudit_Created) // 创建
req.ZoneMoment.ImageAuditOpinion = goproto.String("") // 信息抹除
req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetImageIds())))
}
if req.ZoneMoment.MediaComp != nil && req.ZoneMoment.GetMType() == consts.MediaTypeVideo {
req.ZoneMoment.ImageAuditStatus = goproto.Int64(consts.VideoModeration_Created) // 创建
req.ZoneMoment.ImageAuditOpinion = goproto.String("") // 信息抹除
req.ZoneMoment.MediaAmount = goproto.Int64(int64(len(req.ZoneMoment.MediaComp.GetVideoIds())))
}
if req.ZoneMoment.Text != nil {
isReauditRequired = true
req.ZoneMoment.TextAuditStatus = goproto.Int64(consts.TextAudit_Created) // 创建
req.ZoneMoment.TextAuditOpinion = goproto.String("") // 信息抹除
}
if isReauditRequired {
req.ZoneMoment.Status = goproto.Int64(consts.ZoneMoment_Auditing) // 正在审核中
req.ZoneMoment.ManuallyReviewStatus = goproto.Int64(consts.ZoneMomentManuallyReview_Waiting) // 等待复审
req.ZoneMoment.ManuallyReviewOpinion = goproto.String("") // 信息抹除
req.ZoneMoment.ManuallyReviewOperator = goproto.Int64(0) // 信息抹除
}
err = _DefaultZoneMoment.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeZoneMomentNotExist
err = nil
@ -3282,6 +3348,27 @@ func (s *Service) OpUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.OpUp
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 回退空间内统计总数,只回退公开的情况
if zmStatus == consts.ZoneMoment_Public && isReauditRequired {
mediaCountInc := len(zonemoment.MediaComp.GetImageIds())
videoCountInc := len(zonemoment.MediaComp.GetVideoIds())
err := _DefaultZone.RecordStatisticsById(ctx, zonemoment.GetZid(), -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)
videomoderationtasks := s.CreateZoneMomentVideoModeration(ctx, req.ZoneMoment)
imageaudit.AddTasks(imageaudittasks)
textaudit.AddTasks(textaudittasks)
videomoderation.AddTasks(videomoderationtasks)
return
}
@ -3328,7 +3415,7 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
Id: goproto.Int64(zid),
LastZoneMomentCt: goproto.Int64(0),
},
}, util.DerefInt64(zone.LastZoneMomentCt))
}, zone.GetLastZoneMomentCt())
if err != nil {
logger.Error("OpUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail
@ -3337,13 +3424,13 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
} else {
//还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨
lastzonemoment := list[0]
if util.DerefInt64(lastzonemoment.Ut) < util.DerefInt64(zonemoment.Ut) {
if lastzonemoment.GetUt() < zonemoment.GetUt() {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{
Id: goproto.Int64(zid),
LastZoneMomentCt: lastzonemoment.Ut,
},
}, util.DerefInt64(zone.LastZoneMomentCt))
}, zone.GetLastZoneMomentCt())
if err != nil {
logger.Error("OpUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail
@ -3352,15 +3439,18 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
}
}
// 回退空间内统计总数
// 回退空间内统计总数,只回退公开的情况
if zonemoment.GetStatus() == consts.ZoneMoment_Public {
mediaCountInc := len(zonemoment.MediaComp.GetImageIds())
videoCountInc := len(zonemoment.MediaComp.GetVideoIds())
err = _DefaultZone.RecordStatisticsById(ctx, util.DerefInt64(zonemoment.Zid), -1, -int64(mediaCountInc), -int64(videoCountInc))
err = _DefaultZone.RecordStatisticsById(ctx, zonemoment.GetZid(), -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
}