<?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="jnpf.authority.mapper.FtbPermissionRoleMapper">

  <select id="permissionIdentifications" resultType="java.lang.String">
    SELECT
      F_FuncCoding
    FROM
        ftb_permission_role_authorize_person a
        JOIN ftb_permission_role_menu_relation b ON a.F_RoleId = b.F_RoleId
        JOIN ftb_permission_function_menu c ON b.F_RoleMenuConfigId = c.F_Id
        JOIN ftb_permission_role_menu d ON d.F_Id=b.F_RoleMenuId
    WHERE a.F_EnableMark = 0 and d.F_RoleEnabled = 1 and a.F_UserId = #{userId} GROUP BY c.F_Id
  </select>

  <select id="permissionList" resultType="jnpf.model.authority.vo.role.FtbPermissionRoleInfoVO">
      SELECT
          a.F_RoleName as roleName,a.F_Id as roleId,a.F_RoleDescription as roleDescription,a.F_IsSuperAdmin as isSuperAdmin,
          GROUP_CONCAT(CASE WHEN b.F_RoleEnabled = 1 THEN b.F_FunctionWebId END) as functionWebId,
          GROUP_CONCAT(CASE WHEN b.F_RoleEnabled = 1 THEN b.F_FunctionAppId END) as functionAppId,
          GROUP_CONCAT(CASE WHEN b.F_RoleEnabled = 1 THEN b.F_FunctionPcId END) as functionPcId
      FROM
          ftb_permission_role a
          LEFT JOIN ftb_permission_role_menu b ON a.F_Id = b.F_RoleId
      <where>
          a.F_EnableMark = 0
          <if test="params.keyword != null and params.keyword != ''">
              AND (a.F_RoleName LIKE CONCAT('%',#{params.keyword},'%') or a.F_RoleDescription LIKE CONCAT('%',#{params.keyword},'%'))
          </if>
          <if test="params.innerModuleIds != null and params.innerModuleIds.size() > 0">
              AND (
              b.F_FunctionWebId IN
              <foreach collection="params.innerModuleIds" item="moduleId" open="(" close=")" separator=",">
                  #{moduleId}
              </foreach>
              OR
              b.F_FunctionAppId IN
              <foreach collection="params.innerModuleIds" item="moduleId" open="(" close=")" separator=",">
                  #{moduleId}
              </foreach>
              )
          </if>
      </where>
      group by a.F_Id
      <if test="params.innerModuleIds != null and params.innerModuleIds.size() > 0">
          HAVING functionWebId IS NOT NULL AND functionAppId IS NOT NULL
      </if>
      ORDER BY a.F_CreatorTime
  </select>

  <select id="queryJobPermissions" resultType="java.lang.String">
      SELECT
          F_FuncCoding
      FROM
          ftb_permission_role_authorize_post a
              JOIN ftb_permission_role_menu_relation b ON a.F_RoleId = b.F_RoleId
              JOIN ftb_permission_function_menu c ON b.F_RoleMenuConfigId = c.F_Id
              JOIN ftb_permission_role_menu d ON d.F_Id=b.F_RoleMenuId
      WHERE a.F_EnableMark = 0 and d.F_RoleEnabled = 1 and a.F_PostId = #{positionId} GROUP BY c.F_Id
    </select>
</mapper>