<?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.css.simulation.resource.server.infra.db.mysql.mapper.RoleMapper" >

    <select id="getRolePageList" parameterType="api.common.pojo.param.system.RoleParam" resultType="api.common.pojo.vo.system.RoleVO">
        SELECT
            id,
            role_name,
            role_code,
            description,
            visible,
            sort
        FROM system_role
        WHERE is_deleted = '0'
        <if test="roleName != null and roleName != ''">
            and role_name like CONCAT('%',#{roleName,jdbcType=VARCHAR},'%')
        </if>
        <if test="roleCode != null and roleCode != ''">
            and role_code like CONCAT('%',#{roleCode,jdbcType=VARCHAR},'%')
        </if>
        <if test="visible != null and visible != ''">
            and visible = #{visible,jdbcType=VARCHAR}
        </if>
        ORDER BY sort
    </select>

    <insert id="insert" parameterType="api.common.pojo.po.system.RolePO">
        INSERT INTO system_role(
            id,
            role_name,
            role_code,
            description,
            visible,
            sort,
            create_time,
            modify_time,
            create_user_id,
            modify_user_id,
            is_deleted
        )
        VALUES(
            #{id,jdbcType=VARCHAR},
            #{roleName,jdbcType=VARCHAR},
            #{roleCode,jdbcType=VARCHAR},
            #{description,jdbcType=VARCHAR},
            #{visible,jdbcType=VARCHAR},
            #{sort,jdbcType=INTEGER},
            #{createTime,jdbcType=TIMESTAMP},
            #{modifyTime,jdbcType=TIMESTAMP},
            #{createUserId,jdbcType=VARCHAR},
            #{modifyUserId,jdbcType=VARCHAR},
            #{isDeleted,jdbcType=VARCHAR}
        )
    </insert>

    <update id="update" parameterType="api.common.pojo.po.system.RolePO">
        update system_role set
            role_name = #{roleName,jdbcType=VARCHAR},
            role_code = #{roleCode,jdbcType=VARCHAR},
            description = #{description,jdbcType=VARCHAR},
            visible = #{visible,jdbcType=VARCHAR},
            sort = #{sort,jdbcType=INTEGER},
            modify_time = #{modifyTime,jdbcType=TIMESTAMP},
            modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="delRoleById" parameterType="api.common.pojo.po.system.RolePO">
        update system_role set
          modify_time = #{modifyTime,jdbcType=TIMESTAMP},
          modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
          is_deleted = #{isDeleted,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="delRoleMenus" parameterType="api.common.pojo.po.system.RoleMenuPO">
        update system_role_menu set
          modify_time = #{modifyTime,jdbcType=TIMESTAMP},
          modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
          is_deleted = #{isDeleted,jdbcType=VARCHAR}
        where role_id = #{roleId,jdbcType=VARCHAR}
    </update>

    <insert id="insertRoleMenus" parameterType="java.util.List">
        insert into system_role_menu(
            id,
            role_id,
            menu_id,
            create_time,
            modify_time,
            create_user_id,
            modify_user_id,
            is_deleted
        ) values
        <foreach collection="list" item="item" separator=",">
          (
            #{item.id,jdbcType=VARCHAR},
            #{item.roleId,jdbcType=VARCHAR},
            #{item.menuId,jdbcType=VARCHAR},
            #{item.createTime,jdbcType=TIMESTAMP},
            #{item.modifyTime,jdbcType=TIMESTAMP},
            #{item.createUserId,jdbcType=VARCHAR},
            #{item.modifyUserId,jdbcType=VARCHAR},
            #{item.isDeleted,jdbcType=VARCHAR}
          )
        </foreach>
    </insert>
</mapper>
