<?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.personnels.mapper.FtbPersonnelsPermissionsMapper">
<!--    分页查询权限信息-->
    <select id="permissionList" resultType="jnpf.model.personnels.vo.authoritys.FtbPermissionInfoVO">
        SELECT a.F_Id as id,a.F_UserName as userName,a.F_Phone as phone,a.F_UserCustomId as userCustomId,a.F_CreatorTime as permissionDate,GROUP_CONCAT(b.F_AuthorityId) as permissionIds,
        a.F_UserId as userId,a.F_OrgNames as orgNamet,a.F_PostNames as postNamet,a.F_PostRankNames as postRankNamet
        FROM ftb_personnels_permissions a JOIN ftb_personnels_permission_user b ON a.F_Id=b.F_PermissionId

<!--        <where>-->
<!--            a.F_Type = #{params.permissionType} and a.F_EnableMark = 0-->
<!--            <if test="params.permissionId != null and params.permissionId != ''">-->
<!--                AND b.F_AuthorityId = #{params.permissionId}-->
<!--            </if>-->
<!--            <if test="params.userId != null and params.userId.size() > 0">-->
<!--                AND a.F_UserId IN-->
<!--                <foreach collection="params.userId" item="item" index="index" open="(" separator="," close=")">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="params.beginTime != null and params.endTime != null">-->
<!--                AND a.F_CreatorTime BETWEEN #{params.beginTime} AND #{params.endTime}-->
<!--            </if>-->
<!--        </where>-->
        GROUP BY a.F_Id
    </select>
<!--    获取顶级权限信息-->
    <select id="getTopLevelPermissions" resultType="jnpf.model.personnels.vo.authoritys.FtbPermissionInfoVO$PermissionsVO">
        SELECT F_AuthorityType as authorityType,F_AuthorityName as authorityName FROM ftb_personnels_authoritys <where>
        <if test="type == null ">
            F_Id IN
            <foreach collection="list" separator="," open="(" close=")" item="item">
                #{item}
            </foreach>
        </if>
        <if test="type != null and type == 1">
            and F_Id IN (
            SELECT
            (
            CASE F_Id
            when '68' THEN '68'
            WHEN '70' THEN '70'
            WHEN '71' THEN '71'
            ELSE
            F_ParentId END
            ) as F_ParentId
            FROM ftb_personnels_authoritys
            WHERE F_Id IN
            <foreach collection="list" separator="," open="(" close=")" item="item">
                #{item}
            </foreach>
            GROUP BY F_ParentId
            )
        </if>
    </where>
    </select>
<!--获取评审权限列表-->
    <select id="getReviewerPermissions" resultType="java.lang.String">
        SELECT F_PermissionId FROM ftb_personnels_permission_user
        WHERE F_AuthorityId IN
        <foreach collection="list" separator="," open="(" close=")" item="item">
            #{item}
        </foreach>
        GROUP BY F_PermissionId
    </select>
<!--    模糊查询权限信息-->
    <select id="rosterFuzzyQuery" resultType="java.lang.String">
        select F_UserId from ftb_personnels_staff_roster where F_Name like CONCAT('%',#{keyword},'%')
        or F_SystemWokerId like CONCAT('%',#{keyword},'%') or F_Phone like CONCAT('%',#{keyword},'%')
    </select>
<!--    根据权限ID查询权限相关信息-->
    <select id="queryFtbPermissionUserVoByAuthorityId"
            resultType="jnpf.model.personnels.vo.authoritys.FtbPermissionUserVO">
        SELECT
        *
        FROM
        (
        SELECT
        a.F_UserId AS userId,
        a.F_UserName AS userName,
        a.F_ScopePermission AS scopePermission,
        a.F_SpecifyOrgIds AS specifyOrgIds,
        GROUP_CONCAT(b.F_AuthorityId ) AS authorityId
        FROM
        ftb_personnels_permissions a JOIN ftb_personnels_permission_user b ON a.F_Id = b.F_PermissionId
        GROUP BY a.F_UserId
        ) as t WHERE
        <foreach collection="athorityIds" separator=" AND " item="athorityId">
            FIND_IN_SET(#{athorityId},authorityId) > 0
        </foreach>
    </select>
</mapper>