<?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.ss.intention.mapper.IntentionMapper">

    <resultMap type="IntentionVO" id="EIntentionResult" autoMapping="true" />

    <sql id="selectEIntentionVo">
        select
            intention_id,
            phone,
            name,
            reserve_info,
            create_time
        from ss_intention
    </sql>

    <sql id="searchCondition">
        <if test="query.phone != null  and query.phone != ''"> and phone = #{query.phone}</if>
        <if test="query.name != null  and query.name != ''"> and name like concat('%', #{query.name}, '%')</if>
        <if test="query.reserveInfo != null  and query.reserveInfo != ''"> and reserve_info = #{query.reserveInfo}</if>
    </sql>

    <select id="selectEIntentionList" parameterType="IntentionQuery" resultMap="EIntentionResult">
        <include refid="selectEIntentionVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectEIntentionByIntentionId" parameterType="Long" resultMap="EIntentionResult">
        <include refid="selectEIntentionVo"/>
        where intention_id = #{intentionId}
    </select>

    <select id="selectCount" resultType="java.lang.Integer">
        select count(1) from ss_intention
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <insert id="insertEIntention" parameterType="Intention">
        insert into ss_intention
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="intentionId != null">intention_id,</if>
            <if test="phone != null">phone,</if>
            <if test="name != null">name,</if>
            <if test="reserveInfo != null">reserve_info,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="intentionId != null">#{intentionId},</if>
            <if test="phone != null">#{phone},</if>
            <if test="name != null">#{name},</if>
            <if test="reserveInfo != null">#{reserveInfo},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateEIntention" parameterType="Intention">
        update ss_intention
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where intention_id = #{data.intentionId}
    </update>

    <sql id="updateColumns">
        <if test="data.phone != null">phone = #{data.phone},</if>
        <if test="data.name != null">name = #{data.name},</if>
        <if test="data.reserveInfo != null">reserve_info = #{data.reserveInfo},</if>
        <if test="data.createTime != null">create_time = #{data.createTime},</if>
    </sql>

    <delete id="deleteEIntentionByIntentionId" parameterType="Long">
        delete from ss_intention where intention_id = #{intentionId}
    </delete>

    <delete id="deleteEIntentionByIntentionIds" parameterType="String">
        delete from ss_intention where intention_id in
        <foreach item="intentionId" collection="array" open="(" separator="," close=")">
            #{intentionId}
        </foreach>
    </delete>
</mapper>
