Commit b22a9115 authored by tianbo's avatar tianbo

refactor(jg): 重构使用登记查询 SQL

- 优化了字段别名的定义 - 调整了排序字段的引用
parent e54465bb
...@@ -519,89 +519,21 @@ ...@@ -519,89 +519,21 @@
JOIN idx_biz_jg_other_info other ON jri."RECORD" = other."RECORD" JOIN idx_biz_jg_other_info other ON jri."RECORD" = other."RECORD"
WHERE re.equip_transfer_id = md.sequenceNbr) AS supervisoryCode WHERE re.equip_transfer_id = md.sequenceNbr) AS supervisoryCode
FROM main_data md FROM main_data md
GROUP BY md.sequenceNbr
WITH filtered_main_ids AS (
SELECT fu.sequence_nbr
FROM tzs_jg_use_registration fu
WHERE fu.is_delete = '0'
AND exists(
SELECT 1 FROM tzs_jg_use_registration_eq re
INNER 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"
WHERE re.equip_transfer_id = fu.sequence_nbr
)
)
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,
(select company_name from privilege_company where org_code = fu.supervision_org_code and is_deleted = false limit 1) AS orgBranchName,
COALESCE(STRING_AGG(DISTINCT re.equ_id, ','), '') AS equipId,
COALESCE(STRING_AGG(DISTINCT other.supervisory_code, ','), '') AS supervisoryCode,
COALESCE(STRING_AGG(DISTINCT other.CODE96333, ','), '') AS code96333,
COALESCE(STRING_AGG(DISTINCT jri.PRODUCT_NAME, ','), '') AS productName,
COALESCE(STRING_AGG(DISTINCT jri.EQU_CODE, ','), '') AS equCode,
COALESCE(STRING_AGG(DISTINCT jri.EQU_LIST, ','), '') AS equListCode,
COALESCE(STRING_AGG(DISTINCT jri.EQU_CATEGORY, ','), '') AS equCategoryCode,
COALESCE(STRING_AGG(DISTINCT jri.EQU_DEFINE, ','), '') AS equDefineCode,
COALESCE(STRING_AGG(DISTINCT c_list.name, ','), '') AS equListName,
COALESCE(STRING_AGG(DISTINCT c_cate.name, ','), '') AS equCategory,
COALESCE(STRING_AGG(DISTINCT c_def.name, ','), '') AS equDefine
FROM filtered_main_ids fm
JOIN tzs_jg_use_registration fu ON fm.sequence_nbr = fu.sequence_nbr
LEFT JOIN tzs_jg_use_registration_eq re ON fu.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_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
GROUP BY fu.sequence_nbr
ORDER BY ORDER BY
<choose> <choose>
<when test="sort != null and sort.field != null and sort.sortType != null"> <when test="sort != null and sort.field != null and sort.sortType != null">
<choose> <choose>
<when test="sort.field == 'create_date'">fu.create_date</when> <when test="sort.field == 'create_date'">md.create_date</when>
<when test="sort.field == 'apply_no'">fu.apply_no</when> <when test="sort.field == 'apply_no'">md.applyNo</when>
<when test="sort.field == 'reg_date'">fu.reg_date</when> <when test="sort.field == 'reg_date'">md.regType</when>
<when test="sort.field == 'audit_pass_date'">fu.audit_pass_date</when> <when test="sort.field == 'audit_pass_date'">fu.auditPassDate</when>
<otherwise>${sort.field}</otherwise> <otherwise>${sort.field}</otherwise>
</choose> </choose>
${sort.sortType} ${sort.sortType}
</when> </when>
<otherwise> <otherwise>
fu.create_date DESC, fu.apply_no DESC md.create_date DESC, md.applyNo DESC
</otherwise> </otherwise>
</choose> </choose>
LIMIT #{size} OFFSET #{offset} LIMIT #{size} OFFSET #{offset}
......
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