瀏覽代碼

报告查询sql优化

huangguoce 1 月之前
父節點
當前提交
22265a8366

+ 104 - 108
jeeplus-modules/jeeplus-finance/src/main/java/com/jeeplus/finance/projectReport/mapper/xml/CwProjectReportMapper.xml

@@ -66,116 +66,112 @@
     </sql>
 
     <select id="findList" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReportData">
-        SELECT
-        DISTINCT a.id,
-        a.create_by_id as createById,
-        a.create_time,
-        a.update_by_id,
-        a.update_time,
-        a.del_flag,
-        a.remarks,
-        a.status,
-        a.document_no,
-        a.project_report_number,
-        a.project_id,
-        a.office_id,
-        a.signature_type,
-        a.signature_annotator1,
-        a.signature_annotator2,
-        a.signature_contract_id,
-        a.real_create,
-        a.proc_ins_id,
-        a.process_definition_id,
-        a.signature_annotator_status,
-        b.project_number as projectNumber,
-        b.project_name as projectName,
-        b.project_master_id as projectMasterId,
-        b.real_header as projectMasterId2,
-        c.name as departmentName,
-        d.name as userName,
-        ifnull(cw_pa.audit_money,"0") as "auditFees",
-        e.name as projectMasterName,
-        b.real_header as projectMaster2Id,
-        b.project_classification,
-        b.report_type as projectType,
-        f.name as projectMaster2Name,
-        cw_prs1.proc_ins_id as proc_ins_id1,
-        cw_prs1.process_definition_id as process_definition_id1,
-        cw_prs1.status as status1,
-        cw_prs1.id as sid1,
-        cw_prs2.proc_ins_id as proc_ins_id2,
-        cw_prs2.process_definition_id as process_definition_id2,
-        cw_prs2.status as status2,
-        cw_prs2.id as sid2,
-        cw_prs3.proc_ins_id as proc_ins_ids3,
-        cw_prs3.process_definition_id as process_definition_id3,
-        cw_prs3.status as status3,
-        cw_prs3.id as sid3,
-        ifnull(cw_rev.review_status,'0') as reviewStatus,
-        cw_rev.proc_ins_id as procInsId3,
-        cw_rev.new_type as newType,
-        cw_rev.audit_time as auditTime,
-        new_line.report_no as reportNo,
-        new_line.report_date,
-        new_line.approved_no_including_tax as approvedNoIncludingTax,
-        new_line.approved_including_tax as approvedIncludingTax,
-        cwcb.name as servedUnitName,
-        art.ID_ as rev_task_id,
-        arta.ID_ as rev_task_id2,
-        art1.ID_ as sign_task_id1,
-        art2.ID_ as sign_task_id2,
-        art3.ID_ as sign_task_id3,
-        a.industry,
-        a.business_objects,
-        a.report_name,
-        cw_na.proc_ins_id as applyProcId,
-        cw_na.process_definition_id as applyProcDefId,
-        ifnull(cw_na.review_status,'0') as applyStatus,
-        ifnull(cw_na.take_number_type,'0') as takeNumberType,
-        cw_na.improper_take_cause as improperTakeCause,
+        SELECT DISTINCT a.id,
+                        a.create_by_id AS createById,
+                        a.create_time,
+                        a.update_by_id,
+                        a.update_time,
+                        a.del_flag,
+                        a.remarks,
+                        a.status,
+                        a.document_no,
+                        a.project_report_number,
+                        a.project_id,
+                        a.office_id,
+                        a.signature_type,
+                        a.signature_annotator1,
+                        a.signature_annotator2,
+                        a.signature_contract_id,
+                        a.real_create,
+                        a.proc_ins_id,
+                        a.process_definition_id,
+                        a.signature_annotator_status,
+                        b.project_number AS projectNumber,
+                        b.project_name AS projectName,
+                        b.project_master_id AS projectMasterId,
+                        b.real_header AS projectMasterId2,
+                        c.name AS departmentName,
+                        d.name AS userName,
+                        COALESCE(cw_pa.audit_money, 0) AS auditFees,
+                        e.name AS projectMasterName,
+                        b.real_header AS projectMaster2Id,
+                        b.project_classification,
+                        b.report_type AS projectType,
+                        f.name AS projectMaster2Name,
+                        COALESCE(cw_rev.review_status,'0') as reviewStatus,
+                        cw_rev.proc_ins_id AS procInsId3,
+                        cw_rev.new_type AS newType,
+                        cw_rev.audit_time AS auditTime,
+                        new_line.report_no AS reportNo,
+                        new_line.report_date,
+                        new_line.approved_no_including_tax AS approvedNoIncludingTax,
+                        new_line.approved_including_tax AS approvedIncludingTax,
+                        cwcb.name AS servedUnitName,
+                        a.industry,
+                        a.business_objects,
+                        a.report_name,
+                        cw_na.proc_ins_id AS applyProcId,
+                        cw_na.process_definition_id AS applyProcDefId,
+                        COALESCE(cw_na.review_status, '0') AS applyStatus,
+                        COALESCE(cw_na.take_number_type, '0') AS takeNumberType,
+                        cw_na.improper_take_cause AS improperTakeCause,
+                        cw_nra.proc_ins_id AS applyReviewProcId,
+                        cw_nra.process_definition_id AS applyReviewProcDefId,
+                        COALESCE(cw_nra.review_status, '0') AS applyReviewStatus,
+                        cw_ci.contract_name,
+                        cw_ci.contract_no,
+                        rs.id AS revocationId,
+                        rs.status AS rebackStatus,
+                        rs.proc_ins_id AS procInsReId,
+                        rs.process_definition_id AS procDefReId,
+                        cw_prs1.proc_ins_id as proc_ins_id1,
+                        cw_prs1.process_definition_id as process_definition_id1,
 
