<?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.ximai.system.mapper.SysUserAssocintionPrintMapper">

    <resultMap type="SysUserAssocintionPrint" id="SysUserAssocintionPrintResult">
        <result property="userPrintId"    column="user_print_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="nickName"    column="nick_name"    />
        <result property="printerId"    column="printer_id"    />
        <result property="printerName"    column="printer_name"    />
        <result property="printerIp"    column="printer_ip"    />
        <result property="printerPort"    column="printer_port"    />
        <result property="printerType"    column="printer_type"    />
        <result property="printerPlace"    column="printer_place"    />
        <result property="brand"    column="brand"    />
        <result property="status"    column="status"    />
        <result property="printerModel"    column="printer_model"    />
        <result property="connectionType"    column="connection_type"    />
        <result property="printerUrl"    column="printer_url"    />
        <result property="enableFlag"    column="enable_flag"    />
        <result property="printerStatus"    column="printer_status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSysUserAssocintionPrintVo">
        select u.user_print_id,
               u.user_id,
               u.user_name,
               u.nick_name,
               u.printer_id,
               s.printer_name,
               s.printer_ip,
               s.printer_port,
               s.printer_type,
               s.printer_place,
               s.brand,
               u.status,
               s.printer_model,
               s.connection_type,
               s.printer_url,
               s.enable_flag,
               s.status as printer_status,
               s.create_by,
               s.create_time,
               s.update_by,
               s.update_time
        from sys_user_associntion_print u
        left join sys_print_printer_config s on u.printer_id=s.printer_id
    </sql>

    <select id="selectSysUserAssocintionPrintList" parameterType="SysUserAssocintionPrint" resultMap="SysUserAssocintionPrintResult">
        <include refid="selectSysUserAssocintionPrintVo"/>
        <where>
            <if test="userId != null "> and u.user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and u.user_name like concat('%', #{userName}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and u.nick_name like concat('%', #{nickName}, '%')</if>
            <if test="printerId != null "> and u.printer_id = #{printerId}</if>
            <if test="printerName != null  and printerName != ''"> and u.printer_name like concat('%', #{printerName}, '%')</if>
            <if test="printerIp != null  and printerIp != ''"> and s.printer_ip = #{printerIp}</if>
            <if test="printerPort != null "> and s.printer_port = #{printerPort}</if>
            <if test="printerType != null  and printerType != ''"> and s.printer_type = #{printerType}</if>
            <if test="printerPlace != null  and printerPlace != ''"> and s.printer_place = #{printerPlace}</if>
            <if test="brand != null  and brand != ''"> and s.brand = #{brand}</if>
            <if test="status != null "> and u.status = #{status}</if>
            <if test="printerModel != null  and printerModel != ''"> and s.printer_model = #{printerModel}</if>
            <if test="connectionType != null  and connectionType != ''"> and s.connection_type = #{connectionType}</if>
            <if test="printerUrl != null  and printerUrl != ''"> and s.printer_url = #{printerUrl}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and s.enable_flag = #{enableFlag}</if>
            <if test="printerStatus != null  and printerStatus != ''"> and s.printer_status = #{printerStatus}</if>
        </where>
    </select>

    <select id="selectSysUserAssocintionPrintByUserPrintId" parameterType="Long" resultMap="SysUserAssocintionPrintResult">
        <include refid="selectSysUserAssocintionPrintVo"/>
        where user_print_id = #{userPrintId}
    </select>
    <select id="selectSysUserAssocintionPrintByUserPrintIdUserId" parameterType="Long" resultMap="SysUserAssocintionPrintResult">
        <include refid="selectSysUserAssocintionPrintVo"/>
        where u.user_id = #{userId}
    </select>


    <insert id="insertSysUserAssocintionPrint" parameterType="SysUserAssocintionPrint">
        insert into sys_user_associntion_print
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userPrintId != null">user_print_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="printerId != null">printer_id,</if>
            <if test="printerName != null">printer_name,</if>
            <if test="status != null">status,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userPrintId != null">#{userPrintId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="printerId != null">#{printerId},</if>
            <if test="printerName != null">#{printerName},</if>
            <if test="status != null">#{status},</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>
        </trim>
    </insert>

    <update id="updateSysUserAssocintionPrint" parameterType="SysUserAssocintionPrint">
        update sys_user_associntion_print
        <trim prefix="SET" suffixOverrides=",">
            <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="printerId != null">printer_id = #{printerId},</if>
            <if test="printerName != null">printer_name = #{printerName},</if>
            <if test="status != null">status = #{status},</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>
        </trim>
        where user_print_id = #{userPrintId}
    </update>

    <delete id="deleteSysUserAssocintionPrintByUserPrintId" parameterType="Long">
        delete from sys_user_associntion_print where user_print_id = #{userPrintId}
    </delete>

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