<?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.ruoyi.interfaces.mapper.PtConsultDao">

    <resultMap type="com.ruoyi.interfaces.domain.PtConsult" id="ptConsultResultMap">
        <result property="id" column="ID" jdbcType="VARCHAR"/>
        <result property="title" column="TITLE" jdbcType="VARCHAR"/>
        <result property="content" column="CONTENT" jdbcType="VARCHAR"/>
        <result property="type" column="TYPE" jdbcType="VARCHAR"/>
        <result property="userId" column="USER_ID" jdbcType="VARCHAR"/>
        <result property="intm" column="INTM" jdbcType="DATE"/>
        <result property="uptm" column="UPTM" jdbcType="DATE"/>
        <result property="replyUserId" column="REPLY_USER_ID" jdbcType="VARCHAR"/>
        <result property="replyContent" column="REPLY_CONTENT" jdbcType="VARCHAR"/>
        <result property="rplytm" column="RPLYTM" jdbcType="DATE"/>
        <result property="replyUserName" column="REPLY_USER_NAME" jdbcType="VARCHAR"/>
        <result property="userName" column="USER_NAME" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="table_columns">
        ID
        ,
            TITLE,
            CONTENT,
            TYPE,
            USER_ID,
            INTM,
            UPTM,
            REPLY_USER_ID,
            REPLY_CONTENT,
            RPLYTM,
            REPLY_USER_NAME
    </sql>
    <sql id="entity_properties">
        #{id,jdbcType=VARCHAR}
        ,
        #{title,jdbcType=VARCHAR},
        #{content,jdbcType=VARCHAR},
        #{type,jdbcType=VARCHAR},
        #{userId,jdbcType=VARCHAR},
        #{intm,jdbcType=DATE},
        #{uptm,jdbcType=DATE},
        #{replyUserId,jdbcType=VARCHAR},
        #{replyContent,jdbcType=VARCHAR},
        #{rplytm,jdbcType=DATE},
        #{replyUserName,jdbcType=VARCHAR}
    </sql>

    <!-- 使用like用法：columnName like concat('%',#columnName#,'%') -->
    <sql id="page_where">
        <trim prefix="where" prefixOverrides="and | or ">
            <if test="title != null and title != ''">and TITLE LIKE CONCAT('%', CONCAT(#{title}, '%'))</if>
            <if test="content != null and content != ''">and CONTENT = #{content}</if>
            <if test="type != null and type != ''">and TYPE = #{type}</if>
            <if test="userId != null and userId != ''">and USER_ID = #{userId}</if>
            <if test="intm != null">and INTM = #{intm}</if>
            <if test="uptm != null">and UPTM = #{uptm}</if>
            <if test="replyUserId != null and replyUserId != ''">and REPLY_USER_ID = #{replyUserId}</if>
            <if test="replyContent != null and replyContent != ''">and REPLY_CONTENT = #{replyContent}</if>
            <if test="rplytm != null">and RPLYTM = #{rplytm}</if>
            <if test="replyUserName != null and replyUserName != ''">and REPLY_USER_NAME = #{replyUserName}</if>
        </trim>
    </sql>

    <select id="get" resultMap="ptConsultResultMap" parameterType="String">
        select
        <include refid="table_columns"/>
        from PT_CONSULT where ID = #{id}
    </select>

    <select id="findList" resultMap="ptConsultResultMap">
        select
        <include refid="table_columns"/>
        from PT_CONSULT
        <include refid="page_where"/>
    </select>

    <select id="list" resultMap="ptConsultResultMap">
        SELECT P.ID, P.TITLE, P.CONTENT, P.TYPE, P.USER_ID, P.INTM, P.UPTM,
        P.REPLY_USER_ID, P.REPLY_CONTENT, P.RPLYTM,
        U.USER_NAME, UR.USER_NAME AS REPLY_USER_NAME FROM (
        select
        <include refid="table_columns"/>
        from PT_CONSULT
        <include refid="page_where"/>
        ) P
        LEFT JOIN PT_APP_USER U ON U.USER_ID = P.USER_ID
        LEFT JOIN PT_APP_USER UR ON UR.USER_ID = P.REPLY_USER_ID
    </select>

    <insert id="insert" parameterType="com.ruoyi.interfaces.domain.PtConsult">
        insert into PT_CONSULT(
        <include refid="table_columns"/>
        )
        values (
        <include refid="entity_properties"/>
        )
    </insert>

    <delete id="delete" parameterType="java.lang.String">
        delete
        from PT_CONSULT
        where ID = #{id}
    </delete>

    <update id="update" parameterType="com.ruoyi.interfaces.domain.PtConsult">
        update PT_CONSULT
        <trim prefix="set" suffixOverrides=",">
            <if test="title != null and title != ''">TITLE = #{title},</if>
            <if test="content != null and content != ''">CONTENT = #{content},</if>
            <if test="type != null and type != ''">TYPE = #{type},</if>
            <if test="userId != null and userId != ''">USER_ID = #{userId},</if>
            <if test="intm != null">INTM = #{intm},</if>
            <if test="uptm != null">UPTM = #{uptm},</if>
            <if test="replyUserId != null and replyUserId != ''">REPLY_USER_ID = #{replyUserId},</if>
            <if test="replyContent != null and replyContent != ''">REPLY_CONTENT = #{replyContent},</if>
            <if test="rplytm != null">RPLYTM = #{rplytm},</if>
            <if test="replyUserName != null and replyUserName != ''">REPLY_USER_NAME = #{replyUserName},</if>
        </trim>
        <where>ID = #{id}</where>
    </update>

    <update id="updateBy" parameterType="com.ruoyi.interfaces.domain.PtConsult">
        update PT_CONSULT
        <trim prefix="set" suffixOverrides=",">
            <if test="title != null and title != ''">TITLE = #{title},</if>
            <if test="content != null and content != ''">CONTENT = #{content},</if>
            <if test="type != null and type != ''">TYPE = #{type},</if>
            <if test="userId != null and userId != ''">USER_ID = #{userId},</if>
            <if test="intm != null">INTM = #{intm},</if>
            <if test="uptm != null">UPTM = #{uptm},</if>
            <if test="replyUserId != null and replyUserId != ''">REPLY_USER_ID = #{replyUserId},</if>
            <if test="replyContent != null and replyContent != ''">REPLY_CONTENT = #{replyContent},</if>
            <if test="rplytm != null">RPLYTM = #{rplytm},</if>
            <if test="replyUserName != null and replyUserName != ''">REPLY_USER_NAME = #{replyUserName},</if>
        </trim>
        <include refid="page_where"/>
    </update>
</mapper>
