added deployment folder with latest code
This commit is contained in:
@@ -0,0 +1,390 @@
|
||||
drop function if exists mmt_staging2.fn_FTWET_TRS_ODS ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTWET_TRS_ODS(p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
declare __test_instance_id int;
|
||||
declare __file_syspk int;
|
||||
declare __test_tractor_id int;
|
||||
declare __test_master_id int;
|
||||
declare v_state text;
|
||||
declare v_msg text;
|
||||
declare v_detail text;
|
||||
declare v_hint text;
|
||||
declare v_context text;
|
||||
declare _error int;
|
||||
begin
|
||||
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_FTWET_TRS_ODS
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTWET
|
||||
Sheet Format: FTWET_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select mmt_staging2.fn_FTWET_TRS_ODS()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
/*delete from mmt_ods.test_instance where test_file_ref_no =260;
|
||||
|
||||
delete from mmt_ods.test_instance_engine_info where test_file_ref_no =260;
|
||||
|
||||
delete from mmt_ods.test_instance_implement_info where test_file_ref_no =260;
|
||||
|
||||
delete from mmt_ods.test_instance_tractor_info where test_file_ref_no =260;
|
||||
|
||||
|
||||
delete from mmt_ods.test_instance_trailer_info where test_file_ref_no =260;
|
||||
|
||||
delete from mmt_ods.test_instance_tyre_info where test_file_ref_no =260;*/
|
||||
|
||||
select file_syspk into __file_syspk from mmt_staging2.FTWET_TRS_H1_Block;
|
||||
|
||||
|
||||
insert into mmt_ods.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location_name,
|
||||
soil_moisture_content_pct,
|
||||
soil_bulk_density_g_per_cc,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test,
|
||||
test_report_date,
|
||||
season,
|
||||
type_of_soil,
|
||||
soil_cone_index,
|
||||
field_condition,
|
||||
test_file_ref_no,
|
||||
test_file_format,
|
||||
test_file_sheet_format
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
report_reference_no test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location test_location_name,
|
||||
soil_moisture_content_::numeric soil_moisture_content_pct ,
|
||||
soil_bulk_density_g_cc::numeric soil_bulk_density_g_per_cc,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test::date,
|
||||
report_date::date test_report_date,
|
||||
season,
|
||||
type_of_soil,
|
||||
soil_cone_index_kpa::int soil_cone_index,
|
||||
field_condition,
|
||||
file_syspk,
|
||||
file_format,
|
||||
sheet_mnemonic
|
||||
from mmt_staging2.ftwet_trs_h1_block where ods_record=1;
|
||||
|
||||
|
||||
insert into mmt_ods.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
tractor_engine_hp,
|
||||
fip_type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
wheel_drive_type,
|
||||
egr_yn,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
Ballasted_Tractor_Accessories,
|
||||
mechanical_ballast_rear_in_kg,
|
||||
water_ballast_rear_75_pct ,
|
||||
Mechanical_Ballast_Front,
|
||||
mechanical_ballast_front_kg ,
|
||||
Total_Ballast_Weight,
|
||||
test_file_ref_no,
|
||||
test_file_format,
|
||||
test_file_sheet_format
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
trim('HP' from Tractor_Engine_HP)::numeric,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading::numeric,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD wheel_drive_type ,
|
||||
EGR_Yes_No egr_yn,
|
||||
Brake_Type ,
|
||||
PTO_Type ,
|
||||
Standard_PTO_Speed_RPM::numeric,
|
||||
EPTO_Speed_RPM::numeric,
|
||||
Tractor_Weight_kg_Front::numeric tractor_weight_front_kg ,
|
||||
Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg ,
|
||||
Tractor_Weight_kg_Total::numeric tractor_weight_total_kg ,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear_in_KG::numeric mechanical_ballast_rear_in_kg ,
|
||||
Water_Ballast_Rear water_ballast_rear_75_pct ,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg::int mechanical_ballast_front_kg ,
|
||||
Total_Ballast_Weight::numeric,
|
||||
file_syspk,
|
||||
file_format,
|
||||
sheet_mnemonic
|
||||
from mmt_staging2.ftwet_trs_spec_block where tractor_model is not null and ods_record=1;
|
||||
|
||||
update mmt_ods.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
|
||||
) where test_file_ref_no =__file_syspk;
|
||||
|
||||
update mmt_ods.test_instance_tractor_info a
|
||||
set test_tractor_yn ='Y' where syspk in
|
||||
(select min(syspk) from mmt_ods.test_instance_tractor_info b
|
||||
where b.test_file_ref_no =a.test_file_ref_no)
|
||||
and test_file_ref_no =__file_syspk;
|
||||
|
||||
update mmt_ods.test_instance_tractor_info
|
||||
set test_tractor_yn ='N'
|
||||
where test_tractor_yn is null and test_file_ref_no =__file_syspk;
|
||||
|
||||
insert into mmt_ods.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_file_ref_no,
|
||||
test_file_format,
|
||||
test_file_sheet_format,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_format,
|
||||
sheet_mnemonic,
|
||||
'front',
|
||||
front_tyre_make tyre_make,
|
||||
front_tyre_size tyre_size,
|
||||
front_tyre_pressure_psi::int tyre_pressure_psi
|
||||
from mmt_staging2.ftwet_trs_spec_block where front_tyre_make is not null and ods_record=1;
|
||||
|
||||
update mmt_ods.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from mmt_ods.test_instance_tractor_info b
|
||||
where a.test_file_ref_no=b.test_file_ref_no and
|
||||
a.tractor_model=b.tractor_model)
|
||||
where a.tyre_type ='front' and a.test_file_ref_no =__file_syspk;
|
||||
|
||||
insert into mmt_ods.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_file_ref_no,
|
||||
test_file_format,
|
||||
test_file_sheet_format,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_format,
|
||||
sheet_mnemonic,
|
||||
'rear',
|
||||
rear_tyre_make tyre_make,
|
||||
rear_tyre_size tyre_size,
|
||||
rear_tyre_pressure_psi::numeric tyre_pressure_psi
|
||||
from mmt_staging2.ftwet_trs_spec_block where rear_tyre_make is not null and ods_record=1;
|
||||
|
||||
update mmt_ods.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from mmt_ods.test_instance_tractor_info b
|
||||
where a.test_file_ref_no=b.test_file_ref_no and
|
||||
a.tractor_model=b.tractor_model)
|
||||
where a.tyre_type ='rear' and a.test_file_ref_no = __file_syspk;
|
||||
|
||||
insert into mmt_ods.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
low_idle_declared,
|
||||
high_idle_declared,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
test_file_ref_no,
|
||||
test_file_format,
|
||||
test_file_sheet_format
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
low_idle low_idle_declared,
|
||||
high_idle high_idle_declared,
|
||||
rated_rpm::numeric,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
file_syspk,
|
||||
file_format,
|
||||
sheet_mnemonic
|
||||
from mmt_staging2.ftwet_trs_engine_rpm_block where tractor_model is not null and ods_record=1;
|
||||
|
||||
update mmt_ods.test_instance_engine_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from mmt_ods.test_instance_tractor_info b
|
||||
where a.test_file_ref_no=b.test_file_ref_no and
|
||||
a.tractor_model=b.tractor_model)
|
||||
where a.test_file_ref_no = __file_syspk;
|
||||
|
||||
insert into mmt_ods.test_instance_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
make_of_implement,
|
||||
no_of_disc_blades_bottoms,
|
||||
cutting_width_m,
|
||||
implement_weight_kg,
|
||||
hitch_category,
|
||||
span_for_mounted_implement_mm,
|
||||
mast_height_for_mounted_implement_mm,
|
||||
type_of_cage_wheel_hcw_fcw,
|
||||
Cage_Wheel_Width_mm,
|
||||
cage_wheel_weight_kg,
|
||||
cage_wheel_inner_ring_dia_mm,
|
||||
cage_wheel_outer_ring_dia_mm,
|
||||
cage_wheel_center_ring_dia_mm,
|
||||
dist_btwn_lhs_fcw_to_rhs_fcw_mm,
|
||||
No_of_angles_on_cage_wheel,
|
||||
No_of_days_of_water_logging,
|
||||
Depth_of_water_mm,
|
||||
test_file_ref_no,
|
||||
test_file_format,
|
||||
test_file_sheet_format
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
make_of_implement,
|
||||
no_of_bottoms_tyne_disc_blade::numeric no_of_disc_blades_bottoms,
|
||||
cutting_width_m,
|
||||
implement_weight_kg::numeric,
|
||||
hitch_category,
|
||||
span_cm_for_mounted_implement::numeric span_for_mounted_implement_cm ,
|
||||
mast_height_cm_for_mounted_implement::numeric mast_height_for_mounted_implement_cm,
|
||||
Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel type_of_cage_wheel_hcw_fcw ,
|
||||
Cage_Wheel_Width_mm::numeric,
|
||||
Cage_wheel_Weight::numeric cage_wheel_weight_kg,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_inner_ring_dia_mm ,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_outer_ring_dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm::numeric cage_wheel_center_ring_dia_mm ,
|
||||
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm_For_Full_Cage_wheel::int dist_btwn_lhs_fcw_to_rhs_fcw_mm,
|
||||
No_of_angles_on_cage_wheel::numeric,
|
||||
No_of_days_of_water_logging::numeric,
|
||||
Depth_of_water_mm::numeric,
|
||||
file_syspk,
|
||||
file_format,
|
||||
sheet_mnemonic
|
||||
from mmt_staging2.ftwet_trs_implement_block where name_of_implement is not null and ods_record=1;
|
||||
|
||||
|
||||
update mmt_ods.test_instance a
|
||||
set report_template_no=b.report_template_no,
|
||||
report_template_rev_no=b.report_template_rev_no,
|
||||
report_template_rev_date =b.report_template_rev_date
|
||||
from mmt_staging2.ftwet_trs_implement_block b where name_of_implement is not null
|
||||
and a.test_file_ref_no=b.file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from mmt_ods.test_instance where test_file_ref_no =__file_syspk;
|
||||
select syspk from mmt_ods.test_master into __test_master_id where test_type ='Field';
|
||||
select syspk from mmt_ods.test_instance_tractor_info into __test_tractor_id
|
||||
where test_file_ref_no =__file_syspk and test_tractor_yn ='Y';
|
||||
|
||||
|
||||
update mmt_ods.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_tractor_id
|
||||
where test_file_ref_no=__file_syspk;
|
||||
|
||||
update mmt_ods.test_instance_engine_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where test_file_ref_no=__file_syspk;
|
||||
|
||||
|
||||
update mmt_ods.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where test_file_ref_no=__file_syspk;
|
||||
|
||||
|
||||
update mmt_ods.test_instance_tyre_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where test_file_ref_no=__file_syspk;
|
||||
|
||||
update mmt_ods.test_instance_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where test_file_ref_no=__file_syspk;
|
||||
|
||||
update mmt_ods.test_instance_trailer_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where test_file_ref_no=__file_syspk;
|
||||
|
||||
v_context := '';
|
||||
perform mmt_staging2.mmt_insert_db_error ( null, null, 1001, 'Compegence', __file_syspk ,'FTWET','FTWET_TRS' ,null,'ods', 'fn_FTWET_TRS_ODS', v_state, v_msg, v_detail, v_hint, v_context,'success');
|
||||
return v_context;
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
v_state = returned_sqlstate,
|
||||
v_msg = message_text,
|
||||
v_detail = pg_exception_detail,
|
||||
v_hint = pg_exception_hint,
|
||||
v_context = pg_exception_context;
|
||||
|
||||
perform mmt_staging2.mmt_insert_db_error ( null, null, 1001, 'Compegence', __file_syspk ,'FTWET','FTWET_TRS' ,null,'ods', 'fn_FTWET_TRS_ODS', v_state, v_msg, v_detail, v_hint, v_context,'error');
|
||||
return v_context;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user