MerchantMapper.xml 64.2 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 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 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
<?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.MerchantMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.merchants.entity.Merchant">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
        <result column="merchant_abbreviation" jdbcType="VARCHAR" property="merchantAbbreviation"/>
        <result column="merchant_type" jdbcType="TINYINT" property="merchantType"/>
        <result column="merchant_orgcode" jdbcType="VARCHAR" property="merchantOrgcode"/>
        <result column="merchant_address" jdbcType="VARCHAR" property="merchantAddress"/>
        <result column="merchant_legal_person" jdbcType="VARCHAR" property="merchantLegalPerson"/>
        <result column="merchant_legal_person_phone" jdbcType="VARCHAR" property="merchantLegalPersonPhone"/>
        <result column="islogin_name" jdbcType="TINYINT" property="isloginName"/>
        <result column="business_scope" jdbcType="VARCHAR" property="businessScope"/>
        <result column="merchant_brand" jdbcType="VARCHAR" property="merchantBrand"/>
        <result column="merchant_login_account" jdbcType="VARCHAR" property="merchantLoginAccount"/>
        <result column="merchant_account_level" jdbcType="TINYINT" property="merchantAccountLevel"/>
        <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="channel_id" jdbcType="INTEGER" property="channelId"/>
        <result column="lng" jdbcType="REAL" property="lng"/>
        <result column="lat" jdbcType="REAL" property="lat"/>
        <result column="province_code" jdbcType="VARCHAR" property="provinceCode"/>
        <result column="province_name" jdbcType="VARCHAR" property="provinceName"/>
        <result column="city_code" jdbcType="VARCHAR" property="cityCode"/>
        <result column="city_name" jdbcType="VARCHAR" property="cityName"/>
        <result column="district_code" jdbcType="VARCHAR" property="districtCode"/>
        <result column="district_name" jdbcType="VARCHAR" property="districtName"/>
        <result column="resident_contact" jdbcType="VARCHAR" property="residentContact"/>
        <result column="resident_phone" jdbcType="VARCHAR" property="residentPhone"/>
        <result column="merchant_label" jdbcType="TINYINT" property="merchantLabel"/>
        <result column="area_code" jdbcType="TINYINT" property="areaCode"/>
        <result column="bussiness_begintime" jdbcType="VARCHAR" property="bussinessBegintime"/>
        <result column="bussiness_endtime" jdbcType="VARCHAR" property="bussinessEndtime"/>
        <result column="expire_date" jdbcType="TIMESTAMP" property="expireDate"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="entmicro_name" jdbcType="VARCHAR" property="entmicroName"/>
        <result column="entmicro_id" jdbcType="VARCHAR" property="entmicroId"/>
        <result column="merchant_model" jdbcType="TINYINT" property="merchantModel"/>
        <result column="business_type" jdbcType="VARCHAR" property="businessType"/>
        <result column="merchant_brand_main" jdbcType="VARCHAR" property="merchantBrandMain"/>
        <result column="created_source" jdbcType="VARCHAR" property="createdSource"/>
    </resultMap>

    <resultMap id="resultMap" type="cn.com.glsx.merchants.model.response.MerchantResponse">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
        <result column="parentName" jdbcType="VARCHAR" property="parentMerchant"/>
        <result column="merchant_abbreviation" jdbcType="VARCHAR" property="merchantAbbreviation"/>
        <result column="merchant_type" jdbcType="TINYINT" property="merchantType"/>
        <result column="merchant_orgcode" jdbcType="VARCHAR" property="merchantOrgcode"/>
        <result column="merchant_address" jdbcType="VARCHAR" property="merchantAddress"/>
        <result column="merchant_legal_person" jdbcType="VARCHAR" property="merchantLegalPerson"/>
        <result column="merchant_legal_person_phone" jdbcType="VARCHAR" property="merchantLegalPersonPhone"/>
        <result column="islogin_name" jdbcType="TINYINT" property="isloginName"/>
        <result column="business_scope" jdbcType="VARCHAR" property="businessScope"/>
        <result column="merchant_brand" jdbcType="VARCHAR" property="merchantBrand"/>
        <result column="merchant_login_account" jdbcType="VARCHAR" property="merchantLoginAccount"/>
        <result column="merchant_login_password" jdbcType="VARCHAR" property="merchantLoginPassword"/>
        <result column="merchant_account_level" jdbcType="TINYINT" property="merchantAccountLevel"/>
        <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="channel_id" jdbcType="INTEGER" property="channelId"/>
        <result column="lng" jdbcType="REAL" property="lng"/>
        <result column="lat" jdbcType="REAL" property="lat"/>
        <result column="province_code" jdbcType="VARCHAR" property="provinceCode"/>
        <result column="province_name" jdbcType="VARCHAR" property="provinceName"/>
        <result column="city_code" jdbcType="VARCHAR" property="cityCode"/>
        <result column="city_name" jdbcType="VARCHAR" property="cityName"/>
        <result column="district_code" jdbcType="VARCHAR" property="districtCode"/>
        <result column="district_name" jdbcType="VARCHAR" property="districtName"/>
        <result column="resident_contact" jdbcType="VARCHAR" property="residentContact"/>
        <result column="resident_phone" jdbcType="VARCHAR" property="residentPhone"/>
        <result column="merchant_label" jdbcType="TINYINT" property="merchantLabel"/>
        <result column="area_code" jdbcType="TINYINT" property="areaCode"/>
        <result column="bussiness_begintime" jdbcType="VARCHAR" property="bussinessBegintime"/>
        <result column="bussiness_endtime" jdbcType="VARCHAR" property="bussinessEndtime"/>
        <result column="expire_date" jdbcType="TIMESTAMP" property="expireDate"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="account_type" jdbcType="VARCHAR" property="accountType"/>
        <result column="accountTypeNames" jdbcType="VARCHAR" property="accountTypeNames"/>
        <result column="effective_time" jdbcType="TINYINT" property="effectiveTime"/>
        <result column="business_scope_customize" jdbcType="TINYINT" property="businessScopeCustomize"/>
        <result column="parentMerchant" jdbcType="VARCHAR" property="parentMerchant"/>
        <result column="accountLevelName" jdbcType="VARCHAR" property="accountLevelName"/>
        <result column="statusName" jdbcType="VARCHAR" property="statusName"/>
        <result column="businessScopName" jdbcType="VARCHAR" property="businessScopName"/>
        <result column="merchantBrandName" jdbcType="TINYINT" property="merchantBrandName"/>
        <result column="effectiveTimeName" jdbcType="VARCHAR" property="effectiveTimeName"/>
        <result column="channelName" jdbcType="VARCHAR" property="channelName"/>
        <result column="parentId" jdbcType="TINYINT" property="parentId"/>
        <result column="entmicro_name" jdbcType="VARCHAR" property="entmicroName"/>
        <result column="entmicro_id" jdbcType="VARCHAR" property="entmicroId"/>
        <result column="merchant_model" jdbcType="TINYINT" property="merchantModel"/>
        <result column="merchantModelName" jdbcType="TINYINT" property="merchantModelName"/>
        <result column="effective_starttime" jdbcType="TINYINT" property="effectiveStarttime"/>
        <result column="channel_type" jdbcType="TINYINT" property="channelType"/>
        <result column="sap_code" jdbcType="TINYINT" property="sapCode"/>
        <result column="merchantNo" jdbcType="TINYINT" property="merchantNo"/>
        <result column="access_mode" jdbcType="TINYINT" property="accessMode"/>
        <result column="business_type" jdbcType="VARCHAR" property="businessType"/>
        <result column="merchant_brand_main" jdbcType="VARCHAR" property="merchantBrandMain"/>
        <result column="merchant_brand_cars" jdbcType="VARCHAR" property="merchantBrandCars"/>
        <result column="created_source" jdbcType="VARCHAR" property="createdSource"/>
        <result column="created_account" jdbcType="VARCHAR" property="createdAccount"/>
    </resultMap>

    <resultMap id="MerchantBrandDTOMap" type="cn.com.glsx.merchants.dto.MerchantBrandModelDTO">
        <result column="brand_id" property="brandId" jdbcType="INTEGER" />
        <result column="child_id" property="childId" jdbcType="INTEGER" />
    </resultMap>
    <resultMap id="MerchantPageWithBrandDTOMap" type="cn.com.glsx.merchants.dto.MerchantPageWithBrandDTO">
        <id column="merchant_id" property="merchantId" jdbcType="INTEGER" />
        <result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
        <collection
                property="merchantBrandList"
                ofType="cn.com.glsx.merchants.dto.MerchantBrandModelDTO"
                resultMap="MerchantBrandDTOMap"
                fetchType="eager"
        />
    </resultMap>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, merchant_name, merchant_abbreviation, merchant_type, merchant_orgcode, merchant_address,
        merchant_legal_person, merchant_legal_person_phone, islogin_name, business_scope,
        merchant_brand, merchant_login_account, merchant_account_level,account_type,
        created_by, created_time, updated_by, updated_time, del_flag, channel_id, lng, lat,
        province_code, province_name, city_code, city_name, district_code, district_name,
        resident_contact, resident_phone, merchant_label, area_code, bussiness_begintime,merchantNo,
        bussiness_endtime, expire_date, `status`,created_source,created_account
    </sql>
    <update id="batchInvalidaMerchant">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update platform_merchant
            <set>
                status = #{item.status},
                effective_time=#{item.effectiveTime}
            </set>
            where id=#{item.id}
        </foreach>
    </update>
    <update id="updateEntmicroInfoByMerchantNo">
        update platform_merchant
        <set>
            entmicro_id= #{merchantOpenRequest.entmicroId},
            entmicro_name=#{merchantOpenRequest.entmicroName}
        </set>
        where merchantNO=#{merchantOpenRequest.merchantId}
    </update>
    <update id="updateMerchantModelByIds">
        update platform_merchant set merchant_model = #{merchantModel}
        where id in
        <foreach collection="subIds" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>
    <update id="updateAccessMode">
        update platform_merchant
        set access_mode = #{merchantApiAccessMode.accessMode}
        where id = #{merchantApiAccessMode.id}
    </update>
    <update id="updateMerchantBaseInfo">
        update platform_merchant set updated_time = NOW(),updated_account = #{request.updatedAccount},updated_by =
        #{request.updatedBy},islogin_name = #{request.isloginName}
        <if test="request.merchantName != null and request.merchantName != ''">
            ,merchant_name = #{request.merchantName}
        </if>
        <if test="request.merchantLegalPerson != null and request.merchantLegalPerson != ''">
            ,merchant_legal_person = #{request.merchantLegalPerson}
        </if>
        <if test="request.merchantLegalPersonPhone != null and request.merchantLegalPersonPhone != ''">
            ,merchant_legal_person_phone = #{request.merchantLegalPersonPhone}
        </if>
        <if test="request.lng != null">
            ,lng = #{request.lng}
        </if>
        <if test="request.lat != null">
            ,lat = #{request.lat}
        </if>
        <if test="request.provinceCode != null and request.provinceCode != ''">
            ,province_code = #{request.provinceCode}
        </if>
        <if test="request.provinceName != null and request.provinceName != ''">
            ,province_name = #{request.provinceName}
        </if>
        <if test="request.cityCode != null and request.cityCode != ''">
            ,city_code = #{request.cityCode}
        </if>
        <if test="request.cityName != null and request.cityName !=''">
            ,city_name = #{request.cityName}
        </if>
        <if test="request.merchantAddress != null and request.merchantAddress !=''">
            ,merchant_address = #{request.merchantAddress}
        </if>
        <if test="request.merchantBrandCars != null and request.merchantBrandCars !=''">
            ,merchant_brand_cars = #{request.merchantBrandCars}
        </if>
        <if test="request.merchantBrandMain != null and request.merchantBrandMain !=''">
            ,merchant_brand_main = #{request.merchantBrandMain}
        </if>
        where merchantNo = #{request.merchantNo}
    </update>
    <select id="findMerchantByPage" resultMap="resultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantRequest">
        select t1.*,t4.superior_id as parentId,
        t5. merchant_name as parentMerchant,
        t1.province_name||t1.city_name||t1.district_name||t1.merchant_address as merchantAddress
        from platform_merchant t1
        left join platform_merchant_path t4 on t1.id=t4.sub_id and t4.depth = 1 and t4.del_flag = 0
        left join platform_merchant t5 on t5.id=t4.superior_id
        where 1=1
        <if test="merchantRequest.status !=null and merchantRequest.status != ''">
            and t1.status=#{merchantRequest.status}
        </if>
        <if test="merchantRequest.source == 'USER'">
            and (t1.status not in (1) or (t1.status=1 and t1.source="USER"))
        </if>
        <if test="merchantRequest.createdSource != null">
            and t1.created_source = #{merchantRequest.createdSource}
        </if>
        <if test="merchantRequest.parentMerchant !=null and merchantRequest.parentMerchant != ''">
            and t5.merchant_name like concat('%',#{merchantRequest.parentMerchant},'%')
        </if>
        <if test="merchantRequest.merchantNo !=null and merchantRequest.merchantNo != ''">
            and t1.merchantno=#{merchantRequest.merchantNo}
        </if>
        <if test="merchantRequest.parentMerchantNo !=null and merchantRequest.parentMerchantNo != ''">
            and t5.merchantno=#{merchantRequest.parentMerchantNo}
        </if>
        <if test="merchantRequest.merchantAccountLevel !=null and merchantRequest.merchantAccountLevel != ''">
            and t1.merchant_account_level=#{merchantRequest.merchantAccountLevel}
        </if>
        <if test="merchantRequest.channelId !=null and merchantRequest.channelId != ''">
            and t1.channel_id=#{merchantRequest.channelId}
        </if>
        <if test="merchantRequest.merchantModel !=null and merchantRequest.merchantModel != ''">
            and t1.merchant_model=#{merchantRequest.merchantModel}
        </if>
        <if test="merchantRequest.entmicroName !=null and merchantRequest.entmicroName != ''">
            and t1.entmicro_name like concat('%',#{merchantRequest.entmicroName},'%')
        </if>
        <if test="merchantRequest.merchantName !=null and merchantRequest.merchantName != ''">
            and (t1.merchant_name like concat('%',#{merchantRequest.merchantName},'%') or t1.entmicro_name like
            concat('%',#{merchantRequest.merchantName},'%') )
        </if>
        <if test="merchantRequest.merchantLoginAccount !=null and merchantRequest.merchantLoginAccount != ''">
            and t1.merchant_login_account like concat('%',#{merchantRequest.merchantLoginAccount},'%')
        </if>
        <if test="merchantRequest.merchantLegalPersonPhone !=null and merchantRequest.merchantLegalPersonPhone != ''">
            and t1.merchant_legal_person_phone like concat('%',#{merchantRequest.merchantLegalPersonPhone},'%')
        </if>
        <if test="merchantRequest.isRelevance !=null">
            <choose>
                <when test="merchantRequest.isRelevance ==1 ">
                    and t1.entmicro_name is not null
                </when>
                <when test="merchantRequest.isRelevance ==2 ">
                    and t1.entmicro_name is null
                </when>
            </choose>
        </if>
        <if test="merchantRequest.accounttypeId !=null and merchantRequest.accounttypeId.size>0">
            and
            <foreach collection="merchantRequest.accounttypeId" item="item" index="index" open="(" close=")"
                     separator="or">
                FIND_IN_SET(#{item},t1.account_type)
            </foreach>
        </if>
        <if test="merchantRequest.dataPermission !=null and merchantRequest.dataPermission.size>0">
            and t1.id in
            <foreach collection="merchantRequest.dataPermission" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        ORDER BY t1.updated_time desc
    </select>

    <select id="selectById" resultMap="resultMap"
            parameterType="java.lang.Integer">
        select GROUP_CONCAT(t2.accounttype_id) as account_type,
        t1.*,
        GROUP_CONCAT(t3.accounttype_name) as accountTypeNames,
        t4.superior_id as parentId,
        (select merchant_name from platform_merchant where id = t4.superior_id) as parentMerchant,
        (select dict_label
        from platform_merchant_dict_data
        where dict_type = 'merchant_model'
        and dict_value = t1.merchant_model) as merchantModelName,
        (select dict_label
        from platform_merchant_dict_data
        where dict_type = 'account_level'
        and dict_value = t1.merchant_account_level) as accountLevelName,
        (select dict_label
        from platform_merchant_dict_data
        where dict_type = 'merchant_status'
        and dict_value = t1.status) as statusName,
        (select GROUP_CONCAT(dict_label)
        from platform_merchant_dict_data
        where dict_type = 'business_scope'
        and FIND_IN_SET(dict_value, t1.business_scope)) as businessScopName,
        (select GROUP_CONCAT(dict_label)
        from platform_merchant_dict_data
        where dict_type = 'merchant_brand'
        and FIND_IN_SET(dict_value, t1.merchant_brand)) as merchantBrandName,
        (select dict_label
        from platform_merchant_dict_data
        where dict_type = 'account_validity_period'
        and dict_value = t1.effective_time) as effectiveTimeName,
        (select GROUP_CONCAT(dict_label)
        from platform_merchant_dict_data
        where dict_type = 'business_type'
        and FIND_IN_SET(dict_value, t1.business_type)) as businessTypeName,
        t5.channel_name as channelName,
        t5.id as channelType
        from platform_merchant t1
        left join platform_merchant_accounttype_relation t2 on t1.id = t2.merchant_id and t2.del_flag = 0
        left join platform_merchant_accounttype t3 on t2.accounttype_id = t3.id and t3.del_flag = 0
        left join platform_merchant_path t4 on t1.id = t4.sub_id and depth = 1 and t4.del_flag = 0
        left join platform_merchant_channel t5 on t1.channel_id = t5.id
        where 1 = 1
        and t1.id = #{id}
    </select>
    <select id="findAllMerchant" resultMap="resultMap">
        select id,merchant_name,merchantNo from platform_merchant where 1=1 and status in (2)
        <if test="merchantRequest.dataPermission !=null and merchantRequest.dataPermission.size>0">
            and id in
            <foreach collection="merchantRequest.dataPermission" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
    </select>
    <select id="findByAccount" resultType="cn.com.glsx.merchants.model.response.MerchantResponse">
        select pt.id, pt.merchant_Model as merchantModel
        from platform_merchant pt
        left join platform_merchant_login pl on (pt.id = pl.bussinessId and pl.del_flag = 0)
        where pl.login_accout = #{account}
        and pl.merchant_no = #{merchantId} and pl.user_type = 1
    </select>
    <select id="saveSpecialMerchant" resultType="java.lang.Integer">
        select p4.merchant_product_id from platform_merchant p1
        left join platform_merchant_accounttype_relation p2 on p1.id=p2.merchant_id
        left join platform_merchant_product_relation p3 on p2.id=p3.merchant_accounttype_id and p3.del_flag=0
        left join platform_merchant_function_relation p4 on (p3.id=p4.merchant_product_id and p4.del_flag=0)
        where 1=1
        <choose>
            <when test="menuId !=null">
                and p4.menu_id=#{menuId}
            </when>
            <otherwise>
                and p3.product_id=#{productId}
            </otherwise>
        </choose>
        <if test="ownedMerchant !=null and ownedMerchant!=''">
            and p1.merchantNo in
            <foreach collection="ownedMerchant.split(',')" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="accountLevel !=null and accountLevel!=''">
            and p1.merchant_account_level in
            <foreach collection="accountLevel.split(',')" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY p4.merchant_product_id
    </select>


    <select id="findMerchantByStaffAccount" resultType="cn.com.glsx.merchants.model.response.MerchantResponse">
        select pt.merchant_id as id, pm.merchant_Model as merchantModel
        from platform_merchant_staff pt
        left join platform_merchant_login pl on (pt.id = pl.bussinessId and pl.del_flag = 0)
        left join platform_merchant pm
        on pt.merchant_id = pm.id
        where pl.login_accout = #{account}
        and pl.merchant_no = #{merchantId} and pl.user_type = 2
    </select>

    <select id="findNeedExpireMerchant" resultMap="resultMap">
        select pt.id, pt.expire_date
        from platform_merchant pt
        where
        <![CDATA[
        	DATE_ADD(pt.expire_date, INTERVAL 1 DAY) <= NOW()
        ]]>
        AND pt.status = 2
        AND pt.merchant_account_level = 4
    </select>
    <select id="findMerchantByName" resultMap="BaseResultMap">
        select *
        from platform_merchant
        where merchant_name = #{merchantName}
    </select>

    <select id="findByMerchantNo" resultMap="resultMap">
        select t1.*,t5.channel_type as channelType from platform_merchant t1
        left join platform_merchant_channel t5 on t1.channel_id=t5.id
        where merchantNo in
        <foreach collection="merchantNo.split(',')" item="item" index="index" open="(" close=")"
                 separator=",">
            #{item}
        </foreach>
    </select>
    <select id="findByIds" resultMap="resultMap">
        select * from platform_merchant where id in
        <foreach collection="visibleInferiorMer.split(',')" item="item" index="index" open="(" close=")"
                 separator=",">
            #{item}
        </foreach>
    </select>
    <select id="findMerchantList" resultMap="resultMap">

        select * from platform_merchant t1
        left join platform_merchant_channel t2 on t1.channel_id=t2.id
        where t1.del_flag = 0
        <if test="merchantOpenRequest.merchantNameAccurate !=null and merchantOpenRequest.merchantNameAccurate != ''">
            and t1.merchant_name = #{merchantOpenRequest.merchantNameAccurate}
        </if>
        <if test="merchantOpenRequest.merchantNameAccurateList !=null and merchantOpenRequest.merchantNameAccurateList.size() > 0">
            and t1.merchant_name in
            <foreach collection="merchantOpenRequest.merchantNameAccurateList" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantOpenRequest.merchantName !=null and merchantOpenRequest.merchantName != ''">
            and t1.merchant_name like concat('%',#{merchantOpenRequest.merchantName},'%')
        </if>
        <if test="merchantOpenRequest.channelType !=null and merchantOpenRequest.channelType != ''">
            and t2.channel_type=#{merchantOpenRequest.channelType}
        </if>
        <if test="merchantOpenRequest.accountTypeSet !=null and merchantOpenRequest.accountTypeSet.size>0">
            and (
            <foreach collection="merchantOpenRequest.accountTypeSet" item="item" index="index" open="(" close=")"
                     separator="or">
                FIND_IN_SET(#{item}, t1.account_type)
            </foreach>
            )
        </if>
        <if test="merchantOpenRequest.merchantNoSet !=null and merchantOpenRequest.merchantNoSet.size>0">
            and t1.merchantNo
            in
            <foreach collection="merchantOpenRequest.merchantNoSet" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantOpenRequest.merchantBrandCarsList !=null and merchantOpenRequest.merchantBrandCarsList.size>0">
            and (
            <foreach collection="merchantOpenRequest.merchantBrandCarsList" item="item" index="index" open="(" close=")"
                     separator="or">
                t1.merchant_brand_cars like CONCAT('%',#{item},'%')
            </foreach>
            )
        </if>

    </select>

    <select id="findSuperlativeMerchant" resultMap="resultMap">
        select t1.* from platform_merchant t1
        where t1.id
        in
        (select superior_id as id from platform_merchant_path pp where pp.sub_id=(select id from platform_merchant where
        merchantNo=#{merchantOpenRequest.merchantId}))
        <if test="merchantOpenRequest.merchantLevel !=null">
            and t1.merchant_account_level=#{merchantOpenRequest.merchantLevel}
        </if>
    </select>


    <select id="findSubordinateListByPage" resultMap="resultMap">
        select * from platform_merchant t1
        where t1.id
        in
        (select sub_id from platform_merchant_path pp where pp.superior_id=(select id from platform_merchant where
        merchantNo=#{merchantOpenRequest.merchantId})
        <if test="merchantOpenRequest.subMerchantFlag != null and !merchantOpenRequest.subMerchantFlag">
            and pp.depth != 0
        </if>
        <if test="merchantOpenRequest.depth != null ">
            and pp.depth = #{merchantOpenRequest.depth}
        </if>
        )
        <if test="merchantOpenRequest.merchantLevel !=null">
            and t1.merchant_account_level=#{merchantOpenRequest.merchantLevel}
        </if>
        <if test="merchantOpenRequest.merchantName !=null and merchantOpenRequest.merchantName != ''">
            and t1.merchant_name like concat('%',#{merchantOpenRequest.merchantName},'%')
        </if>
        <if test="merchantOpenRequest.isEntmicro !=null and merchantOpenRequest.isEntmicro == 1">
            and t1.entmicro_name is not null
        </if>
    </select>
    <select id="findByEntmicroId" resultMap="resultMap">
        select *
        from platform_merchant
        where entmicro_id = #{entmicroId}
    </select>

    <select id="findSubordinateList" resultMap="resultMap">
        select merchantNo,merchant_name,merchant_account_level,effective_starttime,expire_date from platform_merchant t1
        where t1.id
        in
        (select sub_id from platform_merchant_path pp
        where pp.superior_id=(select id from platform_merchant where
        merchantNo=#{merchantOpenRequest.merchantId}))
        <if test="merchantOpenRequest.merchantLevel !=null">
            and t1.merchant_account_level=#{merchantOpenRequest.merchantLevel}
        </if>
        and t1.status=2
    </select>
    <select id="findProximityMerchantList" resultMap="resultMap">
        select t1.* from platform_merchant t1
        where t1.id
        in
        (select sub_id from platform_merchant_path pp where pp.superior_id=(select id from platform_merchant where
        merchantNo=#{merchantId}))
        and t1.merchant_account_level=4
        <if test="merchantName !=null and merchantName != ''">
            and t1.merchant_name like concat('%',#{merchantName},'%')
        </if>
    </select>
    <select id="findMerchantListByPage" resultMap="resultMap">
        select t1.*,t5.merchantNo as parentId,t5.merchant_name as parentName,
        (select dict_label from platform_merchant_dict_data where dict_type='merchant_type' and
        dict_value=t1.merchant_type) as merchantTypeName,
        (select dict_label from platform_merchant_dict_data where dict_type='merchant_model' and
        dict_value=t1.merchant_model) as merchantModelName,
        (select merchant_name from platform_merchant where id=t4.superior_id) as parentMerchant,
        (select dict_label from platform_merchant_dict_data where dict_type='account_level' and
        dict_value=t1.merchant_account_level) as accountLevelName,
        (select dict_label from platform_merchant_dict_data where dict_type='merchant_status' and dict_value=t1.status)
        as statusName,
        t6.channel_type as channelType
        from platform_merchant t1
        left join platform_merchant_path t4 on t1.id=t4.sub_id and depth=1 and t4.del_flag=0
        left join platform_merchant t5 on t4.superior_id=t5.id
        left join platform_merchant_channel t6 on t1.channel_id=t6.id
        where 1=1
        <if test="merchantRequest.merchantAccountLevel !=null and merchantRequest.merchantAccountLevel.size>0">
            and t1.merchant_account_level
            in
            <foreach collection="merchantRequest.merchantAccountLevel" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantRequest.channelType !=null and merchantRequest.channelType != ''">
            and t6.channel_type=#{merchantRequest.channelType}
        </if>
        <if test="merchantRequest.parentId !=null">
            and (t5.merchantNo=#{merchantRequest.parentId} or t1.merchantNo=#{merchantRequest.parentId})
        </if>
        <if test="merchantRequest.merchantNoSet !=null and merchantRequest.merchantNoSet.size>0">
            and t1.merchantNo in
            <foreach collection="merchantRequest.merchantNoSet" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantRequest.merchantName !=null and merchantRequest.merchantName != ''">
            and t1.merchant_name like concat('%',#{merchantRequest.merchantName},'%')
        </if>
        <if test="merchantRequest.merchantNoOrName !=null and merchantRequest.merchantNoOrName != ''">
            and (t1.merchant_name like concat('%',#{merchantRequest.merchantNoOrName},'%') or t1.merchantNo =
            #{merchantRequest.merchantNoOrName})
        </if>
        <if test="merchantRequest.accounttypeId !=null and merchantRequest.accounttypeId.size>0">
            and
            <foreach collection="merchantRequest.accounttypeId" item="item" index="index" open="(" close=")"
                     separator="or">
                FIND_IN_SET(#{item},t1.account_type)
            </foreach>
        </if>
        <if test="merchantRequest.merchantModel != null">
            and t1.merchant_model = #{merchantRequest.merchantModel}
        </if>
        <if test="merchantRequest.status !=null">
            and t1.status=#{merchantRequest.status}
        </if>
        ORDER BY t1.updated_time desc
    </select>
    <select id="findBySapCode" resultMap="resultMap">
        select *
        from platform_merchant
        where sap_code = #{sapCode}
    </select>
    <select id="findSuperByMerchantNo" resultMap="resultMap">
        select merchantNo, merchant_name, merchant_account_level, effective_starttime, expire_date,
        entmicro_name,account_type
        from platform_merchant t1
        where t1.id
        in
        (select superior_id
        from platform_merchant_path pp
        where pp.sub_id = (select id
        from platform_merchant
        where merchantNo = #{merchantNo})
        and depth = 1)
    </select>
    <select id="findByAccountAndMerchantId" resultType="cn.com.glsx.merchants.model.response.MerchantResponse">
        select t4.id as id
        from
        platform_merchant_login t1
        left join platform_merchant_staff t2 on t1.bussinessId=t2.id
        LEFT JOIN platform_merchant t4 ON t2.merchant_id=t4.id
        left join platform_merchant_channel t3 on t4.channel_id=t3.id
        where t1.del_flag=0 and t1.user_type=2 and t2.del_flag=0
        and t1.login_accout=#{account}
        <if test="merchantId !=null">
            and t4.merchantno=#{merchantId}
        </if>
        and t2.id is not null
        union all
        select t2.id as id
        from platform_merchant_login t1
        left join platform_merchant t2 on t1.bussinessId=t2.id
        left join platform_merchant_channel t3 on t2.channel_id=t3.id
        where t1.del_flag=0 and t1.user_type=1
        and t1.login_accout=#{account}
        <if test="merchantId !=null">
            and t2.merchantno=#{merchantId}
        </if>
        and t2.id is not null
    </select>
    <select id="findById" resultMap="resultMap">
        select *
        from platform_merchant
        where id = #{id};
    </select>
    <select id="findMerchantSingleTableByMerchantNo"
            resultMap="resultMap">
        select *
        from platform_merchant
        where merchantNo = #{merchantNo};
    </select>

    <select id="findByIdCollection" resultMap="BaseResultMap">
        select * from platform_merchant where id in
        <foreach collection="merchantIdSet" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <select id="findAllId" resultType="java.lang.Integer">
        select id
        from platform_merchant
        where del_flag = 0;
    </select>
    <select id="findMerchantInfoToDj"
            resultType="cn.com.glsx.merchants.model.response.MerchantInfoApiDjRopResponse">
        select id,
        merchantNo,
        merchant_brand as merchantBrand,
        merchant_name as merchantName,
        bussiness_begintime as businessBeginTime,
        bussiness_endtime as businessEndTime,
        business_type as businessType
        from platform_merchant
        where merchantNo = #{merchantId};

    </select>
    <select id="findMerchantProductIdByAddMenu" resultType="java.lang.Integer">
        select p3.id from platform_merchant p1
        left join platform_merchant_accounttype_relation p2 on p1.id=p2.merchant_id
        left join platform_merchant_product_relation p3 on p2.id=p3.merchant_accounttype_id and p3.del_flag=0
        where 1=1
        <if test=" productId !=null ">
            and p3.product_id=#{productId}
        </if>
        <if test="ownedMerchant !=null and ownedMerchant!=''">
            and p1.merchantNo in
            <foreach collection="ownedMerchant.split(',')" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="accountLevel !=null and accountLevel!=''">
            and p1.merchant_account_level in
            <foreach collection="accountLevel.split(',')" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY p3.id
    </select>
    <select id="findSubMerchantbySupMerchant"
            resultType="cn.com.glsx.merchants.model.response.MerchantSubListResponse">
        SELECT pm.id AS merchantId,
        pm.merchant_name AS merchantName,
        pm.merchantNo,
        pm.merchant_account_level merchantAccountLevel,
        pm.entmicro_name AS entmicroName,
        COUNT(t1.sub_id) AS childrenNms
        FROM platform_merchant pm
        LEFT JOIN (
        SELECT pa.sub_id,
        pa.superior_id
        FROM platform_merchant_path pa
        LEFT JOIN platform_merchant pm1 ON pa.sub_id = pm1.id
        WHERE pa.depth = 1
        AND pm1.`status` = 2
        ) t1 ON t1.superior_id = pm.id
        WHERE pm.id IN (SELECT sub_id
        FROM platform_merchant_path
        WHERE superior_id = (SELECT id FROM platform_merchant WHERE merchantNo = #{merchantNo})
        AND depth = 1
        AND sub_id
        != superior_id
        AND del_flag = 0 )
        AND pm.`status` = 2
        GROUP BY
        pm.id
    </select>
    <select id="findEntMicroMerchantsByPage"
            resultType="cn.com.glsx.merchants.model.response.MerchantSearchEntMicroResponse">
        SELECT
        t1.merchantNo,
        t1.merchant_name as merchantName,
        t1.merchant_account_level as merchantAccountLevel,
        t3.merchantNo as parentMerchantNo,
        t3.merchant_name as parentMerchantName,
        COUNT(t4.sub_id) as childrenNums
        FROM platform_merchant t1
        left join platform_merchant_path t2 on t1.id=t2.sub_id and t2.depth = 1 and t2.del_flag = 0
        left join platform_merchant t3 on t3.id=t2.superior_id
        LEFT JOIN platform_merchant_path t4 ON t1.id = t4.superior_id AND t4.depth = 1 AND t4.del_flag = 0
        WHERE t1.`status` = 2 AND t1.del_flag = 0 AND t1.merchantNo IS NOT NULL AND ISNULL(t1.entmicro_name)
        <if test="condition.merchantName != null and condition.merchantName != ''">
            AND t1.merchant_name like concat('%',#{condition.merchantName,jdbcType=VARCHAR},'%')
        </if>
        AND t1.id IN (
        SELECT
        sub_id
        FROM
        platform_merchant_path
        WHERE
        superior_id = ( SELECT id FROM platform_merchant WHERE merchantNo = #{condition.parentMerchantNo}))
        GROUP BY t1.merchantNo
    </select>
    <select id="findMerchantNoListByConditiondao" resultType="java.lang.Integer">
        SELECT merchantNo FROM platform_merchant
        WHERE status = 2 and del_flag = 0
        <if test="condition.merchantAccountLevel != null">
            AND merchant_account_level = #{condition.merchantAccountLevel}
        </if>
        <if test="condition.merchantModel != null">
            AND merchant_model = #{condition.merchantModel}
        </if>
        <if test="condition.channelId != null">
            AND channel_id = #{condition.channelId}
        </if>
        <if test="condition.merchantBrandCarsList !=null and condition.merchantBrandCarsList.size>0">
            and (
            <foreach collection="condition.merchantBrandCarsList" item="item" index="index" open="(" close=")"
                     separator="or">
                merchant_brand_cars like CONCAT('%',#{item},'%')
            </foreach>
            )
        </if>
        <if test="condition.limit != null">
            limit #{condition.limit}
        </if>
    </select>
    <select id="findByMerAccountType"
            resultType="cn.com.glsx.merchants.model.response.MerchantListByConditionRpcResponse">
        select merchantNo as merchantId,merchant_name as merchantName
        from platform_merchant WHERE del_flag = 0 and status = 2
        <if test="request.merchantAccountType != null">
            and merchant_account_level = #{request.merchantAccountType}
        </if>
        <if test="request.merchantName != null and request.merchantName != ''">
            and merchant_name like concat ('%',#{request.merchantName},'%')
        </if>
    </select>
    <select id="findIdByMerchantNo" resultType="java.lang.Integer">
        select id
        from platform_merchant
        where merchantNo = #{merchantNo}
    </select>
    <select id="findMerchantListBySupMerchantNo"
            resultType="cn.com.glsx.merchants.model.response.MerchantNoNameRpcResponse">
        SELECT t2.merchantNo, t2.merchant_name as merchantName
        FROM platform_merchant t
        LEFT JOIN platform_merchant_path t1 ON t1.superior_id = t.id AND t1.del_flag = 0
        LEFT JOIN platform_merchant t2 on t1.sub_id = t2.id
        WHERE t.merchantNo = #{condition.supMerchantNo}
        AND t2.merchant_account_level = #{condition.merchantAccountLevel}
        AND t2.status = 2
    </select>
    <select id="findTopMerchantInfoByMerchantIdlist"
            resultType="cn.com.glsx.merchants.model.response.MerchantAndTopMerchantRpcResponse">
        SELECT
        t.merchantNo AS merchantId,
        t.merchant_name AS merchantName,
        t.merchant_account_level AS merchantAccountLevel,
        t.merchant_model AS merchantModel,
        t2.merchantNo AS topMerchantId,
        t2.merchant_name AS topMerchantName
        FROM
        platform_merchant t
        LEFT JOIN platform_merchant_path t1 ON t1.sub_id = t.id
        AND t1.del_flag = 0
        LEFT JOIN platform_merchant t2 ON t2.id = t1.superior_id
        WHERE
        t1.depth = ( SELECT MAX( depth ) FROM platform_merchant_path WHERE sub_id = t.id )
        <if test="list != null and  list.size > 0">
            AND t.merchantNo IN
            <foreach collection="list" item="merchantNo" index="index" separator="," open="(" close=")">
                #{merchantNo}
            </foreach>
        </if>
    </select>
    <select id="selectMaxMerchantNo" resultType="java.lang.Integer">
        SELECT merchantNo FROM platform_merchant WHERE id = (SELECT MAX(id) FROM platform_merchant )
    </select>
    <select id="searchMerchantByMerchantNos"
            resultType="cn.com.glsx.merchants.model.response.serviceCenter.SearchMerchantRpcResponse">
        SELECT t.id as merchantId,
        t.merchantNo,
        t.merchant_name as merchantName,
        t.account_type as accountType,
        t.merchant_account_level as merchantAccountLevel,
        t.merchant_legal_person_phone as merchantLegalPersonPhone,
        t.merchant_legal_person as merchantLegalPerson,
        t.created_time as createdDate,
        t1.login_password as password
        FROM platform_merchant t
        LEFT JOIN platform_merchant_login t1 ON t1.merchant_no = t.merchantNo AND t1.user_type = 1 and t1.account_type =
        2 AND t1.del_flag = 0
        WHERE t.merchantNo in
        <foreach collection="request.merchantNoList" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="request.status != null">
            <choose>
                <when test="request.status == 0">
                    and status = 2
                </when>
                <otherwise>
                    and status != 2
                </otherwise>
            </choose>
        </if>
    </select>
    <select id="findMerchantByMerchantNo" resultMap="BaseResultMap">
        select * from platform_merchant where merchantNo = #{merchantNo}
    </select>
    <select id="searchMerchantName"
            resultType="cn.com.glsx.merchants.model.response.merchant.MerchantNameResponse">
        SELECT id,merchantNo AS merchantId,merchant_name AS merchantName FROM `platform_merchant` WHERE merchantNo IN
        <foreach collection="request.merchantNoList" open="(" separator="," close=")" item="merchantId">
            #{merchantId}
        </foreach>
    </select>
    <select id="searchByMerchantNos"
            resultType="cn.com.glsx.merchants.model.response.serviceCenter.SearchMerchantRpcResponse">
        SELECT
        t.id as merchantId,
        t.merchantNo,
        t.merchant_name as merchantName,
        t.merchant_legal_person as merchantLegalPerson,
        t.merchant_legal_person_phone as merchantLegalPersonPhone,
        t.created_time as createdDate,
        count(t1.id) as staffCount,
        count(t1.staff_business_type = #{request.staffBusinessType}) as staffCountByType
        FROM platform_merchant t
        LEFT JOIN platform_merchant_staff t1 ON t1.merchant_id = t.id AND t1.del_flag = 0
        WHERE t.merchantNo in
        <foreach collection="request.merchantNoList" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and t.status = 2
        group by t.merchantNo
    </select>
    <select id="searchMerchantDetail"
            resultType="cn.com.glsx.merchants.model.response.serviceCenter.MerchantDetailResponse">
        SELECT
        t.id as merchantId,
        t.merchantNo,
        t.merchant_name as merchantName,
        t.merchant_account_level as merchantAccountLevel,
        t.account_type as accountType,
        t.merchant_legal_person as merchantLegalPerson,
        t.merchant_legal_person_phone as merchantLegalPersonPhone,
        t.created_time as createdDate,
        t.lng,
        t.lat,
        t.province_code as provinceCode,
        t.province_name as provinceName,
        t.city_code as cityCode,
        t.city_name as cityName,
        t.merchant_address as merchantAddress,
        t.city_name as cityName,
        t.merchant_brand_cars as merchantBrandCars,
        t.merchant_brand_main as merchantBrandMain,
        t1.login_accout as merchantLoginAccount,
        t1.login_password as merchantLoginPassword
        FROM platform_merchant t
        LEFT JOIN platform_merchant_login t1 on t1.merchant_no = t.merchantNo and t1.user_type = 1 and t1.del_flag = 0
        and t1.account_type = 2
        WHERE t.merchantNo = #{request.merchantNo}
    </select>
    <select id="findMerchantByCondition" resultMap="resultMap">
        select
        <include refid="Base_Column_List"></include>
        from platform_merchant
        where del_flag = 0
        <if test="request.merchantNoList != null and request.merchantNoList.size > 0">
            AND merchantNo IN
            <foreach collection="request.merchantNoList" item="merchantNo" index="index" separator="," open="("
                     close=")">
                #{merchantNo}
            </foreach>
        </if>
        <if test="request.status != null">
            AND status = #{request.status}
        </if>
        <if test="request.accountType != null">
            AND find_in_set(#{request.accountType},account_type)
        </if>
    </select>

    <select id="findAccountTypeNameByIds" resultType="java.lang.String">
        select group_concat(accounttype_name) from platform_merchant_accounttype where del_flag = 0
        and id in
        <foreach collection="list" index="index" item="item" separator="," close=")" open="(">
            #{item}
        </foreach>
    </select>

    <select id="findImportMerchantList" resultType="cn.com.glsx.merchants.dto.merchant.MerchantBasicInfo">
        select id,
        merchantNo as merchantNo,
        account_type as accountType,
        merchant_model as merchantModel,
        merchant_login_account as merchantLoginAccount,
        channel_id as channelId
        from platform_merchant
        where del_flag = 0 and status = 2 and merchant_account_level != 4 AND merchantNo is not null
    </select>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into platform_merchant(
        merchantNo,
        effective_starttime,
        expire_date,
        merchant_name,
        merchant_address,
        merchant_legal_person_phone,
        islogin_name,
        merchant_login_account,
        merchant_account_level,
        created_by,
        created_time,
        updated_time,
        del_flag,
        channel_id,
        lng,
        lat,
        province_code,
        province_name,
        city_code,
        city_name,
        status,
        created_account,
        updated_account,
        account_type,
        merchant_model,
        source,
        merchant_uuid,
        business_type,
        merchant_brand_main,
        merchant_brand_cars,
        created_source
        ) values
        <foreach collection="list" index="index" item="item" separator=",">
            (
            #{item.merchantNo},
            #{item.effectiveStarttime},
            #{item.expireDate},
            #{item.merchantName},
            #{item.merchantAddress},
            #{item.merchantLegalPersonPhone},
            #{item.isloginName},
            #{item.merchantLoginAccount},
            #{item.merchantAccountLevel},
            #{item.createdBy},
            NOW(),
            NOW(),
            0,
            #{item.channelId},
            #{item.lng},
            #{item.lat},
            #{item.provinceCode},
            #{item.provinceName},
            #{item.cityCode},
            #{item.cityName},
            2,
            #{item.createdAccount},
            #{item.createdAccount},
            #{item.accountType},
            #{item.merchantModel},
            #{item.source},
            #{item.merchantUuid},
            #{item.businessType},
            #{item.merchantBrandMain},
            #{item.merchantBrandCars},
            #{item.createdSource}
            )
        </foreach>

    </insert>

    <select id="findAllMerchantAccounts" resultType="java.lang.String">
        select merchant_login_account from platform_merchant where del_flag = 0
    </select>

    <select id="findMerchantBasicInfoList"
            parameterType="cn.com.glsx.merchants.model.request.merchant.MerchantBasicInfoRequest"
            resultType="cn.com.glsx.merchants.model.response.merchant.MerchantBasicInfoListResponse">
        select id,
        merchantNo as merchantId,
        merchant_name as merchantName,
        merchant_account_level as merchantAccountLevel,
        account_type as accountType,
        merchant_brand_main as merchantBrandMain,
        merchant_brand_cars as merchantBrandCars,
        province_code as provinceCode,
        province_name as provinceName,
        city_code as cityCode,
        city_name as cityName
        from platform_merchant
        where del_flag = 0 and status = 2
        <if test="merchantIdList != null and merchantIdList.size > 0">
            and merchantNo in
            <foreach collection="merchantIdList" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="merchantName != null and merchantName != ''">
            and merchant_name like concat('%',#{merchantName},'%')
        </if>
        <if test="districtCode != null and districtCode != ''">
            and district_code = #{districtCode}
        </if>
        <if test="cityCode != null and cityCode != ''">
            and city_code = #{cityCode}
        </if>
        <if test="provinceCode != null and provinceCode != ''">
            and province_code = #{provinceCode}
        </if>
        <if test="provinceNameList != null and provinceNameList.size() > 0">
            and
            <foreach collection="provinceNameList" separator=" OR " open="(" close=")" item="item">
                province_name like concat('%',#{item},'%')
            </foreach>
        </if>
        <if test="cityNameList != null and cityNameList.size() > 0">
            and
            <foreach collection="cityNameList" separator=" OR " open="(" close=")" item="item">
                city_name like concat('%',#{item},'%')
            </foreach>
        </if>
        group by merchantNo
        order by updated_time,id desc
    </select>
    <select id="findSimpleMerchantListByPage"
            resultType="cn.com.glsx.merchants.model.response.MerchantSimpleResponse">
        select t1.merchantNo as merchantNo,
        t1.merchant_name as merchantName
        from platform_merchant t1
        left join platform_merchant_path t4 on t1.id=t4.sub_id and depth=1 and t4.del_flag=0
        left join platform_merchant t5 on t4.superior_id=t5.id
        left join platform_merchant_channel t6 on t1.channel_id=t6.id
        where 1=1
        <if test="merchantRequest.merchantAccountLevel !=null and merchantRequest.merchantAccountLevel.size>0">
            and t1.merchant_account_level
            in
            <foreach collection="merchantRequest.merchantAccountLevel" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantRequest.channelType !=null and merchantRequest.channelType != ''">
            and t6.channel_type=#{merchantRequest.channelType}
        </if>
        <if test="merchantRequest.parentId !=null">
            and (t5.merchantNo=#{merchantRequest.parentId} or t1.merchantNo=#{merchantRequest.parentId})
        </if>
        <if test="merchantRequest.merchantNoSet !=null and merchantRequest.merchantNoSet.size>0">
            and t1.merchantNo in
            <foreach collection="merchantRequest.merchantNoSet" item="item" index="index" open="(" close=")"
                     separator=",">
                #{item}
            </foreach>
        </if>
        <if test="merchantRequest.merchantName !=null and merchantRequest.merchantName != ''">
            and t1.merchant_name like concat('%',#{merchantRequest.merchantName},'%')
        </if>
        <if test="merchantRequest.merchantNoOrName !=null and merchantRequest.merchantNoOrName != ''">
            and (t1.merchant_name like concat('%',#{merchantRequest.merchantNoOrName},'%') or t1.merchantNo =
            #{merchantRequest.merchantNoOrName})
        </if>
        <if test="merchantRequest.accounttypeId !=null and merchantRequest.accounttypeId.size>0">
            and
            <foreach collection="merchantRequest.accounttypeId" item="item" index="index" open="(" close=")"
                     separator="or">
                FIND_IN_SET(#{item},t1.account_type)
            </foreach>
        </if>
        <if test="merchantRequest.merchantModel != null">
            and t1.merchant_model = #{merchantRequest.merchantModel}
        </if>
        <if test="merchantRequest.status !=null">
            and t1.status=#{merchantRequest.status}
        </if>
        ORDER BY t1.updated_time desc

    </select>
    <select id="findMerchantListByBrandIds"
            resultType="cn.com.glsx.merchants.model.response.MerchantSimpleResponse">
        SELECT DISTINCT merchant_id merchantNo FROM `platform_merchant_brand`
        <where>
            del_flag=0
            <if test="firstBrandIdList!=null and firstBrandIdList.size>0">
                AND first_brand_id IN
                <foreach collection="firstBrandIdList" item="item" separator="," index="index" open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="secBrandIdList!=null and secBrandIdList.size>0">
                AND sec_brand_id IN
                <foreach collection="secBrandIdList" item="item"  separator="," index="index" open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    <select id="findMerchantListByBrandIds2"
            resultType="cn.com.glsx.merchants.model.response.MerchantSimpleResponse">
        SELECT merchant_id merchantNo,t2.merchant_name merchantName
        FROM `platform_merchant_brand` t1
        LEFT JOIN `platform_merchant` t2 ON t2.merchantNo=t1.merchant_id
        <where>
            t1.del_flag=0
            AND t2.del_flag=0
            <if test="firstBrandIdList!=null and firstBrandIdList.size>0">
                <if test="secBrandIdList!=null and secBrandIdList.size>0">
                    AND (t1.first_brand_id IN
                    <foreach collection="firstBrandIdList" item="item" separator="," index="index" open="(" close=")">
                        #{item}
                    </foreach>
                    OR t1.sec_brand_id IN
                    <foreach collection="secBrandIdList" item="item" separator="," index="index" open="(" close=")">
                        #{item}
                    </foreach>)
                </if>
                <if test="secBrandIdList==null or secBrandIdList.size==0">
                    AND t1.first_brand_id IN
                    <foreach collection="firstBrandIdList" item="item" separator="," index="index" open="(" close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
            <if test="firstBrandIdList==null or firstBrandIdList.size==0">
                <if test="secBrandIdList!=null and secBrandIdList.size>0">
                    AND t1.sec_brand_id IN
                    <foreach collection="secBrandIdList" item="item" separator="," index="index" open="(" close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
        GROUP BY t1.merchant_id;
    </select>

    <select id="getStaffPhoneByBrandAndScene" resultType="java.lang.String">
        select
            t.staff_phone
        from platform_merchant_staff t
        join platform_merchant t1 on t.merchant_id = t1.id
        <where>
            t.del_flag = 0
            <if test="sceneMerchantIdList != null and sceneMerchantIdList.size() > 0">
                and t1.merchantNo in
                <foreach collection="sceneMerchantIdList" item="item" separator="," index="index" open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="categoryList != null and categoryList.size() > 0">
                and exists (
                        select 1 from (
                            select t1.id
                            from platform_merchant t1
                            left join platform_merchant_brand t2 on t1.merchantNo = t2.merchant_id and t2.del_flag = 0
                            join platform_merchant_accounttype_relation t3 on t1.id = t3.merchant_id and t3.del_flag = 0
                            where t1.del_flag = 0 and t3.accounttype_id in (6, 8)
                            <trim prefix="and (" suffix=")" prefixOverrides="or">
                                <if test="hasHarmony">
                                    or (t2.first_brand_id = #{harmonyBrandId}
                                        <if test="aitoBrandIds != null and aitoBrandIds.size() > 0">
                                            and t2.sec_brand_id not in
                                            <foreach collection="aitoBrandIds" item="aitoBrandId" open="(" separator="," close=")">
                                                #{aitoBrandId}
                                            </foreach>
                                        </if>
                                    )
                                </if>
                                <if test="hasAito">
                                    <if test="aitoBrandIds != null and aitoBrandIds.size() > 0">
                                        or (t2.sec_brand_id in
                                        <foreach collection="aitoBrandIds" item="aitoBrandId" open="(" separator="," close=")">
                                            #{aitoBrandId}
                                        </foreach>)
                                    </if>
                                </if>
                                <if test="hasNormal">
                                    or (t2.first_brand_id != #{harmonyBrandId})
                                </if>
                            </trim>
                        ) tb1 where t.merchant_id = tb1.id
                )
            </if>
        </where>
    </select>

    <select id="getBrand" resultType="cn.com.glsx.merchants.model.response.MerchantBrandResponse">
        select first_brand_id firstId, sec_brand_id secondId
        from platform_merchant_brand  where merchant_id =#{merchantId} and del_flag = 0
    </select>

    <select id="findMerchantListByBrandIdsProvince" resultType="cn.com.glsx.merchants.model.response.MerchantProvinceDTO">
        SELECT DISTINCT pm.merchantNo as merchantId,
        pm.merchant_name as merchantName,
        pm.province_code as provinceCode
        FROM platform_merchant pm
        LEFT JOIN platform_merchant_brand pmb
        ON pm.merchantNo = pmb.merchant_id and pmb.del_flag = 0
        WHERE pm.del_flag = 0
        <if test="provinceIds != null and provinceIds.size() > 0">
            AND pm.province_code IN
            <foreach collection="provinceIds" item="item" separator="," index="index" open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="firstBrandIdList != null and firstBrandIdList.size() > 0">
            AND pmb.first_brand_id IN
            <foreach collection="firstBrandIdList" item="item" separator="," index="index" open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="merchantName != null and merchantName != '' ">
            AND pm.merchant_name LIKE CONCAT('%',#{merchantName},'%')
        </if>
        <if test="merchantNoList != null and merchantNoList.size() > 0">
            AND pm.merchantNo IN
            <foreach collection="merchantNoList" item="item" separator="," index="index" open="(" close=")">
                #{item}
            </foreach>
        </if>
        AND pmb.del_flag = 0
        ORDER BY pm.id;
    </select>

    <select id="findMerchantProvinceListByIds" resultType="cn.com.glsx.merchants.model.response.MerchantProvinceDTO">
        SELECT distinct merchantNo merchantId,
        province_code provinceCode,
        province_name provinceName,
        merchant_name merchantName
        FROM platform_merchant
        WHERE del_flag = 0
        <if test="merchantIds != null and merchantIds.size() > 0">
            AND merchantNo IN
            <foreach collection="merchantIds" item="item" separator="," index="index" open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="getBrandByMerchantIds" resultType="cn.com.glsx.merchants.model.response.MerchantBrandDTO">
        select
            merchant_id as merchantId,
            first_brand_id as firstBrandId,
            sec_brand_id as secBrandId
        from platform_merchant_brand
        where del_flag = 0
        <if test="merchantIds != null and merchantIds.size() > 0">
            AND merchant_id IN
            <foreach collection="merchantIds" item="item" separator="," index="index" open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>


    <!-- 1. 分页查询商户ID(仅查merchant_id,用于分页) -->
    <select id="pageListMerchantIds" parameterType="cn.com.glsx.merchants.dto.MerchantPageWithBrandDTO"
            resultType="java.lang.Integer">
        SELECT DISTINCT s.merchantNo as merchantId
        FROM platform_merchant s
        INNER JOIN platform_merchant_brand m ON s.merchantNo = m.merchant_id
        WHERE s.del_flag = 0
        AND m.del_flag = 0
        <if test="condition.brandIdList != null and condition.brandIdList.size() > 0">
            AND m.first_brand_id IN
            <foreach collection="condition.brandIdList" item="brandId" open="(" separator="," close=")">
                #{brandId}
            </foreach>
        </if>
        <if test="condition.merchantIds != null and condition.merchantIds.size() > 0">
            AND s.merchantNo IN
            <foreach collection="condition.merchantIds" item="merchantId" open="(" separator="," close=")">
                #{merchantId}
            </foreach>
        </if>
        ORDER BY s.merchantNo DESC
    </select>

    <!-- 2. 根据商户ID列表查询带品牌的详情 -->
    <select id="listMerchantWithBrandByMerchantIds" parameterType="map" resultMap="MerchantPageWithBrandDTOMap">
        SELECT DISTINCT s.merchantNo as merchant_id,
        s.merchant_name,
        IFNULL(m.first_brand_id, 0) AS brand_id,
        IFNULL(m.sec_brand_id, 0) AS child_id
        FROM platform_merchant s
        INNER JOIN platform_merchant_brand m ON s.merchantNo = m.merchant_id
        WHERE s.del_flag = 0
        AND m.del_flag = 0
        AND s.merchantNo IN
        <foreach collection="merchantIds" item="merchantId" open="(" separator="," close=")">
            #{merchantId}
        </foreach>
        ORDER BY s.merchantNo DESC
    </select>
    <select id="getMerchantNameByLastTime" resultMap="BaseResultMap">
        SELECT * FROM `platform_merchant` WHERE DATE_FORMAT(updated_time,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d') LIMIT 1000
    </select>


</mapper>