Kaynağa Gözat

sql优化代码提交

wang_xy 2 yıl önce
ebeveyn
işleme
ed31d070fb

+ 0 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gas/GAreaController.java

@@ -88,7 +88,6 @@ public class GAreaController extends BaseController {
      * 导出小区列表
      */
     @ApiOperation("导出小区列表")
-    @PreAuthorize("@ss.hasPermi('gas:area:exports')")
     @Log(title = "小区", businessType = BusinessType.EXPORT)
     @GetMapping("/exports")
     public void exports(@Validated GAreaBo bo, HttpServletResponse response) {

+ 36 - 37
ruoyi-gas/src/main/resources/mapper/GAreaMapper.xml

@@ -56,9 +56,9 @@
     <select id="getHouse" resultType="java.lang.Integer">
         select count(a.id)
         from g_house a
-                     left join g_unit b on a.unit_id = b.id  and b.del_flag = '0'
-                     left join g_building c on b.building_id = c.id  and c.del_flag = '0'
-                     left join g_area d on c.area_id = d.id and d.del_flag = '0'
+                     left join g_unit b on (a.unit_id = b.id  and b.del_flag = '0')
+                     left join g_building c on (b.building_id = c.id  and c.del_flag = '0')
+                     left join g_area d on (c.area_id = d.id and d.del_flag = '0')
         where
            a.del_flag = '0'  and  d.id = #{id}
     </select>
@@ -66,10 +66,10 @@
         select count( o.house_id) as value,
         o.examine_status as name
         from g_order o
-        left join g_house a on o.house_id = a.id and a.del_flag = '0'
-        left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-        left join g_building c on b.building_id = c.id and c.del_flag = '0'
-        left join g_area d on c.area_id = d.id  and d.del_flag = '0'
+        left join g_house a on (o.house_id = a.id and a.del_flag = '0')
+        left join g_unit b on (a.unit_id = b.id and b.del_flag = '0')
+        left join g_building c on (b.building_id = c.id and c.del_flag = '0')
+        left join g_area d on (c.area_id = d.id  and d.del_flag = '0')
         where o.order_status = '002'
         and o.service_type = '002'
         and o.del_flag = '0'
@@ -82,10 +82,10 @@
         select count( o.id) as value,
         o.service_type as name
         from g_order o
-        left join g_house a on o.house_id = a.id and a.del_flag = '0'
-        left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-        left join g_building c on b.building_id = c.id and c.del_flag = '0'
-        left join g_area d on c.area_id = d.id and d.del_flag = '0'
+        left join g_house a on (o.house_id = a.id and a.del_flag = '0')
+        left join g_unit b on (a.unit_id = b.id and b.del_flag = '0')
+        left join g_building c on (b.building_id = c.id and c.del_flag = '0')
+        left join g_area d on (c.area_id = d.id and d.del_flag = '0')
         where o.del_flag = '0'
         and o.service_type = ''
         or o.service_type = '001'
@@ -106,9 +106,9 @@
                d.affiliated_package as affiliatedPackage,
                a.name as houseName
         from g_area d
-                 left join g_building c on d.id = c.area_id and c.del_flag = '0'
-                 left join g_unit b on c.id = b.building_id and b.del_flag = '0'
-                 left join  g_house a on b.id = a.unit_id and a.del_flag = '0'
+                 left join g_building c on (d.id = c.area_id and c.del_flag = '0')
+                 left join g_unit b on (c.id = b.building_id and b.del_flag = '0')
+                 left join  g_house a on (b.id = a.unit_id and a.del_flag = '0')
         where d.del_flag = '0'
     </select>
     <select id="getExport" resultType="com.ruoyi.gas.domain.vo.GExportsVo">
@@ -119,7 +119,7 @@
                a.affiliated_package    AS affiliatedPackage,
                COUNT(b.area_id) AS count
         FROM g_area a
-            LEFT JOIN g_order b ON b.area_id = a.id AND b.del_flag = '0'
+            LEFT JOIN g_order b ON (b.area_id = a.id AND b.del_flag = '0')
         WHERE a.del_flag = '0'
           AND a.calculate_district_id = #{calculateDistrictId}
           AND a.affiliated_package = #{affiliatedPackage}
@@ -130,7 +130,7 @@
         SELECT
             CONCAT(a.dict_label,'-工程任务单(',b.dict_label,')') AS name
         FROM `sys_dict_data` a
-                 LEFT JOIN sys_dict_data b ON b.dict_type = 'affiliated_package' AND b.dict_value = #{affiliatedPackage}
+                 LEFT JOIN sys_dict_data b ON (b.dict_type = 'affiliated_package' AND b.dict_value = #{affiliatedPackage})
         WHERE a.dict_type = 'district' AND a.dict_value = #{calculateDistrictId}
     </select>
     <select id="getByName" resultType="com.ruoyi.gas.domain.GArea">
@@ -142,10 +142,10 @@
         select count( o.house_id) as value,
         o.service_type as name
         from g_order o
-        left join g_house a on o.house_id = a.id and a.del_flag = '0'
-        left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-        left join g_building c on b.building_id = c.id and c.del_flag = '0'
-        left join g_area d on c.area_id = d.id and d.del_flag = '0'
+        left join g_house a on (o.house_id = a.id and a.del_flag = '0')
+        left join g_unit b on (a.unit_id = b.id and b.del_flag = '0')
+        left join g_building c on (b.building_id = c.id and c.del_flag = '0')
+        left join g_area d on (c.area_id = d.id and d.del_flag = '0')
         where o.del_flag = '0'
         and o.service_type = '002' or o.service_type = '003' or o.service_type = ''
         <if test="areaId != null  and areaId != ''">
@@ -156,10 +156,10 @@
     <select id="getInConform" resultType="java.lang.Integer">
         select count( o.house_id)
         from g_order o
-        left join g_house a on o.house_id = a.id and a.del_flag = '0'
-        left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-        left join g_building c on b.building_id = c.id and c.del_flag = '0'
-        left join g_area d on c.area_id = d.id  and d.del_flag = '0'
+        left join g_house a on (o.house_id = a.id and a.del_flag = '0')
+        left join g_unit b on (a.unit_id = b.id and b.del_flag = '0')
+        left join g_building c on (b.building_id = c.id and c.del_flag = '0')
+        left join g_area d on (c.area_id = d.id  and d.del_flag = '0')
         where o.service_type = '003'
         and o.del_flag = '0'
         <if test="areaId != null  and areaId != ''">
@@ -169,9 +169,9 @@
     <select id="getHouseCount" resultType="java.lang.Integer">
         select count( a.id)
         from g_house a
-        left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-        left join g_building c on b.building_id = c.id and c.del_flag = '0'
-        left join g_area d on c.area_id = d.id and d.del_flag = '0'
+        left join g_unit b on (a.unit_id = b.id and b.del_flag = '0')
+        left join g_building c on (b.building_id = c.id and c.del_flag = '0')
+        left join g_area d on (c.area_id = d.id and d.del_flag = '0')
         where a.del_flag = '0'
         <if test="areaId != null  and areaId != ''">
             and d.id = #{areaId}
@@ -189,7 +189,7 @@
     <select id="getPhoto" resultType="java.lang.String">
         select a.pic_url
         from g_order_photo a
-                     left join g_order b on a.order_id = b.id and b.service_type = '002' and b.examine_status = '001'
+                     left join g_order b on (a.order_id = b.id and b.service_type = '002' and b.examine_status = '001')
                      left join g_house c on b.house_id = c.id
                      left join g_unit d on c.unit_id = d.id
                      left join g_building e on d.building_id=e.id
@@ -200,9 +200,9 @@
         select b.id as id,
                 CONCAT(e.name,'-',d.name,'-',c.name,'-',b.name) as houseName
         from g_house b
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-            left join g_building d on c.building_id = d.id and d.del_flag = '0'
-            left join g_area e on d.area_id = e.id and e.id = #{areaId} and e.del_flag = '0'
+        left join g_unit c on (b.unit_id = c.id and c.del_flag = '0')
+            left join g_building d on (c.building_id = d.id and d.del_flag = '0')
+            left join g_area e on (d.area_id = e.id and e.id = #{areaId} and e.del_flag = '0')
         where
            b.del_flag = '0'
     </select>
@@ -210,13 +210,12 @@
         select a.house_id as id,
                CONCAT(e.name,'-',d.name,'-',c.name,'-',b.name) as houseName
         from g_order a
-                     left join g_house b on a.house_id = b.id and b.del_flag = '0'
-                     left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-                     left join g_building d on c.building_id = d.id and d.del_flag = '0'
-                     left join g_area e on d.area_id = e.id and e.del_flag = '0'
+                     left join g_house b on (a.house_id = b.id and b.del_flag = '0')
+                     left join g_unit c on (b.unit_id = c.id and c.del_flag = '0')
+                     left join g_building d on (c.building_id = d.id and d.del_flag = '0')
+                     left join g_area e on (d.area_id = e.id and e.id = #{areaId} and e.del_flag = '0')
         where
-           e.id = #{areaId}
-        and  a.del_flag = '0'
+         a.del_flag = '0'
         and a.service_type = '002'
         and a.examine_status = '001'
     </select>

+ 52 - 52
ruoyi-gas/src/main/resources/mapper/GOrderMapper.xml

@@ -40,11 +40,11 @@
         a.version as version,
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id and e.del_flag = '0'
-        left join sys_dict_data f on e.district = f.dict_value and f.dict_type='district'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id and e.del_flag = '0')
+        left join sys_dict_data f on ( e.district = f.dict_value and f.dict_type='district')
         left join g_user u on a.user_id = u.id
         where a.del_flag = '0'
         and a.service_type not in ('004','005','006')
@@ -104,10 +104,10 @@
         a.house_id as houseId,
         a.reason as reason
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id  and e.del_flag = '0'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id  and e.del_flag = '0')
         left join sys_dict_data f on e.district = f.dict_value
         left join g_user u on a.user_id = u.id
         where a.del_flag = '0'
@@ -166,11 +166,11 @@
         a.version as version,
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id  and e.del_flag = '0'
-        left join sys_dict_data f on e.district = f.dict_value and f.dict_type='district'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id  and e.del_flag = '0')
+        left join sys_dict_data f on ( e.district = f.dict_value and f.dict_type='district')
         left join g_user u on a.user_id = u.id
         where a.del_flag = '0' and a.order_status = '001'
         and a.service_type not in ('004','005','006')
@@ -208,10 +208,10 @@
     <select id="getCount" resultType="java.lang.Integer">
         select count(DISTINCT o.house_id)
         from g_order o
-                     left join g_house a on o.house_id = a.id and a.del_flag = '0'
-                     left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-                     left join g_building c on b.building_id = c.id and c.del_flag = '0'
-                     left join g_area d on c.area_id = d.id and d.del_flag = '0'
+                     left join g_house a on ( o.house_id = a.id and a.del_flag = '0')
+                     left join g_unit b on ( a.unit_id = b.id and b.del_flag = '0')
+                     left join g_building c on ( b.building_id = c.id and c.del_flag = '0')
+                     left join g_area d on ( c.area_id = d.id and d.del_flag = '0')
         where d.id = #{id}
           and o.del_flag = '0'
           and o.order_status = '002'
@@ -221,10 +221,10 @@
         select count(DISTINCT o.id) as value,
             o.pipe_type as name
         from g_order o
-                left join g_house a on o.house_id = a.id and a.del_flag = '0'
-                left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-                left join g_building c on b.building_id = c.id and c.del_flag = '0'
-                left join g_area d on c.area_id = d.id and d.del_flag = '0'
+                left join g_house a on ( o.house_id = a.id and a.del_flag = '0')
+                left join g_unit b on ( a.unit_id = b.id and b.del_flag = '0')
+                left join g_building c on ( b.building_id = c.id and c.del_flag = '0')
+                left join g_area d on ( c.area_id = d.id and d.del_flag = '0')
         where o.service_type = '002'
         and o.del_flag = '0'
         <if test="id != null  and id != ''">
@@ -236,10 +236,10 @@
         select count(DISTINCT o.id) as value,
             o.pipe_length as name
         from g_order o
-                left join g_house a on o.house_id = a.id and a.del_flag = '0'
-                left join g_unit b on a.unit_id = b.id  and b.del_flag = '0'
-                left join g_building c on b.building_id = c.id  and c.del_flag = '0'
-                left join g_area d on c.area_id = d.id  and d.del_flag = '0'
+                left join g_house a on ( o.house_id = a.id and a.del_flag = '0')
+                left join g_unit b on ( a.unit_id = b.id  and b.del_flag = '0')
+                left join g_building c on ( b.building_id = c.id  and c.del_flag = '0')
+                left join g_area d on ( c.area_id = d.id  and d.del_flag = '0')
         where
         o.service_type = '002'
           and o.del_flag = '0'
@@ -252,10 +252,10 @@
         select count(DISTINCT o.id) as value,
         o.valve_type as name
         from g_order o
-        left join g_house a on o.house_id = a.id and a.del_flag = '0'
-        left join g_unit b on a.unit_id = b.id and b.del_flag = '0'
-        left join g_building c on b.building_id = c.id and c.del_flag = '0'
-        left join g_area d on c.area_id = d.id and d.del_flag = '0'
+        left join g_house a on ( o.house_id = a.id and a.del_flag = '0')
+        left join g_unit b on ( a.unit_id = b.id and b.del_flag = '0')
+        left join g_building c on ( b.building_id = c.id and c.del_flag = '0')
+        left join g_area d on ( c.area_id = d.id and d.del_flag = '0')
         where o.service_type = '002'
         and o.del_flag = '0'
         <if test="id != null  and id != ''">
@@ -323,12 +323,12 @@
         a.version as version,
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id and e.del_flag = '0'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id and e.del_flag = '0')
         left join g_user u on a.user_id = u.id
-        left join sys_dict_data f on e.district = f.dict_value and f.dict_type='district'
+        left join sys_dict_data f on ( e.district = f.dict_value and f.dict_type='district')
         where a.del_flag = '0' and a.service_type ='004'
         <if test="p.userId != null  and p.userId != ''">
             and a.user_id = #{p.userId}
@@ -368,10 +368,10 @@
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house,
         a.whether as whether
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id and e.del_flag = '0'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id and e.del_flag = '0')
         left join g_user u on a.user_id = u.id
         left join sys_dict_data f on e.district = f.dict_value
         where a.del_flag = '0'
