SysRoleMapper.xml 13.9 KB
<?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.glsx.usercenter.mapper.SysRoleMapper">
    <resultMap id="BaseResultMap" type="com.glsx.usercenter.pojo.role.SysRole">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="permission_character" jdbcType="VARCHAR" property="permissionCharacter"/>
        <result column="sort" jdbcType="INTEGER" property="sort"/>
        <result column="role_remark" jdbcType="VARCHAR" property="roleRemark"/>
        <result column="role_status" jdbcType="VARCHAR" property="roleStatus"/>
        <result column="create_by" jdbcType="INTEGER" property="createBy"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_by" jdbcType="INTEGER" property="updateBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <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">
        <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">
        id, name, permission_character, sort, role_remark, role_status, create_by, create_time,
        update_by, update_time
    </sql>
    <select id="selectByExample" parameterType="com.glsx.usercenter.pojo.role.SysRoleExample" resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        'false' as QUERYID,
        <include refid="Base_Column_List"/>
        from sys_role
        <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.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_role
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        DELETE FROM sys_role
        WHERE id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByExample" parameterType="com.glsx.usercenter.pojo.role.SysRoleExample">
        delete from sys_role
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="com.glsx.usercenter.pojo.role.SysRole">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into sys_role (name, permission_character, sort,
        role_remark, role_status, create_by,
        create_time, update_by, update_time
        )
        values (#{name,jdbcType=VARCHAR}, #{permissionCharacter,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER},
        #{roleRemark,jdbcType=VARCHAR}, #{roleStatus,jdbcType=VARCHAR}, #{createBy,jdbcType=INTEGER},
        #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}
        )
    </insert>
    <insert id="insertSelective" parameterType="com.glsx.usercenter.pojo.role.SysRole">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into sys_role
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">
                name,
            </if>
            <if test="permissionCharacter != null">
                permission_character,
            </if>
            <if test="sort != null">
                sort,
            </if>
            <if test="roleRemark != null">
                role_remark,
            </if>
            <if test="roleStatus != null">
                role_status,
            </if>
            <if test="createBy != null">
                create_by,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateBy != null">
                update_by,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="permissionCharacter != null">
                #{permissionCharacter,jdbcType=VARCHAR},
            </if>
            <if test="sort != null">
                #{sort,jdbcType=INTEGER},
            </if>
            <if test="roleRemark != null">
                #{roleRemark,jdbcType=VARCHAR},
            </if>
            <if test="roleStatus != null">
                #{roleStatus,jdbcType=TINYINT},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>

    <update id="updateByExampleSelective" parameterType="map">
        update sys_role
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=INTEGER},
            </if>
            <if test="record.name != null">
                name = #{record.name,jdbcType=VARCHAR},
            </if>
            <if test="record.permissionCharacter != null">
                permission_character = #{record.permissionCharacter,jdbcType=VARCHAR},
            </if>
            <if test="record.sort != null">
                sort = #{record.sort,jdbcType=INTEGER},
            </if>
            <if test="record.roleRemark != null">
                role_remark = #{record.roleRemark,jdbcType=VARCHAR},
            </if>
            <if test="record.roleStatus != null">
                role_status = #{record.roleStatus,jdbcType=VARCHAR},
            </if>
            <if test="record.createBy != null">
                create_by = #{record.createBy,jdbcType=INTEGER},
            </if>
            <if test="record.createTime != null">
                create_time = #{record.createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.updateBy != null">
                update_by = #{record.updateBy,jdbcType=INTEGER},
            </if>
            <if test="record.updateTime != null">
                update_time = #{record.updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update sys_role
        set id = #{record.id,jdbcType=INTEGER},
        name = #{record.name,jdbcType=VARCHAR},
        permission_character = #{record.permissionCharacter,jdbcType=VARCHAR},
        sort = #{record.sort,jdbcType=INTEGER},
        role_remark = #{record.roleRemark,jdbcType=VARCHAR},
        role_status = #{record.roleStatus,jdbcType=VARCHAR},
        create_by = #{record.createBy,jdbcType=INTEGER},
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
        update_by = #{record.updateBy,jdbcType=INTEGER},
        update_time = #{record.updateTime,jdbcType=TIMESTAMP}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.glsx.usercenter.pojo.role.SysRole">
        update sys_role
        <set>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="permissionCharacter != null">
                permission_character = #{permissionCharacter,jdbcType=VARCHAR},
            </if>
            <if test="sort != null">
                sort = #{sort,jdbcType=INTEGER},
            </if>
            <if test="roleRemark != null">
                role_remark = #{roleRemark,jdbcType=VARCHAR},
            </if>
            <if test="roleStatus != null">
                role_status = #{roleStatus,jdbcType=VARCHAR},
            </if>
            <if test="createBy != null">
                create_by = #{createBy,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy,jdbcType=INTEGER},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.glsx.usercenter.pojo.role.SysRole">
        UPDATE sys_role
        SET name                 = #{name,jdbcType=VARCHAR},
            permission_character = #{permissionCharacter,jdbcType=VARCHAR},
            sort                 = #{sort,jdbcType=INTEGER},
            role_remark          = #{roleRemark,jdbcType=VARCHAR},
            role_status          = #{roleStatus,jdbcType=VARCHAR},
            create_by            = #{createBy,jdbcType=INTEGER},
            create_time          = #{createTime,jdbcType=TIMESTAMP},
            update_by            = #{updateBy,jdbcType=INTEGER},
            update_time          = #{updateTime,jdbcType=TIMESTAMP}
        WHERE id = #{id,jdbcType=INTEGER}
    </update>

    <update id="deleteRoleById" parameterType="com.glsx.usercenter.pojo.vo.RoleQueryVo">
        update sys_role
        set role_status = 'sys_user_status_logout',update_by= #{id},update_time= #{time,jdbcType=TIMESTAMP}
        where id in
        <foreach collection="ids" index="index" item="id"
                 separator="," open="(" close=")">
            #{id,jdbcType=TINYINT}
        </foreach>
    </update>

    <select id="getMenuByRoleId" parameterType="java.lang.Integer" resultType="com.glsx.usercenter.pojo.menu.SysMenu">
        SELECT
        sm. NAME,
        sm.id,
        sm.parent_id parentId,
        sm.sort
        FROM
        sys_role_menu srm
        LEFT JOIN sys_menu sm ON srm.menu_id = sm.id
        WHERE sm.menu_status = 1
        <if test="_parameter != 0">
            AND srm.role_id = #{id,jdbcType=INTEGER}
        </if>
    </select>

    <select id="getIdByCharacter" resultType="java.lang.Integer">
        SELECT id
        FROM
            sys_role
        WHERE sys_role.permission_character = #{permissionCharacter,jdbcType=VARCHAR}
    </select>

</mapper>