Commit ee3fb4f9 authored by tianbo's avatar tianbo

refactor(amos-boot-module-jg): 优化 SQL 查询性能

- 调整了 SQL 提示,去除了对特定表的 tablescan 提示,增加了整体查询的并行度设置
parent 00840d1a
...@@ -687,206 +687,8 @@ ...@@ -687,206 +687,8 @@
</choose> </choose>
</select> </select>
<select id="getListPage2" resultType="java.util.Map">
WITH filtered_ur AS (
SELECT
sequence_nbr,
audit_status,
reg_date,
use_unit_name,
supervision_org_code,
status,
receive_org_name,
use_address,
instance_id,
apply_no,
next_execute_ids,
promoter,
use_registration_code,
audit_pass_date,
create_date,
next_execute_user_ids,
next_task_id,
create_user_id,
rec_date,
manage_type,
reg_type,
is_delete,
receive_company_code,
use_unit_credit_code,
transfer_to_user_ids,
cancel_reason,
project_contraption_id
FROM tzs_jg_use_registration
WHERE is_delete = 0
<!-- 公共主表过滤条件 -->
<if test="dto.status != null and dto.status != ''">
AND status = #{dto.status}
</if>
<if test="dto.applicationDate != null">
AND create_date LIKE CONCAT('%', DATE_FORMAT(#{dto.applicationDate}, '%Y-%m-%d'), '%')
</if>
<if test="dto.fullAddress != null and dto.fullAddress != ''">
AND use_address LIKE CONCAT('%', #{dto.fullAddress}, '%')
</if>
<if test="dto.useUnitName != null and dto.useUnitName != ''">
AND use_unit_name LIKE CONCAT('%', #{dto.useUnitName}, '%')
</if>
<if test="dto.applyNo != null and dto.applyNo != ''">
AND apply_no LIKE CONCAT('%', #{dto.applyNo}, '%')
</if>
<if test="dto.useRegistrationCode != null and dto.useRegistrationCode != ''">
AND use_registration_code LIKE CONCAT('%', #{dto.useRegistrationCode}, '%')
</if>
<if test="dto.useUnitCode != null and dto.useUnitCode != ''">
AND use_unit_credit_code = #{dto.useUnitCode}
</if>
<if test="dto.orgBranchCode != null and dto.orgBranchCode != ''">
<choose>
<when test="client == 'jgLook'">
AND supervision_org_code LIKE CONCAT(#{dto.orgBranchCode}, '%')
</when>
<otherwise>
AND supervision_org_code = #{dto.orgBranchCode}
</otherwise>
</choose>
</if>
<if test="dto.auditPassDateStart != null and dto.auditPassDateEnd != null">
AND audit_pass_date BETWEEN #{dto.auditPassDateStart} AND #{dto.auditPassDateEnd}
</if>
<if test="dto.dataType == 'supervision' ">
<choose>
<when test="client == 'jgAudit'">
AND (receive_company_code = #{dto.receiveCompanyCode}
OR transfer_to_user_ids LIKE CONCAT('%', #{dto.currentUserId}, '%'))
</when>
<otherwise>
AND supervision_org_code LIKE CONCAT(#{dto.supervisionOrgCode}, '%')
</otherwise>
</choose>
AND status <![CDATA[<>]]> '使用单位待提交'
</if>
<if test="dto.dataType == 'company' ">
AND (use_unit_credit_code = #{dto.unitCode}
OR transfer_to_user_ids LIKE CONCAT('%', #{dto.currentUserId}, '%'))
</if>
ORDER BY
<choose>
<when test="sort != null">
${sort.field} ${sort.sortType}
</when>
<otherwise>
create_date DESC, apply_no DESC
</otherwise>
</choose>
),
equipment_data AS (
SELECT
re.equip_transfer_id,
GROUP_CONCAT(re.equ_id) AS equipId,
GROUP_CONCAT(DISTINCT other.supervisory_code) AS supervisoryCode,
GROUP_CONCAT(DISTINCT other.CODE96333) AS code96333,
GROUP_CONCAT(jri.PRODUCT_NAME) AS productName,
GROUP_CONCAT(DISTINCT jri.EQU_CODE) AS equCode,
GROUP_CONCAT(DISTINCT jri.EQU_LIST) AS equListCode,
GROUP_CONCAT(DISTINCT jri.EQU_CATEGORY) AS equCategoryCode,
GROUP_CONCAT(DISTINCT jri.EQU_DEFINE) AS equDefineCode,
GROUP_CONCAT(DISTINCT c_list.name) AS equListName,
GROUP_CONCAT(DISTINCT c_cate.name) AS equCategory,
GROUP_CONCAT(DISTINCT c_def.name) AS equDefine
FROM filtered_ur fu
JOIN tzs_jg_use_registration_eq re ON fu.sequence_nbr = re.equip_transfer_id
JOIN idx_biz_jg_register_info jri ON re.equ_id = jri.RECORD
LEFT JOIN idx_biz_jg_other_info other ON jri.RECORD = other.RECORD
LEFT JOIN tz_equipment_category c_list ON jri.EQU_LIST = c_list.code
LEFT JOIN tz_equipment_category c_cate ON jri.EQU_CATEGORY = c_cate.code
LEFT JOIN tz_equipment_category c_def ON jri.EQU_DEFINE = c_def.code
<where>
<!-- 统一设备过滤条件 -->
<if test="dto.equList != null and dto.equList != ''">
AND jri.EQU_LIST = #{dto.equList}
</if>
<if test="dto.equCategory != null and dto.equCategory != ''">
AND jri.EQU_CATEGORY = #{dto.equCategory}
</if>
<if test="dto.equDefine != null and dto.equDefine != ''">
AND jri.EQU_DEFINE = #{dto.equDefine}
</if>
<if test="dto.equCode != null and dto.equCode != ''">
AND jri.EQU_CODE LIKE CONCAT('%', #{dto.equCode}, '%')
</if>
<if test="dto.code96333 != null and dto.code96333 != ''">
AND other.CODE96333 LIKE CONCAT('%', #{dto.code96333}, '%')
</if>
<if test="dto.supervisoryCode != null and dto.supervisoryCode != ''">
AND other.supervisory_code LIKE CONCAT('%', #{dto.supervisoryCode}, '%')
</if>
</where>
GROUP BY re.equip_transfer_id
)
SELECT
fu.sequence_nbr AS sequenceNbr,
fu.audit_status AS auditStatus,
DATE_FORMAT(fu.reg_date,'%Y-%m-%d') AS regDate,
fu.use_unit_name AS useUnitName,
fu.supervision_org_code AS supervisionOrgCode,
fu.status,
fu.receive_org_name AS receiveOrgName,
fu.use_address AS place,
fu.instance_id AS instanceId,
fu.apply_no AS applyNo,
fu.next_execute_ids AS nextExecuteIds,
fu.promoter,
fu.use_registration_code AS useRegistrationCode,
DATE_FORMAT(fu.audit_pass_date,'%Y-%m-%d') AS auditPassDate,
DATE_FORMAT(fu.create_date,'%Y-%m-%d') AS createDate,
fu.receive_org_name AS receiveOrgName,
fu.next_execute_user_ids AS nextExecuteUserIds,
fu.next_task_id AS nextTaskId,
fu.create_user_id AS createUserId,
fu.rec_date AS recDate,
fu.manage_type AS manageType,
fu.reg_type AS regType,
fu.is_delete,
fu.create_date,
fu.receive_company_code,
fu.use_unit_credit_code,
fu.transfer_to_user_ids,
fu.supervision_org_code,
fu.use_address AS fullAddress,
fu.cancel_reason AS cancelReason,
fu.project_contraption_id AS projectContraptionId,
<!-- 设备字段 -->
COALESCE(ed.equipId, '') AS equipId,
COALESCE(ed.supervisoryCode, '') AS supervisoryCode,
COALESCE(ed.code96333, '') AS code96333,
COALESCE(ed.productName, '') AS productName,
COALESCE(ed.equCode, '') AS equCode,
COALESCE(ed.equListCode, '') AS equListCode,
COALESCE(ed.equCategoryCode, '') AS equCategoryCode,
COALESCE(ed.equDefineCode, '') AS equDefineCode,
COALESCE(ed.equListName, '') AS equListName,
COALESCE(ed.equCategory, '') AS equCategory,
COALESCE(ed.equDefine, '') AS equDefine
FROM filtered_ur fu
INNER JOIN equipment_data ed ON fu.sequence_nbr = ed.equip_transfer_id
WHERE 1=1
ORDER BY
<choose>
<when test="sort != null">
${sort.field} ${sort.sortType}
</when>
<otherwise>
fu.create_date DESC, fu.apply_no DESC
</otherwise>
</choose>
LIMIT #{size} OFFSET #{offset}
</select>
<select id="getListPageCount" resultType="long"> <select id="getListPageCount" resultType="long">
SELECT <![CDATA[/*+ use_cplan tablescan(ur) tablescan(re) tablescan(jri) tablescan(other) set(query_dop 16)*/]]> COUNT(DISTINCT ur.sequence_nbr) SELECT <![CDATA[/*+ set(query_dop 16)*/]]> COUNT(DISTINCT ur.sequence_nbr)
FROM tzs_jg_use_registration ur FROM tzs_jg_use_registration ur
LEFT JOIN tzs_jg_use_registration_eq re ON ur.sequence_nbr = re.equip_transfer_id LEFT JOIN tzs_jg_use_registration_eq re ON ur.sequence_nbr = re.equip_transfer_id
LEFT JOIN idx_biz_jg_register_info jri ON re.equ_id = jri."RECORD" LEFT JOIN idx_biz_jg_register_info jri ON re.equ_id = jri."RECORD"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment