<?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.suelec.permission.dao.SysRoleDao">
  <resultMap id="BaseResultMap" type="com.suelec.permission.pojo.SysRole">
    <result column="id" jdbcType="VARCHAR" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="description" jdbcType="VARCHAR" property="description" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="deleted" jdbcType="TINYINT" property="deleted" />
  </resultMap>
  <insert id="insert" parameterType="com.suelec.permission.pojo.SysRole">
    insert into sys_role (id, `name`, description, 
      `status`, create_time, update_time, 
      deleted)
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
      #{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, 
      #{deleted,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" parameterType="com.suelec.permission.pojo.SysRole">
    insert into sys_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="description != null">
        description,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=TINYINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.suelec.permission.pojo.SysRole">
    update sys_role
    <set>
      <if test="name != null">
        name=#{name},
      </if>
      <if test="description != null">
        description=#{description},
      </if>
      <if test="status != null">
        status=#{status},
      </if>
      <if test="createTime != null">
        create_time=#{createTime},
      </if>
      <if test="updateTime != null">
        update_time=#{updateTime},
      </if>
      <if test="deleted != null">
        deleted=#{deleted},
      </if>
    </set>
    where id=#{id}
  </update>

  <!-- 分页查询角色管理数据 -->
  <select id="selectAll" resultType="SysRole" parameterType="com.suelec.permission.vo.req.RolePageReqVo">
    select *
    from sys_role
    <where>
      deleted=1
      <if test="roleId != null and roleId != ''">
        and id=#{roleId}
      </if>
      <if test="roleName != null and roleName != ''">
        and `name` like concat('%',#{roleName},'%')
      </if>
      <if test="status != null and status != ''">
        and status=#{status}
      </if>
      <if test="startTime != null and startTime != ''">
        and create_time &gt;= #{startTime}
      </if>
      <if test="endTime != null and endTime != ''">
        and create_time &lt;= #{endTime}
      </if>
    </where>
  </select>

  <select id="selectByPrimaryKey" resultType="SysRole" parameterType="string">
    select *
    from sys_role
    where id=#{roleId} and deleted=1
  </select>

</mapper>