<?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.neusoft.smart.pos.user.persistent.mapper.UserMapper">
    <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.user.persistent.domain.User">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="username" jdbcType="VARCHAR" property="username"/>
        <result column="nickname" jdbcType="VARCHAR" property="nickname"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="role" jdbcType="VARCHAR" property="role"/>
        <result column="org" jdbcType="INTEGER" property="org"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
            AND activated = 1
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        id, username, nickname, password, role, org
    </sql>
    <select id="selectByExample" parameterType="com.neusoft.smart.pos.user.persistent.domain.UserExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from `user_info`
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        <if test="offset != null and limit != null">
            limit ${offset}, ${limit}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from `user_info`
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from `user_info`
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.user.persistent.domain.UserExample">
        delete from `user_info`
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="com.neusoft.smart.pos.user.persistent.domain.User" useGeneratedKeys="true"
            keyProperty="id">
        insert into `user_info` (id, username, nickname, password,
        role, org)
        values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR},
        #{password,jdbcType=VARCHAR},
        #{role,jdbcType=VARCHAR}, #{org,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="com.neusoft.smart.pos.user.persistent.domain.User"
            useGeneratedKeys="true" keyProperty="id">
        insert into `user_info`
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="username != null">
                username,
            </if>
            <if test="nickname != null">
                nickname,
            </if>
            <if test="password != null">
                password,
            </if>
            <if test="role != null">
                role,
            </if>
            <if test="org != null">
                org,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="username != null">
                #{username,jdbcType=VARCHAR},
            </if>
            <if test="nickname != null">
                #{nickname,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                #{password,jdbcType=VARCHAR},
            </if>
            <if test="role != null">
                #{role,jdbcType=VARCHAR},
            </if>
            <if test="org != null">
                #{org,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="com.neusoft.smart.pos.user.persistent.domain.UserExample"
            resultType="java.lang.Integer">
        select count(*) from `user_info`
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update `user_info`
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=INTEGER},
            </if>
            <if test="record.username != null">
                username = #{record.username,jdbcType=VARCHAR},
            </if>
            <if test="record.nickname != null">
                nickname = #{record.nickname,jdbcType=VARCHAR},
            </if>
            <if test="record.password != null">
                password = #{record.password,jdbcType=VARCHAR},
            </if>
            <if test="record.role != null">
                role = #{record.role,jdbcType=VARCHAR},
            </if>
            <if test="record.org != null">
                org = #{record.org,jdbcType=INTEGER},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update `user_info`
        set id = #{record.id,jdbcType=INTEGER},
        username = #{record.username,jdbcType=VARCHAR},
        nickname = #{record.nickname,jdbcType=VARCHAR},
        password = #{record.password,jdbcType=VARCHAR},
        role = #{record.role,jdbcType=VARCHAR},
        org = #{record.org,jdbcType=INTEGER}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.user.persistent.domain.User">
        update `user_info`
        <set>
            <if test="username != null">
                username = #{username,jdbcType=VARCHAR},
            </if>
            <if test="nickname != null">
                nickname = #{nickname,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                password = #{password,jdbcType=VARCHAR},
            </if>
            <if test="role != null">
                role = #{role,jdbcType=VARCHAR},
            </if>
            <if test="org != null">
                org = #{org,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.user.persistent.domain.User">
        update `user_info`
        set username = #{username,jdbcType=VARCHAR},
        nickname = #{nickname,jdbcType=VARCHAR},
        password = #{password,jdbcType=VARCHAR},
        role = #{role,jdbcType=VARCHAR},
        org = #{org,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="deActivate" parameterType="java.lang.Integer">
        update `user_info`
        set activated = 0
        where id = #{id,jdbcType=INTEGER}
    </update>
</mapper>