Explorar o código

【CHG】方法抽象

zhaomn %!s(int64=2) %!d(string=hai) anos
pai
achega
63af6d4a4a

+ 29 - 44
railway-business/src/main/java/com/railway/business/bi/service/impl/ChartServiceImpl.java

@@ -61,29 +61,8 @@ public class ChartServiceImpl implements IChartService {
                 continue;
             }
             gqFlag.add(bdDto.getGq());
-            List<Integer> bdData = new ArrayList<>();
-            bdData.add(bdDto.getDj1());
-            bdData.add(bdDto.getDj2());
-            bdData.add(bdDto.getDj3());
-
-            List<Integer> dlData = new ArrayList<>();
             DlycDTO dlDto = dlycMap.get(bdDto.getGq());
-            if(null != dlDto){
-                dlData.add(dlDto.getDj1());
-                dlData.add(dlDto.getDj2());
-                dlData.add(dlDto.getDj3());
-            }else {
-                dlData.add(0);
-                dlData.add(0);
-                dlData.add(0);
-            }
-
-            List<SeriesDTO> series = new ArrayList<>();
-            SeriesDTO zs = createSeriesDTO(xAxis, bdData, "变电");
-            SeriesDTO yt = createSeriesDTO(xAxis, dlData, "电力");
-            series.add(zs);
-            series.add(yt);
-
+            List<SeriesDTO> series = listSeries(xAxis, bdDto, dlDto);
             chartList.add(createChartVO(xAxis, series, bdDto.getGq()));
         }
 
@@ -92,35 +71,41 @@ public class ChartServiceImpl implements IChartService {
                 continue;
             }
             gqFlag.add(dlDto.getGq());
-            List<Integer> dlData = new ArrayList<>();
-            dlData.add(dlDto.getDj1());
-            dlData.add(dlDto.getDj2());
-            dlData.add(dlDto.getDj3());
-
-            List<Integer> bdData = new ArrayList<>();
             DlycDTO bdDto = bdycMap.get(dlDto.getGq());
-            if(null != bdDto){
-                bdData.add(bdDto.getDj1());
-                bdData.add(bdDto.getDj2());
-                bdData.add(bdDto.getDj3());
-            }else {
-                bdData.add(0);
-                bdData.add(0);
-                bdData.add(0);
-            }
-
-            List<SeriesDTO> series = new ArrayList<>();
-            SeriesDTO zs = createSeriesDTO(xAxis, bdData, "变电");
-            SeriesDTO yt = createSeriesDTO(xAxis, dlData, "电力");
-            series.add(zs);
-            series.add(yt);
-
+            List<SeriesDTO> series = listSeries(xAxis, bdDto, dlDto);
             chartList.add(createChartVO(xAxis, series, dlDto.getGq()));
         }
 
         return chartList;
     }
 