@@ -416,11 +416,11 @@
         a.version as version,
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id and e.del_flag = '0'
-        left join sys_dict_data f on e.district = f.dict_value AND f.dict_type='district'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id and e.del_flag = '0')
+        left join sys_dict_data f on ( e.district = f.dict_value AND f.dict_type='district')
         left join g_user u on a.user_id = u.id
         where a.service_type ='005' and a.del_flag = '0'
         <if test="p.userId != null  and p.userId != ''">
@@ -461,10 +461,10 @@
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house,
         a.whether as whether
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id and e.del_flag = '0'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id and e.del_flag = '0')
         left join sys_dict_data f on e.district = f.dict_value
         left join g_user u on a.user_id = u.id
         where a.del_flag = '0'
@@ -507,10 +507,10 @@
         a.update_time as updateTime,
         CONCAT(f.dict_label,'-',e.name,'-',d.name,'-',c.name,'-',b.name) as house
         from g_order a
-        left join g_house b on a.house_id = b.id and b.del_flag = '0'
-        left join g_unit c on b.unit_id = c.id and c.del_flag = '0'
-        left join g_building d on c.building_id = d.id and d.del_flag = '0'
-        left join g_area e on d.area_id = e.id and e.del_flag = '0'
+        left join g_house b on ( a.house_id = b.id and b.del_flag = '0')
+        left join g_unit c on ( b.unit_id = c.id and c.del_flag = '0')
+        left join g_building d on ( c.building_id = d.id and d.del_flag = '0')
+        left join g_area e on ( d.area_id = e.id and e.del_flag = '0')
         left join sys_dict_data f on e.district = f.dict_value
         left join g_user u on a.user_id = u.id
         where a.del_flag = '0'