Browse Source

按表类型统计抄表率

lin 4 years ago
parent
commit
a536e48165

+ 17 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/StatMeterReadRateByBuildingMapper.java

@@ -60,6 +60,13 @@ public interface StatMeterReadRateByBuildingMapper {
             @Param("buildingIds") List<Integer> buildingIds,
             @Param("customerIds") List<Integer> customerIds);
 
+    WaterReadRateCountDto getRateCountByTimeV2(
+            @Param("tableName") String tableName,
+            @Param("siteId") Integer siteId,
+            @Param("startDate") Integer startDate,
+            @Param("buildingIds") List<Integer> buildingIds,
+            @Param("customerIds") List<Integer> customerIds);
+
     WaterReadRateCountDto getRateCount7DayByTime(
             @Param("siteId") Integer siteId,
             @Param("startDate") Integer startDate,
@@ -81,6 +88,16 @@ public interface StatMeterReadRateByBuildingMapper {
             @Param("buildingIds") List<Integer> buildingIds,
             @Param("customerIds") List<Integer> customerIds);
 
+
+    List<WaterReadRateListDto> getRateListByTypeV2(
+            @Param("tableName") String tableName,
+            @Param("siteId") Integer siteId,
+            @Param("sortColumn") String sortColumn,
+            @Param("sortOrder") String sortOrder,
+            @Param("startDate") Integer startDate,
+            @Param("buildingIds") List<Integer> buildingIds,
+            @Param("customerIds") List<Integer> customerIds);
+
     List<WaterReadRateListDto> getRateList7DayByType(
             @Param("siteId") Integer siteId,
             @Param("sortColumn") String sortColumn,

+ 18 - 9
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/StatMeterReadRateByBuildingServiceImpl.java

@@ -249,11 +249,14 @@ public class StatMeterReadRateByBuildingServiceImpl implements StatMeterReadRate
         Integer startDate = Integer.valueOf(LocalDate.now().plusDays(-1).format(formatter));
 
         if (period == 2) {
-            return statMeterReadRateByBuildingMapper.getRateCountByTime(loginUser.getSiteId(), startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building";
+            return statMeterReadRateByBuildingMapper.getRateCountByTimeV2(tableName,loginUser.getSiteId(), startDate, buildingIds, UserUtil.getCustomerIds());
         } else if (period == 7) {
-            return statMeterReadRateByBuildingMapper.getRateCount7DayByTime(loginUser.getSiteId(), startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building";
+            return statMeterReadRateByBuildingMapper.getRateCountByTimeV2(tableName,loginUser.getSiteId(), startDate, buildingIds, UserUtil.getCustomerIds());
         } else if (period == 15) {
-            return statMeterReadRateByBuildingMapper.getRateCount15DayByTime(loginUser.getSiteId(), startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building";
+            return statMeterReadRateByBuildingMapper.getRateCountByTimeV2(tableName,loginUser.getSiteId(), startDate, buildingIds, UserUtil.getCustomerIds());
         }
         return null;
 
@@ -273,11 +276,14 @@ public class StatMeterReadRateByBuildingServiceImpl implements StatMeterReadRate
 
         List<WaterReadRateListDto> waterReadRateListDtoList = newArrayList();
         if (period == 2) {
-            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByType(loginUser.getSiteId(), sortColumn, sortOrder, startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building";
+            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByTypeV2(tableName,loginUser.getSiteId(), sortColumn, sortOrder, startDate, buildingIds, UserUtil.getCustomerIds());
         } else if (period == 7) {
-            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateList7DayByType(loginUser.getSiteId(), sortColumn, sortOrder, startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building_7day";
+            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByTypeV2(tableName,loginUser.getSiteId(), sortColumn, sortOrder, startDate, buildingIds, UserUtil.getCustomerIds());
         } else if (period == 15) {
-            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateList15DayByType(loginUser.getSiteId(), sortColumn, sortOrder, startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building_15day";
+            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByTypeV2(tableName,loginUser.getSiteId(), sortColumn, sortOrder, startDate, buildingIds, UserUtil.getCustomerIds());
         }
         return waterReadRateListDtoList;
     }
@@ -296,11 +302,14 @@ public class StatMeterReadRateByBuildingServiceImpl implements StatMeterReadRate
 
         List<WaterReadRateListDto> waterReadRateListDtoList = newArrayList();
         if (period == 2) {
-            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByType(loginUser.getSiteId(), null, null, startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building";
+            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByTypeV2(tableName,loginUser.getSiteId(), null, null, startDate, buildingIds, UserUtil.getCustomerIds());
         } else if (period == 7) {
-            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateList7DayByType(loginUser.getSiteId(), null, null, startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building_7day";
+            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByTypeV2(tableName,loginUser.getSiteId(), null, null, startDate, buildingIds, UserUtil.getCustomerIds());
         } else if (period == 15) {
-            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateList15DayByType(loginUser.getSiteId(), null, null, startDate, buildingIds, UserUtil.getCustomerIds());
+            String tableName = "sc_stat_meter_read_rate_by_building_15day";
+            waterReadRateListDtoList = statMeterReadRateByBuildingMapper.getRateListByTypeV2(tableName,loginUser.getSiteId(), null, null, startDate, buildingIds, UserUtil.getCustomerIds());
         }
 
 

+ 38 - 0
smart-city-platform/src/main/resources/mapper/StatMeterReadRateByBuildingMapper.xml

@@ -307,6 +307,20 @@
         <if test="customerIds != null and customerIds.size() != 0"> and a.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
     </select>
 
+    <select id="getRateCountByTimeV2" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
+        SELECT
+        SUM(device_count) as device_count,
+        SUM(read_times) as read_times,
+        SUM(real_read_times) as real_read_times,
+        SUM(un_read_times) as un_read_times,
+        ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
+        FROM ${tableName} ssmrrbb
+        WHERE ssmrrbb.stat_day = #{startDate}
+        <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
+        <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>
+    </select>
+
     <!--按表类型查询7天内的抄表率数据统计-->
     <select id="getRateCount7DayByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
         SELECT
@@ -381,6 +395,30 @@
         where t1.device_count is not null
     </select>
 
+    <select id="getRateListByTypeV2" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
+        SELECT
+        ssmrrbb.channel_id,
+        sc.channel_name as device_type_name,
+        SUM(device_count) as device_count,
+        SUM(ssmrrbb.read_times) as read_times,
+        SUM(ssmrrbb.real_read_times) as real_read_times,
+        SUM(ssmrrbb.un_read_times) as un_read_times,
+        ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
+        FROM ${tableName} ssmrrbb
+        left join sc_channel sc on(sc.id = ssmrrbb.channel_id)
+        WHERE
+        ssmrrbb.stat_day =  #{startDate}
+        <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
+        <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.channel_id,sc.channel_name
+        <if test="sortColumn != null and sortColumn != ''">
+            <if test="sortOrder != null and sortOrder != ''">
+                order by ${sortColumn} ${sortOrder}
+            </if>
+        </if>
+    </select>
+
     <!--查询7天内根据表类型的抄表率数据统计-->
     <select id="getRateList7DayByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
         select * from (