쿼리 간소화 및 정리

dev
박성영 1 month ago
parent d23ec8b47e
commit bff4091e91

@ -3,6 +3,127 @@
<mapper namespace="go.kr.project.crdn.crndRegistAndView.main.mapper.CrdnRegistAndViewMapper">
<!-- 공통 검색 조건 - 기본 (날짜 제외) -->
<sql id="searchConditionsBasic">
<if test='schCrdnYr != null and schCrdnYr != ""'>
AND c.CRDN_YR = #{schCrdnYr}
</if>
<if test='schCrdnNo != null and schCrdnNo != ""'>
AND c.CRDN_NO LIKE CONCAT('%', #{schCrdnNo}, '%')
</if>
<if test='schStdgEmdCd != null and schStdgEmdCd.size() > 0'>
AND p.STDG_EMD_CD IN
<foreach collection="schStdgEmdCd" item="emdCd" open="(" separator="," close=")">
#{emdCd}
</foreach>
</if>
<if test='schRgnSeCd != null and schRgnSeCd != ""'>
AND c.RGN_SE_CD = #{schRgnSeCd}
</if>
<if test='schDsclMthdCd != null and schDsclMthdCd != ""'>
AND c.DSCL_MTHD_CD = #{schDsclMthdCd}
</if>
<if test='schExmnr != null and schExmnr != ""'>
AND c.EXMNR LIKE CONCAT('%', #{schExmnr}, '%')
</if>
<if test='schCrdnPrcsSttsCd != null and schCrdnPrcsSttsCd != ""'>
AND c.CRDN_PRCS_STTS_CD = #{schCrdnPrcsSttsCd}
</if>
<if test='schAgrvtnLevyTrgtYn != null and schAgrvtnLevyTrgtYn != ""'>
AND c.AGRVTN_LEVY_TRGT_YN = #{schAgrvtnLevyTrgtYn}
</if>
<if test='schZip != null and schZip != ""'>
AND p.ZIP LIKE CONCAT('%', #{schZip}, '%')
</if>
<if test='schLotnoAddr != null and schLotnoAddr != ""'>
AND p.LOTNO_ADDR LIKE CONCAT('%', #{schLotnoAddr}, '%')
</if>
<if test='schDtlAddr != null and schDtlAddr != ""'>
AND p.DTL_ADDR LIKE CONCAT('%', #{schDtlAddr}, '%')
</if>
<if test='schLotnoMno != null and schLotnoMno != ""'>
AND p.LOTNO_MNO = #{schLotnoMno}
</if>
<if test='schLotnoSno != null and schLotnoSno != ""'>
AND p.LOTNO_SNO = #{schLotnoSno}
</if>
</sql>
<!-- 공통 검색 조건 - 날짜 (진행단계별 복잡 로직) -->
<sql id="searchConditionsDate">
<!-- 중요로직: 진행단계 코드에 따라 해당 일자 컬럼과 비교, null/"" 일 경우 모든 단계 OR 조건 검색 -->
<if test='schPrcsSttsStartDt != null and schPrcsSttsStartDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
</choose>
</if>
<if test='schPrcsSttsEndDt != null and schPrcsSttsEndDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
</choose>
</if>
</sql>
<!-- 공통 검색 조건 - 전체 (Basic + Date) -->
<sql id="searchConditions">
<include refid="searchConditionsBasic"/>
<include refid="searchConditionsDate"/>
</sql>
<!-- 단속 목록 조회 -->
<select id="selectList" parameterType="CrdnRegistAndViewVO" resultType="CrdnRegistAndViewVO">
/* CrdnRegistAndViewMapper.selectList : 단속 목록 조회 */
@ -105,113 +226,7 @@
LEFT JOIN tb_usg_idx usg ON usg.USG_IDX_CD = a.USG_IDX_CD
LEFT JOIN tb_strct_idx strct ON strct.STRCT_IDX_CD = a.STRCT_IDX_CD
WHERE c.DEL_YN = 'N'
<if test='schCrdnYr != null and schCrdnYr != ""'>
AND c.CRDN_YR = #{schCrdnYr}
</if>
<if test='schCrdnNo != null and schCrdnNo != ""'>
AND c.CRDN_NO LIKE CONCAT('%', #{schCrdnNo}, '%')
</if>
<if test='schStdgEmdCd != null and schStdgEmdCd.size() > 0'>
AND p.STDG_EMD_CD IN
<foreach collection="schStdgEmdCd" item="emdCd" open="(" separator="," close=")">
#{emdCd}
</foreach>
</if>
<if test='schRgnSeCd != null and schRgnSeCd != ""'>
AND c.RGN_SE_CD = #{schRgnSeCd}
</if>
<if test='schDsclMthdCd != null and schDsclMthdCd != ""'>
AND c.DSCL_MTHD_CD = #{schDsclMthdCd}
</if>
<if test='schExmnr != null and schExmnr != ""'>
AND c.EXMNR LIKE CONCAT('%', #{schExmnr}, '%')
</if>
<if test='schCrdnPrcsSttsCd != null and schCrdnPrcsSttsCd != ""'>
AND c.CRDN_PRCS_STTS_CD = #{schCrdnPrcsSttsCd}
</if>
<!-- 중요로직: 진행단계 코드에 따라 해당 일자 컬럼과 비교, null/"" 일 경우 모든 단계 OR 조건 검색 -->
<if test='schPrcsSttsStartDt != null and schPrcsSttsStartDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
</choose>
</if>
<if test='schPrcsSttsEndDt != null and schPrcsSttsEndDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
</choose>
</if>
<if test='schAgrvtnLevyTrgtYn != null and schAgrvtnLevyTrgtYn != ""'>
AND c.AGRVTN_LEVY_TRGT_YN = #{schAgrvtnLevyTrgtYn}
</if>
<if test='schZip != null and schZip != ""'>
AND p.ZIP LIKE CONCAT('%', #{schZip}, '%')
</if>
<if test='schLotnoAddr != null and schLotnoAddr != ""'>
AND p.LOTNO_ADDR LIKE CONCAT('%', #{schLotnoAddr}, '%')
</if>
<if test='schDtlAddr != null and schDtlAddr != ""'>
AND p.DTL_ADDR LIKE CONCAT('%', #{schDtlAddr}, '%')
</if>
<if test='schLotnoMno != null and schLotnoMno != ""'>
AND p.LOTNO_MNO = #{schLotnoMno}
</if>
<if test='schLotnoSno != null and schLotnoSno != ""'>
AND p.LOTNO_SNO = #{schLotnoSno}
</if>
<include refid="searchConditions"/>
) m
WHERE 1=1
<if test='schActCmpltCd != null and schActCmpltCd != ""'>
@ -253,113 +268,7 @@
GROUP BY CRDN_YR, CRDN_NO
) act_cnt ON act_cnt.CRDN_YR = c.CRDN_YR AND act_cnt.CRDN_NO = c.CRDN_NO
WHERE c.DEL_YN = 'N'
<if test='schCrdnYr != null and schCrdnYr != ""'>
AND c.CRDN_YR = #{schCrdnYr}
</if>
<if test='schCrdnNo != null and schCrdnNo != ""'>
AND c.CRDN_NO LIKE CONCAT('%', #{schCrdnNo}, '%')
</if>
<if test='schStdgEmdCd != null and schStdgEmdCd.size() > 0'>
AND p.STDG_EMD_CD IN
<foreach collection="schStdgEmdCd" item="emdCd" open="(" separator="," close=")">
#{emdCd}
</foreach>
</if>
<if test='schRgnSeCd != null and schRgnSeCd != ""'>
AND c.RGN_SE_CD = #{schRgnSeCd}
</if>
<if test='schDsclMthdCd != null and schDsclMthdCd != ""'>
AND c.DSCL_MTHD_CD = #{schDsclMthdCd}
</if>
<if test='schExmnr != null and schExmnr != ""'>
AND c.EXMNR LIKE CONCAT('%', #{schExmnr}, '%')
</if>
<if test='schCrdnPrcsSttsCd != null and schCrdnPrcsSttsCd != ""'>
AND c.CRDN_PRCS_STTS_CD = #{schCrdnPrcsSttsCd}
</if>
<!-- 중요로직: 진행단계 코드에 따라 해당 일자 컬럼과 비교, null/"" 일 경우 모든 단계 OR 조건 검색 -->
<if test='schPrcsSttsStartDt != null and schPrcsSttsStartDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
</choose>
</if>
<if test='schPrcsSttsEndDt != null and schPrcsSttsEndDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
</choose>
</if>
<if test='schAgrvtnLevyTrgtYn != null and schAgrvtnLevyTrgtYn != ""'>
AND c.AGRVTN_LEVY_TRGT_YN = #{schAgrvtnLevyTrgtYn}
</if>
<if test='schZip != null and schZip != ""'>
AND p.ZIP LIKE CONCAT('%', #{schZip}, '%')
</if>
<if test='schLotnoAddr != null and schLotnoAddr != ""'>
AND p.LOTNO_ADDR LIKE CONCAT('%', #{schLotnoAddr}, '%')
</if>
<if test='schDtlAddr != null and schDtlAddr != ""'>
AND p.DTL_ADDR LIKE CONCAT('%', #{schDtlAddr}, '%')
</if>
<if test='schLotnoMno != null and schLotnoMno != ""'>
AND p.LOTNO_MNO = #{schLotnoMno}
</if>
<if test='schLotnoSno != null and schLotnoSno != ""'>
AND p.LOTNO_SNO = #{schLotnoSno}
</if>
<include refid="searchConditions"/>
) m
WHERE 1=1
<if test='schActCmpltCd != null and schActCmpltCd != ""'>
@ -370,12 +279,12 @@
<!-- 단속 목록 조회 - 그리드형태 그대로 다운로드 -->
<select id="selectListExcelGrid" parameterType="CrdnRegistAndViewVO" resultType="CrdnRegistAndViewExcelGridVO">
/* CrdnRegistAndViewMapper.selectList : 단속 목록 조회 */
/* CrdnRegistAndViewMapper.selectListExcelGrid : 단속 목록 조회 - 그리드형태 그대로 다운로드 */
SELECT m.*,
m.ACT_CMPLT_CD,
case when m.ACT_CMPLT_CD = '0' then '행위정보없음'
when m.ACT_CMPLT_CD = '1' then '미조치'
when m.ACT_CMPLT_CD = '2' then '조치완료'
when m.ACT_CMPLT_CD = '3' then '조치완료'
end as ACT_CMPLT_CD_NM
FROM (
SELECT
@ -403,7 +312,7 @@
DATE_FORMAT(STR_TO_DATE(c.PAY_URG_BGNG_YMD, '%Y%m%d'), '%Y-%m-%d') AS PAY_URG_BGNG_YMD, /* 납부촉구 시작일 */
DATE_FORMAT(STR_TO_DATE(c.PAY_URG_END_YMD, '%Y%m%d'), '%Y-%m-%d') AS PAY_URG_END_YMD, /* 납부촉구 종료일 */
DATE_FORMAT(STR_TO_DATE(c.FRST_CRDN_YR, '%Y%m%d'), '%Y-%m-%d') AS FRST_CRDN_YR, /* 최초 단속 연도 */
DATE_FORMAT(STR_TO_DATE(c.FRST_CRDN_NO, '%Y%m%d'), '%Y-%m-%d') AS FRST_CRDN_NO, /* 최초 */
DATE_FORMAT(STR_TO_DATE(c.FRST_CRDN_NO, '%Y%m%d'), '%Y-%m-%d') AS FRST_CRDN_NO, /* 최초 단속 번호 */
case when c.RELEVY_YN = 'Y' then '재부과'
else '신규'
end as RELEVY_YN, /* 재과 여부 */
@ -450,12 +359,10 @@
IFNULL(act_cnt.ACT_COMPLT_CNT, 0) as ACT_COMPLT_CNT,
/* 중요로직: ACT_CMPLT_CD를 메인 SELECT에서 직접 계산 - 외부 SELECT에서 재계산 불필요 */
case when IFNULL(act_cnt.ACT_ALL_CNT, 0) = 0 then '0'
when IFNULL(act_cnt.ACT_ALL_CNT, 0) != 0 and IFNULL(act_cnt.ACT_ALL_CNT, 0) != IFNULL(act_cnt.ACT_COMPLT_CNT, 0)
then '1'
when IFNULL(act_cnt.ACT_ALL_CNT, 0) != 0 and IFNULL(act_cnt.ACT_ALL_CNT, 0) = IFNULL(act_cnt.ACT_COMPLT_CNT, 0)
then '3'
when IFNULL(act_cnt.ACT_ALL_CNT, 0) != 0 and IFNULL(act_cnt.ACT_ALL_CNT, 0) != IFNULL(act_cnt.ACT_COMPLT_CNT, 0) then '1'
when IFNULL(act_cnt.ACT_ALL_CNT, 0) != 0 and IFNULL(act_cnt.ACT_ALL_CNT, 0) = IFNULL(act_cnt.ACT_COMPLT_CNT, 0) then '3'
else '-'
end as ACT_CMPLT_CD, /* [행위정보없음 0: , 미조치 : 1, 조치완료 : 2] */
end as ACT_CMPLT_CD, /* [행위정보없음 0: , 미조치 : 1, 조치완료 : 3] */
a.USG_IDX_CD, /* 용도 지수 코드 */
usg.USG_NM AS USG_IDX_CD_NM,
a.AREA, /* 면적 */
@ -480,120 +387,12 @@
WHERE DEL_YN = 'N'
GROUP BY CRDN_YR, CRDN_NO
) act_cnt ON act_cnt.CRDN_YR = c.CRDN_YR AND act_cnt.CRDN_NO = c.CRDN_NO
LEFT Join tb_act_info a ON a.CRDN_YR = c.CRDN_YR and a.CRDN_NO = c.CRDN_NO AND a.DEL_YN = 'N' AND a.ACT_NO =
(SELECT MIN(a1.ACT_NO) FROM tb_act_info a1 WHERE a1.CRDN_YR = a.CRDN_YR AND a1.CRDN_NO = a.CRDN_NO AND
a1.DEL_YN='N')
LEFT Join tb_act_info a ON a.CRDN_YR = c.CRDN_YR and a.CRDN_NO = c.CRDN_NO AND a.DEL_YN = 'N' AND a.ACT_NO = (SELECT MIN(a1.ACT_NO) FROM tb_act_info a1 WHERE a1.CRDN_YR = a.CRDN_YR AND a1.CRDN_NO = a.CRDN_NO AND a1.DEL_YN='N')
LEFT JOIN tb_act_type act ON act.ACT_TYPE_CD = a.ACT_TYPE_CD
LEFT JOIN tb_usg_idx usg ON usg.USG_IDX_CD = a.USG_IDX_CD
LEFT JOIN tb_strct_idx strct ON strct.STRCT_IDX_CD = a.STRCT_IDX_CD
WHERE c.DEL_YN = 'N'
<if test='schCrdnYr != null and schCrdnYr != ""'>
AND c.CRDN_YR = #{schCrdnYr}
</if>
<if test='schCrdnNo != null and schCrdnNo != ""'>
AND c.CRDN_NO LIKE CONCAT('%', #{schCrdnNo}, '%')
</if>
<if test='schStdgEmdCd != null and schStdgEmdCd.size() > 0'>
AND p.STDG_EMD_CD IN
<foreach collection="schStdgEmdCd" item="emdCd" open="(" separator="," close=")">
#{emdCd}
</foreach>
</if>
<if test='schRgnSeCd != null and schRgnSeCd != ""'>
AND c.RGN_SE_CD = #{schRgnSeCd}
</if>
<if test='schDsclMthdCd != null and schDsclMthdCd != ""'>
AND c.DSCL_MTHD_CD = #{schDsclMthdCd}
</if>
<if test='schExmnr != null and schExmnr != ""'>
AND c.EXMNR LIKE CONCAT('%', #{schExmnr}, '%')
</if>
<if test='schCrdnPrcsSttsCd != null and schCrdnPrcsSttsCd != ""'>
AND c.CRDN_PRCS_STTS_CD = #{schCrdnPrcsSttsCd}
</if>
<!-- 중요로직: 진행단계 코드에 따라 해당 일자 컬럼과 비교, null/"" 일 경우 모든 단계 OR 조건 검색 -->
<if test='schPrcsSttsStartDt != null and schPrcsSttsStartDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
OR c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_BGNG_YMD <![CDATA[>=]]> REPLACE(#{schPrcsSttsStartDt}, '-', '')
</when>
</choose>
</if>
<if test='schPrcsSttsEndDt != null and schPrcsSttsEndDt != ""'>
<choose>
<when test='schCrdnPrcsSttsCd == null or schCrdnPrcsSttsCd == ""'>
AND (
c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
OR c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
)
</when>
<when test='schCrdnPrcsSttsCd == "1"'>
AND c.DSPS_BFHD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "2"'>
AND c.CRC_CMD_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "3"'>
AND c.CRC_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "4"'>
AND c.LEVY_PRVNTC_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "5"'>
AND c.LEVY_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
<when test='schCrdnPrcsSttsCd == "6"'>
AND c.PAY_URG_END_YMD <![CDATA[<=]]> REPLACE(#{schPrcsSttsEndDt}, '-', '')
</when>
</choose>
</if>
<if test='schAgrvtnLevyTrgtYn != null and schAgrvtnLevyTrgtYn != ""'>
AND c.AGRVTN_LEVY_TRGT_YN = #{schAgrvtnLevyTrgtYn}
</if>
<if test='schZip != null and schZip != ""'>
AND p.ZIP LIKE CONCAT('%', #{schZip}, '%')
</if>
<if test='schLotnoAddr != null and schLotnoAddr != ""'>
AND p.LOTNO_ADDR LIKE CONCAT('%', #{schLotnoAddr}, '%')
</if>
<if test='schDtlAddr != null and schDtlAddr != ""'>
AND p.DTL_ADDR LIKE CONCAT('%', #{schDtlAddr}, '%')
</if>
<if test='schLotnoMno != null and schLotnoMno != ""'>
AND p.LOTNO_MNO = #{schLotnoMno}
</if>
<if test='schLotnoSno != null and schLotnoSno != ""'>
AND p.LOTNO_SNO = #{schLotnoSno}
</if>
<include refid="searchConditions"/>
) m
WHERE 1=1
<if test='schActCmpltCd != null and schActCmpltCd != ""'>
@ -727,7 +526,15 @@
p.ZIP,
ai.ACT_TYPE_CD, /* 행위 유형 코드 */
ai.USG_IDX_CD, /* 용도 지수 코드 */
ai.ACT_INFO_ID
ai.ACT_INFO_ID,
IFNULL(act_cnt.ACT_ALL_CNT, 0) as ACT_ALL_CNT,
IFNULL(act_cnt.ACT_COMPLT_CNT, 0) as ACT_COMPLT_CNT,
/* 중요로직: ACT_CMPLT_CD를 메인 SELECT에서 직접 계산 - 외부 SELECT에서 재계산 불필요 */
case when IFNULL(act_cnt.ACT_ALL_CNT, 0) = 0 then '0'
when IFNULL(act_cnt.ACT_ALL_CNT, 0) != 0 and IFNULL(act_cnt.ACT_ALL_CNT, 0) != IFNULL(act_cnt.ACT_COMPLT_CNT, 0) then '1'
when IFNULL(act_cnt.ACT_ALL_CNT, 0) != 0 and IFNULL(act_cnt.ACT_ALL_CNT, 0) = IFNULL(act_cnt.ACT_COMPLT_CNT, 0) then '3'
else '-'
end as ACT_CMPLT_CD /* [행위정보없음 0: , 미조치 : 1, 조치완료 : 3] */
FROM tb_crdn c
inner join tb_act_info ai on ai.CRDN_NO = c.CRDN_NO and ai.CRDN_YR = c.CRDN_YR and ai.ACTN_PRCS_STTS_CD != '3' and ai.DEL_YN = 'N'
LEFT JOIN tb_cd_detail sgg ON sgg.CD_GROUP_ID = 'ORG_CD' AND sgg.CD_ID = c.SGG_CD
@ -737,60 +544,27 @@
LEFT JOIN tb_user u ON u.USER_ID = c.RGTR AND u.USE_YN = 'Y'
LEFT JOIN tb_pstn_info p ON p.CRDN_YR = c.CRDN_YR AND p.CRDN_NO = c.CRDN_NO AND p.DEL_YN = 'N'
LEFT JOIN tb_cd_detail emd ON emd.CD_GROUP_ID = 'STDG_EMD_CD' AND emd.CD_ID = p.STDG_EMD_CD
LEFT JOIN (
SELECT
CRDN_YR,
CRDN_NO,
COUNT(1) as ACT_ALL_CNT,
SUM(CASE WHEN ACTN_PRCS_STTS_CD = '3' THEN 1 ELSE 0 END) as ACT_COMPLT_CNT
FROM tb_act_info
WHERE DEL_YN = 'N'
GROUP BY CRDN_YR, CRDN_NO
) act_cnt ON act_cnt.CRDN_YR = c.CRDN_YR AND act_cnt.CRDN_NO = c.CRDN_NO
LEFT JOIN tb_act_type act ON act.ACT_TYPE_CD = ai.ACT_TYPE_CD
LEFT JOIN tb_usg_idx usg ON usg.USG_IDX_CD = ai.USG_IDX_CD
LEFT JOIN tb_strct_idx strct_ai ON strct_ai.STRCT_IDX_CD = ai.STRCT_IDX_CD
WHERE c.DEL_YN = 'N'
<if test='schCrdnYr != null and schCrdnYr != ""'>
AND c.CRDN_YR = #{schCrdnYr}
</if>
<if test='schCrdnNo != null and schCrdnNo != ""'>
AND c.CRDN_NO LIKE CONCAT('%', #{schCrdnNo}, '%')
</if>
<if test='schStdgEmdCd != null and schStdgEmdCd.size() > 0'>
AND p.STDG_EMD_CD IN
<foreach collection="schStdgEmdCd" item="emdCd" open="(" separator="," close=")">
#{emdCd}
</foreach>
</if>
<if test='schRgnSeCd != null and schRgnSeCd != ""'>
AND c.RGN_SE_CD = #{schRgnSeCd}
</if>
<if test='schDsclMthdCd != null and schDsclMthdCd != ""'>
AND c.DSCL_MTHD_CD = #{schDsclMthdCd}
</if>
<if test='schExmnr != null and schExmnr != ""'>
AND c.EXMNR LIKE CONCAT('%', #{schExmnr}, '%')
</if>
<if test='schCrdnPrcsSttsCd != null and schCrdnPrcsSttsCd != ""'>
AND c.CRDN_PRCS_STTS_CD = #{schCrdnPrcsSttsCd}
</if>
<if test='schPrcsSttsStartDt != null and schPrcsSttsStartDt != ""'>
AND c.CRDN_PRCS_YMD &gt;= #{schPrcsSttsStartDt}
</if>
<if test='schPrcsSttsEndDt != null and schPrcsSttsEndDt != ""'>
AND c.CRDN_PRCS_YMD &lt;= #{schPrcsSttsEndDt}
</if>
<if test='schAgrvtnLevyTrgtYn != null and schAgrvtnLevyTrgtYn != ""'>
AND c.AGRVTN_LEVY_TRGT_YN = #{schAgrvtnLevyTrgtYn}
</if>
<if test='schZip != null and schZip != ""'>
AND p.ZIP LIKE CONCAT('%', #{schZip}, '%')
</if>
<if test='schLotnoAddr != null and schLotnoAddr != ""'>
AND p.LOTNO_ADDR LIKE CONCAT('%', #{schLotnoAddr}, '%')
</if>
<if test='schDtlAddr != null and schDtlAddr != ""'>
AND p.DTL_ADDR LIKE CONCAT('%', #{schDtlAddr}, '%')
</if>
<if test='schLotnoMno != null and schLotnoMno != ""'>
AND p.LOTNO_MNO = #{schLotnoMno}
</if>
<if test='schLotnoSno != null and schLotnoSno != ""'>
AND p.LOTNO_SNO = #{schLotnoSno}
</if>
<include refid="searchConditionsBasic"/>
) m
WHERE 1=1
<if test='schActCmpltCd != null and schActCmpltCd != ""'>
/* 중요로직: ACT_CMPLT_CD가 메인 SELECT에서 이미 계산되어 단순 비교만 수행 */
AND m.ACT_CMPLT_CD = #{schActCmpltCd} /* [행위정보없음 0: , 미조치 : 1, 조치완료 : 2] */
</if>
ORDER BY m.CRDN_YR DESC, m.CRDN_NO DESC, m.ACT_INFO_ID
</select>

Loading…
Cancel
Save