<?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.custclient.mapper.CustInfoMapper">
    
    <resultMap type="CustInfo" id="CustInfoResult">
        <result property="custId"    column="cust_id"    />
        <result property="name"    column="name"    />
        <result property="phone"    column="phone"    />
        <result property="birthDate"    column="birth_date"    />
        <result property="address"    column="address"    />
        <result property="detailedAddress"    column="detailed_address"    />
        <result property="remarks"    column="remarks"    />
        <result property="source"    column="source"    />
        <result property="type"    column="type"    />
        <result property="state"    column="state"    />
        <result property="becomeCustTime"    column="become_cust_time"    />
        <result property="superintendentId"    column="superintendent_id"    />
        <result property="createId"    column="create_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="modifyId"    column="modify_id"    />
        <result property="modifyTime"    column="modify_time"    />
    </resultMap>

    <sql id="selectCustInfoVo">
        select cust_id, name, phone, birth_date, address, detailed_address, remarks, source, type, state, become_cust_time, superintendent_id, create_id, create_time, modify_id, modify_time from cust_info
    </sql>

    <select id="selectCustInfoList" parameterType="CustInfo" resultMap="CustInfoResult">
        <include refid="selectCustInfoVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="birthDate != null "> and birth_date = #{birthDate}</if>
            <if test="address != null  and address != ''"> and address like concat('%', #{address}, '%')</if>
            <if test="detailedAddress != null  and detailedAddress != ''"> and detailed_address like concat('%', #{detailedAddress}, '%')</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="source != null "> and source = #{source}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="becomeCustTime != null "> and become_cust_time = #{becomeCustTime}</if>
            <if test="superintendentId != null "> and superintendent_id = #{superintendentId}</if>
        </where>
    </select>
    
    <select id="selectCustInfoByCustId" parameterType="Long" resultMap="CustInfoResult">
        <include refid="selectCustInfoVo"/>
        where cust_id = #{custId}
    </select>

    <insert id="insertCustInfo" parameterType="CustInfo">
        insert into cust_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="custId != null">cust_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="birthDate != null">birth_date,</if>
            <if test="address != null">address,</if>
            <if test="detailedAddress != null">detailed_address,</if>
            <if test="remarks != null">remarks,</if>
            <if test="source != null">source,</if>
            <if test="type != null">type,</if>
            <if test="state != null">state,</if>
            <if test="becomeCustTime != null">become_cust_time,</if>
            <if test="superintendentId != null">superintendent_id,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="modifyId != null">modify_id,</if>
            <if test="modifyTime != null">modify_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="custId != null">#{custId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="birthDate != null">#{birthDate},</if>
            <if test="address != null">#{address},</if>
            <if test="detailedAddress != null">#{detailedAddress},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="source != null">#{source},</if>
            <if test="type != null">#{type},</if>
            <if test="state != null">#{state},</if>
            <if test="becomeCustTime != null">#{becomeCustTime},</if>
            <if test="superintendentId != null">#{superintendentId},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="modifyId != null">#{modifyId},</if>
            <if test="modifyTime != null">#{modifyTime},</if>
         </trim>
    </insert>

    <update id="updateCustInfo" parameterType="CustInfo">
        update cust_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="birthDate != null">birth_date = #{birthDate},</if>
            <if test="address != null">address = #{address},</if>
            <if test="detailedAddress != null">detailed_address = #{detailedAddress},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="source != null">source = #{source},</if>
            <if test="type != null">type = #{type},</if>
            <if test="state != null">state = #{state},</if>
            <if test="becomeCustTime != null">become_cust_time = #{becomeCustTime},</if>
            <if test="superintendentId != null">superintendent_id = #{superintendentId},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="modifyId != null">modify_id = #{modifyId},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
        </trim>
        where cust_id = #{custId}
    </update>

    <delete id="deleteCustInfoByCustId" parameterType="Long">
        delete from cust_info where cust_id = #{custId}
    </delete>

    <delete id="deleteCustInfoByCustIds" parameterType="String">
        delete from cust_info where cust_id in 
        <foreach item="custId" collection="array" open="(" separator="," close=")">
            #{custId}
        </foreach>
    </delete>
</mapper>