<?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.buy507.mall.dao.TmsAdminIstratorDao">
    <resultMap id="BaseResultMap" type="com.buy507.mall.model.TmsAdminIstrator">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="username" jdbcType="VARCHAR" property="userName" />
        <result column="password" jdbcType="VARCHAR" property="password" />
        <result column="icon" jdbcType="VARCHAR" property="icon" />
        <result column="email" jdbcType="VARCHAR" property="email" />
        <result column="nick_name" jdbcType="VARCHAR" property="nickName" />
        <result column="note" jdbcType="VARCHAR" property="note" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="login_time" jdbcType="TIMESTAMP" property="loginTime" />
        <result column="status" jdbcType="INTEGER" property="status" />
    </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>
        </where>
    </sql>
    <sql id="Base_Column_List">
        id, username, password, icon, email, nick_name, note, create_time, login_time, status
    </sql>

    <select id="selectAll" resultType="java.util.HashMap">
        SELECT
              v.id as id,
              v.username as username,
              v.icon as icon,
              v.email as email,
              v.nick_name as nickName,
              v.note as note,
              DATE_FORMAT(v.create_time ,'%Y-%m-%d %H:%i:%s')as createTime,
              DATE_FORMAT(v.login_time ,'%Y-%m-%d %H:%i:%s')as loginTime,
              v.status as status

              FROM ums_admin v
    </select>

    <insert id="insert" parameterType="com.buy507.mall.model.TmsAdminIstrator">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        INSERT INTO ums_admin
            (username,password,icon,email,nick_name,note,create_time,status)
        VALUE
            ( #{userName,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR},#{icon,jdbcType=VARCHAR},
              #{email,jdbcType=VARCHAR},#{nickName,jdbcType=VARCHAR},#{note,jdbcType=VARCHAR},
              #{createTime,jdbcType=TIMESTAMP},#{status,jdbcType=INTEGER})
    </insert>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ums_admin
        where id = #{id,jdbcType=BIGINT}
    </select>

    <update id="updateByPrimaryKeySelective" parameterType="com.buy507.mall.model.TmsAdminIstrator">
        update ums_admin
        <set>
            <if test="userName != null">
                username = #{userName,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                password = #{password,jdbcType=VARCHAR},
            </if>
            <if test="icon != null">
                icon = #{icon,jdbcType=VARCHAR},
            </if>
            <if test="email != null">
                email = #{email,jdbcType=VARCHAR},
            </if>
            <if test="nickName != null">
                nick_name = #{nickName,jdbcType=VARCHAR},
                nick_name = #{nickName,jdbcType=VARCHAR},
                nick_name = #{nickName,jdbcType=VARCHAR},
            </if>
            <if test="note != null">
                note = #{note,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <delete id="deleteByExample" parameterType="com.buy507.mall.model.SmsHomeAdvertiseExample">
        delete from ums_admin
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
    </delete>

</mapper>