Merge branch 'feat-hjj-Competitors#A203' into dev
# Conflicts: # pkg/cron/cron.go
This commit is contained in:
commit
eb6a6363ef
10
cmd/app.go
10
cmd/app.go
@ -34,16 +34,6 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 一次性执行任务余额同步(幂等):若已执行或存在数据则跳过
|
|
||||||
// if syncErr := dao.RunInitialTaskBalanceSync(); syncErr != nil {
|
|
||||||
// app.ModuleClients.Lg.Warn("initial task-balance sync failed", zap.Error(syncErr))
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 增量同步:每次服务重启时执行,同步套餐余额表中的新数据到任务余额表
|
|
||||||
// if incrementalSyncErr := dao.RunIncrementalTaskBalanceSync(); incrementalSyncErr != nil {
|
|
||||||
// app.ModuleClients.Lg.Warn("incremental task-balance sync failed", zap.Error(incrementalSyncErr))
|
|
||||||
// }
|
|
||||||
|
|
||||||
//l, err := net.Listen("tcp", ":8883")
|
//l, err := net.Listen("tcp", ":8883")
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// fmt.Printf("failed to listen: %v", err)
|
// fmt.Printf("failed to listen: %v", err)
|
||||||
|
|||||||
@ -13,57 +13,12 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetPendingTaskList 查询待指派任务记录
|
|
||||||
func (b *BundleProvider) GetPendingTaskList(_ context.Context, req *bundle.TaskQueryRequest) (*bundle.TaskQueryResponse, error) {
|
|
||||||
// 转换请求参数
|
|
||||||
daoReq := &dao.TaskQueryRequest{
|
|
||||||
Keyword: req.Keyword,
|
|
||||||
Page: int(req.Page),
|
|
||||||
PageSize: int(req.PageSize),
|
|
||||||
SortBy: req.SortBy,
|
|
||||||
SortType: req.SortType,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用logic层
|
|
||||||
tasks, total, err := logic.GetPendingTaskList(daoReq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换响应数据
|
|
||||||
var taskInfos []*bundle.TaskManagementInfo
|
|
||||||
for _, task := range tasks {
|
|
||||||
taskInfo := &bundle.TaskManagementInfo{
|
|
||||||
SubNum: task.SubNum,
|
|
||||||
TelNum: task.TelNum,
|
|
||||||
ArtistName: task.ArtistName,
|
|
||||||
PendingVideoCount: int32(task.PendingVideoCount),
|
|
||||||
PendingPostCount: int32(task.PendingPostCount),
|
|
||||||
PendingDataCount: int32(task.PendingDataCount),
|
|
||||||
ProgressTaskCount: int32(task.ProgressTaskCount),
|
|
||||||
CompleteTaskCount: int32(task.CompleteTaskCount),
|
|
||||||
LastTaskAssignee: task.LastTaskAssignee,
|
|
||||||
TaskAssigneeNum: task.TaskAssigneeNum,
|
|
||||||
PendingVideoScriptCount: 0,
|
|
||||||
}
|
|
||||||
taskInfos = append(taskInfos, taskInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bundle.TaskQueryResponse{
|
|
||||||
Tasks: taskInfos,
|
|
||||||
Total: total,
|
|
||||||
Page: req.Page,
|
|
||||||
PageSize: req.PageSize,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AssignTask 指派某位员工完成某个艺人的任务
|
// AssignTask 指派某位员工完成某个艺人的任务
|
||||||
func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignRequest) (*bundle.CommonResponse, error) {
|
||||||
// 转换请求参数
|
|
||||||
daoReq := &dao.TaskAssignRequest{
|
daoReq := &dao.TaskAssignRequest{
|
||||||
SubNum: req.SubNum,
|
SubNum: req.SubNum,
|
||||||
TelNum: req.TelNum,
|
TelNum: req.TelNum,
|
||||||
ArtistName: req.ArtistName, // 添加缺失的ArtistName字段
|
ArtistName: req.ArtistName,
|
||||||
TaskAssignee: req.TaskAssignee,
|
TaskAssignee: req.TaskAssignee,
|
||||||
TaskAssigneeNum: req.TaskAssigneeNum,
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
||||||
Operator: req.Operator,
|
Operator: req.Operator,
|
||||||
@ -75,7 +30,6 @@ func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignReq
|
|||||||
AssignVideoScriptCount: int(req.AssignVideoScriptCount),
|
AssignVideoScriptCount: int(req.AssignVideoScriptCount),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用logic层
|
|
||||||
err := logic.AssignTask(daoReq)
|
err := logic.AssignTask(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.CommonResponse{
|
return &bundle.CommonResponse{
|
||||||
@ -88,35 +42,6 @@ func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignReq
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePendingCount 修改待发数量
|
|
||||||
func (b *BundleProvider) UpdatePendingCount(_ context.Context, req *bundle.UpdatePendingCountRequest) (*bundle.CommonResponse, error) {
|
|
||||||
// 转换请求参数
|
|
||||||
daoReq := &dao.UpdatePendingCountRequest{
|
|
||||||
SubNum: req.SubNum,
|
|
||||||
TelNum: req.TelNum,
|
|
||||||
ArtistName: req.ArtistName, // 添加缺失的ArtistName字段
|
|
||||||
PendingVideoCount: int(req.PendingVideoCount),
|
|
||||||
PendingPostCount: int(req.PendingPostCount),
|
|
||||||
PendingDataCount: int(req.PendingDataCount),
|
|
||||||
Operator: req.Operator,
|
|
||||||
OperatorNum: req.OperatorNum,
|
|
||||||
TaskAssignee: req.TaskAssignee,
|
|
||||||
TaskAssigneeNum: req.TaskAssigneeNum,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用logic层
|
|
||||||
err := logic.UpdatePendingCount(daoReq)
|
|
||||||
if err != nil {
|
|
||||||
return &bundle.CommonResponse{
|
|
||||||
Msg: err.Error(),
|
|
||||||
}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bundle.CommonResponse{
|
|
||||||
Msg: "待发数量修改成功",
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRecentAssignRecords 查询最近被指派记录
|
// GetRecentAssignRecords 查询最近被指派记录
|
||||||
func (b *BundleProvider) GetRecentAssignRecords(_ context.Context, req *bundle.RecentAssignRecordsRequest) (*bundle.RecentAssignRecordsResponse, error) {
|
func (b *BundleProvider) GetRecentAssignRecords(_ context.Context, req *bundle.RecentAssignRecordsRequest) (*bundle.RecentAssignRecordsResponse, error) {
|
||||||
limit := int(req.Limit)
|
limit := int(req.Limit)
|
||||||
@ -142,7 +67,6 @@ func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle
|
|||||||
if int(req.Status) == 2 {
|
if int(req.Status) == 2 {
|
||||||
req.SortBy = "complete_time"
|
req.SortBy = "complete_time"
|
||||||
}
|
}
|
||||||
// 转换请求参数
|
|
||||||
daoReq := &dao.EmployeeTaskQueryRequest{
|
daoReq := &dao.EmployeeTaskQueryRequest{
|
||||||
TaskAssigneeNum: req.TaskAssigneeNum,
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
@ -158,13 +82,11 @@ func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle
|
|||||||
TaskBatch: req.TaskBatch,
|
TaskBatch: req.TaskBatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用logic层
|
|
||||||
records, total, err := logic.GetEmployeeAssignedTasks(daoReq)
|
records, total, err := logic.GetEmployeeAssignedTasks(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换响应数据
|
|
||||||
var recordInfos []*bundle.TaskAssignRecordInfo
|
var recordInfos []*bundle.TaskAssignRecordInfo
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
recordInfo := convertToTaskAssignRecordInfo(record)
|
recordInfo := convertToTaskAssignRecordInfo(record)
|
||||||
@ -181,7 +103,6 @@ func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle
|
|||||||
|
|
||||||
// CompleteTaskManually 员工手动点击完成任务
|
// CompleteTaskManually 员工手动点击完成任务
|
||||||
func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.CompleteTaskManuallyRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.CompleteTaskManuallyRequest) (*bundle.CommonResponse, error) {
|
||||||
// 调用logic层
|
|
||||||
err := logic.CompleteTaskManually(req.AssignRecordsUUID, req.TaskAssigneeNum)
|
err := logic.CompleteTaskManually(req.AssignRecordsUUID, req.TaskAssigneeNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.CommonResponse{
|
return &bundle.CommonResponse{
|
||||||
@ -196,7 +117,6 @@ func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.Com
|
|||||||
|
|
||||||
// UpdateTaskProgress 员工实际完成任务状态更新
|
// UpdateTaskProgress 员工实际完成任务状态更新
|
||||||
func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.UpdateTaskProgressRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.UpdateTaskProgressRequest) (*bundle.CommonResponse, error) {
|
||||||
// 转换请求参数
|
|
||||||
daoReq := &dao.CompleteTaskRequest{
|
daoReq := &dao.CompleteTaskRequest{
|
||||||
AssignRecordsUUID: req.AssignRecordsUUID,
|
AssignRecordsUUID: req.AssignRecordsUUID,
|
||||||
EmployeeName: req.EmployeeName,
|
EmployeeName: req.EmployeeName,
|
||||||
@ -206,7 +126,6 @@ func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.Updat
|
|||||||
UUID: req.Uuid,
|
UUID: req.Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用logic层
|
|
||||||
err := logic.UpdateTaskProgress(daoReq)
|
err := logic.UpdateTaskProgress(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.CommonResponse{
|
return &bundle.CommonResponse{
|
||||||
@ -219,9 +138,8 @@ func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.Updat
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerminateTaskByUUID 根据指派记录UUID终止任务(实际状态置为已中止)
|
// TerminateTaskByUUID 根据指派记录UUID终止任务
|
||||||
func (b *BundleProvider) TerminateTaskByUUID(_ context.Context, req *bundle.TerminateTaskByUUIDRequest) (*bundle.ComResponse, error) {
|
func (b *BundleProvider) TerminateTaskByUUID(_ context.Context, req *bundle.TerminateTaskByUUIDRequest) (*bundle.ComResponse, error) {
|
||||||
// 调用logic层
|
|
||||||
err := logic.TerminateTaskByUUID(req.AssignRecordsUUID)
|
err := logic.TerminateTaskByUUID(req.AssignRecordsUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.ComResponse{Msg: err.Error()}, err
|
return &bundle.ComResponse{Msg: err.Error()}, err
|
||||||
@ -274,7 +192,6 @@ func (b *BundleProvider) GetTaskAssignRecordsList(_ context.Context, req *bundle
|
|||||||
if sortBy, ok := model.OrderByPending[req.SortBy]; ok {
|
if sortBy, ok := model.OrderByPending[req.SortBy]; ok {
|
||||||
req.SortBy = sortBy
|
req.SortBy = sortBy
|
||||||
}
|
}
|
||||||
// 转换请求参数
|
|
||||||
daoReq := &dao.TaskAssignRecordsQueryRequest{
|
daoReq := &dao.TaskAssignRecordsQueryRequest{
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
TaskAssignee: req.TaskAssignee,
|
TaskAssignee: req.TaskAssignee,
|
||||||
@ -297,7 +214,6 @@ func (b *BundleProvider) GetTaskAssignRecordsList(_ context.Context, req *bundle
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换响应数据
|
|
||||||
var recordInfos []*bundle.TaskAssignRecordInfo
|
var recordInfos []*bundle.TaskAssignRecordInfo
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
recordInfo := convertToTaskAssignRecordInfo(record)
|
recordInfo := convertToTaskAssignRecordInfo(record)
|
||||||
@ -364,51 +280,7 @@ func convertToTaskAssignRecordsSummary(s *dao.TaskAssignRecordsSummary) *bundle.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArtistBundleBalance 查询艺人的当前任务余额与待发数量(区分套餐/增值两类)
|
// BatchAssignTask 批量指派
|
||||||
// 说明:
|
|
||||||
// - 查询条件优先使用艺人编号(customerNum),为空时使用手机号(telNum)
|
|
||||||
// - 返回同时包含“套餐类型”和“增值类型”的余额与待发数量,均按视频/图文/数据分析三类区分
|
|
||||||
func (b *BundleProvider) GetArtistBundleBalance(_ context.Context, req *bundle.ArtistBundleBalanceRequest) (*bundle.ArtistBundleBalanceResponse, error) {
|
|
||||||
// 参数校验:艺人编号与手机号不能同时为空
|
|
||||||
if req.CustomerNum == "" && req.TelNum == "" {
|
|
||||||
return nil, fmt.Errorf("艺人编号和手机号不能同时为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 仅使用艺人编号进行查询(与DAO层 GetRemainingPendingBySubNum 一致)
|
|
||||||
subNum := req.CustomerNum
|
|
||||||
if subNum == "" {
|
|
||||||
// 暂不支持通过手机号查询剩余待发数据
|
|
||||||
return nil, fmt.Errorf("暂不支持通过手机号查询剩余待发数据,请传入艺人编号")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用逻辑层:仅查询剩余待发数量(区分套餐/增值)
|
|
||||||
resp, err := logic.GetArtistRemainingPending(subNum)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 组装proto响应:非DAO返回字段统一置为0
|
|
||||||
return &bundle.ArtistBundleBalanceResponse{
|
|
||||||
// 套餐类型余额(暂置0)
|
|
||||||
BundleVideoBalance: 0,
|
|
||||||
BundleImageBalance: 0,
|
|
||||||
BundleDataAnalysisBalance: 0,
|
|
||||||
// 增值类型余额(暂置0)
|
|
||||||
IncreaseVideoBalance: 0,
|
|
||||||
IncreaseImageBalance: 0,
|
|
||||||
IncreaseDataAnalysisBalance: 0,
|
|
||||||
// 套餐类型待发数量
|
|
||||||
BundlePendingVideoCount: int32(resp.PendingBundleVideoCount),
|
|
||||||
BundlePendingImageCount: int32(resp.PendingBundleImageCount),
|
|
||||||
BundlePendingDataAnalysisCount: int32(resp.PendingBundleDataAnalysisCount),
|
|
||||||
// 增值类型待发数量
|
|
||||||
IncreasePendingVideoCount: int32(resp.PendingIncreaseVideoCount),
|
|
||||||
IncreasePendingImageCount: int32(resp.PendingIncreaseImageCount),
|
|
||||||
IncreasePendingDataAnalysisCount: int32(resp.PendingIncreaseDataAnalysisCount),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BatchAssignTask 批量指派(仅写入指派记录,不更新任务管理表)
|
|
||||||
func (b *BundleProvider) BatchAssignTask(_ context.Context, req *bundle.BatchAssignTaskRequest) (*bundle.ComResponse, error) {
|
func (b *BundleProvider) BatchAssignTask(_ context.Context, req *bundle.BatchAssignTaskRequest) (*bundle.ComResponse, error) {
|
||||||
if req == nil || len(req.Items) == 0 {
|
if req == nil || len(req.Items) == 0 {
|
||||||
return &bundle.ComResponse{Msg: "批量指派项不能为空"}, fmt.Errorf("批量指派项不能为空")
|
return &bundle.ComResponse{Msg: "批量指派项不能为空"}, fmt.Errorf("批量指派项不能为空")
|
||||||
@ -451,7 +323,6 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
if sortBy, ok := model.OrderByDataAnalysis[req.SortBy]; ok {
|
if sortBy, ok := model.OrderByDataAnalysis[req.SortBy]; ok {
|
||||||
req.SortBy = sortBy
|
req.SortBy = sortBy
|
||||||
}
|
}
|
||||||
// 构造 DAO 请求参数
|
|
||||||
daoReq := &dao.TaskQueryRequest{
|
daoReq := &dao.TaskQueryRequest{
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
Page: int(req.Page),
|
Page: int(req.Page),
|
||||||
@ -462,13 +333,11 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
SubNums: req.SubNums,
|
SubNums: req.SubNums,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用逻辑层
|
|
||||||
items, total, err := logic.GetArtistUploadStatsList(daoReq)
|
items, total, err := logic.GetArtistUploadStatsList(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换响应数据
|
|
||||||
formatTime := func(s string) string {
|
formatTime := func(s string) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return ""
|
return ""
|
||||||
@ -525,29 +394,6 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BundleProvider) GetPendingUploadBreakdown(_ context.Context, req *bundle.PendingUploadBreakdownRequest) (*bundle.PendingUploadBreakdownResponse, error) {
|
|
||||||
items, total, err := logic.GetPendingUploadBreakdownBySubNums(req.SubNums, int(req.Page), int(req.PageSize))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
respItems := make([]*bundle.PendingUploadBreakdownItem, 0, len(items))
|
|
||||||
for _, it := range items {
|
|
||||||
respItems = append(respItems, &bundle.PendingUploadBreakdownItem{
|
|
||||||
SubNum: it.SubNum,
|
|
||||||
TelNum: it.TelNum,
|
|
||||||
ArtistName: it.UserName,
|
|
||||||
PendingVideoScriptCount: int32(it.PendingVideoScriptCount),
|
|
||||||
PendingBundleVideoCount: int32(it.PendingBundleVideoCount),
|
|
||||||
PendingIncreaseVideoCount: int32(it.PendingIncreaseVideoCount),
|
|
||||||
PendingBundlePostCount: int32(it.PendingBundlePostCount),
|
|
||||||
PendingIncreasePostCount: int32(it.PendingIncreasePostCount),
|
|
||||||
PendingBundleDataCount: int32(it.PendingBundleDataCount),
|
|
||||||
PendingIncreaseDataCount: int32(it.PendingIncreaseDataCount),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return &bundle.PendingUploadBreakdownResponse{Items: respItems, Total: total, Page: req.Page, PageSize: req.PageSize}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPendingAssign 查询艺人可指派数量
|
// GetPendingAssign 查询艺人可指派数量
|
||||||
func (b *BundleProvider) GetPendingAssign(_ context.Context, req *bundle.PendingAssignRequest) (*bundle.PendingAssignResponse, error) {
|
func (b *BundleProvider) GetPendingAssign(_ context.Context, req *bundle.PendingAssignRequest) (*bundle.PendingAssignResponse, error) {
|
||||||
items, total, err := logic.GetPendingAssignBySubNums(req.SubNums, int(req.Page), int(req.PageSize))
|
items, total, err := logic.GetPendingAssignBySubNums(req.SubNums, int(req.Page), int(req.PageSize))
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import (
|
|||||||
"micro-bundle/pkg/utils"
|
"micro-bundle/pkg/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/clause"
|
"gorm.io/gorm/clause"
|
||||||
)
|
)
|
||||||
@ -454,14 +453,6 @@ func ExtendBundleBalanceByUserId(data model.BundleBalanceExtendPo) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 套餐余额更新成功后,同步增量更新任务余额
|
|
||||||
// 如果任务余额更新失败,只记录错误日志,不影响主流程
|
|
||||||
if taskErr := ExtendTaskBalanceByUserId(data.UserId, data.ImageNumber, data.DataAnalysisNumber, data.VideoNumber, data.DurationNumber); taskErr != nil {
|
|
||||||
// 记录错误日志但不返回错误,避免影响主流程
|
|
||||||
logger.Errorf("任务余额同步失败,用户ID: %d, 错误: %v", data.UserId, taskErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,13 +460,6 @@ func CreateBundleBalance(data model.BundleBalance) error {
|
|||||||
if err := app.ModuleClients.BundleDB.Save(&data).Error; err != nil {
|
if err := app.ModuleClients.BundleDB.Save(&data).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// 同步任务余额(新建套餐余额时)
|
|
||||||
// 如果任务余额同步失败,只记录错误日志,不影响主流程
|
|
||||||
if taskErr := SyncTaskBalanceFromBundleBalance(data); taskErr != nil {
|
|
||||||
// 记录错误日志但不返回错误,避免影响主流程
|
|
||||||
logger.Errorf("新建套餐余额时任务余额同步失败,更新数据: %v, 错误 %v", data, taskErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,570 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pkg/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RunInitialTaskBalanceSync 一次性将 BundleBalance 同步到 TaskBalance
|
|
||||||
// 仅在未执行过且任务余额表为空时运行;执行成功后写入标记,避免再次执行
|
|
||||||
func RunInitialTaskBalanceSync() error {
|
|
||||||
// 确保标记表存在
|
|
||||||
_ = app.ModuleClients.TaskBenchDB.AutoMigrate(&model.TaskSyncStatus{})
|
|
||||||
|
|
||||||
// 已执行标记检查
|
|
||||||
var markerCount int64
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Model(&model.TaskSyncStatus{}).
|
|
||||||
Where("sync_key = ?", model.InitialSyncKey).Count(&markerCount).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if markerCount > 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 安全检查:如果任务余额表已存在数据,则不再执行,同样写入标记
|
|
||||||
var existing int64
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Model(&model.TaskBalance{}).Count(&existing).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if existing > 0 {
|
|
||||||
_ = app.ModuleClients.TaskBenchDB.Create(&model.TaskSyncStatus{
|
|
||||||
SyncKey: model.InitialSyncKey,
|
|
||||||
ExecutedAt: time.Now(),
|
|
||||||
Remark: "skipped: task_balance already has data",
|
|
||||||
}).Error
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取当前有效(未过期且已支付)的艺人及其最新订单
|
|
||||||
validArtists, err := GetValidArtistList()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println(validArtists)
|
|
||||||
if len(validArtists) == 0 {
|
|
||||||
// 不写入已执行标记,留待后续有数据时再次执行
|
|
||||||
fmt.Println("无数据更新")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构造待插入的 TaskBalance 列表
|
|
||||||
tasks := make([]model.TaskBalance, 0, len(validArtists))
|
|
||||||
for _, a := range validArtists {
|
|
||||||
// 根据 user_id + order_uuid 获取 BundleBalance 明细
|
|
||||||
var bb model.BundleBalance
|
|
||||||
if err := app.ModuleClients.BundleDB.Where("user_id = ? AND order_uuid = ?", a.UserID, a.OrderUUID).First(&bb).Error; err != nil {
|
|
||||||
// 若未查到则跳过该条
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
subNum, telNum, err := fetchIdentityForBundle(&bb)
|
|
||||||
if err != nil {
|
|
||||||
// 无法获取身份信息则跳过该条
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tb := model.TaskBalance{
|
|
||||||
SubNum: subNum,
|
|
||||||
TelNum: telNum,
|
|
||||||
Month: bb.Month,
|
|
||||||
StartAt: bb.StartAt,
|
|
||||||
ExpiredAt: bb.ExpiredAt,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}
|
|
||||||
copyBundleToTaskBalance(&tb, &bb)
|
|
||||||
tasks = append(tasks, tb)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 原子写入:插入 TaskBalance + 插入标记(确保有插入才写标记)
|
|
||||||
tx := app.ModuleClients.TaskBenchDB.Begin()
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if len(tasks) == 0 {
|
|
||||||
// 没有可插入的数据,不写标记,直接返回
|
|
||||||
tx.Rollback()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tx.Create(&tasks).Error; err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := tx.Create(&model.TaskSyncStatus{
|
|
||||||
SyncKey: model.InitialSyncKey,
|
|
||||||
ExecutedAt: time.Now(),
|
|
||||||
Remark: "initial sync executed",
|
|
||||||
}).Error; err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := tx.Commit().Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RunIncrementalTaskBalanceSync 增量同步:每次服务重启时执行
|
|
||||||
// 将套餐余额表中的新数据同步到任务余额表,跳过已存在的记录
|
|
||||||
func RunIncrementalTaskBalanceSync() error {
|
|
||||||
// 获取当前有效(未过期且已支付)的艺人及其最新订单
|
|
||||||
validArtists, err := GetValidArtistList()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(validArtists) == 0 {
|
|
||||||
fmt.Println("增量同步:无有效艺人数据")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构造待插入的 TaskBalance 列表(仅包含不存在的记录)
|
|
||||||
tasks := make([]model.TaskBalance, 0)
|
|
||||||
skippedCount := 0
|
|
||||||
|
|
||||||
for _, a := range validArtists {
|
|
||||||
// 根据 user_id + order_uuid 获取 BundleBalance 明细
|
|
||||||
var bb model.BundleBalance
|
|
||||||
if err := app.ModuleClients.BundleDB.Where("user_id = ? AND order_uuid = ?", a.UserID, a.OrderUUID).First(&bb).Error; err != nil {
|
|
||||||
// 若未查到则跳过该条
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
subNum, telNum, err := fetchIdentityForBundle(&bb)
|
|
||||||
if err != nil {
|
|
||||||
// 无法获取身份信息则跳过该条
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查任务余额表中是否已存在该记录(按 sub_num + tel_num + month 唯一)
|
|
||||||
var existingCount int64
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Model(&model.TaskBalance{}).
|
|
||||||
Where("sub_num = ? AND tel_num = ? AND month = ?", subNum, telNum, bb.Month).
|
|
||||||
Count(&existingCount).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if existingCount > 0 {
|
|
||||||
// 记录已存在,跳过
|
|
||||||
skippedCount++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构造新的 TaskBalance 记录
|
|
||||||
tb := model.TaskBalance{
|
|
||||||
SubNum: subNum,
|
|
||||||
TelNum: telNum,
|
|
||||||
Month: bb.Month,
|
|
||||||
StartAt: bb.StartAt,
|
|
||||||
ExpiredAt: bb.ExpiredAt,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}
|
|
||||||
copyBundleToTaskBalance(&tb, &bb)
|
|
||||||
tasks = append(tasks, tb)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("增量同步:跳过已存在记录 %d 条,准备插入新记录 %d 条\n", skippedCount, len(tasks))
|
|
||||||
|
|
||||||
// 如果没有新记录需要插入,直接返回
|
|
||||||
if len(tasks) == 0 {
|
|
||||||
fmt.Println("增量同步:无新记录需要同步")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量插入新记录
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Create(&tasks).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("增量同步:成功插入 %d 条新记录\n", len(tasks))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 用户新买套餐时使用
|
|
||||||
// SyncTaskBalanceFromBundleBalance 增量/每月:根据单条 BundleBalance 同步或更新 TaskBalance(按 sub_num + tel_num + month 唯一)
|
|
||||||
func SyncTaskBalanceFromBundleBalance(bb model.BundleBalance) error {
|
|
||||||
// 获取身份信息(sub_num, tel_num)
|
|
||||||
subNum, telNum, err := fetchIdentityForBundle(&bb)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 组装 TaskBalance
|
|
||||||
tb := model.TaskBalance{
|
|
||||||
SubNum: subNum,
|
|
||||||
TelNum: telNum,
|
|
||||||
Month: bb.Month,
|
|
||||||
ExpiredAt: bb.ExpiredAt,
|
|
||||||
StartAt: bb.StartAt,
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
}
|
|
||||||
copyBundleToTaskBalance(&tb, &bb)
|
|
||||||
|
|
||||||
// 查询是否已存在(唯一:sub_num + tel_num + month)
|
|
||||||
var existing model.TaskBalance
|
|
||||||
err = app.ModuleClients.TaskBenchDB.
|
|
||||||
Where("sub_num = ? AND tel_num = ? AND month = ?", subNum, telNum, bb.Month).
|
|
||||||
First(&existing).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
// 不存在则创建
|
|
||||||
return app.ModuleClients.TaskBenchDB.Create(&tb).Error
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 已存在则更新所有映射字段与时间
|
|
||||||
tb.ID = existing.ID
|
|
||||||
return app.ModuleClients.TaskBenchDB.Save(&tb).Error
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetchIdentityForBundle 根据 BundleBalance 拿到 sub_num 与 tel_num
|
|
||||||
func fetchIdentityForBundle(bb *model.BundleBalance) (string, string, error) {
|
|
||||||
// tel_num 来自 micro-account.user
|
|
||||||
type userRow struct {
|
|
||||||
Tel string
|
|
||||||
}
|
|
||||||
var ur userRow
|
|
||||||
if err := app.ModuleClients.BundleDB.Table("`micro-account`.`user`").Unscoped().
|
|
||||||
Select("tel_num AS tel").Where("id = ?", bb.UserId).Limit(1).Scan(&ur).Error; err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
// customer_num 来自 bundle_order_records(按 order_uuid)
|
|
||||||
type orderRow struct {
|
|
||||||
Customer string
|
|
||||||
}
|
|
||||||
var or orderRow
|
|
||||||
if bb.OrderUUID == "" {
|
|
||||||
return "", "", errors.New("bundle order_uuid missing")
|
|
||||||
}
|
|
||||||
if err := app.ModuleClients.BundleDB.Table("bundle_order_records").
|
|
||||||
Select("customer_num AS customer").Where("uuid = ?", bb.OrderUUID).Limit(1).Scan(&or).Error; err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
return or.Customer, ur.Tel, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateTaskBalance 每月批量更新任务余额
|
|
||||||
// 类似于 UpdateBundleBalance 的逻辑,但针对任务余额表
|
|
||||||
func UpdateTaskBalanceEveryMon() error {
|
|
||||||
// 查询需要更新的任务余额记录(最新月份且未过期的记录)
|
|
||||||
tl := []model.TaskBalance{}
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Raw(`select
|
|
||||||
*
|
|
||||||
from
|
|
||||||
task_balance tb
|
|
||||||
inner join (
|
|
||||||
select
|
|
||||||
max(tb.month) as month ,
|
|
||||||
sub_num,
|
|
||||||
tel_num
|
|
||||||
from
|
|
||||||
task_balance tb
|
|
||||||
group by
|
|
||||||
tb.sub_num, tb.tel_num
|
|
||||||
) newest on
|
|
||||||
newest.month = tb.month
|
|
||||||
and (tb.sub_num = newest.sub_num OR tb.tel_num = newest.tel_num)
|
|
||||||
and tb.expired_at > now()`).Find(&tl).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
month := time.Now().Format("2006-01")
|
|
||||||
|
|
||||||
for _, v := range tl {
|
|
||||||
if v.Month == month {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
cal := func(total, limit int) int { // 计算本月发放的限制类型数量
|
|
||||||
var released int // 已释放的次数
|
|
||||||
if v.StartAt.Month() == now.Month() && v.StartAt.Year() == now.Year() {
|
|
||||||
} else if v.StartAt.Day() >= 16 { //第一个月释放的
|
|
||||||
released += (limit + 1) / 2
|
|
||||||
} else {
|
|
||||||
released += limit
|
|
||||||
}
|
|
||||||
interval := now.Year()*12 + int(now.Month()) - (v.StartAt.Year()*12 + int(v.StartAt.Month())) // 释放了多少个月
|
|
||||||
released += max(interval-1, 0) * limit // 后续月份释放的
|
|
||||||
remaining := max(total-released, 0) // 还剩余多少次没有发放
|
|
||||||
|
|
||||||
if v.StartAt.Month() == now.Month() && v.StartAt.Year() == now.Year() && v.StartAt.Day() >= 16 { // 本月为第一个月并且16号后购买只给一半(向上取整)
|
|
||||||
return min((limit+1)/2, remaining)
|
|
||||||
}
|
|
||||||
if v.ExpiredAt.Month() == now.Month() && v.ExpiredAt.Year() == now.Year() && v.ExpiredAt.Day() < 16 { // 本月为最后一个月并且16号前到期只给一半(向下取整)
|
|
||||||
return min(limit/2, remaining)
|
|
||||||
}
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
|
|
||||||
v.MonthlyInvalidBundleVideoNumber = v.MonthlyBundleLimitExpiredVideoNumber - v.MonthlyBundleLimitExpiredVideoConsumptionNumber // 当月过期的视频数
|
|
||||||
v.InvalidBundleVideoNumber += v.MonthlyInvalidBundleVideoNumber
|
|
||||||
v.MonthlyInvalidBundleImageNumber = v.MonthlyBundleLimitExpiredImageNumber - v.MonthlyBundleLimitExpiredImageConsumptionNumber // 当月过期的图片数
|
|
||||||
v.InvalidBundleImageNumber += v.MonthlyInvalidBundleImageNumber
|
|
||||||
v.MonthlyInvalidBundleDataAnalysisNumber = v.MonthlyBundleLimitExpiredDataAnalysisNumber - v.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber // 当月过期的数据分析数
|
|
||||||
v.InvalidBundleDataAnalysisNumber += v.MonthlyInvalidBundleDataAnalysisNumber
|
|
||||||
|
|
||||||
// 当月可用的限制类型数等于本月方法的套餐和增值两种类型的总和
|
|
||||||
v.MonthlyBundleLimitExpiredVideoNumber = cal(v.BundleLimitVideoExpiredNumber, v.MonthlyLimitVideoQuotaNumber)
|
|
||||||
v.MonthlyIncreaseLimitExpiredVideoNumber = cal(v.IncreaseLimitVideoExpiredNumber, v.MonthlyLimitVideoQuotaNumber)
|
|
||||||
v.MonthlyBundleLimitVideoNumber = v.MonthlyBundleLimitVideoNumber - v.MonthlyBundleLimitVideoConsumptionNumber + cal(v.BundleLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
|
||||||
v.MonthlyIncreaseLimitVideoNumber = v.MonthlyIncreaseLimitVideoNumber - v.MonthlyIncreaseLimitVideoConsumptionNumber + cal(v.IncreaseLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
|
||||||
v.MonthlyBundleLimitExpiredImageNumber = cal(v.BundleLimitImageExpiredNumber, v.MonthlyLimitImageQuotaNumber)
|
|
||||||
v.MonthlyIncreaseLimitExpiredImageNumber = cal(v.IncreaseLimitImageExpiredNumber, v.MonthlyLimitImageQuotaNumber)
|
|
||||||
v.MonthlyBundleLimitImageNumber = v.MonthlyBundleLimitImageNumber - v.MonthlyBundleLimitImageConsumptionNumber + cal(v.BundleLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
|
||||||
v.MonthlyIncreaseLimitImageNumber = v.MonthlyIncreaseLimitImageNumber - v.MonthlyIncreaseLimitImageConsumptionNumber + cal(v.IncreaseLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
|
||||||
v.MonthlyBundleLimitExpiredDataAnalysisNumber = cal(v.BundleLimitDataAnalysisExpiredNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
|
||||||
v.MonthlyIncreaseLimitExpiredDataAnalysisNumber = cal(v.IncreaseLimitDataAnalysisExpiredNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
|
||||||
v.MonthlyBundleLimitDataAnalysisNumber = v.MonthlyBundleLimitDataAnalysisNumber - v.MonthlyBundleLimitDataAnalysisConsumptionNumber + cal(v.BundleLimitDataAnalysisNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
|
||||||
v.MonthlyIncreaseLimitDataAnalysisNumber = v.MonthlyIncreaseLimitDataAnalysisNumber - v.MonthlyIncreaseLimitDataAnalysisConsumptionNumber + cal(v.IncreaseLimitDataAnalysisNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
|
||||||
// 重置单月消耗数量
|
|
||||||
v.MonthlyBundleVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitExpiredVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitExpiredVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyNewManualVideoNumber = 0
|
|
||||||
v.MonthlyManualVideoConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleImageConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseImageConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitImageConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitImageConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitExpiredImageConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitExpiredImageConsumptionNumber = 0
|
|
||||||
v.MonthlyNewManualImageNumber = 0
|
|
||||||
v.MonthlyManualImageConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleDataAnalysisConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseDataAnalysisConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitDataAnalysisConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitDataAnalysisConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber = 0
|
|
||||||
v.MonthlyNewManualDataAnalysisNumber = 0
|
|
||||||
v.MonthlyManualDataAnalysisConsumptionNumber = 0
|
|
||||||
|
|
||||||
// 设置新月份和重置ID
|
|
||||||
v.Month = month
|
|
||||||
v.ID = 0
|
|
||||||
|
|
||||||
// 创建新的任务余额记录
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Create(&v).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateTaskBalanceExpiredAt 更新任务余额表的ExpiredAt字段
|
|
||||||
func updateTaskBalanceExpiredAt(subNum, telNum string, durationNumber int) error {
|
|
||||||
return app.ModuleClients.TaskBenchDB.Transaction(func(tx *gorm.DB) error {
|
|
||||||
var taskBalance model.TaskBalance
|
|
||||||
query := tx.Model(&model.TaskBalance{})
|
|
||||||
|
|
||||||
// 构建查询条件,优先使用 subNum
|
|
||||||
if subNum != "" {
|
|
||||||
query = query.Where("sub_num = ?", subNum)
|
|
||||||
} else {
|
|
||||||
query = query.Where("tel_num = ?", telNum)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询当前有效的任务余额记录,按最新的开始时间排序
|
|
||||||
now := time.Now()
|
|
||||||
err := query.Where("start_at <= ? AND expired_at >= ?", now, now).Order("start_at DESC").First(&taskBalance).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 增加过期时间
|
|
||||||
taskBalance.ExpiredAt = taskBalance.ExpiredAt.Add(time.Hour * 24 * time.Duration(durationNumber))
|
|
||||||
|
|
||||||
return tx.Save(&taskBalance).Error
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// copyBundleToTaskBalance 将 BundleBalance 的图片、视频、数据分析相关字段映射到 TaskBalance
|
|
||||||
func copyBundleToTaskBalance(tb *model.TaskBalance, bb *model.BundleBalance) {
|
|
||||||
// ===== 视频类 =====
|
|
||||||
tb.BundleVideoNumber = bb.BundleVideoNumber
|
|
||||||
tb.IncreaseVideoNumber = bb.IncreaseVideoNumber
|
|
||||||
tb.BundleLimitVideoNumber = bb.BundleLimitVideoNumber
|
|
||||||
tb.IncreaseLimitVideoNumber = bb.IncreaseLimitVideoNumber
|
|
||||||
tb.BundleLimitVideoExpiredNumber = bb.BundleLimitVideoExpiredNumber
|
|
||||||
tb.IncreaseLimitVideoExpiredNumber = bb.IncreaseLimitVideoExpiredNumber
|
|
||||||
tb.MonthlyInvalidBundleVideoNumber = bb.MonthlyInvalidBundleVideoNumber
|
|
||||||
tb.InvalidBundleVideoNumber = bb.InvalidBundleVideoNumber
|
|
||||||
tb.MonthlyInvalidIncreaseVideoNumber = bb.MonthlyInvalidIncreaseVideoNumber
|
|
||||||
tb.InvalidIncreaseVideoNumber = bb.InvalidIncreaseVideoNumber
|
|
||||||
tb.BundleVideoConsumptionNumber = bb.BundleVideoConsumptionNumber
|
|
||||||
tb.IncreaseVideoConsumptionNumber = bb.IncreaseVideoConsumptionNumber
|
|
||||||
tb.BundleLimitVideoConsumptionNumber = bb.BundleLimitVideoConsumptionNumber
|
|
||||||
tb.IncreaseLimitVideoConsumptionNumber = bb.IncreaseLimitVideoConsumptionNumber
|
|
||||||
tb.BundleLimitVideoExpiredConsumptionNumber = bb.BundleLimitVideoExpiredConsumptionNumber
|
|
||||||
tb.IncreaseLimitVideoExpiredConsumptionNumber = bb.IncreaseLimitVideoExpiredConsumptionNumber
|
|
||||||
tb.MonthlyBundleVideoConsumptionNumber = bb.MonthlyBundleVideoConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseVideoConsumptionNumber = bb.MonthlyIncreaseVideoConsumptionNumber
|
|
||||||
tb.MonthlyBundleLimitVideoNumber = bb.MonthlyBundleLimitVideoNumber
|
|
||||||
tb.MonthlyIncreaseLimitVideoNumber = bb.MonthlyIncreaseLimitVideoNumber
|
|
||||||
tb.MonthlyBundleLimitVideoConsumptionNumber = bb.MonthlyBundleLimitVideoConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseLimitVideoConsumptionNumber = bb.MonthlyIncreaseLimitVideoConsumptionNumber
|
|
||||||
tb.MonthlyBundleLimitExpiredVideoNumber = bb.MonthlyBundleLimitExpiredVideoNumber
|
|
||||||
tb.MonthlyIncreaseLimitExpiredVideoNumber = bb.MonthlyIncreaseLimitExpiredVideoNumber
|
|
||||||
tb.MonthlyBundleLimitExpiredVideoConsumptionNumber = bb.MonthlyBundleLimitExpiredVideoConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseLimitExpiredVideoConsumptionNumber = bb.MonthlyIncreaseLimitExpiredVideoConsumptionNumber
|
|
||||||
tb.MonthlyLimitVideoQuotaNumber = bb.MonthlyLimitVideoQuotaNumber
|
|
||||||
// 手动扩展(视频)
|
|
||||||
tb.ManualVideoNumber = bb.ManualVideoNumber
|
|
||||||
tb.ManualVideoConsumptionNumber = bb.ManualVideoConsumptionNumber
|
|
||||||
tb.MonthlyNewManualVideoNumber = bb.MonthlyNewManualVideoNumber
|
|
||||||
tb.MonthlyManualVideoConsumptionNumber = bb.MonthlyManualVideoConsumptionNumber
|
|
||||||
|
|
||||||
// ===== 图片类 =====
|
|
||||||
tb.BundleImageNumber = bb.BundleImageNumber
|
|
||||||
tb.IncreaseImageNumber = bb.IncreaseImageNumber
|
|
||||||
tb.BundleLimitImageNumber = bb.BundleLimitImageNumber
|
|
||||||
tb.IncreaseLimitImageNumber = bb.IncreaseLimitImageNumber
|
|
||||||
tb.BundleLimitImageExpiredNumber = bb.BundleLimitImageExpiredNumber
|
|
||||||
tb.IncreaseLimitImageExpiredNumber = bb.IncreaseLimitImageExpiredNumber
|
|
||||||
tb.MonthlyInvalidBundleImageNumber = bb.MonthlyInvalidBundleImageNumber
|
|
||||||
tb.InvalidBundleImageNumber = bb.InvalidBundleImageNumber
|
|
||||||
tb.MonthlyInvalidIncreaseImageNumber = bb.MonthlyInvalidIncreaseImageNumber
|
|
||||||
tb.InvalidIncreaseImageNumber = bb.InvalidIncreaseImageNumber
|
|
||||||
tb.BundleImageConsumptionNumber = bb.BundleImageConsumptionNumber
|
|
||||||
tb.IncreaseImageConsumptionNumber = bb.IncreaseImageConsumptionNumber
|
|
||||||
tb.BundleLimitImageConsumptionNumber = bb.BundleLimitImageConsumptionNumber
|
|
||||||
tb.IncreaseLimitImageConsumptionNumber = bb.IncreaseLimitImageConsumptionNumber
|
|
||||||
tb.BundleLimitImageExpiredConsumptionNumber = bb.BundleLimitImageExpiredConsumptionNumber
|
|
||||||
tb.IncreaseLimitImageExpiredConsumptionNumber = bb.IncreaseLimitImageExpiredConsumptionNumber
|
|
||||||
tb.MonthlyBundleImageConsumptionNumber = bb.MonthlyBundleImageConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseImageConsumptionNumber = bb.MonthlyIncreaseImageConsumptionNumber
|
|
||||||
tb.MonthlyBundleLimitImageNumber = bb.MonthlyBundleLimitImageNumber
|
|
||||||
tb.MonthlyIncreaseLimitImageNumber = bb.MonthlyIncreaseLimitImageNumber
|
|
||||||
tb.MonthlyBundleLimitImageConsumptionNumber = bb.MonthlyBundleLimitImageConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseLimitImageConsumptionNumber = bb.MonthlyIncreaseLimitImageConsumptionNumber
|
|
||||||
tb.MonthlyBundleLimitExpiredImageNumber = bb.MonthlyBundleLimitExpiredImageNumber
|
|
||||||
tb.MonthlyIncreaseLimitExpiredImageNumber = bb.MonthlyIncreaseLimitExpiredImageNumber
|
|
||||||
tb.MonthlyBundleLimitExpiredImageConsumptionNumber = bb.MonthlyBundleLimitExpiredImageConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseLimitExpiredImageConsumptionNumber = bb.MonthlyIncreaseLimitExpiredImageConsumptionNumber
|
|
||||||
tb.MonthlyLimitImageQuotaNumber = bb.MonthlyLimitImageQuotaNumber
|
|
||||||
// 手动扩展(图片)
|
|
||||||
tb.ManualImageNumber = bb.ManualImageNumber
|
|
||||||
tb.ManualImageConsumptionNumber = bb.ManualImageConsumptionNumber
|
|
||||||
tb.MonthlyNewManualImageNumber = bb.MonthlyNewManualImageNumber
|
|
||||||
tb.MonthlyManualImageConsumptionNumber = bb.MonthlyManualImageConsumptionNumber
|
|
||||||
|
|
||||||
// ===== 数据分析类 =====
|
|
||||||
tb.BundleDataAnalysisNumber = bb.BundleDataAnalysisNumber
|
|
||||||
tb.IncreaseDataAnalysisNumber = bb.IncreaseDataAnalysisNumber
|
|
||||||
tb.BundleLimitDataAnalysisNumber = bb.BundleLimitDataAnalysisNumber
|
|
||||||
tb.IncreaseLimitDataAnalysisNumber = bb.IncreaseLimitDataAnalysisNumber
|
|
||||||
tb.BundleLimitDataAnalysisExpiredNumber = bb.BundleLimitDataAnalysisExpiredNumber
|
|
||||||
tb.IncreaseLimitDataAnalysisExpiredNumber = bb.IncreaseLimitDataAnalysisExpiredNumber
|
|
||||||
tb.MonthlyInvalidBundleDataAnalysisNumber = bb.MonthlyInvalidBundleDataAnalysisNumber
|
|
||||||
tb.InvalidBundleDataAnalysisNumber = bb.InvalidBundleDataAnalysisNumber
|
|
||||||
tb.MonthlyInvalidIncreaseDataAnalysisNumber = bb.MonthlyInvalidIncreaseDataAnalysisNumber
|
|
||||||
tb.InvalidIncreaseDataAnalysisNumber = bb.InvalidIncreaseDataAnalysisNumber
|
|
||||||
tb.BundleDataAnalysisConsumptionNumber = bb.BundleDataAnalysisConsumptionNumber
|
|
||||||
tb.IncreaseDataAnalysisConsumptionNumber = bb.IncreaseDataAnalysisConsumptionNumber
|
|
||||||
tb.BundleLimitDataAnalysisConsumptionNumber = bb.BundleLimitDataAnalysisConsumptionNumber
|
|
||||||
tb.IncreaseLimitDataAnalysisConsumptionNumber = bb.IncreaseLimitDataAnalysisConsumptionNumber
|
|
||||||
tb.BundleLimitDataAnalysisExpiredConsumptionNumber = bb.BundleLimitDataAnalysisExpiredConsumptionNumber
|
|
||||||
tb.IncreaseLimitDataAnalysisExpiredConsumptionNumber = bb.IncreaseLimitDataAnalysisExpiredConsumptionNumber
|
|
||||||
tb.MonthlyBundleDataAnalysisConsumptionNumber = bb.MonthlyBundleDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseDataAnalysisConsumptionNumber = bb.MonthlyIncreaseDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyBundleLimitDataAnalysisNumber = bb.MonthlyBundleLimitDataAnalysisNumber
|
|
||||||
tb.MonthlyIncreaseLimitDataAnalysisNumber = bb.MonthlyIncreaseLimitDataAnalysisNumber
|
|
||||||
tb.MonthlyBundleLimitDataAnalysisConsumptionNumber = bb.MonthlyBundleLimitDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseLimitDataAnalysisConsumptionNumber = bb.MonthlyIncreaseLimitDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyBundleLimitExpiredDataAnalysisNumber = bb.MonthlyBundleLimitExpiredDataAnalysisNumber
|
|
||||||
tb.MonthlyIncreaseLimitExpiredDataAnalysisNumber = bb.MonthlyIncreaseLimitExpiredDataAnalysisNumber
|
|
||||||
tb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber = bb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber = bb.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyLimitDataAnalysisQuotaNumber = bb.MonthlyLimitDataAnalysisQuotaNumber
|
|
||||||
// 手动扩展(数据分析)
|
|
||||||
tb.ManualDataAnalysisNumber = bb.ManualDataAnalysisNumber
|
|
||||||
tb.ManualDataAnalysisConsumptionNumber = bb.ManualDataAnalysisConsumptionNumber
|
|
||||||
tb.MonthlyNewManualDataAnalysisNumber = bb.MonthlyNewManualDataAnalysisNumber
|
|
||||||
tb.MonthlyManualDataAnalysisConsumptionNumber = bb.MonthlyManualDataAnalysisConsumptionNumber
|
|
||||||
|
|
||||||
// 其他字段
|
|
||||||
tb.MonthlyNewDurationNumber = bb.MonthlyNewDurationNumber
|
|
||||||
tb.ExpansionPacksNumber = bb.ExpansionPacksNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExtendTaskBalanceByUserId(userId int, imageNumber int, dataAnalysisNumber int, videoNumber int, durationNumber int) error {
|
|
||||||
// 根据用户ID获取其最新套餐记录,进而获取 sub_num、tel_num
|
|
||||||
oldBundle := model.BundleBalance{}
|
|
||||||
if err := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).
|
|
||||||
Where("user_id = ?", userId).
|
|
||||||
Order("created_at desc").
|
|
||||||
First(&oldBundle).Error; err != nil {
|
|
||||||
return errors.New("用户还没有套餐信息")
|
|
||||||
}
|
|
||||||
|
|
||||||
subNum, telNum, err := fetchIdentityForBundle(&oldBundle)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 事务更新当前有效的任务余额记录(按 start_at 最近的一条)
|
|
||||||
err = app.ModuleClients.TaskBenchDB.Transaction(func(tx *gorm.DB) error {
|
|
||||||
var tb model.TaskBalance
|
|
||||||
now := time.Now()
|
|
||||||
query := tx.Model(&model.TaskBalance{}).
|
|
||||||
Where("sub_num = ? AND tel_num = ? AND start_at <= ? AND expired_at >= ?", subNum, telNum, now, now).
|
|
||||||
Order("start_at DESC")
|
|
||||||
|
|
||||||
if err := query.First(&tb).Error; err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return errors.New("用户还没有任务余额信息")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 手动扩展额度与当月新增记录
|
|
||||||
tb.ManualImageNumber += imageNumber
|
|
||||||
tb.MonthlyNewManualImageNumber += imageNumber
|
|
||||||
|
|
||||||
tb.ManualDataAnalysisNumber += dataAnalysisNumber
|
|
||||||
tb.MonthlyNewManualDataAnalysisNumber += dataAnalysisNumber
|
|
||||||
|
|
||||||
tb.ManualVideoNumber += videoNumber
|
|
||||||
tb.MonthlyNewManualVideoNumber += videoNumber
|
|
||||||
|
|
||||||
tb.MonthlyNewDurationNumber += durationNumber
|
|
||||||
|
|
||||||
return tx.Model(&model.TaskBalance{}).Where("id = ?", tb.ID).Save(&tb).Error
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 增加过期时间(按天)
|
|
||||||
if durationNumber > 0 {
|
|
||||||
if err := updateTaskBalanceExpiredAt(subNum, telNum, durationNumber); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -9,13 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetValidArtistList 查询套餐状态为有效中的艺人列表
|
// GetValidArtistList 查询套餐状态为有效中的艺人列表
|
||||||
// 调用dao层获取艺人详细信息
|
|
||||||
func GetValidArtistList() ([]dao.ValidArtistInfo, error) {
|
func GetValidArtistList() ([]dao.ValidArtistInfo, error) {
|
||||||
return dao.GetValidArtistList()
|
return dao.GetValidArtistList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValidArtistIDs 查询套餐没有过期的艺人ID列表(保持向后兼容)
|
// GetValidArtistIDs 查询套餐没有过期的艺人ID列表(保持向后兼容)
|
||||||
// 根据BundleOrderRecords表查询过期时间大于当前时间且状态为已支付的艺人
|
|
||||||
func GetValidArtistIDs() ([]string, error) {
|
func GetValidArtistIDs() ([]string, error) {
|
||||||
artistList, err := GetValidArtistList()
|
artistList, err := GetValidArtistList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -34,8 +32,6 @@ func GetValidArtistIDs() ([]string, error) {
|
|||||||
|
|
||||||
// todo 目前暂时不做检验,后续需要做判断
|
// todo 目前暂时不做检验,后续需要做判断
|
||||||
// GetValidEmployeeIDs 查询可以被指派任务的员工ID列表
|
// GetValidEmployeeIDs 查询可以被指派任务的员工ID列表
|
||||||
// 这里可以根据实际业务需求实现,比如查询员工表、权限表等
|
|
||||||
// 目前先返回一个示例实现,实际项目中需要根据具体的员工管理逻辑来实现
|
|
||||||
func GetValidEmployeeIDs() ([]string, error) {
|
func GetValidEmployeeIDs() ([]string, error) {
|
||||||
var employeeIDs []string
|
var employeeIDs []string
|
||||||
|
|
||||||
@ -63,33 +59,11 @@ func ValidateEmployee(employeeNum string) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPendingTaskList 查询待指派任务记录
|
|
||||||
func GetPendingTaskList(req *dao.TaskQueryRequest) ([]*dao.TaskQueryResponse, int64, error) {
|
|
||||||
// 1. 先查询套餐没有过期的艺人
|
|
||||||
validArtist, err := GetValidArtistList()
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 调用DAO层查询待指派任务记录(已包含联表查询和排序分页)
|
|
||||||
recordResponse, total, err := dao.GetPendingTaskList(req, validArtist)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 直接返回DAO层的结果(已经包含了所有计算和排序分页逻辑)
|
|
||||||
return recordResponse, total, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetArtistUploadStatsList 查询艺人上传与额度统计列表
|
// GetArtistUploadStatsList 查询艺人上传与额度统计列表
|
||||||
func GetArtistUploadStatsList(req *dao.TaskQueryRequest) ([]*dao.ArtistUploadStatsItem, int64, error) {
|
func GetArtistUploadStatsList(req *dao.TaskQueryRequest) ([]*dao.ArtistUploadStatsItem, int64, error) {
|
||||||
return dao.GetArtistUploadStatsList(req)
|
return dao.GetArtistUploadStatsList(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPendingUploadBreakdownBySubNums(subNums []string, page int, pageSize int) ([]*dao.ArtistPendingUploadBreakdownItem, int64, error) {
|
|
||||||
return dao.GetPendingUploadBreakdownBySubNums(subNums, page, pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPendingAssignBySubNums 查询指定艺人的可指派数量
|
// GetPendingAssignBySubNums 查询指定艺人的可指派数量
|
||||||
func GetPendingAssignBySubNums(subNums []string, page int, pageSize int) ([]*dao.ArtistPendingAssignItem, int64, error) {
|
func GetPendingAssignBySubNums(subNums []string, page int, pageSize int) ([]*dao.ArtistPendingAssignItem, int64, error) {
|
||||||
return dao.GetPendingAssignBySubNums(subNums, page, pageSize)
|
return dao.GetPendingAssignBySubNums(subNums, page, pageSize)
|
||||||
@ -160,42 +134,6 @@ func BatchAssignTask(items []*dao.BatchAssignItem) error {
|
|||||||
return dao.BatchAssignTasks(items)
|
return dao.BatchAssignTasks(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePendingCount 修改待发数量
|
|
||||||
func UpdatePendingCount(req *dao.UpdatePendingCountRequest) error {
|
|
||||||
// 待发视频数、图文数、数据分析数不能都为0
|
|
||||||
if req.PendingVideoCount == 0 && req.PendingPostCount == 0 && req.PendingDataCount == 0 {
|
|
||||||
return commonErr.ReturnError(nil, "请输入正确的本次任务数字", "待发视频数、图文数、数据分析数不能都为0")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. 验证艺人是否有有效套餐
|
|
||||||
validArtistIDs, err := GetValidArtistIDs()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查艺人是否在有效列表中
|
|
||||||
isValidArtist := false
|
|
||||||
for _, artistID := range validArtistIDs {
|
|
||||||
if artistID == req.SubNum {
|
|
||||||
isValidArtist = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isValidArtist {
|
|
||||||
return commonErr.ReturnError(nil, "艺人套餐已过期", "该艺人没有有效的套餐,无法修改待发数量")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询艺人当前任务余额,校验是否存在记录(不做数量比较,避免排除手动余额)
|
|
||||||
_, err = dao.GetRemainingPendingBySubNum(req.SubNum)
|
|
||||||
if err != nil {
|
|
||||||
return commonErr.ReturnError(err, "查询艺人任务余额失败", "查询艺人任务余额失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 调用DAO层更新待发数量(DAO 内部已做充足的额度与当月限额校验)
|
|
||||||
return dao.UpdatePendingCount(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRecentAssignRecords 查询最近被指派记录
|
// GetRecentAssignRecords 查询最近被指派记录
|
||||||
func GetRecentAssignRecords(limit int) ([]*bundle.RecentAssigneeItem, error) {
|
func GetRecentAssignRecords(limit int) ([]*bundle.RecentAssigneeItem, error) {
|
||||||
records, err := dao.GetRecentAssignRecords(limit)
|
records, err := dao.GetRecentAssignRecords(limit)
|
||||||
@ -290,7 +228,6 @@ func TerminateTaskByUUID(assignRecordsUUID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BatchTerminateTaskByUUIDs 批量根据指派记录UUID终止任务(实际状态置为已中止)
|
// BatchTerminateTaskByUUIDs 批量根据指派记录UUID终止任务(实际状态置为已中止)
|
||||||
// 返回成功数量、失败数量、失败UUID列表和错误(仅当整体参数错误时返回错误)
|
|
||||||
func BatchTerminateTaskByUUIDs(assignRecordsUUIDs []string) (int, int, []string, error) {
|
func BatchTerminateTaskByUUIDs(assignRecordsUUIDs []string) (int, int, []string, error) {
|
||||||
if len(assignRecordsUUIDs) == 0 {
|
if len(assignRecordsUUIDs) == 0 {
|
||||||
return 0, 0, nil, commonErr.ReturnError(nil, "参数错误", "AssignRecordsUUIDs 不能为空")
|
return 0, 0, nil, commonErr.ReturnError(nil, "参数错误", "AssignRecordsUUIDs 不能为空")
|
||||||
@ -404,65 +341,6 @@ func GetTaskAssignRecordsList(req *dao.TaskAssignRecordsQueryRequest) ([]*dao.Ta
|
|||||||
return recordResponse, total, summary, nil
|
return recordResponse, total, summary, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:查询艺人剩余待发数量(区分套餐/增值,共6个字段)
|
|
||||||
func GetArtistRemainingPending(subNum string) (*dao.ArtistRemainingPendingResponse, error) {
|
|
||||||
if strings.TrimSpace(subNum) == "" {
|
|
||||||
return nil, commonErr.ReturnError(nil, "查询参数错误", "艺人编号不能为空")
|
|
||||||
}
|
|
||||||
return dao.GetRemainingPendingBySubNum(subNum)
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculatePendingFromTaskBalance 从TaskBalance表计算待发任务数量
|
|
||||||
func calculatePendingFromTaskBalance(subNum string) (videoTotal, imageTotal, dataTotal int) {
|
|
||||||
// 查询用户的任务余额
|
|
||||||
tb, err := dao.GetTaskBalanceBySubNum(subNum)
|
|
||||||
if err != nil || tb == nil {
|
|
||||||
return 0, 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算视频类待发数量:总余额 - 消耗数量
|
|
||||||
videoTotal = (tb.MonthlyBundleLimitExpiredVideoNumber - tb.MonthlyBundleLimitExpiredVideoConsumptionNumber) +
|
|
||||||
(tb.MonthlyBundleLimitVideoNumber - tb.MonthlyBundleLimitVideoConsumptionNumber) +
|
|
||||||
(tb.BundleVideoNumber - tb.BundleVideoConsumptionNumber) +
|
|
||||||
(tb.IncreaseVideoNumber - tb.IncreaseVideoConsumptionNumber) +
|
|
||||||
(tb.MonthlyIncreaseLimitVideoNumber - tb.MonthlyIncreaseLimitVideoConsumptionNumber) +
|
|
||||||
(tb.MonthlyIncreaseLimitExpiredVideoNumber - tb.MonthlyIncreaseLimitExpiredVideoConsumptionNumber) +
|
|
||||||
(tb.ManualVideoNumber - tb.ManualVideoConsumptionNumber)
|
|
||||||
if videoTotal < 0 {
|
|
||||||
videoTotal = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算图片类待发数量:总余额 - 消耗数量
|
|
||||||
imageTotal = (tb.MonthlyBundleLimitExpiredImageNumber - tb.MonthlyBundleLimitExpiredImageConsumptionNumber) +
|
|
||||||
(tb.MonthlyBundleLimitImageNumber - tb.MonthlyBundleLimitImageConsumptionNumber) +
|
|
||||||
(tb.BundleImageNumber - tb.BundleImageConsumptionNumber) +
|
|
||||||
(tb.IncreaseImageNumber - tb.IncreaseImageConsumptionNumber) +
|
|
||||||
(tb.MonthlyIncreaseLimitImageNumber - tb.MonthlyIncreaseLimitImageConsumptionNumber) +
|
|
||||||
(tb.MonthlyIncreaseLimitExpiredImageNumber - tb.MonthlyIncreaseLimitExpiredImageConsumptionNumber) +
|
|
||||||
(tb.ManualImageNumber - tb.ManualImageConsumptionNumber)
|
|
||||||
if imageTotal < 0 {
|
|
||||||
imageTotal = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算数据分析类待发数量:总余额 - 消耗数量
|
|
||||||
dataTotal = (tb.MonthlyBundleLimitExpiredDataAnalysisNumber - tb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber) +
|
|
||||||
(tb.MonthlyBundleLimitDataAnalysisNumber - tb.MonthlyBundleLimitDataAnalysisConsumptionNumber) +
|
|
||||||
(tb.BundleDataAnalysisNumber - tb.BundleDataAnalysisConsumptionNumber) +
|
|
||||||
(tb.IncreaseDataAnalysisNumber - tb.IncreaseDataAnalysisConsumptionNumber) +
|
|
||||||
(tb.MonthlyIncreaseLimitDataAnalysisNumber - tb.MonthlyIncreaseLimitDataAnalysisConsumptionNumber) +
|
|
||||||
(tb.MonthlyIncreaseLimitExpiredDataAnalysisNumber - tb.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber) +
|
|
||||||
(tb.ManualDataAnalysisNumber - tb.ManualDataAnalysisConsumptionNumber)
|
|
||||||
if dataTotal < 0 {
|
|
||||||
dataTotal = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return videoTotal, imageTotal, dataTotal
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTaskBalanceEveryMonLogic() {
|
|
||||||
dao.UpdateTaskBalanceEveryMon()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskActualStatusByUUID 根据指派记录UUID查询实际完成状态
|
// GetTaskActualStatusByUUID 根据指派记录UUID查询实际完成状态
|
||||||
func GetTaskActualStatusByUUID(assignRecordsUUID string) (int, error) {
|
func GetTaskActualStatusByUUID(assignRecordsUUID string) (int, error) {
|
||||||
if strings.TrimSpace(assignRecordsUUID) == "" {
|
if strings.TrimSpace(assignRecordsUUID) == "" {
|
||||||
@ -548,10 +426,7 @@ func AddHiddenTaskAssignee(taskAssignee string, taskAssigneeNum string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateTaskWorkLog 创建任务日志记录
|
// CreateTaskWorkLog 创建任务日志记录
|
||||||
// 用于记录任务操作日志,包括加任务、消耗任务、完成任务、任务过期等操作
|
|
||||||
func CreateTaskWorkLog(req *dao.CreateTaskWorkLogRequest) error {
|
func CreateTaskWorkLog(req *dao.CreateTaskWorkLogRequest) error {
|
||||||
// 参数校验已在 DAO 层完成,这里可以添加额外的业务逻辑校验
|
|
||||||
// 例如:校验操作类型是否合法、任务类型是否合法等
|
|
||||||
if req.OperationType < 1 || req.OperationType > 4 {
|
if req.OperationType < 1 || req.OperationType > 4 {
|
||||||
return commonErr.ReturnError(nil, "参数错误", "操作类型必须在1-4之间")
|
return commonErr.ReturnError(nil, "参数错误", "操作类型必须在1-4之间")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package cron
|
package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"micro-bundle/internal/logic"
|
"micro-bundle/internal/logic"
|
||||||
|
|
||||||
@ -11,14 +10,13 @@ import (
|
|||||||
func InitCronJob() {
|
func InitCronJob() {
|
||||||
c := cron.New(cron.WithSeconds())
|
c := cron.New(cron.WithSeconds())
|
||||||
|
|
||||||
// 避免冲突,任务余额每月更新定时任务 - 每月1号1点执行
|
spec := "0 0 0 1 * *"
|
||||||
taskBalanceSpec := "0 0 1 1 * *"
|
|
||||||
_, err := c.AddFunc(taskBalanceSpec, func() {
|
_, err := c.AddFunc(spec, func() {
|
||||||
log.Printf("执行任务余额每月数据更新")
|
log.Printf("执行余量每月数据更新")
|
||||||
logic.UpdateTaskBalanceEveryMonLogic()
|
logic.UpdateBundleBalance()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("添加任务余额每月数据更新定时任务失败", err)
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user