<?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.community.huiju.dao.ToSysRoleMapper">
  <resultMap id="BaseResultMap" type="com.community.huiju.model.ToSysRole">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
    <result column="description" jdbcType="VARCHAR" property="description" />
    <result column="status" jdbcType="CHAR" property="status" />
    <result column="create_user" jdbcType="INTEGER" property="createUser" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="update_user" jdbcType="INTEGER" property="updateUser" />
    <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  </resultMap>
  <sql id="Base_Column_List">
    id, role_name, description, status, create_user, create_date, update_user, update_date
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from to_sys_role
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from to_sys_role
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.ToSysRole">
    insert into to_sys_role (id, role_name, description, 
      status, create_user, create_date, 
      update_user, update_date)
    values (#{id,jdbcType=INTEGER}, #{roleName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
      #{status,jdbcType=CHAR}, #{createUser,jdbcType=INTEGER}, #{createDate,jdbcType=TIMESTAMP}, 
      #{updateUser,jdbcType=INTEGER}, #{updateDate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.ToSysRole">
    insert into to_sys_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="roleName != null">
        role_name,
      </if>
      <if test="description != null">
        description,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="createUser != null">
        create_user,
      </if>
      <if test="createDate != null">
        create_date,
      </if>
      <if test="updateUser != null">
        update_user,
      </if>
      <if test="updateDate != null">
        update_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="roleName != null">
        #{roleName,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=CHAR},
      </if>
      <if test="createUser != null">
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null">
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null">
        #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null">
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.ToSysRole">
    update to_sys_role
    <set>
      <if test="roleName != null">
        role_name = #{roleName,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        description = #{description,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=CHAR},
      </if>
      <if test="createUser != null">
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null">
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null">
        update_user = #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null">
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.ToSysRole">
    update to_sys_role
    set role_name = #{roleName,jdbcType=VARCHAR},
      description = #{description,jdbcType=VARCHAR},
      status = #{status,jdbcType=CHAR},
      create_user = #{createUser,jdbcType=INTEGER},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectRoleByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    role.*
     from to_sys_user_role ur left join to_sys_role role on ur.role_id = role.id where ur.user_id=#{userId}
  </select>

</mapper>