<?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.hw.system.common.mapper.HwPrinterInfoMapper">

    <resultMap type="HwPrinterInfo" id="HwPrinterInfoResult">
        <result property="printerInfoId" column="printer_info_id"/>
        <result property="printerInfoCode" column="printer_info_code"/>
        <result property="printerInfoName" column="printer_info_name"/>
        <result property="printerInfoAddress" column="printer_info_address"/>
        <result property="printerInfoIp" column="printer_info_ip"/>
        <result property="remark" column="remark"/>
        <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="selectHwPrinterInfoVo">
        select printer_info_id,
               printer_info_code,
               printer_info_name,
               printer_info_address,
               printer_info_ip,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from hw_printer_info
    </sql>

    <select id="selectHwPrinterInfoList" parameterType="HwPrinterInfo" resultMap="HwPrinterInfoResult">
        <include refid="selectHwPrinterInfoVo"/>
        <where>
            <if test="printerInfoCode != null  and printerInfoCode != ''">and printer_info_code = #{printerInfoCode}
            </if>
            <if test="printerInfoName != null  and printerInfoName != ''">and printer_info_name like concat('%',
                #{printerInfoName}, '%')
            </if>
            <if test="printerInfoAddress != null  and printerInfoAddress != ''">and printer_info_address like
                concat('%', #{printerInfoAddress}, '%')
            </if>
            <if test="printerInfoIp != null  and printerInfoIp != ''">and printer_info_ip = #{printerInfoIp}</if>
            <if test="remark != null  and remark != ''">and remark = #{remark}</if>
            <if test="createBy != null  and createBy != ''">and create_by = #{createBy}</if>
            <if test="createTime != null ">and create_time = #{createTime}</if>
            <if test="updateBy != null  and updateBy != ''">and update_by = #{updateBy}</if>
            <if test="updateTime != null ">and update_time = #{updateTime}</if>
        </where>
    </select>

    <select id="selectHwPrinterInfoByPrinterInfoId" parameterType="Long" resultMap="HwPrinterInfoResult">
        <include refid="selectHwPrinterInfoVo"/>
        where printer_info_id = #{printerInfoId}
    </select>

    <insert id="insertHwPrinterInfo" parameterType="HwPrinterInfo" useGeneratedKeys="true" keyProperty="printerInfoId">
        insert into hw_printer_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="printerInfoCode != null and printerInfoCode != ''">printer_info_code,</if>
            <if test="printerInfoName != null">printer_info_name,</if>
            <if test="printerInfoAddress != null">printer_info_address,</if>
            <if test="printerInfoIp != null">printer_info_ip,</if>
            <if test="remark != null">remark,</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="printerInfoCode != null and printerInfoCode != ''">#{printerInfoCode},</if>
            <if test="printerInfoName != null">#{printerInfoName},</if>
            <if test="printerInfoAddress != null">#{printerInfoAddress},</if>
            <if test="printerInfoIp != null">#{printerInfoIp},</if>
            <if test="remark != null">#{remark},</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="updateHwPrinterInfo" parameterType="HwPrinterInfo">
        update hw_printer_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="printerInfoCode != null and printerInfoCode != ''">printer_info_code = #{printerInfoCode},</if>
            <if test="printerInfoName != null">printer_info_name = #{printerInfoName},</if>
            <if test="printerInfoAddress != null">printer_info_address = #{printerInfoAddress},</if>
            <if test="printerInfoIp != null">printer_info_ip = #{printerInfoIp},</if>
            <if test="remark != null">remark = #{remark},</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_info_id = #{printerInfoId}
    </update>

    <delete id="deleteHwPrinterInfoByPrinterInfoId" parameterType="Long">
        delete
        from hw_printer_info
        where printer_info_id = #{printerInfoId}
    </delete>

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