Compare commits
No commits in common. "493a2cad43887964bd893f6657d52505a0b8d48f" and "e979f3950b181756c0b51f26822d293e7402b4e5" have entirely different histories.
493a2cad43
...
e979f3950b
@ -1393,14 +1393,8 @@ func UpdateTaskRecordsByAssigneeNum(taskAssigneeNum string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPendingTaskList 查询待指派任务记录(按有效艺人过滤)
|
// GetPendingTaskList 查询待指派任务记录(按有效艺人过滤)
|
||||||
// 说明:使用LEFT JOIN联表查询TaskManagement和TaskBalance表,直接在SQL层计算待发任务数量
|
// 说明:由于待发视频/图文/数据以及进行中/已完成数量来自不同表,这里仅返回基础字段,后续由逻辑层计算并排序
|
||||||
func GetPendingTaskList(req *TaskQueryRequest, validArtist []ValidArtistInfo) ([]*TaskQueryResponse, int64, error) {
|
func GetPendingTaskList(req *TaskQueryRequest, validArtist []ValidArtistInfo) ([]*TaskQueryResponse, int64, error) {
|
||||||
// 首先为有TaskBalance记录但没有TaskManagement记录的有效艺人创建TaskManagement记录
|
|
||||||
if err := CreateMissingTaskManagementRecords(validArtist); err != nil {
|
|
||||||
zap.L().Error("创建缺失的TaskManagement记录失败", zap.Error(err))
|
|
||||||
// 记录错误但不中断流程,继续执行查询
|
|
||||||
}
|
|
||||||
|
|
||||||
// 提取有效艺人的艺人编号(sub_num)
|
// 提取有效艺人的艺人编号(sub_num)
|
||||||
subNums := make([]string, 0, len(validArtist))
|
subNums := make([]string, 0, len(validArtist))
|
||||||
for _, a := range validArtist {
|
for _, a := range validArtist {
|
||||||
@ -1413,122 +1407,42 @@ func GetPendingTaskList(req *TaskQueryRequest, validArtist []ValidArtistInfo) ([
|
|||||||
return []*TaskQueryResponse{}, 0, nil
|
return []*TaskQueryResponse{}, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建联表查询,计算待发任务数量
|
// 构建 TaskManagement 的基础查询
|
||||||
now := time.Now()
|
query := app.ModuleClients.TaskBenchDB.Model(&model.TaskManagement{}).
|
||||||
selectFields := `
|
Select("sub_num, tel_num, artist_name, last_task_assignee, task_assignee_num").
|
||||||
tm.sub_num,
|
Where("sub_num IN ?", subNums)
|
||||||
tm.tel_num,
|
|
||||||
tm.artist_name,
|
|
||||||
tm.last_task_assignee,
|
|
||||||
tm.task_assignee_num,
|
|
||||||
tm.progress_count AS progress_count,
|
|
||||||
tm.complete_count AS complete_count,
|
|
||||||
COALESCE(
|
|
||||||
(tb.monthly_bundle_limit_expired_video_number - tb.monthly_bundle_limit_expired_video_consumption_number) +
|
|
||||||
(tb.monthly_bundle_limit_video_number - tb.monthly_bundle_limit_video_consumption_number) +
|
|
||||||
(tb.bundle_video_number - tb.bundle_video_consumption_number) +
|
|
||||||
(tb.increase_video_number - tb.increase_video_consumption_number) +
|
|
||||||
(tb.monthly_increase_limit_video_number - tb.monthly_increase_limit_video_consumption_number) +
|
|
||||||
(tb.monthly_increase_limit_expired_video_number - tb.monthly_increase_limit_expired_video_consumption_number) +
|
|
||||||
(tb.manual_video_number - tb.manual_video_consumption_number),
|
|
||||||
0
|
|
||||||
) AS pending_video_count,
|
|
||||||
COALESCE(
|
|
||||||
(tb.monthly_bundle_limit_expired_image_number - tb.monthly_bundle_limit_expired_image_consumption_number) +
|
|
||||||
(tb.monthly_bundle_limit_image_number - tb.monthly_bundle_limit_image_consumption_number) +
|
|
||||||
(tb.bundle_image_number - tb.bundle_image_consumption_number) +
|
|
||||||
(tb.increase_image_number - tb.increase_image_consumption_number) +
|
|
||||||
(tb.monthly_increase_limit_image_number - tb.monthly_increase_limit_image_consumption_number) +
|
|
||||||
(tb.monthly_increase_limit_expired_image_number - tb.monthly_increase_limit_expired_image_consumption_number) +
|
|
||||||
(tb.manual_image_number - tb.manual_image_consumption_number),
|
|
||||||
0
|
|
||||||
) AS pending_post_count,
|
|
||||||
COALESCE(
|
|
||||||
(tb.monthly_bundle_limit_expired_data_analysis_number - tb.monthly_bundle_limit_expired_data_analysis_consumption_number) +
|
|
||||||
(tb.monthly_bundle_limit_data_analysis_number - tb.monthly_bundle_limit_data_analysis_consumption_number) +
|
|
||||||
(tb.bundle_data_analysis_number - tb.bundle_data_analysis_consumption_number) +
|
|
||||||
(tb.increase_data_analysis_number - tb.increase_data_analysis_consumption_number) +
|
|
||||||
(tb.monthly_increase_limit_data_analysis_number - tb.monthly_increase_limit_data_analysis_consumption_number) +
|
|
||||||
(tb.monthly_increase_limit_expired_data_analysis_number - tb.monthly_increase_limit_expired_data_analysis_consumption_number) +
|
|
||||||
(tb.manual_data_analysis_number - tb.manual_data_analysis_consumption_number),
|
|
||||||
0
|
|
||||||
) AS pending_data_count`
|
|
||||||
|
|
||||||
query := app.ModuleClients.TaskBenchDB.Table("task_management tm").
|
|
||||||
Select(selectFields).
|
|
||||||
Joins(`LEFT JOIN task_balance_new tb ON tm.sub_num = tb.sub_num AND
|
|
||||||
((tb.start_at <= ? AND tb.expired_at >= ?) OR
|
|
||||||
tb.id = (SELECT id FROM task_balance_new tb2 WHERE tb2.sub_num = tm.sub_num ORDER BY tb2.start_at DESC LIMIT 1))`, now, now).
|
|
||||||
Where("tm.sub_num IN ?", subNums)
|
|
||||||
|
|
||||||
// 关键词搜索(支持 sub_num / tel_num / artist_name)
|
// 关键词搜索(支持 sub_num / tel_num / artist_name)
|
||||||
if req.Keyword != "" {
|
if req.Keyword != "" {
|
||||||
like := "%" + req.Keyword + "%"
|
like := "%" + req.Keyword + "%"
|
||||||
query = query.Where("(tm.sub_num LIKE ? OR tm.tel_num LIKE ? OR tm.artist_name LIKE ?)", like, like, like)
|
query = query.Where("(sub_num LIKE ? OR tel_num LIKE ? OR artist_name LIKE ?)", like, like, like)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理排序
|
// 执行查询(不做排序与分页,交由逻辑层处理)
|
||||||
if req.SortBy != "" && req.SortType != "" {
|
var tmList []model.TaskManagement
|
||||||
sortType := req.SortType
|
if err := query.Find(&tmList).Error; err != nil {
|
||||||
if sortType != "asc" && sortType != "desc" && sortType != "ASC" && sortType != "DESC" {
|
|
||||||
sortType = "DESC"
|
|
||||||
}
|
|
||||||
|
|
||||||
switch req.SortBy {
|
|
||||||
case "pending_video_count", "pendingVideoCount":
|
|
||||||
query = query.Order(fmt.Sprintf("pending_video_count %s", sortType))
|
|
||||||
case "pending_post_count", "pendingPostCount":
|
|
||||||
query = query.Order(fmt.Sprintf("pending_post_count %s", sortType))
|
|
||||||
case "pending_data_count", "pendingDataCount":
|
|
||||||
query = query.Order(fmt.Sprintf("pending_data_count %s", sortType))
|
|
||||||
case "progress_count", "progressCount":
|
|
||||||
query = query.Order(fmt.Sprintf("progress_task_count %s", sortType))
|
|
||||||
case "complete_count", "completeCount":
|
|
||||||
query = query.Order(fmt.Sprintf("complete_task_count %s", sortType))
|
|
||||||
default:
|
|
||||||
query = query.Order("tm.sub_num ASC")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
query = query.Order("tm.sub_num ASC")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 先查询总数(不分页)
|
|
||||||
var totalCount int64
|
|
||||||
countQuery := app.ModuleClients.TaskBenchDB.Table("task_management tm").
|
|
||||||
Joins(`LEFT JOIN task_balance_new tb ON tm.sub_num = tb.sub_num AND
|
|
||||||
((tb.start_at <= ? AND tb.expired_at >= ?) OR
|
|
||||||
tb.id = (SELECT id FROM task_balance_new tb2 WHERE tb2.sub_num = tm.sub_num ORDER BY tb2.start_at DESC LIMIT 1))`, now, now).
|
|
||||||
Where("tm.sub_num IN ?", subNums)
|
|
||||||
|
|
||||||
if req.Keyword != "" {
|
|
||||||
like := "%" + req.Keyword + "%"
|
|
||||||
countQuery = countQuery.Where("(tm.sub_num LIKE ? OR tm.tel_num LIKE ? OR tm.artist_name LIKE ?)", like, like, like)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := countQuery.Count(&totalCount).Error; err != nil {
|
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询待指派任务记录总数失败", "查询待指派任务记录总数失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理分页
|
|
||||||
if req.PageSize > 0 && req.Page > 0 {
|
|
||||||
offset := (req.Page - 1) * req.PageSize
|
|
||||||
query = query.Offset(offset).Limit(req.PageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行查询
|
|
||||||
var results []TaskQueryResponse
|
|
||||||
if err := query.Scan(&results).Error; err != nil {
|
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询待指派任务记录失败", "查询待指派任务记录失败: ")
|
return nil, 0, commonErr.ReturnError(err, "查询待指派任务记录失败", "查询待指派任务记录失败: ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建已存在的 sub_num 集合,用于补充缺失的有效艺人
|
// 构建已存在的 sub_num 集合,用于补充缺失的有效艺人
|
||||||
existingSubNums := make(map[string]struct{}, len(results))
|
existingSubNums := make(map[string]struct{}, len(tmList))
|
||||||
for _, r := range results {
|
for _, t := range tmList {
|
||||||
existingSubNums[r.SubNum] = struct{}{}
|
existingSubNums[t.SubNum] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 映射为响应结构(基础字段)
|
||||||
|
resp := make([]*TaskQueryResponse, 0, len(tmList)+len(validArtist))
|
||||||
|
for _, t := range tmList {
|
||||||
|
resp = append(resp, &TaskQueryResponse{
|
||||||
|
SubNum: t.SubNum,
|
||||||
|
TelNum: t.TelNum,
|
||||||
|
ArtistName: t.ArtistName,
|
||||||
|
LastTaskAssignee: t.LastTaskAssignee,
|
||||||
|
TaskAssigneeNum: t.TaskAssigneeNum,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 追加:对在 TaskManagement 中不存在的有效艺人构建基础记录
|
// 追加:对在 TaskManagement 中不存在的有效艺人构建基础记录
|
||||||
var additionalResults []*TaskQueryResponse
|
|
||||||
for _, a := range validArtist {
|
for _, a := range validArtist {
|
||||||
if a.CustomerNum == "" {
|
if a.CustomerNum == "" {
|
||||||
continue
|
continue
|
||||||
@ -1545,175 +1459,17 @@ func GetPendingTaskList(req *TaskQueryRequest, validArtist []ValidArtistInfo) ([
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
additionalResults = append(additionalResults, &TaskQueryResponse{
|
resp = append(resp, &TaskQueryResponse{
|
||||||
SubNum: a.CustomerNum,
|
SubNum: a.CustomerNum,
|
||||||
TelNum: a.UserPhoneNumber,
|
TelNum: a.UserPhoneNumber,
|
||||||
ArtistName: a.UserName,
|
ArtistName: a.UserName,
|
||||||
LastTaskAssignee: "",
|
LastTaskAssignee: "",
|
||||||
TaskAssigneeNum: "",
|
TaskAssigneeNum: "",
|
||||||
PendingVideoCount: 0,
|
|
||||||
PendingPostCount: 0,
|
|
||||||
PendingDataCount: 0,
|
|
||||||
ProgressTaskCount: 0,
|
|
||||||
CompleteTaskCount: 0,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并结果
|
// 统计总数(分页前)
|
||||||
resp := make([]*TaskQueryResponse, 0, len(results)+len(additionalResults))
|
total := int64(len(resp))
|
||||||
for i := range results {
|
|
||||||
// 确保待发数量不为负数
|
|
||||||
if results[i].PendingVideoCount < 0 {
|
|
||||||
results[i].PendingVideoCount = 0
|
|
||||||
}
|
|
||||||
if results[i].PendingPostCount < 0 {
|
|
||||||
results[i].PendingPostCount = 0
|
|
||||||
}
|
|
||||||
if results[i].PendingDataCount < 0 {
|
|
||||||
results[i].PendingDataCount = 0
|
|
||||||
}
|
|
||||||
resp = append(resp, &results[i])
|
|
||||||
}
|
|
||||||
resp = append(resp, additionalResults...)
|
|
||||||
|
|
||||||
fmt.Println(resp)
|
|
||||||
|
|
||||||
// 更新总数(包含补充的艺人)
|
|
||||||
total := totalCount + int64(len(additionalResults))
|
|
||||||
|
|
||||||
return resp, total, nil
|
return resp, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateMissingTaskManagementRecords 为有TaskBalance记录但没有TaskManagement记录的有效艺人创建TaskManagement记录
|
|
||||||
// 说明:检查有效艺人列表,如果艺人在TaskBalance表中有记录但在TaskManagement表中没有记录,则创建记录
|
|
||||||
// 新创建的记录中的待发任务数量将从TaskBalance表中计算得出,而不是默认为0
|
|
||||||
func CreateMissingTaskManagementRecords(validArtist []ValidArtistInfo) error {
|
|
||||||
if len(validArtist) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 提取有效艺人的艺人编号(sub_num)
|
|
||||||
subNums := make([]string, 0, len(validArtist))
|
|
||||||
artistMap := make(map[string]ValidArtistInfo)
|
|
||||||
for _, a := range validArtist {
|
|
||||||
if a.CustomerNum != "" {
|
|
||||||
subNums = append(subNums, a.CustomerNum)
|
|
||||||
artistMap[a.CustomerNum] = a
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(subNums) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询已存在的TaskManagement记录
|
|
||||||
var existingTaskManagement []model.TaskManagement
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Where("sub_num IN ?", subNums).Find(&existingTaskManagement).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "查询现有任务管理记录失败", "查询现有任务管理记录失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建已存在的sub_num集合
|
|
||||||
existingSubNums := make(map[string]struct{})
|
|
||||||
for _, tm := range existingTaskManagement {
|
|
||||||
existingSubNums[tm.SubNum] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询有TaskBalance记录的艺人
|
|
||||||
now := time.Now()
|
|
||||||
var taskBalances []model.TaskBalance
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Where("sub_num IN ? AND ((start_at <= ? AND expired_at >= ?) OR id IN (SELECT MAX(id) FROM task_balance_new WHERE sub_num IN ? GROUP BY sub_num))",
|
|
||||||
subNums, now, now, subNums).Find(&taskBalances).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "查询任务余额记录失败", "查询任务余额记录失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建有TaskBalance记录的sub_num集合
|
|
||||||
balanceSubNums := make(map[string]model.TaskBalance)
|
|
||||||
for _, tb := range taskBalances {
|
|
||||||
balanceSubNums[tb.SubNum] = tb
|
|
||||||
}
|
|
||||||
|
|
||||||
// 找出需要创建TaskManagement记录的艺人(有TaskBalance记录但没有TaskManagement记录)
|
|
||||||
var recordsToCreate []model.TaskManagement
|
|
||||||
for _, artist := range validArtist {
|
|
||||||
if artist.CustomerNum == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否已存在TaskManagement记录
|
|
||||||
if _, exists := existingSubNums[artist.CustomerNum]; exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否有TaskBalance记录
|
|
||||||
tb, hasBalance := balanceSubNums[artist.CustomerNum]
|
|
||||||
if !hasBalance {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算待发任务数量(使用与GetPendingTaskList相同的计算逻辑)
|
|
||||||
pendingVideoCount := (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)
|
|
||||||
|
|
||||||
pendingPostCount := (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)
|
|
||||||
|
|
||||||
pendingDataCount := (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 pendingVideoCount < 0 {
|
|
||||||
pendingVideoCount = 0
|
|
||||||
}
|
|
||||||
if pendingPostCount < 0 {
|
|
||||||
pendingPostCount = 0
|
|
||||||
}
|
|
||||||
if pendingDataCount < 0 {
|
|
||||||
pendingDataCount = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 只有当至少有一种类型的待发任务数量大于0时才创建记录
|
|
||||||
if pendingVideoCount > 0 || pendingPostCount > 0 || pendingDataCount > 0 {
|
|
||||||
newRecord := model.TaskManagement{
|
|
||||||
SubNum: artist.CustomerNum,
|
|
||||||
TelNum: artist.UserPhoneNumber,
|
|
||||||
ArtistName: artist.UserName,
|
|
||||||
LastTaskAssignee: "",
|
|
||||||
TaskAssigneeNum: "",
|
|
||||||
ProgressCount: 0,
|
|
||||||
CompleteCount: 0,
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
UpdatedAt: time.Now(),
|
|
||||||
}
|
|
||||||
recordsToCreate = append(recordsToCreate, newRecord)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量创建记录
|
|
||||||
if len(recordsToCreate) > 0 {
|
|
||||||
if err := app.ModuleClients.TaskBenchDB.Create(&recordsToCreate).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "批量创建任务管理记录失败", "批量创建任务管理记录失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 记录日志
|
|
||||||
zap.L().Info("成功为有效艺人创建TaskManagement记录",
|
|
||||||
zap.Int("创建记录数", len(recordsToCreate)),
|
|
||||||
zap.Any("创建的记录", recordsToCreate))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"micro-bundle/internal/dao"
|
"micro-bundle/internal/dao"
|
||||||
commonErr "micro-bundle/pkg/err"
|
commonErr "micro-bundle/pkg/err"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,13 +70,110 @@ func GetPendingTaskList(req *dao.TaskQueryRequest) ([]*dao.TaskQueryResponse, in
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 调用DAO层查询待指派任务记录(已包含联表查询和排序分页)
|
// 2. 调用DAO层查询待指派任务记录
|
||||||
recordResponse, total, err := dao.GetPendingTaskList(req, validArtist)
|
record, total, err := dao.GetPendingTaskList(req, validArtist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 直接返回DAO层的结果(已经包含了所有计算和排序分页逻辑)
|
// 3. 转换为响应结构体
|
||||||
|
var recordResponse []*dao.TaskQueryResponse
|
||||||
|
for _, record := range record {
|
||||||
|
// 从TaskBalance表计算待发任务数量:任务余额 - 消耗数量
|
||||||
|
videoTotal, imageTotal, dataTotal := calculatePendingFromTaskBalance(record.SubNum)
|
||||||
|
|
||||||
|
// 根据 SubNum 查询对应的艺人正在进行中的任务和已完成任务数量
|
||||||
|
progressTaskCount, completeTaskCount, err := dao.GetArtistTaskStatsBySubNum(record.SubNum)
|
||||||
|
if err != nil {
|
||||||
|
recordResponse = append(recordResponse, &dao.TaskQueryResponse{
|
||||||
|
SubNum: record.SubNum,
|
||||||
|
TelNum: record.TelNum,
|
||||||
|
ArtistName: record.ArtistName,
|
||||||
|
TaskAssigneeNum: record.TaskAssigneeNum,
|
||||||
|
PendingPostCount: imageTotal,
|
||||||
|
PendingVideoCount: videoTotal,
|
||||||
|
PendingDataCount: dataTotal,
|
||||||
|
ProgressTaskCount: 0,
|
||||||
|
CompleteTaskCount: 0,
|
||||||
|
LastTaskAssignee: record.LastTaskAssignee,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
recordResponse = append(recordResponse, &dao.TaskQueryResponse{
|
||||||
|
SubNum: record.SubNum,
|
||||||
|
TelNum: record.TelNum,
|
||||||
|
ArtistName: record.ArtistName,
|
||||||
|
TaskAssigneeNum: record.TaskAssigneeNum,
|
||||||
|
PendingPostCount: imageTotal,
|
||||||
|
PendingVideoCount: videoTotal,
|
||||||
|
PendingDataCount: dataTotal,
|
||||||
|
ProgressTaskCount: progressTaskCount,
|
||||||
|
CompleteTaskCount: completeTaskCount,
|
||||||
|
LastTaskAssignee: record.LastTaskAssignee,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 处理待发数量相关的排序(在Logic层处理,因为这些数据从TaskBalance表计算)
|
||||||
|
if req.SortBy != "" && req.SortType != "" {
|
||||||
|
sortType := req.SortType
|
||||||
|
if sortType != "asc" && sortType != "desc" && sortType != "ASC" && sortType != "DESC" {
|
||||||
|
sortType = "DESC"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch req.SortBy {
|
||||||
|
case "pending_video_count", "pendingVideoCount":
|
||||||
|
sort.Slice(recordResponse, func(i, j int) bool {
|
||||||
|
if strings.ToUpper(sortType) == "ASC" {
|
||||||
|
return recordResponse[i].PendingVideoCount < recordResponse[j].PendingVideoCount
|
||||||
|
}
|
||||||
|
return recordResponse[i].PendingVideoCount > recordResponse[j].PendingVideoCount
|
||||||
|
})
|
||||||
|
case "pending_post_count", "pendingPostCount":
|
||||||
|
sort.Slice(recordResponse, func(i, j int) bool {
|
||||||
|
if strings.ToUpper(sortType) == "ASC" {
|
||||||
|
return recordResponse[i].PendingPostCount < recordResponse[j].PendingPostCount
|
||||||
|
}
|
||||||
|
return recordResponse[i].PendingPostCount > recordResponse[j].PendingPostCount
|
||||||
|
})
|
||||||
|
case "pending_data_count", "pendingDataCount":
|
||||||
|
sort.Slice(recordResponse, func(i, j int) bool {
|
||||||
|
if strings.ToUpper(sortType) == "ASC" {
|
||||||
|
return recordResponse[i].PendingDataCount < recordResponse[j].PendingDataCount
|
||||||
|
}
|
||||||
|
return recordResponse[i].PendingDataCount > recordResponse[j].PendingDataCount
|
||||||
|
})
|
||||||
|
case "progress_count", "progressCount":
|
||||||
|
sort.Slice(recordResponse, func(i, j int) bool {
|
||||||
|
if strings.ToUpper(sortType) == "ASC" {
|
||||||
|
return recordResponse[i].ProgressTaskCount < recordResponse[j].ProgressTaskCount
|
||||||
|
}
|
||||||
|
return recordResponse[i].ProgressTaskCount > recordResponse[j].ProgressTaskCount
|
||||||
|
})
|
||||||
|
case "complete_count", "completeCount":
|
||||||
|
sort.Slice(recordResponse, func(i, j int) bool {
|
||||||
|
if strings.ToUpper(sortType) == "ASC" {
|
||||||
|
return recordResponse[i].CompleteTaskCount < recordResponse[j].CompleteTaskCount
|
||||||
|
}
|
||||||
|
return recordResponse[i].CompleteTaskCount > recordResponse[j].CompleteTaskCount
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 分页(在排序后进行)
|
||||||
|
total = int64(len(recordResponse))
|
||||||
|
if req.PageSize > 0 && req.Page > 0 {
|
||||||
|
offset := (req.Page - 1) * req.PageSize
|
||||||
|
if offset < len(recordResponse) {
|
||||||
|
end := offset + req.PageSize
|
||||||
|
if end > len(recordResponse) {
|
||||||
|
end = len(recordResponse)
|
||||||
|
}
|
||||||
|
recordResponse = recordResponse[offset:end]
|
||||||
|
} else {
|
||||||
|
recordResponse = []*dao.TaskQueryResponse{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return recordResponse, total, nil
|
return recordResponse, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,43 +395,28 @@ func GetArtistRemainingPending(subNum string) (*dao.ArtistRemainingPendingRespon
|
|||||||
// calculatePendingFromTaskBalance 从TaskBalance表计算待发任务数量
|
// calculatePendingFromTaskBalance 从TaskBalance表计算待发任务数量
|
||||||
func calculatePendingFromTaskBalance(subNum string) (videoTotal, imageTotal, dataTotal int) {
|
func calculatePendingFromTaskBalance(subNum string) (videoTotal, imageTotal, dataTotal int) {
|
||||||
// 查询用户的任务余额
|
// 查询用户的任务余额
|
||||||
tb, err := dao.GetTaskBalanceBySubNum(subNum)
|
taskBalance, err := dao.GetTaskBalanceBySubNum(subNum)
|
||||||
if err != nil || tb == nil {
|
if err != nil || taskBalance == nil {
|
||||||
return 0, 0, 0
|
return 0, 0, 0
|
||||||
}
|
}
|
||||||
|
// 计算套餐与增值剩余待发数量(非限制 + 限制非过期 + 限制会过期)
|
||||||
|
bundleVideo, bundleImage, bundleData := dao.CalculateBundleBalances(taskBalance)
|
||||||
|
increaseVideo, increaseImage, increaseData := dao.CalculateIncreaseBalances(taskBalance)
|
||||||
|
|
||||||
// 计算视频类待发数量:总余额 - 消耗数量
|
// 计算视频类待发数量:总余额 - 消耗数量
|
||||||
videoTotal = (tb.MonthlyBundleLimitExpiredVideoNumber - tb.MonthlyBundleLimitExpiredVideoConsumptionNumber) +
|
videoTotal = bundleVideo + increaseVideo
|
||||||
(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 {
|
if videoTotal < 0 {
|
||||||
videoTotal = 0
|
videoTotal = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算图片类待发数量:总余额 - 消耗数量
|
// 计算图片类待发数量:总余额 - 消耗数量
|
||||||
imageTotal = (tb.MonthlyBundleLimitExpiredImageNumber - tb.MonthlyBundleLimitExpiredImageConsumptionNumber) +
|
imageTotal = bundleImage + increaseImage
|
||||||
(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 {
|
if imageTotal < 0 {
|
||||||
imageTotal = 0
|
imageTotal = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算数据分析类待发数量:总余额 - 消耗数量
|
// 计算图片类待发数量:总余额 - 消耗数量
|
||||||
dataTotal = (tb.MonthlyBundleLimitExpiredDataAnalysisNumber - tb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber) +
|
dataTotal = bundleData + increaseData
|
||||||
(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 {
|
if dataTotal < 0 {
|
||||||
dataTotal = 0
|
dataTotal = 0
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user