<?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.zehong.system.mapper.TSerialNumberInfoMapper">
    
    <resultMap type="TSerialNumberInfo" id="TSerialNumberInfoResult">
        <result property="numberId"    column="number_id"    />
        <result property="tableType"    column="table_type"    />
        <result property="columnName"    column="column_name"    />
        <result property="maxNum"    column="max_num"    />
        <result property="numLength"    column="num_length"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="version"    column="version"    />
        <result property="isDel"    column="is_del"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTSerialNumberInfoVo">
        select number_id, table_type, `column_name`, max_num, num_length, update_time, update_by, version, is_del, remark from t_serial_number_info
    </sql>

    <select id="selectTSerialNumberInfoList" parameterType="TSerialNumberInfo" resultMap="TSerialNumberInfoResult">
        <include refid="selectTSerialNumberInfoVo"/>
        <where>  
            <if test="tableType != null "> and table_type = #{tableType}</if>
            <if test="columnName != null "> and `column_name` like concat('%', #{columnName}, '%')</if>
            <if test="maxNum != null  and maxNum != ''"> and max_num = #{maxNum}</if>
            <if test="numLength != null  and numLength != ''"> and num_length = #{numLength}</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectTSerialNumberInfoById" parameterType="Long" resultMap="TSerialNumberInfoResult">
        <include refid="selectTSerialNumberInfoVo"/>
        where number_id = #{numberId}
    </select>
        
    <insert id="insertTSerialNumberInfo" parameterType="TSerialNumberInfo" useGeneratedKeys="true" keyProperty="numberId">
        insert into t_serial_number_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tableType != null">table_type,</if>
            <if test="columnName != null">`column_name`,</if>
            <if test="maxNum != null">max_num,</if>
            <if test="numLength != null">num_length,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="version != null">version,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tableType != null">#{tableType},</if>
            <if test="columnName != null">#{columnName},</if>
            <if test="maxNum != null">#{maxNum},</if>
            <if test="numLength != null">#{numLength},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="version != null">#{version},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTSerialNumberInfo" parameterType="TSerialNumberInfo">
        update t_serial_number_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="tableType != null">table_type = #{tableType},</if>
            <if test="columnName != null">`column_name` = #{columnName},</if>
            <if test="maxNum != null">max_num = #{maxNum},</if>
            <if test="numLength != null">num_length = #{numLength},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="version != null">version = #{version} + 1,</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where number_id = #{numberId} and version = #{version}
    </update>

    <delete id="deleteTSerialNumberInfoById" parameterType="Long">
        delete from t_serial_number_info where number_id = #{numberId}
    </delete>

    <delete id="deleteTSerialNumberInfoByIds" parameterType="String">
        delete from t_serial_number_info where number_id in 
        <foreach item="numberId" collection="array" open="(" separator="," close=")">
            #{numberId}
        </foreach>
    </delete>
</mapper>