Parcourir la source

调整报废车辆判断逻辑

weijianghai il y a 2 semaines
Parent
commit
4a8e27e820

+ 32 - 12
src/main/java/com/nokia/finance/tasks/dao/car/CarProcedureDao.java

@@ -183,7 +183,7 @@ set
                 a.last_month = b.year_month
                 and a.che_pai_hao = b.che_pai_hao
             )
-        else to_date(year_month::varchar, 'YYYYMM')
+        else (select min(data_date) from car.car_base_data_day b where a.year_month = b.year_month and a.che_pai_hao = b.che_pai_hao and b.year_month = #{endYearMonth})
     end,
     car_move = case
         when (
@@ -250,7 +250,7 @@ set
                 a.last_month = b.year_month
                 and a.che_pai_hao = b.che_pai_hao
                 and a.first_unit != b.first_unit
-            )) then to_date(year_month::varchar, 'YYYYMM')
+            )) then (select min(data_date) from car.car_base_data_day b where a.year_month = b.year_month and a.che_pai_hao = b.che_pai_hao and a.first_unit = b.first_unit and b.year_month = #{endYearMonth})
         else (
             select
                 car_move_yj_date
@@ -326,6 +326,24 @@ where year_month = #{endYearMonth}
 """)
     int updateCarBaseDataMonthChange(@Param("endYearMonth") Integer endYearMonth);
 
+    /**
+     * 更新车辆报废是否有效
+     * @param endYearMonth 账期
+     */
+    @Update("""
+update
+    car.car_bao_fei a
+set
+    valid = 0
+from
+    car.car_bao_fei_invalid b
+where
+    a.che_pai_hao = b.che_pai_hao
+    and a.bao_fei_ri_qi = b.bao_fei_ri_qi
+    and a.month_id = #{endYearMonth}
+""")
+    int updateCarBaoFeiValid(@Param("endYearMonth") Integer endYearMonth);
+
     /**
      * 更新车辆行驶里程月数据工作日
      * @param endYearMonth 账期
@@ -351,8 +369,8 @@ where
 update
     car.car_li_cheng_month
 set
-    ri_jun_li_cheng = zong_li_cheng / workday,
-    chu_qin_lv = xing_shi_tian_shu / workday::numeric
+    ri_jun_li_cheng = case when workday > 0 then zong_li_cheng / workday end,
+    chu_qin_lv = case when workday > 0 then xing_shi_tian_shu / workday::numeric end
 where
     year_month = #{endYearMonth}
 """)
@@ -367,18 +385,20 @@ update
     car.car_li_cheng_month a
 set
     di_xiao = case
+        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.month_id = #{endYearMonth} and b.valid = 1)) then 0
+        when (select not exists(select 1 from car.car_base_data_month b where b.che_pai_hao = a.che_pai_hao and b.year_month = a.year_month)) then 0
+        when bao_fei = 1 then 0
         when first_unit = '省公司本部' then 0
         when position('建设部' in che_liang_suo_shu_dan_wei) > 0 then 0
         when che_liang_lei_xing in ('特种车', '中型面包车(8-20座的面包车)', '大巴车') then 0
         when che_liang_shi_yong_xing_zhi in ('特种车', '负责人用车') then 0
         when (select exists(select 1 from car_theme.wz_f_spc_car b where a.che_pai_hao = b.card_num and b.is_spec = '1')) then 0
-        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.year_month <= #{endYearMonth} and b.valid = 1)) then 0
-        when bao_fei = 1 then 0
         when chu_qin_lv < 0.5 and ri_jun_li_cheng < 20 then 1
         else 0
     end,
     di_xiao_exclude_reason = case
-        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.year_month <= #{endYearMonth} and b.valid = 1)) then (select max(b.year_month) from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.year_month <= #{endYearMonth}) || '报废'
+        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.month_id = #{endYearMonth} and b.valid = 1)) then (select max(b.year_month) from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.month_id = #{endYearMonth}) || '报废'
+        when (select not exists(select 1 from car.car_base_data_month b where b.che_pai_hao = a.che_pai_hao and b.year_month = a.year_month)) then '车辆基本信息已删除'
         when first_unit = '省公司本部' then '省公司本部'
         when position('建设部' in che_liang_suo_shu_dan_wei) > 0 then '建设部'
         when che_liang_lei_xing = '特种车' then '特种车'
@@ -545,7 +565,7 @@ t107 as (
 t111 as (
 select
     case
-        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.year_month <= a.stat_year_month)) then 0
+        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.month_id = a.stat_year_month and b.valid = 1)) then 0
         when (select not exists(select 1 from car.car_base_data_month b where b.che_pai_hao = a.che_pai_hao and b.year_month = a.stat_year_month)) then 0
         when first_unit = '省公司本部' then 0
         when position('建设部' in che_liang_suo_shu_dan_wei) > 0 then 0
@@ -558,7 +578,7 @@ select
         else 0
     end as di_xiao_sum,
     case
