<?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.vetti.system.mapper.SysSerialNumberInfoMapper">
    
    <resultMap type="SysSerialNumberInfo" id="SysSerialNumberInfoResult">
        <result property="id"    column="id"    />
        <result property="businessType"    column="business_type"    />
        <result property="codePrefix"    column="code_prefix"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="lockFlag"    column="lock_flag"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysSerialNumberInfoVo">
        select id, business_type, code_prefix, serial_number, lock_flag, create_by, create_time, update_by, update_time, remark from sys_serial_number_info
    </sql>

    <select id="selectSysSerialNumberInfoList" parameterType="SysSerialNumberInfo" resultMap="SysSerialNumberInfoResult">
        <include refid="selectSysSerialNumberInfoVo"/>
        <where>  
            <if test="businessType != null  and businessType != ''"> and business_type = #{businessType}</if>
            <if test="codePrefix != null  and codePrefix != ''"> and code_prefix = #{codePrefix}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="lockFlag != null  and lockFlag != ''"> and lock_flag = #{lockFlag}</if>
        </where>
    </select>
    
    <select id="selectSysSerialNumberInfoById" parameterType="Long" resultMap="SysSerialNumberInfoResult">
        <include refid="selectSysSerialNumberInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSysSerialNumberInfo" parameterType="SysSerialNumberInfo" useGeneratedKeys="true" keyProperty="id">
        insert into sys_serial_number_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessType != null">business_type,</if>
            <if test="codePrefix != null">code_prefix,</if>
            <if test="serialNumber != null">serial_number,</if>
            <if test="lockFlag != null">lock_flag,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessType != null">#{businessType},</if>
            <if test="codePrefix != null">#{codePrefix},</if>
            <if test="serialNumber != null">#{serialNumber},</if>
            <if test="lockFlag != null">#{lockFlag},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysSerialNumberInfo" parameterType="SysSerialNumberInfo">
        update sys_serial_number_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessType != null">business_type = #{businessType},</if>
            <if test="codePrefix != null">code_prefix = #{codePrefix},</if>
            <if test="serialNumber != null">serial_number = #{serialNumber},</if>
            <if test="lockFlag != null">lock_flag = #{lockFlag},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysSerialNumberInfoById" parameterType="Long">
        delete from sys_serial_number_info where id = #{id}
    </delete>

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

    <insert id="batchInsertSysSerialNumberInfo">
        insert into sys_serial_number_info( id, business_type, code_prefix, serial_number, lock_flag, create_by, create_time, update_by, update_time, remark,) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.businessType}, #{item.codePrefix}, #{item.serialNumber}, #{item.lockFlag}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark},)
        </foreach>
    </insert>
</mapper>