UserServiceDaoImplMapper.xml 29.3 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
<?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="userServiceDaoImpl">

    <resultMap type="com.java110.dto.user.Cust" id="custMap">
        <id column="custId" jdbcType="VARCHAR" property="custId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="cellphone" jdbcType="VARCHAR" property="cellphone"/>
        <result column="realName" jdbcType="VARCHAR" property="realName"/>
        <result column="sex" jdbcType="VARCHAR" property="sex"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="lanId" jdbcType="VARCHAR" property="lanId"/>
        <result column="custAdress" jdbcType="VARCHAR" property="custAdress"/>
        <result column="custType" jdbcType="VARCHAR" property="custType"/>
        <result column="openId" jdbcType="VARCHAR" property="openId"/>
        <!-- 一对多关系 -->
        <!-- <collection property="stus" resultMap="Student.StudentResult"></collection>  -->
        <collection property="custAttrs" javaType="com.java110.dto.user.CustAttr">
            <id property="custId" column="custId"/>
            <result property="attrCd" column="attrCd"/>
            <result property="value" column="value"/>
        </collection>
    </resultMap>

    <!--根据用户Id查询用户角色
    <select id="findRolesByUserId" resultType="SysRole">
        SELECT
        r.*
        FROM
        t_role r,
        t_user_role ur
        WHERE ur.uid = #{userId}
        AND ur.roleId = r.roleId
        AND ur.status_cd = '1'
    </select>
