<?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="com.goldenwater.hzz.mapper.EventClearMapper">
    <select id="findList" resultType="com.goldenwater.hzz.domain.EventDTO" parameterType="java.util.Map">
        SELECT EV.GUID AS "guid", EV.EV_CODE AS "evCode", EV.AD_CODE AS "adCode", AD.AD_NAME AS "adName",
               EV.OBJ_TYPE AS "objectType", EV.OBJ_CODE AS "objectId",
               CASE WHEN EV.OBJ_TYPE='REA' THEN REA.REA_NAME WHEN EV.OBJ_TYPE='LKS' THEN LKS.LKS_NAME ELSE RER.RER_NAME END AS "objectName",
               EV.EV_TYPE AS "evType", EV.EV_DESC AS "eventDesc", EV.LOC AS "eventAddress",
               EV.STATUS AS "status", EV.DEAL_DESC AS "dealDesc",
               TO_CHAR(EV.FIND_TS,'YYYY-MM-DD HH24:MI:SS') AS "findTs",
               TO_CHAR(EV.DONE_DATE,'YYYY-MM-DD HH24:MI:SS') AS "doneDate",
               EV.REPO_NAME AS "userName"
        FROM ATT_EV_BASE EV
        LEFT JOIN ATT_REA_BASE REA ON EV.OBJ_CODE=REA.REA_CODE AND EV.OBJ_TYPE='REA'
        LEFT JOIN ATT_LKS_BASE LKS ON EV.OBJ_CODE=LKS.LKS_CODE AND EV.OBJ_TYPE='LKS'
        LEFT JOIN ATT_RER_BASE RER ON EV.OBJ_CODE=RER.RER_CODE AND EV.OBJ_TYPE='RER'
        LEFT JOIN ATT_AD_BASE AD ON EV.AD_CODE=AD.AD_CODE
        WHERE EV.TO_DATE IS NULL AND REA.EXPR_DATE IS NULL AND LKS.EXPR_DATE IS NULL AND RER.EXPR_DATE IS NULL AND AD.EXPR_DATE IS NULL AND EV.SOURCE_TYPE='3'
        <if test="ad_code != null and ad_code != ''">AND EV.AD_CODE=#{ad_code}</if>
        <if test="ev_type != null and ev_type != ''">AND EV.EV_TYPE=#{ev_type}</if>
        <if test="key_word != null and key_word != ''">AND (REA.REA_NAME LIKE '%'||#{key_word}||'%' OR AD.AD_NAME LIKE '%'||#{key_word}||'%' OR EV.EV_DESC LIKE '%'||#{key_word}||'%')</if>
        ORDER BY EV.FIND_TS DESC
    </select>
    <select id="findListByAdCode" resultType="com.goldenwater.hzz.domain.EventDTO">
        SELECT EV.GUID AS "guid", EV.EV_CODE AS "evCode", EV.AD_CODE AS "adCode", AD.AD_NAME AS "adName",
               EV.OBJ_TYPE AS "objectType", EV.OBJ_CODE AS "objectId",
               CASE WHEN EV.OBJ_TYPE='REA' THEN REA.REA_NAME WHEN EV.OBJ_TYPE='LKS' THEN LKS.LKS_NAME ELSE RER.RER_NAME END AS "objectName",
               EV.EV_TYPE AS "evType", EV.EV_DESC AS "eventDesc", EV.LOC AS "eventAddress",
               EV.STATUS AS "status", EV.DEAL_DESC AS "dealDesc",
               TO_CHAR(EV.FIND_TS,'YYYY-MM-DD HH24:MI:SS') AS "findTs",
               TO_CHAR(EV.DONE_DATE,'YYYY-MM-DD HH24:MI:SS') AS "doneDate",
               EV.REPO_NAME AS "userName"
        FROM ATT_EV_BASE EV
        LEFT JOIN ATT_REA_BASE REA ON EV.OBJ_CODE=REA.REA_CODE AND EV.OBJ_TYPE='REA'
        LEFT JOIN ATT_LKS_BASE LKS ON EV.OBJ_CODE=LKS.LKS_CODE AND EV.OBJ_TYPE='LKS'
        LEFT JOIN ATT_RER_BASE RER ON EV.OBJ_CODE=RER.RER_CODE AND EV.OBJ_TYPE='RER'
        LEFT JOIN ATT_AD_BASE AD ON EV.AD_CODE=AD.AD_CODE
        WHERE EV.TO_DATE IS NULL AND REA.EXPR_DATE IS NULL AND LKS.EXPR_DATE IS NULL AND RER.EXPR_DATE IS NULL AND AD.EXPR_DATE IS NULL AND EV.SOURCE_TYPE='3'
        <if test="adCode != null and adCode != ''">AND EV.AD_CODE=#{adCode}</if>
        <if test="evType != null and evType != ''">AND EV.EV_TYPE=#{evType}</if>
        <if test="keyWord != null and keyWord != ''">AND (REA.REA_NAME LIKE '%'||#{keyWord}||'%' OR AD.AD_NAME LIKE '%'||#{keyWord}||'%' OR EV.EV_DESC LIKE '%'||#{keyWord}||'%')</if>
        ORDER BY EV.FIND_TS DESC
    </select>
</mapper>
