MerchantStaffMapper.xml 42.4 KB
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 187 188 189 190 191 192 193 194 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 337 338 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 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 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
<?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="cn.com.glsx.merchants.mapper.MerchantStaffMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.merchants.entity.MerchantStaff">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
        <result column="staff_job" jdbcType="VARCHAR" property="staffJob"/>
        <result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
        <result column="visible_inferior_mer" jdbcType="VARCHAR" property="visibleInferiorMer"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
        <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="merchant_id" jdbcType="INTEGER" property="merchantId"/>
        <result column="staff_email" jdbcType="VARCHAR" property="staffEmail"/>
        <result column="staff_code" jdbcType="VARCHAR" property="staffCode"/>
        <result column="created_account" jdbcType="VARCHAR" property="createdAccount"/>
        <result column="we_chat_open_id" jdbcType="VARCHAR" property="weChatOpenId"/>
        <result column="we_chat_union_id" jdbcType="VARCHAR" property="weChatUnionId"/>
        <result column="we_chat_nick_name" jdbcType="VARCHAR" property="weChatNickName"/>
        <result column="we_chat_avatar_url" jdbcType="VARCHAR" property="weChatAvatarUrl"/>
        <result column="we_chat_app_id" jdbcType="VARCHAR" property="weChatAppId"/>
        <result column="we_chat_phone" jdbcType="VARCHAR" property="weChatPhone"/>
        <result column="staff_label" jdbcType="VARCHAR" property="staffLabel"/>
        <result column="department" jdbcType="INTEGER" property="department"/>
        <result column="staff_uuid" jdbcType="VARCHAR" property="staffUuid"/>
    </resultMap>
    <resultMap id="resultMap" type="cn.com.glsx.merchants.model.response.MerchantStaffResponse">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
        <result column="staff_job" jdbcType="VARCHAR" property="staffJob"/>
        <result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="visible_inferior_mer" jdbcType="VARCHAR" property="visibleInferiorMer"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
        <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="merchant_id" jdbcType="INTEGER" property="merchantId"/>
        <result column="staff_email" jdbcType="VARCHAR" property="staffEmail"/>
        <result column="staff_code" jdbcType="VARCHAR" property="staffCode"/>
        <result column="created_account" jdbcType="VARCHAR" property="createdAccount"/>
        <result column="updated_account" jdbcType="VARCHAR" property="updatedAccount"/>
        <result column="merchantName" jdbcType="VARCHAR" property="merchantName"/>
        <result column="roleName" jdbcType="VARCHAR" property="roleName"/>
        <result column="statusName" jdbcType="VARCHAR" property="statusName"/>
        <result column="status" jdbcType="VARCHAR" property="status"/>
        <result column="effective_time" jdbcType="VARCHAR" property="effectiveTime"/>
        <result column="entmicro_name" jdbcType="VARCHAR" property="entmicroName"/>
        <result column="belongingEntmicroName" jdbcType="VARCHAR" property="belongingEntmicroName"/>
        <result column="staff_uuid" jdbcType="VARCHAR" property="uuid"/>
        <result column="we_chat_open_id" jdbcType="VARCHAR" property="weChatOpenId"/>
        <result column="we_chat_union_id" jdbcType="VARCHAR" property="weChatUnionId"/>
        <result column="we_chat_nick_name" jdbcType="VARCHAR" property="weChatNickName"/>
        <result column="we_chat_avatar_url" jdbcType="VARCHAR" property="weChatAvatarUrl"/>
        <result column="we_chat_app_id" jdbcType="VARCHAR" property="weChatAppId"/>
        <result column="we_chat_phone" jdbcType="VARCHAR" property="weChatPhone"/>
        <result column="staff_label" jdbcType="VARCHAR" property="staffLabel"/>
        <result column="department" jdbcType="INTEGER" property="department"/>
        <result column="visual_type" jdbcType="INTEGER" property="visualType"/>
        <result column="visible_merchant_no" jdbcType="VARCHAR" property="visibleMerchantNo"/>
        <result column="created_source" jdbcType="INTEGER" property="createdSource"/>
        <result column="merchantNo" jdbcType="INTEGER" property="merchantNo"/>
        <result column="merchant_legal_person" jdbcType="VARCHAR" property="merchantLegalPerson"/>
        <result column="merchant_legal_person_phone" jdbcType="VARCHAR" property="merchantLegalPersonPhone"/>
        <result column="staff_business_type" jdbcType="INTEGER" property="staffBusinessType"/>
        <result column="mes_verify_flag" jdbcType="INTEGER" property="mesVerifyFlag"/>
    </resultMap>

    <resultMap id="serviceStaffMap" type="cn.com.glsx.merchants.model.response.serviceCenter.SearchMerchantRpcResponse">
        <result column="id" jdbcType="INTEGER" property="merchantId"/>
        <result column="merchantNo" jdbcType="INTEGER" property="merchantNo"/>
        <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
        <result column="login_password" jdbcType="VARCHAR" property="password"/>
        <result column="merchant_legal_person" jdbcType="VARCHAR" property="merchantLegalPerson"/>
        <result column="merchant_legal_person_phone" jdbcType="VARCHAR" property="merchantLegalPersonPhone"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdDate"/>
        <collection property="staffList"
                    ofType="cn.com.glsx.merchants.model.response.serviceCenter.ServiceStaffRpcResponse">
            <result column="staffMerchantNo" jdbcType="INTEGER" property="merchantNo"/>
            <result column="staffMerchantName" jdbcType="VARCHAR" property="merchantName"/>
            <result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
            <result column="staff_phone" jdbcType="VARCHAR" property="staffPhone"/>
            <result column="department" jdbcType="VARCHAR" property="departmentId"/>
            <result column="staff_uuid" jdbcType="VARCHAR" property="staffUuid"/>
            <result column="visual_type" jdbcType="INTEGER" property="visualType"/>
            <result column="we_chat_avatar_url" jdbcType="VARCHAR" property="weChatAvatarUrl"/>
            <result column="visible_merchant_no" jdbcType="VARCHAR" property="visibleMerchantNo"/>
            <result column="staff_created_time" jdbcType="TIMESTAMP" property="createdDate"/>
        </collection>
    </resultMap>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, staff_name, staff_job, staff_phone, staff_password, visible_inferior_mer, created_by,
        created_time, updated_by, updated_time, del_flag, merchant_id, staff_email, staff_code,
        created_account, updated_account,staff_business_type
    </sql>
    <update id="batchInvalidaStaff">

        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update platform_merchant_staff
            <set>
                del_flag = #{item.delFlag}
            </set>
            where id=#{item.id}
        </foreach>
    </update>
    <update id="updateStaffStatusBatch">
        <foreach collection="staffIds" item="item" index="index" open="" close="" separator=";">
            update platform_merchant_staff
            <set>
                del_flag = #{status},
                updated_time=NOW(),
                updated_by=#{updatedBy}
            </set>
            where id = #{item} and del_flag != -1
        </foreach>
    </update>

    <update id="updateStaffBatch">
        <foreach collection="request.staffList" item="item" index="index" open="" close="" separator=";">
            update platform_merchant_staff
            <set>
                staff_name=#{item.staffName},
                updated_time=NOW(),
                updated_by=#{request.updatedBy},
                staff_label=#{item.staffLabel}
            </set>
            where id = #{item.id}
        </foreach>
    </update>

    <update id="updateStaff">
        update platform_merchant_staff
        set updated_time = NOW()
        <if test="request.updatedAccount != null and request.updatedAccount != ''">
            ,updated_account=#{request.updatedAccount}
        </if>
        <if test="request.updatedBy != null">
            ,updated_by=#{request.updatedBy}
        </if>
        <if test="request.visualType != null">
            ,visual_type=#{request.visualType}
        </if>
        <if test="request.staffPhone != null and request.staffPhone != ''">
            ,staff_phone=#{request.staffPhone}
        </if>
        <if test="request.staffBusinessType != null">
            ,staff_business_type=#{request.staffBusinessType}
        </if>
        <if test="request.staffName != null and request.staffName != ''">
            ,staff_name = #{request.staffName}
        </if>
        <if test="request.visibleMerchantNo != null and request.visibleMerchantNo != ''">
            ,visible_merchant_no = #{request.visibleMerchantNo}
        </if>
        where staff_uuid = #{request.staffUuid}
    </update>
    <update id="ineffectiveStaffBatch">
        <foreach collection="staffIds" item="item" index="index" open="" close="" separator=";">
            update platform_merchant_staff
            <set>
                del_flag = #{status},
                updated_time=NOW(),
                updated_account=#{updatedBy}
            </set>
            where id = #{item} and del_flag != -1
        </foreach>
    </update>
    <delete id="deleteMerchant" parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">
        update platform_merchant_staff
        set del_flag= -1,
            updated_time=NOW(),
            updated_account=#{merchantStaffRequest.updatedAccount},
            updated_by=#{merchantStaffRequest.updatedBy}
        WHERE id = #{merchantStaffRequest.id}
    </delete>
    <select id="findMerchantStaff" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">
        select st.id, st.staff_name, st.staff_job, st.staff_phone as staff_phone, st.visible_inferior_mer,
               st.department,st.staff_uuid ,st.we_chat_avatar_url ,st.staff_business_type,
        st.created_by,
        st.created_time, st.updated_by, st.updated_time, st.del_flag, st.merchant_id, st.staff_email,
        st.staff_code,ro.role_name as roleName,pm.merchant_name as merchantName,
        st.effective_time,
        st.entmicro_name,
        pm.merchantNo,
        st.created_name as createdAccount
        from platform_merchant_staff st
        left join platform_merchant_role_staff_relation pr on st.id=pr.staff_id and pr.del_flag=0
        left join platform_merchant_role ro on pr.role_id=ro.id and ro.del_flag=0
        left join platform_merchant pm on st.merchant_id=pm.id and pm.del_flag=0
        where 1=1 and st.del_flag IN (0,2)
        <if test="merchantStaffRequest.id !=null and merchantStaffRequest.id != ''">
            and st.id=#{merchantStaffRequest.id}
        </if>
        <if test="merchantStaffRequest.merchantId !=null and merchantStaffRequest.merchantId != ''">
            and st.merchant_id=#{merchantStaffRequest.merchantId}
        </if>
        <if test="merchantStaffRequest.merchantNo !=null ">
            and pm.merchantNo=#{merchantStaffRequest.merchantNo}
        </if>
        <if test="merchantStaffRequest.keyword!=null and merchantStaffRequest.keyword != ''">
            and (st.staff_name like concat('%', #{merchantStaffRequest.keyword},'%') or st.staff_phone like concat('%',
            #{merchantStaffRequest.keyword},'%'))
        </if>
        <if test="merchantStaffRequest.staffName!=null and merchantStaffRequest.staffName != ''">
            and st.staff_name like concat('%', #{merchantStaffRequest.staffName},'%')
        </if>
        <if test="merchantStaffRequest.staffPhone!=null and merchantStaffRequest.staffPhone != ''">
            and st.staff_phone = #{merchantStaffRequest.staffPhone}
        </if>
        <if test="merchantStaffRequest.staffLableList != null and merchantStaffRequest.staffLableList.size > 0">
            <foreach collection="merchantStaffRequest.staffLableList" item="item" index="index">
                and FIND_IN_SET(#{item},staff_label)
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffPhoneList != null and merchantStaffRequest.staffPhoneList.size > 0">
            and st.staff_phone in
            <foreach collection="merchantStaffRequest.staffPhoneList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffLabelFlag != null and merchantStaffRequest.staffLabelFlag">
            and st.staff_label is not null and st.staff_label != ''
        </if>
        <if test="merchantStaffRequest.roleName != null and merchantStaffRequest.roleName != ''">
            and ro.role_name = #{merchantStaffRequest.roleName}
        </if>
        <if test="merchantStaffRequest.roleNameLike != null and merchantStaffRequest.roleNameLike != ''">
            and ro.role_name like concat('%', #{merchantStaffRequest.roleNameLike},'%')
        </if>
        <if test="merchantStaffRequest.staffUuid != null and merchantStaffRequest.staffUuid != ''">
            and st.staff_uuid = #{merchantStaffRequest.staffUuid}
        </if>
        <if test="merchantStaffRequest.staffUuidList != null and merchantStaffRequest.staffUuidList.size>0">
            and st.staff_uuid in
            <foreach collection="merchantStaffRequest.staffUuidList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.shareStaffUuid != null and merchantStaffRequest.shareStaffUuid != ''">
            and st.share_staff_uuid = #{merchantStaffRequest.shareStaffUuid}
        </if>
        <if test="merchantStaffRequest.merchantNoList != null and merchantStaffRequest.merchantNoList.size > 0">
            and pm.merchantNo in
            <foreach collection="merchantStaffRequest.merchantNoList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffBusinessType != null">
            and st.staff_business_type = #{merchantStaffRequest.staffBusinessType}
        </if>
        <if test="merchantStaffRequest.delFlag != null">
            and st.del_flag = #{merchantStaffRequest.delFlag}
        </if>
        order by st.created_time desc
    </select>

    <select id="findOnJobMerchantStaff" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">
        select st.id, st.staff_name, st.staff_job, st.staff_phone as staff_phone, st.visible_inferior_mer,
        st.department,st.staff_uuid ,st.we_chat_avatar_url ,st.staff_business_type,
        st.created_by,
        st.created_time, st.updated_by, st.updated_time, st.del_flag, st.merchant_id, st.staff_email,
        st.staff_code,ro.role_name as roleName,pm.merchant_name as merchantName,
        st.effective_time,
        st.entmicro_name,
        pm.merchantNo,
        st.created_name as createdAccount
        from platform_merchant_staff st
        inner join beisen_employee_info b on st.staff_phone=CONVERT(b.mobile_phone USING utf8mb4) and b.std_is_deleted=0 and b.zz_status = 0
        left join platform_merchant_role_staff_relation pr on st.id=pr.staff_id and pr.del_flag=0
        left join platform_merchant_role ro on pr.role_id=ro.id and ro.del_flag=0
        left join platform_merchant pm on st.merchant_id=pm.id and pm.del_flag=0
        where 1=1 and st.del_flag IN (0,2)
        <if test="merchantStaffRequest.id !=null and merchantStaffRequest.id != ''">
            and st.id=#{merchantStaffRequest.id}
        </if>
        <if test="merchantStaffRequest.merchantId !=null and merchantStaffRequest.merchantId != ''">
            and st.merchant_id=#{merchantStaffRequest.merchantId}
        </if>
        <if test="merchantStaffRequest.merchantNo !=null ">
            and pm.merchantNo=#{merchantStaffRequest.merchantNo}
        </if>
        <if test="merchantStaffRequest.keyword!=null and merchantStaffRequest.keyword != ''">
            and (st.staff_name like concat('%', #{merchantStaffRequest.keyword},'%') or st.staff_phone like concat('%',
            #{merchantStaffRequest.keyword},'%'))
        </if>
        <if test="merchantStaffRequest.staffName!=null and merchantStaffRequest.staffName != ''">
            and st.staff_name like concat('%', #{merchantStaffRequest.staffName},'%')
        </if>
        <if test="merchantStaffRequest.staffPhone!=null and merchantStaffRequest.staffPhone != ''">
            and st.staff_phone = #{merchantStaffRequest.staffPhone}
        </if>
        <if test="merchantStaffRequest.staffLableList != null and merchantStaffRequest.staffLableList.size > 0">
            <foreach collection="merchantStaffRequest.staffLableList" item="item" index="index">
                and FIND_IN_SET(#{item},staff_label)
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffPhoneList != null and merchantStaffRequest.staffPhoneList.size > 0">
            and st.staff_phone in
            <foreach collection="merchantStaffRequest.staffPhoneList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffLabelFlag != null and merchantStaffRequest.staffLabelFlag">
            and st.staff_label is not null and st.staff_label != ''
        </if>
        <if test="merchantStaffRequest.roleName != null and merchantStaffRequest.roleName != ''">
            and ro.role_name = #{merchantStaffRequest.roleName}
        </if>
        <if test="merchantStaffRequest.roleNameLike != null and merchantStaffRequest.roleNameLike != ''">
            and ro.role_name like concat('%', #{merchantStaffRequest.roleNameLike},'%')
        </if>
        <if test="merchantStaffRequest.staffUuid != null and merchantStaffRequest.staffUuid != ''">
            and st.staff_uuid = #{merchantStaffRequest.staffUuid}
        </if>
        <if test="merchantStaffRequest.staffUuidList != null and merchantStaffRequest.staffUuidList.size>0">
            and st.staff_uuid in
            <foreach collection="merchantStaffRequest.staffUuidList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.shareStaffUuid != null and merchantStaffRequest.shareStaffUuid != ''">
            and st.share_staff_uuid = #{merchantStaffRequest.shareStaffUuid}
        </if>
        <if test="merchantStaffRequest.merchantNoList != null and merchantStaffRequest.merchantNoList.size > 0">
            and pm.merchantNo in
            <foreach collection="merchantStaffRequest.merchantNoList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffBusinessType != null">
            and st.staff_business_type = #{merchantStaffRequest.staffBusinessType}
        </if>
        <if test="merchantStaffRequest.delFlag != null">
            and st.del_flag = #{merchantStaffRequest.delFlag}
        </if>
        order by st.created_time desc
    </select>


    <select id="findMerchantStaffById" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">
        select st.id, st.staff_name, st.staff_job,st.visible_inferior_mer,
        st.created_by,
        st.created_time, st.updated_by, st.updated_time, st.del_flag, st.merchant_id, st.staff_email,
        st.staff_code,concat(pm.merchant_name,'(',pm.merchantno,')') as merchantName,
        st.effective_time,
        st.entmicro_name,
        st.created_name as createdAccount,
        st.we_chat_open_id,
        st.we_chat_union_id,
        st.we_chat_nick_name,
        st.we_chat_avatar_url,
        st.we_chat_app_id,
        st.we_chat_phone,
        st.staff_label,
        st.department
        from platform_merchant_staff st
        left join platform_merchant pm on st.merchant_id=pm.id and pm.del_flag=0
        where 1=1 and st.del_flag IN (0,2)
        <if test="merchantStaffRequest.id !=null and merchantStaffRequest.id != ''">
            and st.id=#{merchantStaffRequest.id}
        </if>
        <if test="merchantStaffRequest.merchantId !=null and merchantStaffRequest.merchantId != ''">
            and st.merchant_id=#{merchantStaffRequest.merchantId}
        </if>
        <if test="merchantStaffRequest.keyword!=null and merchantStaffRequest.keyword != ''">
            and (st.staff_name like concat('%', #{merchantStaffRequest.keyword},'%') or st.staff_phone like concat('%',
            #{merchantStaffRequest.keyword},'%'))
        </if>
        order by st.created_time desc
    </select>

    <select id="merchantProductByPage" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">

        select st.id, st.staff_name, st.staff_job, st.staff_phone, st.visible_inferior_mer, st.created_by,
        st.created_time, st.updated_by, st.updated_time, st.del_flag, st.merchant_id, st.staff_email, st.staff_code, st.staff_uuid
        ,ro.role_name as roleName,CONCAT(pm.merchant_name,'(',merchantNo,')') as
        merchantName,pl.login_password as password,
        st.del_flag as status,
        st.effective_time,
        st.entmicro_name ,
        pm.entmicro_name as belongingEntmicroName,
        pm.merchant_legal_person,
        pm.merchant_legal_person_phone ,
        st.created_source,
        st.created_account,
        st.staff_label,
        st.department,
        pm.merchantNo
        from platform_merchant_staff st
        left join platform_merchant_role_staff_relation pr on st.id=pr.staff_id and pr.del_flag=0
        left join platform_merchant_role ro on pr.role_id=ro.id and ro.del_flag=0
        left join platform_merchant pm on st.merchant_id=pm.id and pm.del_flag=0
        left join platform_merchant_login pl on (st.id=pl.bussinessId and user_type=2 and pl.account_type=2 and
        pl.del_flag=0)
        where 1=1 and st.del_flag IN (0,2)
        <if test="merchantStaffRequest.staffName!=null and merchantStaffRequest.staffName != ''">
            and st.staff_name like concat('%', #{merchantStaffRequest.staffName},'%')
        </if>
        <if test="merchantStaffRequest.status!=null and (merchantStaffRequest.status == 0 or merchantStaffRequest.status == 2)">
            and st.del_flag=#{merchantStaffRequest.status}
        </if>
        <if test="merchantStaffRequest.status!=null">
            <if test="merchantStaffRequest.status == 3">
                and st.entmicro_name is not null
            </if>
            <if test="merchantStaffRequest.status == 4">
                and st.entmicro_name is null
            </if>
        </if>
        <if test="merchantStaffRequest.merchantId!=null">
            and st.merchant_id=#{merchantStaffRequest.merchantId}
        </if>
        <if test="merchantStaffRequest.staffBusinessType!=null">
            and st.staff_business_type=#{merchantStaffRequest.staffBusinessType}
        </if>
        <if test="merchantStaffRequest.staffPhone!=null and merchantStaffRequest.staffPhone != ''">
            and st.staff_phone like concat('%', #{merchantStaffRequest.staffPhone},'%')
        </if>
        <if test="merchantStaffRequest.createdName!=null and merchantStaffRequest.createdName != ''">
            and st.created_name like concat('%', #{merchantStaffRequest.createdName},'%')
        </if>
        <if test="merchantStaffRequest.roleId!=null">
            and pr.role_id=#{merchantStaffRequest.roleId}
        </if>
        <if test="merchantStaffRequest.dataPermission !=null and merchantStaffRequest.dataPermission.size>0">
            and st.merchant_id in
            <foreach collection="merchantStaffRequest.dataPermission" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.createdSource != null">
            and st.created_source=#{merchantStaffRequest.createdSource}
        </if>
        <if test="merchantStaffRequest.department != null">
            and st.department=#{merchantStaffRequest.department}
        </if>
        <if test="merchantStaffRequest.staffLabel != null and merchantStaffRequest.staffLabel != ''">
            and FIND_IN_SET(#{merchantStaffRequest.staffLabel},st.staff_label)
        </if>
        <if test="merchantStaffRequest.merchantNoList != null and merchantStaffRequest.merchantNoList.size > 0">
            and pm.merchantNo in
            <foreach collection="merchantStaffRequest.merchantNoList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.staffUuidList != null and merchantStaffRequest.staffUuidList.size > 0">
            and st.staff_uuid in
            <foreach collection="merchantStaffRequest.staffUuidList" index="index" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantStaffRequest.roleName!=null and merchantStaffRequest.roleName != ''">
            and ro.role_name like concat('%', #{merchantStaffRequest.roleName},'%')
        </if>
        order by st.updated_time desc
    </select>

    <select id="findClaimStaff" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">
        select * from platform_merchant_staff where del_flag = 0 and id in
        (select staff_id from platform_merchant_role_staff_relation where del_flag =0 and role_id in
        (select id from platform_merchant_role where del_flag =0 and id in
        (select role_id from platform_merchant_role_accounttype_relation where del_flag =0 and id in
        (select distinct role_accounttype_id  from platform_merchant_role_function_relation where del_flag = 0 and funciton_id = #{merchantStaffRequest.menuId}
        ))))
    </select>

    <select id="exportStaff" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantStaffRequest">

        select st.id, st.staff_name, st.staff_job, st.staff_phone, st.visible_inferior_mer, st.created_by,
        st.created_time, st.updated_by, st.updated_time, st.del_flag, st.merchant_id, st.staff_email, st.staff_code
        ,ro.role_name as roleName,CONCAT(pm.merchant_name,'(',merchantNo,')') as
        merchantName,pl.login_password as password,
        (select dict_label from platform_merchant_dict_data where dict_type='staff_status' and dict_value=st.del_flag)
        as statusName,
        st.created_name as createdAccount
        from platform_merchant_staff st
        left join platform_merchant_role_staff_relation pr on st.id=pr.staff_id and pr.del_flag=0
        left join platform_merchant_role ro on pr.role_id=ro.id and ro.del_flag=0
        left join platform_merchant pm on st.merchant_id=pm.id and pm.del_flag=0
        left join platform_merchant_login pl on (st.id=pl.bussinessId and user_type=2 and pl.del_flag=0)
        where 1=1 and st.del_flag IN (0,2)
        <if test="merchantStaffRequest.staffName!=null and merchantStaffRequest.staffName != ''">
            and st.staff_name like concat('%', #{merchantStaffRequest.staffName},'%')
        </if>
        <if test="merchantStaffRequest.staffPhone!=null and merchantStaffRequest.staffPhone != ''">
            and st.staff_phone like concat('%', #{merchantStaffRequest.staffPhone},'%')
        </if>
        <if test="merchantStaffRequest.status!=null">
            and st.del_flag=#{merchantStaffRequest.status}
        </if>
        <if test="merchantStaffRequest.merchantId!=null">
            and st.merchant_id=#{merchantStaffRequest.merchantId}
        </if>
        <if test="merchantStaffRequest.roleId!=null">
            and pr.role_id=#{merchantStaffRequest.roleId}
        </if>
        <if test="merchantStaffRequest.createdName!=null and merchantStaffRequest.createdName != ''">
            and st.created_name like concat('%', #{merchantStaffRequest.createdName},'%')
        </if>
        <if test="merchantStaffRequest.dataPermission !=null and merchantStaffRequest.dataPermission.size>0">
            and st.merchant_id in
            <foreach collection="merchantStaffRequest.dataPermission" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY st.id
        order by st.updated_time desc
    </select>
    <select id="findByAccount" resultMap="resultMap"
            parameterType="java.lang.String">
        select st.* from platform_merchant_staff st
        left join platform_merchant_login pl on (st.id=pl.bussinessId and user_type=2 and pl.del_flag=0)
        LEFT JOIN platform_merchant t4 ON st.merchant_id=t4.id
        where pl.login_accout=#{account}
        <if test="merchantId!=null">
            and t4.merchantNo=#{merchantId}
        </if>
        and st.del_flag=0
    </select>
    <select id="findStaffByMerchant" resultMap="resultMap">
        select * from platform_merchant_staff where del_flag in (0,2)
        and merchant_id in
        <foreach collection="list" item="item" index="index" open="(" close=")"
                 separator=",">
            #{item}
        </foreach>
    </select>
    <select id="findMerchantByMerchantAndName" resultMap="BaseResultMap">
        select *
        from platform_merchant_staff
        where staff_name = #{staffName}
          and merchant_id = #{merchantId}
          and del_flag = 0
    </select>
    <select id="findEntMicroEmployeeCount" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM platform_merchant_staff
        WHERE merchant_id = #{merchantId}
          and del_flag!=-1 AND entmicro_name IS NOT NULL
    </select>
    <select id="findByAccountAndMerchantId"
            resultMap="resultMap">
        select st.*, pl.login_password as password
        from platform_merchant_staff st
                 left join platform_merchant_login pl on (st.id = pl.bussinessId and user_type = 2 and pl.del_flag = 0)
        where pl.login_accout = #{staffPhone}
          and st.merchant_id = #{merchantId}
          and st.del_flag in (0, 2)
    </select>
    <select id="findStaffById" resultMap="resultMap">
        select *
        from platform_merchant_staff
        where id = #{bussinessId};
    </select>
    <select id="findByIdCollection" resultMap="BaseResultMap">
        select * from platform_merchant_staff where id in
        <foreach collection="staffIdSet" item="item" index="index" open="(" close=")"
                 separator=",">
            #{item}
        </foreach>
    </select>
    <select id="getStaffRoleName" resultType="java.lang.String">
        SELECT ro.role_name
        FROM platform_merchant_staff st
                 LEFT JOIN platform_merchant_role_staff_relation str ON str.staff_id = st.id AND str.del_flag = 0
                 LEFT JOIN platform_merchant_role ro ON ro.id = str.role_id AND ro.del_flag = 0
        WHERE st.merchant_id = #{merchantId}
          AND st.staff_phone = #{account}
          AND st.del_flag = 0 LIMIT 1
    </select>
    <select id="findEntMicroStaffByMerchantId"
            resultMap="resultMap">
        SELECT *
        FROM platform_merchant_staff
        WHERE merchant_id = #{merchantId}
          and del_flag = 0
          AND entmicro_name IS NOT NULL
    </select>
    <select id="selectStaffListByMerchantIdsAndPhone" resultMap="resultMap">
        SELECT s.* FROM `platform_merchant_staff` s LEFT JOIN `platform_merchant` m ON m.`id`=s.`merchant_id`
        WHERE s.`staff_phone` =#{request.staffPhone} AND m.`merchantNo` IN
        <foreach collection="request.merchantIds" open="(" close=")" separator="," item="merchantNo">
            #{merchantNo}
        </foreach>
        AND m.`del_flag`=0
        <if test="request.statusList != null and request.statusList.size() > 0">
            AND s.`del_flag` in
            <foreach collection="request.statusList" open="(" close=")" separator="," item="status">
                #{status}
            </foreach>
        </if>
        <if test="request.statusList == null or request.statusList.size() == 0">
            AND s.`del_flag` = 0
        </if>
    </select>
    <select id="selectStaffListByMerchantIdAndStaffLabels" resultMap="resultMap">
        SELECT s.* FROM `platform_merchant_staff` s LEFT JOIN `platform_merchant` m ON m.`id`=s.`merchant_id`
        WHERE m.`merchantNo` = #{request.merchantNo}
        <if test="request.staffLabelList !=null and request.staffLabelList.size>0">
            AND (
            <foreach collection="request.staffLabelList" open="(" close=")" separator=" OR " item="staffLabel">
                FIND_IN_SET(#{staffLabel},staff_label)
            </foreach>
            )
        </if>
        AND s.`del_flag` = 0 AND m.`del_flag`=0
    </select>
    <select id="selectStaffListByStaffIds" resultMap="resultMap">
        SELECT s.* FROM `platform_merchant_staff` s WHERE s.id in
        <foreach collection="request.ids" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </select>
    <select id="selectStaffListByStaffUUID" resultMap="resultMap">
        SELECT s.*,mr.role_name roleName FROM `platform_merchant_staff` s
        LEFT JOIN `platform_merchant_role_staff_relation` rr ON rr.staff_id=s.id AND rr.del_flag=0
        LEFT JOIN `platform_merchant_role` mr ON mr.id=rr.role_id AND mr.del_flag=0
        WHERE s.staff_uuid in
        <foreach collection="uuidList" open="(" close=")" separator="," item="uuid">
            #{uuid}
        </foreach>
        GROUP BY s.id
    </select>
    <select id="selectStaffByMerchantNoAndWechatUnionId" resultMap="resultMap">
        SELECT s.*
        FROM `platform_merchant_staff` s
                 LEFT JOIN `platform_merchant` m ON m.`id` = s.`merchant_id`
        WHERE m.`merchantNo` = #{request.merchantNo}
          AND s.`we_chat_union_id` = #{request.weChatUnionId}
          AND s.`del_flag` = 0
          AND m.`del_flag` = 0
    </select>
    <select id="findIdByMerchantId" resultType="java.lang.Integer">
        select id
        from platform_merchant_staff
        where merchant_id = #{merchantId}
          and del_flag = 0
    </select>
    <select id="merchantNoListByStaffPhone" resultType="java.lang.Integer">
        SELECT t.merchantNo
        FROM platform_merchant t
                 LEFT JOIN platform_merchant_staff t1 ON t1.merchant_id = t.id AND t1.del_flag = 0
        WHERE t1.staff_phone = #{phone}
    </select>
    <select id="findStaffByMerchantNos"
            resultMap="serviceStaffMap">
        SELECT
        t.id,t.merchantNo,t.merchant_name,t1.we_chat_avatar_url,t.merchant_legal_person_phone,t.merchant_legal_person,t.created_time,t2.login_password,
        t1.staff_phone,t1.staff_name,t1.department,t1.visual_type as visualType,
        t1.visible_merchant_no,t1.staff_uuid,t1.created_time as staff_created_time,t3.merchant_name as staffMerchantName,t3.merchantNo as staffMerchantNo
        FROM platform_merchant t
        LEFT JOIN platform_merchant_staff t1 ON t1.merchant_id = t.id AND t1.del_flag = 0
        LEFT JOIN platform_merchant_login t2 ON t2.merchant_no = t.merchantNo AND t2.user_type = 1 and t2.account_type =
        2 AND t2.del_flag = 0
        LEFT JOIN platform_merchant t3 on t1.merchant_id = t3.id AND t3.del_flag = 0
        WHERE t.merchantNo in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="findStaffPage"
            resultType="cn.com.glsx.merchants.model.response.serviceCenter.ServiceStaffRpcResponse">
        SELECT
        t.merchantNo,
        t.merchant_name as merchantName,
        t1.staff_phone as staffPhone,
        t1.staff_name as staffName,
        t1.department as departmentId,
        t1.staff_uuid as staffUuid,
        t1.visual_type as visualType,
        t1.we_chat_avatar_url as weChatAvatarUrl,
        t1.visible_merchant_no as visibleMerchantNo,
        t1.staff_business_type as staffBusinessType,
        t1.staff_label as staffLabel,
        t1.del_flag as delFlag,
        t1.created_time as createdDate,
        t1.created_source as createdSource,
        t2.role_id as roleId,
        t3.role_name as roleName
        FROM platform_merchant t
        LEFT JOIN platform_merchant_staff t1 ON t1.merchant_id = t.id
        left join platform_merchant_role_staff_relation t2 on t2.staff_id = t1.id and t2.del_flag = 0
        left join platform_merchant_role t3 on t3.id = t2.role_id and t3.del_flag = 0
        WHERE t.del_flag = 0
        <if test="request.merchantNoList != null and request.merchantNoList.size>0">
            and t.merchantNo in
            <foreach collection="request.merchantNoList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="request.staffPhone != null and request.staffPhone != ''">
            and t1.staff_phone like concat('%',#{request.staffPhone},'%')
        </if>
        <if test="request.staffName != null and request.staffName != ''">
            and t1.staff_name like concat('%',#{request.staffName},'%')
        </if>
        <if test="request.merchantName != null and request.merchantName != ''">
            and t.merchant_name like concat('%',#{request.merchantName},'%')
        </if>
        <if test="request.staffLabel != null and request.staffLabel != ''">
            and t.staff_label like concat('%',#{request.staffLabel},'%')
        </if>
        <if test="request.staffBusinessType != null">
            and t1.staff_business_type = #{request.staffBusinessType}
        </if>
        <if test="request.delFlag != null">
            <choose>
                <when test="request.delFlag == 4">
                    and t1.del_flag != -1
                </when>
                <otherwise>
                    and t1.del_flag = #{request.delFlag}
                </otherwise>
            </choose>
        </if>
        <if test="request.staffUuidList != null and request.staffUuidList.size >0">
            and t1.staff_uuid in
            <foreach collection="request.staffUuidList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        order by t1.updated_time desc,t1.id desc
    </select>
    <select id="selectStaffCount"
            resultType="cn.com.glsx.merchants.model.response.staff.StaffCountRpcResponse">
        select pm.merchantNo,
               SUM(IF(pms.staff_business_type = 1,1,0)) AS staffCount
        from platform_merchant pm
        left join platform_merchant_staff pms on pm.id = pms.merchant_id and pms.del_flag = 0
        where pm.status = 2 and pm.merchantNo in
        <foreach collection="merchantNoList" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        group by pm.merchantNo
    </select>
    <select id="findZdStaff" resultMap="resultMap">

        SELECT
        t.merchantNo,
        t.merchant_name as merchantName,
        t1.*
        FROM  platform_merchant_staff t1


        LEFT JOIN platform_merchant t ON t1.merchant_id = t.id

        where t1.staff_phone=#{mobile} and t1.del_flag in (0,2) and t.merchant_account_level=4 and  find_in_set(account_type,#{accountType})

    </select>
    <select id="findStaffListByMerchantId" resultMap="resultMap">
        SELECT
        t.merchantNo,
        t.merchant_name as merchantName,
        t1.*
        FROM  platform_merchant_staff t1


        LEFT JOIN platform_merchant t ON t1.merchant_id = t.id

        where t1.staff_phone=#{mobile} and t1.del_flag in (0,2) and t1.merchant_id=#{manageMerchantId}
    </select>
    <select id="findYqStaffByPage" resultMap="resultMap">
        SELECT * FROM `platform_merchant_staff` pms WHERE pms.staff_phone is not null and pms.merchant_id IN (
        SELECT DISTINCT t1.id FROM `platform_merchant` t1
        INNER JOIN `platform_merchant_accounttype_relation` t2 ON t2.merchant_id=t1.id
        INNER JOIN `platform_merchant_accounttype`  t3 ON t3.id=t2.accounttype_id
        WHERE t1.del_flag=0 AND t2.del_flag=0 AND t3.del_flag=0 AND (t3.id IN (6,8)
        <if test="merchantNoList!=null and merchantNoList.size>0">
            OR t1.merchantNo IN
            <foreach collection="merchantNoList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        )) AND pms.del_flag=0
        <if test="staffName != null and staffName != ''">
            AND pms.staff_name LIKE concat('%',#{staffName},'%')
        </if>
    </select>

    <select id="qryPhoneInStaffList" resultType="java.lang.String">
        select distinct staff_phone from platform_merchant_staff
        <where>
            del_flag = 0
            <if test="phones != null and phones.size() > 0">
                and (staff_phone in
                <trim>
                    <foreach collection="phones" item="phone" index="index" open="(" close=")">
                        <if test="index != 0">
                            <choose>
                                <when test="(index % 999) == 998">
                                    ) or staff_phone in (
                                </when>
                                <otherwise>
                                    ,
                                </otherwise>
                            </choose>
                        </if>
                        #{phone}
                    </foreach>
                </trim>
                )
            </if>
        </where>
    </select>
</mapper>