Browse Source

批量安装BUG

lin 4 years ago
parent
commit
c7b4f38c10

+ 21 - 17
smart-city-platform/src/main/resources/mapper/StatMeterReadRateByBuildingMapper.xml

@@ -493,23 +493,27 @@
     </select>
 
     <select id="getRateListByCustomerV2" resultType="com.bz.smart_city.dto.CustomerRateDto">
-		SELECT
-            ssmrrbb.customer_id,
-            sc.customer_name,
-            sc.children_num
-        FROM
-            ${tableName} ssmrrbb
-        left join sc_customer sc on(sc.id = ssmrrbb.customer_id)
-        WHERE
-            ssmrrbb.site_id = #{siteId}
-            <if test="channelId != null"> and ssmrrbb.channel_id = #{channelId} </if>
-            AND ssmrrbb.stat_day = #{startDate}
-            AND ssmrrbb.channel_id <![CDATA[ <> ]]> - 99
-            <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
-            <if test="customerIds != null and customerIds.size() != 0"> and ssmrrbb.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
-            <if test="customerIds == null "> and sc.parent_id = 0 </if>
-        GROUP BY
-            ssmrrbb.customer_id,sc.customer_name,sc.children_num
+        SELECT sc.id as customer_id,sc.customer_name,sc.children_num FROM sc_customer sc
+        LEFT JOIN(
+            SELECT
+                ssmrrbb.customer_id,
+                SUM(device_count) as device_count
+            FROM
+                ${tableName} ssmrrbb
+            WHERE
+                ssmrrbb.site_id = #{siteId}
+                <if test="channelId != null"> and ssmrrbb.channel_id = #{channelId} </if>
+                AND ssmrrbb.stat_day = #{startDate}
+                AND ssmrrbb.channel_id <![CDATA[ <> ]]> - 99
+                <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
+                <if test="customerIds != null and customerIds.size() != 0"> and ssmrrbb.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
+            GROUP BY
+                ssmrrbb.customer_id
+        )t1 on(t1.customer_id = sc.id)
+        WHERE sc.`status` = 1 and sc.site_id = #{siteId}
+        <if test="customerIds != null and customerIds.size() != 0"> and sc.id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
+        <if test="customerIds == null "> and sc.parent_id = 0 </if>
+        ORDER BY device_count desc
     </select>
     <select id="getRateListByCustomerV2AndDeviceType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
         SELECT