-        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.year_month <= a.stat_year_month and b.valid = 1)) then (select max(b.year_month) from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.year_month <= a.stat_year_month) || '报废'
+        when (select exists(select 1 from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.month_id = a.stat_year_month and b.valid = 1)) then (select max(b.year_month) from car.car_bao_fei b where b.che_pai_hao = a.che_pai_hao and b.month_id = a.stat_year_month) || '报废'
         when (select not exists(select 1 from car.car_base_data_month b where b.che_pai_hao = a.che_pai_hao and b.year_month = a.stat_year_month)) then '车辆基本信息已删除'
         when first_unit = '省公司本部' then '省公司本部'
         when position('建设部' in che_liang_suo_shu_dan_wei) > 0 then '建设部'
@@ -2045,7 +2065,7 @@ where
         car.car_bao_fei b
     where
         b.che_pai_hao = a.che_pai_hao
-        and b.year_month <= a.year_month and b.valid = 1)
+        and b.month_id = a.year_month and b.valid = 1)
     and year_month = #{endYearMonth}
 ),
 t102 as (
@@ -2237,7 +2257,7 @@ where
         car.car_bao_fei b
     where
         b.che_pai_hao = a.che_pai_hao
-        and b.year_month <= a.year_month and b.valid = 1)
+        and b.month_id = a.year_month and b.valid = 1)
     and year_month = #{endYearMonth}
 ),
 t102 as (
@@ -2385,7 +2405,7 @@ where
         car.car_bao_fei b
     where
         b.che_pai_hao = a.che_pai_hao
-        and b.year_month <= a.year_month and b.valid = 1)
+        and b.month_id = a.year_month and b.valid = 1)
     and year_month = #{endYearMonth}
 ),
 t102 as (

+ 2 - 2
src/main/java/com/nokia/finance/tasks/dao/car/CarReportDao.java

@@ -138,7 +138,7 @@ where
         car.car_bao_fei b
     where
         b.che_pai_hao = a.che_pai_hao
-        and b.year_month <= a.year_month and b.valid = 1)
+        and b.month_id = a.year_month and b.valid = 1)
 ),
 t102 as (
 select
@@ -241,7 +241,7 @@ where
         car.car_bao_fei b
     where
         b.che_pai_hao = a.che_pai_hao
-        and b.year_month <= a.year_month and b.valid = 1)
+        and b.month_id = a.year_month and b.valid = 1)
 ),
 t102 as (
 select

+ 10 - 1
src/main/java/com/nokia/finance/tasks/dao/gdc/car/GdcCarProcedureDao.java

@@ -9,6 +9,14 @@ import org.apache.ibatis.annotations.Update;
  */
 @Mapper
 public interface GdcCarProcedureDao {
+    /**
+     * 清空车辆报废记录
+     */
+    @Update("""
+truncate table car_theme.wz_f_car_scrap
+""")
+    int truncateCarScrap();
+
     /**
      * 插入车辆报废记录
      * @param endYearMonth 账期
@@ -33,7 +41,8 @@ third_unit as grid,
 date_part('year', bao_fei_ri_qi) as year_info,
 date_part('month', bao_fei_ri_qi) as month_info
 from car.car_bao_fei
-where year_month = #{endYearMonth}
+where month_id = #{endYearMonth}
+and valid = 1
 """)
     int insertCarScrap(@Param("endYearMonth") Integer endYearMonth);
 

+ 4 - 2
src/main/java/com/nokia/finance/tasks/jobs/car/procedure/CarBaseDataMonthProcJob.java

@@ -55,8 +55,10 @@ public class CarBaseDataMonthProcJob {
             int update1 = carProcedureDao.insertCarBaseDataMonth(endYearMonth);
             int update2 = carProcedureDao.updateCarBaseDataMonthChange(endYearMonth);
             int update3 = gdcCarProcedureDao.insertCarInfo(endYearMonth);
-            gdcCarProcedureDao.insertCarScrap(endYearMonth);
-            if (update1 == 0 || update2 == 0 || update3 == 0) {
+            carProcedureDao.updateCarBaoFeiValid(endYearMonth);
+            gdcCarProcedureDao.truncateCarScrap();
+            int update4 = gdcCarProcedureDao.insertCarScrap(endYearMonth);
+            if (update1 == 0 || update2 == 0 || update3 == 0 || update4 == 0) {
                 throw new MyRuntimeException("车辆基本信息月数据加工定时任务失败");
             }
             dataLogPo.setDataCount(update1);

+ 2 - 3
src/main/java/com/nokia/finance/tasks/jobs/car/rx/CarBaoFeiMonthTask.java

@@ -236,9 +236,8 @@ public class CarBaoFeiMonthTask {
             map.put("source", path.getFileName().toString());
         }
         // 去重
-        return list.stream().filter(t -> t.get("month_id").equals(t.get("year_month")))
-                .filter(distinctByKey(map -> map.get("che_pai_hao") + map.get("bao_fei_ri_qi")))
-                .toList();
+        return list.stream().filter(distinctByKey(map ->  map.get("month_id")
+                        +  map.get("che_pai_hao") + map.get("bao_fei_ri_qi"))).toList();
     }
 
     /**