<?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.dgtly.system.mapper.SysUserCustomerAuthorizationMapper">

    <resultMap type="SysUserCustomerAuthorization" id="SysUserCustomerAuthorizationResult">
        <result property="customerCode"    column="customer_code"    />
        <result property="userId"    column="user_id"    />
        <result property="isConsignee"    column="is_consignee"    />
        <result property="isIndependently"    column="is_independently"    />
        <result property="isSelfDelivery"    column="is_self_delivery"    />
        <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="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectSysUserCustomerAuthorizationVo">
        select customer_code, user_id, is_consignee, is_independently, is_self_delivery, create_by, create_time, update_by, update_time, is_delete from sys_user_customer_authorization
    </sql>

    <select id="selectSysUserCustomerAuthorizationList" parameterType="SysUserCustomerAuthorization" resultMap="SysUserCustomerAuthorizationResult">
        <include refid="selectSysUserCustomerAuthorizationVo"/>
        <where>
            <if test="customerCode != null  and customerCode != ''"> and customer_code = #{customerCode}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="isConsignee != null  and isConsignee != ''"> and is_consignee = #{isConsignee}</if>
            <if test="isIndependently != null  and isIndependently != ''"> and is_independently = #{isIndependently}</if>
            <if test="isSelfDelivery != null  and isSelfDelivery != ''"> and is_self_delivery = #{isSelfDelivery}</if>
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
        </where>
    </select>

    <select id="selectSysUserCustomerAuthorizationById" parameterType="String" resultMap="SysUserCustomerAuthorizationResult">
        <include refid="selectSysUserCustomerAuthorizationVo"/>
        where customer_code = #{customerCode}
    </select>

    <insert id="insertSysUserCustomerAuthorization" parameterType="SysUserCustomerAuthorization">
        insert into sys_user_customer_authorization
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="customerCode != null  and customerCode != ''">customer_code,</if>
            <if test="userId != null ">user_id,</if>
            <if test="isConsignee != null  and isConsignee != ''">is_consignee,</if>
            <if test="isIndependently != null  and isIndependently != ''">is_independently,</if>
            <if test="isSelfDelivery != null  and isSelfDelivery != ''">is_self_delivery,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="isDelete != null ">is_delete,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="customerCode != null  and customerCode != ''">#{customerCode},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="isConsignee != null  and isConsignee != ''">#{isConsignee},</if>
            <if test="isIndependently != null  and isIndependently != ''">#{isIndependently},</if>
            <if test="isSelfDelivery != null  and isSelfDelivery != ''">#{isSelfDelivery},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="isDelete != null ">#{isDelete},</if>
         </trim>
    </insert>

    <update id="updateSysUserCustomerAuthorization" parameterType="SysUserCustomerAuthorization">
        update sys_user_customer_authorization
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="isConsignee != null  and isConsignee != ''">is_consignee = #{isConsignee},</if>
            <if test="isIndependently != null  and isIndependently != ''">is_independently = #{isIndependently},</if>
            <if test="isSelfDelivery != null  and isSelfDelivery != ''">is_self_delivery = #{isSelfDelivery},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="isDelete != null ">is_delete = #{isDelete},</if>
        </trim>
        where customer_code = #{customerCode}
    </update>

    <delete id="deleteSysUserCustomerAuthorizationById" parameterType="String">
        delete from sys_user_customer_authorization where customer_code = #{customerCode}
    </delete>

    <delete id="deleteSysUserCustomerAuthorizationByIds" parameterType="String">
        delete from sys_user_customer_authorization where customer_code in
        <foreach item="customerCode" collection="array" open="(" separator="," close=")">
            #{customerCode}
        </foreach>
    </delete>

    <update id="updateAuthorizationByCustomerCodeAndUserId" parameterType="SysUserCustomerAuthorization">
        update sys_user_customer_authorization
        <trim prefix="SET" suffixOverrides=",">
            <if test="isConsignee != null  and isConsignee != ''">is_consignee = #{isConsignee},</if>
            <if test="isIndependently != null  and isIndependently != ''">is_independently = #{isIndependently},</if>
            <if test="isSelfDelivery != null  and isSelfDelivery != ''">is_self_delivery = #{isSelfDelivery},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="isDelete != null ">is_delete = #{isDelete},</if>
        </trim>
        where customer_code = #{customerCode} and user_id = #{userId}
    </update>

    <select id="selectAuthorizationByUserIdAndCustomerCode" parameterType="String" resultMap="SysUserCustomerAuthorizationResult">
        <include refid="selectSysUserCustomerAuthorizationVo"/>
        where customer_code = #{customerCode} and user_id = #{userId}
    </select>

</mapper>
