Skip to content

Commit

Permalink
fix(SILVA-584): fixing queries
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Dec 5, 2024
1 parent 59b1d87 commit 464d660
Showing 1 changed file with 123 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,26 @@ WHERE raac.RESULTS_AUDIT_ACTION_CODE IN (?1)
submitted_to_frpa108
FROM (
SELECT
o.OPENING_ID AS opening_id,
o.OPENING_NUMBER AS opening_number,
o.OPEN_CATEGORY_CODE AS category,
o.OPENING_STATUS_CODE AS status,
cboa.CUTTING_PERMIT_ID AS cutting_permit_id,
cboa.TIMBER_MARK AS timber_mark,
cboa.CUT_BLOCK_ID AS cut_block_id,
cboa.OPENING_GROSS_AREA AS opening_gross_area,
cboa.DISTURBANCE_START_DATE AS disturbance_start_date,
cboa.FOREST_FILE_ID AS forest_file_id,
ou.ORG_UNIT_CODE AS org_unit_code,
ou.ORG_UNIT_NAME AS org_unit_name,
res.CLIENT_NUMBER AS client_number,
res.CLIENT_LOCN_CODE AS client_location,
ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12)) AS regen_delay_date,
ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12)) AS early_free_growing_date,
ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12)) AS late_free_growing_date,
o.UPDATE_TIMESTAMP AS update_timestamp,
o.ENTRY_USERID AS entry_user_id,
COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0) AS submitted_to_frpa108,
ROW_NUMBER() OVER (PARTITION BY o.OPENING_ID ORDER BY o.UPDATE_TIMESTAMP DESC) AS rn
o.OPENING_ID AS opening_id,
MAX(o.OPENING_NUMBER) AS opening_number,
MAX(o.OPEN_CATEGORY_CODE) AS category,
MAX(o.OPENING_STATUS_CODE) AS status,
MAX(cboa.CUTTING_PERMIT_ID) AS cutting_permit_id,
MAX(cboa.TIMBER_MARK) AS timber_mark,
MAX(cboa.CUT_BLOCK_ID) AS cut_block_id,
MAX(cboa.OPENING_GROSS_AREA) AS opening_gross_area,
MAX(cboa.DISTURBANCE_START_DATE) AS disturbance_start_date,
MAX(cboa.FOREST_FILE_ID) AS forest_file_id,
MAX(ou.ORG_UNIT_CODE) AS org_unit_code,
MAX(ou.ORG_UNIT_NAME) AS org_unit_name,
MAX(res.CLIENT_NUMBER) AS client_number,
MAX(res.CLIENT_LOCN_CODE) AS client_location,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12))) AS regen_delay_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12))) AS early_free_growing_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12))) AS late_free_growing_date,
MAX(o.UPDATE_TIMESTAMP) AS update_timestamp,
MAX(o.ENTRY_USERID) AS entry_user_id,
MAX(COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0)) AS submitted_to_frpa108
FROM THE.OPENING o
LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)
Expand All @@ -147,8 +146,9 @@ LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (sra.ACTIVITY_TREATMENT_UNIT_ID = a
LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.STOCKING_MILESTONE smrg ON (smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG')
LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG')
GROUP BY o.OPENING_ID
)
WHERE rn = 1 AND (
WHERE (
NVL(:#{#filter.mainSearchTerm},'NOVALUE') = 'NOVALUE' OR (
REGEXP_LIKE(:#{#filter.mainSearchTerm}, '^\\d+$')
AND OPENING_ID = TO_NUMBER(:#{#filter.mainSearchTerm})
Expand Down Expand Up @@ -212,17 +212,41 @@ LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.S
NVL(:#{#filter.clientLocationCode},'NOVALUE') = 'NOVALUE' OR client_location = :#{#filter.clientLocationCode}
)""",
countQuery = """
SELECT count(o.OPENING_ID) as total
FROM THE.OPENING o
LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)
LEFT JOIN THE.RESULTS_ELECTRONIC_SUBMISSION res ON (res.RESULTS_SUBMISSION_ID = o.RESULTS_SUBMISSION_ID)
LEFT JOIN THE.ACTIVITY_TREATMENT_UNIT atu ON atu.OPENING_ID = o.OPENING_ID
LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (sra.ACTIVITY_TREATMENT_UNIT_ID = atu.ACTIVITY_TREATMENT_UNIT_ID AND sra.SILV_RELIEF_APPL_STATUS_CODE = 'APP')
LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.STOCKING_MILESTONE smrg ON (smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG')
LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG')
WHERE (
SELECT count(opening_id) as total
FROM (
SELECT
o.OPENING_ID AS opening_id,
MAX(o.OPENING_NUMBER) AS opening_number,
MAX(o.OPEN_CATEGORY_CODE) AS category,
MAX(o.OPENING_STATUS_CODE) AS status,
MAX(cboa.CUTTING_PERMIT_ID) AS cutting_permit_id,
MAX(cboa.TIMBER_MARK) AS timber_mark,
MAX(cboa.CUT_BLOCK_ID) AS cut_block_id,
MAX(cboa.OPENING_GROSS_AREA) AS opening_gross_area,
MAX(cboa.DISTURBANCE_START_DATE) AS disturbance_start_date,
MAX(cboa.FOREST_FILE_ID) AS forest_file_id,
MAX(ou.ORG_UNIT_CODE) AS org_unit_code,
MAX(ou.ORG_UNIT_NAME) AS org_unit_name,
MAX(res.CLIENT_NUMBER) AS client_number,
MAX(res.CLIENT_LOCN_CODE) AS client_location,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12))) AS regen_delay_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12))) AS early_free_growing_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12))) AS late_free_growing_date,
MAX(o.UPDATE_TIMESTAMP) AS update_timestamp,
MAX(o.ENTRY_USERID) AS entry_user_id,
MAX(COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0)) AS submitted_to_frpa108
FROM THE.OPENING o
LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)
LEFT JOIN THE.RESULTS_ELECTRONIC_SUBMISSION res ON (res.RESULTS_SUBMISSION_ID = o.RESULTS_SUBMISSION_ID)
LEFT JOIN THE.ACTIVITY_TREATMENT_UNIT atu ON atu.OPENING_ID = o.OPENING_ID
LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (sra.ACTIVITY_TREATMENT_UNIT_ID = atu.ACTIVITY_TREATMENT_UNIT_ID AND sra.SILV_RELIEF_APPL_STATUS_CODE = 'APP')
LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.STOCKING_MILESTONE smrg ON (smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG')
LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG')
GROUP BY o.OPENING_ID
)
WHERE (
NVL(:#{#filter.mainSearchTerm},'NOVALUE') = 'NOVALUE' OR (
REGEXP_LIKE(:#{#filter.mainSearchTerm}, '^\\d+$')
AND o.OPENING_ID = TO_NUMBER(:#{#filter.mainSearchTerm})
Expand Down Expand Up @@ -294,34 +318,33 @@ Page<SilvicultureSearchProjection> searchBy(

@Query(
value = """
SELECT opening_id, opening_number, category, status, cutting_permit_id, timber_mark,\s
cut_block_id, opening_gross_area, disturbance_start_date, forest_file_id,\s
org_unit_code, org_unit_name, client_number, client_location, regen_delay_date,\s
early_free_growing_date, late_free_growing_date, update_timestamp, entry_user_id,\s
SELECT opening_id, opening_number, category, status, cutting_permit_id, timber_mark,
cut_block_id, opening_gross_area, disturbance_start_date, forest_file_id,
org_unit_code, org_unit_name, client_number, client_location, regen_delay_date,
early_free_growing_date, late_free_growing_date, update_timestamp, entry_user_id,
submitted_to_frpa108
FROM (
SELECT
o.OPENING_ID AS opening_id,
o.OPENING_NUMBER AS opening_number,
o.OPEN_CATEGORY_CODE AS category,
o.OPENING_STATUS_CODE AS status,
cboa.CUTTING_PERMIT_ID AS cutting_permit_id,
cboa.TIMBER_MARK AS timber_mark,
cboa.CUT_BLOCK_ID AS cut_block_id,
cboa.OPENING_GROSS_AREA AS opening_gross_area,
cboa.DISTURBANCE_START_DATE AS disturbance_start_date,
cboa.FOREST_FILE_ID AS forest_file_id,
ou.ORG_UNIT_CODE AS org_unit_code,
ou.ORG_UNIT_NAME AS org_unit_name,
res.CLIENT_NUMBER AS client_number,
res.CLIENT_LOCN_CODE AS client_location,
ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12)) AS regen_delay_date,
ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12)) AS early_free_growing_date,
ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12)) AS late_free_growing_date,
o.UPDATE_TIMESTAMP AS update_timestamp,
o.ENTRY_USERID AS entry_user_id,
COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0) AS submitted_to_frpa108,
ROW_NUMBER() OVER (PARTITION BY o.OPENING_ID ORDER BY o.UPDATE_TIMESTAMP DESC) AS rn
o.OPENING_ID AS opening_id,
MAX(o.OPENING_NUMBER) AS opening_number,
MAX(o.OPEN_CATEGORY_CODE) AS category,
MAX(o.OPENING_STATUS_CODE) AS status,
MAX(cboa.CUTTING_PERMIT_ID) AS cutting_permit_id,
MAX(cboa.TIMBER_MARK) AS timber_mark,
MAX(cboa.CUT_BLOCK_ID) AS cut_block_id,
MAX(cboa.OPENING_GROSS_AREA) AS opening_gross_area,
MAX(cboa.DISTURBANCE_START_DATE) AS disturbance_start_date,
MAX(cboa.FOREST_FILE_ID) AS forest_file_id,
MAX(ou.ORG_UNIT_CODE) AS org_unit_code,
MAX(ou.ORG_UNIT_NAME) AS org_unit_name,
MAX(res.CLIENT_NUMBER) AS client_number,
MAX(res.CLIENT_LOCN_CODE) AS client_location,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12))) AS regen_delay_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12))) AS early_free_growing_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12))) AS late_free_growing_date,
MAX(o.UPDATE_TIMESTAMP) AS update_timestamp,
MAX(o.ENTRY_USERID) AS entry_user_id,
MAX(COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0)) AS submitted_to_frpa108
FROM THE.OPENING o
LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)
Expand All @@ -331,20 +354,50 @@ LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (sra.ACTIVITY_TREATMENT_UNIT_ID = a
LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.STOCKING_MILESTONE smrg ON (smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG')
LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG')
GROUP BY o.OPENING_ID
)
WHERE rn = 1 AND OPENING_ID IN :openingIds""",
WHERE OPENING_ID IN :openingIds""",
countQuery = """
SELECT count(o.OPENING_ID) as total
FROM THE.OPENING o
LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)
LEFT JOIN THE.RESULTS_ELECTRONIC_SUBMISSION res ON (res.RESULTS_SUBMISSION_ID = o.RESULTS_SUBMISSION_ID)
LEFT JOIN THE.ACTIVITY_TREATMENT_UNIT atu ON atu.OPENING_ID = o.OPENING_ID
LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (sra.ACTIVITY_TREATMENT_UNIT_ID = atu.ACTIVITY_TREATMENT_UNIT_ID AND sra.SILV_RELIEF_APPL_STATUS_CODE = 'APP')
LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.STOCKING_MILESTONE smrg ON (smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG')
LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG')
WHERE o.OPENING_ID IN :openingIds""",
SELECT count(opening_id) as total
SELECT opening_id, opening_number, category, status, cutting_permit_id, timber_mark,
cut_block_id, opening_gross_area, disturbance_start_date, forest_file_id,
org_unit_code, org_unit_name, client_number, client_location, regen_delay_date,
early_free_growing_date, late_free_growing_date, update_timestamp, entry_user_id,
submitted_to_frpa108
FROM (
SELECT
o.OPENING_ID AS opening_id,
MAX(o.OPENING_NUMBER) AS opening_number,
MAX(o.OPEN_CATEGORY_CODE) AS category,
MAX(o.OPENING_STATUS_CODE) AS status,
MAX(cboa.CUTTING_PERMIT_ID) AS cutting_permit_id,
MAX(cboa.TIMBER_MARK) AS timber_mark,
MAX(cboa.CUT_BLOCK_ID) AS cut_block_id,
MAX(cboa.OPENING_GROSS_AREA) AS opening_gross_area,
MAX(cboa.DISTURBANCE_START_DATE) AS disturbance_start_date,
MAX(cboa.FOREST_FILE_ID) AS forest_file_id,
MAX(ou.ORG_UNIT_CODE) AS org_unit_code,
MAX(ou.ORG_UNIT_NAME) AS org_unit_name,
MAX(res.CLIENT_NUMBER) AS client_number,
MAX(res.CLIENT_LOCN_CODE) AS client_location,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12))) AS regen_delay_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12))) AS early_free_growing_date,
MAX(ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12))) AS late_free_growing_date,
MAX(o.UPDATE_TIMESTAMP) AS update_timestamp,
MAX(o.ENTRY_USERID) AS entry_user_id,
MAX(COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0)) AS submitted_to_frpa108
FROM THE.OPENING o
LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)
LEFT JOIN THE.RESULTS_ELECTRONIC_SUBMISSION res ON (res.RESULTS_SUBMISSION_ID = o.RESULTS_SUBMISSION_ID)
LEFT JOIN THE.ACTIVITY_TREATMENT_UNIT atu ON atu.OPENING_ID = o.OPENING_ID
LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (sra.ACTIVITY_TREATMENT_UNIT_ID = atu.ACTIVITY_TREATMENT_UNIT_ID AND sra.SILV_RELIEF_APPL_STATUS_CODE = 'APP')
LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID)
LEFT JOIN THE.STOCKING_MILESTONE smrg ON (smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG')
LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG')
GROUP BY o.OPENING_ID
)
WHERE opening_id IN :openingIds""",
nativeQuery = true
)
Page<SilvicultureSearchProjection> searchByOpeningIds(
Expand Down

0 comments on commit 464d660

Please sign in to comment.