diff --git a/backend/src/main/resources/mapper/llm/LlmMcpMapper.xml b/backend/src/main/resources/mapper/llm/LlmMcpMapper.xml index ef96f587..8893e29f 100644 --- a/backend/src/main/resources/mapper/llm/LlmMcpMapper.xml +++ b/backend/src/main/resources/mapper/llm/LlmMcpMapper.xml @@ -911,10 +911,10 @@ cross join users_scope u ) select - case - when #{groupBy} = 'owner' then e.user_name - else to_char(e.report_date, 'YYYY-MM-DD') - end as "groupName", + + e.user_name + to_char(e.report_date, 'YYYY-MM-DD') + as "groupName", count(1)::bigint as "expectedCount", count(r.id)::bigint as "submittedCount", (count(1) - count(r.id))::bigint as "missingCount", @@ -924,7 +924,11 @@ on r.user_id = e.user_id and r.report_date = e.report_date and coalesce(r.status, 'submitted') in ('submitted', 'read', 'reviewed') - group by case when #{groupBy} = 'owner' then e.user_name else to_char(e.report_date, 'YYYY-MM-DD') end + group by + + e.user_name + to_char(e.report_date, 'YYYY-MM-DD') + order by "groupName" asc limit #{limit} offset #{offset} @@ -932,11 +936,11 @@ select - case - when #{groupBy} = 'status' then coalesce(c.status, 'unknown') - when #{groupBy} = 'source' then coalesce(c.source, 'unknown') - else coalesce(c.industry, 'unknown') - end as "groupName", + + coalesce(c.status, 'unknown') + coalesce(c.source, 'unknown') + coalesce(c.industry, 'unknown') + as "groupName", count(1)::bigint as "customerCount" from crm_customer c where c.created_at::date between #{startDate} and #{endDate} and c.owner_user_id = #{ownerUserId} and exists (select 1 from sys_tenant_user tu where tu.user_id = c.owner_user_id and tu.tenant_id = #{tenantId} and coalesce(tu.is_deleted, 0) = 0) - group by case - when #{groupBy} = 'status' then coalesce(c.status, 'unknown') - when #{groupBy} = 'source' then coalesce(c.source, 'unknown') - else coalesce(c.industry, 'unknown') - end + group by + + coalesce(c.status, 'unknown') + coalesce(c.source, 'unknown') + coalesce(c.industry, 'unknown') + order by "customerCount" desc, "groupName" asc limit #{limit} offset #{offset} @@ -1025,7 +1031,10 @@