refactor(): 优化用户评估统计分页查询sql

dev
lishiwei 2026-06-11 08:38:14 +08:00
parent 8a0e5a335e
commit 709fb49bbb
3 changed files with 64 additions and 4 deletions

View File

@ -19,7 +19,6 @@ import java.util.Map;
@DataScopes({
@DataScope(method = "corpHidddenPage", menuPerms = ""),
@DataScope(method = "corpEvalStatisticsPage", menuPerms = ""),
@DataScope(method = "userEvalStatisticsPage", menuPerms = ""),
@DataScope(method = "corpEvalPage", menuPerms = ""),
})
public interface HiddenEvaluationRecordMapper extends BaseMapper<HiddenEvaluationRecordDO> {
@ -32,6 +31,8 @@ public interface HiddenEvaluationRecordMapper extends BaseMapper<HiddenEvaluatio
IPage<UserEvalStatisticsDO> userEvalStatisticsPage(IPage<UserEvalStatisticsDO> iPage, Map<String, Object> params, String menuPerms);
Long userEvalStatisticsPageCount(Map<String, Object> params, String menuPerms);
IPage<HiddenEvalDO> hiddenEvalPage(IPage<HiddenEvalDO> iPage, Map<String, Object> params);
IPage<CorpEvalDO> corpEvalPage(IPage<CorpEvalDO> iPage, Map<String, Object> params, String menuPerms);

View File

@ -80,13 +80,14 @@ public class HiddenEvaluationRecordRepositoryImpl extends BaseRepositoryImpl<Hid
@Override
public PageResponse<UserEvalStatisticsDO> userEvalStatisticsPage(Map<String, Object> params) {
IPage<UserEvalStatisticsDO> iPage = new Query<UserEvalStatisticsDO>().getPage(params);
((com.baomidou.mybatisplus.extension.plugins.pagination.Page<?>) iPage).setSearchCount(false);
String menuPerms = "";
if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))){
menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
}
// 关闭 count SQL 优化,因为该查询包含派生表子查询 + CROSS JOIN 等复杂结构JSQLParser 无法解析
((com.baomidou.mybatisplus.extension.plugins.pagination.Page<?>) iPage).setOptimizeCountSql(false);
IPage<UserEvalStatisticsDO> result = hiddenEvaluationRecordMapper.userEvalStatisticsPage(iPage, params, menuPerms);
Long total = hiddenEvaluationRecordMapper.userEvalStatisticsPageCount(params, menuPerms);
result.setTotal(total != null ? total : 0);
return PageHelper.pageToResponse(result, result.getRecords());
}

View File

@ -437,6 +437,64 @@
ORDER BY userId ASC
</select>
<select id="userEvalStatisticsPageCount" resultType="java.lang.Long">
SELECT COUNT(*) FROM (
SELECT u.id
FROM user u
LEFT JOIN hidden h ON h.creator_id = u.id
AND h.delete_enum = 'FALSE'
AND h.state = 301
AND ((h.source IN (4,5) AND h.final_check = 1) OR h.source NOT IN (4,5))
AND h.hidden_type IN ('aqyh','rdbaqys','wzcz','wzzh','grfhyp','wdbaqzt','jxsb','hcl','dqsb','gsj','aqbhzz','ss','xf','tzsb','hjdbaqys','zmjdgyxbj','aqbzbs','gkkd','zykjxzzl','eltq','gldqx','wzdhzdlsbdw','wfacs','jypx','aqyh-qt')
WHERE u.delete_enum = 'FALSE'
AND h.id IS NOT NULL
<if test="params.corpinfoId != null">
AND u.corpinfo_id = #{params.corpinfoId}
</if>
<if test="params.departmentId != null ">
AND u.department_id = #{params.departmentId}
</if>
<if test="params.userName != null and params.userName != ''">
AND u.name LIKE CONCAT('%', #{params.userName}, '%')
</if>
<if test="params.userIdList != null and params.userIdList.size() > 0">
AND u.id IN
<foreach collection="params.userIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
GROUP BY u.id
UNION ALL
SELECT u.id
FROM user u
LEFT JOIN hidden h ON h.creator_id = u.id
AND h.delete_enum = 'FALSE'
AND h.state = 301
AND ((h.source IN (4,5) AND h.final_check = 1) OR h.source NOT IN (4,5))
AND h.hidden_type IN ('wshb','hjwr','ws','dq','zs','gf','hjwsjlh','yqfk','wshb-qt')
WHERE u.delete_enum = 'FALSE'
AND h.id IS NOT NULL
<if test="params.corpinfoId != null">
AND u.corpinfo_id = #{params.corpinfoId}
</if>
<if test="params.departmentId != null ">
AND u.department_id = #{params.departmentId}
</if>
<if test="params.userName != null and params.userName != ''">
AND u.name LIKE CONCAT('%', #{params.userName}, '%')
</if>
<if test="params.userIdList != null and params.userIdList.size() > 0">
AND u.id IN
<foreach collection="params.userIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
GROUP BY u.id
) total_count
</select>
<select id="hiddenEvalPage" resultType="com.zcloud.hidden.evaluation.persistence.dataobject.HiddenEvalDO">
select h.source,
h.hidden_id AS hiddenId,