-        artar.ID_ as review_task_number_id,
-        cw_nra.proc_ins_id as applyReviewProcId,
-        cw_nra.process_definition_id as applyReviewProcDefId,
-        ifnull(cw_nra.review_status,'0') as applyReviewStatus,
-        cw_ci.contract_name,
-        cw_ci.contract_no,
-        rs.id as revocationId,
-        rs.status as rebackStatus,
-        rs.proc_ins_id as procInsReId,
-        rs.process_definition_id as procDefReId,
-        actru.ID_ as revocationTaskId
+                        cw_prs1.status as status1,
+                        cw_prs1.id as sid1,
+                        cw_prs2.proc_ins_id as proc_ins_id2,
+                        cw_prs2.process_definition_id as process_definition_id2,
+                        cw_prs2.status as status2,
+                        cw_prs2.id as sid2,
+                        cw_prs3.proc_ins_id as proc_ins_ids3,
+                        cw_prs3.process_definition_id as process_definition_id3,
+                        cw_prs3.status as status3,
+                        cw_prs3.id as sid3,
+                        artar.ID_ as review_task_number_id,
+                        art.ID_ as rev_task_id,
+                        arta.ID_ as rev_task_id2,
+                        art1.ID_ as sign_task_id1,
+                        art2.ID_ as sign_task_id2,
+                        art3.ID_ as sign_task_id3,
+                        actru.ID_ as revocationTaskId
         FROM cw_project_report a