+    private List<SeriesDTO> listSeries(List<String> xAxis, DlycDTO bdDto, DlycDTO dlDto){
+        List<Integer> dlData = getSeries(dlDto);
+        List<Integer> bdData = getSeries(bdDto);
+
+        List<SeriesDTO> series = new ArrayList<>();
+        SeriesDTO zs = createSeriesDTO(xAxis, bdData, "变电");
+        SeriesDTO yt = createSeriesDTO(xAxis, dlData, "电力");
+        series.add(zs);
+        series.add(yt);
+
+        return series;
+    }
+
+    private List<Integer> getSeries(DlycDTO dto){
+        List<Integer> data = new ArrayList<>();
+        if(null != dto){
+            data.add(null == dto.getDj1() ? 0 : dto.getDj1());
+            data.add(null == dto.getDj2() ? 0 : dto.getDj2());
+            data.add(null == dto.getDj3() ? 0 : dto.getDj3());
+        }else {
+            data.add(0);
+            data.add(0);
+            data.add(0);
+        }
+        return data;
+    }
+
     /**
      * 获取地图上的图表数据
      *

+ 16 - 13
railway-business/src/main/resources/mapper/bi/ShowBdycMapper.xml

@@ -23,7 +23,8 @@
   </resultMap>
 
   <sql id="Base_Column_List">
-    id,
+    id
+    ,
     found_date,
     line_name,
     station_name,
@@ -186,25 +187,27 @@
     <where>
       del_flag='0'
       <if test="gravity!=null and gravity!=''">
-        and qxdj=(select dict_label from sys_dict_data where dict_type='dlycyzx' and dict_value=#{gravity})
+        and qxdj=(select dict_label from sys_dict_data where dict_type='dlycyzx' and
+        dict_value=#{gravity})
       </if>
       <if test="ssgq!=null and ssgq!=''">
-        and sjgq=(select dict_label from sys_dict_data where dict_type='dlyc_sygq' and dict_value=#{ssgq})
+        and sjgq=(select dict_label from sys_dict_data where dict_type='dlyc_sygq' and
+        dict_value=#{ssgq})
       </if>
     </where>
   </select>
 
   <select id="totalByDay" resultType="com.railway.business.bi.domain.dto.DlycDTO">
-    select sjgq as gq, t1.dict_value as gqCode, sum(yj) as dj1, sum(ej) as dj2, sum(sj) as dj3
-    from (
-           select sjgq,
-                  case when qxdj = '一级' then 1 else 0 end as yj,
-                  case when qxdj = '二级' then 1 else 0 end as ej,
-                  case when qxdj = '三级' then 1 else 0 end as sj
-           from show_bdyc
-           where found_date = '2022-05-25' and sjgq is not null
-         ) x
-    left join sys_dict_data t1 on x.sjgq = t1.dict_label and t1.dict_type='dlyc_sygq'
+    select dict_label as gq, t1.dict_value as gqCode, sum(yj) as dj1, sum(ej) as dj2, sum(sj) as dj3
+    from (select sjgq,
+                 case when qxdj = '一级' then 1 else 0 end as yj,
+                 case when qxdj = '二级' then 1 else 0 end as ej,
+                 case when qxdj = '三级' then 1 else 0 end as sj
+          from show_bdyc
+          where found_date = '2022-05-25'
+            and sjgq is not null) x
+           right join sys_dict_data t1 on x.sjgq = t1.dict_label
+    where t1.dict_type = 'dlyc_sygq'
     group by sjgq
   </select>
 

+ 16 - 13
railway-business/src/main/resources/mapper/bi/ShowDlycMapper.xml

@@ -22,7 +22,8 @@
   </resultMap>
 
   <sql id="Base_Column_List">
-    id,
+    id
+    ,
     qxsbmc,
     ssgq,
     sdjb,
@@ -177,25 +178,27 @@
     <where>
       del_flag='0'
       <if test="gravity!=null and gravity!=''">
-        and gravity=(select dict_label from sys_dict_data where dict_type='dlycyzx' and dict_value=#{gravity})
+        and gravity=(select dict_label from sys_dict_data where dict_type='dlycyzx' and
+        dict_value=#{gravity})
       </if>
       <if test="ssgq!=null and ssgq!=''">
-        and ssgq=(select dict_label from sys_dict_data where dict_type='dlyc_sygq' and dict_value=#{ssgq})
+        and ssgq=(select dict_label from sys_dict_data where dict_type='dlyc_sygq' and
+        dict_value=#{ssgq})
       </if>
     </where>
   </select>
 
   <select id="totalByDay" resultType="com.railway.business.bi.domain.dto.DlycDTO">
-    select ssgq as gq, t1.dict_value as gqCode, sum(yj) as dj1, sum(ej) as dj2, sum(sj) as dj3
-    from (
-           select ssgq,
-                  case when gravity = '一级' then 1 else 0 end as yj,
-                  case when gravity = '二级' then 1 else 0 end as ej,
-                  case when gravity = '三级' then 1 else 0 end as sj
-           from show_dlyc
-           where found_date = '2021-11-10' and ssgq is not null
-         ) x
-           left join sys_dict_data t1 on x.ssgq = t1.dict_label and t1.dict_type='dlyc_sygq'
+    select dict_label as gq, t1.dict_value as gqCode, sum(yj) as dj1, sum(ej) as dj2, sum(sj) as dj3
+    from (select ssgq,
+                 case when gravity = '一级' then 1 else 0 end as yj,
+                 case when gravity = '二级' then 1 else 0 end as ej,
+                 case when gravity = '三级' then 1 else 0 end as sj
+          from show_dlyc
+          where found_date = '2021-11-10'
+            and ssgq is not null) x
+           right join sys_dict_data t1 on x.ssgq = t1.dict_label
+    where t1.dict_type = 'dlyc_sygq'
     group by ssgq
   </select>