This commit is contained in:
dheepa
2021-08-09 11:14:23 +00:00
parent a0d3257be0
commit f3cf5e1d2d
89 changed files with 4769 additions and 1508 deletions

View File

@@ -1,34 +1,34 @@
drop function if exists staging2.fn_IHTNST_NST_TRX;
CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_NST_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
LANGUAGE plpgsql
RETURNS void
LANGUAGE plpgsql
AS $function$
declare __test_instance_id int;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_mnemonic text :=p_file_mnemonic;
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
declare __make text;
declare __model text;
declare err_state text;
declare err_msg text;
declare err_detail text;
declare err_hint text;
declare err_context text;
declare _error int;
declare __test_master_id int;
declare __test_instance_tractor_id int;
begin
__file_syspk := p_file_syspk;
declare __test_instance_id int;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_mnemonic text :=p_file_mnemonic;
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
declare __make text;
declare __model text;
declare err_state text;
declare err_msg text;
declare err_detail text;
declare err_hint text;
declare err_context text;
declare _error int;
declare __test_master_id int;
declare __test_instance_tractor_id int;
begin
--__file_syspk := p_file_syspk;
/************************************************************
/************************************************************
Function Name:fn_IHTNST_NST_TRX
Function Desc: This function populates data into ODS
File Format: IHTNST
Sheet Format: IHTNST_NST
Creation Date:
Creation Date:
Updation Date:
Author: compegence team
Function Call: select staging2.fn_IHTNST_NST_TRX()
@@ -61,7 +61,7 @@ objective_of_test,
test_condition,
test_purpose
)
select
select
client_id,
function_id,
file_syspk,
@@ -69,15 +69,15 @@ file_mnemonic,
file_sheet_mnemonic,
make,model,
Test_Request_no,
date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date,
sample_receipt_date::Date,
Test_report_No,
Generation,
Customer_Name,
Customer_Name,
Test_Engineer,
date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date,
Test_Report_Date::Date,
No_of_Sample,
date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date,
date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date,
Test_Start_Date::Date,
Test_End_Date::Date,
Tractor_Sr_No,
Test_Standard_Refer,
Test_facility,
@@ -86,8 +86,8 @@ Project_Group,
Objective,
condition,
Test_Purpose
from
staging2.IHTNST_NST_H1_block where trx_record=1;
from
staging2.IHTNST_NST_H1_block where trx_record=1;
update transactional.test_instance a
set report_prepared_by=b.prepared_by,
@@ -98,9 +98,9 @@ report_title=b.comments,
report_template_no=b.rev1,
report_template_rev_date=b.rev2,
report_template_rev_no= b.rev3
from staging2.IHTNST_nst_footer_block b
from staging2.IHTNST_nst_footer_block b
where a.file_sheet_mnemonic='IHTNST_NST' and trx_record=1;
insert into transactional.test_instance_tyre_info
(
client_id,
@@ -117,7 +117,7 @@ tyre_ply_rating,
tyre_load_carrying_capacity,
tyre_wheel_rim_make_and_size
)
select
select
client_id,
function_id,
file_syspk,
@@ -133,8 +133,8 @@ wheel_rim_make_size
from staging2.IHTNST_nst_tyre_details_block where trx_record=1;
insert into transactional.test_instance_engine_info
(
insert into transactional.test_instance_engine_info
(
client_id,
function_id,
file_syspk,
@@ -148,9 +148,11 @@ high_idle_declared,
high_idle_observed,
rated_rpm,
rated_rpm_observed,
engine_to_pto_ratio_540_pto
engine_to_pto_ratio_540_pto,
low_idle_remark,
high_idle_remark
)
select
select
client_id,
function_id,
file_syspk,
@@ -163,11 +165,13 @@ high_idle_declared,
high_idle_observed::numeric,
rated_rpm_declared::numeric,
rated_rpm_observed::numeric,
engine_to_pto_ratio
engine_to_pto_ratio ,
low_idle_remark,
high_idle_remark
from staging2.IHTNST_nst_engine_rpm_block where trx_record=1;
insert into transactional.test_instance_tractor_info
(
insert into transactional.test_instance_tractor_info
(
client_id,
function_id,
file_syspk,
@@ -175,17 +179,17 @@ file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
weight_reactions_front_kg,
tractor_weight_front_kg,
tractor_weight_front_observed_kg,
tractor_weight_front_remark,
weight_reactions_rear_kg,
tractor_weight_rear_kg,
tractor_weight_rear_observed_kg,
tractor_weight_rear_remark,
tractor_weight_total_kg,
tractor_weight_total_observed_kg,
tractor_weight_total_remark
)
select
select
client_id,
function_id,
file_syspk,
@@ -203,18 +207,39 @@ total_weight_observed::numeric,
total_weight_remark
from staging2.IHTNST_nst_weight_block where trx_record=1;
update transactional.test_instance_tractor_info
update transactional.test_instance_tractor_info a
set mahindra_model_yn = (
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
) where file_syspk =__file_syspk;
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
) where a.file_syspk =__file_syspk;
update transactional.test_instance_tractor_info a
set test_tractor_yn ='Y' where syspk in
set test_tractor_yn ='Y' where syspk in
(select min(syspk) from transactional.test_instance_tractor_info b
where b.file_syspk =a.file_syspk)
and a.file_syspk =__file_syspk;
update transactional.test_instance_tractor_info a
set
wheel_drive_type = b.Drive,
tractor_platform = b.Platform,
generation =b.generation ,
tractor_sr_no=b.tractor_sr_no,
tractor_engine_hp= b.Tractor_power_hp::numeric
from staging2.IHTNST_NST_H1_block b
where b.trx_record=1
and a.file_sheet_mnemonic ='IHTNST_NST'
and a.file_syspk =__file_syspk;
update transactional.test_instance_tyre_info b
set tractor_sr_no = a.tractor_sr_no
from transactional.test_instance_tractor_info a
where a.file_syspk =b.file_syspk;
/*block */
insert into transactional.test_instance_atmospheric_info
@@ -232,7 +257,7 @@ pressure_kpa,
background_noise_dba,
wind_velocity_kmph
)
select
select
client_id,
function_id,
file_syspk,
@@ -262,7 +287,7 @@ noise_level_1_db_a,
noise_level_2_db_a,
noise_level_3_db_a
)
select
select
client_id,
function_id,
file_syspk,
@@ -277,42 +302,12 @@ column5::numeric,
column6::numeric
from staging2.IHTNST_nst_stand_noise_block where trx_record=1;
update transactional.IHT_noise_measurement_results
set test_condition = (select column4
from staging2.IHTNST_nst_stand_noise_block
where block_row_number=3) where file_syspk = __file_syspk;
update transactional.IHT_noise_measurement_results
set test_condition = (select column4
from staging2.IHTNST_nst_stand_noise_block a
where a.block_row_number=3) where file_syspk = __file_syspk;
insert into transactional.IHT_noise_measurement_test
(
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
test_condition,
test_type,
test_mode
)
select
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
test_condition,
test_type,
test_mode
from transactional.IHT_noise_measurement_results where test_type='BY STANDERS NOISE';
update transactional.IHT_noise_measurement_test
set acceptance_criteria=b.acceptance_criteria,
remarks =b.remarks
from staging2.IHTNST_nst_stand_noise_block b
where b.column1 ='BY STANDERS NOISE' and test_type='BY STANDERS NOISE' and trx_record=1;
insert into transactional.IHT_noise_measurement_results
(
@@ -330,7 +325,7 @@ noise_level_1_db_a,
noise_level_2_db_a,
noise_level_3_db_a
)
select
select
client_id,
function_id,
file_syspk,
@@ -345,42 +340,12 @@ column8::numeric,
column9::numeric
from staging2.IHTNST_nst_stand_noise_block where trx_record=1;
update transactional.IHT_noise_measurement_results
set test_condition = (select column7
update transactional.IHT_noise_measurement_results a
set test_condition = (select column7
from staging2.IHTNST_nst_stand_noise_block
where block_row_number=3) where test_condition is null;
where block_row_number=3) where test_condition is null and test_type = 'BY STANDERS NOISE'
and a.file_syspk=__file_syspk;
insert into transactional.IHT_noise_measurement_test
(
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
test_condition,
test_type,
test_mode
)
select
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
test_condition,
test_type,
test_mode
from transactional.IHT_noise_measurement_results where test_type='BY STANDERS NOISE';
update transactional.IHT_noise_measurement_test
set acceptance_criteria=b.acceptance_criteria,
remarks =b.remarks
from staging2.IHTNST_nst_stand_noise_block b
where b.column1 ='BY STANDERS NOISE' and test_type='BY STANDERS NOISE' and trx_record=1;
insert into transactional.IHT_noise_measurement_results
(
@@ -401,7 +366,7 @@ noise_level_1_db_a,
noise_level_2_db_a,
noise_level_3_db_a
)
select
select
client_id,
function_id,
file_syspk,
@@ -419,11 +384,8 @@ column8::numeric,
column9::numeric
from staging2.IHTNST_nst_oel_noise_block where trx_record=1;
update transactional.IHT_noise_measurement_test
set acceptance_criteria=b.acceptance_criteria,
remarks =b.remarks
from staging2.IHTNST_nst_oel_noise_block b
where b.column1 ='OEL Noise without Load' and test_type='OEL Noise without Load';
insert into transactional.IHT_noise_measurement_results
(
@@ -444,7 +406,7 @@ noise_level_1_db_a,
noise_level_2_db_a,
noise_level_3_db_a
)
select
select
client_id,
function_id,
file_syspk,
@@ -462,11 +424,40 @@ column8::numeric,
column9::numeric
from staging2.IHTNST_nst_oel_noise_load_block where trx_record=1;
update transactional.IHT_noise_measurement_test
insert into transactional.IHT_noise_measurement_test
(
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
test_condition,
test_type,
test_mode
)
select
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
test_condition,
test_type,
test_mode
from transactional.IHT_noise_measurement_results b where test_type='BY STANDERS NOISE' and b.file_syspk=__file_syspk;
update transactional.IHT_noise_measurement_test a
set acceptance_criteria=b.acceptance_criteria,
remarks =b.remarks
from staging2.IHTNST_nst_oel_noise_load_block b
where b.column1 ='OEL Noise with Load' and test_type='OEL Noise with Load';
remarks =b.remarks
from staging2.IHTNST_nst_stand_noise_block b
where b.column1 ='BY STANDERS NOISE' and test_type='BY STANDERS NOISE' and trx_record=1
and a.file_syspk=__file_syspk;
insert into transactional.IHT_noise_measurement_test
(
@@ -492,7 +483,10 @@ tractor_model,
test_condition,
test_type,
test_mode
from transactional.IHT_noise_measurement_results where test_type ='OEL Noise without Load' ;
from transactional.IHT_noise_measurement_results b where test_type ='OEL Noise without Load' and b.file_syspk=__file_syspk;
insert into transactional.IHT_noise_measurement_test
(
@@ -518,60 +512,87 @@ tractor_model,
test_condition,
test_type,
test_mode
from transactional.IHT_noise_measurement_results where test_type ='OEL Noise with Load';
from transactional.IHT_noise_measurement_results b where test_type ='OEL Noise with Load' and b.file_syspk=__file_syspk;
delete from transactional.IHT_noise_measurement_test a
using transactional.IHT_noise_measurement_test b
where (a.syspk < b.syspk and
where (a.syspk < b.syspk and
a.test_condition is not null and
a.test_condition =b.test_condition and
a.test_mode =b.test_mode and a.test_type=b.test_type) or
(a.syspk < b.syspk and a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type);
a.test_condition =b.test_condition and
a.test_mode =b.test_mode and a.test_type=b.test_type and a.file_syspk=b.file_syspk) or
(a.syspk < b.syspk and a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type and a.file_syspk=b.file_syspk);
update transactional.IHT_noise_measurement_results a
set noise_measurement_id =(select syspk
set noise_measurement_id =(
select syspk
from transactional.IHT_noise_measurement_test b
where (a.test_condition =b.test_condition and a.test_condition is not null and
a.test_mode =b.test_mode and a.test_type=b.test_type) or
(a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type));
where
(a.test_condition =b.test_condition and a.test_condition is not null and a.test_mode =b.test_mode and a.test_type=b.test_type and a.file_syspk=b.file_syspk )
or
(a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type and a.file_syspk=b.file_syspk)
);
update transactional.IHT_noise_measurement_test a
set acceptance_criteria=b.acceptance_criteria,
remarks =b.remarks
from staging2.IHTNST_nst_oel_noise_load_block b
where b.column1 ='OEL Noise with Load' and test_type='OEL Noise with Load'
and b.block_row_number=1
and a.file_syspk=__file_syspk;
update transactional.IHT_noise_measurement_test a
set acceptance_criteria=b.acceptance_criteria,
remarks =b.remarks
from staging2.IHTNST_nst_oel_noise_block b
where b.column1 ='OEL Noise without Load'
and test_type='OEL Noise without Load'
and trx_record=1
and a.file_syspk=__file_syspk;
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
update transactional.test_instance
update transactional.test_instance
set test_master_id =__test_master_id,
test_tractor_id =__test_instance_tractor_id
where file_syspk=__file_syspk;
update transactional.test_instance_engine_info
set test_instance_id=__test_instance_id,
set
test_instance_id=__test_instance_id,
test_instance_tractor_id = __test_instance_tractor_id,
tractor_model =__model,
tractor_make=__make
where file_syspk=__file_syspk;
update transactional.test_instance_tyre_info
update transactional.test_instance_tyre_info
set test_instance_id=__test_instance_id,
test_instance_tractor_id = __test_instance_tractor_id,
tractor_model =__model,
tractor_make=__make
where file_syspk=__file_syspk;
update transactional.test_instance_tractor_info
update transactional.test_instance_tractor_info
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where file_syspk=__file_syspk;
update transactional.test_instance_atmospheric_info
update transactional.test_instance_atmospheric_info
set test_instance_id=__test_instance_id,
test_instance_tractor_id = __test_instance_tractor_id,
tractor_model =__model,
@@ -585,19 +606,31 @@ tractor_model =__model,
tractor_make=__make
where file_syspk=__file_syspk;
update transactional.IHT_noise_measurement_test
update transactional.IHT_noise_measurement_test
set test_instance_id=__test_instance_id,
test_instance_tractor_id = __test_instance_tractor_id,
tractor_model =__model,
tractor_make=__make
where file_syspk=__file_syspk;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTNST_NST_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
update transactional.test_instance
set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1)
where file_syspk = __file_syspk;
update transactional.test_instance
set test_type = a.test_type,
test_name= a.test_name
from fw_core.test_file_sheet_format_master a
where transactional.test_instance.file_sheet_mnemonic = a.file_sheet_mnemonic
and transactional.test_instance.file_syspk=__file_syspk;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic, __file_sheet_mnemonic ,null,'trx', 'fn_IHTNST_NST_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
end
$function$
;