<?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.basicData.mapper.TCustomerContactMapper">

    <resultMap type="TCustomerContact" id="TCustomerContactResult">
        <result property="tId" column="t_id"/>
        <result property="fPid" column="f_pid"/>
        <result property="fNo" column="f_no"/>
        <result property="fName" column="f_name"/>
        <result property="fEname" column="f_ename"/>
        <result property="fTel" column="f_tel"/>
        <result property="fDuty" column="f_duty"/>
        <result property="fEmail" column="f_email"/>
        <result property="fWx" column="f_wx"/>
        <result property="fStatus" column="f_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="deptId" column="dept_id"/>
        <result property="userId" column="user_id"/>
    </resultMap>

    <sql id="selectTCustomerContactVo">
        select t_id, f_pid, f_no, f_name, f_ename, f_tel, f_duty, f_email, f_wx, dept_id, user_id, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_customer_contact
    </sql>

    <select id="selectTCustomerContactList" parameterType="TCustomerContact" resultMap="TCustomerContactResult">
        <include refid="selectTCustomerContactVo"/>
        <where>
            <if test="fPid != null ">and f_pid = #{fPid}</if>
            <if test="fNo != null  and fNo != ''">and f_no = #{fNo}</if>
            <if test="fName != null  and fName != ''">and f_name like concat('%', #{fName}, '%')</if>
            <if test="fEname != null  and fEname != ''">and f_ename like concat('%', #{fEname}, '%')</if>
            <if test="fTel != null  and fTel != ''">and f_tel = #{fTel}</if>
            <if test="fDuty != null  and fDuty != ''">and f_duty = #{fDuty}</if>
            <if test="fEmail != null  and fEmail != ''">and f_email = #{fEmail}</if>
            <if test="userId != null  and userId != ''">and user_id = #{userId}</if>
            <if test="fWx != null  and fWx != ''">and f_wx = #{fWx}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
        </where>
    </select>

    <select id="selectTCustomerContactById" parameterType="Long" resultMap="TCustomerContactResult">
        <include refid="selectTCustomerContactVo"/>
        where t_id = #{tId}
    </select>

    <select id="checkTelUnique" parameterType="string" resultType="int">
        select count(t_id) from t_customer_contact where f_tel = #{fTel}
    </select>

    <insert id="insertTCustomerContact" parameterType="TCustomerContact" useGeneratedKeys="true" keyProperty="tId">
        insert into t_customer_contact
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fPid != null">f_pid,</if>
            <if test="fNo != null and fNo != ''">f_no,</if>
            <if test="fName != null and fName != ''">f_name,</if>
            <if test="fEname != null">f_ename,</if>
            <if test="fTel != null">f_tel,</if>
            <if test="fDuty != null">f_duty,</if>
            <if test="fEmail != null">f_email,</if>
            <if test="fWx != null">f_wx,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fPid != null">#{fPid},</if>
            <if test="fNo != null and fNo != ''">#{fNo},</if>
            <if test="fName != null and fName != ''">#{fName},</if>
            <if test="fEname != null">#{fEname},</if>
            <if test="fTel != null">#{fTel},</if>
            <if test="fDuty != null">#{fDuty},</if>
            <if test="fEmail != null">#{fEmail},</if>
            <if test="fWx != null">#{fWx},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</if>
        </trim>
    </insert>

    <update id="updateTCustomerContact" parameterType="TCustomerContact">
        update t_customer_contact
        <trim prefix="SET" suffixOverrides=",">
            <if test="fPid != null">f_pid = #{fPid},</if>
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fName != null and fName != ''">f_name = #{fName},</if>
            <if test="fEname != null">f_ename = #{fEname},</if>
            <if test="fTel != null">f_tel = #{fTel},</if>
            <if test="fDuty != null">f_duty = #{fDuty},</if>
            <if test="fEmail != null">f_email = #{fEmail},</if>
            <if test="fWx != null">f_wx = #{fWx},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where t_id = #{tId}
    </update>

    <delete id="deleteTCustomerContactById" parameterType="Long">
        delete from t_customer_contact where t_id = #{tId}
    </delete>

    <delete id="deleteTCustomerContactByIds" parameterType="String">
        delete from t_customer_contact where t_id in
        <foreach item="tId" collection="array" open="(" separator="," close=")">
            #{tId}
        </foreach>
    </delete>

    <delete id="deleteCustomerContactByCorps" parameterType="Long">
        delete from t_customer_contact where f_pid = #{fPid}
    </delete>

</mapper>