<?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.AssessMapper">
    <select id="getTotalScore" resultType="com.goldenwater.hzz.domain.AssessScoreDTO">
        SELECT C.AD_CODE AS "adCode", D.AD_NAME AS "adName", C.SCORE AS "score"
        FROM (SELECT A.AD_CODE,SUM(A.SCORE) AS SCORE FROM ATT_ASS_GRADE A
        LEFT JOIN ATT_AD_EXPD B ON A.AD_CODE=B.AD_CODE AND B.PARENT_AD_CODE=${adCode} AND B.EFF_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (TO_DATE(${effDate},'YYYY-MM-DD')&lt;=B.EXPR_DATE OR B.EXPR_DATE IS NULL)
        WHERE A.ASS_TIME=TO_DATE(${assTime},'YYYY-MM-DD') AND A.EFF_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (TO_DATE(${effDate},'YYYY-MM-DD')&lt;=A.EXPR_DATE OR A.EXPR_DATE IS NULL)
        GROUP BY A.AD_CODE) C
        LEFT JOIN OBJ_AD D ON C.AD_CODE=D.AD_CODE AND D.FROM_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (TO_DATE(${effDate},'YYYY-MM-DD')&lt;=D.TO_DATE OR D.TO_DATE IS NULL)
    </select>
    <select id="getMthNameAndScore" resultType="com.goldenwater.hzz.domain.AssessScoreDTO">
        SELECT A.AD_CODE AS "adCode", B.AD_NAME AS "adName", C.SCORE AS "score", TO_CHAR(C.ASS_TIME,'YYYY-MM-DD') AS "assTime", C.EXPLAIN AS "explain", D.MTH_GUID AS "mthGuid", D.MTH_NAME AS "mthName"
        FROM ATT_AD_EXPD A
        LEFT JOIN ATT_AD_BASE B ON A.AD_CODE=B.AD_CODE AND B.EFF_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (B.EXPR_DATE IS NULL OR TO_DATE(${effDate},'YYYY-MM-DD')&lt;=B.EXPR_DATE)
        LEFT JOIN ATT_ASS_GRADE C ON A.AD_CODE=C.AD_CODE AND C.EFF_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (C.EXPR_DATE IS NULL OR TO_DATE(${effDate},'YYYY-MM-DD')&lt;=C.EXPR_DATE) AND C.ASS_TIME=TO_DATE(${assTime},'YYYY-MM-DD')
        LEFT JOIN ATT_ASSESS_METHOD D ON C.MTH_GUID=D.MTH_GUID AND D.EFF_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (D.EXPR_DATE IS NULL OR TO_DATE(${effDate},'YYYY-MM-DD')&lt;=D.EXPR_DATE)
        WHERE A.PARENT_AD_CODE=${adCode} AND A.EFF_DATE&lt;=TO_DATE(${effDate},'YYYY-MM-DD') AND (A.EXPR_DATE IS NULL OR TO_DATE(${effDate},'YYYY-MM-DD')&lt;=A.EXPR_DATE)
    </select>
    <select id="getMethodFile" resultType="com.goldenwater.hzz.domain.AssessFileDTO">
        SELECT A.AD_CODE AS "adCode", A.ASS_GUID AS "assGuid", A.ASS_NAME AS "assName", A.ENTER_UNIT AS "enterUnit", TO_CHAR(A.ENTER_TM,'YYYY-MM-DD') AS "enterTm", A.TOTAL_POINTS AS "totalPoints", A.ACCEPTANCE_LINE AS "acceptanceLine", A.WELL_LINE AS "wellLine", A.EXCELLENT_LINE AS "excellentLine", C.MD_NAME AS "mdName", C.FILE_TITL AS "fileTitl", C.FILE_PATH AS "filePath"
        FROM ATT_RV_ASSESS A
        LEFT JOIN REL_MD_OBJ B ON A.ASS_GUID=B.OBJ_GUID AND B.OBJ_TAB_CODE='ATT_RV_ASSESS' AND B.FROM_DATE&lt;=TO_DATE(#{effDate},'YYYY-MM-DD') AND (B.TO_DATE IS NULL OR B.TO_DATE&gt;=TO_DATE(#{effDate},'YYYY-MM-DD'))
        LEFT JOIN ATT_MD_BASE C ON B.MD_GUID=C.MD_CODE AND C.FROM_DATE&lt;=TO_DATE(#{effDate},'YYYY-MM-DD') AND (C.TO_DATE IS NULL OR TO_DATE(#{effDate},'YYYY-MM-DD')&gt;=C.TO_DATE)
        WHERE A.AD_CODE=#{adCode} AND A.EFF_DATE&lt;TO_DATE(#{effDate},'YYYY-MM-DD') AND (A.EXPR_DATE IS NULL OR TO_DATE(#{effDate},'YYYY-MM-DD')&gt;A.EXPR_DATE)
    </select>
    <select id="getAttFileText" resultType="com.goldenwater.hzz.domain.AssessScoreDTO">
        SELECT * FROM ATT_FILE_TEXT WHERE MD_CODE=#{mdCode} AND EFF_DATE&lt;#{effDate} AND (EXPR_DATE&gt;#{exprDate} OR EXPR_DATE IS NULL)
    </select>
</mapper>
