Browse Source

优化首页查询效率

夏文涛 8 tháng trước cách đây
mục cha
commit
6cec514222
2 tập tin đã thay đổi với 59 bổ sung110 xóa
  1. 41 42
      .idea/workspace.xml
  2. 18 68
      src/main/resources/mapper/repair/RepairRecordMapper.xml

+ 41 - 42
.idea/workspace.xml

@@ -20,11 +20,11 @@
   </component>
   <component name="FileEditorManager">
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
-      <file pinned="false" current-in-tab="false">
+      <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/controller/RepairRecordController.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="453">
-              <caret line="1069" column="60" selection-start-line="1069" selection-start-column="45" selection-end-line="1069" selection-end-column="60" />
+            <state relative-caret-position="140">
+              <caret line="4179" column="65" selection-start-line="4179" selection-start-column="58" selection-end-line="4179" selection-end-column="65" />
               <folding>
                 <element signature="imports" expanded="true" />
               </folding>
@@ -33,28 +33,28 @@
         </entry>
       </file>
       <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/controller/LoginController.java">
+        <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/common/utils/DateUtils.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="6785">
-              <caret line="337" column="37" selection-start-line="337" selection-start-column="30" selection-end-line="337" selection-end-column="37" />
+            <state relative-caret-position="154">
+              <caret line="32" column="25" selection-start-line="32" selection-start-column="25" selection-end-line="32" selection-end-column="25" />
             </state>
           </provider>
         </entry>
       </file>
       <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/common/utils/JWTUtil.java">
+        <entry file="file://$PROJECT_DIR$/src/main/resources/mapper/repair/RepairRecordMapper.xml">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="138">
-              <caret line="18" column="9" selection-start-line="18" selection-start-column="9" selection-end-line="18" selection-end-column="9" />
+            <state relative-caret-position="139">
+              <caret line="1059" column="35" selection-start-line="1059" selection-start-column="35" selection-end-line="1059" selection-end-column="35" />
             </state>
           </provider>
         </entry>
       </file>
-      <file pinned="false" current-in-tab="true">
-        <entry file="file://$PROJECT_DIR$/src/main/resources/mapper/repair/RepairRecordMapper.xml">
+      <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/common/utils/JWTUtil.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="367">
-              <caret line="495" column="67" selection-start-line="495" selection-start-column="67" selection-end-line="495" selection-end-column="67" />
+            <state relative-caret-position="138">
+              <caret line="18" column="9" selection-start-line="18" selection-start-column="9" selection-end-line="18" selection-end-column="9" />
             </state>
           </provider>
         </entry>
@@ -120,9 +120,6 @@
   </component>
   <component name="FindInProjectRecents">
     <findStrings>
-      <find>queryRepairCloses</find>
-      <find>事务</find>
-      <find>MapperS</find>
       <find>EnableTransactionManagement</find>
       <find>result</find>
       <find>RdvName</find>
@@ -139,8 +136,6 @@
       <find>closedCount</find>
       <find>queryManageCount</find>
       <find>closed_count</find>
-      <find>maintenanceGoods</find>
-      <find>maintenanceGoodsTotal</find>
       <find>case</find>
       <find>NotT</find>
       <find>60 * 60</find>
@@ -150,6 +145,11 @@
       <find>queryManagePage</find>
       <find>queryNotTimeout</find>
       <find>(case rr.maintenance_state when 2 then (select user_name from repair_user where id = rdv.user_id and deleted = 0) else '' end) as rdvName</find>
+      <find>maintenanceWorker</find>
+      <find>maintenanceGoods</find>
+      <find>maintenanceGoodsTotal</find>
+      <find>repairArea</find>
+      <find>repairAreaTotal</find>
     </findStrings>
     <replaceStrings>
       <replace />
@@ -226,7 +226,7 @@
   </component>
   <component name="ProjectFrameBounds">
     <option name="x" value="-7" />
-    <option name="width" value="958" />
+    <option name="width" value="974" />
     <option name="height" value="1039" />
   </component>
   <component name="ProjectId" id="2ahuEEqvb7VL7aZNfgOouNVEGo4" />
@@ -608,12 +608,12 @@
       <workItem from="1756693944345" duration="29000" />
       <workItem from="1758268354634" duration="308000" />
       <workItem from="1759110496778" duration="10917000" />
-      <workItem from="1760945262667" duration="1949000" />
+      <workItem from="1760945262667" duration="5793000" />
     </task>
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="287915000" />
+    <option name="totallyTimeSpent" value="291759000" />
   </component>
   <component name="TodoView">
     <todo-panel id="selected-file">
@@ -625,8 +625,7 @@
     </todo-panel>
   </component>
   <component name="ToolWindowManager">
