and extract(year from a.napo_dt) = #{year}::numeric
and extract(month from a.napo_dt) = #{month}::numeric
select a.cds_key,
a.status,
a.napo_dt,
f.violationStr,
a.napo_sea_point_lon,
a.napo_sea_point_lat,
a.napo_sea_point_detail,
f.violationCode,
a.nll,
a.obstr_exspd_cnt ,
a.person_damage_cnt ,
a.person_damage_amount ,
a.person_damage_detail ,
a.material_damage_cnt ,
a.material_damage_amount ,
a.material_damage_detail ,
a.case_agency ,
a.crackdown_police ,
a.crackdown_boat ,
a.mmsi ,
c.boat_name_kr ,
c.ton_cnt ,
c.sailor_cnt,
c.boat_material ,
c.boat_nny_sung ,
c.boat_nny_si ,
d.sailor_name_kr as captainName,
d.birthdate as captainBirthDate,
c.fishery_type ,
c.catch_fish_species ,
c.catch_cnt ,
c.offense_type ,
c.offense_weight ,
c.offense_quantity ,
c.offense_amount ,
c.offense_illegal_waste_quantity ,
b.process_status ,
c.dambo_unpaid_amount ,
c.dambo_payment ,
c.payment_payment_dt ,
b.consignment_start_dt ,
b.consignment_end_dt ,
b.eviction_dt ,
b.direct_handover_dt ,
b.boat_disposal_type ,
b.exile_dt ,
b.return_dt ,
b.handover_sea_point_lon ,
b.handover_sea_point_lat ,
b.handover_sea_point_detail ,
b.handover_boat ,
b.middle_takeover_boat ,
b.confiscation_dt,
coalesce(e.captainRestriction, 0) as captainRestriction,
coalesce(e.navigaterRestriction, 0) as navigaterRestriction,
coalesce(e.engineerRestriction, 0) as engineerRestriction,
coalesce(e.ownerRestriction, 0) as ownerRestriction,
coalesce(e.seniorRestriction, 0) as seniorRestriction,
coalesce(e.normalRestriction, 0) as normalRestriction,
coalesce(e.captainRestrictionNot, 0) as captainRestrictionNot,
coalesce(e.navigaterRestrictionNot, 0) as navigaterRestrictionNot,
coalesce(e.engineerRestrictionNot, 0) as engineerRestrictionNot,
coalesce(e.ownerRestrictionNot, 0) as ownerRestrictionNot,
coalesce(e.seniorRestrictionNot, 0) as seniorRestrictionNot,
coalesce(e.normalRestrictionNot, 0) as normalRestrictionNot,
a.field_ivsgt,
b.release_dt ,
date_part('DAY', b.release_dt-a.napo_dt)||'일'||date_part('HOUR', b.release_dt-a.napo_dt)||'시간' as fieldIvsgtDayHour,
b.pressurized_time_taken ,
a.distance ,
b.warrant_req_take_time ,
c.confiscation_frame ,
c.confiscation_width ,
c.confiscation_jo ,
c.confiscation_gae ,
c.confiscation_etc,
a.wrt_organ,
a.wrt_part,
a.wrt_user_seq,
a.wrt_user_grd,
a.wrt_user_nm,
a.wrt_dt
from crackdown_status a
inner join process_result b
on a.cds_key = b.cds_key
inner join fishing_boat c
on a.cds_key = c.cds_key
left outer join sailor d
on c.fb_key = d.fb_key and d.position = 'POS001'
left outer join (
select fb_key,
sum(case when ab.item_cd = 'POS001' and is_restriction = 'Y' then 1 end) as captainRestriction,
sum(case when ab.item_cd = 'POS001' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as captainRestrictionNot,
sum(case when ab.item_cd = 'POS002' and is_restriction = 'Y' then 1 end) as navigaterRestriction,
sum(case when ab.item_cd = 'POS002' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as navigaterRestrictionNot,
sum(case when ab.item_cd = 'POS003' and is_restriction = 'Y' then 1 end) as engineerRestriction,
sum(case when ab.item_cd = 'POS003' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as engineerRestrictionNot,
sum(case when ab.item_cd = 'POS004' and is_restriction = 'Y' then 1 end) as ownerRestriction,
sum(case when ab.item_cd = 'POS004' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as ownerRestrictionNot,
sum(case when ab.item_cd = 'POS005' and is_restriction = 'Y' then 1 end) as seniorRestriction,
sum(case when ab.item_cd = 'POS005' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as seniorRestrictionNot,
sum(case when ab.item_cd = 'POS006' and is_restriction = 'Y' then 1 end) as normalRestriction,
sum(case when ab.item_cd = 'POS006' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as normalRestrictionNot
from sailor aa left outer join code_mgt ab on aa.position = ab.item_cd
group by fb_key
) e on c.fb_key = e.fb_key
left outer join (
select aa.fb_key,
array_to_string(array_agg(ab.item_value), ', ') as violationStr,
array_to_string(array_agg(ab.item_cd), ', ') as violationCode
from violation aa
inner join code_mgt ab
on aa.violation = ab.item_cd
group by aa.fb_key
) f on c.fb_key = f.fb_key
order by a.napo_dt desc
select count(*)
from crackdown_status a
inner join process_result b
on a.cds_key = b.cds_key
inner join fishing_boat c
on a.cds_key = c.cds_key
left outer join sailor d
on c.fb_key = d.fb_key and d.position = 'POS001'
left outer join (
select fb_key,
sum(case when ab.item_cd = 'POS001' and is_restriction = 'Y' then 1 end) as captainRestriction,
sum(case when ab.item_cd = 'POS001' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as captainRestrictionNot,
sum(case when ab.item_cd = 'POS002' and is_restriction = 'Y' then 1 end) as navigaterRestriction,
sum(case when ab.item_cd = 'POS002' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as navigaterRestrictionNot,
sum(case when ab.item_cd = 'POS003' and is_restriction = 'Y' then 1 end) as engineerRestriction,
sum(case when ab.item_cd = 'POS003' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as engineerRestrictionNot,
sum(case when ab.item_cd = 'POS004' and is_restriction = 'Y' then 1 end) as ownerRestriction,
sum(case when ab.item_cd = 'POS004' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as ownerRestrictionNot,
sum(case when ab.item_cd = 'POS005' and is_restriction = 'Y' then 1 end) as seniorRestriction,
sum(case when ab.item_cd = 'POS005' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as seniorRestrictionNot,
sum(case when ab.item_cd = 'POS006' and is_restriction = 'Y' then 1 end) as normalRestriction,
sum(case when ab.item_cd = 'POS006' and (is_restriction is null or is_restriction <> 'Y') then 1 end) as normalRestrictionNot
from sailor aa left outer join code_mgt ab on aa.position = ab.item_cd
group by fb_key, is_restriction
) e on c.fb_key = e.fb_key
left outer join (
select aa.fb_key,
array_to_string(array_agg(ab.item_value), ', ') as violationStr,
array_to_string(array_agg(ab.item_cd), ', ') as violationCode
from violation aa
inner join code_mgt ab
on aa.violation = ab.item_cd
group by aa.fb_key
) f on c.fb_key = f.fb_key
and extract(year from a.napo_dt) = ${year}
and a.case_agency = #{caseAgency}
and a.crackdown_police = #{crackdownPolice}
and a.crackdown_boat = #{crackdownBoat}
and b.boat_name_kr like '%'||#{boatNameKr}||'%'
and b.boat_nny_sung like '%'||#{boatNnySung}||'%'
and b.boat_nny_si like '%'||#{boatNnySi}||'%'
and b.boat_material = #{boatMaterial}
and b.fishery_type = #{fisheryType}
and c.process_status = #{processStatus}
and b.ton_cnt >= #{tonMin}
and b.ton_cnt <= #{tonMax}
and
e.violationCode like '%'||#{violation}||'%'
and a.napo_dt >= #{startDate}::date
and a.napo_dt <= #{endDate}::date+1
and c.eviction_dt >= #{startDate}::date
and c.eviction_dt <= #{endDate}::date+1
and c.direct_handover_dt >= #{startDate}::date
and c.direct_handover_dt <= #{endDate}::date+1
and c.consignment_dt >= #{startDate}::date
and c.consignment_dt <= #{endDate}::date+1
and c.confiscation_dt >= #{startDate}::date
and c.confiscation_dt <= #{endDate}::date+1
and c.boat_disposal_dt >= #{startDate}::date
and c.boat_disposal_dt <= #{endDate}::date+1
and c.return_dt >= #{startDate}::date
and c.return_dt <= #{endDate}::date+1
and a.wrt_dt >= #{startDate}::date
and a.wrt_dt <= #{endDate}::date+1
select a.cds_key,
a.napo_dt,
a.napo_sea_point_lon,
a.napo_sea_point_lat,
a.napo_sea_point_detail,
a.case_agency,
a.crackdown_police,
a.crackdown_boat,
b.boat_name_kr,
b.fishery_type,
b.boat_nny_sung,
b.boat_nny_si,
b.ton_cnt,
b.boat_material,
b.wrt_organ,
b.wrt_user_grd,
b.wrt_user_nm,
b.wrt_dt,
c.process_status,
d.sailor_name_kr,
e.violationStr
from crackdown_status a
inner join fishing_boat b
on a.cds_key = b.cds_key
inner join process_result c
on a.cds_key = c.cds_key
left outer join sailor d
on b.fb_key = d.fb_key and d.position = 'POS001'
left outer join (
select aa.fb_key,
array_to_string(array_agg(ab.item_value), ', ') as violationStr,
array_to_string(array_agg(ab.item_cd), ', ') as violationCode
from violation aa
inner join code_mgt ab
on aa.violation = ab.item_cd
group by aa.fb_key
) e on b.fb_key = e.fb_key
order by a.cds_key desc
limit #{rowCnt} offset #{firstIndex}
select count(*)
from crackdown_status a
inner join fishing_boat b
on a.cds_key = b.cds_key
inner join process_result c
on a.cds_key = c.cds_key
left outer join sailor d
on b.fb_key = d.fb_key and d.position = 'POS001'
left outer join (
select aa.fb_key,
array_to_string(array_agg(ab.item_value), ', ') as violationStr,
array_to_string(array_agg(ab.item_cd), ', ') as violationCode
from violation aa
inner join code_mgt ab
on aa.violation = ab.item_cd
group by aa.fb_key
) e on b.fb_key = e.fb_key
select distinct extract(year from napo_dt) as year
from crackdown_status
where napo_dt is not null
select cds_key,
version_no,
wrt_organ,
wrt_part,
wrt_user_grd,
wrt_user_nm,
wrt_dt
from crackdown_status_version
where cds_key = #{cds_key}
order by version_no desc