<?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="cn.iocoder.yudao.module.rescue.mapper.RescueCustomerInfoMapper">

    <resultMap type="cn.iocoder.yudao.module.rescue.domain.RescueCustomerInfo" id="RescueCustomerInfoResult">
        <result property="id" column="id"/>
        <result property="customerName" column="customer_name"/>
        <result property="customerPhone" column="customer_phone"/>
        <result property="customerDeptId" column="customer_dept_id"/>
        <result property="signStartDate" column="sign_start_date"/>
        <result property="signEndDate" column="sign_end_date"/>
        <result property="orderPrefix" column="order_prefix"/>
        <result property="defaultRescueType" column="default_rescue_type"/>
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
    </resultMap>


    <select id="selectRescueCustomerInfoList" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueCustomerInfo"
            resultMap="RescueCustomerInfoResult">
        select rsi.*,d.name as dept_name from rescue_customer_info rsi
        left join system_dept d on d.id = rsi.customer_dept_id where rsi.deleted = '0'
        <if test="map.customerName != null  and map.customerName != ''">and customer_name like concat('%',
            #{map.customerName}, '%')
        </if>
        <if test="map.customerPhone != null  and map.customerPhone != ''">and customer_phone like concat('%',
            #{map.customerPhone}, '%')
        </if>
        <if test="map.customerDeptId != null ">and customer_dept_id = #{map.customerDeptId}</if>
        <if test="map.signStartDate != null ">and sign_start_date &gt;= #{map.signStartDate}</if>
        <if test="map.signEndDate != null ">and sign_end_date &lt;= #{map.signEndDate}</if>
        <if test="map.defaultRescueType != null  and map.defaultRescueType != ''">and default_rescue_type =
            #{map.defaultRescueType}
        </if>
        order by rsi.create_time desc
    </select>

    <select id="selectRescueCustomerInfoById" parameterType="java.lang.Long" resultMap="RescueCustomerInfoResult">
        select *
        from rescue_customer_info
        where id = #{id}
    </select>

    <insert id="insertRescueCustomerInfo" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueCustomerInfo">
        insert into rescue_customer_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="customerName != null">customer_name,</if>
            <if test="customerPhone != null">customer_phone,</if>
            <if test="customerDeptId != null">customer_dept_id,</if>
            <if test="signStartDate != null">sign_start_date,</if>
            <if test="signEndDate != null">sign_end_date,</if>
            <if test="orderPrefix != null">order_prefix,</if>
            <if test="defaultRescueType != null">default_rescue_type,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="customerName != null">#{customerName},</if>
            <if test="customerPhone != null">#{customerPhone},</if>
            <if test="customerDeptId != null">#{customerDeptId},</if>
            <if test="signStartDate != null">#{signStartDate},</if>
            <if test="signEndDate != null">#{signEndDate},</if>
            <if test="orderPrefix != null">#{orderPrefix},</if>
            <if test="defaultRescueType != null">#{defaultRescueType},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateRescueCustomerInfo" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueCustomerInfo">
        update rescue_customer_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="customerName != null">customer_name = #{customerName},</if>
            <if test="customerPhone != null">customer_phone = #{customerPhone},</if>
            <if test="customerDeptId != null">customer_dept_id = #{customerDeptId},</if>
            <if test="signStartDate != null">sign_start_date = #{signStartDate},</if>
            <if test="signEndDate != null">sign_end_date = #{signEndDate},</if>
            <if test="orderPrefix != null">order_prefix = #{orderPrefix},</if>
            <if test="defaultRescueType != null">default_rescue_type = #{defaultRescueType},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRescueCustomerInfoById" parameterType="java.lang.Long">
        delete
        from rescue_customer_info
        where id = #{id}
    </delete>

    <delete id="deleteRescueCustomerInfoByIds" parameterType="java.lang.String">
        delete from rescue_customer_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>