[BO] 임가현황 작업 중 (10)
This commit is contained in:
@@ -7,57 +7,77 @@
|
||||
<select id="getHouseholdsStatus"
|
||||
resultType="app.module.admin.usecase.household.getHouseholdsStatus.ports.application.domain.GetHouseholdsStatus">
|
||||
/* getHouseholdsStatus : 임가현황 리스트 조회 */
|
||||
WITH record_progress AS (
|
||||
SELECT ROUND(
|
||||
100.0 *
|
||||
(SELECT COUNT(*)
|
||||
FROM daily_record
|
||||
WHERE record_month = #{cmd.recordMonth} AND all_status = 'DONE')
|
||||
/ NULLIF(
|
||||
(SELECT COUNT(*)
|
||||
FROM daily_day_group
|
||||
WHERE end_day <= EXTRACT(DAY FROM CURRENT_DATE)), 0
|
||||
),
|
||||
2
|
||||
) AS progress_percent
|
||||
) /* 일계부 입력 진행 완료 퍼센테이지 (이번달 작성 완료일 수 / 현재날짜 기준 전체 입력 가능 날짜 수) */
|
||||
WITH daily_progress AS (
|
||||
/* 임가별 이번달 완료된 일 수 계산 */
|
||||
SELECT
|
||||
household_seq,
|
||||
COUNT(*) as completed_days
|
||||
FROM daily_record
|
||||
WHERE record_month = #{cmd.recordMonth}
|
||||
AND all_status IN ('DONE', 'TODAY_NONE')
|
||||
GROUP BY household_seq
|
||||
),
|
||||
total_days AS (
|
||||
/* 오늘 날짜 기준 전체 입력 가능 날짜 수 */
|
||||
SELECT COUNT(*) as total_possible_days
|
||||
FROM daily_day_group
|
||||
WHERE end_day <= EXTRACT(DAY FROM CURRENT_DATE)
|
||||
),
|
||||
visit_summary AS (
|
||||
/* 임가별 1차임가방문, 2차임가방문, 답례품전달여부 */
|
||||
SELECT
|
||||
rhh.household_seq,
|
||||
MIN(v.visit_date) AS first_visit_date,
|
||||
MAX(v.visit_date) AS second_visit_date,
|
||||
BOOL_OR(v.is_gift_sent) AS is_gift_sent
|
||||
FROM household_visit v
|
||||
JOIN researcher_has_household rhh ON v.household_seq = rhh.household_seq
|
||||
WHERE rhh.is_deleted = false
|
||||
AND TO_CHAR(v.visit_date, 'YYYYMM') = #{cmd.recordMonth}
|
||||
GROUP BY rhh.household_seq
|
||||
)
|
||||
SELECT
|
||||
hvr.*,
|
||||
COUNT(*) OVER () AS total
|
||||
FROM (
|
||||
SELECT
|
||||
r.admin_seq AS adminSeq,
|
||||
h.seq AS householdSeq,
|
||||
h.household_num AS householdNum,
|
||||
h.owner_name AS householdName,
|
||||
h.phone AS householdPhone,
|
||||
h.region_main_code AS regionMainCode,
|
||||
h.region_main_name AS regionMainName,
|
||||
h.region_sub_code AS regionSubCode,
|
||||
h.region_sub_name AS regionSubName,
|
||||
h.region_detail_code AS regionDetailCode,
|
||||
h.region_detail_name AS regionDetailName,
|
||||
h.industry_large_code as industryLargeCode,
|
||||
h.industry_large_name AS industryLargeName,
|
||||
h.industry_middle_code as industryMiddleCode,
|
||||
h.industry_middle_name AS industryMiddleName,
|
||||
h.is_panel AS isPanel,
|
||||
ps.progress_percent AS progressPercent,
|
||||
v.first_visit_date AS firstVisitDate,
|
||||
v.second_visit_date AS secondVisitDate,
|
||||
COALESCE(v.is_gift_sent, false) AS isGiftSent,
|
||||
r.researcher_name AS researcherName,
|
||||
r.researcher_phone AS researcherPhone
|
||||
r.admin_seq AS adminSeq,
|
||||
h.seq AS householdSeq,
|
||||
h.household_num AS householdNum,
|
||||
h.owner_name AS householdName,
|
||||
h.phone AS householdPhone,
|
||||
h.region_main_code AS regionMainCode,
|
||||
h.region_main_name AS regionMainName,
|
||||
h.region_sub_code AS regionSubCode,
|
||||
h.region_sub_name AS regionSubName,
|
||||
h.region_detail_code AS regionDetailCode,
|
||||
h.region_detail_name AS regionDetailName,
|
||||
h.industry_large_code AS industryLargeCode,
|
||||
h.industry_large_name AS industryLargeName,
|
||||
h.industry_middle_code AS industryMiddleCode,
|
||||
h.industry_middle_name AS industryMiddleName,
|
||||
h.is_panel AS isPanel,
|
||||
/* 일계부 입력 진행 완료 퍼센테이지 (이번달 작성 완료일 수 / 현재날짜 기준 전체 입력 가능 날짜 수) */
|
||||
ROUND(
|
||||
100.0 * COALESCE(dp.completed_days, 0) / NULLIF(td.total_possible_days, 0),
|
||||
2
|
||||
) AS progressPercent,
|
||||
vs.first_visit_date AS firstVisitDate,
|
||||
vs.second_visit_date AS secondVisitDate,
|
||||
COALESCE(vs.is_gift_sent, false) AS isGiftSent,
|
||||
r.researcher_name AS researcherName,
|
||||
r.researcher_phone AS researcherPhone
|
||||
FROM v_household_with_code h
|
||||
LEFT JOIN v_household_visit v ON h.seq = v.household_seq
|
||||
CROSS JOIN total_days td
|
||||
LEFT JOIN daily_progress dp ON h.seq = dp.household_seq
|
||||
LEFT JOIN visit_summary vs ON h.seq = vs.household_seq
|
||||
LEFT JOIN v_household_researcher r ON h.seq = r.household_seq
|
||||
CROSS JOIN record_progress ps
|
||||
) AS hvr
|
||||
|
||||
<where>
|
||||
1=1
|
||||
|
||||
<if test="cmd.ownerField != null and cmd.ownerField != ''">
|
||||
<if test="cmd.ownerField != null and cmd.ownerField != '' and cmd.ownerValue != ''">
|
||||
/* 경영주 검색 */
|
||||
<choose>
|
||||
<when test="cmd.ownerField eq 'name'">
|
||||
@@ -69,7 +89,7 @@
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.researcherField != null and cmd.researcherField != ''">
|
||||
<if test="cmd.researcherField != null and cmd.researcherField != '' and cmd.researcherValue != ''">
|
||||
/* 조사원 검색 */
|
||||
<choose>
|
||||
<when test="cmd.researcherField eq 'name'">
|
||||
|
||||
Reference in New Issue
Block a user