<?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.dgtis.dorm.manager.db.dao.RoleMapper">
  <resultMap id="BaseResultMap" type="com.dgtis.dorm.manager.db.domain.Role">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
    <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
    <result column="modify_user_id" jdbcType="VARCHAR" property="modifyUserId" />
  </resultMap>

  <sql id="Base_Column_List">
    id, role_name, create_time, create_user_id, modify_time, modify_user_id
  </sql>

  <select id="selectByExample" parameterType="com.dgtis.dorm.manager.db.domain.Role" resultMap="BaseResultMap">
    select distinct
    <include refid="Base_Column_List" />
    from zhll_sys_role
    <where>
      <if test="roleName != null and roleName != ''">
        role_name like concat('%', #{roleName}, '%')
      </if>
    </where>
  </select>

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

  <select id="selectAdminUserMenuByAdminId" parameterType="java.lang.Integer" resultType="java.lang.String">
    SELECT DISTINCT
    re.`menu_id`
    FROM
    zhll_sys_admin a
    LEFT JOIN
    `zhll_sys_admin_role` ar ON a.id = ar.admin_id
    LEFT JOIN
    zhll_sys_role_menu re ON ar.`role_id` = re.`role_id`
    WHERE
    a.id = #{id,jdbcType=INTEGER}
  </select>

  <insert id="insertSelective" parameterType="com.dgtis.dorm.manager.db.domain.Role">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into zhll_sys_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="roleName != null">
        role_name,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createUserId != null">
        create_user_id,
      </if>
      <if test="modifyTime != null">
        modify_time,
      </if>
      <if test="modifyUserId != null">
        modify_user_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="roleName != null">
        #{roleName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        #{createUserId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyUserId != null">
        #{modifyUserId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.dgtis.dorm.manager.db.domain.Role">
    update zhll_sys_role
    <set>
      <if test="roleName != null">
        role_name = #{roleName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        create_user_id = #{createUserId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyUserId != null">
        modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from zhll_sys_role
    where id = #{id,jdbcType=INTEGER}
  </delete>

</mapper>