<?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.ibs.list.mapper.CustInfoRecordMapper">
    
    <resultMap type="CustInfoRecord" id="CustInfoRecordResult">
        <result property="id"    column="id"    />
        <result property="custName"    column="cust_name"    />
        <result property="lpName"    column="lp_name"    />
        <result property="custPhone"    column="cust_phone"    />
        <result property="custCapital"    column="cust_capital"    />
        <result property="custLocation"    column="cust_location"    />
        <result property="belongBranchId"    column="belong_branch_id"    />
        <result property="belongBranchName"    column="belong_branch_name"    />
        <result property="belongUserId"    column="belong_user_id"    />
        <result property="belongUserName"    column="belong_user_name"    />
        <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="socialCreditCode"    column="social_credit_code"    />
        <result property="tel"    column="tel"    />
        <result property="registerLocation"    column="register_location"    />
        <result property="businessScope"    column="business_scope"    />
        <result property="industry"    column="industry"    />
        <result property="custIdc"    column="cust_idc"    />
        <result property="custGender"    column="cust_gender"    />
        <result property="custAge"    column="cust_age"    />
        <result property="status"    column="status"    />
        <result property="isMarried"    column="is_married"    />
        <result property="custEdu"    column="cust_edu"    />
        <result property="custSalary"    column="cust_salary"    />
        <result property="birthday"    column="birthday"    />
        <result property="jobLocation"    column="job_location"    />
        <result property="custType"    column="cust_type"    />
    </resultMap>

    <sql id="selectCustInfoRecordVo">
        select id, cust_name, lp_name, cust_phone, cust_capital, cust_location, belong_branch_id, belong_branch_name, belong_user_id, belong_user_name, create_by, create_time, update_by, update_time, social_credit_code, tel, register_location, business_scope, industry, cust_idc, cust_gender, cust_age, status, is_married, cust_edu, cust_salary, birthday, job_location, cust_type from cust_info_record
    </sql>

    <select id="selectCustInfoRecordList" parameterType="CustInfoRecord" resultMap="CustInfoRecordResult">
        <include refid="selectCustInfoRecordVo"/>
        <where>  
            <if test="custName != null  and custName != ''"> and cust_name like concat('%', #{custName}, '%')</if>
            <if test="lpName != null  and lpName != ''"> and lp_name like concat('%', #{lpName}, '%')</if>
            <if test="custPhone != null  and custPhone != ''"> and cust_phone = #{custPhone}</if>
            <if test="custCapital != null  and custCapital != ''"> and cust_capital = #{custCapital}</if>
            <if test="custLocation != null  and custLocation != ''"> and cust_location = #{custLocation}</if>
            <if test="belongBranchId != null  and belongBranchId != ''"> and belong_branch_id like concat(#{belongBranchId},'%') </if>
            <if test="belongBranchName != null  and belongBranchName != ''"> and belong_branch_name like concat('%', #{belongBranchName}, '%')</if>
            <if test="belongUserId != null  and belongUserId != ''"> and belong_user_id = #{belongUserId}</if>
            <if test="belongUserName != null  and belongUserName != ''"> and belong_user_name like concat('%', #{belongUserName}, '%')</if>
            <if test="socialCreditCode != null  and socialCreditCode != ''"> and social_credit_code = #{socialCreditCode}</if>
            <if test="tel != null  and tel != ''"> and tel = #{tel}</if>
            <if test="registerLocation != null  and registerLocation != ''"> and register_location = #{registerLocation}</if>
            <if test="businessScope != null  and businessScope != ''"> and business_scope = #{businessScope}</if>
            <if test="industry != null  and industry != ''"> and industry = #{industry}</if>
            <if test="custIdc != null  and custIdc != ''"> and cust_idc = #{custIdc}</if>
            <if test="custGender != null  and custGender != ''"> and cust_gender = #{custGender}</if>
            <if test="custAge != null  and custAge != ''"> and cust_age = #{custAge}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="isMarried != null  and isMarried != ''"> and is_married = #{isMarried}</if>
            <if test="custEdu != null  and custEdu != ''"> and cust_edu = #{custEdu}</if>
            <if test="custSalary != null  and custSalary != ''"> and cust_salary = #{custSalary}</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="jobLocation != null  and jobLocation != ''"> and job_location = #{jobLocation}</if>
            <if test="custType != null  and custType != ''"> and cust_type = #{custType}</if>
        </where>
    </select>

    <select id="selectCustInfoRecordListByCustTypeAndKeywords" parameterType="CustInfoRecord" resultMap="CustInfoRecordResult">
        <include refid="selectCustInfoRecordVo"/>
        <where>
            <if test="deptId != null  and deptId != ''">
                and belong_branch_id in (select dept_id from sys_dept where dept_id = #{deptId}
                or find_in_set(#{deptId},ancestors))
            </if>
            <if test="userName != null  and userName != ''"> and belong_user_id = #{userName}</if>
            <if test="keyword != null  and keyword != ''"> and ( cust_idc like concat('%', #{keyword}, '%') or cust_name like concat('%', #{keyword}, '%')
                or cust_phone like concat('%', #{keyword}, '%') or lp_name like concat('%', #{keyword}, '%'))
            </if>
            <if test="custType != null  and custType != ''"> and cust_type = #{custType}</if>
        </where>
    </select>

    <select id="selectHeadCustInfoRecordListByCustTypeAndKeywords" parameterType="CustInfoRecord" resultMap="CustInfoRecordResult">
        <include refid="selectCustInfoRecordVo"/>
        <where>
            <if test="deptId != null  and deptId != ''">
                and belong_branch_id like concat('%', #{deptId}, '%')
            </if>
            <if test="keyword != null  and keyword != ''"> and ( cust_idc like concat('%', #{keyword}, '%') or cust_name like concat('%', #{keyword}, '%')
                or cust_phone like concat('%', #{keyword}, '%') or lp_name like concat('%', #{keyword}, '%'))
            </if>
            <if test="custType != null  and custType != ''"> and cust_type = #{custType}</if>
        </where>
    </select>

    
    <select id="selectCustInfoRecordById" parameterType="Long" resultMap="CustInfoRecordResult">
        <include refid="selectCustInfoRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertCustInfoRecord" parameterType="CustInfoRecord" useGeneratedKeys="true" keyProperty="id">
        insert into cust_info_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="custName != null">cust_name,</if>
            <if test="lpName != null">lp_name,</if>
            <if test="custPhone != null">cust_phone,</if>
            <if test="custCapital != null">cust_capital,</if>
            <if test="custLocation != null">cust_location,</if>
            <if test="belongBranchId != null">belong_branch_id,</if>
            <if test="belongBranchName != null">belong_branch_name,</if>
            <if test="belongUserId != null">belong_user_id,</if>
            <if test="belongUserName != null">belong_user_name,</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="socialCreditCode != null">social_credit_code,</if>
            <if test="tel != null">tel,</if>
            <if test="registerLocation != null">register_location,</if>
            <if test="businessScope != null">business_scope,</if>
            <if test="industry != null">industry,</if>
            <if test="custIdc != null">cust_idc,</if>
            <if test="custGender != null">cust_gender,</if>
            <if test="custAge != null">cust_age,</if>
            <if test="status != null">status,</if>
            <if test="isMarried != null">is_married,</if>
            <if test="custEdu != null">cust_edu,</if>
            <if test="custSalary != null">cust_salary,</if>
            <if test="birthday != null">birthday,</if>
            <if test="jobLocation != null">job_location,</if>
            <if test="custType != null">cust_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="custName != null">#{custName},</if>
            <if test="lpName != null">#{lpName},</if>
            <if test="custPhone != null">#{custPhone},</if>
            <if test="custCapital != null">#{custCapital},</if>
            <if test="custLocation != null">#{custLocation},</if>
            <if test="belongBranchId != null">#{belongBranchId},</if>
            <if test="belongBranchName != null">#{belongBranchName},</if>
            <if test="belongUserId != null">#{belongUserId},</if>
            <if test="belongUserName != null">#{belongUserName},</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="socialCreditCode != null">#{socialCreditCode},</if>
            <if test="tel != null">#{tel},</if>
            <if test="registerLocation != null">#{registerLocation},</if>
            <if test="businessScope != null">#{businessScope},</if>
            <if test="industry != null">#{industry},</if>
            <if test="custIdc != null">#{custIdc},</if>
            <if test="custGender != null">#{custGender},</if>
            <if test="custAge != null">#{custAge},</if>
            <if test="status != null">#{status},</if>
            <if test="isMarried != null">#{isMarried},</if>
            <if test="custEdu != null">#{custEdu},</if>
            <if test="custSalary != null">#{custSalary},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="jobLocation != null">#{jobLocation},</if>
            <if test="custType != null">#{custType},</if>
         </trim>
    </insert>

    <update id="updateCustInfoRecord" parameterType="CustInfoRecord">
        update cust_info_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="custName != null and custName != ''">cust_name = #{custName},</if>
            <if test="lpName != null">lp_name = #{lpName},</if>
            <if test="custPhone != null">cust_phone = #{custPhone},</if>
            <if test="custCapital != null">cust_capital = #{custCapital},</if>
            <if test="custLocation != null">cust_location = #{custLocation},</if>
            <if test="belongBranchId != null">belong_branch_id = #{belongBranchId},</if>
            <if test="belongBranchName != null">belong_branch_name = #{belongBranchName},</if>
            <if test="belongUserId != null">belong_user_id = #{belongUserId},</if>
            <if test="belongUserName != null">belong_user_name = #{belongUserName},</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="socialCreditCode != null">social_credit_code = #{socialCreditCode},</if>
            <if test="tel != null">tel = #{tel},</if>
            <if test="registerLocation != null">register_location = #{registerLocation},</if>
            <if test="businessScope != null">business_scope = #{businessScope},</if>
            <if test="industry != null">industry = #{industry},</if>
            <if test="custIdc != null">cust_idc = #{custIdc},</if>
            <if test="custGender != null">cust_gender = #{custGender},</if>
            <if test="custAge != null">cust_age = #{custAge},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isMarried != null">is_married = #{isMarried},</if>
            <if test="custEdu != null">cust_edu = #{custEdu},</if>
            <if test="custSalary != null">cust_salary = #{custSalary},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="jobLocation != null">job_location = #{jobLocation},</if>
            <if test="custType != null">cust_type = #{custType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustInfoRecordById" parameterType="Long">
        delete from cust_info_record where id = #{id}
    </delete>

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