-    <frame x="-8" y="-8" width="1936" height="1048" extended-state="6" />
-    <editor active="true" />
+    <frame x="-7" y="0" width="974" height="1039" extended-state="0" />
     <layout>
       <window_info id="Structure" order="0" side_tool="true" weight="0.25" />
       <window_info id="Designer" order="1" />
@@ -636,11 +635,11 @@
       <window_info id="UI Designer" order="5" />
       <window_info id="Favorites" order="6" side_tool="true" />
       <window_info id="Web" order="7" side_tool="true" />
-      <window_info content_ui="combo" id="Project" order="8" weight="0.40087622" />
+      <window_info content_ui="combo" id="Project" order="8" visible="true" weight="0.392779" />
       <window_info anchor="bottom" id="Message" order="0" />
       <window_info anchor="bottom" id="Find" order="1" />
-      <window_info anchor="bottom" id="Run" order="2" weight="0.42651933" />
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.809628" />
+      <window_info anchor="bottom" id="Run" order="2" weight="0.41767955" />
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.9668508" />
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
       <window_info anchor="bottom" id="TODO" order="6" weight="0.32932165" />
@@ -657,7 +656,7 @@
       <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
       <window_info anchor="right" id="Ant Build" order="1" weight="0.2494432" />
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
-      <window_info anchor="right" id="Maven" order="3" weight="0.6247265" />
+      <window_info anchor="right" id="Maven" order="3" visible="true" weight="0.5743983" />
       <window_info anchor="right" id="Palette" order="4" />
       <window_info anchor="right" id="Capture Analysis" order="5" />
       <window_info anchor="right" id="Database" order="6" />
@@ -737,13 +736,6 @@
     <option name="FILTER_TARGETS" value="false" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/common/result/ResponseStatusEnum.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="920">
-          <caret line="40" column="44" selection-start-line="40" selection-start-column="30" selection-end-line="40" selection-end-column="44" />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/common/utils/StrUtils.java">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="276">
@@ -1067,13 +1059,10 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/controller/RepairRecordController.java">
+    <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/common/utils/DateUtils.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="453">
-          <caret line="1069" column="60" selection-start-line="1069" selection-start-column="45" selection-end-line="1069" selection-end-column="60" />
-          <folding>
-            <element signature="imports" expanded="true" />
-          </folding>
+        <state relative-caret-position="154">
+          <caret line="32" column="25" selection-start-line="32" selection-start-column="25" selection-end-line="32" selection-end-column="25" />
         </state>
       </provider>
     </entry>
@@ -1086,8 +1075,18 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/src/main/resources/mapper/repair/RepairRecordMapper.xml">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="367">
-          <caret line="495" column="67" selection-start-line="495" selection-start-column="67" selection-end-line="495" selection-end-column="67" />
+        <state relative-caret-position="139">
+          <caret line="1059" column="35" selection-start-line="1059" selection-start-column="35" selection-end-line="1059" selection-end-column="35" />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/main/java/com/repair/controller/RepairRecordController.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="140">
+          <caret line="4179" column="65" selection-start-line="4179" selection-start-column="58" selection-end-line="4179" selection-end-column="65" />
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
         </state>
       </provider>
     </entry>

+ 18 - 68
src/main/resources/mapper/repair/RepairRecordMapper.xml

@@ -1049,22 +1049,15 @@
         FROM (SELECT count(rr.area_id)   AS orders_total,
                      rs.`name`           AS school_name,
                      rr.area_id          AS area_name,
-                     (SELECT COUNT(area_id)
-                      FROM `repair_record`
-                      WHERE price > 0
-                        AND rr.area_id = area_id
-                        AND deleted = 0) AS orders_compensation,
-                     (SELECT COUNT(area_id)
-                      FROM `repair_record`
-                      WHERE (price IS NULL OR price = 0)
-                        AND rr.area_id = area_id
-                        AND deleted = 0) AS orders_gratis,
+                     COUNT(CASE WHEN rr.price > 0 THEN 1 END) AS orders_compensation,
+        COUNT(CASE WHEN rr.price IS NULL OR rr.price = 0 THEN 1 END) AS orders_gratis,
                      SUM(rr.price)       AS total_price
               FROM `repair_record` rr
                        LEFT JOIN repair_school rs ON rs.deleted = 0
                   AND rr.school_id = rs.id
               where rr.deleted = 0
-              GROUP BY rr.area_id) ra
+              GROUP BY rr.area_id, rs.name) ra
+              ORDER BY ra.area_name
     </select>
 
     <select id="repairArea" resultType="com.repair.model.vo.RepairAreaVo">
