<?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.njcn.gather.icd.mapping.mapper.CsIcdPathMapper">

    <resultMap id="CsIcdPathVOResultMap"
               type="com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathVO">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="angle" property="angle"/>
        <result column="usePhaseIndex" property="usePhaseIndex"/>
        <result column="state" property="state"/>
        <result column="result" property="result"/>
        <result column="msg" property="msg"
                typeHandler="com.njcn.gather.icd.mapping.typehandler.JsonNodeTypeHandler"/>
        <result column="type" property="type"/>
        <result column="referenceIcdId" property="referenceIcdId"/>
        <result column="createBy" property="createBy"/>
        <result column="createTime" property="createTime"/>
        <result column="updateBy" property="updateBy"/>
        <result column="updateTime" property="updateTime"/>
    </resultMap>

    <select id="selectIcdPathList"
            resultMap="CsIcdPathVOResultMap">
        SELECT
            ID AS id,
            Name AS name,
            Angle AS angle,
            Use_Phase_Index AS usePhaseIndex,
            State AS state,
            Result AS result,
            Msg AS msg,
            Type AS type,
            Reference_Icd_Id AS referenceIcdId,
            Create_By AS createBy,
            Create_Time AS createTime,
            Update_By AS updateBy,
            Update_Time AS updateTime
        FROM cs_icd_path
        WHERE State = 1
        <if test="keyword != null and keyword != ''">
            AND Name LIKE CONCAT('%', #{keyword}, '%')
        </if>
        <if test="type != null">
            AND Type = #{type}
        </if>
        <if test="result != null">
            AND Result = #{result}
        </if>
        ORDER BY Update_Time DESC, Create_Time DESC
    </select>

    <select id="selectReferenceIcdPathList"
            resultMap="CsIcdPathVOResultMap">
        SELECT
            ID AS id,
            Name AS name,
            Angle AS angle,
            Use_Phase_Index AS usePhaseIndex,
            State AS state,
            Result AS result,
            Msg AS msg,
            Type AS type,
            Reference_Icd_Id AS referenceIcdId,
            Create_By AS createBy,
            Create_Time AS createTime,
            Update_By AS updateBy,
            Update_Time AS updateTime
        FROM cs_icd_path
        WHERE State = 1
          AND Type IN (1, 3)
        ORDER BY Update_Time DESC, Create_Time DESC
    </select>

    <select id="selectIcdCheckMsgById"
            resultMap="CsIcdPathVOResultMap">
        SELECT Msg AS msg
        FROM cs_icd_path
        WHERE ID = #{id}
          AND State = 1
    </select>

    <select id="selectIcdPathDetailById"
            resultType="com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathDetailVO">
        SELECT
            ID AS id,
            Name AS name,
            Json_Str AS jsonStr,
            Xml_Str AS xmlStr,
            Icd AS icdContent
        FROM cs_icd_path
        WHERE ID = #{id}
          AND State = 1
    </select>

</mapper>
