|
@@ -0,0 +1,1931 @@
|
|
|
+package com.nokia.finance.tasks.dao.car;
|
|
|
+
|
|
|
+import org.apache.ibatis.annotations.Mapper;
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
+import org.apache.ibatis.annotations.Select;
|
|
|
+import org.apache.ibatis.annotations.Update;
|
|
|
+
|
|
|
+@Mapper
|
|
|
+public interface CarProcedureDao {
|
|
|
+ /**
|
|
|
+ * 插入车辆基本信息月数据
|
|
|
+ *
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+insert into car.car_base_data_month
|
|
|
+(
|
|
|
+year_month,
|
|
|
+che_pai_hao,
|
|
|
+che_liang_pin_pai,
|
|
|
+pai_liang,
|
|
|
+pai_liang_lei_xing,
|
|
|
+ran_you_lei_xing,
|
|
|
+ran_you_biao_hao,
|
|
|
+deng_ji_ri_qi,
|
|
|
+che_liang_lai_yuan,
|
|
|
+che_liang_lei_xing,
|
|
|
+che_liang_shi_yong_xing_zhi,
|
|
|
+huan_bao_deng_ji,
|
|
|
+fa_dong_ji_hao,
|
|
|
+che_jia_hao,
|
|
|
+chu_shi_li_cheng,
|
|
|
+che_liang_suo_shu_dan_wei,
|
|
|
+xing_shi_zheng_hao,
|
|
|
+bei_zhu,
|
|
|
+shen_he_zhuang_tai,
|
|
|
+che_liang_zhuang_tai,
|
|
|
+zi_chan_bian_hao,
|
|
|
+bang_ding_jia_shi_yuan_xing_ming,
|
|
|
+gou_zhi_jia_ge,
|
|
|
+che_ling_nian,
|
|
|
+biao_zhun_bai_gong_li_you_hao,
|
|
|
+she_bei_gong_zuo_mo_shi,
|
|
|
+yong_che_mo_shi,
|
|
|
+first_unit,
|
|
|
+second_unit,
|
|
|
+third_unit,
|
|
|
+area_no,
|
|
|
+area_name,
|
|
|
+city_no,
|
|
|
+city_name,
|
|
|
+area_no2,
|
|
|
+area_name2,
|
|
|
+city_id,
|
|
|
+city,
|
|
|
+district_id,
|
|
|
+district,
|
|
|
+data_date,
|
|
|
+last_month,
|
|
|
+year_no,
|
|
|
+month_no,
|
|
|
+raw_che_pai_hao,
|
|
|
+che_pai_fail,
|
|
|
+che_ling,
|
|
|
+source
|
|
|
+)
|
|
|
+select
|
|
|
+year_month,
|
|
|
+che_pai_hao,
|
|
|
+che_liang_pin_pai,
|
|
|
+pai_liang,
|
|
|
+pai_liang_lei_xing,
|
|
|
+ran_you_lei_xing,
|
|
|
+ran_you_biao_hao,
|
|
|
+deng_ji_ri_qi,
|
|
|
+che_liang_lai_yuan,
|
|
|
+che_liang_lei_xing,
|
|
|
+che_liang_shi_yong_xing_zhi,
|
|
|
+huan_bao_deng_ji,
|
|
|
+fa_dong_ji_hao,
|
|
|
+che_jia_hao,
|
|
|
+chu_shi_li_cheng,
|
|
|
+che_liang_suo_shu_dan_wei,
|
|
|
+xing_shi_zheng_hao,
|
|
|
+bei_zhu,
|
|
|
+shen_he_zhuang_tai,
|
|
|
+che_liang_zhuang_tai,
|
|
|
+zi_chan_bian_hao,
|
|
|
+bang_ding_jia_shi_yuan_xing_ming,
|
|
|
+gou_zhi_jia_ge,
|
|
|
+che_ling_nian,
|
|
|
+biao_zhun_bai_gong_li_you_hao,
|
|
|
+she_bei_gong_zuo_mo_shi,
|
|
|
+yong_che_mo_shi,
|
|
|
+first_unit,
|
|
|
+second_unit,
|
|
|
+third_unit,
|
|
|
+area_no,
|
|
|
+area_name,
|
|
|
+city_no,
|
|
|
+city_name,
|
|
|
+area_no2,
|
|
|
+area_name2,
|
|
|
+city_id,
|
|
|
+city,
|
|
|
+district_id,
|
|
|
+district,
|
|
|
+data_date,
|
|
|
+last_month,
|
|
|
+year_no,
|
|
|
+month_no,
|
|
|
+raw_che_pai_hao,
|
|
|
+che_pai_fail,
|
|
|
+che_ling,
|
|
|
+source
|
|
|
+from car.car_base_data_day
|
|
|
+where data_date = (select max(data_date) from car.car_base_data_day where year_month = #{endYearMonth})
|
|
|
+""")
|
|
|
+ int insertCarBaseDataMonth(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆基本信息月数据新车调配字段
|
|
|
+ *
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update
|
|
|
+ car.car_base_data_month a
|
|
|
+set
|
|
|
+ car_new = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )) then 0
|
|
|
+ else 1
|
|
|
+ end,
|
|
|
+ car_new_year_month = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )) then (
|
|
|
+ select
|
|
|
+ car_new_year_month
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )
|
|
|
+ else year_month
|
|
|
+ end,
|
|
|
+ car_new_date = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )) then (
|
|
|
+ select
|
|
|
+ car_new_date
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )
|
|
|
+ else to_date(year_month::varchar, 'YYYYMM')
|
|
|
+ end,
|
|
|
+ car_move = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.che_liang_suo_shu_dan_wei != b.che_liang_suo_shu_dan_wei
|
|
|
+ )) then 1
|
|
|
+ else 0
|
|
|
+ end,
|
|
|
+ car_move_yj = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.first_unit != b.first_unit
|
|
|
+ )) then 1
|
|
|
+ else 0
|
|
|
+ end,
|
|
|
+ car_move_yj_year_month = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.first_unit != b.first_unit
|
|
|
+ )) then year_month
|
|
|
+ else (
|
|
|
+ select
|
|
|
+ car_move_yj_year_month
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )
|
|
|
+ end,
|
|
|
+ car_move_yj_date = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ 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')
|
|
|
+ else (
|
|
|
+ select
|
|
|
+ car_move_yj_date
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )
|
|
|
+ end,
|
|
|
+ last_first_unit = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.first_unit != b.first_unit
|
|
|
+ )) then (
|
|
|
+ select
|
|
|
+ first_unit
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )
|
|
|
+ else (
|
|
|
+ select
|
|
|
+ last_first_unit
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ )
|
|
|
+ end,
|
|
|
+ car_move_ej = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.second_unit != b.second_unit
|
|
|
+ )) then 1
|
|
|
+ else 0
|
|
|
+ end,
|
|
|
+ car_move_sj = case
|
|
|
+ when (
|
|
|
+ select
|
|
|
+ exists(
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month b
|
|
|
+ where
|
|
|
+ a.last_month = b.year_month
|
|
|
+ and a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.third_unit != b.third_unit
|
|
|
+ )) then 1
|
|
|
+ else 0
|
|
|
+ end
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarBaseDataMonthChange(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆行驶里程月数据工作日
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update
|
|
|
+ car.car_li_cheng_month a
|
|
|
+set
|
|
|
+ workday = b.workday
|
|
|
+from
|
|
|
+ car.workdays b
|
|
|
+where
|
|
|
+ a.year_month = b.year_month
|
|
|
+ and a.year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarLiChengMonthWorkday(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆行驶里程月数据日均里程出勤率
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update
|
|
|
+ car.car_li_cheng_month
|
|
|
+set
|
|
|
+ ri_jun_li_cheng = zong_li_cheng / workday,
|
|
|
+ chu_qin_lv = xing_shi_tian_shu / workday::numeric
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarLiChengMonthRiJunLiChengChuQinLv(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆行驶里程月数据低效
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update
|
|
|
+ car.car_li_cheng_month a
|
|
|
+set
|
|
|
+ di_xiao = case
|
|
|
+ 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})) 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})) 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 first_unit = '省公司本部' then '省公司本部'
|
|
|
+ when position('建设部' in che_liang_suo_shu_dan_wei) > 0 then '建设部'
|
|
|
+ when che_liang_lei_xing = '特种车' then '特种车'
|
|
|
+ when che_liang_lei_xing = '中型面包车(8-20座的面包车)' then '中型面包车(8-20座的面包车)'
|
|
|
+ when che_liang_lei_xing = '大巴车' then '大巴车'
|
|
|
+ when che_liang_shi_yong_xing_zhi = '特种车' then '特种车'
|
|
|
+ when che_liang_shi_yong_xing_zhi = '负责人用车' then '负责人用车'
|
|
|
+ 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 '特殊车辆'
|
|
|
+ when bao_fei = 1 then '报废'
|
|
|
+ else ''
|
|
|
+ end
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarLiChengMonthDiXiao(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆行驶里程月数据车辆基本信息
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update car.car_li_cheng_month a set
|
|
|
+che_liang_lai_yuan = b.che_liang_lai_yuan,
|
|
|
+che_liang_lei_xing = b.che_liang_lei_xing,
|
|
|
+che_liang_shi_yong_xing_zhi = b.che_liang_shi_yong_xing_zhi,
|
|
|
+che_liang_suo_shu_dan_wei = b.che_liang_suo_shu_dan_wei,
|
|
|
+first_unit = b.first_unit,
|
|
|
+second_unit = b.second_unit,
|
|
|
+third_unit = b.third_unit,
|
|
|
+area_no = b.area_no,
|
|
|
+area_name = b.area_name,
|
|
|
+city_no = b.city_no,
|
|
|
+city_name = b.city_name,
|
|
|
+area_name2 = b.area_name2,
|
|
|
+area_no2 = b.area_no2,
|
|
|
+city_id = b.city_id,
|
|
|
+city = b.city,
|
|
|
+district_id = b.district_id,
|
|
|
+district = b.district,
|
|
|
+car_new = b.car_new,
|
|
|
+car_move = b.car_move,
|
|
|
+car_move_yj = b.car_move_yj,
|
|
|
+car_move_ej = b.car_move_ej,
|
|
|
+car_move_sj = b.car_move_sj,
|
|
|
+car_new_year_month = b.car_new_year_month,
|
|
|
+car_new_date = b.car_new_date,
|
|
|
+deng_ji_ri_qi = b.deng_ji_ri_qi,
|
|
|
+last_first_unit = b.last_first_unit,
|
|
|
+car_move_yj_date = b.car_move_yj_date,
|
|
|
+car_move_yj_year_month = b.car_move_yj_year_month,
|
|
|
+no_info = 0
|
|
|
+from car.car_base_data_month b
|
|
|
+where a.year_month = b.year_month
|
|
|
+and a.che_pai_hao = b.che_pai_hao
|
|
|
+and a.year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarLiChengMonthBaseInfo(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆行驶里程月累计
|
|
|
+ * @param startYearMonth 开始年月
|
|
|
+ * @param endYearMonth 结束年月
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ car.workdays
|
|
|
+where
|
|
|
+ year_month >= #{startYearMonth}
|
|
|
+ and year_month <= #{endYearMonth}
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ car.car_li_cheng_month
|
|
|
+where
|
|
|
+ year_month >= #{startYearMonth}
|
|
|
+ and year_month <= #{endYearMonth}
|
|
|
+ and bao_fei = 0
|
|
|
+),
|
|
|
+t103 as (
|
|
|
+select
|
|
|
+ distinct on
|
|
|
+ (che_pai_hao) *
|
|
|
+from
|
|
|
+ t102
|
|
|
+order by
|
|
|
+ che_pai_hao,
|
|
|
+ year_month desc
|
|
|
+),
|
|
|
+t104 as (
|
|
|
+select
|
|
|
+ (
|
|
|
+ select
|
|
|
+ sum(workday)
|
|
|
+ from
|
|
|
+ t101 b
|
|
|
+ where
|
|
|
+ b.year_month >= (
|
|
|
+ case
|
|
|
+ when a.car_move_yj_date is not null then to_char((a.car_move_yj_date + interval '3 month')::date,
|
|
|
+ 'YYYYMM')::int4
|
|
|
+ when a.car_new_date is not null then to_char((a.car_new_date + interval '3 month')::date,
|
|
|
+ 'YYYYMM')::int4
|
|
|
+ else #{startYearMonth}
|
|
|
+ end
|
|
|
+ )) as workday_sum,
|
|
|
+ *
|
|
|
+from
|
|
|
+ t103 a
|
|
|
+),
|
|
|
+t105 as (
|
|
|
+select
|
|
|
+ che_pai_hao,
|
|
|
+ first_unit,
|
|
|
+ sum(case when car_move_yj_date is not null and year_month >= car_move_yj_year_month and year_month < to_char((car_move_yj_date + interval '3 month')::date, 'YYYYMM')::int4 then 0 when car_new_date is not null and year_month >= car_new_year_month and year_month < to_char((car_new_date + interval '3 month')::date, 'YYYYMM')::int4 then 0 else xing_shi_shi_chang end) as xing_shi_shi_chang_sum,
|
|
|
+ sum(case when car_move_yj_date is not null and year_month >= car_move_yj_year_month and year_month < to_char((car_move_yj_date + interval '3 month')::date, 'YYYYMM')::int4 then 0 when car_new_date is not null and year_month >= car_new_year_month and year_month < to_char((car_new_date + interval '3 month')::date, 'YYYYMM')::int4 then 0 else xing_shi_tian_shu end) as xing_shi_tian_shu_sum,
|
|
|
+ sum(case when car_move_yj_date is not null and year_month >= car_move_yj_year_month and year_month < to_char((car_move_yj_date + interval '3 month')::date, 'YYYYMM')::int4 then 0 when car_new_date is not null and year_month >= car_new_year_month and year_month < to_char((car_new_date + interval '3 month')::date, 'YYYYMM')::int4 then 0 else zong_li_cheng end) as zong_li_cheng_sum
|
|
|
+from
|
|
|
+ t102
|
|
|
+group by
|
|
|
+ che_pai_hao,
|
|
|
+ first_unit
|
|
|
+),
|
|
|
+t106 as (
|
|
|
+select
|
|
|
+t104.*,
|
|
|
+t105.xing_shi_shi_chang_sum,
|
|
|
+t105.xing_shi_tian_shu_sum,
|
|
|
+t105.zong_li_cheng_sum
|
|
|
+from t104 join t105 on t104.che_pai_hao = t105.che_pai_hao and t104.first_unit = t105.first_unit
|
|
|
+),
|
|
|
+t107 as (
|
|
|
+ select
|
|
|
+ case when workday_sum = 0 then null else zong_li_cheng_sum / workday_sum end as ri_jun_li_cheng_sum,
|
|
|
+ case when workday_sum = 0 then null else xing_shi_tian_shu_sum / workday_sum::numeric end as chu_qin_lv_sum,
|
|
|
+ #{endYearMonth} as stat_year_month,
|
|
|
+ *
|
|
|
+ from t106
|
|
|
+),
|
|
|
+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 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 car_move_yj_date is not null and stat_year_month >= car_move_yj_year_month and stat_year_month < to_char((car_move_yj_date + interval '3 month')::date, 'YYYYMM')::int4 then 0
|
|
|
+ when car_new_date is not null and stat_year_month >= car_new_year_month and stat_year_month < to_char((car_new_date + interval '3 month')::date, 'YYYYMM')::int4 then 0
|
|
|
+ when chu_qin_lv_sum < 0.5 and ri_jun_li_cheng_sum < 20 then 1
|
|
|
+ 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)) 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 first_unit = '省公司本部' then '省公司本部'
|
|
|
+ when position('建设部' in che_liang_suo_shu_dan_wei) > 0 then '建设部'
|
|
|
+ when che_liang_lei_xing = '特种车' then '特种车'
|
|
|
+ when che_liang_lei_xing = '中型面包车(8-20座的面包车)' then '中型面包车(8-20座的面包车)'
|
|
|
+ when che_liang_lei_xing = '大巴车' then '大巴车'
|
|
|
+ when che_liang_shi_yong_xing_zhi = '特种车' then '特种车'
|
|
|
+ when che_liang_shi_yong_xing_zhi = '负责人用车' then '负责人用车'
|
|
|
+ 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 '特殊车辆'
|
|
|
+ when car_move_yj_date is not null and stat_year_month >= car_move_yj_year_month and stat_year_month < to_char((car_move_yj_date + interval '3 month')::date, 'YYYYMM')::int4 then car_move_yj_year_month || '从' || last_first_unit || '调配到' || first_unit
|
|
|
+ when car_new_date is not null and stat_year_month >= car_new_year_month and stat_year_month < to_char((car_new_date + interval '3 month')::date, 'YYYYMM')::int4 then car_new_year_month || '新车'
|
|
|
+ else ''
|
|
|
+ end as di_xiao_sum_exclude_reason,
|
|
|
+ *
|
|
|
+from
|
|
|
+ t107 a
|
|
|
+)
|
|
|
+insert into car.car_li_cheng_lei_ji_month
|
|
|
+(
|
|
|
+year_month,
|
|
|
+che_pai_hao,
|
|
|
+di_xiao_sum,
|
|
|
+di_xiao_sum_exclude_reason,
|
|
|
+xing_shi_shi_chang_sum,
|
|
|
+xing_shi_tian_shu_sum,
|
|
|
+zong_li_cheng_sum,
|
|
|
+ri_jun_li_cheng_sum,
|
|
|
+chu_qin_lv_sum,
|
|
|
+workday_sum,
|
|
|
+che_liang_lei_xing,
|
|
|
+che_liang_lai_yuan,
|
|
|
+che_liang_shi_yong_xing_zhi,
|
|
|
+che_liang_suo_shu_dan_wei,
|
|
|
+first_unit,
|
|
|
+second_unit,
|
|
|
+third_unit,
|
|
|
+area_no,
|
|
|
+area_name,
|
|
|
+city_no,
|
|
|
+city_name,
|
|
|
+city_id,
|
|
|
+city,
|
|
|
+district_id,
|
|
|
+district,
|
|
|
+area_name2,
|
|
|
+area_no2,
|
|
|
+year_no,
|
|
|
+month_no,
|
|
|
+latest_year_month,
|
|
|
+car_new_year_month,
|
|
|
+car_move_yj_year_month
|
|
|
+)
|
|
|
+select
|
|
|
+stat_year_month as year_month,
|
|
|
+che_pai_hao,
|
|
|
+di_xiao_sum,
|
|
|
+di_xiao_sum_exclude_reason,
|
|
|
+xing_shi_shi_chang_sum,
|
|
|
+xing_shi_tian_shu_sum,
|
|
|
+zong_li_cheng_sum,
|
|
|
+ri_jun_li_cheng_sum,
|
|
|
+chu_qin_lv_sum,
|
|
|
+workday_sum,
|
|
|
+che_liang_lei_xing,
|
|
|
+che_liang_lai_yuan,
|
|
|
+che_liang_shi_yong_xing_zhi,
|
|
|
+che_liang_suo_shu_dan_wei,
|
|
|
+first_unit,
|
|
|
+second_unit,
|
|
|
+third_unit,
|
|
|
+area_no,
|
|
|
+area_name,
|
|
|
+city_no,
|
|
|
+city_name,
|
|
|
+city_id,
|
|
|
+city,
|
|
|
+district_id,
|
|
|
+district,
|
|
|
+area_name2,
|
|
|
+area_no2,
|
|
|
+left(cast(stat_year_month as varchar), 4)::int4 as year_no,
|
|
|
+right(cast(stat_year_month as varchar), 2)::int4 as month_no,
|
|
|
+year_month as latest_year_month,
|
|
|
+car_new_year_month,
|
|
|
+car_move_yj_year_month
|
|
|
+from t111
|
|
|
+""")
|
|
|
+ int insertCarLiChengLeiJiMonth(@Param("startYearMonth") Integer startYearMonth,
|
|
|
+ @Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆低效-累计算法
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+insert into car.car_di_xiao_month
|
|
|
+(
|
|
|
+year_month,
|
|
|
+ che_pai_hao,
|
|
|
+ xing_shi_shi_chang_sum,
|
|
|
+ xing_shi_tian_shu_sum,
|
|
|
+ zong_li_cheng_sum,
|
|
|
+ ri_jun_li_cheng_sum,
|
|
|
+ chu_qin_lv_sum,
|
|
|
+ workday_sum,
|
|
|
+ che_liang_lei_xing,
|
|
|
+ che_liang_lai_yuan,
|
|
|
+ che_liang_shi_yong_xing_zhi,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district,
|
|
|
+ area_name2,
|
|
|
+ area_no2,
|
|
|
+ year_no,
|
|
|
+ month_no
|
|
|
+)
|
|
|
+select
|
|
|
+ year_month,
|
|
|
+ che_pai_hao,
|
|
|
+ xing_shi_shi_chang_sum,
|
|
|
+ xing_shi_tian_shu_sum,
|
|
|
+ zong_li_cheng_sum,
|
|
|
+ ri_jun_li_cheng_sum,
|
|
|
+ chu_qin_lv_sum,
|
|
|
+ workday_sum,
|
|
|
+ che_liang_lei_xing,
|
|
|
+ che_liang_lai_yuan,
|
|
|
+ che_liang_shi_yong_xing_zhi,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district,
|
|
|
+ area_name2,
|
|
|
+ area_no2,
|
|
|
+ year_no,
|
|
|
+ month_no
|
|
|
+from
|
|
|
+ car.car_li_cheng_lei_ji_month
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and di_xiao_sum = 1
|
|
|
+""")
|
|
|
+ int insertCarDiXiaoMonth(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆违规数据
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+insert into car.car_wei_gui
|
|
|
+(
|
|
|
+che_liang_suo_shu_dan_wei,
|
|
|
+che_pai_hao,
|
|
|
+che_liang_lei_xing,
|
|
|
+che_liang_shi_yong_xing_zhi,
|
|
|
+bao_jing_qu_yu_miao_shu,
|
|
|
+bao_jing_gui_ze_miao_shu,
|
|
|
+yue_jie_shi_jian,
|
|
|
+shi_fou_zhi_xing_zhong_yue_jie,
|
|
|
+xiang_qing,
|
|
|
+first_unit,
|
|
|
+second_unit,
|
|
|
+third_unit,
|
|
|
+car_id,
|
|
|
+year_month,
|
|
|
+data_date,
|
|
|
+bao_fei,
|
|
|
+source,
|
|
|
+raw_che_pai_hao,
|
|
|
+area_no,
|
|
|
+area_name,
|
|
|
+city_no,
|
|
|
+city_name,
|
|
|
+area_no2,
|
|
|
+area_name2,
|
|
|
+city_id,
|
|
|
+city,
|
|
|
+district_id,
|
|
|
+district,
|
|
|
+year_no,
|
|
|
+month_no,
|
|
|
+che_pai_fail
|
|
|
+)
|
|
|
+select
|
|
|
+che_liang_suo_shu_dan_wei,
|
|
|
+che_pai_hao,
|
|
|
+che_liang_lei_xing,
|
|
|
+che_liang_shi_yong_xing_zhi,
|
|
|
+bao_jing_qu_yu_miao_shu,
|
|
|
+bao_jing_gui_ze_miao_shu,
|
|
|
+yue_jie_shi_jian,
|
|
|
+shi_fou_zhi_xing_zhong_yue_jie,
|
|
|
+xiang_qing,
|
|
|
+first_unit,
|
|
|
+second_unit,
|
|
|
+third_unit,
|
|
|
+car_id,
|
|
|
+year_month,
|
|
|
+data_date,
|
|
|
+bao_fei,
|
|
|
+source,
|
|
|
+raw_che_pai_hao,
|
|
|
+area_no,
|
|
|
+area_name,
|
|
|
+city_no,
|
|
|
+city_name,
|
|
|
+area_no2,
|
|
|
+area_name2,
|
|
|
+city_id,
|
|
|
+city,
|
|
|
+district_id,
|
|
|
+district,
|
|
|
+year_no,
|
|
|
+month_no,
|
|
|
+che_pai_fail
|
|
|
+from car.car_yue_jie
|
|
|
+where shi_fou_zhi_xing_zhong_yue_jie = '否'
|
|
|
+and year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int insertCarWeiGui(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆其他费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as qi_ta,
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+from
|
|
|
+ car.car_qi_ta
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) *
|
|
|
+from
|
|
|
+ car.car_qi_ta
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+order by
|
|
|
+ license_plate_number,
|
|
|
+ year_month,
|
|
|
+ start_time desc
|
|
|
+),
|
|
|
+t103 as (
|
|
|
+select
|
|
|
+ t101.*,
|
|
|
+ t102.year_no,
|
|
|
+ t102.month_no,
|
|
|
+ t102.dept_id,
|
|
|
+ t102.first_unit,
|
|
|
+ t102.second_unit,
|
|
|
+ t102.third_unit,
|
|
|
+ t102.area_no,
|
|
|
+ t102.area_name,
|
|
|
+ t102.city_no,
|
|
|
+ t102.city_name,
|
|
|
+ t102.area_no2,
|
|
|
+ t102.area_name2,
|
|
|
+ t102.city_id,
|
|
|
+ t102.city,
|
|
|
+ t102.district_id,
|
|
|
+ t102.district
|
|
|
+from
|
|
|
+ t101
|
|
|
+join t102 on
|
|
|
+ t101.year_month = t102.year_month
|
|
|
+ and t101.license_plate_number = t102.license_plate_number
|
|
|
+)
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ qi_ta,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+)
|
|
|
+select
|
|
|
+ qi_ta,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ dept_id as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ t103 b
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.license_plate_number
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarQiTa(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆年检费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as nian_jian_fei,
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+from
|
|
|
+ car.car_nian_jian_fei
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) *
|
|
|
+from
|
|
|
+ car.car_nian_jian_fei
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+order by
|
|
|
+ license_plate_number,
|
|
|
+ year_month,
|
|
|
+ start_time desc
|
|
|
+),
|
|
|
+t103 as (
|
|
|
+select
|
|
|
+ t101.*,
|
|
|
+ t102.year_no,
|
|
|
+ t102.month_no,
|
|
|
+ t102.dept_id,
|
|
|
+ t102.first_unit,
|
|
|
+ t102.second_unit,
|
|
|
+ t102.third_unit,
|
|
|
+ t102.area_no,
|
|
|
+ t102.area_name,
|
|
|
+ t102.city_no,
|
|
|
+ t102.city_name,
|
|
|
+ t102.area_no2,
|
|
|
+ t102.area_name2,
|
|
|
+ t102.city_id,
|
|
|
+ t102.city,
|
|
|
+ t102.district_id,
|
|
|
+ t102.district
|
|
|
+from
|
|
|
+ t101
|
|
|
+join t102 on
|
|
|
+ t101.year_month = t102.year_month
|
|
|
+ and t101.license_plate_number = t102.license_plate_number
|
|
|
+)
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ nian_jian_fei,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+)
|
|
|
+select
|
|
|
+ nian_jian_fei,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ dept_id as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ t103 b
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.license_plate_number
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarNianJianFei(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆保险费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(total_amount) as bao_xian,
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+from
|
|
|
+ car.car_bao_xian
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) *
|
|
|
+from
|
|
|
+ car.car_bao_xian
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+order by
|
|
|
+ license_plate_number,
|
|
|
+ year_month,
|
|
|
+ start_time desc
|
|
|
+),
|
|
|
+t103 as (
|
|
|
+select
|
|
|
+ t101.*,
|
|
|
+ t102.year_no,
|
|
|
+ t102.month_no,
|
|
|
+ t102.dept_id,
|
|
|
+ t102.first_unit,
|
|
|
+ t102.second_unit,
|
|
|
+ t102.third_unit,
|
|
|
+ t102.area_no,
|
|
|
+ t102.area_name,
|
|
|
+ t102.city_no,
|
|
|
+ t102.city_name,
|
|
|
+ t102.area_no2,
|
|
|
+ t102.area_name2,
|
|
|
+ t102.city_id,
|
|
|
+ t102.city,
|
|
|
+ t102.district_id,
|
|
|
+ t102.district
|
|
|
+from
|
|
|
+ t101
|
|
|
+join t102 on
|
|
|
+ t101.year_month = t102.year_month
|
|
|
+ and t101.license_plate_number = t102.license_plate_number
|
|
|
+)
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ bao_xian,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+)
|
|
|
+select
|
|
|
+ bao_xian,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ dept_id as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ t103 b
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.license_plate_number
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarBaoXian(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆路桥费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as lu_qiao,
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+from
|
|
|
+ car.car_lu_qiao
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) *
|
|
|
+from
|
|
|
+ car.car_lu_qiao
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+order by
|
|
|
+ license_plate_number,
|
|
|
+ year_month,
|
|
|
+ start_time desc
|
|
|
+),
|
|
|
+t103 as (
|
|
|
+select
|
|
|
+ t101.*,
|
|
|
+ t102.year_no,
|
|
|
+ t102.month_no,
|
|
|
+ t102.dept_id,
|
|
|
+ t102.first_unit,
|
|
|
+ t102.second_unit,
|
|
|
+ t102.third_unit,
|
|
|
+ t102.area_no,
|
|
|
+ t102.area_name,
|
|
|
+ t102.city_no,
|
|
|
+ t102.city_name,
|
|
|
+ t102.area_no2,
|
|
|
+ t102.area_name2,
|
|
|
+ t102.city_id,
|
|
|
+ t102.city,
|
|
|
+ t102.district_id,
|
|
|
+ t102.district
|
|
|
+from
|
|
|
+ t101
|
|
|
+join t102 on
|
|
|
+ t101.year_month = t102.year_month
|
|
|
+ and t101.license_plate_number = t102.license_plate_number
|
|
|
+)
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ lu_qiao,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+)
|
|
|
+select
|
|
|
+ lu_qiao,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ dept_id as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ t103 b
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.license_plate_number
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarLuQiao(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆维修费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as wei_xiu,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_wei_xiu
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as wei_xiu,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_da_wei_xiu
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t201 as (
|
|
|
+select
|
|
|
+ (coalesce(t101.wei_xiu, 0) + coalesce(t102.wei_xiu, 0)) as wei_xiu,
|
|
|
+ t101.che_pai_hao,
|
|
|
+ t101.year_month
|
|
|
+from
|
|
|
+ t101
|
|
|
+join t102 on
|
|
|
+ t101.che_pai_hao = t102.che_pai_hao
|
|
|
+ and t101.year_month = t102.year_month
|
|
|
+),
|
|
|
+t202 as (
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t101
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ t201
|
|
|
+ where
|
|
|
+ t201.che_pai_hao = t101.che_pai_hao
|
|
|
+ and t201.year_month = t101.year_month)
|
|
|
+),
|
|
|
+t203 as (
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t102
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ t201
|
|
|
+ where
|
|
|
+ t201.che_pai_hao = t102.che_pai_hao
|
|
|
+ and t201.year_month = t102.year_month)
|
|
|
+),
|
|
|
+t301 as (
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t201
|
|
|
+union all
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t202
|
|
|
+union all
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t203
|
|
|
+),
|
|
|
+t401 as (
|
|
|
+select
|
|
|
+ distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) license_plate_number,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ organization as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ car.car_wei_xiu
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+),
|
|
|
+t402 as (
|
|
|
+select
|
|
|
+ distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) license_plate_number,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ vehicle_unit as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ car.car_da_wei_xiu
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+),
|
|
|
+t403 as (
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t401
|
|
|
+union all
|
|
|
+select
|
|
|
+ *
|
|
|
+from
|
|
|
+ t402
|
|
|
+),
|
|
|
+t404 as (
|
|
|
+select
|
|
|
+ distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) *
|
|
|
+from
|
|
|
+ t403
|
|
|
+),
|
|
|
+t501 as (
|
|
|
+select
|
|
|
+ t301.*,
|
|
|
+ t404.year_no,
|
|
|
+ t404.month_no,
|
|
|
+ t404.che_liang_suo_shu_dan_wei,
|
|
|
+ t404.first_unit,
|
|
|
+ t404.second_unit,
|
|
|
+ t404.third_unit,
|
|
|
+ t404.area_no,
|
|
|
+ t404.area_name,
|
|
|
+ t404.city_no,
|
|
|
+ t404.city_name,
|
|
|
+ t404.area_no2,
|
|
|
+ t404.area_name2,
|
|
|
+ t404.city_id,
|
|
|
+ t404.city,
|
|
|
+ t404.district_id,
|
|
|
+ t404.district
|
|
|
+from
|
|
|
+ t301
|
|
|
+join t404 on
|
|
|
+ t301.che_pai_hao = t404.license_plate_number
|
|
|
+ and t301.year_month = t404.year_month
|
|
|
+)
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ wei_xiu,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+)
|
|
|
+select
|
|
|
+ wei_xiu,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ t501 b
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarWeiXiu(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆燃油费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as ran_you,
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+from
|
|
|
+ car.car_ran_you
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+ and license_plate_number is not null
|
|
|
+ and license_plate_number != ''
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select distinct on
|
|
|
+ (license_plate_number,
|
|
|
+ year_month) *
|
|
|
+from
|
|
|
+ car.car_ran_you
|
|
|
+where
|
|
|
+ year_month = #{endYearMonth}
|
|
|
+order by
|
|
|
+ license_plate_number,
|
|
|
+ year_month,
|
|
|
+ start_time desc
|
|
|
+),
|
|
|
+t103 as (
|
|
|
+select
|
|
|
+ t101.*,
|
|
|
+ t102.year_no,
|
|
|
+ t102.month_no,
|
|
|
+ t102.vehicle_unit,
|
|
|
+ t102.first_unit,
|
|
|
+ t102.second_unit,
|
|
|
+ t102.third_unit,
|
|
|
+ t102.area_no,
|
|
|
+ t102.area_name,
|
|
|
+ t102.city_no,
|
|
|
+ t102.city_name,
|
|
|
+ t102.area_no2,
|
|
|
+ t102.area_name2,
|
|
|
+ t102.city_id,
|
|
|
+ t102.city,
|
|
|
+ t102.district_id,
|
|
|
+ t102.district
|
|
|
+from
|
|
|
+ t101
|
|
|
+join t102 on
|
|
|
+ t101.year_month = t102.year_month
|
|
|
+ and t101.license_plate_number = t102.license_plate_number
|
|
|
+)
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ ran_you,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+)
|
|
|
+select
|
|
|
+ ran_you,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month,
|
|
|
+ year_no,
|
|
|
+ month_no,
|
|
|
+ vehicle_unit as che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ second_unit,
|
|
|
+ third_unit,
|
|
|
+ area_no,
|
|
|
+ area_name,
|
|
|
+ city_no,
|
|
|
+ city_name,
|
|
|
+ area_no2,
|
|
|
+ area_name2,
|
|
|
+ city_id,
|
|
|
+ city,
|
|
|
+ district_id,
|
|
|
+ district
|
|
|
+from
|
|
|
+ t103 b
|
|
|
+where
|
|
|
+ not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.license_plate_number
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarRanYou(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入车辆租赁费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+insert into car.car_fei_yong_month
|
|
|
+(
|
|
|
+ zu_lin,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month
|
|
|
+)
|
|
|
+select
|
|
|
+ bu_han_shui_jin_e as zu_lin,
|
|
|
+ che_liang_suo_shu_dan_wei,
|
|
|
+ first_unit,
|
|
|
+ che_pai_hao,
|
|
|
+ year_month
|
|
|
+from
|
|
|
+ car.car_zu_lin b
|
|
|
+where
|
|
|
+ b.year_month = #{endYearMonth}
|
|
|
+ and b.che_pai_hao is not null
|
|
|
+ and b.che_pai_hao != ''
|
|
|
+ and not exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_fei_yong_month a
|
|
|
+ where
|
|
|
+ a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.year_month = b.year_month)
|
|
|
+""")
|
|
|
+ int insertCarZuLin(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆其他费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as qi_ta,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_qi_ta
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+)
|
|
|
+update car.car_fei_yong_month a set qi_ta = b.qi_ta
|
|
|
+from t101 b
|
|
|
+where a.che_pai_hao = b.che_pai_hao and a.year_month = b.year_month
|
|
|
+""")
|
|
|
+ int updateCarQiTan(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆年检费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as nian_jian_fei,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_nian_jian_fei
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+)
|
|
|
+update car.car_fei_yong_month a set nian_jian_fei = b.nian_jian_fei
|
|
|
+from t101 b
|
|
|
+where a.che_pai_hao = b.che_pai_hao and a.year_month = b.year_month
|
|
|
+""")
|
|
|
+ int updateCarNianJianFei(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆保险费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(total_amount) as bao_xian,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_bao_xian
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+)
|
|
|
+update car.car_fei_yong_month a set bao_xian = b.bao_xian
|
|
|
+from t101 b
|
|
|
+where a.che_pai_hao = b.che_pai_hao and a.year_month = b.year_month
|
|
|
+""")
|
|
|
+ int updateCarBaoXian(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆路桥费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as lu_qiao,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_lu_qiao
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+)
|
|
|
+update car.car_fei_yong_month a set lu_qiao = b.lu_qiao
|
|
|
+from t101 b
|
|
|
+where a.che_pai_hao = b.che_pai_hao and a.year_month = b.year_month
|
|
|
+""")
|
|
|
+ int updateCarLuQiao(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆维修费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as wei_xiu,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_wei_xiu
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t102 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as wei_xiu,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_da_wei_xiu
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+),
|
|
|
+t201 as (
|
|
|
+select
|
|
|
+(coalesce(t101.wei_xiu, 0) + coalesce(t102.wei_xiu, 0)) as wei_xiu,
|
|
|
+t101.che_pai_hao,
|
|
|
+t101.year_month
|
|
|
+from t101 join t102 on t101.che_pai_hao = t102.che_pai_hao and t101.year_month = t102.year_month
|
|
|
+),
|
|
|
+t202 as (
|
|
|
+select * from t101
|
|
|
+where not exists (select 1 from t201 where t201.che_pai_hao = t101.che_pai_hao and t201.year_month = t101.year_month)
|
|
|
+),
|
|
|
+t203 as (
|
|
|
+select * from t102
|
|
|
+where not exists (select 1 from t201 where t201.che_pai_hao = t102.che_pai_hao and t201.year_month = t102.year_month)
|
|
|
+),
|
|
|
+t301 as (
|
|
|
+select * from t201
|
|
|
+union all
|
|
|
+select * from t202
|
|
|
+union all
|
|
|
+select * from t203
|
|
|
+)
|
|
|
+update car.car_fei_yong_month a set wei_xiu = b.wei_xiu
|
|
|
+from t301 b
|
|
|
+where a.che_pai_hao = b.che_pai_hao and a.year_month = b.year_month
|
|
|
+""")
|
|
|
+ int updateCarWeiXiu(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆燃油费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+with
|
|
|
+t101 as (
|
|
|
+select
|
|
|
+ sum(amount_excluding_tax) as ran_you,
|
|
|
+ license_plate_number as che_pai_hao,
|
|
|
+ year_month as year_month
|
|
|
+from
|
|
|
+ car.car_ran_you
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+group by
|
|
|
+ license_plate_number,
|
|
|
+ year_month
|
|
|
+)
|
|
|
+update car.car_fei_yong_month a set ran_you = b.ran_you
|
|
|
+from t101 b
|
|
|
+where a.che_pai_hao = b.che_pai_hao and a.year_month = b.year_month
|
|
|
+""")
|
|
|
+ int updateCarRanYou(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆租赁费
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update
|
|
|
+ car.car_fei_yong_month a
|
|
|
+set
|
|
|
+ zu_lin = b.bu_han_shui_jin_e
|
|
|
+from
|
|
|
+ car.car_zu_lin b
|
|
|
+where
|
|
|
+ a.che_pai_hao = b.che_pai_hao
|
|
|
+ and a.year_month = b.year_month
|
|
|
+ and a.year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarZuLin(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆运行费总费用
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update
|
|
|
+ car.car_fei_yong_month
|
|
|
+set
|
|
|
+ yun_xing_fei = case
|
|
|
+ when ran_you is null
|
|
|
+ and bao_xian is null
|
|
|
+ and wei_xiu is null
|
|
|
+ and lu_qiao is null then null
|
|
|
+ else (coalesce(ran_you,
|
|
|
+ 0) + coalesce(bao_xian,
|
|
|
+ 0) + coalesce(wei_xiu,
|
|
|
+ 0) + coalesce(lu_qiao,
|
|
|
+ 0))
|
|
|
+ end,
|
|
|
+ zong_fei_yong = case
|
|
|
+ when ran_you is null
|
|
|
+ and bao_xian is null
|
|
|
+ and wei_xiu is null
|
|
|
+ and lu_qiao is null
|
|
|
+ and zu_lin is null
|
|
|
+ and nian_jian_fei is null
|
|
|
+ and qi_ta is null
|
|
|
+ then null
|
|
|
+ else (coalesce(ran_you,
|
|
|
+ 0) + coalesce(bao_xian,
|
|
|
+ 0) + coalesce(wei_xiu,
|
|
|
+ 0) + coalesce(lu_qiao,
|
|
|
+ 0) + coalesce(zu_lin,
|
|
|
+ 0) + coalesce(nian_jian_fei,
|
|
|
+ 0) + coalesce(qi_ta,
|
|
|
+ 0))
|
|
|
+ end
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarFeiYongMonthYunXingFeiZongFeiYong(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新车辆费用基本信息
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Update("""
|
|
|
+update car.car_fei_yong_month a set
|
|
|
+che_liang_lai_yuan = coalesce((select che_liang_lai_yuan from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), che_liang_lai_yuan),
|
|
|
+che_liang_lei_xing = coalesce((select che_liang_lei_xing from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), che_liang_lei_xing),
|
|
|
+che_liang_shi_yong_xing_zhi = coalesce((select che_liang_shi_yong_xing_zhi from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), che_liang_shi_yong_xing_zhi),
|
|
|
+che_liang_suo_shu_dan_wei = coalesce((select che_liang_suo_shu_dan_wei from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), che_liang_suo_shu_dan_wei),
|
|
|
+first_unit = coalesce((select first_unit from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), first_unit),
|
|
|
+second_unit = coalesce((select second_unit from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), second_unit),
|
|
|
+third_unit = coalesce((select third_unit from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), third_unit),
|
|
|
+area_no = coalesce((select area_no from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), area_no),
|
|
|
+area_name = coalesce((select area_name from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), area_name),
|
|
|
+city_no = coalesce((select city_no from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), city_no),
|
|
|
+city_name = coalesce((select city_name from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), city_name),
|
|
|
+city_id = coalesce((select city_id from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), city_id),
|
|
|
+city = coalesce((select city from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), city),
|
|
|
+district_id = coalesce((select district_id from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), district_id),
|
|
|
+district = coalesce((select district from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), district),
|
|
|
+area_name2 = coalesce((select area_name2 from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), area_name2),
|
|
|
+area_no2 = coalesce((select area_no2 from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month order by b.year_month desc limit 1), area_no2),
|
|
|
+rui_xing = case when exists(select 1 from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month <= a.year_month) then 1 else 0 end,
|
|
|
+rui_xing_month = case when exists(select 1 from car.car_base_data_month b where a.che_pai_hao = b.che_pai_hao and b.year_month = a.year_month) then 1 else 0 end,
|
|
|
+year_no = left(cast(a.year_month as varchar), 4)::int4,
|
|
|
+month_no = right(cast(a.year_month as varchar), 2)::int4
|
|
|
+where year_month = #{endYearMonth}
|
|
|
+""")
|
|
|
+ int updateCarFeiYongMonthBaseInfo(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否有车辆基本信息、用车数据
|
|
|
+ * @param endYearMonth 账期
|
|
|
+ */
|
|
|
+ @Select("""
|
|
|
+select
|
|
|
+ (
|
|
|
+ select
|
|
|
+ exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_base_data_month
|
|
|
+ where
|
|
|
+ year_month = #{endYearMonth}))
|
|
|
+ and (
|
|
|
+ select
|
|
|
+ exists (
|
|
|
+ select
|
|
|
+ 1
|
|
|
+ from
|
|
|
+ car.car_yong_che
|
|
|
+ where
|
|
|
+ year_month = #{endYearMonth}))
|
|
|
+""")
|
|
|
+ boolean hasCarBaseDataYongChe(@Param("endYearMonth") Integer endYearMonth);
|
|
|
+}
|