Quellcode durchsuchen

优化图表查询语句,增加注水量显示

周壕 vor 10 Monaten
Ursprung
Commit
719d188267

+ 1 - 0
src/main/java/com/bowintek/practice/mapper/cquery/FactWellCQuery.java

@@ -7,4 +7,5 @@ public interface FactWellCQuery {
     List<FactWellGroupList> getDayGroupList(String wellId, String startDay, String endDay);
     List<FactWellGroupList> getMonthGroupList(String wellId, String startDay, String endDay);
     List<FactWellGroupList> getYearGroupList(String wellId, String startDay, String endDay);
+    List<FactWellGroupList> getMonthShowInList(String wellId, String startDay, String endDay);
 }

+ 45 - 7
src/main/java/com/bowintek/practice/services/impl/FactWellServiceImpl.java

@@ -25,9 +25,48 @@ public class FactWellServiceImpl implements FactWellService {
     @Override
     @SwitchDataSource(DBTypeEnum.POSTGRE)
     public List<FactWellGroupList> getFactWellList(String wellId, String timeType){
-        if(timeType.equals("day")) return getDayGroupList(wellId);
-        if(timeType.equals("month")) return getMonthGroupList(wellId);
-        else return getYearGroupList(wellId);
+        //当前只有月份计算方式
+        return getMonthShowInList(wellId);
+    }
+
+    public List<FactWellGroupList> getMonthShowInList(String wellId){
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(getToDay());
+
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        calendar.add(Calendar.DAY_OF_MONTH, -1);
+        //上月最后
+        Date endTime = calendar.getTime();
+
+        //11月前的1号
+        calendar.add(Calendar.MONTH, -11);
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        Date startTime = calendar.getTime();
+
+        return getMonthShowInList(wellId, startTime, endTime);
+    }
+    public List<FactWellGroupList> getMonthShowInList(String wellId, Date startTime, Date endTime){
+        //重新计算当前12月
+        if(startTime==null || endTime==null) return getMonthGroupList(wellId);
+
+        System.out.println("getMonthGroupList "+dateToDayString(startTime)+" "+dateToDayString(endTime));
+
+        List<FactWellGroupList> rtnList = factWellCQuery
+                .getMonthShowInList(wellId, dateToDayString(startTime), dateToDayString(endTime));
+
+        //补充列表数据
+        List<String> monthList = new ArrayList<>();
+        for(Date time = startTime;time.getTime()<=endTime.getTime();){
+            Calendar calendarTime = Calendar.getInstance();
+            calendarTime.setTime(time);
+            monthList.add(dateToMonthString(calendarTime.getTime()));
+            //下一月
+            calendarTime.add(Calendar.MONTH, 1);
+            time = calendarTime.getTime();
+        }
+
+        rtnList = supplementList(wellId, monthList, rtnList);
+        return rtnList;
     }
 
     @Override
@@ -41,8 +80,6 @@ public class FactWellServiceImpl implements FactWellService {
     public List<FactWellGroupList> getDayGroupList(String wellId){
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(getToDay()); // 设置当前天日期
-        calendar.set(Calendar.DAY_OF_MONTH, 1);
-        calendar.add(Calendar.DAY_OF_MONTH, -1);
         //上月最后一天
         Date endTime = calendar.getTime();
 
@@ -85,9 +122,10 @@ public class FactWellServiceImpl implements FactWellService {
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(getToDay());
 
+        calendar.add(Calendar.MONTH, 1);
         calendar.set(Calendar.DAY_OF_MONTH, 1);
         calendar.add(Calendar.DAY_OF_MONTH, -1);
-        //上一月最后一天
+        //当前月最后一天
         Date endTime = calendar.getTime();
 
         //11月前的1号
@@ -128,7 +166,7 @@ public class FactWellServiceImpl implements FactWellService {
         calendar.set(Calendar.DAY_OF_MONTH, 1);
         calendar.add(Calendar.MONTH, 1);
         calendar.add(Calendar.DAY_OF_MONTH, -1);
-        //当年12月30日
+        //当年最后一天
         Date endTime = calendar.getTime();
         //5年前1月1日
         calendar.add(Calendar.YEAR, -4);

+ 2 - 0
src/main/java/com/bowintek/practice/vo/FactWell/FactWellGroupList.java

@@ -11,6 +11,7 @@ public class FactWellGroupList {
     private double water;
     private double fluid;
     private double watercut;
+    private double vol;
 
     public static FactWellGroupList gen(String wellId, String timeStr){
         FactWellGroupList obj = new FactWellGroupList();
@@ -21,6 +22,7 @@ public class FactWellGroupList {
         obj.setFluid(0);
         obj.setWater(0);
         obj.setWatercut(0);
+        obj.setVol(0);
         return obj;
     }
 }

+ 48 - 13
src/main/resources/mapping/cquery/FactWellCQuery.xml

@@ -8,14 +8,16 @@
                 SUM(t.oil_prod_daily) oil,
                 SUM(t.fluid_prod_daily) fluid,
                 SUM(t.water_prod_daily) water,
-                SUM(t.water_cut) watercut
+                SUM(t.water_cut) watercut,
+                SUM(inj_vol_daily) vol
         FROM (  SELECT  wd.well_id,
                         TO_CHAR(wd.prod_date , 'YYYY-MM-DD') prod_time_str,
                         COALESCE(wd.gas_prod_daily, 0)      gas_prod_daily,
                         COALESCE(wd.oil_prod_daily, 0)      oil_prod_daily,
                         COALESCE(wd.fluid_prod_daily, 0)      fluid_prod_daily,
                         COALESCE(wd.water_prod_daily, 0)      water_prod_daily,
-                        COALESCE(wd.water_cut, 0)      water_cut
+                        COALESCE(wd.water_cut, 0)      water_cut,
+                        COALESCE(wd.inj_vol_daily)  inj_vol_daily
                 FROM by_dwr.fact_dwr_pc_pro_well_vol_d wd
                 WHERE wd.prod_date <![CDATA[ >= ]]> to_date(#{startDay},'YYYY-MM-DD')
                     and wd.prod_date <![CDATA[ <= ]]> to_date(#{endDay},'YYYY-MM-DD')
@@ -26,7 +28,7 @@
         GROUP BY t.well_id, t.prod_time_str
     </select>
 
-    <select id="getMonthGroupList" resultType="com.bowintek.practice.vo.FactWell.FactWellGroupList">
+    <select id="getMonthShowInList" resultType="com.bowintek.practice.vo.FactWell.FactWellGroupList">
         SELECT t.well_id,
             t.prod_time_str time_str,
             MAX(t.gas_prod_mon) gas,
@@ -44,32 +46,65 @@
                 WHERE wm.prod_date is not null
                     and wm.prod_date <![CDATA[ >= ]]> to_date(#{startDay},'YYYY-MM-DD')
                     and wm.prod_date <![CDATA[ <= ]]> to_date(#{endDay},'YYYY-MM-DD')
-                  and wm.well_id=#{wellId}
+                    <if test="wellId!='' and wellId!=null">
+                        and wm.well_id=#{wellId}
+                    </if>
             ) t
         GROUP BY t.well_id, t.prod_time_str
     </select>
 
-    <select id="getYearGroupList" resultType="com.bowintek.practice.vo.FactWell.FactWellGroupList">
+    <select id="getMonthGroupList" resultType="com.bowintek.practice.vo.FactWell.FactWellGroupList">
         SELECT t.well_id,
             t.prod_time_str time_str,
             SUM(t.gas_prod_mon) gas,
             SUM(t.oil_prod_mon) oil,
             SUM(t.water_prod_mon) water,
             SUM(t.fluid_prod_mon) fluid,
-            0 watercut
+            SUM(t.water_cut_ratio_m) watercut,
+            SUM(t.inj_vol_mon) vol
         FROM (  SELECT wm.well_id,
-                    SUBSTRING(prod_date, 1, 4) prod_time_str,
+                    to_char(to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD'), 'YYYY年MM月') prod_time_str,
                     COALESCE(wm.gas_prod_mon, 0) gas_prod_mon,
                     COALESCE(wm.oil_prod_mon, 0) oil_prod_mon,
                     COALESCE(wm.water_prod_mon, 0) water_prod_mon,
-                    COALESCE(wm.fluid_prod_mon, 0) fluid_prod_mon
+                    COALESCE(wm.fluid_prod_mon, 0) fluid_prod_mon,
+                    COALESCE(wm.water_cut_ratio_m, 0) water_cut_ratio_m,
+                    COALESCE(wm.inj_vol_mon, 0) inj_vol_mon
                 FROM by_dwr.fact_dwr_pc_pro_well_vol_m wm
                 WHERE wm.prod_date is not null
-                and to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD')  <![CDATA[ >= ]]> to_date(#{startDay},'YYYY-MM-DD')
-                and to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD')  <![CDATA[ <= ]]> to_date(#{endDay},'YYYY-MM-DD')
-        <if test="wellId!='' and wellId!=null">
-            and wm.well_id=#{wellId}
-        </if>
+                    and to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD')  <![CDATA[ >= ]]> to_date(#{startDay},'YYYY-MM-DD')
+                    and to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD')  <![CDATA[ <= ]]> to_date(#{endDay},'YYYY-MM-DD')
+                    <if test="wellId!='' and wellId!=null">
+                        and wm.well_id=#{wellId}
+                    </if>
+        ) t
+        GROUP BY t.well_id, t.prod_time_str
+    </select>
+
+    <select id="getYearGroupList" resultType="com.bowintek.practice.vo.FactWell.FactWellGroupList">
+        SELECT t.well_id,
+            t.prod_time_str time_str,
+            MAX(t.gas_prod_year) gas,
+            MAX(t.oil_prod_year) oil,
+            MAX(t.water_prod_year) water,
+            MAX(t.fluid_prod_year) fluid,
+            MAX(t.water_cut_ratio_y) watercut,
+            MAX(t.inj_vol_year) vol
+        FROM (  SELECT wm.well_id,
+                    SUBSTRING(prod_date, 1, 4) prod_time_str,
+                    COALESCE(wm.gas_prod_year, 0) gas_prod_year,
+                    COALESCE(wm.oil_prod_year, 0) oil_prod_year,
+                    COALESCE(wm.water_prod_year, 0) water_prod_year,
+                    COALESCE(wm.liquid_prod_year, 0) fluid_prod_year,
+                    COALESCE(wm.water_cut_ratio_y, 0) water_cut_ratio_y,
+                    COALESCE(wm.inj_vol_year, 0) inj_vol_year
+                FROM by_dwr.fact_dwr_pc_pro_well_vol_m wm
+                WHERE wm.prod_date is not null
+                    and to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD')  <![CDATA[ >= ]]> to_date(#{startDay},'YYYY-MM-DD')
+                    and to_date(CONCAT(wm.prod_date,'-01'), 'YYYY-MM-DD')  <![CDATA[ <= ]]> to_date(#{endDay},'YYYY-MM-DD')
+                    <if test="wellId!='' and wellId!=null">
+                        and wm.well_id=#{wellId}
+                    </if>
             ) t
         GROUP BY t.well_id, t.prod_time_str
     </select>

+ 2 - 1
vue/src/components/basic/chart/chart-prod-dynamics.vue

@@ -144,7 +144,8 @@
           {label:'产水量', value:'water', unit:'万吨'},
           {label:'产液量', value:'fluid', unit:'万吨'},
           {label:'产气量', value:'gas', unit:'立方米'},
-          {label:'含水率', value:'watercut', unit:'万吨'}
+          {label:'含水率', value:'watercut', unit:'万吨'},
+          {label:'注水量', value:'vol', unit:'立方米'}
         ];
       },
       getTypes:function (){