<?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.SysPrintPrinterConfigMapper">

    <resultMap type="SysPrintPrinterConfig" id="SysPrintPrinterConfigResult">
        <result property="printerId"    column="printer_id"    />
        <result property="printerType"    column="printer_type"    />
        <result property="printerName"    column="printer_name"    />
        <result property="brand"    column="brand"    />
        <result property="printerPlace"    column="printer_place"    />
        <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="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="attr1"    column="attr1"    />
        <result property="attr2"    column="attr2"    />
        <result property="attr3"    column="attr3"    />
        <result property="attr4"    column="attr4"    />
        <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="selectSysPrintPrinterConfigVo">
        select printer_id, printer_type, printer_name, brand, printer_place, printer_model, connection_type,
               printer_url, printer_ip, printer_port, enable_flag, status, remark,
               attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from sys_print_printer_config
    </sql>

    <select id="selectSysPrintPrinterConfigList" parameterType="SysPrintPrinterConfig" resultMap="SysPrintPrinterConfigResult">
        <include refid="selectSysPrintPrinterConfigVo"/>
        <where>
            <if test="printerType != null  and printerType != ''"> and printer_type = #{printerType}</if>
            <if test="printerName != null  and printerName != ''"> and printer_name like concat('%', #{printerName}, '%')</if>
            <if test="brand != null  and brand != ''"> and brand = #{brand}</if>
            <if test="printerPlace != null  and printerPlace != ''"> and printer_place = #{printerPlace}</if>
            <if test="printerModel != null  and printerModel != ''"> and printer_model = #{printerModel}</if>
            <if test="connectionType != null  and connectionType != ''"> and connection_type = #{connectionType}</if>
            <if test="printerUrl != null  and printerUrl != ''"> and printer_url = #{printerUrl}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="attr1 != null  and attr1 != ''"> and attr1 = #{attr1}</if>
            <if test="attr2 != null  and attr2 != ''"> and attr2 = #{attr2}</if>
            <if test="attr3 != null "> and attr3 = #{attr3}</if>
            <if test="attr4 != null "> and attr4 = #{attr4}</if>
        </where>
    </select>

    <select id="selectSysPrintPrinterConfigByPrinterId" parameterType="Long" resultMap="SysPrintPrinterConfigResult">
        <include refid="selectSysPrintPrinterConfigVo"/>
        where printer_id = #{printerId}
    </select>

    <insert id="insertSysPrintPrinterConfig" parameterType="SysPrintPrinterConfig" useGeneratedKeys="true" keyProperty="printerId">
        insert into sys_print_printer_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="printerType != null">printer_type,</if>
            <if test="printerName != null and printerName != ''">printer_name,</if>
            <if test="brand != null">brand,</if>
            <if test="printerPlace != null">printer_place,</if>
            <if test="printerModel != null">printer_model,</if>
            <if test="connectionType != null">connection_type,</if>
            <if test="printerUrl != null">printer_url,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="printerIp != null">printer_ip,</if>
            <if test="printerPort != null">printer_port,</if>
            <if test="attr1 != null">attr1,</if>
            <if test="attr2 != null">attr2,</if>
            <if test="attr3 != null">attr3,</if>
            <if test="attr4 != null">attr4,</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="printerType != null">#{printerType},</if>
            <if test="printerName != null and printerName != ''">#{printerName},</if>
            <if test="brand != null">#{brand},</if>
            <if test="printerPlace != null">#{printerPlace},</if>
            <if test="printerModel != null">#{printerModel},</if>
            <if test="connectionType != null">#{connectionType},</if>
            <if test="printerUrl != null">#{printerUrl},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="printerIp != null">#{printerIp},</if>
            <if test="printerPort != null">#{printerPort},</if>
            <if test="attr1 != null">#{attr1},</if>
            <if test="attr2 != null">#{attr2},</if>
            <if test="attr3 != null">#{attr3},</if>
            <if test="attr4 != null">#{attr4},</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="updateSysPrintPrinterConfig" parameterType="SysPrintPrinterConfig">
        update sys_print_printer_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="printerType != null">printer_type = #{printerType},</if>
            <if test="printerName != null and printerName != ''">printer_name = #{printerName},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="printerPlace != null">printer_place = #{printerPlace},</if>
            <if test="printerModel != null">printer_model = #{printerModel},</if>
            <if test="connectionType != null">connection_type = #{connectionType},</if>
            <if test="printerUrl != null">printer_url = #{printerUrl},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="printerIp != null">printer_ip = #{printerIp},</if>
            <if test="printerPort != null">printer_port = #{printerPort},</if>
            <if test="attr1 != null">attr1 = #{attr1},</if>
            <if test="attr2 != null">attr2 = #{attr2},</if>
            <if test="attr3 != null">attr3 = #{attr3},</if>
            <if test="attr4 != null">attr4 = #{attr4},</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 printer_id = #{printerId}
    </update>

    <delete id="deleteSysPrintPrinterConfigByPrinterId" parameterType="Long">
        delete from sys_print_printer_config where printer_id = #{printerId}
    </delete>

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