<?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.goafanti.common.dao.RoleResourcesMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.RoleResources">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="role_id" jdbcType="VARCHAR" property="roleId" />
    <result column="resources" jdbcType="INTEGER" property="resources" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    id, role_id, resources, create_time
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.RoleResourcesExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from role_resources
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from role_resources
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    delete from role_resources
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.RoleResourcesExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    delete from role_resources
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.RoleResources">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    insert into role_resources (id, role_id, resources, 
      create_time)
    values (#{id,jdbcType=VARCHAR}, #{roleId,jdbcType=VARCHAR}, #{resources,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.RoleResources">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    insert into role_resources
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="roleId != null">
        role_id,
      </if>
      <if test="resources != null">
        resources,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="roleId != null">
        #{roleId,jdbcType=VARCHAR},
      </if>
      <if test="resources != null">
        #{resources,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.RoleResourcesExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    select count(*) from role_resources
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    update role_resources
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.roleId != null">
        role_id = #{record.roleId,jdbcType=VARCHAR},
      </if>
      <if test="record.resources != null">
        resources = #{record.resources,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    update role_resources
    set id = #{record.id,jdbcType=VARCHAR},
      role_id = #{record.roleId,jdbcType=VARCHAR},
      resources = #{record.resources,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.RoleResources">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    update role_resources
    <set>
      <if test="roleId != null">
        role_id = #{roleId,jdbcType=VARCHAR},
      </if>
      <if test="resources != null">
        resources = #{resources,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.RoleResources">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jun 11 10:45:21 CST 2018.
    -->
    update role_resources
    set role_id = #{roleId,jdbcType=VARCHAR},
      resources = #{resources,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=VARCHAR}
  </update>
   <delete id="deleteResources" parameterType="java.lang.String">
    delete from role_resources
    where role_id = #{rid,jdbcType=VARCHAR}
  </delete>
   
   <select id="checkRid" parameterType="java.lang.String" resultType="java.lang.Integer">
    select count(1) from role_resources
    where role_id = #{rid,jdbcType=VARCHAR}
  </select>
  <select id="selectAdminRoleResources" parameterType="java.lang.String" resultType="java.lang.Integer">
    select c.resources
from admin a left join user_role b on a.id=b.uid 
left join role_resources c on  b.rid=c.role_id
where a.id= #{aid,jdbcType=VARCHAR}
  </select>
  <update id="updateDimissionTransfer" parameterType="java.lang.String">
    <if test="type == 0">
        update  user 
	 set aid=#{transferId,jdbcType=VARCHAR}
	 where aid = #{aid,jdbcType=VARCHAR}
	and share_type = 0
	and status != 1
      </if>
      <if test="type == 2">
	update  user 
		 set information_maintainer=#{transferId,jdbcType=VARCHAR}
		 where information_maintainer = #{aid,jdbcType=VARCHAR}
		and share_type = 0
		and status != 1
      </if>
      <if test="type == 3">
	update t_order
		set salesman_id=#{transferId,jdbcType=VARCHAR}
		WHERE order_type = 0
		and salesman_id=#{aid,jdbcType=VARCHAR}
      </if>
      <if test="type == 4">
	update contract_task
		set task_allocator=#{aid,jdbcType=VARCHAR},
			task_receiver=#{transferId,jdbcType=VARCHAR}
		where task_receiver=#{aid,jdbcType=VARCHAR}	
      </if>
      <if test="type == 5">
		update demand
		set tech_broker_id=#{transferId,jdbcType=VARCHAR}
		where deleted_sign=0
		and tech_broker_id= #{aid,jdbcType=VARCHAR}
      </if>
      <if test="type == 6">
		update achievement
			set tech_broker_id=#{transferId,jdbcType=VARCHAR}
		where deleted_sign=0
		and tech_broker_id= #{aid,jdbcType=VARCHAR}
      </if>
  </update>
  <update id="updateLockRelease" parameterType="java.lang.String">
     update  user_lock_release 
	 set aid=#{transferId,jdbcType=VARCHAR}
	 where aid = #{aid,jdbcType=VARCHAR}
	 and type=#{type,jdbcType=VARCHAR}
	 and status=0
</update>

<select id="selectByRid" parameterType="java.lang.String" resultType="com.goafanti.common.model.RoleResources">
    select
    id,role_id as roleId,resources,create_time as createTime
    from role_resources
    where 1=1
    <if test="rid != null">
     and role_id= #{rid,jdbcType=VARCHAR}
    </if>
    
  </select>
</mapper>