@ -89,9 +89,9 @@ newest_month AS (
active_windows AS (
SELECT
u . id AS user_id ,
u . tel_num COLLATE utf8mb4_0900_ai_ci AS phone ,
u . tel_num AS phone ,
bor . uuid AS order_uuid ,
bor . customer_num COLLATE utf8mb4_0900_ai_ci AS customer_num ,
bor . customer_num ,
bb . start_at ,
bb . expired_at ,
bb . bundle_video_number , bb . bundle_limit_video_number , bb . bundle_limit_video_expired_number ,
@ -106,7 +106,7 @@ active_windows AS (
bb . bundle_competitive_number , bb . bundle_limit_competitive_number , bb . bundle_limit_competitive_expired_number ,
bb . increase_competitive_number , bb . increase_limit_competitive_number , bb . increase_limit_competitive_expired_number ,
bb . manual_competitive_number , bb . manual_competitive_consumption_number ,
rn . name COLLATE utf8mb4_0900_ai_ci AS user_name
rn . name AS user_name
FROM ` + " ` micro - account ` . ` user ` " + ` u
INNER JOIN ` + " ` micro - account ` .real_name" + ` rn ON rn . id = u . real_name_id AND rn . name IS NOT NULL AND rn . deleted_at = 0
INNER JOIN bundle_activate bc ON bc . user_id = u . id AND bc . activate = 2
@ -188,7 +188,7 @@ cw_agg AS (
COUNT ( CASE WHEN cw . work_category = 2 AND cw . cost = 1 AND cw . deleted_at = 0 AND ( cw . origin_uuid = ' ' OR cw . origin_uuid IS NULL ) AND cw . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS released_video_consumed ,
COUNT ( CASE WHEN cw . work_category = 1 AND cw . cost = 1 AND cw . deleted_at = 0 AND ( cw . origin_uuid = ' ' OR cw . origin_uuid IS NULL ) AND cw . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS released_post_consumed
FROM active_windows aw
LEFT JOIN cast_work cw ON cw . artist_phone = aw . phone
LEFT JOIN cast_work cw ON cw . artist_phone COLLATE utf8mb4_general_ci = aw . phone COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -196,10 +196,10 @@ cw_agg AS (
cwa_agg AS (
SELECT
aw . user_id ,
COUNT ( CASE WHEN cwa . deleted_at = 0 AND cwa . work_analysis_status != 1 AND cwa . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_data_count ,
COUNT ( CASE WHEN cwa . cost = 1 AND cwa . deleted_at = 0 AND cwa . work_analysis_status != 1 AND cwa . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS released_data_consumed
COUNT ( CASE WHEN cwa . deleted_at = 0 AND ( cwa . work_analysis_status IS NULL OR cwa . work_analysis_status != 1 ) AND cwa . submit_time BETWEEN UNIX_TIMESTAMP ( aw . start_at ) AND UNIX_TIMESTAMP ( aw . expired_at ) THEN 1 END ) AS uploaded_data_count ,
COUNT ( CASE WHEN cwa . cost = 1 AND cwa . deleted_at = 0 AND ( cwa . work_analysis_status IS NULL OR cwa . work_analysis_status != 1 ) AND cwa . submit_time BETWEEN UNIX_TIMESTAMP ( aw . start_at ) AND UNIX_TIMESTAMP ( aw . expired_at ) THEN 1 END ) AS released_data_consumed
FROM active_windows aw
LEFT JOIN cast_work_analysis cwa ON cwa . artist_phone = aw . phone
LEFT JOIN cast_work_analysis cwa ON cwa . artist_phone COLLATE utf8mb4_general_ci = aw . phone COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -210,7 +210,7 @@ ccr_agg AS (
COUNT ( CASE WHEN ccr . deleted_at = 0 AND ccr . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_report_count ,
COUNT ( CASE WHEN ccr . cost = 1 AND ccr . deleted_at = 0 AND ccr . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS released_report_consumed
FROM active_windows aw
LEFT JOIN cast_competitive_report ccr ON ccr . artist_phone = aw . phone
LEFT JOIN cast_competitive_report ccr ON ccr . artist_phone COLLATE utf8mb4_general_ci = aw . phone COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -220,7 +220,7 @@ cvs_agg AS (
aw . user_id ,
COUNT ( cvs . artist_uuid ) AS uploaded_video_script_count
FROM active_windows aw
LEFT JOIN cast_video_script cvs ON CAST ( aw . user_id AS CHAR ) = cvs . artist_uuid
LEFT JOIN cast_video_script cvs ON CAST ( aw . user_id AS CHAR ) COLLATE utf8mb4_general_ci = cvs . artist_uuid COLLATE utf8mb4_general_ci
AND cvs . deleted_at = 0
AND cvs . created_at BETWEEN UNIX_TIMESTAMP ( CONVERT_TZ ( aw . start_at , ' + 00 : 00 ' , ' + 00 : 00 ' ) )
AND UNIX_TIMESTAMP ( CONVERT_TZ ( aw . expired_at , ' + 00 : 00 ' , ' + 00 : 00 ' ) )
@ -234,7 +234,7 @@ tar_agg AS (
COUNT ( CASE WHEN tar . status = 1 AND tar . deleted_at = 0 AND tar . created_at BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS progress_task_count ,
COUNT ( CASE WHEN tar . status = 2 AND tar . deleted_at = 0 AND tar . created_at BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS complete_task_count
FROM active_windows aw
LEFT JOIN ` + " ` " + taskSchema + " ` " + ` . task_assign_records tar ON tar . sub_num = aw . customer_num
LEFT JOIN ` + " ` " + taskSchema + " ` " + ` . task_assign_records tar ON tar . sub_num COLLATE utf8mb4_general_ci = aw . customer_num COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -273,7 +273,7 @@ assigned_pending_agg AS (
END
) , 0 ) AS assigned_report_count
FROM active_windows aw
LEFT JOIN ` + " ` " + taskSchema + " ` " + ` . task_assign_records tar ON tar . sub_num = aw . customer_num
LEFT JOIN ` + " ` " + taskSchema + " ` " + ` . task_assign_records tar ON tar . sub_num COLLATE utf8mb4_general_ci = aw . customer_num COLLATE utf8mb4_general_ci
AND tar . actual_status IN ( 1 , 3 )
AND tar . deleted_at = 0
AND tar . created_at BETWEEN aw . start_at AND aw . expired_at
@ -325,16 +325,9 @@ LEFT JOIN assigned_pending_agg apa ON apa.user_id = aw.user_id`
whereClause = " WHERE " + strings . Join ( whereParts , " AND " )
}
// 使用事务固定同一连接,仅对本次查询的 session 设置 collation, 不影响其他接口
tx := app . ModuleClients . BundleDB . Begin ( )
defer tx . Rollback ( )
if err := tx . Exec ( "SET NAMES utf8mb4 COLLATE utf8mb4_0900_ai_ci" ) . Error ; err != nil {
return nil , 0 , commonErr . ReturnError ( err , "设置字符集失败" , "设置字符集失败: " )
}
countSQL := cte + " SELECT COUNT(DISTINCT aw.customer_num) " + fromClause + whereClause
var total int64
if err := tx . Raw ( countSQL , args ... ) . Scan ( & total ) . Error ; err != nil {
if err := app . ModuleClients . BundleDB . Raw ( countSQL , args ... ) . Scan ( & total ) . Error ; err != nil {
return nil , 0 , commonErr . ReturnError ( err , "查询总数失败" , "查询艺人上传统计总数失败: " )
}
@ -433,7 +426,7 @@ LEFT JOIN assigned_pending_agg apa ON apa.user_id = aw.user_id`
}
items := make ( [ ] dto . ArtistUploadStatsItem , 0 )
if err := tx . Raw ( selectSQL , listArgs ... ) . Scan ( & items ) . Error ; err != nil {
if err := app. ModuleClients . BundleDB . Raw ( selectSQL , listArgs ... ) . Scan ( & items ) . Error ; err != nil {
return nil , 0 , commonErr . ReturnError ( err , "查询艺人余额与上传数据失败" , "查询艺人余额与上传数据失败: " )
}
@ -481,20 +474,20 @@ newest_month AS (
active_windows AS (
SELECT
u . id AS user_id ,
u . tel_num COLLATE utf8mb4_0900_ai_ci AS phone ,
u . tel_num AS phone ,
bor . uuid AS order_uuid ,
bor . customer_num COLLATE utf8mb4_0900_ai_ci AS customer_num ,
bor . customer_num ,
bb . start_at ,
bb . expired_at ,
bb . manual_video_number , bb . manual_video_consumption_number ,
bb . manual_image_number , bb . manual_image_consumption_number ,
bb . manual_data_analysis_number , bb . manual_data_analysis_consumption_number ,
bb . manual_competitive_number , bb . manual_competitive_consumption_number ,
rn . name COLLATE utf8mb4_0900_ai_ci AS user_name
rn . name AS user_name
FROM ` + " ` micro - account ` . ` user ` " + ` u
INNER JOIN ` + " ` micro - account ` .real_name" + ` rn ON rn . id = u . real_name_id AND rn . name IS NOT NULL AND rn . deleted_at = 0
INNER JOIN ` + " ` micro - account ` .real_name" + ` rn ON rn . id = u . real_name_id AND rn . name IS NOT NULL
INNER JOIN bundle_activate bc ON bc . user_id = u . id AND bc . activate = 2
INNER JOIN latest_bor bor ON bor . customer_id = u . id AND u . deleted_at = 0
INNER JOIN latest_bor bor ON bor . customer_id = u . id
INNER JOIN newest_month nm ON nm . user_id = u . id
INNER JOIN bundle_balance bb ON bb . user_id = u . id AND bb . order_uuid = bor . uuid AND bb . month = nm . month AND bb . deleted_at IS NULL
WHERE u . deleted_at = 0
@ -563,14 +556,14 @@ balance_sum AS (
GROUP BY bb2 . user_id
) ,
-- 6. 作品统计 ( 只统计 origin_uuid 为空的作品 )
-- 6. 作品统计
cw_agg AS (
SELECT
aw . user_id ,
COUNT ( CASE WHEN cw . work_category = 2 AND cw . deleted_at = 0 AND ( cw . origin_uuid = ' ' OR cw . origin_uuid IS NULL ) AND cw . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_video_count ,
COUNT ( CASE WHEN cw . work_category = 1 AND cw . deleted_at = 0 AND ( cw . origin_uuid = ' ' OR cw . origin_uuid IS NULL ) AND cw . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_post_count
COUNT ( CASE WHEN cw . work_category = 2 AND cw . deleted_at = 0 AND cw . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_video_count ,
COUNT ( CASE WHEN cw . work_category = 1 AND cw . deleted_at = 0 AND cw . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_post_count
FROM active_windows aw
LEFT JOIN cast_work cw ON cw . artist_phone = aw . phone
LEFT JOIN cast_work cw ON cw . artist_phone COLLATE utf8mb4_general_ci = aw . phone COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -578,9 +571,9 @@ cw_agg AS (
cwa_agg AS (
SELECT
aw . user_id ,
COUNT ( CASE WHEN cwa . deleted_at = 0 AND cwa . work_analysis_status != 1 AND cwa . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_data_count
COUNT ( CASE WHEN cwa . deleted_at = 0 AND ( cwa . work_analysis_status IS NULL OR cwa . work_analysis_status != 1 ) AND cwa . submit_time BETWEEN UNIX_TIMESTAMP ( aw . start_at ) AND UNIX_TIMESTAMP ( aw . expired_at ) THEN 1 END ) AS uploaded_data_count
FROM active_windows aw
LEFT JOIN cast_work_analysis cwa ON cwa . artist_phone = aw . phone
LEFT JOIN cast_work_analysis cwa ON cwa . artist_phone COLLATE utf8mb4_general_ci = aw . phone COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -590,7 +583,7 @@ ccr_agg AS (
aw . user_id ,
COUNT ( CASE WHEN ccr . deleted_at = 0 AND ccr . submit_time BETWEEN aw . start_at AND aw . expired_at THEN 1 END ) AS uploaded_report_count
FROM active_windows aw
LEFT JOIN cast_competitive_report ccr ON ccr . artist_phone = aw . phone
LEFT JOIN cast_competitive_report ccr ON ccr . artist_phone COLLATE utf8mb4_general_ci = aw . phone COLLATE utf8mb4_general_ci
GROUP BY aw . user_id
) ,
@ -600,7 +593,7 @@ cvs_agg AS (
aw . user_id ,
COUNT ( cvs . artist_uuid ) AS uploaded_video_script_count
FROM active_windows aw
LEFT JOIN cast_video_script cvs ON CAST ( aw . user_id AS CHAR ) = cvs . artist_uuid
LEFT JOIN cast_video_script cvs ON CAST ( aw . user_id AS CHAR ) COLLATE utf8mb4_general_ci = cvs . artist_uuid COLLATE utf8mb4_general_ci
AND cvs . deleted_at = 0
AND cvs . created_at BETWEEN UNIX_TIMESTAMP ( CONVERT_TZ ( aw . start_at , ' + 00 : 00 ' , ' + 00 : 00 ' ) )
AND UNIX_TIMESTAMP ( CONVERT_TZ ( aw . expired_at , ' + 00 : 00 ' , ' + 00 : 00 ' ) )
@ -642,7 +635,7 @@ assigned_pending_agg AS (
END
) , 0 ) AS assigned_report_count
FROM active_windows aw
LEFT JOIN ` + " ` " + taskSchema + " ` " + ` . task_assign_records tar ON tar . sub_num = aw . customer_num
LEFT JOIN ` + " ` " + taskSchema + " ` " + ` . task_assign_records tar ON tar . sub_num COLLATE utf8mb4_general_ci = aw . customer_num COLLATE utf8mb4_general_ci
AND tar . actual_status IN ( 1 , 3 )
AND tar . deleted_at = 0
AND tar . created_at BETWEEN aw . start_at AND aw . expired_at
@ -661,16 +654,9 @@ LEFT JOIN assigned_pending_agg apa ON apa.user_id = aw.user_id`
args = append ( args , subNums )
args = append ( args , nowMonth )
// 使用事务固定同一连接,仅对本次查询的 session 设置 collation, 不影响其他接口
tx2 := app . ModuleClients . BundleDB . Begin ( )
defer tx2 . Rollback ( )
if err := tx2 . Exec ( "SET NAMES utf8mb4 COLLATE utf8mb4_0900_ai_ci" ) . Error ; err != nil {
return nil , 0 , commonErr . ReturnError ( err , "设置字符集失败" , "设置字符集失败: " )
}
countSQL := cte + " SELECT COUNT(DISTINCT aw.customer_num) " + fromClause
var total int64
if err := tx2 . Raw ( countSQL , args ... ) . Scan ( & total ) . Error ; err != nil {
if err := app . ModuleClients . BundleDB . Raw ( countSQL , args ... ) . Scan ( & total ) . Error ; err != nil {
return nil , 0 , commonErr . ReturnError ( err , "查询可指派数量总数失败" , "查询可指派数量总数失败: " )
}
@ -694,7 +680,7 @@ LEFT JOIN assigned_pending_agg apa ON apa.user_id = aw.user_id`
}
items := make ( [ ] dto . ArtistPendingAssignItem , 0 )
if err := tx2 . Raw ( selectSQL , listArgs ... ) . Scan ( & items ) . Error ; err != nil {
if err := app. ModuleClients . BundleDB . Raw ( selectSQL , listArgs ... ) . Scan ( & items ) . Error ; err != nil {
return nil , 0 , commonErr . ReturnError ( err , "查询可指派数量失败" , "查询可指派数量失败: " )
}