<?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.toesbieya.my.mapper.SysRoleMapper">
    <sql id="searchCondition">
        <if test="id!=null">and id=#{id}</if>
        <if test="name!=null and name!=''">and name like "%"#{name}"%"</if>
        <if test="cid!=null">and cid=#{cid}</if>
        <if test="cname!=null and cname!=''">and cname like "%"#{cname}"%"</if>
        <if test="status!=null">and status=#{status}</if>
        <if test="startTime!=null">and ctime <![CDATA[ >= ]]> #{startTime}</if>
        <if test="endTime!=null">and ctime <![CDATA[ <= ]]> #{endTime}</if>
    </sql>
    <insert id="add" parameterType="com.toesbieya.my.model.entity.SysRole">
        insert into sys_role (name, resource_id, cid, cname, ctime, status)
        values (#{name}, #{resource_id}, #{cid}, #{cname}, #{ctime}, #{status})
    </insert>
    <update id="update" parameterType="com.toesbieya.my.model.entity.SysRole">
        update sys_role
        set name=#{name},
        resource_id=#{resource_id},
        status=#{status}
        where id = #{id}
    </update>
    <delete id="del" parameterType="java.lang.Integer">
        delete
        from sys_role
        where id = #{id}
        and status = 0
    </delete>
    <select id="get" resultType="com.toesbieya.my.model.entity.SysRole">
        select *
        from sys_role
        where status = 1
    </select>
    <select id="getAll" resultType="com.toesbieya.my.model.entity.SysRole">
        select *
        from sys_role
    </select>

    <select id="isNameExist" resultType="java.lang.Boolean">
        select if(count(0) > 0, 1, 0)
        from sys_role
        where name = #{name}
        <if test="id!=null">
            and id!=#{id}
        </if>
    </select>
    <select id="search" resultType="com.toesbieya.my.model.entity.SysRole"
            parameterType="com.toesbieya.my.model.vo.search.RoleSearch">
        select *
        from sys_role
        where 1
        <include refid="searchCondition"/>
        order by ctime desc
    </select>
</mapper>