Przeglądaj źródła

事件中心,综合查询,SQL优化

王哲 1 miesiąc temu
rodzic
commit
32ccd3e0d3

+ 77 - 0
src/main/resources/mapper/centereventteventcatalogue/CentereventTEventcatalogueMapper.xml

@@ -51,6 +51,83 @@
         from centerevent_t_eventcatalogue a
         from centerevent_t_eventcatalogue a
         left join centerevent_t_eventtype y1 on y1.id = a.event_type
         left join centerevent_t_eventtype y1 on y1.id = a.event_type
         left join centerevent_t_eventtype y2 on y2.id = a.event_type_xl
         left join centerevent_t_eventtype y2 on y2.id = a.event_type_xl
+        where exists (
+        select 1 from centerevent_t_dept_event d
+        left join ${database_system}.sys_dept c on c.dept_id = d.dept_id
+        where d.event_code = a.event_code
+        ${params.dataScope}
+        )
+        <if test="eventName != null and eventName != ''">
+            and event_name like concat('%', #{eventName}, '%')
+        </if>
+        <if test="reportSource != null and reportSource != ''">
+            and report_source = #{reportSource}
+        </if>
+        <if test="reportor != null and reportor != ''">
+            and reportor = #{reportor}
+        </if>
+        <if test="reportTimeRange != null and reportTimeRange.length > 0">
+            <foreach collection="reportTimeRange" item="item" index="index">
+                <if test="index == 0">and a.create_time between concat(#{item}, ' 00:00:00')</if>
+                <if test="index == 1">and concat(#{item}, ' 23:59:59')</if>
+            </foreach>
+        </if>
+        <if test="isUrged != null and isUrged != ''">
+            and a.is_urged = #{isUrged}
+        </if>
+        <if test="eventStatusValue != null and eventStatusValue != ''">
+            and a.event_status_value = #{eventStatusValue}
+        </if>
+        <choose>
+            <when test="eventTypeXls != null and eventTypeXls.size > 0">
+                <choose>
+                    <when test="eventType != null">
+                        and ( ( a.event_type = '1' and a.event_status_value in ( 'forest_event_status_1',
+                        'forest_event_status_7', 'forest_event_status_3', 'forest_event_status_4' ) ) or
+                        a.event_type_xl in
+                        <foreach item="eventTypeXl" collection="eventTypeXls" open="(" separator="," close=")">
+                            #{eventTypeXl}
+                        </foreach>)
+                    </when>
+                    <otherwise>
+                        and a.event_type_xl in
+                        <foreach item="eventTypeXl" collection="eventTypeXls" open="(" separator="," close=")">
+                            #{eventTypeXl}
+                        </foreach>
+                    </otherwise>
+                </choose>
+            </when>
+            <otherwise>
+                <choose>
+                    <when test="eventType != null">
+                        and ( ( a.event_type = '1' and a.event_status_value in ( 'forest_event_status_1',
+                        'forest_event_status_7', 'forest_event_status_3', 'forest_event_status_4' ) ) or
+                        a.event_type_xl in
+                        <foreach item="eventTypeXl" collection="defaultTypeXl" open="(" separator="," close=")">
+                            #{eventTypeXl}
+                        </foreach>)
+                    </when>
+                    <otherwise>
+                        and a.event_type_xl in
+                        <foreach item="eventTypeXl" collection="defaultTypeXl" open="(" separator="," close=")">
+                            #{eventTypeXl}
+                        </foreach>
+                    </otherwise>
+                </choose>
+            </otherwise>
+        </choose>
+        order by a.create_time desc
+    </select>
+
+    <select id="selectCentereventTEventcatalogueListByPc_旧代码,暂时先不用删,看看新代码稳定不,谁删谁后续维护哦" parameterType="CentereventTEventcatalogue"
+            resultMap="CentereventTEventcatalogueResult">
+        select a.id, a.event_code, y1.event_type_name eventTypeLabel, y2.event_type_name eventTypeXlLabel, event_name,
+        event_description, report_source, longitude, latitude, reportor, a.is_urged, a.event_status,
+        a.event_status_value, a.create_by, a.create_name, a.create_time, a.update_by, a.update_name, a.update_time,
+        data_status, a.dept_id, a.dept_name, address, urge_count
+        from centerevent_t_eventcatalogue a
+        left join centerevent_t_eventtype y1 on y1.id = a.event_type
+        left join centerevent_t_eventtype y2 on y2.id = a.event_type_xl
         left join centerevent_t_dept_event d on d.event_code = a.event_code
         left join centerevent_t_dept_event d on d.event_code = a.event_code
         left join ${database_system}.sys_dept c on c.dept_id = d.dept_id
         left join ${database_system}.sys_dept c on c.dept_id = d.dept_id
         <where>
         <where>