<?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.fuxi.ws.data.dao.WRightMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WRight">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    <id column="RoleID" jdbcType="INTEGER" property="roleid" />
    <id column="OperatingID" jdbcType="INTEGER" property="operatingid" />
    <result column="Creater" jdbcType="INTEGER" property="creater" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    <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="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    RoleID, OperatingID, Creater
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WRightExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Right
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WRightKey" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Right
    where RoleID = #{roleid,jdbcType=INTEGER}
      and OperatingID = #{operatingid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WRightKey">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    delete from W_Right
    where RoleID = #{roleid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WRight">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    insert into W_Right (RoleID, OperatingID, Creater
      )
    values (#{roleid,jdbcType=INTEGER}, #{operatingid,jdbcType=INTEGER}, #{creater,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WRight">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    insert into W_Right
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="roleid != null">
        RoleID,
      </if>
      <if test="operatingid != null">
        OperatingID,
      </if>
      <if test="creater != null">
        Creater,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="roleid != null">
        #{roleid,jdbcType=INTEGER},
      </if>
      <if test="operatingid != null">
        #{operatingid,jdbcType=INTEGER},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WRightExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    select count(*) from W_Right
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WRight">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    update W_Right
    <set>
      <if test="creater != null">
        Creater = #{creater,jdbcType=INTEGER},
      </if>
    </set>
    where RoleID = #{roleid,jdbcType=INTEGER}
      and OperatingID = #{operatingid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WRight">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon May 18 19:22:32 CST 2015.
    -->
    update W_Right
    set Creater = #{creater,jdbcType=INTEGER}
    where RoleID = #{roleid,jdbcType=INTEGER}
      and OperatingID = #{operatingid,jdbcType=INTEGER}
  </update>
  
  <!-- 插入角色的等价功能（设置时不显示，通过等价功能设置） -->
  <insert id="insertBelongOper" parameterType="java.lang.Integer">
		insert into W_Right (RoleID,OperatingID,Creater)
		select  a.RoleID,b.OperatingID,a.Creater from W_Right a inner join 
		W_Operating b on a.OperatingID=b.BelongOper
		where a.RoleID= #{roleid,jdbcType=INTEGER}
	</insert>
  
  <!-- 通过角色获取菜单权限列表 -->
  <select id="selectByRole" resultType="java.util.LinkedHashMap">
		SELECT a.RoleID,a.OperatingID,b.PoperatingID,
		case a.OperatingID when 203 then (select top 1 ItemValue from W_Config where configid='73') + '列表'
			when 204 then (select top 1 ItemValue from W_Config where configid='74')  + '列表'
			when 103 then (select top 1 ItemValue from W_Config where configid='84')  + '设置'
			when 104 then (select top 1 ItemValue from W_Config where configid='85')  + '设置'
			else b.Operating end as Operating,
		b.OPeratetype,
		replace(b.Event,'this','''a_' + Convert(varchar(6),a.OperatingID) + '''') Event,b.Param
		FROM W_Right AS a INNER JOIN
        W_Operating AS b ON a.OperatingID = b.OperatingID
		where a.RoleID=#{roleid,jdbcType=INTEGER}
		and b.OPeratetype in (0,1)
		order by b.PoperatingID asc,b.ShowIndex asc
	</select>
	
	<!-- 通过角色和菜单模块获取界面按钮权限 -->
  	<select id="selectByModel" resultType="java.util.LinkedHashMap">
		SELECT a.RoleID,a.OperatingID,b.PoperatingID,b.Operating,b.OPeratetype,b.Event,b.Param
		FROM W_Right AS a INNER JOIN
        W_Operating AS b ON a.OperatingID = b.OperatingID
		where a.RoleID=#{roleid,jdbcType=INTEGER} 
		and b.PoperatingID=#{operatingid,jdbcType=INTEGER} 
		and b.OPeratetype=2 
		<if test="showsite != null">
			and b.ShowSite=#{showsite,jdbcType=TINYINT} 
		</if>
		order by b.PoperatingID asc,b.ShowIndex asc
	</select>
	
	<!-- 通过菜单模块获取界面按钮权限 ,无此功能的清除功能事件-->
  	<select id="selectEventByModel" resultType="java.util.LinkedHashMap">
		SELECT a.RoleID,a.OperatingID,b.PoperatingID,b.Operating,b.OPeratetype,
		case when a.RoleID=#{roleid,jdbcType=INTEGER} then b.Event else '' end as Event,b.Param
		FROM W_Operating AS b left JOIN 
		W_Right AS a ON a.OperatingID = b.OperatingID and a.RoleID=#{roleid,jdbcType=INTEGER}
		where b.PoperatingID=#{operatingid,jdbcType=INTEGER} 
		and b.OPeratetype=2 
		<if test="showsite != null">
			and b.ShowSite=#{showsite,jdbcType=TINYINT} 
		</if>
		order by b.PoperatingID asc,b.ShowIndex asc
	</select>
</mapper>