-        left join cw_project_records b on a.project_id = b.id
-        LEFT JOIN sys_office c on a.office_id = c.id
-        LEFT JOIN sys_user d on a.create_by_id = d.id
-        LEFT JOIN sys_user e on b.project_master_id = e.id
-        LEFT JOIN sys_user f on b.real_header = f.id
-
-        LEFT JOIN cw_project_report_signature cw_prs1 on cw_prs1.report_id = a.id and cw_prs1.type = '1' and cw_prs1.del_flag = '0'
-        LEFT JOIN cw_project_report_signature cw_prs2 on cw_prs2.report_id = a.id and cw_prs2.type = '2' and cw_prs2.del_flag = '0'
-        LEFT JOIN cw_project_report_signature cw_prs3 on cw_prs3.report_id = a.id and cw_prs3.type = '3' and cw_prs3.del_flag = '0'
-        left join act_ru_task art1 ON cw_prs1.proc_ins_id = art1.PROC_INST_ID_
-        left join act_ru_task art2 ON cw_prs2.proc_ins_id = art2.PROC_INST_ID_
-        left join act_ru_task art3 ON cw_prs3.proc_ins_id = art3.PROC_INST_ID_
-
-        left join cw_project_report_new_line new_line on a.id = new_line.report_id and new_line.del_flag = '0'
-        left join cw_project_report_review cw_rev on a.id = cw_rev.report_id and cw_rev.del_flag = '0'
-        LEFT JOIN cw_project_report_archive cw_pa on  a.id = cw_pa.report_id and cw_pa.del_flag = '0'
-        left join act_ru_task art ON cw_rev.proc_ins_id = art.PROC_INST_ID_
-        left join cw_project_members cpm on b.id = cpm.project_id
-        left join sys_user sub on cpm.user_id = sub.id
-        left join sys_user_manage_office sumo on sumo.office_id = sub.office_id
-        left join cw_work_client_base cwcb on new_line.served_unit_id = cwcb.id
-        LEFT JOIN cw_work_contract_info cw_ci on  b.contract_id=cw_ci.id
-        LEFT JOIN cw_project_report_number_apply cw_na on  a.id = cw_na.report_id
-        LEFT JOIN cw_project_report_number_review_apply cw_nra on  a.id = cw_nra.report_id
-         left join act_ru_task arta ON cw_na.proc_ins_id = arta.PROC_INST_ID_
-         left join act_ru_task artar ON cw_nra.proc_ins_id = artar.PROC_INST_ID_
-         left join cw_revocation_signature rs on a.id = rs.report_id and rs.del_flag = '0'
-         left join act_ru_task actru ON rs.proc_ins_id = actru.PROC_INST_ID_
-        ${ew.customSqlSegment}
-        ORDER BY a.create_time DESC
+                 LEFT JOIN cw_project_records b ON a.project_id = b.id
+                 LEFT JOIN sys_office c ON a.office_id = c.id
+                 LEFT JOIN sys_user d ON a.create_by_id = d.id
+                 LEFT JOIN sys_user e ON b.project_master_id = e.id
+                 LEFT JOIN sys_user f ON b.real_header = f.id
+                 LEFT JOIN cw_project_report_new_line new_line ON a.id = new_line.report_id AND new_line.del_flag = '0'
+                 LEFT JOIN cw_project_report_review cw_rev ON a.id = cw_rev.report_id AND cw_rev.del_flag = '0'
+                 LEFT JOIN cw_project_report_archive cw_pa ON a.id = cw_pa.report_id AND cw_pa.del_flag = '0'
+                 LEFT JOIN cw_work_client_base cwcb ON new_line.served_unit_id = cwcb.id
+                 LEFT JOIN cw_work_contract_info cw_ci ON b.contract_id = cw_ci.id
+                 LEFT JOIN cw_project_report_number_apply cw_na ON a.id = cw_na.report_id
+                 LEFT JOIN cw_project_report_number_review_apply cw_nra ON a.id = cw_nra.report_id
+                 LEFT JOIN cw_revocation_signature rs ON a.id = rs.report_id AND rs.del_flag = '0'
+                 LEFT JOIN cw_project_report_signature cw_prs1 on cw_prs1.report_id = a.id and cw_prs1.type = '1' and cw_prs1.del_flag = '0'
+                 LEFT JOIN cw_project_report_signature cw_prs2 on cw_prs2.report_id = a.id and cw_prs2.type = '2' and cw_prs2.del_flag = '0'
+                 LEFT JOIN cw_project_report_signature cw_prs3 on cw_prs3.report_id = a.id and cw_prs3.type = '3' and cw_prs3.del_flag = '0'
+                 LEFT JOIN cw_project_members cpm on b.id = cpm.project_id
+                 LEFT JOIN sys_user sub on cpm.user_id = sub.id
+                 LEFT JOIN act_ru_task art ON cw_rev.proc_ins_id = art.PROC_INST_ID_
+                 LEFT JOIN act_ru_task artar ON cw_nra.proc_ins_id = artar.PROC_INST_ID_
+                 LEFT JOIN act_ru_task arta ON cw_na.proc_ins_id = arta.PROC_INST_ID_
+                 LEFT JOIN act_ru_task art1 ON cw_prs1.proc_ins_id = art1.PROC_INST_ID_
+                 LEFT JOIN act_ru_task art2 ON cw_prs2.proc_ins_id = art2.PROC_INST_ID_
+                 LEFT JOIN act_ru_task art3 ON cw_prs3.proc_ins_id = art3.PROC_INST_ID_
+                 LEFT JOIN act_ru_task actru ON rs.proc_ins_id = actru.PROC_INST_ID_
+            ${ew.customSqlSegment}
+        ORDER BY a.create_time DESC;
     </select>