@@ -1072,28 +1065,8 @@
         FROM (SELECT count(rr.area_id) AS orders_total,
         rs.`name` AS school_name,
         rr.area_id AS area_name,
-        (SELECT COUNT(area_id)
-        FROM `repair_record`
-        <where>
-            AND price > 0
-            AND rr.area_id = area_id
-            AND deleted = 0
-            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
-                and report_time between #{startTime} and #{endTime}
-            </if>
-        </where>
-        ) AS orders_compensation,
-        (SELECT COUNT(area_id)
-        FROM `repair_record`
-        <where>
-            AND (price IS NULL OR price = 0)
-            AND rr.area_id = area_id
-            AND deleted = 0
-            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
-                and report_time between #{startTime} and #{endTime}
-            </if>
-        </where>
-        ) AS orders_gratis,
+        COUNT(CASE WHEN rr.price > 0 THEN 1 END) AS orders_compensation,
+        COUNT(CASE WHEN rr.price IS NULL OR rr.price = 0 THEN 1 END) AS orders_gratis,
         SUM(rr.price) AS total_price
         FROM `repair_record` rr
         LEFT JOIN repair_school rs ON rs.deleted = 0
@@ -1104,28 +1077,22 @@
                 and report_time between #{startTime} and #{endTime}
             </if>
         </where>
-        GROUP BY rr.area_id) ra
+        GROUP BY rr.area_id,rs.name) ra
+        ORDER BY ra.area_name
     </select>
     <select id="maintenanceGoodsTotal" resultType="com.repair.model.vo.MaintenanceGoodsVo">
         SELECT row_number() over ( ORDER BY wx.article_name ) AS id, wx.*
         FROM (SELECT rat.`name`           AS article_name,
                      rat.school_id as school_id,
                      count(rr.article_id) AS orders_total,
-                     (SELECT COUNT(article_id)
-                      FROM `repair_record`
-                      WHERE price > 0
-                        AND rr.article_id = article_id
-                        AND deleted = 0)  AS orders_compensation,
-                     (SELECT COUNT(article_id)
-                      FROM `repair_record`
-                      WHERE (price IS NULL OR price = 0)
-                        AND rr.article_id = article_id
-                        AND deleted = 0)  AS orders_gratis,
-                     SUM(rr.price)        AS total_price
+                     COUNT(CASE WHEN rr.price > 0 THEN 1 END) AS orders_compensation,
+        COUNT(CASE WHEN rr.price IS NULL OR rr.price = 0 THEN 1 END) AS orders_gratis,
+                     SUM(rr.price) AS total_price
               FROM `repair_record` rr
-                       LEFT JOIN repair_article_type rat ON rr.article_id = rat.id
+              LEFT JOIN repair_article_type rat ON rr.article_id = rat.id
               WHERE rr.deleted = 0
-              GROUP BY rr.article_id) wx
+              GROUP BY rr.article_id, rat.name, rat.school_id) wx
+              ORDER BY wx.article_name
     </select>
 
     <select id="maintenanceGoods" resultType="com.repair.model.vo.MaintenanceGoodsVo">
@@ -1133,26 +1100,8 @@
         FROM (SELECT rat.`name` AS article_name,
         rat.school_id as school_id,
         count(rr.article_id) AS orders_total,
-        (SELECT COUNT(article_id)
-        FROM `repair_record`
-        <where>
-            and price > 0 AND rr.article_id = article_id AND deleted = 0
-            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
-                and report_time between #{startTime} and #{endTime}
-            </if>
-        </where>
-        ) AS orders_compensation,
-        (SELECT COUNT(article_id)
-        FROM `repair_record`
-        <where>
-            and (price IS NULL OR price = 0)
-            AND rr.article_id = article_id
-            AND deleted = 0
-            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
-                and report_time between #{startTime} and #{endTime}
-            </if>
-        </where>
-        ) AS orders_gratis,
+        COUNT(CASE WHEN rr.price > 0 THEN 1 END) AS orders_compensation,
+        COUNT(CASE WHEN rr.price IS NULL OR rr.price = 0 THEN 1 END) AS orders_gratis,
         SUM(rr.price) AS total_price
         FROM `repair_record` rr
         LEFT JOIN repair_article_type rat ON rr.article_id = rat.id
@@ -1162,7 +1111,8 @@
                 and report_time between #{startTime} and #{endTime}
             </if>
         </where>
-        GROUP BY rr.article_id) wx
+        GROUP BY rr.article_id, rat.name, rat.school_id) wx
+        ORDER BY wx.article_name
     </select>
     <select id="repairAreaExport" resultType="com.repair.model.vo.RepairAreaVo">
         SELECT row_number() over ( ORDER BY ra.area_name ) AS id, ra.*