<?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.slodon.b2b2c.dao.write.system.AdminWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.system.pojo.Admin">
    <id column="admin_id" property="adminId" />
    <result column="admin_name" property="adminName" />
    <result column="password" property="password" />
    <result column="role_id" property="roleId" />
    <result column="role_name" property="roleName" />
    <result column="phone" property="phone" />
    <result column="email" property="email" />
    <result column="state" property="state" />
    <result column="is_super" property="isSuper" />
    <result column="login_time" property="loginTime" />
    <result column="create_admin_id" property="createAdminId" />
    <result column="create_time" property="createTime" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="adminName != null">
        `admin_name`,
      </if>
      <if test="password != null">
        `password`,
      </if>
      <if test="roleId != null">
        `role_id`,
      </if>
      <if test="roleName != null">
        `role_name`,
      </if>
      <if test="phone != null">
        `phone`,
      </if>
      <if test="email != null">
        `email`,
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="isSuper != null">
        `is_super`,
      </if>
      <if test="loginTime != null">
        `login_time`,
      </if>
      <if test="createAdminId != null">
        `create_admin_id`,
      </if>
      <if test="createTime != null">
        `create_time`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `admin_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.adminIdNotEquals != null">
          AND `admin_id` != #{example.adminIdNotEquals}
        </if>
        <if test="example.adminIdIn != null">
          AND `admin_id` in (${example.adminIdIn})
        </if>
        <if test="example.adminName != null">
          AND `admin_name` = #{example.adminName}
        </if>
        <if test="example.adminNameLike != null">
          AND `admin_name` like concat('%',#{example.adminNameLike},'%')
        </if>
        <if test="example.password != null">
          AND `password` = #{example.password}
        </if>
        <if test="example.roleId != null">
          AND `role_id` = #{example.roleId}
        </if>
        <if test="example.roleName != null">
          AND `role_name` = #{example.roleName}
        </if>
        <if test="example.roleNameLike != null">
          AND `role_name` like concat('%',#{example.roleNameLike},'%')
        </if>
        <if test="example.phone != null">
          AND `phone` = #{example.phone}
        </if>
        <if test="example.email != null">
          AND `email` = #{example.email}
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </if>
        <if test="example.stateIn != null">
          AND `state` in (${example.stateIn})
        </if>
        <if test="example.stateNotIn != null">
          AND `state` not in (${example.stateNotIn})
        </if>
        <if test="example.stateNotEquals != null">
          AND `state` != #{example.stateNotEquals}
        </if>
        <if test="example.isSuper != null">
          AND `is_super` = #{example.isSuper}
        </if>
        <if test="example.loginTimeAfter != null">
          AND `login_time` <![CDATA[ >= ]]> #{example.loginTimeAfter}
        </if>
        <if test="example.loginTimeBefore != null">
          AND `login_time` <![CDATA[ <= ]]> #{example.loginTimeBefore}
        </if>
        <if test="example.createAdminId != null">
          AND `create_admin_id` = #{example.createAdminId}
        </if>
        <if test="example.createTimeAfter != null">
          AND `create_time` <![CDATA[ >= ]]> #{example.createTimeAfter}
        </if>
        <if test="example.createTimeBefore != null">
          AND `create_time` <![CDATA[ <= ]]> #{example.createTimeBefore}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `admin_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.system.example.AdminExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `sys_admin`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `sys_admin`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `sys_admin`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `sys_admin`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `sys_admin`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `sys_admin`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM `sys_admin`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `sys_admin`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="admin_id" keyProperty="adminId" parameterType="com.slodon.b2b2c.system.pojo.Admin" useGeneratedKeys="true">
    INSERT INTO `sys_admin`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="adminName != null">
        #{adminName},
      </if>
      <if test="password != null">
        #{password},
      </if>
      <if test="roleId != null">
        #{roleId},
      </if>
      <if test="roleName != null">
        #{roleName},
      </if>
      <if test="phone != null">
        #{phone},
      </if>
      <if test="email != null">
        #{email},
      </if>
      <if test="state != null">
        #{state},
      </if>
      <if test="isSuper != null">
        #{isSuper},
      </if>
      <if test="loginTime != null">
        #{loginTime},
      </if>
      <if test="createAdminId != null">
        #{createAdminId},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `sys_admin`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.adminName != null">
        `admin_name` = #{record.adminName},
      </if>
      <if test="record.password != null">
        `password` = #{record.password},
      </if>
      <if test="record.roleId != null">
        `role_id` = #{record.roleId},
      </if>
      <if test="record.roleName != null">
        `role_name` = #{record.roleName},
      </if>
      <if test="record.phone != null">
        `phone` = #{record.phone},
      </if>
      <if test="record.email != null">
        `email` = #{record.email},
      </if>
      <if test="record.state != null">
        `state` = #{record.state},
      </if>
      <if test="record.isSuper != null">
        `is_super` = #{record.isSuper},
      </if>
      <if test="record.loginTime != null">
        `login_time` = #{record.loginTime},
      </if>
      <if test="record.createAdminId != null">
        `create_admin_id` = #{record.createAdminId},
      </if>
      <if test="record.createTime != null">
        `create_time` = #{record.createTime},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `sys_admin`
    <trim prefix="SET" suffixOverrides=",">
      <if test="adminName != null">
        `admin_name` = #{adminName},
      </if>
      <if test="password != null">
        `password` = #{password},
      </if>
      <if test="roleId != null">
        `role_id` = #{roleId},
      </if>
      <if test="roleName != null">
        `role_name` = #{roleName},
      </if>
      <if test="phone != null">
        `phone` = #{phone},
      </if>
      <if test="email != null">
        `email` = #{email},
      </if>
      <if test="state != null">
        `state` = #{state},
      </if>
      <if test="isSuper != null">
        `is_super` = #{isSuper},
      </if>
      <if test="loginTime != null">
        `login_time` = #{loginTime},
      </if>
      <if test="createAdminId != null">
        `create_admin_id` = #{createAdminId},
      </if>
      <if test="createTime != null">
        `create_time` = #{createTime},
      </if>
    </trim>
    WHERE `admin_id` = #{adminId}
  </update>
</mapper>