XS03.xml 35.7 KB
Newer Older
wuwenlong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="XS03">


    <!--====================    SQL    include    ======================-->

    <!--根据loginName获取用户的父组是管理组的所有用户组信息-->
    <sql id="queryManagerMembersByLoginNameBase">
        SELECT DISTINCT t3.group_ename
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1, ${platSchema}.XS_USER
        t2, ${platSchema}.XS_USER_GROUP t3
        WHERE t1.MEMBER_ID = t2.USER_ID AND t3.ID = t1.PARENT_ID and t3.group_type = 'MANAGERGROUP' AND t2.LOGIN_NAME =
        #loginName#
    </sql>

    <!--根据登录账号获取其所有管辖组管理的用户组的id-->
    <sql id="queryManagerMembersByLoginName">
        select DISTINCT id from ${platSchema}.XS_USER_GROUP where 1=1
        <isNotEmpty prepend="AND" property="groupType">
            (MANAGE_GROUP_ENAME IN (<include refid="queryManagerMembersByLoginNameBase"/>) OR
            group_ename in (<include refid="queryManagerMembersByLoginNameBase"/>) ) and group_type = 'MANAGERGROUP'
        </isNotEmpty>
        <isEmpty prepend="AND" property="groupType">
            MANAGE_GROUP_ENAME IN (<include refid="queryManagerMembersByLoginNameBase"/>) and group_type !=
            'MANAGERGROUP'
        </isEmpty>
    </sql>

    <!--根据用户登录账号获取其父组为管理组时所管理的用户组的ID(包括所能管理的用户组的子组)-->
    <sql id="getAllManagerGroupsByLoginName">
        WITH TEMP (LEVEL, MEMBER_ID, PARENT_ID, MEMBER_TYPE) AS
        (
        SELECT
        0 AS LEVEL,
        MEMBER_ID,
        PARENT_ID,
        MEMBER_TYPE
        FROM
        ${platSchema}.XS_USER_GROUP_MEMBER
        WHERE
        PARENT_ID IN (<include refid="queryManagerMembersByLoginName"/>)
        UNION ALL
        SELECT
        PARENT.LEVEL + 1,
        CHILD.MEMBER_ID,
        CHILD.PARENT_ID,
        CHILD.MEMBER_TYPE
        FROM TEMP PARENT,
        ${platSchema}.XS_USER_GROUP_MEMBER
        CHILD
        WHERE PARENT.MEMBER_ID = CHILD.PARENT_ID AND LEVEL <![CDATA[<]]> 6
        )
    </sql>

    <sql id="getAllManagerGroupsByLoginNameDetail">
        select id from (<include refid="queryManagerMembersByLoginName"/>) where 1=1
        <isNotEmpty prepend="AND" property="groupType">
            group_type = 'MANAGERGROUP'
        </isNotEmpty>
        <isEmpty prepend="AND" property="groupType">
            group_type != 'MANAGERGROUP'
            UNION
            <include refid="queryManagerMembersByLoginName"/>
            union
            select distinct id from ${platSchema}.XS_USER_GROUP where ( group_type = 'MANAGERGROUP' AND GROUP_ENAME !=
            'ADMIN' and group_ename != 'managerRoot')
            or MANAGE_GROUP_ENAME is null or MANAGE_GROUP_ENAME=''
        </isEmpty>
    </sql>

    <!--根据登录账号获取其所有管辖组管理的用户组的id-->
    <sql id="queryManagerMembersByLoginNameIncludeManagerGroups">
        select DISTINCT id from ${platSchema}.XS_USER_GROUP where
        (MANAGE_GROUP_ENAME IN (<include refid="queryManagerMembersByLoginNameBase"/>) OR
        group_ename in (<include refid="queryManagerMembersByLoginNameBase"/>) )
    </sql>

    <!--根据用户登录账号获取其父组为管理组时所管理的用户组的ID(包括所能管理的用户组的子组)-->
    <sql id="getAllManagerGroupsByLoginNameIncludeManagerGroups">
        WITH TEMP (LEVEL, MEMBER_ID, PARENT_ID, MEMBER_TYPE) AS
        (
        SELECT
        0 AS LEVEL,
        MEMBER_ID,
        PARENT_ID,
        MEMBER_TYPE
        FROM
        ${platSchema}.XS_USER_GROUP_MEMBER
        WHERE
        PARENT_ID IN (<include refid="queryManagerMembersByLoginNameIncludeManagerGroups"/>)
        UNION ALL
        SELECT
        PARENT.LEVEL + 1,
        CHILD.MEMBER_ID,
        CHILD.PARENT_ID,
        CHILD.MEMBER_TYPE
        FROM TEMP PARENT,
        ${platSchema}.XS_USER_GROUP_MEMBER
        CHILD
        WHERE PARENT.MEMBER_ID = CHILD.PARENT_ID AND LEVEL <![CDATA[<]]> 6
        )
    </sql>

    <sql id="getAllManagerGroupsByLoginNameDetailIncludeManagerGroups">
        select id from ${platSchema}.XS_USER_GROUP where id in (
        select DISTINCT parent_id as groupId from TEMP
        UNION SELECT DISTINCT MEMBER_ID as groupId FROM TEMP WHERE MEMBER_TYPE = 'USER_GROUP')
        <isNotEmpty prepend="AND" property="groupType">
            group_type = 'MANAGERGROUP' AND GROUP_ENAME != 'ADMIN' and group_ename != 'managerRoot'
            UNION
            <include refid="queryManagerMembersByLoginName"/>
        </isNotEmpty>
    </sql>
    <!--====================    SQL    include    ======================-->

    <insert id="insert">
        INSERT INTO ${platSchema}.XS_USER_GROUP_MEMBER (
        MEMBER_ID,
        PARENT_ID,
        MEMBER_TYPE,
        SORT_INDEX,
        PATH,
        REC_CREATOR,
        REC_CREATE_TIME,
        REC_REVISOR,
        REC_REVISE_TIME,
        ARCHIVE_FLAG
        ) VALUES (
        #memberId#,
        #parentId#,
        #memberType#,
        #sortIndex#,
        #path#,
        #recCreator#,
        #recCreateTime#,
        #recRevisor#,
        #recReviseTime#,
        #archiveFlag#
        )
    </insert>


    <select id="queryGroupMember" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        SELECT
        MEMBER_ID as "memberId",  <!-- 成员ID -->
        PARENT_ID as "parentId",  <!-- 父节点ID -->
        MEMBER_TYPE as "memberType",  <!-- 授权类别:USER,GROUP -->
        SORT_INDEX as "sortIndex",  <!-- 排序 -->
        PATH as "path",  <!-- 来源 -->
        REC_CREATOR as "recCreator",  <!-- 创建人 -->
        REC_CREATE_TIME as "recCreateTime",  <!-- 创建时间 -->
        REC_REVISOR as "recRevisor",  <!-- 修改人 -->
        REC_REVISE_TIME as "recReviseTime",  <!-- 修改时间 -->
        ARCHIVE_FLAG as "archiveFlag" <!-- 归档标记 -->
        FROM ${platSchema}.XS_USER_GROUP_MEMBER WHERE 1=1
        <isNotEmpty prepend=" AND " property="memberId">
            MEMBER_ID = #memberId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentId">
            PARENT_ID = #parentId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberType">
            MEMBER_TYPE = #memberType#
        </isNotEmpty>
        <dynamic prepend="ORDER BY">
            <isNotEmpty property="orderBy">
                $orderBy$
            </isNotEmpty>
            <isEmpty property="orderBy">
                MEMBER_ID asc,
                PARENT_ID asc
            </isEmpty>
        </dynamic>
    </select>


    <select id="queryNodes" resultClass="java.util.HashMap">
        SELECT
        t1.parent_id as "parent",
        t1.parent_id as "parentId",
        t1.member_id as "label",
        t2.group_cname as "text",
        0 as "leaf",
        t2.group_type as "isManagerGroup"