-->
    <!--保存数据至过程表 bo_cust 中 -->
    <insert id="saveDataToBoCust" parameterType="com.java110.dto.user.BoCust">
        <![CDATA[


                            insert into bo_cust(boId,custId,name,email,cellphone,realName,sex,password,lanId,custAdress,custType,openId,state)
                            values(#{boId},#{custId},#{name},#{email},#{cellphone},#{realName},#{sex},#{password},#{lanId},#{custAdress},#{custType},#{openId},#{state})


        ]]>
    </insert>
    <!-- 保存数据至过程表bo_cust_attr 中-->
    <insert id="saveDataToBoCustAttr" parameterType="com.java110.dto.user.BoCustAttr">
        <![CDATA[


                            insert into bo_cust_attr(boId,custId,attrCd,value,state)
                            values(#{boId},#{custId},#{attrCd},#{value},#{state})


        ]]>
    </insert>
    <!-- 保存 实例客户信息 cust -->
    <insert id="saveDataToCust" parameterType="com.java110.dto.user.Cust">
        <![CDATA[


                            insert into cust(custId,name,email,cellphone,realName,sex,password,lanId,custAdress,custType,openId,status_cd)
                            values(#{custId},#{name},#{email},#{cellphone},#{realName},#{sex},#{password},#{lanId},#{custAdress},#{custType},#{openId},#{status_cd})


        ]]>
    </insert>
    <!-- 删除实例客户信息 cust -->
    <insert id="deleteDataToCust" parameterType="com.java110.dto.user.Cust">
        <![CDATA[


                           delete * from cust c where c.custId = #{custId}


        ]]>
    </insert>

    <!-- 保存 实例客户属性信息 cust_attr -->
    <insert id="saveDataToCustAttr" parameterType="com.java110.dto.user.CustAttr">
        <![CDATA[


                            insert into cust_attr(custId,attrCd,value,status_cd)
                            values(#{custId},#{attrCd},#{value},#{status_cd})


        ]]>
    </insert>
    <!-- 删除实例客户信息 cust -->
    <update id="deleteDataToCustAttr" parameterType="com.java110.dto.user.CustAttr">
        delete * from cust_attr ct where 1=1
        <if test="custId != null and custId != ''">
            and ct.custId = #{custId}
        </if>
        <if test="attrCd != null and attrCd != ''">
            and ct.attrCd = #{attrCd}
        </if>
    </update>
    <!--根据客户ID 查询客户信息,其中包括 cust 和custAttr 数据-->
    <select id="queryDataToCust" parameterType="com.java110.dto.user.Cust" resultMap="custMap">

        select c.custId,c.name,c.email,c.cellphone,c.realName,c.sex,c.password,c.lanId,c.custAdress,c.custType,c.openId,
        ca.custId,ca.attrCd,ca.value
        from cust c, cust_attr ca where c.custId= ca.custId
        <if test="custId != null and custId != ''">
            and c.custId = #{custId}
        </if>
        <if test="versionId != null and versionId != ''">
            and c.versionId = #{versionId}
        </if>
        and c.status_cd = '0'

    </select>

    <!-- 查询客户过程数据 -->
    <select id="queryBoCust" parameterType="com.java110.dto.user.BoCust" resultType="com.java110.dto.user.BoCust">
        select
        bc.boId,bc.custId,bc.name,bc.email,bc.cellphone,bc.realName,bc.sex,bc.password,bc.lanId,bc.custAdress,bc.custType,bc.openId,bc.create_dt
        from bo_cust bc where 1=1
        <if test="boId != null and boId != ''">
            and bc.boId = #{boId}
        </if>
        <if test="custId != null and custId != ''">
            and bc.custId = #{custId}
        </if>
        <if test="versionId != null and versionId != ''">
            and c.versionId = #{versionId}
        </if>
        and bc.state in ('ADD','DEL','KIP')
        <if test="create_dt != null and create_dt != ''">
            order by bc.create_dt desc
        </if>
    </select>
    <!-- 查询客户属性过程表-->
    <select id="queryBoCustAttr" parameterType="com.java110.dto.user.BoCustAttr"
            resultType="com.java110.dto.user.BoCustAttr">
        select bca.boId,bca.custId,bca.attrCd,bca.value,bca.state,bca.create_dt from bo_cust_attr bca where 1=1
        <if test="boId !=null and boId != ''">
            and bca.boId = #{boId}
        </if>
        <if test="custId != null and custId != ''">
            and bca.custId = #{custId}
        </if>
        <if test="versionId != null and versionId != ''">
            and bca.versionId = #{versionId}
        </if>
        <if test="create_dt != null and create_dt != ''">
            order by bca.create_dt desc
        </if>
    </select>

    <!-- 查询客户属性信息 -->
    <select id="queryDataToCustAttr" parameterType="com.java110.dto.user.CustAttr"
            resultType="com.java110.dto.user.CustAttr">
        select * from cust_attr ca where 1=1
        <if test="custId != null and custId != ''">
            and ca.custId = #{custId}
        </if>
        <if test="versionId != null and versionId != ''">
            and ca.versionId = #{versionId}
        </if>
        <if test="attrCd != null and attrCd != ''">
            and ca.attrCd = #{attrCd}
        </if>
        and status_cd = '0'
    </select>

    <!-- 保存用户信息 -->
    <insert id="saveBusinessUserInfo" parameterType="map">
        insert into business_user(b_id,user_id,name,email,address,password,location_cd,age,sex,tel,level_cd,operate)
        values(#{bId},#{userId},#{name},#{email},#{address},#{password},#{locationCd},#{age},#{sex},#{tel},#{levelCd},#{operate})
    </insert>

    <!-- 保存用户属性 -->
    <insert id="saveBusinessUserAttr" parameterType="map">
        insert into business_user_attr(b_id,user_id,attr_id,spec_cd,value,operate)
        values(#{bId},#{userId},#{attrId},#{specCd},#{value},#{operate})
    </insert>
    <!-- 实例数据 -->
    <insert id="saveUserInfoInstance" parameterType="map">
        insert into u_user(user_id,name,email,address,password,location_cd,age,sex,tel,level_cd,b_id,status_cd)
        select
        bu.user_id,bu.name,bu.email,bu.address,bu.password,bu.location_cd,bu.age,bu.sex,bu.tel,bu.level_cd,bu.b_id,'0'
        from business_user bu where bu.operate = 'ADD' and bu.b_id=#{b_id}
    </insert>

    <insert id="saveUserAttrInstance" parameterType="map">
        insert into u_user_attr(attr_id,user_id,spec_cd,value,b_id,status_cd)
        select bua.attr_id,bua.user_id,bua.spec_cd,bua.value,bua.b_id,'0' from business_user_attr bua where
        bua.operate='ADD' and bua.b_id=#{b_id}
    </insert>

    <update id="updateUserInfoInstance" parameterType="map">
        update u_user u set u.status_cd = #{statusCd}
        <if test="newBId != null and newBId != ''">
            ,u.b_id = #{newBId}
        </if>
        <if test="name !=null and name != ''">
            ,u.name= #{name}
        </if>
        <if test="email !=null and email != ''">
            ,u.email= #{email}
        </if>
        <if test="address !=null and address != ''">
            ,u.address= #{address}
        </if>
        <if test="password !=null and password != ''">
            ,u.password= #{password}
        </if>
        <if test="locationCd !=null and locationCd != ''">
            ,u.location_cd= #{locationCd}
        </if>
        <if test="age !=null and age != ''">
            ,u.age= #{age}
        </if>
        <if test="sex !=null and sex != ''">
            ,u.sex= #{sex}
        </if>
        <if test="tel !=null and tel != ''">
            ,u.tel= #{tel}
        </if>
        <if test="score !=null and score != ''">
            ,u.score= #{score}
        </if>
        where 1 = 1
        <if test="bId != null and bId != ''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId !=''">
            and u.user_id = #{userId}
        </if>
        <if test="attrId != null and attrId != ''">
            and u.attr_id = #{attrId}
        </if>
    </update>

    <update id="updateUserAttrInstance" parameterType="map">
        update u_user_attr ua set ua.status_cd = #{statusCd} where 1 = 1
        <if test="bId != null and bId != ''">
            and ua.b_id = #{bId}
        </if>
        <if test="userId != null and userId !=''">
            and ua.user_id = #{userId}
        </if>
    </update>


    <!-- 查询用户信息 Business -->
    <select id="queryBusinessUserInfo" parameterType="map" resultType="map">
        select u.user_id,u.name,u.email,u.address,u.password,u.location_cd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id,u.operate
        from business_user u where 1 = 1
        <if test="operate != null and operate != ''">
            and u.operate = #{operate}
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
    </select>

    <!-- 查询用户属性信息 Business-->
    <select id="queryBusinessUserInfoAttrs" parameterType="map" resultType="map">
        select u.attr_id,u.user_id,u.spec_cd,u.value,u.b_id,u.operate
        from business_user_attr u where 1 = 1
        <if test="operate != null and operate != ''">
            and u.operate = #{operate}
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
        <if test="attrId != null and attrId != ''">
            and u.attr_id = #{attrId}
        </if>
    </select>

    <!-- 查询用户信息 -->
    <select id="queryUserInfo" parameterType="map" resultType="map">
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id
        from u_user u where 1= 1
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and u.status_cd = #{statusCd}
        </if>
        <if test="userIds != null and userIds != null">
            and u.user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>


    <!-- 查询用户属性信息 -->
    <select id="queryUserInfoAttrs" parameterType="map" resultType="map">
        select u.attr_id,u.user_id,u.spec_cd,u.value,u.b_id,
        u.attr_id attrId,u.user_id userId,u.spec_cd specCd,u.b_id bId
        from u_user_attr u where u.status_cd = '0'
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
        <if test="attrId != null and attrId != ''">
            and u.attr_id = #{attrId}
        </if>
        <if test="specCd != null and specCd != ''">
            and u.spec_cd = #{specCd}
        </if>
    </select>


    <!--保存用户地址信息 add by wuxw 2018-06-29 -->
    <insert id="saveBusinessUserAddress" parameterType="map">
        insert into business_user_address(address_id,b_id,user_id,tel,postal_code,address,is_default,operate)
        values(#{addressId},#{bId},#{userId},#{tel},#{postalCode},#{address},#{isDefault},#{operate})
    </insert>


    <!-- 查询用户地址信息 add by wuxw 2018-06-29-->
    <select id="queryBusinessUserAddress" parameterType="map" resultType="map">
        select ua.address_id,ua.b_id,ua.user_id,ua.tel,ua.postal_code,ua.address,ua.is_default,ua.operate
        from business_user_address ua where 1 = 1
        <if test="operate != null and operate != ''">
            and ua.operate = #{operate}
        </if>
        <if test="bId != null and bId !=''">
            and ua.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and ua.user_id = #{userId}
        </if>
    </select>

    <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 -->
    <insert id="saveUserAddressInstance" parameterType="map">
        insert into u_user_address(address_id,b_id,user_id,tel,postal_code,address,is_default,status_cd)
        select ua.address_id,ua.b_id,ua.user_id,ua.tel,ua.postal_code,ua.address,ua.is_default,'0'
        from business_user_address ua where 1 = 1
        ua.operate = 'ADD' and ua.b_id=#{b_id}
    </insert>

    <!-- 作废用户地址信息数据 add by wuxw 2018-06-29-->
    <update id="updateUserAddressInstance" parameterType="map">
        update u_user_address ua set ua.status_cd = #{statusCd} where 1 = 1
        <if test="bId != null and bId != ''">
            and ua.b_id = #{bId}
        </if>
        <if test="userId != null and userId !=''">
            and ua.user_id = #{userId}
        </if>
        <if test="addressId != null and addressId != ''">
            and ua.address_id = #{addressId}
        </if>
    </update>


    <!--保存用户打标信息 add by wuxw 2018-06-29 -->
    <insert id="saveBusinessUserTag" parameterType="map">
        insert into business_user_tag(tag_id,b_id,user_id,tag_cd,remark,operate)
        values(#{tagId},#{bId},#{userId},#{tagCd},#{remark},#{operate})
    </insert>


    <!-- 查询用户地址信息 add by wuxw 2018-06-29-->
    <select id="queryBusinessUserTag" parameterType="map" resultType="map">
        select ut.tag_id,ut.b_id,ut.user_id,ut.tag_cd,ut.remark,ut.operate
        from business_user_tag ut where 1 = 1
        <if test="operate != null and operate != ''">
            and ut.operate = #{operate}
        </if>
        <if test="bId != null and bId !=''">
            and ut.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and ut.user_id = #{userId}
        </if>
    </select>

    <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 -->
    <insert id="saveUserTagInstance" parameterType="map">
        insert into u_user_tag(tag_id,b_id,user_id,tag_cd,remark,status_cd)
        select ut.tag_id,ut.b_id,ut.user_id,ut.tag_cd,ut.remark,'0'
        from business_user_tag ut where 1 = 1
        ut.operate = 'ADD' and ut.b_id=#{b_id}
    </insert>

    <!-- 作废用户地址信息数据 add by wuxw 2018-06-29-->
    <update id="updateUserTagInstance" parameterType="map">
        update u_user_tag ut set ut.status_cd = #{statusCd} where 1 = 1
        <if test="bId != null and bId != ''">
            and ut.b_id = #{bId}
        </if>
        <if test="userId != null and userId !=''">
            and ut.user_id = #{userId}
        </if>
        <if test="addressId != null and addressId != ''">
            and ut.address_id = #{tagId}
        </if>
    </update>


    <!--保存用户证件信息 add by wuxw 2018-06-29 -->
    <insert id="saveBusinessUserCredentials" parameterType="map">
        insert into business_user_credentials(credentials_id,b_id,user_id,credentials_cd,value,operate)
        values(#{credentialsId},#{bId},#{userId},#{credentialsCd},#{value},#{operate})
    </insert>


    <!-- 查询用户地址信息 add by wuxw 2018-06-29-->
    <select id="queryBusinessUserCredentials" parameterType="map" resultType="map">
        select uc.credentials_id,uc.b_id,uc.user_id,uc.credentials_cd,uc.value,uc.operate
        from business_user_credentials uc where 1 = 1
        <if test="operate != null and operate != ''">
            and uc.operate = #{operate}
        </if>
        <if test="bId != null and bId !=''">
            and uc.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and uc.user_id = #{userId}
        </if>
    </select>

    <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 -->
    <insert id="saveUserCredentialsInstance" parameterType="map">
        insert into u_user_credentials(credentials_id,b_id,user_id,credentials_cd,value,status_cd)
        select uc.credentials_id,uc.b_id,uc.user_id,uc.credentials_cd,uc.value,'0'
        from business_user_credentials uc where 1 = 1
        uc.operate = 'ADD' and uc.b_id=#{b_id}
    </insert>

    <!-- 作废用户地址信息数据 add by wuxw 2018-06-29-->
    <update id="updateUserCredentialsInstance" parameterType="map">
        update u_user_credentials uc set uc.status_cd = #{statusCd} where 1 = 1
        <if test="bId != null and bId != ''">
            and uc.b_id = #{bId}
        </if>
        <if test="userId != null and userId !=''">
            and uc.user_id = #{userId}
        </if>
        <if test="addressId != null and addressId != ''">
            and uc.credentials_id = #{credentialsId}
        </if>
    </update>

    <!-- 查询员工总量 -->
    <select id="getStaffCount" parameterType="Map" resultType="Map">
        <if test="orgIds != null and orgIds.length > 0">
            select count(*) count from(
        </if>
        select count(1) count
        from u_user u
        inner join s_store_user su on su.user_id = u.user_id
        <if test="(orgId !=null and orgId != '')||(orgIds != null and orgIds.length > 0)">
            left join u_org_staff_rel uosr on u.user_id = uosr.staff_id and uosr.status_cd = '0'
            left join u_org uo on uosr.org_id = uo.org_id and uo.status_cd = '0'
        </if>
        where su.status_cd = '0'
        and u.status_cd = '0'
        <if test="levelCd !=null and levelCd != ''">
            and u.level_cd = #{levelCd}
        </if>
        <if test="storeId !=null and storeId != ''">
            and su.store_id = #{storeId}
        </if>
        <if test="orgId !=null and orgId != ''">
            and uosr.org_id = #{orgId}
        </if>
        <if test="tel !=null and tel != ''">
            and u.tel= #{tel}
        </if>
        <if test="name !=null and name != ''">
            and u.name like concat('%',#{name},'%')
        </if>
        <if test="nameLike !=null and nameLike != ''">
            and u.name like concat('%',#{nameLike},'%')
        </if>
        <if test="staffName !=null and staffName != ''">
            and u.name like concat('%',#{staffName},'%')
        </if>
        <if test="staffId != null and staffId !=''">
            and u.user_id = #{staffId}
        </if>
        <if test="orgId !=null and orgId != ''">
            and uo.org_id = #{orgId}
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userIds != null and userIds != null">
            and u.user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="orgIds != null and orgIds.length > 0">
            and uosr.org_id in
            <foreach collection="orgIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
            and uosr.status_cd =0
            GROUP BY u.user_id
        </if>
        <if test="orgIds != null and orgIds.length > 0">
            )a
        </if>
    </select>

    <!-- 查询员工总量 -->
    <select id="getStaffs" parameterType="Map" resultType="Map">
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd levelCd,u.b_id,su.rel_cd relCd,td.name relCdName,ua.value idCard,
        s.name storeName,s.store_type_cd storeTypeCd
        <if test="orgId !=null and orgId != ''">
            ,uo.org_id orgId,uo.org_name,uo.org_name orgName,uosr.store_id storeId,uosr.rel_id relId
        </if>
        from
        u_user u
        inner join s_store_user su on su.user_id = u.user_id
        left join s_store s on su.store_id = s.store_id
        left join t_dict td on su.rel_cd = td.status_cd and td.table_name='s_store_user' and td.table_columns='rel_cd'
        left join u_user_attr ua on ua.user_id = u.user_id and ua.spec_cd = '100202406002' and ua.status_cd = '0'
        <if test="(orgId !=null and orgId != '')||(orgIds != null and orgIds.length > 0)">
            left join u_org_staff_rel uosr on u.user_id = uosr.staff_id and uosr.status_cd = '0'
            left join u_org uo on uosr.org_id = uo.org_id and uo.status_cd = '0'
        </if>
        where su.status_cd = '0'
        and u.status_cd = '0'
        and s.status_cd = '0'
        <if test="levelCd !=null and levelCd != ''">
            and u.level_cd = #{levelCd}
        </if>
        <if test="storeId !=null and storeId != ''">
            and su.store_id = #{storeId}
        </if>
        <if test="orgId !=null and orgId != ''">
            and uosr.org_id = #{orgId}
        </if>
        <if test="tel !=null and tel != ''">
            and u.tel= #{tel}
        </if>
        <if test="name !=null and name != ''">
            and u.name like concat('%',#{name},'%')
        </if>
        <if test="nameLike !=null and nameLike != ''">
            and u.name like concat('%',#{nameLike},'%')
        </if>
        <if test="staffName !=null and staffName != ''">
            and u.name like concat('%',#{staffName},'%')
        </if>
        <if test="staffId != null and staffId !=''">
            and u.user_id = #{staffId}
        </if>
        <if test="orgId !=null and orgId != ''">
            and uo.org_id = #{orgId}
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userIds != null and userIds != null">
            and u.user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="orgIds != null and orgIds.length > 0">
            and uosr.org_id in
            <foreach collection="orgIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
            and uosr.status_cd =0
            GROUP BY u.user_id,u.name,u.email,u.address,u.location_cd,
            u.age,u.sex,u.tel,u.level_cd ,u.b_id,su.rel_cd ,td.name
            ,uo.org_id,uo.org_name,uosr.store_id,uosr.rel_id,ua.value,
            s.name,s.store_type_cd
        </if>
        order by u.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>

    <!-- 查询用户 -->
    <select id="getUsers" parameterType="Map" resultType="Map">
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id,u.level_cd levelCd,u.score
        from u_user u
        <if test="openId != null and openId !=''">
            ,u_user_attr ua
        </if>
        <if test="key != null and key !=''">
            ,u_user_attr ub
        </if>
        <if test="unionId != null and unionId !=''">
            ,u_user_attr ua
        </if>
        where 1= 1

        <if test="openId != null and openId != ''">
            and u.user_id = ua.user_id
            and ua.spec_cd in ('100201911001','100201911003')
            and ua.value = #{openId}
            and ua.status_cd = '0'
        </if>
        <if test="unionId != null and unionId != ''">
            and u.user_id = ua.user_id
            and ua.spec_cd = '100201911002'
            and ua.value = #{unionId}
            and ua.status_cd = '0'
        </if>
        <if test="key != null and key != ''">
            and u.user_id = ub.user_id
            and ub.spec_cd = '100202061602'
            and ub.value = #{key}
            and ub.status_cd = '0'
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and u.status_cd = #{statusCd}
        </if>
        <if test="userIds != null and userIds != null">
            and u.user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>

        <if test="name !=null and name != ''">
            and u.name= #{name}
        </if>
        <if test="userName !=null and userName != ''">
            and u.name= #{userName}
        </if>
        <if test="email !=null and email != ''">
            and u.email= #{email}
        </if>
        <if test="password !=null and password != ''">
            and u.password= #{password}
        </if>
        <if test="locationCd !=null and locationCd != ''">
            and u.location_cd= #{locationCd}
        </if>
        <if test="age !=null and age != ''">
            and u.age= #{age}
        </if>
        <if test="sex !=null and sex != ''">
            and u.sex= #{sex}
        </if>
        <if test="tel !=null and tel != ''">
            and u.tel= #{tel}
        </if>
        <if test="levelCd !=null and levelCd != ''">
            and u.level_cd= #{levelCd}
        </if>
        <if test="levelCds != null">
            and u.level_cd in
            <foreach collection="levelCds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test='userFlag !=null and userFlag =="1"'>
            and u.level_cd != '02'
        </if>
        order by u.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>

    <select id="getUserCount" parameterType="Map" resultType="Map">
        select count(1) count
        from u_user u
        <if test="openId != null and openId !=''">
            ,u_user_attr ua
        </if>
        <if test="unionId != null and unionId !=''">
            ,u_user_attr ua
        </if>
        where 1= 1
        <if test="openId != null and openId != ''">
            and u.user_id = ua.user_id
            and ua.spec_cd in ('100201911001','100201911003')
            and ua.value = #{openId}
            and ua.status_cd = '0'
        </if>
        <if test="unionId != null and unionId != ''">
            and u.user_id = ua.user_id
            and ua.spec_cd = '100201911002'
            and ua.value = #{unionId}
            and ua.status_cd = '0'
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and u.status_cd = #{statusCd}
        </if>
        <if test="userIds != null and userIds != null">
            and u.user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>

    </select>

    <!-- 查询用户密码 -->
    <select id="getUserHasPwd" parameterType="Map" resultType="Map">
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd levelCd,u.b_id,u.password
        from u_user u
        <if test="openId != null and openId !=''">
            ,u_user_attr ua
        </if>
        <if test="unionId != null and unionId !=''">
            ,u_user_attr ua
        </if>
        where 1= 1
        <if test="openId != null and openId != ''">
            and u.user_id = ua.user_id
            and ua.spec_cd = '100201911001'
            and ua.value = #{openId}
            and ua.status_cd = '0'
        </if>
        <if test="unionId != null and unionId != ''">
            and u.user_id = ua.user_id
            and ua.spec_cd = '100201911002'
            and ua.value = #{unionId}
            and ua.status_cd = '0'
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
        </if>
        <if test="userId != null and userId != ''">
            and u.user_id = #{userId}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and u.status_cd = #{statusCd}
        </if>

    </select>

</mapper>