便利查询--各版本管理员查看用户的design频次和各生成功能使用频次以及积分使用情况

This commit is contained in:
2025-04-13 17:20:14 +08:00
parent 7b75e6ac69
commit cbc760ebaf
7 changed files with 237 additions and 42 deletions

View File

@@ -29,5 +29,106 @@
where id = #{id}
</update>
<!-- 查询用户积分使用情况,可灵活按事件类型查询或查询全部 -->
<select id="selectCreditUsage" resultType="com.ai.da.model.dto.AccountCreditsUsageDTO">
SELECT
a.id id,
a.user_email,
a.credits currentCredits,
<if test="groupByEvent">
cd.change_event generateFunction,
</if>
cd.total_changed_credits consumedCredits,
cd.count_account_id usageCount
FROM
t_account a
LEFT JOIN
(SELECT
account_id,
<if test="groupByEvent">
change_event,
</if>
SUM(changed_credits) AS total_changed_credits,
COUNT(account_id) AS count_account_id
FROM
t_credits_detail
WHERE
changed_credits &lt;= 0
<if test="changeEvent != null and changeEvent != ''">
AND change_event = #{changeEvent}
</if>
<!-- 添加时间区间查询条件 -->
<if test="startTime != null and startTime != ''">
AND cd.create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND cd.create_time &lt;= #{endTime}
</if>
GROUP BY
account_id
<if test="groupByEvent">
, change_event
</if>
) cd
ON
a.id = cd.account_id
WHERE
<choose>
<when test="role == 'corp'">
a.system_user IN (5, 6)
</when>
<when test="role == 'edu'">
a.system_user IN (7, 8)
</when>
<when test="role == 'prsn'">
a.system_user IN (0, 1, 2, 3, 4)
</when>
</choose>
<if test="id != null">
AND a.id = #{id}
</if>
<if test="userEmail != null and userEmail != ''">
AND a.user_email = #{userEmail}
</if>
<!-- 添加分页查询 -->
ORDER BY a.id
<if test="size != null and offset != null">
LIMIT #{size} OFFSET #{offset}
</if>
</select>
<!-- 查询总记录数 (优化版) -->
<select id="countCreditUsage" resultType="int">
SELECT COUNT(1)
FROM t_account a
<if test="changeEvent != null or startTime != null or endTime != null">
LEFT JOIN t_credits_detail cd ON a.id = cd.account_id
AND cd.changed_credits &lt;= 0
<if test="changeEvent != null and changeEvent != ''">
AND cd.change_event = #{changeEvent}
</if>
<if test="startTime != null and startTime != ''">
AND cd.create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND cd.create_time &lt;= #{endTime}
</if>
</if>
WHERE
<choose>
<when test="role == 'corp'">
a.system_user IN (5, 6)
</when>
<when test="role == 'edu'">
a.system_user IN (7, 8)
</when>
<when test="role == 'prsn'">
a.system_user IN (0, 1, 2, 3, 4)
</when>
</choose>
<if test="userEmail != null and userEmail != ''">
AND a.user_email = #{userEmail}
</if>
</select>
</mapper>