187 188
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1,
        ${platSchema}.XS_USER_GROUP t2
wuwenlong committed
189 190 191 192
        WHERE
            t1.member_id = t2.ID
        AND t1.parent_id = #parentId#
        AND t2.group_ename != 'ADMIN'
193 194
        <isNotEmpty prepend=" AND " property="accountCode">
            t2.account_code = #accountCode#
wuwenlong committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
        </isNotEmpty>
        <dynamic prepend="ORDER BY">
            <isNotEmpty property="orderBy">
                $orderBy$
            </isNotEmpty>
            <isEmpty property="orderBy">
                t2.SORT_INDEX,t2.GROUP_ENAME asc
            </isEmpty>
        </dynamic>

    </select>

    <select id="queryGroupInfo" resultClass="java.util.HashMap">
        WITH respse(member_id,parent_id) as (
        select member_id,parent_id FROM ${platSchema}.XS_USER_GROUP_MEMBER where parent_id ='root'
        UNION ALL
        SELECT b.member_id,b.parent_id FROM respse a ,${platSchema}.XS_USER_GROUP_MEMBER b WHERE a.member_id =
        b.parent_id
        )
        SELECT
        t1.parent_id as "parentId",
        t1.member_id as "label",
        t2.group_cname as "text",
        0 as "leaf",
        t2.group_type as "isManagerGroup",
        t3.group_cname as "parentText"
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1
        LEFT JOIN ${platSchema}.XS_USER_GROUP t2 ON t2.id = t1.member_id
        LEFT JOIN ${platSchema}.XS_USER_GROUP t3 ON t3.id = t1.parent_id
        WHERE t2.ID IN (SELECT DISTINCT member_id FROM respse) AND t2.GROUP_CNAME LIKE ('%$groupText$%')
        OR t2.GROUP_ENAME LIKE ('%$groupText$%')
        <dynamic prepend="ORDER BY">
            <isNotEmpty property="orderBy">
                $orderBy$
            </isNotEmpty>
            <isEmpty property="orderBy">
                t2.GROUP_ENAME asc
            </isEmpty>
        </dynamic>
    </select>

    <select id="expandPath" resultClass="java.util.HashMap">
        WITH respse(member_id,parent_id) as (
        select member_id,parent_id FROM ${platSchema}.XS_USER_GROUP_MEMBER where member_id =#label# AND parent_id =
        #parentId#
        UNION ALL
        SELECT b.member_id,b.parent_id FROM respse a ,${platSchema}.XS_USER_GROUP_MEMBER b WHERE b.member_id =
        a.parent_id
        )
        SELECT * FROM respse
    </select>

    <select id="countNodes" resultClass="int">
        SELECT count(*) FROM ${platSchema}.XS_USER_GROUP_MEMBER t1,${platSchema}.XS_USER_GROUP t2
        <dynamic prepend=" WHERE ">
            t1.member_id = t2.ID AND
            t1.parent_id = #parentId# and
            t2.group_type != 'MANAGERGROUP'
        </dynamic>
    </select>

    <select id="queryManagerGroupNodes" resultClass="java.util.HashMap">
        SELECT
        t1.parent_id as "parent",
        t1.parent_id as "parentId",
        t1.member_id as "label",
        t2.group_cname as "text",
        0 as "leaf"
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1,${platSchema}.XS_USER_GROUP t2
        WHERE
        t1.member_id = t2.ID
        <isNotEmpty prepend="AND" property="parentId">
            t1.parent_id = #parentId#
        </isNotEmpty>
        <isNotEmpty prepend="AND" property="loginName">
            t1.member_id in (<include refid="getAllManagerGroupsByLoginNameDetail"/>)
        </isNotEmpty>
        <dynamic prepend="ORDER BY">
            <isNotEmpty property="orderBy">
                $orderBy$
            </isNotEmpty>
            <isEmpty property="orderBy">
                t2.GROUP_ENAME asc
            </isEmpty>
        </dynamic>
    </select>

    <select id="queryManagerGroupNodesWithRoot" resultClass="java.util.HashMap">
        SELECT
        'root' as "parent",
        'root' as "parentId",
        id as "label",
        group_cname as "text",
        group_ename as "enametext",
        0 as "leaf"
        FROM ${platSchema}.XS_USER_GROUP
        WHERE 1=1
        <isNotEmpty prepend="AND" property="loginName">
            id in (select DISTINCT id from ${platSchema}.XS_USER_GROUP where MANAGE_GROUP_ENAME IN (
            SELECT DISTINCT t3.group_ename
            FROM ${platSchema}.XS_USER_GROUP_MEMBER t1, ${platSchema}.XS_USER
            t2, ${platSchema}.XS_USER_GROUP t3
            WHERE t1.MEMBER_ID = t2.USER_ID AND t3.ID = t1.PARENT_ID and t3.group_type = 'MANAGERGROUP' AND
            t2.LOGIN_NAME = #loginName#))
        </isNotEmpty>
        <dynamic prepend="ORDER BY">
            <isNotEmpty property="orderBy">
                $orderBy$
            </isNotEmpty>
            <isEmpty property="orderBy">
                GROUP_ENAME asc
            </isEmpty>
        </dynamic>
    </select>

    <select id="queryForMemberGroups" resultClass="java.util.HashMap">
        <isNotEmpty prepend="" property="loginName">
            <include refid="getAllManagerGroupsByLoginName"/>
        </isNotEmpty>
        SELECT
        id as "groupId",
        group_ename as "groupEname",
        group_cname as "groupCname",
        manage_group_ename as "manageGroupEname",
        group_type as "groupType"
        FROM ${platSchema}.XS_USER_GROUP where 1=1 and group_ename != 'ADMIN' and group_ename != 'root'
        and group_ename != 'managerRoot'
        <isNotEmpty prepend=" AND " property="insertParentId">
            id not in (SELECT DISTINCT MEMBER_ID
            FROM ${platSchema}.XS_USER_GROUP_MEMBER WHERE MEMBER_TYPE = 'USER_GROUP' and PARENT_ID = #insertParentId#
            and MEMBER_ID is not null union select #insertParentId# from dual)
        </isNotEmpty>

        <isNotEmpty prepend=" AND " property="groupEname">
            group_ename like ('%$groupEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupCname">
            group_cname like ('%$groupCname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            id in (<include refid="getAllManagerGroupsByLoginNameDetail"/>)
        </isNotEmpty>
337 338
        <isNotEmpty prepend=" AND " property="accountCode">
            account_code = #accountCode#
wuwenlong committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        </isNotEmpty>
    </select>

    <select id="countForMemberGroups" resultClass="int">
        <isNotEmpty prepend="" property="loginName">
            <include refid="getAllManagerGroupsByLoginName"/>
        </isNotEmpty>
        SELECT
        count(*)
        FROM ${platSchema}.XS_USER_GROUP where 1=1 and group_ename != 'ADMIN' and group_ename != 'root'
        and group_ename != 'managerRoot'
        <isNotEmpty prepend=" AND " property="insertParentId">
            id not in (SELECT DISTINCT MEMBER_ID
            FROM ${platSchema}.XS_USER_GROUP_MEMBER WHERE MEMBER_TYPE = 'USER_GROUP' and PARENT_ID = #insertParentId#
            and MEMBER_ID is not null union select #insertParentId# from dual)
        </isNotEmpty>

        <isNotEmpty prepend=" AND " property="groupEname">
            group_ename like ('%$groupEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupCname">
            group_cname like ('%$groupCname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            id in (<include refid="getAllManagerGroupsByLoginNameDetail"/>)
        </isNotEmpty>
365 366
        <isNotEmpty prepend=" AND " property="accountCode">
            account_code = #accountCode#
wuwenlong committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
        </isNotEmpty>
    </select>

    <select id="queryForMemberUsers" resultClass="java.util.HashMap">
        select
        user_id as "userId",
        login_name as "loginName",
        user_name as "userName",
        USER_GROUP_ENAME as "userGroupEname"
        FROM ${platSchema}.XS_USER where 1=1 and login_name != 'admin'
        <isNotEmpty prepend=" AND " property="insertUserParentId">
            USER_ID NOT IN (SELECT DISTINCT MEMBER_ID
            FROM ${platSchema}.XS_USER_GROUP_MEMBER
            WHERE MEMBER_TYPE = 'USER' and PARENT_ID = #insertUserParentId# and MEMBER_ID is not null)
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="userId">
            user_id = #userId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="userName">
            user_name like ('%$userName$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            login_name like ('%$loginName$%')
        </isNotEmpty>
391 392
        <isNotEmpty prepend=" AND " property="accountCode">
            account_code = #accountCode#
wuwenlong committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="sqlCondition">
            ( USER_GROUP_ENAME $sqlCondition$ or USER_GROUP_ENAME is null )
        </isNotEmpty>
    </select>

    <select id="countForMemberUsers" resultClass="int">
        select count(*)
        FROM ${platSchema}.XS_USER where 1=1 and login_name != 'admin'
        <isNotEmpty prepend=" AND " property="insertUserParentId">
            USER_ID NOT IN (SELECT DISTINCT MEMBER_ID
            FROM ${platSchema}.XS_USER_GROUP_MEMBER
            WHERE MEMBER_TYPE = 'USER' and PARENT_ID = #insertUserParentId# and MEMBER_ID is not null)
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="userId">
            user_id = #userId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="userName">
            user_name like ('%$userName$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            login_name like ('%$loginName$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="sqlCondition">
            ( USER_GROUP_ENAME $sqlCondition$ or USER_GROUP_ENAME is null )
        </isNotEmpty>
    </select>

    <select id="query" resultClass="java.util.HashMap">
        <!--<isNotEmpty prepend="" property="loginName">
            <include refid="getAllManagerGroupsByLoginNameIncludeManagerGroups"/>
        </isNotEmpty>-->
        SELECT
        t1.member_id as "memberId",
        t1.parent_id as "parentId",
        t1.member_type as "memberType",
        CASE t1.MEMBER_TYPE
        WHEN 'USER_GROUP' THEN t2.GROUP_CNAME
        ELSE t3.USER_NAME
        END AS "memberName",
        CASE t1.MEMBER_TYPE
        WHEN 'USER_GROUP' THEN t2.GROUP_ENAME
        ELSE t3.LOGIN_NAME
        END AS "memberEname",
        t4.GROUP_ENAME as "parentEname",
        t4.GROUP_CNAME as "parentName",
        t1.sort_index as "sortIndex",
        t1.path as "path",
        t1.rec_creator as "recCreator",
        t1.rec_create_time as "recCreateTime",
        t1.rec_revisor as "recRevisor",
        t1.rec_revise_time as "recReviseTime",
        t1.archive_flag as "archiveFlag"
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1
        LEFT JOIN ${platSchema}.XS_USER_GROUP t2 ON t1.MEMBER_ID=t2.ID
        LEFT JOIN ${platSchema}.XS_USER t3 ON t1.MEMBER_ID = t3.USER_ID
        LEFT JOIN ${platSchema}.XS_USER_GROUP t4 ON t1.PARENT_ID=t4.ID
        where 1=1
        <isNotEmpty prepend=" AND " property="memberId">
            t1.member_id = #memberId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentId">
            t1.parent_id = #parentId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberEname">
            (t2.group_ename like ('%$memberEname$%') or t3.login_name like ('%$memberEname$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberName">
            (t2.group_cname like ('%$memberName$%') or t3.user_name like ('%$memberName$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentName">
            t4.group_cname like ('%$parentName$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentEname">
            t4.group_ename like ('%$parentEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberType">
            t1.member_type = #memberType#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="sqlCondition">
            t3.user_group_ename $sqlCondition$
        </isNotEmpty>
        <!--<isNotEmpty prepend=" AND " property="loginName">
            t1.parent_id in (<include refid="getAllManagerGroupsByLoginNameDetailIncludeManagerGroups"/>)
        </isNotEmpty>-->
        ORDER BY t1.SORT_INDEX,t1.MEMBER_ID,t1.PARENT_ID
    </select>

    <select id="count" resultClass="int">
        <!-- <isNotEmpty prepend="" property="loginName">
             <include refid="getAllManagerGroupsByLoginNameIncludeManagerGroups"/>
         </isNotEmpty>-->
        SELECT count(*) FROM ${platSchema}.XS_USER_GROUP_MEMBER t1
        LEFT JOIN ${platSchema}.XS_USER_GROUP t2 ON t1.MEMBER_ID=t2.ID
        LEFT JOIN ${platSchema}.XS_USER t3 ON t1.MEMBER_ID = t3.USER_ID
        LEFT JOIN ${platSchema}.XS_USER_GROUP t4 ON t1.PARENT_ID=t4.ID
        where 1=1
        <isNotEmpty prepend=" AND " property="memberId">
            member_id = #memberId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentId">
            parent_id = #parentId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberName">
            (t2.group_cname like ('%$memberName$%') or t3.user_name like ('%$memberName$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentName">
            t4.group_cname like ('%$parentName$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="parentEname">
            t4.group_ename like ('%$parentEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberType">
            member_type = #memberType#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="sqlCondition">
            t3.user_group_ename $sqlCondition$
        </isNotEmpty>
        <!--<isNotEmpty prepend=" AND " property="loginName">
            t1.parent_id in (<include refid="getAllManagerGroupsByLoginNameDetailIncludeManagerGroups"/>)
        </isNotEmpty>-->
    </select>

    <update id="update">
        UPDATE ${platSchema}.XS_USER_GROUP_MEMBER
        <dynamic prepend="set">
            <isNotEmpty prepend="," property="memberType">
                member_type = #memberType#
            </isNotEmpty>
            <isNotEmpty prepend="," property="sortIndex">
                sort_index = #sortIndex#
            </isNotEmpty>
            <isNotEmpty prepend="," property="recCreator">
                rec_creator = #recCreator#
            </isNotEmpty>
            <isNotEmpty prepend="," property="recCreateTime">
                rec_create_time = #recCreateTime#
            </isNotEmpty>
            <isNotEmpty prepend="," property="recRevisor">
                rec_revisor = #recRevisor#
            </isNotEmpty>
            <isNotEmpty prepend="," property="recReviseTime">
                rec_revise_time = #recReviseTime#
            </isNotEmpty>
            <isNotEmpty prepend="," property="archiveFlag">
                archive_flag = #archiveFlag#
            </isNotEmpty>
        </dynamic>
        WHERE member_id = #memberId#
        and parent_id = #parentId#
    </update>

    <delete id="delete">
        DELETE FROM ${platSchema}.XS_USER_GROUP_MEMBER
        WHERE member_id = #memberId#
        and parent_id = #parentId#
    </delete>

    <delete id="deleteByMemberId">
        DELETE FROM ${platSchema}.XS_USER_GROUP_MEMBER
        WHERE member_id = #memberId#
    </delete>

    <!--根据组id查询它下面的所有用户和用户组-->
    <select id="selectAllMemberByGroupId" resultClass="java.util.HashMap">
        WITH res (MEMBER_ID, PARENT_ID, MEMBER_TYPE) AS
        (select MEMBER_ID,PARENT_ID,MEMBER_TYPE FROM ${platSchema}.XS_USER_GROUP_MEMBER where PARENT_ID=#memberId#
        UNION ALL
        SELECT b.MEMBER_ID,b.PARENT_ID,b.MEMBER_TYPE FROM res a ,${platSchema}.XS_USER_GROUP_MEMBER b WHERE a.MEMBER_ID
        = b.PARENT_ID
        )
        SELECT t1.LOGIN_NAME as "loginName",t2.GROUP_ENAME as "groupEname" from res
        left join ${platSchema}.XS_USER t1 on res.MEMBER_ID = t1.USER_ID
        left join ${platSchema}.XS_USER_GROUP t2 on res.MEMBER_ID = t2.ID
    </select>

    <!--根据子成员的id查是哪个Ename,但由于前面的操作会把关系数据删除,所以直接查两张表-->
    <select id="queryEnameByMemberId" resultClass="java.util.HashMap">
        select t1.LOGIN_NAME as "subjectEname" from ${platSchema}.XS_USER t1 where t1.USER_ID =#memberId#
        union all
        SELECT t2.GROUP_ENAME as "subjectEname" from ${platSchema}.XS_USER_GROUP t2 where t2.ID =#memberId#
    </select>

    <insert id="insertAdmin">
        INSERT INTO ${platSchema}.XS_USER_GROUP_MEMBER (
        MEMBER_ID,
        PARENT_ID,
        MEMBER_TYPE,
        SORT_INDEX,
        PATH,
        REC_CREATOR,
        REC_CREATE_TIME,
        REC_REVISOR,
        REC_REVISE_TIME,
        ARCHIVE_FLAG
        ) VALUES (
        #memberId#,
        'a4f78cafbe0b451fbc215c5e895e1b4d',
        #memberType#,
        #sortIndex#,
        #path#,
        #recCreator#,
        #recCreateTime#,
        #recRevisor#,
        #recReviseTime#,
        #archiveFlag#
        )
    </insert>

    <select id="queryAdmin" resultClass="java.util.HashMap">
        SELECT
        member_id as "memberId",
        parent_id as "parentId",
        member_type as "memberType",
        CASE t1.MEMBER_TYPE
        WHEN 'USER_GROUP' THEN t2.GROUP_CNAME
        ELSE t3.USER_NAME
        END AS "memberName",
        CASE t1.MEMBER_TYPE
        WHEN 'USER_GROUP' THEN t2.GROUP_ENAME
        ELSE t3.LOGIN_NAME
        END AS "memberEname",
        t4.GROUP_CNAME as "parentName",
        t1.sort_index as "sortIndex",
        t1.path as "path",
        t1.rec_creator as "recCreator",
        t1.rec_create_time as "recCreateTime",
        t1.rec_revisor as "recRevisor",
        t1.rec_revise_time as "recReviseTime",
        t1.archive_flag as "archiveFlag"
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1
        LEFT JOIN ${platSchema}.XS_USER_GROUP t2 ON t1.MEMBER_ID=t2.ID
        LEFT JOIN ${platSchema}.XS_USER t3 ON t1.MEMBER_ID = t3.USER_ID
        LEFT JOIN ${platSchema}.XS_USER_GROUP t4 ON t1.PARENT_ID=t4.ID
        where t1.PARENT_ID='a4f78cafbe0b451fbc215c5e895e1b4d'
        <isNotEmpty prepend=" AND " property="memberEname">
            (t2.group_ename like ('%$memberEname$%') or t3.login_name like ('%$memberEname$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberName">
            (t2.group_cname like ('%$memberName$%') or t3.user_name like ('%$memberName$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberId">
            member_id = #memberId#
        </isNotEmpty>
        ORDER BY t1.SORT_INDEX,t1.MEMBER_ID,t1.PARENT_ID
    </select>

    <select id="countAdmin" resultClass="int">
        SELECT
        count(*)
        FROM ${platSchema}.XS_USER_GROUP_MEMBER t1
        LEFT JOIN ${platSchema}.XS_USER_GROUP t2 ON t1.MEMBER_ID=t2.ID
        LEFT JOIN ${platSchema}.XS_USER t3 ON t1.MEMBER_ID = t3.USER_ID
        LEFT JOIN ${platSchema}.XS_USER_GROUP t4 ON t1.PARENT_ID=t4.ID
        where t1.PARENT_ID='a4f78cafbe0b451fbc215c5e895e1b4d'
        <isNotEmpty prepend=" AND " property="memberEname">
            (t2.group_ename like ('%$memberEname$%') or t3.login_name like ('%$memberEname$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberName">
            (t2.group_cname like ('%$memberName$%') or t3.user_name like ('%$memberName$%'))
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="memberId">
            member_id = #memberId#
        </isNotEmpty>
    </select>
    <!--获取某个用户组的所有父组-->
    <select id="queryParent" resultClass="java.util.HashMap">

        select t3.GROUP_ENAME as "parentEname",
        t3.GROUP_CNAME as "parentCname",
        t2.GROUP_ENAME as "childEname",
        t2.GROUP_CNAME as "childCname"
        from ${platSchema}.XS_USER_GROUP_MEMBER t1
        left join ${platSchema}.XS_USER_GROUP t2 on t1.member_id=t2.id
        left join ${platSchema}.XS_USER_GROUP t3 on t1.parent_id=t3.id
        where member_id=#groupId#

    </select>

    <!--获取用户组的直接子组的信息-->
    <select id="queryMemberGroups" resultClass="java.util.HashMap">
        select id as "groupId",
        GROUP_ENAME as "groupEname",
        GROUP_CNAME AS "groupCname",
        GROUP_TYPE as "groupType",
        MANAGE_GROUP_ENAME as "manageGroupEname"
        FROM ${platSchema}.XS_USER_GROUP WHERE ID IN (
        SELECT DISTINCT t2.MEMBER_ID
        FROM ${platSchema}.XS_USER_GROUP t1, ${platSchema}.XS_USER_GROUP_MEMBER t2
        WHERE t1.ID = t2.PARENT_ID AND t1.ID = #groupId# AND t2.MEMBER_TYPE = 'USER_GROUP')
    </select>

    <select id="countMemberGroups" resultClass="int">
        select count(*)
        FROM ${platSchema}.XS_USER_GROUP WHERE ID IN (
        SELECT DISTINCT t2.MEMBER_ID
        FROM ${platSchema}.XS_USER_GROUP t1, ${platSchema}.XS_USER_GROUP_MEMBER t2
        WHERE t1.ID = t2.PARENT_ID AND t1.ID = #groupId# AND t2.MEMBER_TYPE = 'USER_GROUP')
    </select>

    <select id="queryForMemberGroupsForAuth" resultClass="java.util.HashMap">
        SELECT
        id as "groupId",
        group_ename as "groupEname",
        group_cname as "groupCname",
        manage_group_ename as "manageGroupEname",
        group_type as "groupType"
        FROM ${platSchema}.XS_USER_GROUP where 1=1 and group_ename != 'ADMIN' and group_ename != 'root'
        and group_ename != 'managerRoot'
        <isNotEmpty prepend=" AND " property="insertParentId">
            id not in (SELECT t8.SUBJECT_ID
            FROM ${platSchema}.XS_AUTHORIZATION t8
            WHERE t8.OBJECT_ID = #insertParentId# AND
            t8.SUBJECT_ID IS NOT NULL AND t8.OPERATION_TYPE='ACCESS'
            AND t8.SUBJECT_TYPE='USER_GROUP')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupId">
            id = #groupId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupEname">
            group_ename like ('%$groupEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupCname">
            group_cname like ('%$groupCname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            id in (
            select DISTINCT id from ${platSchema}.XS_USER_GROUP t1
            WHERE t1.GROUP_ENAME IN (
            select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t2
            WHERE t2.MANAGE_GROUP_ENAME IS NULL
            OR t2.MANAGE_GROUP_ENAME=' ' OR t2.GROUP_TYPE='MANAGERGROUP'
            union all select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t3
            WHERE t3.MANAGE_GROUP_ENAME IN (SELECT DISTINCT t4.group_ename
            FROM ${platSchema}.XS_USER_GROUP_MEMBER t5, ${platSchema}.XS_USER t6, ${platSchema}.XS_USER_GROUP t4
            WHERE t5.MEMBER_ID = t6.USER_ID AND t4.ID = t5.PARENT_ID and t4.group_type = 'MANAGERGROUP'
            AND t6.LOGIN_NAME = #loginName#)
            )
            )
        </isNotEmpty>
    </select>

    <select id="countForMemberGroupsForAuth" resultClass="int">
        SELECT
        count(*)
        FROM ${platSchema}.XS_USER_GROUP where 1=1 and group_ename != 'ADMIN' and group_ename != 'root'
        and group_ename != 'managerRoot'
        <isNotEmpty prepend=" AND " property="insertParentId">
            id not in (SELECT t8.SUBJECT_ID
            FROM ${platSchema}.XS_AUTHORIZATION t8
            WHERE t8.OBJECT_ID = #insertParentId# AND
            t8.SUBJECT_ID IS NOT NULL AND t8.OPERATION_TYPE='ACCESS'
            AND t8.SUBJECT_TYPE='USER_GROUP')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupId">
            id = #groupId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupEname">
            group_ename like ('%$groupEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupCname">
            group_cname like ('%$groupCname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            id in (
            select DISTINCT id from ${platSchema}.XS_USER_GROUP t1
            WHERE t1.GROUP_ENAME IN (
            select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t2
            WHERE t2.MANAGE_GROUP_ENAME IS NULL
            OR t2.MANAGE_GROUP_ENAME=' ' OR t2.GROUP_TYPE='MANAGERGROUP'
            union all select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t3
            WHERE t3.MANAGE_GROUP_ENAME IN (SELECT DISTINCT t4.group_ename
            FROM ${platSchema}.XS_USER_GROUP_MEMBER t5, ${platSchema}.XS_USER t6, ${platSchema}.XS_USER_GROUP t4
            WHERE t5.MEMBER_ID = t6.USER_ID AND t4.ID = t5.PARENT_ID and t4.group_type = 'MANAGERGROUP'
            AND t6.LOGIN_NAME = #loginName#)
            )
            )
        </isNotEmpty>
    </select>

    <select id="countForMemberGroupsForModuleAuth" resultClass="int">
        SELECT
        count(*)
        FROM ${platSchema}.XS_USER_GROUP where 1=1 and group_ename != 'ADMIN' and group_ename != 'root'
        and group_ename != 'managerRoot'
        <isNotEmpty prepend=" AND " property="insertParentId">
            id not in (SELECT t8.SUBJECT_ID
            FROM ${platSchema}.XS_AUTHORIZATION t8
            WHERE t8.OBJECT_ID =(select id from ${platSchema}.XS_RESOURCE where resource_ename= #insertParentId#) AND
            t8.SUBJECT_ID IS NOT NULL AND t8.OPERATION_TYPE='ACCESS'
            AND t8.SUBJECT_TYPE='USER_GROUP')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupId">
            id = #groupId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupEname">
            group_ename like ('%$groupEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupCname">
            group_cname like ('%$groupCname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            id in (
            select DISTINCT id from ${platSchema}.XS_USER_GROUP t1
            WHERE t1.GROUP_ENAME IN (
            select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t2
            WHERE t2.MANAGE_GROUP_ENAME IS NULL
            OR t2.MANAGE_GROUP_ENAME=' ' OR t2.GROUP_TYPE='MANAGERGROUP'
            union all select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t3
            WHERE t3.MANAGE_GROUP_ENAME IN (SELECT DISTINCT t4.group_ename
            FROM ${platSchema}.XS_USER_GROUP_MEMBER t5, ${platSchema}.XS_USER t6, ${platSchema}.XS_USER_GROUP t4
            WHERE t5.MEMBER_ID = t6.USER_ID AND t4.ID = t5.PARENT_ID and t4.group_type = 'MANAGERGROUP'
            AND t6.LOGIN_NAME = #loginName#)
            )
            )
        </isNotEmpty>
    </select>

    <select id="queryForMemberGroupsForModuleAuth" resultClass="java.util.HashMap">
        SELECT
        id as "groupId",
        group_ename as "groupEname",
        group_cname as "groupCname",
        manage_group_ename as "manageGroupEname",
        group_type as "groupType"
        FROM ${platSchema}.XS_USER_GROUP where 1=1 and group_ename != 'ADMIN' and group_ename != 'root'
        and group_ename != 'managerRoot'
        <isNotEmpty prepend=" AND " property="insertParentId">
            id not in (SELECT t8.SUBJECT_ID
            FROM ${platSchema}.XS_AUTHORIZATION t8
            WHERE t8.OBJECT_ID =(select id from ${platSchema}.XS_RESOURCE where resource_ename= #insertParentId#) AND
            t8.SUBJECT_ID IS NOT NULL AND t8.OPERATION_TYPE='ACCESS'
            AND t8.SUBJECT_TYPE='USER_GROUP')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupId">
            id = #groupId#
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupEname">
            group_ename like ('%$groupEname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="groupCname">
            group_cname like ('%$groupCname$%')
        </isNotEmpty>
        <isNotEmpty prepend=" AND " property="loginName">
            id in (
            select DISTINCT id from ${platSchema}.XS_USER_GROUP t1
            WHERE t1.GROUP_ENAME IN (
            select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t2
            WHERE t2.MANAGE_GROUP_ENAME IS NULL
            OR t2.MANAGE_GROUP_ENAME=' ' OR t2.GROUP_TYPE='MANAGERGROUP'
            union all select DISTINCT group_ename from ${platSchema}.XS_USER_GROUP t3
            WHERE t3.MANAGE_GROUP_ENAME IN (SELECT DISTINCT t4.group_ename
            FROM ${platSchema}.XS_USER_GROUP_MEMBER t5, ${platSchema}.XS_USER t6, ${platSchema}.XS_USER_GROUP t4
            WHERE t5.MEMBER_ID = t6.USER_ID AND t4.ID = t5.PARENT_ID and t4.group_type = 'MANAGERGROUP'
            AND t6.LOGIN_NAME = #loginName#)
            )
            )
        </isNotEmpty>
    </select>

    <!--用户组拖拽功能 修改夫节点-->
    <update id="dragendUpdate">
        UPDATE ${platSchema}.XS_USER_GROUP_MEMBER
        SET parent_id = #newParentId#
        WHERE member_id = #memberId#
        and parent_id = #parentId#
    </update>


    <!--    查询当前节点子节点-->
    <select id="queryChildInfo" resultClass="java.util.HashMap">
        SELECT MEMBER_ID as "memberId",PARENT_ID as "parentId" FROM ${platSchema}.XS_USER_GROUP_MEMBER WHERE PARENT_ID =
        #parentId# and MEMBER_TYPE = 'USER_GROUP'
    </select>
    <!--    查询当前节点父节点-->
    <select id="queryParentInfo" resultClass="java.util.HashMap">
        SELECT MEMBER_ID as "memberId",PARENT_ID as "parentId" FROM ${platSchema}.XS_USER_GROUP_MEMBER WHERE MEMBER_ID =
        #memberId# and MEMBER_TYPE = 'USER_GROUP'
    </select>

</sqlMap>