OrderArrearageSMapper.xml 33 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
<?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.OrderArrearageSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.order.domain.OrderArrearage">
        <id column="id" jdbcType="BIGINT" property="id" />
	    <result column="order_id" jdbcType="VARCHAR" property="orderId" />
	    <result column="order_big_type" jdbcType="INTEGER" property="orderBigType" />
	    <result column="order_state" jdbcType="INTEGER" property="orderState" />
	    <result column="source_type" jdbcType="INTEGER" property="sourceType" />
	    <result column="order_dicount_fee" jdbcType="BIGINT" property="orderDicountFee" />
	    <result column="order_total_fee" jdbcType="BIGINT" property="orderTotalFee" />
	    <result column="order_act_fee" jdbcType="BIGINT" property="orderActFee" />
	    <result column="arrearage_fee" jdbcType="BIGINT" property="arrearageFee" />
	    <result column="cust_id" jdbcType="VARCHAR" property="custId" />
	    <result column="cust_name" jdbcType="VARCHAR" property="custName" />
	    <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
	    <result column="pl_name" jdbcType="VARCHAR" property="plName" />
	    <result column="car_number" jdbcType="VARCHAR" property="carNumber" />
        <result column="car_number_color" jdbcType="INTEGER" property="carNumberColor" />
	    <result column="car_type" jdbcType="INTEGER" property="carType" />
	    <result column="pre_park_in_time" jdbcType="TIMESTAMP" property="preParkInTime" />
	    <result column="pre_park_out_time" jdbcType="TIMESTAMP" property="preParkOutTime" />
	    <result column="park_in_time" jdbcType="TIMESTAMP" property="parkInTime" />
	    <result column="park_out_time" jdbcType="TIMESTAMP" property="parkOutTime" />
	    <result column="berth_range_no" jdbcType="VARCHAR" property="berthRangeNo" />
	    <result column="berth_range_name" jdbcType="VARCHAR" property="berthRangeName" />
	    <result column="berth_no" jdbcType="VARCHAR" property="berthNo" />
	    <result column="park_in_source_code" jdbcType="VARCHAR" property="parkInSourceCode" />
	    <result column="park_in_source_name" jdbcType="VARCHAR" property="parkInSourceName" />
	    <result column="park_out_source_code" jdbcType="VARCHAR" property="parkOutSourceCode" />
	    <result column="park_out_source_name" jdbcType="VARCHAR" property="parkOutSourceName" />
	    <result column="parking_duration" jdbcType="BIGINT" property="parkingDuration" />
	    <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="remark" jdbcType="VARCHAR" property="remark" />
	    <result column="pre_act_fee" jdbcType="BIGINT" property="preActFee" />
	    <result column="pre_total_fee" jdbcType="BIGINT" property="preTotalFee" />
	    <result column="overtime_total_fee" jdbcType="BIGINT" property="overtimeTotalFee" />
	    <result column="overtime_act_fee" jdbcType="BIGINT" property="overtimeActFee" />
	    <result column="org_id" jdbcType="BIGINT" property="orgId" />
	    <result column="org_name" jdbcType="VARCHAR" property="orgName" />
    </resultMap>
    <sql id="Base_Column_List">
    id, order_id, order_big_type, order_state, source_type, order_dicount_fee, order_total_fee,
    order_act_fee, arrearage_fee, cust_id, cust_name, pl_no, pl_name, car_number, car_type,
    pre_park_in_time, pre_park_out_time, park_in_time, park_out_time, berth_range_no,
    berth_range_name, berth_no, park_in_source_code, park_in_source_name, park_out_source_code,
    park_out_source_name, parking_duration, data_state, create_emp_id, create_emp_name,
    create_date, modfiy_emp_id, modfiy_emp_name, modfiy_date, remark, pre_act_fee, pre_total_fee,
    overtime_total_fee, overtime_act_fee, org_id, org_name,car_number_color
  </sql>

    <sql id="selective_where_condition">
        <if test="orderId != null">
            AND order_id = #{orderId,jdbcType=VARCHAR},
        </if>
        <if test="orderBigType != null">
            AND order_big_type = #{orderBigType,jdbcType=INTEGER},
        </if>
        <if test="orderState != null">
            AND order_state = #{orderState,jdbcType=INTEGER},
        </if>
        <if test="orderTotalFee != null">
            AND order_total_fee,
        </if>
        <if test="orderActFee != null">
            AND order_act_fee,
        </if>
        <if test="orderArrearFee != null">
            AND arrearage_fee,
        </if>
        <if test="custId != null">
            AND cust_id = #{custId,jdbcType=VARCHAR},
        </if>
        <if test="custName != null">
            AND cust_name = #{custName,jdbcType=VARCHAR},
        </if>
        <if test="plNo != null">
            AND pl_no = #{plNo,jdbcType=VARCHAR},
        </if>
        <if test="plName != null">
            AND pl_name = #{plName,jdbcType=VARCHAR},
        </if>
        <if test="carNumber != null">
            AND car_number = #{carNumber,jdbcType=VARCHAR},
        </if>
        <if test="carNumberColor != null">
            AND car_number_color = #{carNumberColor}
        </if>
        <if test="carType != null">
            AND car_type = #{carType,jdbcType=VARCHAR},
        </if>
        <if test="parkInTime != null">
            AND park_in_time = #{parkInTime,jdbcType=TIMESTAMP},
        </if>
        <if test="parkOutTime != null">
            AND park_out_time = #{parkOutTime,jdbcType=TIMESTAMP},
        </if>
        <if test="berthRangeNo != null">
            AND berth_range_no = #{berthRangeNo,jdbcType=VARCHAR},
        </if>
        <if test="berthRangeName != null">
            AND berth_range_name = #{berthRangeName,jdbcType=VARCHAR},
        </if>
        <if test="berthNo != null">
            AND berth_no = #{berthNo,jdbcType=VARCHAR},
        </if>
        <if test="parkInSourceCode != null">
            AND park_in_source_code = #{parkInSourceCode,jdbcType=VARCHAR},
        </if>
        <if test="parkInSourceName != null">
            AND park_in_source_name = #{parkInSourceName,jdbcType=VARCHAR},
        </if>
        <if test="parkOutSourceCode != null">
            AND park_out_source_code = #{parkOutSourceCode,jdbcType=VARCHAR},
        </if>
        <if test="parkOutSourceName != null">
            AND park_out_source_name = #{parkOutSourceName,jdbcType=VARCHAR},
        </if>
        <if test="parkingDuration != null">
            AND parking_duration = #{parkingDuration,jdbcType=BIGINT},
        </if>
        <if test="dataState != null">
            AND data_state = #{dataState,jdbcType=INTEGER},
        </if>
        <if test="createEmpId != null">
            AND create_emp_id = #{createEmpId,jdbcType=VARCHAR},
        </if>
        <if test="createDate != null">
            AND create_date = #{createDate,jdbcType=TIMESTAMP},
        </if>
        <if test="modfiyEmpId != null">
            AND modfiy_emp_id = #{modfiyEmpId,jdbcType=VARCHAR},
        </if>
        <if test="modfiyDate != null">
            AND modfiy_date = #{modfiyDate,jdbcType=TIMESTAMP},
        </if>
        <if test="remark != null">
            AND remark = #{remark,jdbcType=VARCHAR},
        </if>
    </sql>


    <select id="pageQueryArrearRecordByCondition" resultMap="BaseResultMap"
            parameterType="com.zteits.clouds.api.dto.order.arrearageorder.param.ArrearOrderPageQueryByContidionReq">

        SELECT
        <include refid="Base_Column_List"/>
        FROM order_arrearage
        <where>
            data_state = 1

            <if test="orderId != null">
                AND order_id = #{orderId}
            </if>

            <if test="orderBigType != null">
                AND order_big_type = #{orderBigType}
            </if>
            <if test="orderState != null">
                AND order_state = #{orderState}
            </if>
            <if test="sourceType != null">
                AND source_type = #{sourceType}
            </if>
            <if test="plNos != null and plNos.size != 0 ">
                AND pl_no in
                <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                    #{plNo}
                </foreach>
            </if>
            <if test="chargeCode != null">
                AND (park_in_source_code LIKE CONCAT(#{chargeCode},'%' ) OR park_out_source_code LIKE
                CONCAT(#{chargeCode},'%' )
            </if>
            <if test="carNum != null">
                AND car_number LIKE CONCAT(#{carNum,jdbcType=VARCHAR},'%' )
            </if>
            <if test="carNumber != null">
                AND car_number = #{carNumber,jdbcType=VARCHAR}
            </if>
            <if test="carNumbers != null and carNumbers.size >0 ">
	            AND car_number IN
	            <foreach collection="carNumbers" item="carN" index="index" open="(" close=")" separator=",">
	                #{carN}
	            </foreach>
	        </if>
            <if test="allMatchCarNum != null">
                AND car_number = #{allMatchCarNum}
            </if>
            <if test="inTimeStart != null">
                AND park_in_time &gt;= #{inTimeStart}
            </if>
            <if test="inTimeEnd != null">
                AND park_in_time &lt;= #{inTimeEnd}
            </if>
            <if test="outTimeStart != null">
                AND park_out_time &gt;= #{outTimeStart}
            </if>
            <if test="outTimeEnd != null">
                AND park_out_time &lt;= #{outTimeEnd}
            </if>
            <if test="custId != null and custId !=''">
                AND cust_id = #{custId}
            </if>
            <if test="orgId != null">
                AND org_id = #{orgId}
            </if>
			<if test="orderStates != null and orderStates.size >0 ">
            	AND order_state IN
            <foreach collection="orderStates" item="orderState" index="index" open="(" close=")" separator=",">
                #{orderState}
            </foreach>
        </if>
        </where>
        order by create_date desc

    </select>


    <select id="queryArrearageSta" resultType="com.zteits.clouds.api.dto.pda.dto.ArrearsRecordStaDTO"
            parameterType="com.zteits.clouds.api.dto.order.arrearageorder.param.ArrearOrderPageQueryByContidionReq">

        SELECT
        sum(arrearage_fee) arrearageTotalFee,
        count(1) arrearageNum
        FROM order_arrearage
        <where>
            data_state = 1

            <if test="orderId != null">
                AND order_id = #{orderId}
            </if>

            <if test="orderBigType != null">
                AND order_big_type = #{orderBigType}
            </if>
            <if test="orderState != null">
                AND order_state = #{orderState}
            </if>
            <if test="sourceType != null">
                AND source_type = #{sourceType}
            </if>
            <if test="plNos != null and plNos.size != 0 ">
                AND pl_no in
                <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                    #{plNo}
                </foreach>
            </if>
            <if test="chargeCode != null">
                AND (park_in_source_code LIKE CONCAT(#{chargeCode},'%' ) OR park_out_source_code LIKE
                CONCAT(#{chargeCode},'%' ))
            </if>
            <if test="carNum != null">
                AND car_number LIKE CONCAT(#{carNum,jdbcType=VARCHAR},'%' )
            </if>
            <if test="carNumbers != null and carNumbers.size >0 ">
                AND car_number IN
                <foreach collection="carNumbers" item="carNumber" index="index" open="(" close=")" separator=",">
                    #{carNumber}
                </foreach>
            </if>
            <if test="allMatchCarNum != null">
                AND car_number = #{allMatchCarNum}
            </if>
            <if test="inTimeStart != null">
                AND park_in_time &gt;= #{inTimeStart}
            </if>
            <if test="inTimeEnd != null">
                AND park_in_time &lt;= #{inTimeEnd}
            </if>
            <if test="outTimeStart != null">
                AND park_out_time &gt;= #{outTimeStart}
            </if>
            <if test="outTimeEnd != null">
                AND park_out_time &lt;= #{outTimeEnd}
            </if>
            <if test="custId != null and custId !=''">
                AND cust_id = #{custId}
            </if>
            <if test="orgId != null">
                AND org_id = #{orgId}
            </if>
            <if test="orderStates != null and orderStates.size >0 ">
                AND order_state IN
                <foreach collection="orderStates" item="orderState" index="index" open="(" close=")" separator=",">
                    #{orderState}
                </foreach>
            </if>
        </where>

    </select>

    <select id="queryArrearageSumFeeByCondition" resultType="java.lang.Long"
            parameterType="com.zteits.order.domain.OrderArrearage">

        SELECT
        ifnull(sum(arrearage_fee),0) sumFee
        FROM order_arrearage
        <where>
            <include refid="selective_where_condition"/>
        </where>


    </select>

    <select id="queryArrearageOrderForCheckDay" resultType="com.zteits.order.domain.TdBCheckDay">
        SELECT
          pl_no as plNo,
          order_big_type as checkFeeType,
          DATE_FORMAT(park_out_time, '%Y-%m-%d') AS  checkDate,
          sum(IFNULL(arrearage_fee, 0)) arrearageFee
        FROM order_arrearage
        where data_state=1
        and order_state=52
        and park_out_time BETWEEN #{beginTime} and #{endTime}
        GROUP BY
            plNo,
            checkFeeType,
            DATE_FORMAT(park_out_time, '%Y-%m-%d')
    </select>

    <select id="queryArrearFeeByPlNo" resultType="java.lang.Long">

        SELECT ifnull(sum(arrearage_fee),0) FROM order_arrearage WHERE pl_no = #{plNo} AND park_out_time &gt;= #{startTime} AND park_out_time &lt;=#{endTime}
    </select>


    <select id="queryArrearFeeWithBackByPlNo" resultType="java.lang.Long">

        SELECT ifnull(sum(arrearage_fee),0) FROM order_arrearage WHERE pl_no = #{plNo} AND park_out_time &gt;= #{startTime} AND park_out_time &lt;=#{endTime}
        and data_state=1
        and order_state = 53
    </select>

    <!-- 根据条件查询欠费汇总信息 -->
	<select id="queryArrearTotalByCondition" resultType="com.zteits.clouds.api.dto.order.arrearageorder.dto.ArrearageTotalDTO"
            parameterType="com.zteits.clouds.api.dto.order.arrearageorder.param.ArrearOrderCommonConditionReq">
        SELECT
            IFNULL( SUM( a.arrearageFee ), 0 ) arrearageFee,
            IFNULL( SUM( a.carNum ), 0 ) carNum,
            IFNULL( SUM( a.arrearageNum ), 0 ) arrearageNum
        FROM
        (SELECT
			IFNULL(SUM(arrearage_fee), 0) arrearageFee,
			IFNULL(COUNT(DISTINCT car_number), 0) carNum,
			IFNULL(COUNT(id), 0) arrearageNum
		FROM
			`order_arrearage`
		WHERE
			data_state = 1
			AND order_state in(10,20,30,52,-10)
		<if test="plNos != null and plNos.size != 0 ">
             AND pl_no in
             <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                 #{plNo}
             </foreach>

		  </if>
        <if test="carNumber != null and carNumber != ''">
            AND car_number LIKE CONCAT(#{carNumber,jdbcType=VARCHAR},'%' )
        </if>
		  <if test="carNumberColor != null">
            AND car_number_color = #{carNumberColor}
		  </if>
        <if test="beginTime != null">
            AND park_out_time &gt;= #{beginTime}
        </if>
        <if test="endTime != null">
            AND park_out_time &lt;= #{endTime}
        </if>
        <if test="orgId != null">
            AND org_id = #{orgId}
        </if>
        <if test="type == 0">
            group by	pl_no
        </if>
        <if test="type == 1">
            group by   car_number
        </if>
        <if test="type == 3">
            group by id
        </if>
        <if test="minArrearageFee != null or maxArrearageFee != null or  minArrearageNum != null   or maxArrearageNum != null  "  >
            HAVING 1=1
            <if test="minArrearageFee != null">
                and arrearageFee >= #{minArrearageFee}
            </if>
            <if test="maxArrearageFee != null">
                and arrearageFee &lt;= #{maxArrearageFee}
            </if>

            <if test="minArrearageNum != null">
                and count(*) >= #{minArrearageNum}
            </if>
            <if test="maxArrearageNum != null">
                and count(*) &lt;= #{maxArrearageNum}
            </if>

        </if>
        ) a

    </select>

    <!-- 根据条件查询欠费列表(按停车场&车主) -->
    <select id="queryArrearListForParkOrCarNumber" resultType="com.zteits.clouds.api.dto.order.arrearageorder.dto.ArrearageListDTO"
            parameterType="com.zteits.clouds.api.dto.order.arrearageorder.param.ArrearOrderCommonConditionReq">
        SELECT
        	<if test="dateFlag == 1">
        		MAX(park_out_time) staticDate,
        	</if>
        	<if test="dateFlag == 0">
        		DATE_FORMAT(park_out_time,'%Y-%m-01') staticDate,
        	</if>
			IFNULL(SUM(arrearage_fee), 0) arrearageFee,
			car_number carNumber,
            car_number_color as carNumberColor,
			pl_no plNo,
			pl_name plName,
			IFNULL(count(id), 0) arrearageNum,
            min(park_in_time) minParkInTime,
            max(park_out_time) maxParkOutTime

		FROM
			`order_arrearage`
		WHERE
			data_state = 1
			AND order_state = 52
            and arrearage_fee>0
		<if test="plNos != null and plNos.size != 0 ">
             AND pl_no in
             <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                 #{plNo}
             </foreach>
        </if>
        <if test="carNumber != null and carNumber != ''">
            AND car_number = #{carNumber}
        </if>
        <if test="beginTime != null">
            AND park_out_time &gt;= #{beginTime}
        </if>
        <if test="endTime != null">
            AND park_out_time &lt;= #{endTime}
        </if>
        <if test="orgId != null">
            AND org_id = #{orgId}
        </if>

        <if test="type == 0">
            group by	pl_no
       	</if>
       	<if test="type == 1">
            group by   car_number
       	</if>
        <if test="type == 3">
            group by id
        </if>
        <if test="dateFlag != null">
        	<if test="dateFlag == 1">

        	</if>
        	<if test="dateFlag == 0">
        		,DATE_FORMAT(park_out_time,'%Y-%m-01')
        	</if>
        </if>
        <if test="minArrearageFee != null or maxArrearageFee != null or  minArrearageNum != null   or maxArrearageNum != null  "  >
        	HAVING 1=1
        	<if test="minArrearageFee != null">
        		and arrearageFee >= #{minArrearageFee}
        	</if>
        	<if test="maxArrearageFee != null">
        		and arrearageFee &lt;= #{maxArrearageFee}
        	</if>

            <if test="minArrearageNum != null">
                and count(*) >= #{minArrearageNum}
            </if>
            <if test="maxArrearageNum != null">
                and count(*) &lt;= #{maxArrearageNum}
            </if>

        </if>
        <choose>
	        <when test="baseRequest != null and baseRequest.sortName != null and baseRequest.sortOrder != null
	        	and baseRequest.sortName != '' and baseRequest.sortOrder != ''">
	            ORDER BY ${baseRequest.sortName} ${baseRequest.sortOrder}
	        </when>
<!--	        <otherwise>-->
<!--	             ORDER BY staticDate ASC-->
<!--	        </otherwise>-->
    	</choose>
    </select>



    <!-- 根据欠费订单数量 -->
    <select id="queryArrerageOrderStatistsc" resultType="java.lang.Integer"
            parameterType="com.zteits.clouds.api.dto.order.parkorder.param.OrderParkQueryReq">
        select
        ifnull(count(1),0)
        from order_park o
        where 1=1
        <if test="parkStateList != null and parkStateList.size >0 ">
            AND o.park_state IN
            <foreach collection="parkStateList" item="parkState" index="index" open="(" close=")" separator=",">
                #{parkState}
            </foreach>
        </if>
        <if test="orderStateList != null and orderStateList.size >0 ">
            AND o.order_state IN
            <foreach collection="orderStateList" item="orderState" index="index" open="(" close=")" separator=",">
                #{orderState}
            </foreach>
        </if>
        <if test="carNumberList != null and carNumberList.size >0 ">
            AND o.car_number IN
            <foreach collection="carNumberList" item="carNumber" index="index" open="(" close=")" separator=",">
                #{carNumber}
            </foreach>
        </if>
        <if test="carColorList != null and carColorList.size >0 ">
            and
            <foreach collection="carColorList" item="carColor" index="index" open="(" close=")" separator="">
                <if test="index == 0">
                    ( o.car_number = #{carColor.carNumber}
                    <if test="carColor.carNumberColor != null">
                        and o.car_number_color = #{carColor.carNumberColor}
                    </if>
                    )
                </if>
                <if test="index != 0">
                    or ( o.car_number = #{carColor.carNumber}
                    <if test="carColor.carNumberColor != null">
                        and o.car_number_color = #{carColor.carNumberColor}
                    </if>
                    )
                </if>
            </foreach>
        </if>
        <if test="orgId != null">
            AND o.org_id = #{orgId}
        </if>
        and o.data_state = 1
    </select>
    <!--财务管理-账单管理(对账助手) 查询当天欠费金额及总金额(目前欠费总金额=当天欠费金额)-->
    <select id="queryArrearageOrderByTimeForFinanceBill" resultType="com.zteits.order.domain.IncomeFinanceBill">
        SELECT
          /**欠费金额.*/
          IFNULL(sum(IFNULL(arrearage_fee, 0)),0) arrearageFeeTotal,
           /**当天欠费金额.*/
          IFNULL(sum(IFNULL(arrearage_fee, 0)),0) currentArrearageFeeTotal
        FROM order_arrearage
        where data_state=1
        and order_state in(52,53)
        and pl_no=#{plNo}
        and park_out_time BETWEEN #{startTime} and #{endTime}
    </select>

    <!--通过停车场编码、车牌号、欠费最小值、欠费最大值 查询欠费金额-->
    <select id="queryArrearageFeeByPlNoAndCarNum" resultType="java.lang.Long">
          SELECT
                IFNULL(sum(a.arrearage_fee),0)
            FROM
                order_arrearage a
            where 1=1
                and a.data_state=1
                #and a.order_state=52
                and a.pl_no=#{plNo}
                and a.car_number=#{carNum}
                and a.arrearage_fee BETWEEN #{minArrearageFee} and #{maxArrearageFee}
    </select>

    <!--查询当前用户绑定车牌欠费总额-->
    <select id="queryCustArrearageSumFee" resultType="java.lang.Long"
            parameterType="com.zteits.clouds.api.dto.order.arrearageorder.param.ArrearOrderSumFeeQueryByConditionReq">

        SELECT
        ifnull(sum(arrearage_fee),0) sumFee
        FROM order_arrearage
        where data_state = 1
        and order_state = 52
        and car_number in
        <foreach collection="carNumbers" separator="," item="carNumber" open="(" close=")">
            #{carNumber}
        </foreach>


    </select>
    <select id="queryChargerArrearageFee" resultType="java.lang.Long">
        select
            ifnull(sum(arrearage_fee),0) sumFee
        from order_arrearage t
        where t.data_state = 1
          and t.park_out_source_code = #{chargerCode}
          and t.park_out_time between #{beginTime} and #{endTime}
          and t.order_state in (52, 53)

    </select>
    <select id="queryArrearListForParkOrCarNumberWithVipCard"
            resultType="com.zteits.clouds.api.dto.order.arrearageorder.dto.ArrearageListDTO">

        SELECT
        <if test="dateFlag == 1">
            MAX(park_out_time) staticDate,
        </if>
        <if test="dateFlag == 0">
            DATE_FORMAT(park_out_time,'%Y-%m-01') staticDate,
        </if>
        IFNULL(SUM(arrearage_fee), 0) arrearageFee,
        car_number carNumber,
        car_number_color as carNumberColor,
        pl_no plNo,
        pl_name plName,
        IFNULL(count(id), 0) arrearageNum,
        min(park_in_time) minParkInTime,
        max(park_out_time) maxParkOutTime

        FROM
        `order_arrearage`
        WHERE
        data_state = 1
        AND order_state = 52
        and arrearage_fee>0
        <if test="plNos != null and plNos.size != 0 ">
            AND pl_no in
            <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                #{plNo}
            </foreach>
        </if>

        <if test="vipCarList != null and vipCarList.size != 0 ">
            AND car_number in
            <foreach collection="vipCarList" separator="," item="plateNumber" open="(" close=")">
                #{plateNumber}
            </foreach>
        </if>
        <if test="carNumber != null and carNumber != ''">
            AND car_number = #{carNumber}
        </if>
        <if test="beginTime != null">
            AND park_out_time &gt;= #{beginTime}
        </if>
        <if test="carNumberColorStr != null and carNumberColorStr != ''">
            AND car_number_color = #{carNumberColorStr}
        </if>
        <if test="endTime != null">
            AND park_out_time &lt;= #{endTime}
        </if>
        <if test="orgId != null">
            AND org_id = #{orgId}
        </if>

        <if test="type == 0">
            group by	pl_no
        </if>
        <if test="type == 1">
            group by car_number , car_number_color
        </if>
        <if test="type == 3">
            group by id
        </if>
        <if test="dateFlag != null">
            <if test="dateFlag == 1">

            </if>
            <if test="dateFlag == 0">
                ,DATE_FORMAT(park_out_time,'%Y-%m-01')
            </if>
        </if>
        <if test="minArrearageFee != null or maxArrearageFee != null or  minArrearageNum != null   or maxArrearageNum != null  "  >
            HAVING 1=1
            <if test="minArrearageFee != null">
                and arrearageFee >= #{minArrearageFee}
            </if>
            <if test="maxArrearageFee != null">
                and arrearageFee &lt;= #{maxArrearageFee}
            </if>

            <if test="minArrearageNum != null">
                and count(*) >= #{minArrearageNum}
            </if>
            <if test="maxArrearageNum != null">
                and count(*) &lt;= #{maxArrearageNum}
            </if>

        </if>
        <choose>
            <when test="baseRequest != null and baseRequest.sortName != null and baseRequest.sortOrder != null
	        	and baseRequest.sortName != '' and baseRequest.sortOrder != ''">
                ORDER BY ${baseRequest.sortName} ${baseRequest.sortOrder}
            </when>
            <otherwise>
                ORDER BY staticDate ASC
            </otherwise>
        </choose>
    </select>



    <select id="pageQueryArrearRecordByConditionNew" resultMap="BaseResultMap"
            parameterType="com.zteits.clouds.api.dto.order.arrearageorder.param.ArrearOrderPageQueryByContidionReq">

        SELECT
        <include refid="Base_Column_List"/>
        FROM order_arrearage
        <where>
            data_state = 1
            <if test="vipCarList != null and vipCarList.size != 0 ">
                AND car_number in
                <foreach collection="vipCarList" separator="," item="plateNumber" open="(" close=")">
                    #{plateNumber}
                </foreach>
            </if>

            <if test="orderId != null">
                AND order_id = #{orderId}
            </if>

            <if test="orderBigType != null">
                AND order_big_type = #{orderBigType}
            </if>
            <if test="orderState != null">
                AND order_state = #{orderState}
            </if>
            <if test="sourceType != null">
                AND source_type = #{sourceType}
            </if>
            <if test="plNos != null and plNos.size != 0 ">
                AND pl_no in
                <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                    #{plNo}
                </foreach>
            </if>
            <if test="chargeCode != null">
                AND (park_in_source_code LIKE CONCAT(#{chargeCode},'%' ) OR park_out_source_code LIKE
                CONCAT(#{chargeCode},'%' )
            </if>
            <if test="carNum != null">
                AND car_number LIKE CONCAT(#{carNum,jdbcType=VARCHAR},'%' )
            </if>
            <if test="carNumber != null">
                AND car_number = #{carNumber,jdbcType=VARCHAR}
            </if>
            <if test="carNumbers != null and carNumbers.size >0 ">
                AND car_number IN
                <foreach collection="carNumbers" item="carN" index="index" open="(" close=")" separator=",">
                    #{carN}
                </foreach>
            </if>
            <if test="carNumberColorStr != null">
                AND car_number_color = #{carNumberColorStr}
            </if>
            <if test="allMatchCarNum != null">
                AND car_number = #{allMatchCarNum}
            </if>
            <if test="inTimeStart != null">
                AND park_in_time &gt;= #{inTimeStart}
            </if>
            <if test="inTimeEnd != null">
                AND park_in_time &lt;= #{inTimeEnd}
            </if>
            <if test="outTimeStart != null">
                AND park_out_time &gt;= #{outTimeStart}
            </if>
            <if test="outTimeEnd != null">
                AND park_out_time &lt;= #{outTimeEnd}
            </if>
            <if test="custId != null and custId !=''">
                AND cust_id = #{custId}
            </if>
            <if test="orgId != null">
                AND org_id = #{orgId}
            </if>
            <if test="orderStates != null and orderStates.size >0 ">
                AND order_state IN
                <foreach collection="orderStates" item="orderState" index="index" open="(" close=")" separator=",">
                    #{orderState}
                </foreach>
            </if>
        </where>
        order by create_date desc

    </select>
    <select id="queryArrearageSumFeeByCarNumber" resultType="java.lang.Long">
        SELECT
                IFNULL(sum(a.arrearage_fee),0)
            FROM
                order_arrearage a
            where   a.data_state=1
                AND car_number = #{carNumber}
                AND car_number_color = #{carNumberColor}
                and a.order_state=52
                and a.org_id=#{orgId}

    </select>
    <select id="queryArrearTotalByConditionWithVipCard"
            resultType="com.zteits.clouds.api.dto.order.arrearageorder.dto.ArrearageTotalDTO">

        SELECT
        IFNULL(SUM(arrearage_fee), 0) arrearageFee,
        IFNULL(COUNT(DISTINCT car_number), 0) carNum,
        IFNULL(COUNT(id), 0) arrearageNum
        FROM
        `order_arrearage`
        WHERE
        data_state = 1
        AND order_state in(10,20,30,52,-10)
        <if test="plNos != null and plNos.size != 0 ">
            AND pl_no in
            <foreach collection="plNos" separator="," item="plNo" open="(" close=")">
                #{plNo}
            </foreach>
        </if>
        <if test="carNumber != null and carNumber != ''">
            AND car_number LIKE CONCAT(#{carNumber,jdbcType=VARCHAR},'%' )
        </if>
        <if test="vipCarList != null and vipCarList.size != 0 ">
            AND car_number in
            <foreach collection="vipCarList" separator="," item="plateNumber" open="(" close=")">
                #{plateNumber}
            </foreach>
        </if>
        <if test="carNumberColorStr != null and carNumberColorStr != ''">
            AND car_number_color = #{carNumberColorStr}
        </if>
        <if test="beginTime != null">
            AND park_out_time &gt;= #{beginTime}
        </if>
        <if test="endTime != null">
            AND park_out_time &lt;= #{endTime}
        </if>
        <if test="orgId != null">
            AND org_id = #{orgId}
        </if>
        <if test="minArrearageFee != null or maxArrearageFee != null or  minArrearageNum != null   or maxArrearageNum != null  "  >
            HAVING 1=1
            <if test="minArrearageFee != null">
                and arrearageFee >= #{minArrearageFee}
            </if>
            <if test="maxArrearageFee != null">
                and arrearageFee &lt;= #{maxArrearageFee}
            </if>

            <if test="minArrearageNum != null">
                and count(*) >= #{minArrearageNum}
            </if>
            <if test="maxArrearageNum != null">
                and count(*) &lt;= #{maxArrearageNum}
            </if>

        </if>

    </select>

</mapper>