[BO] 임가현황 리스트, 상세 작업 중 (1)
This commit is contained in:
@@ -6,29 +6,172 @@
|
||||
|
||||
<select id="getHouseholdsStatus"
|
||||
resultType="app.module.admin.usecase.household.getHouseholdsStatus.ports.application.domain.GetHouseholdsStatus">
|
||||
/* getHouseholdsStatus : 임가현황 리스트 조회 */
|
||||
SELECT
|
||||
h.seq AS householdSeq,
|
||||
h.household_num AS householdNum,
|
||||
h.owner_name AS householdName,
|
||||
h.phone AS householdPhone,
|
||||
h.region_main_name AS regionMainName,
|
||||
h.region_sub_name AS regionSubName,
|
||||
h.region_detail_name AS regionDetailName,
|
||||
h.industry_large_name AS industryLargeName,
|
||||
h.industry_middle_name AS industryMiddleName,
|
||||
v.first_visit_date AS firstVisitDate,
|
||||
v.second_visit_date AS secondVisitDate,
|
||||
v.is_gift_sent 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
|
||||
LEFT JOIN v_household_researcher r ON h.seq = r.household_seq
|
||||
ORDER BY h.household_num asc
|
||||
/* 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
|
||||
),
|
||||
1
|
||||
) AS progress_percent
|
||||
) /* 일계부 입력 진행 완료 퍼센테이지 (이번달 작성 완료일 수 / 현재날짜 기준 전체 입력 가능 날짜 수) */
|
||||
|
||||
-- TODO : where 조건절 추가
|
||||
SELECT
|
||||
hvr.*,
|
||||
COUNT(*) OVER () AS total
|
||||
FROM (
|
||||
SELECT
|
||||
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
|
||||
FROM v_household_with_code h
|
||||
LEFT JOIN v_household_visit v ON h.seq = v.household_seq
|
||||
LEFT JOIN v_household_researcher r ON h.seq = r.household_seq
|
||||
CROSS JOIN record_progress ps
|
||||
) AS hvr
|
||||
|
||||
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
|
||||
<where>
|
||||
1=1
|
||||
|
||||
<if test="cmd.ownerField != null and cmd.ownerField != ''">
|
||||
/* 경영주 검색 */
|
||||
<choose>
|
||||
<when test="cmd.ownerField eq 'name'">
|
||||
AND hvr.householdName ILIKE '%' || #{cmd.ownerValue} || '%'
|
||||
</when>
|
||||
<when test="cmd.ownerField eq 'phone'">
|
||||
AND hvr.householdPhone ILIKE '%' || #{cmd.ownerValue} || '%'
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.researcherField != null and cmd.researcherField != ''">
|
||||
/* 조사원 검색 */
|
||||
<choose>
|
||||
<when test="cmd.researcherField eq 'name'">
|
||||
AND hvr.researcherName ILIKE '%' || #{cmd.researcherValue} || '%'
|
||||
</when>
|
||||
<when test="cmd.researcherField eq 'phone'">
|
||||
AND hvr.researcherPhone ILIKE '%' || #{cmd.researcherValue} || '%'
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.regionMainCode != null and cmd.regionMainCode != ''">
|
||||
/* 실사 검색 */
|
||||
AND hvr.regionMainCode = #{cmd.regionMainCode}
|
||||
</if>
|
||||
<if test="cmd.regionSubCode != null and cmd.regionSubCode != ''">
|
||||
/* 지역 검색 */
|
||||
AND hvr.regionSubCode = #{cmd.regionSubCode}
|
||||
</if>
|
||||
<if test="cmd.regionDetailCode != null and cmd.regionDetailCode != ''">
|
||||
/* 세부지역 검색 */
|
||||
AND hvr.regionDetailCode = #{cmd.regionDetailCode}
|
||||
</if>
|
||||
<if test="cmd.industryLargeCode != null and cmd.industryLargeCode != ''">
|
||||
/* 업종 대분류 검색 */
|
||||
AND hvr.industryLargeCode = #{cmd.industryLargeCode}
|
||||
</if>
|
||||
<if test="cmd.industryMiddleCode != null and cmd.industryMiddleCode != ''">
|
||||
/* 업종 중분류1 검색*/
|
||||
AND hvr.industryMiddleCode = #{cmd.industryMiddleCode}
|
||||
</if>
|
||||
|
||||
<if test="cmd.progressType != null and cmd.progressType != ''">
|
||||
/* 일계부 현황 퍼센테이지 검색 */
|
||||
<choose>
|
||||
<when test="cmd.progressType eq 'PROGRESS_25'">
|
||||
AND hvr.progressPercent < 25
|
||||
</when>
|
||||
<when test="cmd.progressType eq 'PROGRESS_50'">
|
||||
AND hvr.progressPercent >= 25 AND hvr.progressPercent < 50
|
||||
</when>
|
||||
<when test="cmd.progressType eq 'PROGRESS_75'">
|
||||
AND hvr.progressPercent >= 50 AND hvr.progressPercent < 75
|
||||
</when>
|
||||
<when test="cmd.progressType eq 'PROGRESS_75_UP'">
|
||||
AND hvr.progressPercent > 75
|
||||
</when>
|
||||
<when test="cmd.progressType eq 'PROGRESS_100'">
|
||||
AND hvr.progressPercent = 100
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.isFirstVisited != null">
|
||||
/* 당월 1차 방문 여부 */
|
||||
<choose>
|
||||
<when test="cmd.isFirstVisited">
|
||||
AND hvr.firstVisitDate is not null
|
||||
</when>
|
||||
<when test="!cmd.isFirstVisited">
|
||||
AND hvr.firstVisitDate is null
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.isSecondVisited != null">
|
||||
/* 당월 2차 방문 여부 */
|
||||
<choose>
|
||||
<when test="cmd.isSecondVisited">
|
||||
AND hvr.secondVisitDate is not null
|
||||
</when>
|
||||
<when test="!cmd.isSecondVisited">
|
||||
AND hvr.secondVisitDate is null
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.isGiftSent != null">
|
||||
/* 답례품 전달 여부 */
|
||||
<choose>
|
||||
<when test="cmd.isGiftSent">
|
||||
AND hvr.isGiftSent = true
|
||||
</when>
|
||||
<when test="!cmd.isGiftSent">
|
||||
AND hvr.isGiftSent = false
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<if test="cmd.isPanel != null">
|
||||
/* 패널 유지 여부 */
|
||||
<choose>
|
||||
<when test="cmd.isPanel">
|
||||
AND hvr.isPanel = true
|
||||
</when>
|
||||
<when test="!cmd.isPanel">
|
||||
AND hvr.isPanel = false
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</where>
|
||||
|
||||
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user