Updata:解决冲突
This commit is contained in:
commit
eda7b21dcc
124
pkg/cron/task.go
124
pkg/cron/task.go
@ -5,12 +5,16 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fonchain-fiee/api/bundle"
|
||||||
"fonchain-fiee/api/cast"
|
"fonchain-fiee/api/cast"
|
||||||
"fonchain-fiee/pkg/cache"
|
"fonchain-fiee/pkg/cache"
|
||||||
|
bundleModel "fonchain-fiee/pkg/model/bundle"
|
||||||
modelCast "fonchain-fiee/pkg/model/cast"
|
modelCast "fonchain-fiee/pkg/model/cast"
|
||||||
"fonchain-fiee/pkg/service"
|
"fonchain-fiee/pkg/service"
|
||||||
serverCast "fonchain-fiee/pkg/service/cast"
|
serverCast "fonchain-fiee/pkg/service/cast"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis"
|
||||||
@ -34,6 +38,9 @@ func InitTasks() error {
|
|||||||
// 启动队列消费者
|
// 启动队列消费者
|
||||||
go WorkPublishQueueConsumer()
|
go WorkPublishQueueConsumer()
|
||||||
|
|
||||||
|
// 启动随机间隔的自动确认任务
|
||||||
|
go AutoManuallyConfirmWorkTaskWithRandomInterval()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +76,123 @@ func RefreshWorkAnalysisApprovalStatusTask() {
|
|||||||
serverCast.RefreshWorkAnalysisApproval(nil, resp.Data)
|
serverCast.RefreshWorkAnalysisApproval(nil, resp.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutoManuallyConfirmWorkTaskWithRandomInterval 以随机间隔(3-7分钟)执行自动确认任务
|
||||||
|
func AutoManuallyConfirmWorkTaskWithRandomInterval() {
|
||||||
|
|
||||||
|
for {
|
||||||
|
// 执行任务
|
||||||
|
AutoManuallyConfirmWorkTask()
|
||||||
|
|
||||||
|
// 生成3-7分钟之间的随机间隔(单位:分钟)
|
||||||
|
randomMinutes := rand.Intn(5) + 3 // 3-7分钟
|
||||||
|
randomDuration := time.Duration(randomMinutes) * time.Minute
|
||||||
|
|
||||||
|
// 等待随机时间
|
||||||
|
time.Sleep(randomDuration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func AutoManuallyConfirmWorkTask() {
|
||||||
|
var req bundle.GetWaitConfirmWorkListReq
|
||||||
|
res, err := service.BundleProvider.GetWaitConfirmWorkList(context.Background(), &req)
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("获取待确认作品列表失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if res.Data == nil || len(res.Data) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, work := range res.Data {
|
||||||
|
var req bundleModel.UserWorkConfirmReq
|
||||||
|
req.WorkUuid = work.WorkUuid
|
||||||
|
req.ConfirmStatus = 1
|
||||||
|
artistId, err := strconv.ParseInt(work.ArtistUuid, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("解析艺术家ID失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.ConfirmStatus == 2 { // 驳回完直接结束
|
||||||
|
_, err := service.CastProvider.UpdateStatus(context.Background(), &cast.UpdateStatusReq{
|
||||||
|
WorkAction: cast.WorkActionENUM_CONFIRM,
|
||||||
|
WorkUuid: req.WorkUuid,
|
||||||
|
ConfirmRemark: req.ConfirmRemark,
|
||||||
|
ConfirmStatus: 2,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("确认作品失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
balanceInfoRes, err := service.BundleProvider.GetBundleBalanceByUserId(context.Background(), &bundle.GetBundleBalanceByUserIdReq{
|
||||||
|
UserId: int32(artistId),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
wordInfoRes, err := service.CastProvider.WorkDetail(context.Background(), &cast.WorkDetailReq{
|
||||||
|
WorkUuid: req.WorkUuid,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if wordInfoRes.WorkStatus != 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var workCategory = wordInfoRes.WorkCategory
|
||||||
|
|
||||||
|
var addBalanceReq bundle.AddBundleBalanceReq
|
||||||
|
addBalanceReq.UserId = int32(artistId)
|
||||||
|
switch workCategory {
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if balanceInfoRes.ImageConsumptionNumber >= balanceInfoRes.ImageNumber { // 图文余量不足
|
||||||
|
_, err = service.CastProvider.UpdateStatus(context.Background(), &cast.UpdateStatusReq{
|
||||||
|
WorkAction: cast.WorkActionENUM_CONFIRM,
|
||||||
|
WorkUuid: req.WorkUuid,
|
||||||
|
ConfirmRemark: req.ConfirmRemark,
|
||||||
|
ConfirmStatus: 3,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
addBalanceReq.ImageConsumptionNumber = 1
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if balanceInfoRes.VideoConsumptionNumber >= balanceInfoRes.VideoNumber { // 视频余量不足
|
||||||
|
_, err = service.CastProvider.UpdateStatus(context.Background(), &cast.UpdateStatusReq{
|
||||||
|
WorkAction: cast.WorkActionENUM_CONFIRM,
|
||||||
|
WorkUuid: req.WorkUuid,
|
||||||
|
ConfirmRemark: req.ConfirmRemark,
|
||||||
|
ConfirmStatus: 3,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
addBalanceReq.VideoConsumptionNumber = 1
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resp, err := service.BundleProvider.AddBundleBalance(context.Background(), &addBalanceReq)
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("扣除余额失败,作品uuid:"+req.WorkUuid, zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_, err = service.CastProvider.UpdateStatus(context.Background(), &cast.UpdateStatusReq{
|
||||||
|
WorkAction: cast.WorkActionENUM_CONFIRM,
|
||||||
|
WorkUuid: req.WorkUuid,
|
||||||
|
ConfirmRemark: req.ConfirmRemark,
|
||||||
|
CostType: resp.UsedType,
|
||||||
|
ConfirmStatus: 1,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
zap.L().Error("更新作品状态失败,作品uuid:"+req.WorkUuid, zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ArtistAutoConfirmTask() {
|
func ArtistAutoConfirmTask() {
|
||||||
now := float64(time.Now().Unix())
|
now := float64(time.Now().Unix())
|
||||||
opt := redis.ZRangeBy{
|
opt := redis.ZRangeBy{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user