<?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.CustDeptUserCmpmMapper">
    
    <resultMap type="CustDeptUserCmpm" id="CustDeptUserCmpmResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="outlets"    column="outlets"    />
        <result property="outletsId"    column="outlets_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="nickName"    column="nick_name"    />
        <result property="custId"    column="cust_id"    />
        <result property="custType"    column="cust_type"    />
        <result property="custName"    column="cust_name"    />
        <result property="custIdc"    column="cust_idc"    />
        <result property="codeNoLevel1"    column="code_no_level1"    />
        <result property="codeValueLevel1"    column="code_value_level1"    />
        <result property="codeNoLevel2"    column="code_no_level2"    />
        <result property="codeValueLevel2"    column="code_value_level2"    />
    </resultMap>

    <sql id="selectCustDeptUserCmpmVo">
        select id, dept_id, dept_name, outlets, outlets_id, user_id, user_name, nick_name, cust_id, cust_type, cust_name, cust_idc, code_no_level1, code_value_level1, code_no_level2, code_value_level2 from cust_dept_user_cmpm
    </sql>

    <select id="selectCustDeptUserCmpmList" parameterType="CustDeptUserCmpm" resultMap="CustDeptUserCmpmResult">
        <include refid="selectCustDeptUserCmpmVo"/>
        <where>  
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="outlets != null  and outlets != ''"> and outlets = #{outlets}</if>
            <if test="outletsId != null  and outletsId != ''"> and outlets_id = #{outletsId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="custId != null  and custId != ''"> and cust_id = #{custId}</if>
            <if test="custType != null  and custType != ''"> and cust_type = #{custType}</if>
            <if test="custName != null  and custName != ''"> and cust_name like concat('%', #{custName}, '%')</if>
            <if test="custIdc != null  and custIdc != ''"> and cust_idc = #{custIdc}</if>
            <if test="codeNoLevel1 != null  and codeNoLevel1 != ''"> and code_no_level1 = #{codeNoLevel1}</if>
            <if test="codeValueLevel1 != null "> and code_value_level1 = #{codeValueLevel1}</if>
            <if test="codeNoLevel2 != null  and codeNoLevel2 != ''"> and code_no_level2 = #{codeNoLevel2}</if>
            <if test="codeValueLevel2 != null "> and code_value_level2 = #{codeValueLevel2}</if>
        </where>
    </select>
    
    <select id="selectCustDeptUserCmpmById" parameterType="Long" resultMap="CustDeptUserCmpmResult">
        <include refid="selectCustDeptUserCmpmVo"/>
        where id = #{id}
    </select>

    <insert id="insertCustDeptUserCmpm" parameterType="CustDeptUserCmpm" useGeneratedKeys="true" keyProperty="id">
        insert into cust_dept_user_cmpm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="outlets != null">outlets,</if>
            <if test="outletsId != null">outlets_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="custId != null">cust_id,</if>
            <if test="custType != null">cust_type,</if>
            <if test="custName != null">cust_name,</if>
            <if test="custIdc != null">cust_idc,</if>
            <if test="codeNoLevel1 != null">code_no_level1,</if>
            <if test="codeValueLevel1 != null">code_value_level1,</if>
            <if test="codeNoLevel2 != null">code_no_level2,</if>
            <if test="codeValueLevel2 != null">code_value_level2,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="outlets != null">#{outlets},</if>
            <if test="outletsId != null">#{outletsId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="custId != null">#{custId},</if>
            <if test="custType != null">#{custType},</if>
            <if test="custName != null">#{custName},</if>
            <if test="custIdc != null">#{custIdc},</if>
            <if test="codeNoLevel1 != null">#{codeNoLevel1},</if>
            <if test="codeValueLevel1 != null">#{codeValueLevel1},</if>
            <if test="codeNoLevel2 != null">#{codeNoLevel2},</if>
            <if test="codeValueLevel2 != null">#{codeValueLevel2},</if>
         </trim>
    </insert>

    <update id="updateCustDeptUserCmpm" parameterType="CustDeptUserCmpm">
        update cust_dept_user_cmpm
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="outlets != null">outlets = #{outlets},</if>
            <if test="outletsId != null">outlets_id = #{outletsId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="custId != null">cust_id = #{custId},</if>
            <if test="custType != null">cust_type = #{custType},</if>
            <if test="custName != null">cust_name = #{custName},</if>
            <if test="custIdc != null">cust_idc = #{custIdc},</if>
            <if test="codeNoLevel1 != null">code_no_level1 = #{codeNoLevel1},</if>
            <if test="codeValueLevel1 != null">code_value_level1 = #{codeValueLevel1},</if>
            <if test="codeNoLevel2 != null">code_no_level2 = #{codeNoLevel2},</if>
            <if test="codeValueLevel2 != null">code_value_level2 = #{codeValueLevel2},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustDeptUserCmpmById" parameterType="Long">
        delete from cust_dept_user_cmpm where id = #{id}
    </delete>

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