<?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.ics.system.mapper.SnMapper">
    
    <resultMap type="com.ics.system.domain.Sn" id="SnResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"
                />
        <result property="lastValue"    column="last_value"    />
        <result property="version"    column="version"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSnVo">
        SELECT `id`, `type`, `last_value`, version, create_time, update_time FROM sys_sn
    </sql>
    
    <select id="selectSnByType" resultMap="SnResult">
        <include refid="selectSnVo"/>
        WHERE `type` = #{type}
    </select>

    <update id="updateSn" parameterType="com.ics.system.domain.Sn">
        UPDATE sys_sn
        <trim prefix="SET" suffixOverrides=",">
            <if test="lastValue != null ">`last_value` = #{lastValue},</if>
            <if test="version != null ">`version` = #{version} + 1,</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
        </trim>
        WHERE
            id = #{id}
        AND version = #{version}
    </update>

</mapper>