PayOrderSmapper.xml 66.8 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 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
<?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="com.zteits.order.mapper.smapper.PayOrderSmapper">
    <resultMap id="BaseResultMap" type="com.zteits.order.domain.PayOrder">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <id column="pay_order_id" jdbcType="VARCHAR" property="payOrderId"/>
        <id column="pay_finish_time" jdbcType="TIMESTAMP" property="payFinishTime"/>
        <result column="order_big_type" jdbcType="INTEGER" property="orderBigType"/>
        <result column="pay_order_type" jdbcType="INTEGER" property="payOrderType"/>
        <result column="rlt_order_id" jdbcType="VARCHAR" property="rltOrderId"/>
        <result column="transaction_id" jdbcType="VARCHAR" property="transactionId"/>
        <result column="merchant_no" jdbcType="VARCHAR" property="merchantNo"/>
        <result column="buyer_logon_id" jdbcType="VARCHAR" property="buyerLogonId"/>
        <result column="buyer_user_name" jdbcType="VARCHAR" property="buyerUserName"/>
        <result column="pay_type" jdbcType="INTEGER" property="payType"/>
        <result column="terminal_source" jdbcType="INTEGER" property="terminalSource"/>
        <result column="order_dicount_fee" jdbcType="BIGINT" property="orderDicountFee"/>
        <result column="order_act_fee" jdbcType="BIGINT" property="orderActFee"/>
        <result column="order_total_fee" jdbcType="BIGINT" property="orderTotalFee"/>
        <result column="pay_order_state" jdbcType="INTEGER" property="payOrderState"/>
        <result column="platform_service_fee" jdbcType="BIGINT" property="platformServiceFee"/>
        <result column="pay_bank_id" jdbcType="VARCHAR" property="payBankId"/>
        <result column="pay_bank_name" jdbcType="VARCHAR" property="payBankName"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="data_state" jdbcType="INTEGER" property="dataState"/>
        <result column="create_emp_id" jdbcType="VARCHAR" property="createEmpId"/>
        <result column="create_emp_name" jdbcType="VARCHAR" property="createEmpName"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="modfiy_emp_id" jdbcType="VARCHAR" property="modfiyEmpId"/>
        <result column="modfiy_emp_name" jdbcType="VARCHAR" property="modfiyEmpName"/>
        <result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate"/>
        <result column="pay_order_title" jdbcType="VARCHAR" property="payOrderTitle"/>
        <result column="pl_no" jdbcType="VARCHAR" property="plNo"/>
        <result column="error_code" jdbcType="VARCHAR" property="errorCode"/>
        <result column="error_msg" jdbcType="VARCHAR" property="errorMsg"/>
        <result column="app_id" jdbcType="VARCHAR" property="appId"/>
        <result column="coupon_person_id" jdbcType="VARCHAR" property="couponPersonId"/>
        <result column="discount_remark" jdbcType="VARCHAR" property="discountRemark"/>
        <result column="qeual_type" jdbcType="INTEGER" property="qeualType"/>
        <result column="diff_FEE" jdbcType="BIGINT" property="diffFee"/>
        <result column="diff_remark" jdbcType="VARCHAR" property="diffRemark"/>
        <result column="trade_service_fee" jdbcType="BIGINT" property="tradeServiceFee"/>
        <result column="org_id" jdbcType="BIGINT" property="orgId" />
        <result column="org_name" jdbcType="VARCHAR" property="orgName" />
    </resultMap>
    <sql id="Base_Column_List">
    id, pay_order_id, pay_finish_time, order_big_type, pay_order_type, rlt_order_id,
    transaction_id, merchant_no, buyer_logon_id, buyer_user_name, pay_type, terminal_source,
    order_dicount_fee, order_act_fee, order_total_fee, pay_order_state, pay_bank_id,
    pay_bank_name, remark, data_state, create_emp_id, create_emp_name, create_date, modfiy_emp_id,
    modfiy_emp_name, modfiy_date, pay_order_title, pl_no, error_code, error_msg, app_id,
    coupon_person_id, discount_remark,qeual_type,diff_FEE,diff_remark,trade_service_fee, org_id, org_name
  </sql>
    <!--查询除现金以为的所有支付单信息-->
    <select id="queryPayOrderForList" resultType="com.zteits.order.domain.TdBPayBlncacResult">
        select
        DATE_FORMAT(a.pay_finish_time,'%Y-%m-%d') as reportDate,
        1 as busType,
        a.pl_no as plNo,
        '' as plName,
        a.pay_order_id as payOrderId,
        a.transaction_id as transactionId,
        a.rlt_order_id as rltOrderId,
        a.pay_finish_time as payFinishTime,
        a.pay_type as payType,
        1 as orderNum,
        a.order_total_fee as totalFee,
        a.order_act_fee as actFee,
        a.app_id as appId,
        a.order_dicount_fee as dicountFee,
        '0' as refundTotalFee,
        '0' as refundActFee,
         a.order_act_fee + ifnull(a.diff_FEE,0)  as  blncaceActualFee,
         a.qeual_type as qeualType,
         a.diff_FEE as diffFee,
         a.diff_remark as diffRemark,
         a.trade_service_fee as tradeServiceFee,
         a.platform_service_fee as platformServiceFee,
         a.data_state as dataState,
         now() as createDate,
         a.create_emp_id as createEmpId,
         a.create_emp_name  as createEmpName

    from pay_order a
    where 1=1
       and a.data_state=1
       and a.pay_order_state=40 /**支付单状态:-10:失败(作废,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功*/
       and a.pay_type in(1,2,4,5,32,34) /**支付方式 1:支付宝  2:微信 3:银联 4:微信公众号 5:个人账户  6:现金 7:IC卡*/
           <![CDATA[and a.pay_finish_time >= #{beginTime}]]>
           <![CDATA[and a.pay_finish_time <= #{endTime}]]>
           and a.id%#{threadNum}=#{modId}
    </select>


    <!-- 云平台首页->今日收入汇总查询 -->
    <select id="queryCustIncomeTotal"
            parameterType="com.zteits.clouds.api.dto.order.payorder.param.CustIncomeTotalQueryRequset"
            resultType="com.zteits.order.domain.sdo.CustIncomeTotalDO">
        select
        IFNULL(sum(a.order_act_fee),0) as payedTotalAmount

        from pay_order a
        where a.data_state=1 /**数据状态:1有效,0无效*/
        and a.pay_order_state= 40 /**支付单状态:-10:失败(作废,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功*/
<!--        and a.pay_type in(1,2,4,5,6) /**支付方式 1:支付宝 2:微信 4:微信公众号 5:个人账户 6:现金*/-->
        and a.pay_order_type in(101,102,103)
        /**支付单类型:101:停车付款单,102:停车预付单,103:停车补缴单;201:余额充值单,202:押金充值;301:会员卡购买单,302:会员卡续费*/
        <if test="beginTime != null ">
            <![CDATA[ and a.pay_finish_time >= #{beginTime}  ]]>
        </if>
        <if test="endTime != null ">
            <![CDATA[ and a.pay_finish_time <= #{endTime}  ]]>
        </if>
        <if test="parkIdList != null and parkIdList.size >0">
            and a.pl_no in
            <foreach collection="parkIdList" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
    </select>
    <!-- 云平台首页 企业客户负责某个停车不同的支付方式收入情况 -->
    <select id="queryCustIncomeForPayType"
            parameterType="com.zteits.clouds.api.dto.order.payorder.param.CustIncomeTotalQueryRequset"
            resultType="com.zteits.order.domain.sdo.CustIncomeForPayTypeDO">
        select
        IFNULL(sum(a.order_act_fee),0) as payedTotalAmount,
        a.pay_type payType
        from pay_order a
        where a.data_state=1 /**数据状态:1有效,0无效*/
        and a.pay_order_state= 40 /**支付单状态:-10:失败(作废,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功*/
<!--        and a.pay_type in(1,2,4,5,6) /**支付方式 1:支付宝 2:微信 4:微信公众号 5:个人账户 6:现金*/-->
        and a.pay_order_type in(101,102,103)
        /**支付单类型:101:停车付款单,102:停车预付单,103:停车补缴单;201:余额充值单,202:押金充值;301:会员卡购买单,302:会员卡续费*/
        <if test="beginTime != null ">
            <![CDATA[ and a.pay_finish_time >= #{beginTime}  ]]>
        </if>
        <if test="endTime != null ">
            <![CDATA[ and a.pay_finish_time <= #{endTime}  ]]>
        </if>
        <if test="parkIdList != null and parkIdList.size >0">
            and a.pl_no in
            <foreach collection="parkIdList" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        group by a.pay_type
    </select>


    <!--账单管理定时任务 -->
    <select id="queryPayOrderForCheckDay" resultType="com.zteits.order.domain.TdBCheckDay">

        SELECT
            a.pl_no AS plNo,
            DATE_FORMAT(a.pay_finish_time, '%Y-%m-%d') AS checkDate,
            CASE
        WHEN a.pay_order_type IN (101, 102) THEN
            100
        WHEN a.pay_order_type IN (201, 202) THEN
            200
        WHEN a.pay_order_type IN (301, 302) THEN
            300
        WHEN a.pay_order_type =103 THEN
            103
        ELSE
            0
        END AS checkFeeType,
         sum(
            IFNULL(a.order_dicount_fee, 0)
        ) dicountFee,
         sum(IFNULL(a.order_total_fee, 0)) as  totalFee,
         sum(IFNULL(a.order_act_fee, 0)) actFee,
        sum(
            CASE
            WHEN a.pay_type = 1 THEN
                IFNULL(a.order_act_fee, 0)
            ELSE
                0
            END
        ) aliFee,
         sum(
            CASE
            WHEN a.pay_type = 1 THEN
                1
            ELSE
                0
            END
        ) aliChargeNum,
         sum(
            CASE
            WHEN a.pay_type IN (2, 4) THEN
                IFNULL(a.order_act_fee, 0)
            ELSE
                0
            END
        ) wxFee,
         sum(
            CASE
            WHEN a.pay_type IN (2, 4) THEN
                1
            ELSE
                0
            END
        ) wxChargeNum,
         sum(
            CASE
            WHEN a.pay_type = 5 THEN
                IFNULL(a.order_act_fee, 0)
            ELSE
                0
            END
        ) balanceFee,
         sum(
            CASE
            WHEN a.pay_type = 5 THEN
                1
            ELSE
                0
            END
        ) balanceChargeNum,
         sum(
            CASE
            WHEN a.pay_type = 6 THEN
                IFNULL(a.order_act_fee, 0)
            ELSE
                0
            END
        ) cashFee,
         sum(
            CASE
            WHEN a.pay_type = 6 THEN
                1
            ELSE
                0
            END
        ) cashChargeNum
        FROM
            pay_order a
        WHERE
        1=1
        AND a.data_state = 1
        AND a.pay_order_state = 40
        and a.pay_type !=7
        <![CDATA[and a.pay_finish_time >= #{beginTime}
        and a.pay_finish_time <= #{endTime}]]>
        GROUP BY
        a.pl_no,
        DATE_FORMAT(a.pay_finish_time, '%Y-%m-%d'),
        a.pay_order_type

    </select>

    <!-- 查询支付单list对象  -->
    <select id="queryPayOrder" resultMap="BaseResultMap"
            parameterType="com.zteits.order.domain.PayOrder">
        select
        <include refid="Base_Column_List"/>
        from pay_order
        where 1=1
        and pay_type !=7
        <if test="orderBigType != null">
            and order_big_type = #{orderBigType,jdbcType=INTEGER}
        </if>
        <if test="payOrderType != null">
            and pay_order_type = #{payOrderType,jdbcType=INTEGER}
        </if>
        <if test="rltOrderId != null">
            and rlt_order_id = #{rltOrderId,jdbcType=VARCHAR}
        </if>
        <if test="transactionId != null">
            and transaction_id = #{transactionId,jdbcType=VARCHAR}
        </if>
        <if test="merchantNo != null">
            and merchant_no = #{merchantNo,jdbcType=VARCHAR}
        </if>
        <if test="buyerLogonId != null">
            and buyer_logon_id = #{buyerLogonId,jdbcType=VARCHAR}
        </if>
        <if test="buyerUserName != null">
            and buyer_user_name = #{buyerUserName,jdbcType=VARCHAR}
        </if>
        <if test="payType != null">
            and pay_type = #{payType,jdbcType=INTEGER}
        </if>
        <if test="terminalSource != null">
            and terminal_source = #{terminalSource,jdbcType=INTEGER}
        </if>
        <if test="payOrderState != null">
            and pay_order_state = #{payOrderState,jdbcType=INTEGER}
        </if>
        <if test="dataState != null">
            and data_state = #{dataState,jdbcType=INTEGER}
        </if>
        <if test="plNo != null">
            and pl_no = #{plNo,jdbcType=VARCHAR}
        </if>
    </select>
    <select id="queryPayOrderByCondition"
            parameterType="com.zteits.clouds.api.dto.order.payorder.param.PayOrderQueryByConditionReq"
            resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        from pay_order
        <where>
            data_state =1
            and pay_type !=7
            <if test="plNos != null and plNos.size>0">
                AND pl_no IN
                <foreach collection="plNos" item="plNo" open="(" close=")" separator="," index="index">
                    #{plNo}
                </foreach>
            </if>
            <if test="payOrderId != null">
                AND pay_order_id = #{payOrderId}
            </if>
            <if test="orderBigType != null">
                AND order_big_type = #{orderBigType,jdbcType=INTEGER}
            </if>
            <if test="payOrderTypes != null and payOrderTypes.size>0">
                AND pay_order_type IN
                <foreach collection="payOrderTypes" item="payOrderType" open="(" close=")" separator=",">
                    #{payOrderType}
                </foreach>

            </if>
            <if test="rltOrderId != null">
                AND rlt_order_id = #{rltOrderId,jdbcType=VARCHAR}
            </if>
            <if test="transactionId != null">
                AND transaction_id = #{transactionId,jdbcType=VARCHAR}
            </if>
            <if test="merchantNo != null">
                AND merchant_no = #{merchantNo,jdbcType=VARCHAR}
            </if>

            <if test="payTypes != null and payTypes.size>0">
                AND pay_type IN
                <foreach collection="payTypes" item="payType" open="(" close=")" separator="," index="index">
                    #{payType}
                </foreach>
            </if>

            <if test="terminalSource != null">
                AND terminal_source = #{terminalSource,jdbcType=INTEGER}
            </if>

            <if test="payOrderStates != null and payOrderStates.size>0">
                AND pay_order_state IN
                <foreach collection="payOrderStates" item="payOrderState" open="(" close=")" separator=",">
                    #{payOrderState}
                </foreach>
            </if>

            <if test="payFinishTimeStart !=null">
                AND pay_finish_time &gt;=#{payFinishTimeStart}
            </if>

            <if test="payFinishTimeEnd !=null">
                AND pay_finish_time &lt;=#{payFinishTimeEnd}
            </if>
            <if test="qeualType !=null">
                AND qeual_type = #{qeualType}
            </if>

        </where>

    </select>

    <select id="queryPayOrderEtcByCondition"
            resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        from pay_order
        <where>
            data_state =1
            and pay_type !=7
            AND pay_order_state = 40
            <if test="payType != null">
                AND pay_type = #{payType,jdbcType=INTEGER}
            </if>
            <if test="terminalSource != null">
                AND terminal_source = #{terminalSource,jdbcType=INTEGER}
            </if>
            <if test="payFinishTimeStart !=null">
                AND pay_finish_time &gt;=#{payFinishTimeStart}
            </if>
            <if test="payFinishTimeEnd !=null">
                AND pay_finish_time &lt;=#{payFinishTimeEnd}
            </if>
        </where>
        and transaction_id%#{threadNum}=#{modId}

    </select>

    <!-- 收费员今日统计明细-按照支付单类型和支付方式统计 -->
    <select id="todayStatisticsForDetail" resultType="com.zteits.order.domain.sdo.RealChargeDO">
      SELECT
        pay_order_type item,
        sum( CASE WHEN pay_type = 1 THEN 1 ELSE 0 END ) aliPayNum,
        sum( CASE WHEN pay_type IN ( 2, 4 ) THEN 1 ELSE 0 END ) wxPayNum,
        sum( CASE WHEN pay_type IN ( 6, 34 ) THEN 1 ELSE 0 END ) cashPayNum,
        sum( CASE WHEN pay_type = 5 THEN 1 ELSE 0 END ) balancePayNum,
        sum( CASE WHEN pay_type = 1 AND pay_order_type IN ( 101, 102 ) THEN IFNULL( order_act_fee, 0 ) ELSE 0 END ) aliPay,
        sum( CASE WHEN pay_type IN ( 2, 4 ) AND pay_order_type IN ( 101, 102 ) THEN IFNULL( order_act_fee, 0 ) ELSE 0 END ) wxPay,
        sum( CASE WHEN pay_type = 5 AND pay_order_type IN ( 101, 102 ) THEN IFNULL( order_act_fee, 0 ) ELSE 0 END ) balancePay,
        sum( CASE WHEN pay_type IN ( 6, 34 ) AND pay_order_type IN ( 101, 102 ) THEN IFNULL( order_act_fee, 0 ) ELSE 0 END ) cashPay,
        sum(order_total_fee) totalFee,
        sum( order_act_fee ) actFee,
        sum( order_dicount_fee ) discountFee,
        sum( order_act_fee ) totalPay
      FROM
        pay_order
      where data_state = 1
      and order_big_type = 100
      and terminal_source in (2)
      and pay_order_state = 40
      and pay_order_type in (101,102)
      AND charger_code = #{chargerCode}
      AND pay_finish_time between #{beginDate} and #{endDate}
      group by pay_order_type
    </select>

    <!-- 非收费员今日收费统计明细-按照支付单类型和支付方式统计 -->
    <select id="todayFeeStatisticsFoOtherPayrDetail" resultType="com.zteits.order.domain.sdo.OtherPayForChargeDO">
        SELECT
          pay_order_type item,
          sum(case pay_type when 1 then 1 else 0 end) aliPayNum,
          sum(case pay_type when 2 then 1 else 0 end) wxPayNum,
          sum(case pay_type when 4 then 1 else 0 end) wxPublicPayNum,
          sum(case pay_type WHEN 5 THEN 1 ELSE 0 END ) balancePayNum,
          sum( CASE WHEN pay_type IN ( 6, 34 ) THEN 1 ELSE 0 END )   otherPayNum,

          sum(case pay_type when 1 then order_act_fee else 0 end) aliPay,
          sum(case pay_type when 2 then order_act_fee else 0 end) wxPay,
          sum(case pay_type when 4 then order_act_fee else 0 end) wxPublicPay,
          sum(case pay_type WHEN 5 THEN order_act_fee ELSE 0 END ) balancePay,
	      sum( CASE WHEN pay_type IN ( 6, 34 ) THEN order_act_fee ELSE 0 END ) otherPay,

          sum(order_total_fee) totalFee,
          sum(order_act_fee) actFee,
          sum(order_dicount_fee) discountFee,
          sum(order_act_fee) totalPay
          FROM
            pay_order
          where data_state = 1
          and terminal_source in (1,3,7)
          and order_big_type = 100
          and pay_order_state = 40
          and pay_order_type in (101,102)
          AND charger_code = #{chargerCode}
          AND pay_finish_time between #{beginDate} and #{endDate}
          group by pay_order_type
    </select>


    <!-- 收费员今日统计明细-按照支付单类型和支付方式统计 -->
    <select id="todayFeeStatisticsForDetailForPlatform" resultType="com.zteits.order.domain.sdo.RealChargeDO">
        SELECT
            pay_order_type item,
            sum(case pay_type when 1 then 1 else 0 end) aliPayNum,
            sum(case pay_type when 2 then 1 else 0 end) wxPayNum,
            sum(case pay_type when 6 then 1 else 0 end) cashPayNum,
            sum(case pay_type WHEN 5 THEN 1 ELSE 0 END ) balancePayNum,
            sum(case pay_type when 1 then order_act_fee else 0 end) aliPay,
            sum(case pay_type when 2 then order_act_fee else 0 end) wxPay,
            sum(case pay_type when 6 then order_act_fee else 0 end) cashPay,
            sum(case pay_type WHEN 5 THEN order_act_fee ELSE 0 END ) balancePay,
            sum(order_total_fee) totalFee,
            sum(order_act_fee) actFee,
            sum(order_dicount_fee) discountFee,
            sum(order_act_fee) totalPay
        FROM
            pay_order
        where data_state = 1
          and order_big_type = 100
          and pay_order_state = 40
          and pay_type in (1,2,5,6)
          and pay_order_type in (101,102,103)
          AND charger_code = #{chargerCode}
          AND create_date between #{beginDate} and #{endDate}
        group by pay_order_type
    </select>



    <!-- 收费员今日应收统计(不包括补缴) -->
    <select id="todayParkTotalFeeStatistic" resultType="com.zteits.order.domain.sdo.ActFeeStatisticDO">
        SELECT
      sum(order_act_fee) totalActFee,
      sum(order_total_fee) totalTotalFee,
      (
        SELECT
          sum(b.arrearage_fee) totalArrearageFee
        FROM
          order_park b
        WHERE
          b.data_state = 1
        AND b.order_state = 52
        AND b.park_out_source_code = #{chargerCode}
        AND b.park_out_time  between #{beginDate} and #{endDate}
      ) totalArrearageFee
    FROM
      pay_order
    WHERE
      data_state = 1
    AND order_big_type = 100
    AND pay_order_state = 40
    AND pay_type IN (1, 2,4,5,34, 6)
    AND pay_order_type IN (101, 102)
    AND create_emp_id = #{chargerCode}
    AND create_date between #{beginDate} and #{endDate}
    </select>
    <!-- 云平台首页 车场概况 查询各个停车场当天停车收入-->
    <select id="queryParkIncome" resultMap="BaseResultMap">
        SELECT
        a.pl_no ,
        IFNULL(sum(a.order_act_fee),0 ) as order_act_fee
        FROM
        pay_order a
        where 1=1
        and a.data_state =1 /**数据状态:1有效,0无效*/
        and a.order_big_type=100 /**关联的订单大类型:100:停车订单 200:充值订单 300:会员卡订单*/
        and a.pay_order_state =40 /**支付单状态:-10:失败,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功*/
        and a.pay_type !=7
        <![CDATA[and a.pay_finish_time >=#{beginTime}]]>
        <![CDATA[and a.pay_finish_time <=#{endTime}]]>
        <if test="plNos != null and plNos.size >0">
            and a.pl_no in
            <foreach collection="plNos" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        group by a.pl_no
    </select>


    <!-- 查询支付单list对象 根据PayOrderIds  -->
    <select id="queryPayOrderListByPayOrderIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from pay_order
        where pay_order_id in
        <foreach collection="payOrderIds" open="(" close=")" item="payOrderId" separator=",">
            #{payOrderId}
        </foreach>
        and pay_type !=7
    </select>
    <!-- 查询停车场最近7天的收入 -->
    <select id="queryParkInComeOfDay" resultType="com.zteits.order.domain.sdo.InComeOfDayDO"
            parameterType="com.zteits.clouds.api.dto.order.payorder.param.QueryInComeOfDayRequest">
        SELECT
        DATE_FORMAT(a.pay_finish_time, '%Y-%m-%d') AS dayStr,
        STR_TO_DATE(DATE_FORMAT(a.pay_finish_time, '%Y-%m-%d'), '%Y-%m-%d') AS day,
        IFNULL(sum(a.order_act_fee),0 ) as inCome
        FROM
        pay_order a
        where 1=1
        and a.data_state =1 /**数据状态:1有效,0无效*/
        and a.order_big_type in(100,300) /**关联的订单大类型:100:停车订单 200:充值订单 300:会员卡订单*/
        and a.pay_order_state =40 /**支付单状态:-10:失败,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功*/
        and a.pay_type !=7
        <![CDATA[and a.pay_finish_time >=#{startDate}]]>
        <![CDATA[and a.pay_finish_time <=#{endDate}]]>
        <if test="plNos != null and plNos.size >0">
            and a.pl_no in
            <foreach collection="plNos" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        group by DATE_FORMAT(a.pay_finish_time, '%Y-%m-%d'),STR_TO_DATE(DATE_FORMAT(a.pay_finish_time, '%Y-%m-%d'),
        '%Y-%m-%d')

    </select>
    <!-- 车场概况 查询最近支付的订单 -->
    <select id="queryRecentPayOrder" resultType="com.zteits.order.domain.sdo.OrderTransDetailDO"
            parameterType="com.zteits.clouds.api.dto.order.payorder.param.OrderRecentQueryRequest">
        select a.rlt_order_id as orderNo,
        a.pl_no as parkId,
        a.order_act_fee as orderTotalFee,
        a.pay_type as payType,
        a.pay_finish_time as createTime

        from pay_order a
        where a.data_state=1
        and a.pay_order_state=40 /**支付单状态:-10:失败(作废,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功*/
        and a.order_big_type=100 /**关联的订单大类型:100:停车订单 200:充值订单 300:会员卡订单*/
        and a.pay_type !=7
        <if test="parkIds != null and parkIds.size >0">
            and a.pl_no in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        ORDER BY a.pay_finish_time DESC
        limit #{count}

    </select>

    <select id="queryVipCardAndBackIncomeByPlNo" resultType="com.zteits.order.domain.sdo.VipCardAndBackIncomeDO">
        SELECT
        sum(CASE pay_order_type
        WHEN 103
        THEN order_act_fee
        ELSE 0 END) backIncome,

        sum(CASE WHEN pay_order_type = 103 AND pay_type = 1
        THEN order_act_fee
        ELSE 0 END) backAliIncome,


        sum(CASE WHEN pay_order_type = 103 AND pay_type in(2,4)
        THEN order_act_fee
        ELSE 0 END) backWxIncome,


        sum(CASE WHEN pay_order_type = 103 AND pay_type IN (5)
        THEN order_act_fee
        ELSE 0 END) backBalanceIncome,


        sum(CASE WHEN pay_order_type = 103 AND pay_type IN (6)
        THEN order_act_fee
        ELSE 0 END) backCashIncome,


        sum(CASE WHEN pay_order_type IN (301, 302)
        THEN order_act_fee
        ELSE 0 END) vipCardIncome,

        sum(CASE WHEN pay_order_type IN (301, 302) AND pay_type IN (1)
        THEN order_act_fee
        ELSE 0 END) vipAliIncome,

        sum(CASE WHEN pay_order_type IN (301, 302) AND pay_type IN (2,4)
        THEN order_act_fee
        ELSE 0 END) vipWxIncome,

        sum(CASE WHEN pay_order_type IN (301, 302) AND pay_type IN (5)
        THEN order_act_fee
        ELSE 0 END) vipBalanceIncome,

        sum(CASE WHEN pay_order_type IN (301, 302) AND pay_type IN (6)
        THEN order_act_fee
        ELSE 0 END) vipCashIncome,



        sum(CASE pay_order_type
        WHEN 103
        THEN 1
        ELSE 0 END) backChargeNum,

        sum(CASE WHEN pay_order_type = 103 AND pay_type IN (1,2,4,5)
        THEN 1
        ELSE 0 END) backOnlineChargeNum,

        sum(CASE WHEN pay_order_type = 103 AND pay_type IN (6)
        THEN 1
        ELSE 0 END) backOfflineChargeNum,


        sum(CASE WHEN pay_order_type IN (301, 302)
        THEN 1
        ELSE 0 END) vipCardChargeNum ,

        sum(CASE WHEN pay_order_type IN (301, 302) AND pay_type IN (1,2,4,5)
        THEN 1
        ELSE 0 END) vipOnlineChargeNum ,

        sum(CASE WHEN pay_order_type IN (301, 302) AND pay_type IN (6)
        THEN 1
        ELSE 0 END) vipOfflineChargeNum


        FROM pay_order
        WHERE data_state = 1
        and pay_type !=7
        AND pay_order_state = 40 AND pay_order_type IN (103, 301, 302) AND pl_no = #{plNo} AND
        <![CDATA[pay_finish_time >= #{startDate}
        AND  pay_finish_time <= #{endDate}]]>

    </select>

    <select id="statisticParkIncomeByPlNo" resultType="com.zteits.order.domain.sdo.ParkIncomeDO">

                SELECT
                  /**IFNULL(SUM(case when n.pay_order_type in(101,102) then
                              n.order_total_fee end), 0)   totalFee,*/
                  IFNULL(SUM(n.order_total_fee), 0)     totalFee,
                  IFNULL(SUM(n.order_act_fee), 0)     actFee,
                  IFNULL(SUM(n.order_dicount_fee), 0) dicountFee,
                  IFNULL(SUM(CASE n.pay_type
                             WHEN 1
                               THEN n.order_act_fee
                             ELSE 0 END), 0)          aliFee,

                  IFNULL(SUM(CASE n.pay_type
                             WHEN 1
                               THEN 1
                             ELSE 0 END), 0)          aliChargeNum,

                  IFNULL(SUM(CASE WHEN n.pay_type IN (2, 4)
                    THEN n.order_act_fee
                             ELSE 0 END), 0)          wxFee,

                  IFNULL(SUM(CASE WHEN n.pay_type IN (2, 4)
                    THEN 1
                             ELSE 0 END), 0)          wxChargeNum,

                  IFNULL(SUM(CASE n.pay_type
                             WHEN 6
                               THEN n.order_act_fee
                             ELSE 0 END), 0)          cashFee,

                  IFNULL(SUM(CASE n.pay_type
                             WHEN 6
                               THEN 1
                             ELSE 0 END), 0)          cashChargeNum,

                  IFNULL(SUM(CASE n.pay_type
                             WHEN 5
                               THEN n.order_act_fee
                             ELSE 0 END), 0)          balanceFee,

                  IFNULL(SUM(CASE n.pay_type
                             WHEN 5
                               THEN 1
                             ELSE 0 END), 0)          balanceChargeNum

                FROM pay_order n
                WHERE 1=1
                      and n.data_state = 1
                      and n.pay_type !=7
                      AND n.pay_order_state = 40
                      AND n.pay_order_type IN (101, 102,103)
                      <![CDATA[AND n.pay_finish_time>= #{startDate}
                      AND n.pay_finish_time<= #{endDate}]]>
                      AND n.pl_no = #{plNo};
    </select>


    <select id="statisticParkIncomeByPlNoOnlyPark" resultType="com.zteits.order.domain.sdo.ParkIncomeDO">

        SELECT
        IFNULL(SUM(n.order_total_fee), 0)   totalFee,
        IFNULL(SUM(n.order_act_fee), 0)     actFee,
        IFNULL(SUM(n.order_dicount_fee), 0) dicountFee,

        IFNULL(SUM(CASE n.pay_type
        WHEN 1
        THEN n.order_act_fee
        ELSE 0 END), 0)          aliFee,

        IFNULL(SUM(CASE n.pay_type
        WHEN 1
        THEN 1
        ELSE 0 END), 0)          aliChargeNum,

        IFNULL(SUM(CASE WHEN n.pay_type IN (2, 4)
        THEN n.order_act_fee
        ELSE 0 END), 0)          wxFee,

        IFNULL(SUM(CASE WHEN n.pay_type IN (2, 4)
        THEN 1
        ELSE 0 END), 0)          wxChargeNum,

        IFNULL(SUM(CASE n.pay_type
        WHEN 6
        THEN n.order_act_fee
        ELSE 0 END), 0)          cashFee,

        IFNULL(SUM(CASE n.pay_type
        WHEN 6
        THEN 1
        ELSE 0 END), 0)          cashChargeNum,

        IFNULL(SUM(CASE n.pay_type
        WHEN 5
        THEN n.order_act_fee
        ELSE 0 END), 0)          balanceFee,

        IFNULL(SUM(CASE n.pay_type
        WHEN 5
        THEN 1
        ELSE 0 END), 0)          balanceChargeNum

        FROM pay_order n
        WHERE 1=1
        and n.data_state = 1
        and n.pay_type !=7
        AND n.pay_order_state = 40
        AND n.pay_order_type IN (101, 102)
        <![CDATA[AND n.pay_finish_time>= #{startDate}
                      AND n.pay_finish_time<= #{endDate}]]>
        AND n.pl_no = #{plNo};
    </select>


    <select id="staticVipCardIncomebyPlNo" resultType="com.zteits.order.domain.IncomeStatisticVipCardDay">
      SELECT
        count(*)               orderNum,
        IFNULL(SUM(t.order_total_fee),0) totalFee,
        IFNULL(SUM(t.order_act_fee) ,0)  actFee,
        IFNULL(SUM(t.order_dicount_fee),0) dicountFee,

        IFNULL(SUM(CASE t.terminal_source
        WHEN 1
        THEN 1
        ELSE 0 END),0)        appNum,

        IFNULL(SUM(CASE t.terminal_source
        WHEN 3
        THEN 1
        ELSE 0 END) ,0)       wxNum,

        IFNULL(SUM(CASE t.terminal_source
        WHEN 4
        THEN 1
        ELSE 0 END),0)        platformNum,

        IFNULL(SUM(CASE WHEN t.terminal_source IN (2, 5)
        THEN 1
        ELSE 0 END),0)        siteNum,


        IFNULL(SUM(CASE t.pay_type
        WHEN 1
        THEN t.order_act_fee
        ELSE 0 END)  ,0)      aliFee,

        IFNULL(SUM(CASE t.pay_type
        WHEN 1
        THEN 1
        ELSE 0 END) ,0)       aliChargeNum,

        IFNULL(SUM(CASE WHEN t.pay_type IN (2, 4)
        THEN t.order_act_fee
        ELSE 0 END) ,0)       wxFee,

        IFNULL(SUM(CASE WHEN t.pay_type IN (2, 4)
        THEN 1
        ELSE 0 END) ,0)       wxChargeNum,

        IFNULL(SUM(CASE t.pay_type
        WHEN 6
        THEN t.order_act_fee
        ELSE 0 END) ,0)       cashFee,

        IFNULL(SUM(CASE t.pay_type
        WHEN 6
        THEN 1
        ELSE 0 END) ,0)       cashChargeNum,

        IFNULL(SUM(CASE t.pay_type
        WHEN 5
        THEN t.order_act_fee
        ELSE 0 END) ,0)       balanceFee,

        IFNULL(SUM(CASE t.pay_type
        WHEN 5
        THEN 1
        ELSE 0 END),0)        balanceChargeNum

        FROM pay_order t
        WHERE t.data_state = 1
        and t.pay_type !=7
        AND t.order_big_type = 300
        AND t.pay_order_state = 40
        AND t.pl_no = #{plNo}
        <![CDATA[AND t.pay_finish_time >= #{startDate}
        AND t.pay_finish_time < #{endDate}]]>


    </select>


    <select id="staticBackIncomebyPlNo" resultType="com.zteits.order.domain.IncomeStatisticBackDay">

      SELECT
        count(*)               orderNum,
        IFNULL(SUM(t.order_total_fee),0) totalFee,
        IFNULL(SUM(t.order_act_fee),0)   actFee,
        IFNULL(SUM(t.order_dicount_fee),0) dicountFee,

        IFNULL(SUM(CASE t.terminal_source
        WHEN 1
        THEN 1
        ELSE 0 END),0)        appNum,

        IFNULL(SUM(CASE t.terminal_source
        WHEN 3
        THEN 1
        ELSE 0 END),0)        wxNum,

       IFNULL( SUM(CASE t.terminal_source
        WHEN 4
        THEN 1
        ELSE 0 END),0)        platformNum,

        IFNULL(SUM(CASE WHEN t.terminal_source IN (2, 5)
        THEN 1
        ELSE 0 END) ,0)       siteNum,


        IFNULL(SUM(CASE t.pay_type
        WHEN 1
        THEN t.order_act_fee
        ELSE 0 END),0)        aliFee,

        IFNULL(SUM(CASE t.pay_type
        WHEN 1
        THEN 1
        ELSE 0 END),0)        aliChargeNum,

        IFNULL(SUM(CASE WHEN t.pay_type IN (2, 4)
        THEN t.order_act_fee
        ELSE 0 END),0)        wxFee,

        IFNULL(SUM(CASE WHEN t.pay_type IN (2, 4)
        THEN 1
        ELSE 0 END),0)        wxChargeNum,

        IFNULL(SUM(CASE t.pay_type
        WHEN 6
        THEN t.order_act_fee
        ELSE 0 END) ,0)       cashFee,

        IFNULL(SUM(CASE t.pay_type
        WHEN 6
        THEN 1
        ELSE 0 END),0)        cashChargeNum,

        IFNULL(SUM(CASE t.pay_type
        WHEN 5
        THEN t.order_act_fee
        ELSE 0 END) ,0)       balanceFee,

        IFNULL(SUM(CASE t.pay_type
        WHEN 5
        THEN 1
        ELSE 0 END) ,0)       balanceChargeNum

        FROM pay_order t
        WHERE t.data_state = 1
        and t.pay_type !=7
        AND t.pay_order_type = 103
        AND t.pay_order_state = 40
        AND t.pl_no = #{plNo}
        <![CDATA[AND t.pay_finish_time >= #{startDate}
        AND t.pay_finish_time < #{endDate}]]>


    </select>
    <select id="getOrderCollections" resultType="com.zteits.clouds.api.dto.syncdata.dto.GetOrderCollectionsDTO">

        SELECT a.*,b.refundOrderTotalFee
        from
        (SELECT
        pl_no AS parkId,
        SUM(CASE WHEN pay_type = 1 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS aliTotalFee,
        SUM(CASE WHEN pay_type = 1 THEN 1 ELSE 0 END) AS aliDealCount,
        SUM(CASE WHEN pay_type IN(2,4) THEN IFNULL(order_total_fee,0) ELSE 0 END) AS wxTotalFee,
        SUM(CASE WHEN pay_type IN(2,4) THEN 1 ELSE 0 END) AS wxDealCount,
        SUM(CASE WHEN pay_type = 6 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS cashTotalFee,
        SUM(CASE WHEN pay_type = 6 THEN 1 ELSE 0 END) AS cashDealCount,
        SUM(CASE WHEN pay_type = 3 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS ylTotalFee,
        SUM(CASE WHEN pay_type = 3 THEN 1 ELSE 0 END) AS ylDealCount,

        SUM(CASE WHEN pay_order_type =101 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS payOrderTotalFee,

        SUM(CASE WHEN pay_order_type IN(201,202) THEN IFNULL(order_total_fee,0) ELSE 0 END) AS rechargeOrderTotalFee,
        SUM(CASE WHEN pay_order_type =102 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS prepayOrderTotalFee,
        SUM(CASE WHEN pay_order_type =103 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS supplyOrderTotalFee,
        SUM(CASE WHEN pay_type = 6 THEN IFNULL(order_total_fee,0) ELSE 0 END) AS lineOrderTotalFee,
        MAX(pay_finish_time) AS billDayTime,
        GROUP_CONCAT(remark) AS remark

        FROM
        pay_order
        WHERE
        1 = 1
        AND data_state = 1
        and pay_type !=7
        <if test="parkIds != null and parkIds.size >0">
            and pl_no in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[AND pay_finish_time >= #{startDate}
        AND pay_finish_time <= #{endDate}]]>
        GROUP BY
        pl_no)a
        LEFT JOIN
        (SELECT
        pl_no AS parkId,
        SUM(IFNULL(refund_total_fee,0)) AS refundOrderTotalFee
        FROM
        order_refund
        WHERE
        1 = 1
        AND data_state = 1
        AND order_state = 70
        <if test="parkIds != null and parkIds.size >0">
            and pl_no in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[AND pay_finish_time >= #{startDate}
        AND pay_finish_time <= #{endDate}]]>
        GROUP BY
        pl_no)b
        ON a.parkId = b.parkId


    </select>

    <select id="queryReconciliationTotal"
            parameterType="com.zteits.clouds.api.dto.order.reconciliation.param.ReconciliationTotalReq"
            resultType="com.zteits.clouds.api.dto.order.reconciliation.dto.ReconciliationTotalDTO">
        SELECT

        COUNT(*)                      allNum,
        IFNULL(SUM(order_act_fee), 0) allFee,
        IFNULL(SUM(CASE WHEN qeual_type = 1
        THEN diff_FEE
        ELSE 0 END), 0)    allDiffFee,


        IFNULL(SUM(CASE WHEN pay_type = 1
        THEN 1
        ELSE 0 END), 0)    aliNum,
        IFNULL(SUM(CASE WHEN pay_type = 1
        THEN order_act_fee
        ELSE 0 END), 0)    aliFee,
        IFNULL(SUM(CASE WHEN pay_type = 1 AND qeual_type = 1
        THEN diff_FEE
        ELSE 0 END), 0)    aliDiffFee,


        IFNULL(SUM(CASE WHEN pay_type IN (2, 4)
        THEN 1
        ELSE 0 END), 0)    wxNum,
        IFNULL(SUM(CASE WHEN pay_type IN (2, 4)
        THEN order_act_fee
        ELSE 0 END), 0)    wxFee,
        IFNULL(SUM(CASE WHEN pay_type = 1 AND qeual_type = 1
        THEN diff_FEE
        ELSE 0 END), 0)    wxDiffFee,


        IFNULL(SUM(CASE WHEN pay_type = 5
        THEN 1
        ELSE 0 END), 0)    balanceNum,
        IFNULL(SUM(CASE WHEN pay_type = 5
        THEN order_act_fee
        ELSE 0 END), 0)    balanceFee,
        IFNULL(SUM(CASE WHEN pay_type = 5 AND qeual_type = 1
        THEN diff_FEE
        ELSE 0 END), 0)    balanceDiffFee

        FROM pay_order
        WHERE data_state = 1
        AND pay_type IN (1, 2, 4, 5)
        AND pay_order_state IN (40)
        AND pl_no IN
        <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
            #{plNo}
        </foreach>
        AND pay_finish_time BETWEEN #{beginTime} AND #{endTime}

    </select>


    <!-- 查询需要开票的订单  -->
    <select id="queryRntPayOrderForInvoice" resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderForInvoiceDTO">
        select org_id as orgId,rlt_order_id as rltOrderId,
        max(pl_no) as plNo,min(pay_order_type) as payOrderType,sum(order_act_fee) as orderActFee,
        max(pay_finish_time) as payFinishTime,max(pay_type) as payType,
        sum(order_total_fee) as orderTotalFee,
        sum(order_dicount_fee) as orderDicountFee,
        max(B.create_date) as createDate,
        max(B.car_number) carNumber,
        max(B.eff_date) as effDate,
        max(B.exp_date) as expDate
        from pay_order,
        (
        <if test="(carNumbers != null and carNumbers.size >0) or (orderIds != null and orderIds.size >0)">
            select order_id,create_date,car_number,null as eff_date,null as exp_date
            from order_park
            where data_state = 1 and invoice_state = 0
            and order_state in (40, 50)
            <if test="carNumbers != null and carNumbers.size >0">
                and car_number in
                <foreach collection="carNumbers" item="carNumber" separator="," open="(" close=")">
                    #{carNumber}
                </foreach>
            </if>
            <if test="orderIds != null and orderIds.size >0">
                and order_id in
                <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                    #{orderId}
                </foreach>
            </if>
            union all
            select b.order_id,b.create_date,b.car_number,b.eff_date,b.exp_date
            FROM order_vipcard a,
            order_vipcard_detail b
            where a.data_state = 1 and a.order_id = b.order_id
            and a.order_state in (40, 50)
            and b.invoice_state = 0
            <if test="carNumbers != null and carNumbers.size >0">
                and b.car_number in
                <foreach collection="carNumbers" item="carNumber" separator="," open="(" close=")">
                    #{carNumber}
                </foreach>
            </if>
            <if test="orderIds != null and orderIds.size >0">
                and a.order_id in
                <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                    #{orderId}
                </foreach>
            </if>
            union all
            select b.order_id,b.create_date,b.car_number,null as eff_date,null as exp_date
            FROM order_back a,
            order_back_detail b
            where a.data_state = 1 and a.order_id = b.order_id
            and a.order_state in (40, 50)
            and a.invoice_state = 0
            <if test="carNumbers != null and carNumbers.size >0">
                and b.car_number in
                <foreach collection="carNumbers" item="carNumber" separator="," open="(" close=")">
                    #{carNumber}
                </foreach>
            </if>
            <if test="orderIds != null and orderIds.size >0">
                and a.order_id in
                <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                    #{orderId}
                </foreach>
            </if>
            group by a.order_id
            union all
        </if>
        select order_id,create_date,'' as car_number,null as eff_date,null as exp_date
        FROM order_recharge a
        where data_state = 1
        and order_state in (40, 50)
        and invoice_state = 0
        and cust_id = #{custId}
        )B
        where data_state = 1
        <if test="orderIds != null and orderIds.size >0">
            and rlt_order_id in
            <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                #{orderId}
            </foreach>
        </if>
        <if test="payOrderTypes != null and payOrderTypes.size >0">
            and pay_order_type in
            <foreach collection="payOrderTypes" open="(" close=")" item="payOrderType" separator=",">
                #{payOrderType}
            </foreach>
        </if>
        and pay_type in (1,2,3,4,32,34)
        and terminal_source in (1,2,3,5,7,13,11)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        <if test="orgIds != null and orgIds.size >0 ">
            AND org_id IN
            <foreach collection="orgIds" item="orgId" index="index" open="(" close=")" separator=",">
                #{orgId}
            </foreach>
        </if>
        group by org_id,rlt_order_id
        order by max(pay_finish_time) desc
    </select>

    <!-- 企业平台临停+补缴开票查询  -->
    <select id="queryPayOrderForParkingInvoice" parameterType="com.zteits.clouds.api.dto.order.payorder.param.PayOrderParkingInvoiceRequest" resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderParkingInvoiceDTO">
        select
            org_id as orgId,
            rlt_order_id as rltOrderId,
            max(pl_no) as plNo,
            min(pay_order_type) as payOrderType,
            sum(order_total_fee) as orderTotalFee,
            sum(order_act_fee) as orderActFee,
            max(pay_finish_time) as payFinishTime,
            max(pay_type) as payType,
            sum(order_dicount_fee) as orderDicountFee,
            max(B.park_out_time) as parkOutTime,
            max(B.create_date) as createDate,
            max(B.car_number) carNumber,
            max(B.cust_id) custId ,
            max(B.invoice_state) invoiceState
        from pay_order,
        (
            select order_id,create_date,car_number,'临停' as type,invoice_state,park_out_time,cust_id
            from order_park
            where data_state = 1
            and order_state in (40, 50)
            and park_out_time  BETWEEN #{parkOutTimeStart} AND #{parkOutTimeEnd}
           <if test="invoiceState != null">
                and invoice_state = #{invoiceState}
           </if>

            <if test="carNumber != null  and carNumber != ''">
                and car_number = #{carNumber}
            </if>
            <if test="carNumbers != null and carNumbers.size >0">
                and car_number in
                <foreach collection="carNumbers" item="carNumber" separator="," open="(" close=")">
                    #{carNumber}
                </foreach>
            </if>
            <if test="orderIds != null and orderIds.size >0">
                and order_id in
                <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                    #{orderId}
                </foreach>
            </if>
            union all
            select b.order_id,b.create_date,b.car_number,'补缴' as type,invoice_state,park_out_time,'' as cust_id
            FROM order_back a,
            order_back_detail b
            where a.data_state = 1 and a.order_id = b.order_id
            and a.order_state in (40, 50)
            <if test="invoiceState != null">
                and invoice_state = #{invoiceState}
            </if>
            and park_out_time  BETWEEN #{parkOutTimeStart} AND #{parkOutTimeEnd}
        <if test="carNumber != null  and carNumber != ''">
            and b.car_number = #{carNumber}
        </if>
            <if test="carNumbers != null and carNumbers.size >0">
                and b.car_number in
                <foreach collection="carNumbers" item="carNumber" separator="," open="(" close=")">
                    #{carNumber}
                </foreach>
            </if>
            <if test="orderIds != null and orderIds.size >0">
                and a.order_id in
                <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                    #{orderId}
                </foreach>
            </if>
            group by a.order_id
        )B
        where data_state = 1
        and pay_type in (1,2,3,4,32,34)
        and terminal_source in (1,2,3,5,7,13,11)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        and pay_finish_time  BETWEEN #{payFinishTimeStart} AND #{payFinishTimeEnd}
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        group by org_id,rlt_order_id
        order by max(pay_finish_time) desc
    </select>


    <!-- 会员卡开票  -->
    <select id="queryPayOrderForVipCardInvoice" parameterType="com.zteits.clouds.api.dto.order.payorder.param.PayOrderParkingInvoiceRequest" resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderParkingInvoiceDTO">
        select  org_id as orgId,
        rlt_order_id as rltOrderId,
        max(pl_no) as plNo,
        min(pay_order_type) as payOrderType,
        sum(order_act_fee) as orderActFee,
        max(pay_finish_time) as payFinishTime,
        max(pay_type) as payType,
        sum(order_total_fee) as orderTotalFee,
        sum(order_dicount_fee) as orderDicountFee,
        max(B.create_date) as createDate,
        max(B.car_number) carNumber,
        max(B.eff_date) as effDate,
        max(B.exp_date) as expDate,
        max(B.order_id) as orderId,
        max(B.person_cust_id) as custId,
        max(B.invoice_state) as invoiceState,
        max(B.pl_name) as plName,
        max(B.vip_card_no) as vipCardNo,
        max(B.modify_date) as modifyDate,
        max(B.remark) as remark

        from pay_order,
        (
            select b.order_id,b.create_date,b.car_number,b.eff_date,b.exp_date,b.person_cust_id,b.invoice_state,b.pl_name,b.vip_card_no,b.modify_date,b.remark
            FROM order_vipcard a,
            order_vipcard_detail b
            where a.data_state = 1 and a.order_id = b.order_id
            and a.order_state in (40, 50)
            <if test="invoiceState != null">
                and b.invoice_state = #{invoiceState}
            </if>
            <if test="vipCardNo != null">
                and b.vip_card_no = #{vipCardNo}
            </if>
            <if test="vipCardNos != null and vipCardNos.size >0">
                and b.vip_card_no in
                <foreach collection="vipCardNos" item="vipCardNo" separator="," open="(" close=")">
                    #{vipCardNo}
                </foreach>
            </if>
            <if test="carNumbers != null and carNumbers.size >0">
                and b.car_number in
                <foreach collection="carNumbers" item="carNumber" separator="," open="(" close=")">
                    #{carNumber}
                </foreach>
            </if>
            <if test="carNumber != null">
                and car_number = #{carNumber}
            </if>
            <if test="orderIds != null and orderIds.size >0">
                and a.order_id in
                <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                    #{orderId}
                </foreach>
            </if>

        )B
        where data_state = 1
        and pay_type in (1,2,3,4,32,34)
        and terminal_source in (1,2,3,5,7,13,11)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        <if test="payFinishTimeStart !=null">
            AND pay_finish_time &gt;=#{payFinishTimeStart}
        </if>
        <if test="payFinishTimeEnd !=null">
            AND pay_finish_time &lt;=#{payFinishTimeEnd}
        </if>
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        group by org_id,rlt_order_id
        order by max(pay_finish_time) desc
    </select>


    <!-- 会员卡开票  -->
    <select id="queryPayOrderForCustAcctInvoice" parameterType="com.zteits.clouds.api.dto.order.payorder.param.PayOrderParkingInvoiceRequest" resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderParkingInvoiceDTO">
        select org_id as orgId,
        rlt_order_id as rltOrderId,
        max(pl_no) as plNo,
        min(pay_order_type) as payOrderType,
        sum(order_act_fee) as orderActFee,
        max(pay_finish_time) as payFinishTime,
        max(pay_type) as payType,
        sum(order_total_fee) as orderTotalFee,
        sum(order_dicount_fee) as orderDicountFee,
        max(B.create_date) as createDate,
        max(B.acct_id) acctId,
        max(B.cust_id) custId,
        max(B.invoice_state) as invoiceState
        from pay_order,
        (
        select order_id,create_date,a.invoice_state,a.acct_id,a.cust_id
        FROM order_recharge a
        where data_state = 1
        and order_state in (40, 50)
        <if test="custId != null">
            and cust_id = #{custId}
        </if>
        <if test="invoiceState != null">
            and invoice_state = #{invoiceState}
        </if>
        )B
        where data_state = 1
        and pay_type in (1,2,3,4,32,34)
        and terminal_source in (1,3,7,13)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        and pay_finish_time  BETWEEN #{payFinishTimeStart} AND #{payFinishTimeEnd}
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        group by org_id,rlt_order_id
        order by max(pay_finish_time) desc
    </select>

    <!-- 查询需要开票的订单 暂时不用 -->
    <select id="queryRntPayOrderForInvoice11" resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderForInvoiceDTO">
        select org_id as orgId,rlt_order_id as rltOrderId,
        max(pl_no) as plNo,min(pay_order_type) as payOrderType,sum(order_act_fee)  as orderActFee,
        max(pay_finish_time) as payFinishTime,max(pay_type) as payType,
        sum(order_total_fee) as orderTotalFee,
        sum(order_dicount_fee) as orderDicountFee,
        max(B.create_date) as createDate,
        max(B.car_number) carNumber
        from pay_order,
        (
        select order_id,create_date,car_number
        from order_park
        where data_state = 1 and invoice_state = 0
        and order_state in (40, 50)
        and cust_id = #{custId}
        union all
        select b.order_id,b.create_date,b.car_number
        FROM order_vipcard a,
        order_vipcard_detail b
        where a.data_state = 1 and a.order_id = b.order_id
        and a.order_state in (40, 50)
        and b.invoice_state = 0
        and b.person_cust_id = #{custId}
        union all
        select b.order_id,b.create_date,b.car_number
        FROM order_back a,
        order_back_detail b
        where a.data_state = 1 and a.order_id = b.order_id
        and a.order_state in (40, 50)
        and a.invoice_state = 0
        and b.back_emp_id = #{custId}
        )B
        where data_state = 1
        <if test="orderIds != null and orderIds.size >0">
            and rlt_order_id in
            <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                #{orderId}
            </foreach>
        </if>
        and pay_type in (1,2,3,4,5)
        and terminal_source in (1,3,13)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        group by rlt_order_id
        order by max(pay_finish_time) desc
    </select>

    <!--从支付单中查询需要结算的记录信息-->
    <select id="queryPayOrderForSettlementRecord" resultType="com.zteits.order.domain.sdo.TdBSettlementRecordDO">
        SELECT
        a.org_id as orgId,
        date(a.pay_finish_time) as checkDate,
        sum(IFNULL(a.order_act_fee, 0)) + sum(IFNULL(b.online_service_fee, 0)) AS settlementTotalFee,
        sum( IFNULL(b.online_service_fee, 0)) AS platformSrvFee,
        sum( IFNULL(a.order_act_fee, 0)) AS settlementActFee,
        sum(CASE WHEN a.pay_type = 1  THEN
        IFNULL(a.order_act_fee, 0)
        ELSE 0
        END) aliFee,
        0 as aliRefundFee,
        sum(CASE WHEN a.pay_type = 1  THEN
        IFNULL(b.online_service_fee, 0)
        ELSE 0
        END) aliSrvFee,
        sum(CASE WHEN a.pay_type = 1 THEN
        1
        ELSE
        0
        END) aliChargeNum,
        sum(CASE WHEN a.pay_type IN (2, 4)  THEN
        IFNULL(a.order_act_fee, 0)
        ELSE
        0
        END) wxFee,
        0 as wxRefundFee,
        sum(CASE WHEN a.pay_type IN (2, 4)  THEN
        IFNULL(b.online_service_fee, 0)
        ELSE
        0
        END) wxSrvFee,
        sum(CASE WHEN a.pay_type IN (2, 4) THEN
        1
        ELSE
        0
        END ) wxChargeNum,
        sum(CASE WHEN a.pay_type = 5 and a.pay_order_state=40 THEN
        IFNULL(a.order_act_fee, 0)
        ELSE
        0
        END) balanceFee,
        sum(CASE WHEN a.pay_type = 5  and a.pay_order_state=70 THEN
           0
        ELSE
        0
        END) balanceRefundFee,
        sum(CASE WHEN a.pay_type = 5  THEN
        0
        ELSE
        0
        END) balanceSrvFee,
        sum(CASE WHEN a.pay_type = 5 THEN
        1
        ELSE
        0
        END) balanceChargeNum,
        1 as  checkStatus
        FROM
        pay_order_success  a,td_b_pay_order_check_result b
        where 1=1
        and a.pay_order_id=b.pay_order_id
        and b.check_result_type=3
        and a.data_state=1
        and b.bus_type=1 /**业务类型: 1:收入 2:退款 3:支出*/
        and date(a.pay_finish_time)=  date(#{payFinshTime})
        and a.pay_type in(1,2,4) /**支付方式 1:支付宝 2:微信 4:微信公众号 6:现金.*/
        AND a.pay_order_state in(40) /**-10:失败(作废,20:待支付,30:支付中,40:已支付,60:退款中,70:退款成功.*/
        group by date(a.pay_finish_time),a.org_id
    </select>



    <!-- 查询收入统计-根据组织ID -->
    <select id="queryIncomeStaByOrgIds"
            parameterType="com.zteits.clouds.api.dto.park.param.parksource.QueryParkSourceByOrgIdsRequest"
            resultType="com.zteits.clouds.api.dto.order.payorder.dto.IncomeStatisticDTO">
        select
        IFNULL(sum( order_act_fee  ),0) totalPay,
        IFNULL(sum(case when pay_type = 1 then order_act_fee end ),0) aliPay,
        IFNULL(sum(case when pay_type = 2 or pay_type = 4 then order_act_fee end ),0) wxPay,
        IFNULL(sum(case when pay_type != 1 and pay_type != 2 and pay_type != 4 then order_act_fee end ),0) otherPay
        from pay_order
        where data_state = 1
        and pay_type !=7
        and pay_order_state = 40
        and org_id in
        <foreach collection="orgIds" open="(" close=")" item="orgId" separator=",">
            #{orgId}
        </foreach>
        <if test="plNos != null and plNos.size >0">
            and pl_no in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        AND create_date between #{beginTime} and #{endTime}
    </select>

     <!--查询用户充值记录信息-->
    <select id="queryRechargeForUser" parameterType="com.zteits.clouds.api.dto.park.param.QueryRechargeForUserReq"
            resultType="com.zteits.clouds.api.dto.order.payorder.dto.UserRechargeDTO">
         SELECT
                a.pay_order_id as payOrderId,
                a.rlt_order_id as rltOrderId ,
                a.pay_type as payType,
                a.transaction_id as transactionId,
                a.create_emp_id as custId,
                a.order_total_fee as orderTotalFee,
                a.order_dicount_fee as orderDicountFee,
                a.order_act_fee as orderActFee,
                a.pay_finish_time as payFinishTime,
                b.refund_total_fee as refundTotalFee,
                a.org_id as orgId,
                b.refund_finish_time as refundFinishTime,
                (case when b.order_state is null then
                   100
                  else
                   b.order_state
                end) as refundState,
              b.error_msg as errorMsg,
              b.refund_reason as refundReason

            FROM
                pay_order a left join order_refund b on(a.pay_order_id=b.rlt_pay_order_id and b.data_state=1)
            WHERE 1=1
            and a.data_state=1
            AND a.order_big_type = 200
            AND a.pay_type in(1,2,4,32)
            and a.terminal_source=1 /**终端来源:1:任你听 2:pda 3:微信公共号 4:云平台,5:道闸*/
            <![CDATA[and a.pay_finish_time >= #{beginTime}
            and a.pay_finish_time <= #{endTime}]]>
            and a.org_id=#{orgId}

            <if test="payorderIds != null and payorderIds.size >0">
                <choose>
                    <when test="refundState==100">
                        and a.pay_order_id not in
                    </when>
                    <otherwise>
                        and a.pay_order_id  in
                    </otherwise>
                </choose>
                <foreach collection="payorderIds" open="(" close=")" item="payOrderId" separator=",">
                    #{payOrderId}
                </foreach>

            </if>



            <if test="custIds != null and custIds.size >0">
                and a.create_emp_id in
                <foreach collection="custIds" open="(" close=")" item="custId" separator=",">
                    #{custId}
                </foreach>

            </if>


    </select>


	<!-- 查询车主每月消费金额 -->
    <select id="queryOwnerPayOutByMonth" resultType="com.zteits.clouds.api.dto.owner.dto.OwnerPayOutDTO"
            parameterType="com.zteits.clouds.api.dto.owner.param.OwnerRequest">
        select
	        IFNULL(SUM(order_act_fee),0) AS fee,
			DATE_FORMAT(pay_finish_time,'%Y-%m') dateStr
        from pay_order
        where 1=1
        and create_emp_id=#{custId}
        and data_state = 1
        and pay_order_state = 40
        and pay_type in(1,2,4,5,6,32) /**支付方式 1:支付宝 2:微信 4:微信公众号 5:个人账户 6:现金*/
        and pay_finish_time BETWEEN #{beginTime} AND #{endTime}
        group by dateStr
    </select>

    <select id="queryPayOrderByOrderPark" resultType="java.lang.Integer"
            parameterType="com.zteits.clouds.api.dto.order.payorder.param.PayOrderByOrderParkReq">
        select
            pay_type
        from pay_order
        where 1=1
        and rlt_order_id = #{orderId}
        and pay_order_state = 40
    </select>

    <!-- 查询车牌的使用第三方优惠的次数 -->
    <select id="queryThirdDiscNumByCarNumber" parameterType="com.zteits.clouds.api.dto.order.payorder.param.ThirdDIscPayOrderByCarNumberReq"
        resultType="com.zteits.clouds.api.dto.order.payorder.dto.ThirdDiscNumDTO">
    select
       ifnull(sum(case
               when date_format(pay_finish_time, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d') then 1
               else 0 end),0) todayDiscNum,
       count(id)           monthDiscNum
        from pay_order
        where data_state = 1
          and pay_order_state = 40
          and pay_finish_time > date_format(#{monthBeginTime}, '%Y-%m-%d')
          and org_id = #{orgId}
          and third_disc_fee > 0
          and third_disc_no = #{thirdDiscNo}
          and car_number = #{carNumber}
    </select>

    <!-- 查询任你停用户使用农行充值优惠的次数 -->
    <select id="queryThirdDiscNumByCustId" parameterType="com.zteits.clouds.api.dto.order.payorder.param.ThirdDIscPayOrderByCustIdReq"
            resultType="com.zteits.clouds.api.dto.order.payorder.dto.ThirdDiscNumDTO">
    select
       ifnull(sum(case
               when date_format(pay_finish_time, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d') then 1
               else 0 end),0) todayDiscNum,
       count(id)           monthDiscNum
        from pay_order
        where data_state = 1
          and pay_order_state = 40
          and pay_finish_time > date_format(#{monthBeginTime}, '%Y-%m-%d')
          and org_id = #{orgId}
          and third_disc_fee > 0
          and third_disc_no = #{thirdDiscNo}
          and create_emp_id = #{custId}
    </select>



    <!-- 通过支付单ID,修改对应的appId (用于更新ETC 的appId) -->
    <update id="updatePayOrderAppIdByPayOrderId" parameterType="com.zteits.order.domain.PayOrder">

        update
            pay_order
          set
              app_id = #{appId}
          where
              pay_order_id = #{payOrderId}
    </update>
    <!-- 商户充值开票-->
    <select id="queryPayOrderForCustAcctInvoiceForBusiness"
            resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderParkingInvoiceDTO">
        select org_id as orgId,
        rlt_order_id as rltOrderId,
        max(pl_no) as plNo,
        min(pay_order_type) as payOrderType,
        sum(order_act_fee) as orderActFee,
        max(pay_finish_time) as payFinishTime,
        max(pay_type) as payType,
        sum(order_total_fee) as orderTotalFee,
        sum(order_dicount_fee) as orderDicountFee,
        max(B.create_date) as createDate,
        max(B.acct_id) acctId,
        max(B.cust_id) custId,
        max(B.business_name) as businessName,
        max(B.invoice_state) as invoiceState
        from pay_order,
        (
        select order_id,create_date,a.invoice_state,a.acct_id,a.cust_id,a.business_id,a.business_name
        FROM order_recharge a
        where data_state = 1
        and order_state in (40, 50)
        <if test="custId != null">
            and cust_id = #{custId}
        </if>
        <if test="invoiceState != null">
            and invoice_state = #{invoiceState}
        </if>
        )B
        where data_state = 1
        and pay_type in (1,2,3,4,32,34,12,16)
        and terminal_source in (1,3,11,16)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        and pay_finish_time  BETWEEN #{payFinishTimeStart} AND #{payFinishTimeEnd}
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        group by org_id,rlt_order_id
        order by max(pay_finish_time) desc
    </select>

    <!-- 20220808商户端增加查询需要开票的订单  -->
    <select id="queryRntPayOrderForBusinessInvoice" resultType="com.zteits.clouds.api.dto.order.payorder.dto.PayOrderForInvoiceDTO">
        select org_id as orgId,rlt_order_id as rltOrderId,
        terminal_source as terminalSource,
        max(pl_no) as plNo,min(pay_order_type) as payOrderType,sum(order_act_fee) as orderActFee,
        max(pay_finish_time) as payFinishTime,max(pay_type) as payType,
        sum(order_total_fee) as orderTotalFee,
        sum(order_dicount_fee) as orderDicountFee,
        max(B.create_date) as createDate,
        max(B.car_number) carNumber,
        max(B.eff_date) as effDate,
        max(B.exp_date) as expDate
        <if test="year != null">
            from pay_order${year},
        </if>
        <if test="year == null">
            from pay_order,
        </if>
        (
        select order_id,create_date,'' as car_number,null as eff_date,null as exp_date
        FROM order_recharge a
        where data_state = 1
        and order_state in (40, 50)
        and invoice_state = 0
        and cust_id = #{custId}
        )B
        where data_state = 1
        <if test="orderIds != null and orderIds.size >0">
            and rlt_order_id in
            <foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
                #{orderId}
            </foreach>
        </if>
        <if test="payOrderTypes != null and payOrderTypes.size >0">
            and pay_order_type in
            <foreach collection="payOrderTypes" open="(" close=")" item="payOrderType" separator=",">
                #{payOrderType}
            </foreach>
        </if>
        and pay_type in (1,2,3,4,6,32,34,12,16)
        and terminal_source in (1,2,3,4,7,11,16)
        and pay_order_state = 40
        and rlt_order_id = B.order_id
        <if test="orgId != null">
            and org_id = #{orgId}
        </if>
        group by org_id,rlt_order_id
        order by max(pay_finish_time) desc
    </select>
</mapper>