便利查询--各版本管理员查看用户的design频次和各生成功能使用频次以及积分使用情况
This commit is contained in:
@@ -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 <= 0
|
||||
<if test="changeEvent != null and changeEvent != ''">
|
||||
AND change_event = #{changeEvent}
|
||||
</if>
|
||||
<!-- 添加时间区间查询条件 -->
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND cd.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND cd.create_time <= #{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 <= 0
|
||||
<if test="changeEvent != null and changeEvent != ''">
|
||||
AND cd.change_event = #{changeEvent}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND cd.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND cd.create_time <= #{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>
|
||||
|
||||
Reference in New Issue
Block a user