<?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.lightinit.hsdataportal.mapper.SentryRoleMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataportal.entity.SentryRole">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="rolecode" jdbcType="VARCHAR" property="rolecode" />
    <result column="rolename" jdbcType="VARCHAR" property="rolename" />
    <result column="parentid" jdbcType="BIGINT" property="parentid" />
    <result column="addtiime" jdbcType="TIMESTAMP" property="addtiime" />
    <collection property="children" column="id" ofType="com.lightinit.hsdataportal.entity.Menu" select="com.lightinit.hsdataportal.mapper.SentryRoleMapper.selectByParentId"></collection>
  </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="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, rolecode, rolename, parentid, addtiime
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdataportal.entity.SentryRoleExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from sentry_role
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>
  <select id="selectByParentId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from sentry_role where parentid = #{parentid,jdbcType=BIGINT} ORDER BY id ASC
  </select>
  <select id="selectByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">
    SELECT r.* FROM sentry_role r JOIN admin_role ar ON r.id=ar.roleid JOIN admin a ON ar.userid=a.id WHERE a.username=#{username,jdbcType=VARCHAR}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from sentry_role
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from sentry_role
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataportal.entity.SentryRoleExample">
    delete from sentry_role
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataportal.entity.SentryRole">
    insert into sentry_role (id, rolecode, rolename, 
      parentid, addtiime)
    values (#{id,jdbcType=BIGINT}, #{rolecode,jdbcType=VARCHAR}, #{rolename,jdbcType=VARCHAR}, 
      #{parentid,jdbcType=BIGINT}, #{addtiime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataportal.entity.SentryRole">
    insert into sentry_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="rolecode != null">
        rolecode,
      </if>
      <if test="rolename != null">
        rolename,
      </if>
      <if test="parentid != null">
        parentid,
      </if>
      <if test="addtiime != null">
        addtiime,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="rolecode != null">
        #{rolecode,jdbcType=VARCHAR},
      </if>
      <if test="rolename != null">
        #{rolename,jdbcType=VARCHAR},
      </if>
      <if test="parentid != null">
        #{parentid,jdbcType=BIGINT},
      </if>
      <if test="addtiime != null">
        #{addtiime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataportal.entity.SentryRoleExample" resultType="java.lang.Long">
    select count(*) from sentry_role
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update sentry_role
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.rolecode != null">
        rolecode = #{record.rolecode,jdbcType=VARCHAR},
      </if>
      <if test="record.rolename != null">
        rolename = #{record.rolename,jdbcType=VARCHAR},
      </if>
      <if test="record.parentid != null">
        parentid = #{record.parentid,jdbcType=BIGINT},
      </if>
      <if test="record.addtiime != null">
        addtiime = #{record.addtiime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update sentry_role
    set id = #{record.id,jdbcType=BIGINT},
      rolecode = #{record.rolecode,jdbcType=VARCHAR},
      rolename = #{record.rolename,jdbcType=VARCHAR},
      parentid = #{record.parentid,jdbcType=BIGINT},
      addtiime = #{record.addtiime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataportal.entity.SentryRole">
    update sentry_role
    <set>
      <if test="rolecode != null">
        rolecode = #{rolecode,jdbcType=VARCHAR},
      </if>
      <if test="rolename != null">
        rolename = #{rolename,jdbcType=VARCHAR},
      </if>
      <if test="parentid != null">
        parentid = #{parentid,jdbcType=BIGINT},
      </if>
      <if test="addtiime != null">
        addtiime = #{addtiime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataportal.entity.SentryRole">
    update sentry_role
    set rolecode = #{rolecode,jdbcType=VARCHAR},
      rolename = #{rolename,jdbcType=VARCHAR},
      parentid = #{parentid,jdbcType=BIGINT},
      addtiime = #{addtiime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>