424 lines
20 KiB
XML
424 lines
20 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
<mapper
|
|
namespace="app.module.admin.usecase.household.excelDownload.getHouseholdsExcel.adapters.persistence.GetHouseholdsExcelMapper">
|
|
<select id="households"
|
|
resultType="app.module.admin.usecase.household.excelDownload.getHouseholdsExcel.ports.application.domain.GetHouseholds">
|
|
/* 엑셀 다운로드 - 임가 현황 (임가 목록) 조회 */
|
|
SELECT
|
|
vha.household_num
|
|
, vha.owner_name AS household_name
|
|
, vha.owner_age AS household_age
|
|
, vha.phone AS household_phone
|
|
, vha.region_main_code_text
|
|
, vha.region_sub_code_text
|
|
, vha.region_detail_code_text
|
|
, vha.address
|
|
, vha.industry_large_code_text
|
|
, vha.industry_middle_code_text
|
|
, vha.industry_sub_middle
|
|
, vha.industry_detail
|
|
, vha.researcher_name
|
|
, vha.researcher_phone
|
|
, CASE
|
|
WHEN vmcr.completion_rate = 0 THEN 0
|
|
ELSE ROUND(vmcr.completion_rate, 1)
|
|
END AS completion_rate
|
|
, vhvs.first_visit_date
|
|
, vhvs.second_visit_date
|
|
, CASE WHEN vhvs.gift_send = true THEN '전달' ELSE '' END AS gift_send
|
|
, vha.usage_type
|
|
, vha.is_panel
|
|
FROM v_household_all vha
|
|
LEFT OUTER JOIN v_household_visit_summary vhvs ON vha.seq = vhvs.household_seq and vhvs.visit_month = #{recordMonth}
|
|
LEFT OUTER JOIN v_monthly_completion_rate vmcr ON vha.seq = vmcr.household_seq and vmcr.record_month = #{recordMonth}
|
|
WHERE vha.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
ORDER BY vha.household_num ASC
|
|
</select>
|
|
|
|
<select id="dailyRecords"
|
|
resultType="app.module.admin.usecase.household.excelDownload.getHouseholdsExcel.ports.application.domain.GetDailyRecords">
|
|
/* 엑셀 다운로드 - 임가 현황 (02. 일계부 등록 현황) 조회 */
|
|
WITH data_counts AS (
|
|
SELECT
|
|
dr.id,
|
|
COUNT(DISTINCT di.id) AS income_cnt,
|
|
COUNT(DISTINCT dw.id) AS work_cnt,
|
|
COUNT(DISTINCT de.id) AS expense_cnt,
|
|
COUNT(DISTINCT dp.id) AS power_cnt,
|
|
COUNT(DISTINCT dfs.id) AS forestry_cnt,
|
|
COUNT(DISTINCT dfm.id) AS farming_cnt
|
|
FROM daily_record dr
|
|
LEFT JOIN daily_income di ON di.daily_record_seq = dr.id AND di.is_deleted = false
|
|
LEFT JOIN daily_work dw ON dw.daily_record_seq = dr.id AND dw.is_deleted = false
|
|
LEFT JOIN daily_expense de ON de.daily_record_seq = dr.id AND de.is_deleted = false
|
|
LEFT JOIN daily_power dp ON dp.daily_record_seq = dr.id AND dp.is_deleted = false
|
|
LEFT JOIN daily_forestry dfs ON dfs.daily_record_seq = dr.id AND dfs.is_deleted = false
|
|
LEFT JOIN daily_farming dfm ON dfm.daily_record_seq = dr.id AND dfm.is_deleted = false
|
|
WHERE dr.record_month = #{recordMonth}
|
|
AND dr.is_deleted = false
|
|
GROUP BY dr.id
|
|
),
|
|
month_check AS (
|
|
SELECT
|
|
#{recordMonth} = TO_CHAR(CURRENT_DATE, 'YYYYMM') AS is_current_month,
|
|
EXTRACT(DAY FROM (TO_DATE(#{recordMonth}, 'YYYYMM') + INTERVAL '1 MONTH - 1 day')) AS month_last_day
|
|
)
|
|
SELECT
|
|
h.seq,
|
|
h.household_num,
|
|
h.owner_name,
|
|
h.owner_age,
|
|
h.phone AS householdPhone,
|
|
h.region_main_code_text,
|
|
h.region_sub_code_text,
|
|
h.region_detail_code_text,
|
|
h.researcher_name,
|
|
h.researcher_phone,
|
|
ddg.group_no AS day_group_no,
|
|
ddg.start_day ||
|
|
CASE
|
|
WHEN ddg.start_day = LEAST(ddg.end_day, mc.month_last_day) THEN ''
|
|
ELSE '-' || LEAST(ddg.end_day, mc.month_last_day)
|
|
END AS day_group,
|
|
ddg.start_day AS start_day,
|
|
CASE
|
|
WHEN ddg.start_day = LEAST(ddg.end_day, mc.month_last_day) THEN ''
|
|
ELSE LEAST(ddg.end_day, mc.month_last_day)::TEXT
|
|
END AS end_day,
|
|
CASE
|
|
WHEN mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE) THEN 'WAITING'
|
|
WHEN dr.all_status IN ('DONE', 'TODAY_NONE') THEN 'DONE'
|
|
WHEN dr.all_status = 'WAITING' THEN 'INCOMPLETE'
|
|
ELSE 'EMPTY'
|
|
END AS all_status_type,
|
|
fn_get_status(mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE), dr.income_status, dc.income_cnt) AS income_status,
|
|
fn_get_status(mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE), dr.work_status, dc.work_cnt) AS work_status,
|
|
fn_get_status(mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE), dr.expense_status, dc.expense_cnt) AS expense_status,
|
|
fn_get_status(mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE), dr.power_status, dc.power_cnt) AS power_status,
|
|
fn_get_status(mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE), dr.forestry_status, dc.forestry_cnt) AS forestry_status,
|
|
fn_get_farming_status(
|
|
ddg.start_day,
|
|
dr.record_month,
|
|
mc.is_current_month AND ddg.start_day > EXTRACT(DAY FROM CURRENT_DATE),
|
|
dr.farming_status,
|
|
dc.farming_cnt
|
|
) AS farming_status
|
|
FROM v_household_all h
|
|
CROSS JOIN daily_day_group ddg
|
|
CROSS JOIN month_check mc
|
|
LEFT JOIN daily_record dr ON dr.day_group_no = ddg.group_no
|
|
AND dr.household_seq = h.seq
|
|
AND dr.record_month = #{recordMonth}
|
|
AND dr.is_deleted = false
|
|
LEFT JOIN data_counts dc ON dc.id = dr.id
|
|
WHERE ddg.start_day <= mc.month_last_day
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
ORDER by h.household_num, ddg.start_day
|
|
</select>
|
|
|
|
<select id="visitInfos"
|
|
resultType="app.module.admin.usecase.household.excelDownload.getHouseholdsExcel.ports.application.domain.GetVisitInfos">
|
|
/* 엑셀 다운로드 - 임가 현황 (03. 임가방문정보) 조회 */
|
|
SELECT household_num,
|
|
owner_name,
|
|
owner_age,
|
|
phone AS household_phone,
|
|
region_main_code_text,
|
|
region_sub_code_text,
|
|
region_detail_code_text,
|
|
researcher_name,
|
|
researcher_phone,
|
|
visit_date,
|
|
management_type,
|
|
content,
|
|
is_gift_sent,
|
|
updated_by,
|
|
TO_CHAR(created_at, 'YYYY-MM-DD HH24:MI') AS created_at
|
|
FROM v_household_all_visit
|
|
WHERE visit_month = #{recordMonth}
|
|
AND seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
ORDER BY household_num
|
|
</select>
|
|
|
|
<select id="forestProductsExcel"
|
|
resultType="app.module.admin.usecase.household.excelDownload.getHouseholdsExcel.ports.application.domain.GetForestProducts">
|
|
/* 엑셀 다운로드 - 일계부 등록데이터 ( 1.임산물현황 ) 조회 */
|
|
WITH unit_codes AS (
|
|
SELECT id, code_value
|
|
FROM uicode
|
|
WHERE parent_id = 'code.record.unit'
|
|
AND is_deleted = false
|
|
)
|
|
SELECT
|
|
h.household_num,
|
|
h.owner_name,
|
|
fp.street_num,
|
|
fp.land_type,
|
|
fp.town,
|
|
fp.available_area,
|
|
fp.crop_name,
|
|
fp.crop_code,
|
|
fp.land_area,
|
|
fp.main_yield,
|
|
CASE WHEN fp.main_yield_unit_code = 'code.record.unit.self' THEN fp.main_yield_unit
|
|
ELSE (select code_value from unit_codes where id = fp.main_yield_unit_code) END AS main_yield_unit_code_name,
|
|
fp.main_sale_amount,
|
|
CASE WHEN fp.main_sale_unit_code = 'code.record.unit.self' THEN fp.main_sale_unit
|
|
ELSE (select code_value from unit_codes where id = fp.main_sale_unit_code) END AS main_sale_unit_code_name,
|
|
fp.sub_yield,
|
|
CASE WHEN fp.sub_yield_unit_code = 'code.record.unit.self' THEN fp.sub_yield_unit
|
|
ELSE (select code_value from unit_codes where id = fp.sub_yield_unit_code) END AS sub_yield_unit_code_name,
|
|
fp.sub_sale_amount ,
|
|
CASE WHEN fp.sub_sale_unit_code = 'code.record.unit.self' THEN fp.sub_sale_unit
|
|
ELSE (select code_value from unit_codes where id = fp.sub_sale_unit_code) END AS sub_sale_unit_code_name
|
|
FROM forest_product fp
|
|
JOIN household h on fp.household_seq = h.seq and h.is_deleted = false
|
|
WHERE fp.is_deleted = false
|
|
AND fp.month = #{recordMonth}
|
|
AND fp.household_seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
ORDER BY household_num
|
|
</select>
|
|
|
|
<select id="bankAutoTransfersExcel"
|
|
resultType="app.module.admin.usecase.household.excelDownload.getHouseholdsExcel.ports.application.domain.GetBankAutoTransfers">
|
|
/* 엑셀 다운로드 - 일계부 등록데이터 ( 2.자동이체_수입(지출) ) 조회 */
|
|
WITH category_codes AS (
|
|
SELECT id, code_text
|
|
FROM uicode
|
|
WHERE (parent_id = 'code.bank.input' OR parent_id = 'code.bank.output')
|
|
AND is_deleted = false
|
|
)
|
|
SELECT
|
|
h.household_num,
|
|
h.owner_name,
|
|
transfer_type.code_text as transfer_type_name,
|
|
bat.income_code,
|
|
bat.expense_code,
|
|
split_part( bat.crop_code,'code.record.crop.',2 ) as crop_code,
|
|
case when bat.transfer_category_code = 'code.bank.input.self' OR bat.transfer_category_code = 'code.bank.output.self' THEN bat.transfer_category
|
|
else (select code_text from category_codes where id = bat.transfer_category_code) END AS transfer_category_code_name,
|
|
bat.source_purpose,
|
|
bat.count,
|
|
case when bat.unit_code = 'code.count.unit.self' then bat.unit
|
|
else unit_code.code_text end as unit_code_name,
|
|
bat.price
|
|
FROM bank_auto_transfer bat
|
|
JOIN household h on bat.household_seq = h.seq and h.is_deleted = false
|
|
LEFT JOIN uicode transfer_type on transfer_type.parent_id = 'code.bank' and transfer_type.id = bat.transfer_type
|
|
LEFT JOIN uicode unit_code on unit_code.parent_id = 'code.count.unit' and unit_code.id = bat.unit_code and unit_code.is_deleted = false
|
|
WHERE bat.is_deleted = false
|
|
AND bat.month = #{recordMonth}
|
|
AND bat.household_seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
ORDER BY household_num
|
|
</select>
|
|
|
|
<select id="carryOversExcel">
|
|
select
|
|
h.household_num,
|
|
h.owner_name,
|
|
ds.carry_over
|
|
from daily_summary ds
|
|
JOIN household h on ds.household_seq = h.seq and h.is_deleted = false
|
|
where ds.record_month = #{recordMonth}
|
|
AND ds.household_seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
order by household_num desc
|
|
</select>
|
|
|
|
<select id="dailyIncomeExpensesExcel">
|
|
select
|
|
h.household_num,
|
|
h.owner_name,
|
|
dg.start_day ,
|
|
case when dg.start_day = dg.end_day then null else dg.end_day end as end_day ,
|
|
di.category ,
|
|
di.income_mark ,
|
|
di.expense_mark ,
|
|
split_part( di.crop_code,'code.record.crop.',2 ) as crop_code,
|
|
di.income_kind as kind,
|
|
di.source_purpose ,
|
|
di.quantity,
|
|
unit_code.code_text as unit_code_name ,
|
|
di.price,
|
|
di.estimated_value
|
|
from household h
|
|
join daily_record dr on h.seq = dr.household_seq and dr.is_deleted = false
|
|
left join daily_day_group dg on dg.group_no = dr.day_group_no and dg.is_deleted = false
|
|
join daily_income di on dr.id = di.daily_record_seq and di.is_deleted = false
|
|
left join uicode unit_code on unit_code.parent_id = 'code.record.unit' and unit_code.id = di.unit_code and unit_code.is_deleted = false
|
|
where h.is_deleted = false
|
|
AND dr.record_month = #{recordMonth}
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
union all
|
|
select
|
|
h.household_num,
|
|
h.owner_name,
|
|
dg.start_day ,
|
|
case when dg.start_day = dg.end_day then null else dg.end_day end as end_day ,
|
|
de.category ,
|
|
de.income_mark ,
|
|
de.expense_mark ,
|
|
null as crop_code,
|
|
de.expense_kind as kind,
|
|
de.source_purpose ,
|
|
de.quantity,
|
|
unit_code.code_text as unit_code_name ,
|
|
de.price,
|
|
de.estimated_value
|
|
from household h
|
|
join daily_record dr on h.seq = dr.household_seq and dr.is_deleted = false
|
|
left join daily_day_group dg on dg.group_no = dr.day_group_no and dg.is_deleted = false
|
|
join daily_expense de on dr.id = de.daily_record_seq and de.is_deleted = false
|
|
left join uicode unit_code on unit_code.parent_id = 'code.record.unit' and unit_code.id = de.unit_code and unit_code.is_deleted = false
|
|
where h.is_deleted = false
|
|
AND dr.record_month = #{recordMonth}
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
order by household_num
|
|
</select>
|
|
|
|
<select id="dailyWorksExcel">
|
|
select
|
|
h.household_num ,
|
|
h.owner_name ,
|
|
dg.start_day ,
|
|
case when dg.start_day = dg.end_day then null else dg.end_day end as end_day ,
|
|
dw.item_name ,
|
|
dw.item_mark ,
|
|
dw.work_name ,
|
|
dw.work_mark ,
|
|
dw.work_land_area ,
|
|
case when dw.area_unit_code = 'code.record.area.self' then dw.area_unit_self
|
|
else unit_code.code_value end as area_unit_name,
|
|
dw.harvest_quantity ,
|
|
case when dw.harvest_unit_code = 'code.record.unit.self' then dw.harvest_unit_self
|
|
else unit_code.code_value end as harvest_unit_name,
|
|
dw.owner_time ,
|
|
dw.spouse_time ,
|
|
dw.family_m_hours ,
|
|
dw.family_f_hours ,
|
|
dw.hired_m_hours ,
|
|
dw.hired_f_hours ,
|
|
dw.shared_m_hours,
|
|
dw.shared_f_hours,
|
|
dw.volunteer_m_hours ,
|
|
dw.volunteer_f_hours
|
|
from household h
|
|
join daily_record dr on h.seq = dr.household_seq and dr.is_deleted = false
|
|
left join daily_day_group dg on dg.group_no = dr.day_group_no and dg.is_deleted = false
|
|
join daily_work dw on dw.daily_record_seq = dr.id and dw.is_deleted = false
|
|
left join uicode area_code on area_code.parent_id = 'code.record.area' and area_code.id = dw.area_unit_code
|
|
left join uicode unit_code on unit_code.parent_id = 'code.record.unit' and unit_code.id = dw.harvest_unit_code and unit_code.is_deleted = false
|
|
where h.is_deleted = false
|
|
AND dr.record_month = #{recordMonth}
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
order by household_num
|
|
</select>
|
|
|
|
<select id="dailyPowersExcel">
|
|
select
|
|
h.household_num ,
|
|
h.owner_name ,
|
|
dg.start_day ,
|
|
case when dg.start_day = dg.end_day then null else dg.end_day end as end_day ,
|
|
dp.equipment_name ,
|
|
dp.equipment_mark ,
|
|
dp.owned_hours ,
|
|
dp.leased_hours
|
|
from household h
|
|
join daily_record dr on h.seq = dr.household_seq and dr.is_deleted = false
|
|
left join daily_day_group dg on dg.group_no = dr.day_group_no and dg.is_deleted = false
|
|
join daily_power dp on dp.daily_record_seq = dr.id and dp.is_deleted = false
|
|
where h.is_deleted = false
|
|
AND dr.record_month = #{recordMonth}
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
order by household_num
|
|
</select>
|
|
|
|
<select id="dailyForestryExcel">
|
|
select
|
|
h.household_num ,
|
|
h.owner_name ,
|
|
extract(week from dr.start_date) - extract(week from DATE_TRUNC('month', dr.start_date)) + 1 AS week_of_month,
|
|
df.income_mark,
|
|
df.expense_mark,
|
|
df.product_name,
|
|
df."usage",
|
|
df.quantity,
|
|
case when df.unit_code = 'code.record.unit.self' then df.unit_self
|
|
else unit_code.code_value end as unit_name,
|
|
df.estimated_value
|
|
from household h
|
|
join daily_record dr on h.seq = dr.household_seq and dr.is_deleted = false
|
|
left join daily_day_group dg on dg.group_no = dr.day_group_no and dg.is_deleted = false
|
|
join daily_forestry df on df.daily_record_seq = dr.id and df.is_deleted = false
|
|
left join uicode unit_code on unit_code.parent_id = 'code.record.unit' and unit_code.id = df.unit_code
|
|
where h.is_deleted = false
|
|
AND dr.record_month = #{recordMonth}
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
order by household_num
|
|
</select>
|
|
|
|
<select id="dailyFarmingsExcel">
|
|
select
|
|
h.household_num ,
|
|
h.owner_name ,
|
|
dg.start_day ,
|
|
case when dg.start_day = dg.end_day then null else dg.end_day end as end_day ,
|
|
df.income_mark ,
|
|
df.expense_mark ,
|
|
case when df.product_code = 'code.record.farming.self' then df.product_self
|
|
else product_code.code_text end as product_name ,
|
|
df."usage" ,
|
|
df.quantity ,
|
|
case when df.unit_code = 'code.record.unit.self' then df.unit_self
|
|
else unit_code.code_value end as unit_name,
|
|
df.estimated_value
|
|
from household h
|
|
join daily_record dr on h.seq = dr.household_seq and dr.is_deleted = false
|
|
left join daily_day_group dg on dg.group_no = dr.day_group_no and dg.is_deleted = false
|
|
join daily_farming df on df.daily_record_seq = dr.id and df.is_deleted = false
|
|
left join uicode product_code on product_code.parent_id = 'code.record.farming' and product_code.id = df.product_code
|
|
left join uicode unit_code on unit_code.parent_id = 'code.record.unit' and unit_code.id = df.unit_code
|
|
where h.is_deleted = false
|
|
AND dr.record_month = #{recordMonth}
|
|
AND h.seq IN
|
|
<foreach collection="householdSeqs" item="seq" open="(" separator="," close=")">
|
|
#{seq}
|
|
</foreach>
|
|
order by household_num
|
|
</select>
|
|
</mapper> |