<?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="cn.roadm.mapper.RoleUrlMapper">

	<resultMap type="RoleUrl" id="RoleUrlResultMapper">
        <id column="id" property="id" />
        <result column="subproductid" property="subproductid" />
        <result column="roleName" property="roleName" />
    </resultMap>
    
    <select id="listPageRoleUrl" parameterType="RoleUrl" resultMap="RoleUrlResultMapper">
        select
        id, subproductid, roleName
        from role_url 
        where 1=1
        <if test="subproductid != null and subproductid != ''">
            and subproductid=#{subproductid}
        </if>
        <if test="roleName!=null and roleName!=''">
            and roleName like CONCAT('%',#{roleName},'%') 
        </if>
    </select>
    
    <select id="getRoleUrl" parameterType="RoleUrl" resultType="RoleUrl">
        select
        id, subproductid, roleName
        from role_url
        <where>
            <if test="id != null and id > 0">
                id=#{id}
            </if>
            <if test="subproductid != null and subproductid != ''">
                and subproductid=#{subproductid}
            </if>
        </where>
    </select>
    
    <select id="getCountBySubproductid" parameterType="RoleUrl" resultType="int">
        select
        count(1)
        from role_url
		where subproductid=#{subproductid}
    </select>
    
    <insert id="insertRoleUrl" useGeneratedKeys="true" keyProperty="id" parameterType="RoleUrl">
        insert into role_url
        (subproductid)
        values
        (#{subproductid})
    </insert>
    
    <update id="updateRoleUrl" parameterType="RoleUrl">
        update role_url set
        roleName=#{roleName}
        where id=#{id}
    </update>
    
    <update id="updateRoleName" parameterType="RoleUrl">
        update res_statistics set
        roleName=#{roleName}
        where subproductid=#{subproductid}
    </update>
    
    
    <delete id="deleteRoleUrl" parameterType="int">
    	delete from role_url where id = #{id}
	</delete>
	
</mapper>