TdBParkDurationRepSmapper.xml 34.7 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
<?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.TdBParkDurationRepSmapper">
    <resultMap id="BaseResultMap" type="com.zteits.order.domain.TdBParkDurationRep">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="order_type" jdbcType="INTEGER" property="orderType"/>
        <result column="park_id" jdbcType="VARCHAR" property="parkId"/>
        <result column="park_name" jdbcType="VARCHAR" property="parkName"/>
        <result column="park_in_time" jdbcType="TIMESTAMP" property="parkInTime"/>
        <result column="park_out_time" jdbcType="TIMESTAMP" property="parkOutTime"/>
        <result column="park_out_source_code" jdbcType="VARCHAR" property="parkOutSourceCode"/>
        <result column="parking_duration" jdbcType="BIGINT" property="parkingDuration"/>
        <result column="park_type" jdbcType="INTEGER" property="parkType"/>
        <result column="data_state" jdbcType="INTEGER" property="dataState"/>
        <result column="rep_time" jdbcType="TIMESTAMP" property="repTime"/>
        <result column="create_empid" jdbcType="VARCHAR" property="createEmpid"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="modfiy_empid" jdbcType="VARCHAR" property="modfiyEmpid"/>
        <result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="pl_type" jdbcType="INTEGER" property="plType"/>

    </resultMap>
    <sql id="Base_Column_List">
    id, order_id, order_type, park_id, park_name, park_in_time, park_out_time, park_out_source_code,
    parking_duration, park_type, data_state, rep_time, create_empid, create_date, modfiy_empid,
    modfiy_date, remark
  </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from td_b_park_duration_rep
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteParkDurationRepByrepTime" parameterType="java.util.Date">
    delete from td_b_park_duration_rep
    where rep_time = #{repTime,jdbcType=TIMESTAMP}
  </delete>
    <!--批量插入停车时长信息-->
    <insert id="batchInsertParkDurationRep" parameterType="java.util.List">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into td_b_park_duration_rep (order_id, park_id, park_name,
        park_in_time, park_out_time, park_out_source_code,
        parking_duration, park_type, data_state,
        rep_time,create_date,order_type,pl_type
        )
        values
        <foreach collection="list" item="bill" separator=",">
            (#{bill.orderId,jdbcType=VARCHAR}, #{bill.parkId,jdbcType=VARCHAR}, #{bill.parkName,jdbcType=VARCHAR},
            #{bill.parkInTime,jdbcType=TIMESTAMP}, #{bill.parkOutTime,jdbcType=TIMESTAMP},
            #{bill.parkOutSourceCode,jdbcType=VARCHAR},
            #{bill.parkingDuration,jdbcType=BIGINT}, #{bill.parkType,jdbcType=INTEGER},1,
            #{bill.repTime,jdbcType=TIMESTAMP},#{bill.createDate,jdbcType=TIMESTAMP},
            #{bill.orderType,jdbcType=INTEGER},
            #{bill.plType,jdbcType=INTEGER}
            )
        </foreach>

    </insert>

    <!--企业云平台-停车时长折线图-按日(一天)-->
    <select id="queryEchartsForParkDurationForOneDay"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultType="com.zteits.order.domain.TdBParkDurationRep">
        select
        a.park_id as parkId,
        a.park_name as parkName,
        date_format(a.park_out_time,'%Y-%m-%d %H:00:00') as parkOutTime,
        avg(case when a.parking_duration is null then
        0
        else
        a.parking_duration
        end) as parkingDuration
        from td_b_park_duration_rep a
        where a.data_state=1
        <if test="parkIds != null and parkIds.size >0">
            and a.park_id in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[and a.park_out_time >=#{parkOutBeginTime}]]>
        <![CDATA[and a.park_out_time <= #{parkOutEndTime}]]>
        group by a.park_id,
        a.park_name,
        date_format(a.park_out_time,'%Y-%m-%d %H:00:00')
    </select>

    <!--企业云平台-停车时长折线图-按日(多天)-->
    <select id="queryEchartsForParkDurationForDay"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultMap="BaseResultMap">
        select
        a.park_id,
        a.park_name,
        date_format(a.park_out_time,'%Y-%m-%d') as park_out_time,
        avg(case when a.parking_duration is null then
        0
        else
        a.parking_duration
        end) as parking_duration
        from td_b_park_duration_rep a
        where a.data_state=1
        <if test="parkIds != null and parkIds.size >0">
            and a.park_id in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[and a.park_out_time >=#{parkOutBeginTime}]]>
        <![CDATA[and a.park_out_time <= #{parkOutEndTime}]]>
        group by a.park_id,
        a.park_name,
        date_format(a.park_out_time,'%Y-%m-%d')
        ORDER BY park_out_time DESC
    </select>
    <!--企业云平台停车时长折线图按日详情-->
    <select id="queryEchartsForParkDurationDayDetail"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultType="com.zteits.order.domain.sdo.ParkDurationForHourDO">
        select a.park_id as parkId,
        a.park_name as parkName,
        DATE_FORMAT(a.park_out_time,'%Y-%m-%d') as parkOutTime,
        a.park_type as parkType,
        count(case when a.parking_duration/3600 &lt;=1 THEN
        a.park_type
        end) as h1,
        count(case when a.parking_duration/3600 &gt;1 and a.parking_duration/3600 &lt;=2 THEN
        a.park_type
        end) as h2,
        count(case when a.parking_duration/3600 &gt;2 and a.parking_duration/3600 &lt;=3 THEN
        a.park_type
        end) as h3,
        count(case when a.parking_duration/3600 &gt;3 and a.parking_duration/3600 &lt;=4 THEN
        a.park_type
        end) as h4,
        count(case when a.parking_duration/3600 &gt;4 and a.parking_duration/3600 &lt;=5 THEN
        a.park_type
        end) as h5,
        count(case when a.parking_duration/3600 &gt;5 and a.parking_duration/3600 &lt;=6 THEN
        a.park_type
        end) h6,
        count(case when a.parking_duration/3600 &gt;6 and a.parking_duration/3600 &lt;=7 THEN
        a.park_type
        end) as h7,
        count(case when a.parking_duration/3600 &gt;7 and a.parking_duration/3600 &lt;=8 THEN
        a.park_type
        end) as h8,
        count(case when a.parking_duration/3600 &gt;8 and a.parking_duration/3600 &lt;=9 THEN
        a.park_type
        end) as h9,
        count(case when a.parking_duration/3600 &gt;9 and a.parking_duration/3600 &lt;=10 THEN
        a.park_type
        end) as h10,
        count(case when a.parking_duration/3600 &gt;10 and a.parking_duration/3600 &lt;=11 THEN
        a.park_type
        end) as h11,
        count(case when a.parking_duration/3600 &gt;11 and a.parking_duration/3600 &lt;=12 THEN
        a.park_type
        end) as h12,
        count(case when a.parking_duration/3600 &gt;12 and a.parking_duration/3600 &lt;=13 THEN
        a.park_type
        end) as h13,
        count(case when a.parking_duration/3600 &gt;13 and a.parking_duration/3600 &lt;=14 THEN
        a.park_type
        end) as h14,
        count(case when a.parking_duration/3600 &gt;14 and a.parking_duration/3600 &lt;=15 THEN
        a.park_type
        end) as h15,
        count(case when a.parking_duration/3600 &gt;15 and a.parking_duration/3600 &lt;=16 THEN
        a.park_type
        end) as h16,
        count(case when a.parking_duration/3600 &gt;16 and a.parking_duration/3600 &lt;=17 THEN
        a.park_type
        end) as h17,
        count(case when a.parking_duration/3600 &gt;17 and a.parking_duration/3600 &lt;=18 THEN
        a.park_type
        end) as h18,
        count(case when a.parking_duration/3600 &gt;18 and a.parking_duration/3600 &lt;=19 THEN
        a.park_type
        end) as h19,
        count(case when a.parking_duration/3600 &gt;19 and a.parking_duration/3600 &lt;=20 THEN
        a.park_type
        end) as h20,
        count(case when a.parking_duration/3600 &gt;20 and a.parking_duration/3600 &lt;=21 THEN
        a.park_type
        end) as h21,
        count(case when a.parking_duration/3600 &gt;21 and a.parking_duration/3600 &lt;=22 THEN
        a.park_type
        end) as h22,
        count(case when a.parking_duration/3600 &gt;22 and a.parking_duration/3600 &lt;23 THEN
        a.park_type
        end) as h23,
        count(case when a.parking_duration/3600 &gt;=23 THEN
        a.park_type
        end) as h24,
        avg(a.parking_duration) as duration

        from td_b_park_duration_rep a
        where 1=1
        <if test="parkIds != null and parkIds.size >0">
            and a.park_id in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[and a.park_out_time >=#{parkOutBeginTime}]]>
        <![CDATA[and a.park_out_time <= #{parkOutEndTime}]]>
        group by a.park_id,
        a.park_name,
        a.park_type,
        DATE_FORMAT(a.park_out_time,'%Y-%m-%d')
        union ALL
        select b.park_id as parkId,
        b.park_name as parkName,
        b.parkOutTime,
        '99' as parkType,
        sum(b.h1) as h1,
        sum(b.h2) as h2,
        sum(b.h3) as h3,
        sum(b.h4) as h4,
        sum(b.h5) as h5,
        sum(b.h6) as h6,
        sum(b.h7) as h7,
        sum(b.h8) as h8,
        sum(b.h9) as h9,
        sum(b.h10) as h10,
        sum(b.h11) as h11,
        sum(b.h12) as h12,
        sum(b.h13) as h13,
        sum(b.h14) as h14,
        sum(b.h15) as h15,
        sum(b.h16) as h16,
        sum(b.h17) as h17,
        sum(b.h18) as h18,
        sum(b.h19) as h19,
        sum(b.h20) as h20,
        sum(b.h21) as h21,
        sum(b.h22) as h22,
        sum(b.h23) as h23,
        sum(b.h24) as h24,
        sum(b.duration) as duration
        from (
        select a.park_id,
        a.park_name,
        a.park_type,
        DATE_FORMAT(a.park_out_time,'%Y-%m-%d') as parkOutTime,
        count(case when a.parking_duration/3600 &lt;=1 THEN
        a.park_type
        end) as h1,
        count(case when a.parking_duration/3600 &gt;1 and a.parking_duration/3600 &lt;=2 THEN
        a.park_type
        end) as h2,
        count(case when a.parking_duration/3600 &gt;2 and a.parking_duration/3600 &lt;=3 THEN
        a.park_type
        end) as h3,
        count(case when a.parking_duration/3600 &gt;3 and a.parking_duration/3600 &lt;=4 THEN
        a.park_type
        end) as h4,
        count(case when a.parking_duration/3600 &gt;4 and a.parking_duration/3600 &lt;=5 THEN
        a.park_type
        end) as h5,
        count(case when a.parking_duration/3600 &gt;5 and a.parking_duration/3600 &lt;=6 THEN
        a.park_type
        end) h6,
        count(case when a.parking_duration/3600 &gt;6 and a.parking_duration/3600 &lt;=7 THEN
        a.park_type
        end) as h7,
        count(case when a.parking_duration/3600 &gt;7 and a.parking_duration/3600 &lt;=8 THEN
        a.park_type
        end) as h8,
        count(case when a.parking_duration/3600 &gt;8 and a.parking_duration/3600 &lt;=9 THEN
        a.park_type
        end) as h9,
        count(case when a.parking_duration/3600 &gt;9 and a.parking_duration/3600 &lt;=10 THEN
        a.park_type
        end) as h10,
        count(case when a.parking_duration/3600 &gt;10 and a.parking_duration/3600 &lt;=11 THEN
        a.park_type
        end) as h11,
        count(case when a.parking_duration/3600 &gt;11 and a.parking_duration/3600 &lt;=12 THEN
        a.park_type
        end) as h12,
        count(case when a.parking_duration/3600 &gt;12 and a.parking_duration/3600 &lt;=13 THEN
        a.park_type
        end) as h13,
        count(case when a.parking_duration/3600 &gt;13 and a.parking_duration/3600 &lt;=14 THEN
        a.park_type
        end) as h14,
        count(case when a.parking_duration/3600 &gt;14 and a.parking_duration/3600 &lt;=15 THEN
        a.park_type
        end) as h15,
        count(case when a.parking_duration/3600 &gt;15 and a.parking_duration/3600 &lt;=16 THEN
        a.park_type
        end) as h16,
        count(case when a.parking_duration/3600 &gt;16 and a.parking_duration/3600 &lt;=17 THEN
        a.park_type
        end) as h17,
        count(case when a.parking_duration/3600 &gt;17 and a.parking_duration/3600 &lt;=18 THEN
        a.park_type
        end) as h18,
        count(case when a.parking_duration/3600 &gt;18 and a.parking_duration/3600 &lt;=19 THEN
        a.park_type
        end) as h19,
        count(case when a.parking_duration/3600 &gt;19 and a.parking_duration/3600 &lt;=20 THEN
        a.park_type
        end) as h20,
        count(case when a.parking_duration/3600 &gt;20 and a.parking_duration/3600 &lt;=21 THEN
        a.park_type
        end) as h21,
        count(case when a.parking_duration/3600 &gt;21 and a.parking_duration/3600 &lt;=22 THEN
        a.park_type
        end) as h22,
        count(case when a.parking_duration/3600 &gt;22 and a.parking_duration/3600 &lt;23 THEN
        a.park_type
        end) as h23,
        count(case when a.parking_duration/3600 &gt;=23 THEN
        a.park_type
        end) as h24,
        avg(a.parking_duration) as duration

        from td_b_park_duration_rep a
        where 1=1
        <if test="parkIds != null and parkIds.size >0">
            and a.park_id in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[and a.park_out_time >=#{parkOutBeginTime}]]>
        <![CDATA[and a.park_out_time <= #{parkOutEndTime}]]>
        group by a.park_id,
        a.park_name,
        DATE_FORMAT(a.park_out_time,'%Y-%m-%d'),
        a.park_type) b
        group by b.park_id,
        b.park_name,
        b.parkOutTime
    </select>


    <!--企业云平台-停车时长折线图-按月-->
    <select id="queryEchartsForParkDurationForMonth"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultMap="BaseResultMap">
        select
        a.park_id,
        a.park_name,
        date_format(a.park_out_time,'%Y-%m-01') as park_out_time,
        avg(case when a.parking_duration is null then
        0
        else
        a.parking_duration
        end) as parking_duration
        from td_b_park_duration_rep a
        where a.data_state=1
        <if test="parkIds != null and parkIds.size >0">
            and a.park_id in
            <foreach collection="parkIds" open="(" close=")" item="parkId" separator=",">
                #{parkId}
            </foreach>
        </if>
        <![CDATA[and DATE_FORMAT(a.park_out_time,'%Y-%m') >=DATE_FORMAT(#{parkOutBeginTime},'%Y-%m')]]>
        <![CDATA[and DATE_FORMAT(a.park_out_time,'%Y-%m') <= DATE_FORMAT(#{parkOutEndTime},'%Y-%m')]]>
        group by a.park_id,
        a.park_name,
        date_format(a.park_out_time,'%Y-%m-01')
        ORDER BY park_out_time DESC
    </select>

    <!-- 更新停车时长停车场类型 -->
    <update id="updatePLType">
        update td_b_park_duration_rep pdr, parking_lot pl
            set pdr.pl_type = pl.pl_type
        where pl.pl_no = pdr.park_id and (pdr.pl_type is null or pdr.pl_type = '') and pdr.id &gt; -1;
    </update>

    <!-- 根据查询停车场类型和时间段,统计不同统计条件下的停车次数 -->
    <select id="parkDurationDistribution"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationDistributionRequest"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDistributionDTO">
        select
        insideCount05m,
        roadCount05m,
        insideCount530m,
        roadCount530m,
        insideCount301mh,
        roadCount301mh,
        insideCount16h,
        roadCount16h,
        insideCount612h,
        roadCount612h,
        insideCount1224h,
        roadCount1224h,
        insideCountLongerThanOneDay,
        roadCountLongerThanOneDay
        from
        (select count(1) insideCount05m from td_b_park_duration_rep
        where pl_type=2 and (parking_duration &gt; 0 and parking_duration &lt;= 300)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCount05m,
        (select count(1) roadCount05m from td_b_park_duration_rep
        where pl_type=1 and (parking_duration &gt; 0 and parking_duration &lt;=300)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCount05m,
        (select count(1) insideCount530m from td_b_park_duration_rep
        where pl_type=2 and (parking_duration &gt; 300 and parking_duration&lt;=1800)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCount530m,
        (select count(1) roadCount530m from td_b_park_duration_rep
        where pl_type=1 and (parking_duration &gt; 300 and parking_duration &lt;=1800)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCount530m,
        (select count(1) insideCount301mh from td_b_park_duration_rep
        where pl_type=2 and (parking_duration &gt; 1800 and parking_duration &lt;= 3600)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCount301mh,
        (select count(1) roadCount301mh from td_b_park_duration_rep
        where pl_type=1 and (parking_duration &gt; 1800 and parking_duration &lt;= 3600)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCount301mh,
        (select count(1) insideCount16h from td_b_park_duration_rep
        where pl_type=2 and (parking_duration &gt; 3600 and parking_duration &lt;= 21600)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCount36h,
        (select count(1) roadCount16h from td_b_park_duration_rep
        where pl_type=1 and (parking_duration &gt; 3600 and parking_duration &lt;= 21600)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCount36h,
        (select count(1) insideCount612h from td_b_park_duration_rep
        where pl_type=2 and (parking_duration &gt; 21600 and parking_duration &lt;= 43200)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCount612h,
        (select count(1) roadCount612h from td_b_park_duration_rep
        where pl_type=1 and (parking_duration &gt; 21600 and parking_duration &lt;= 43200)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCount612h,
        (select count(1) insideCount1224h from td_b_park_duration_rep
        where pl_type=2 and (parking_duration &gt; 43200 and parking_duration &lt;= 86400)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCount1220h,
        (select count(1) roadCount1224h from td_b_park_duration_rep
        where pl_type=1 and (parking_duration &gt; 43200 and parking_duration &lt;= 86400)
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCount1220h,
        (select count(1) insideCountLongerThanOneDay from td_b_park_duration_rep
        where pl_type=2 and parking_duration &gt; 86400
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) insideCountLongerThanOneDay,
        (select count(1) roadCountLongerThanOneDay from td_b_park_duration_rep
        where pl_type=1 and parking_duration &gt; 86400
        and data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}) roadCountLongerThanOneDay
    </select>

    <!-- 停车时长分布详细记录,按日统计 300(5分钟),1800(30分钟),3600(1小时),21600(6小时),43200(12小时),86400(24小时)-->
    <select id="parkDurationDistributionDetailsByDay"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationDistributionRequest"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDistributionDetailDTO">
        SELECT
        count(case when parking_duration&gt;0 and parking_duration &lt;= 300 then pl_type end) count05m,
        count(case when parking_duration&gt;300 and parking_duration &lt;= 1800 then pl_type end) count530m,
        count(case when parking_duration&gt;1800 and parking_duration &lt;= 3600 then pl_type end) count301mh,
        count(case when parking_duration&gt;3600 and parking_duration &lt;= 21600 then pl_type end) count16h,
        count(case when parking_duration&gt;21600 and parking_duration &lt;= 43200 then pl_type end) count612h,
        count(case when parking_duration&gt;43200 and parking_duration &lt;= 86400 then pl_type end) count1224h,
        count(case when parking_duration&gt;86400 then pl_type end) countLongerThanOneDay,
        park_name parkName,
        Date_format(rep_time,"%Y-%m-%d") statisticTime,
        avg(parking_duration) avgTimeLong
        FROM td_b_park_duration_rep
        WHERE
        data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}
        group by park_id,park_name,Date_format(rep_time,"%Y-%m-%d"), pl_type
    </select>

    <!-- 停车时长分布详细记录,按月统计 300(5分钟),1800(30分钟),3600(1小时),21600(6小时),43200(12小时),86400(24小时)-->
    <select id="parkDurationDistributionDetailsByMonth"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationDistributionRequest"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDistributionDetailDTO">
        SELECT
        count(case when parking_duration&gt;0 and parking_duration &lt;= 300 then pl_type end) count05m,
        count(case when parking_duration&gt;300 and parking_duration &lt;= 1800 then pl_type end) count530m,
        count(case when parking_duration&gt;1800 and parking_duration &lt;= 3600 then pl_type end) count301mh,
        count(case when parking_duration&gt;3600 and parking_duration &lt;= 21600 then pl_type end) count16h,
        count(case when parking_duration&gt;21600 and parking_duration &lt;= 43200 then pl_type end) count612h,
        count(case when parking_duration&gt;43200 and parking_duration &lt;= 86400 then pl_type end) count1224h,
        count(case when parking_duration&gt;86400 then pl_type end) countLongerThanOneDay,
        park_name parkName,
        Date_format(rep_time, "%Y-%m") statisticTime,
        avg(parking_duration) avgTimeLong
        FROM td_b_park_duration_rep
        WHERE
        data_state=1
        <if test="plNos != null and plNos.size >0">
            and park_id in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        and park_out_time &gt;= #{beginTime} and park_out_time &lt;= #{endTime}
        group by park_id,park_name, Date_format(rep_time, "%Y-%m"), pl_type

    </select>


    <select id="queryParkDurationDataForChart"
            parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDataDTO">

        SELECT
        pl_type plType,
        sum(CASE WHEN t.parking_duration >= 0 AND t.parking_duration &lt; 15 * 60
        THEN 1
        ELSE 0 END) dataOf1,
        sum(CASE WHEN t.parking_duration >= 15 * 60 AND t.parking_duration &lt; 30 * 60
        THEN 1
        ELSE 0 END) dataOf2,
        sum(CASE WHEN t.parking_duration >= 30 * 60 AND t.parking_duration &lt; 60 * 60
        THEN 1
        ELSE 0 END) dataOf3,
        sum(CASE WHEN t.parking_duration >= 60 * 60 AND t.parking_duration &lt; 6 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf4,
        sum(CASE WHEN t.parking_duration >= 6 * 60 * 60 AND t.parking_duration &lt; 12 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf5,
        sum(CASE WHEN t.parking_duration >= 12 * 60 * 60 AND t.parking_duration &lt; 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf6,
        sum(CASE WHEN t.parking_duration >= 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf7

        FROM td_b_park_duration_rep t
        WHERE
        t.data_state = 1
        <![CDATA[AND t.rep_time >= #{parkOutBeginTime}]]>
        <![CDATA[AND t.rep_time <= #{parkOutEndTime}]]>
        AND t.park_id IN
        <foreach collection="parkIds" item="plNo" open="(" close=")" index="index" separator=",">
            #{plNo}
        </foreach>
        GROUP BY pl_type
    </select>

    <select id="queryParkDurationDataSummary"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDataDTO">
        SELECT
        avg(ifnull(t.parking_duration,0)) avgParkDuration,
        sum(CASE WHEN t.parking_duration >= 0 AND t.parking_duration &lt; 15 * 60
        THEN 1
        ELSE 0 END) dataOf1,
        sum(CASE WHEN t.parking_duration >= 15 * 60 AND t.parking_duration &lt; 30 * 60
        THEN 1
        ELSE 0 END) dataOf2,
        sum(CASE WHEN t.parking_duration >= 30 * 60 AND t.parking_duration &lt; 60 * 60
        THEN 1
        ELSE 0 END) dataOf3,
        sum(CASE WHEN t.parking_duration >= 60 * 60 AND t.parking_duration &lt; 6 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf4,
        sum(CASE WHEN t.parking_duration >= 6 * 60 * 60 AND t.parking_duration &lt; 12 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf5,
        sum(CASE WHEN t.parking_duration >= 12 * 60 * 60 AND t.parking_duration &lt; 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf6,
        sum(CASE WHEN t.parking_duration >= 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf7

        FROM td_b_park_duration_rep t
        WHERE
        id in (
              select id from td_b_park_duration_rep t
         where
        t.data_state = 1
        AND t.rep_time >= #{startTime}
        AND t.rep_time &lt;= #{endTime}
        AND t.park_id IN
        <foreach collection="plNos" item="plNo" open="(" close=")" index="index" separator=",">
            #{plNo}
        </foreach>
        )
    </select>


    <!--
        ⚠️ 手改(非搬迁原样):本 select 原为 statementType="STATEMENT",已去掉该属性。
        原因:老栈 PageHelper 5.0.0 的 MySQL 方言把分页拼成 `LIMIT 3`(字面量),STATEMENT
        (MyBatis SimpleStatementHandler,不做参数绑定)照样能跑;新栈 PageHelper 6.1.1 改拼
        `LIMIT ?`(见 MySqlDialect.getPageSql),STATEMENT 下这个 `?` 永远不绑定 → MySQL
        `SQLSyntaxErrorException ... near '?'` → /page 只要 pageSize!=0 一律 500。
        本 select 通篇只用 `${}` 文本替换、没有 `#{}`,去掉 STATEMENT(回到默认 PREPARED)后
        SQL 文本与语义完全不变,只是 `LIMIT ?` 能被正常绑定。回归见 tools/api_smoke.py §2h。
        本文件另一处 STATEMENT(queryParkDurationDataForFBECharts)没有走 PageHelper.startPage,
        不受影响,保持原样;其余 select(如 queryParkDurationDataSummary)本来就不是 STATEMENT。
    -->
    <select id="queryParkDurationDataForPage" parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDataDTO">
        SELECT
        <if test="queryKind == 1">
            DATE_FORMAT(t.rep_time, '%Y-%m-%d') staticTimeStr,
        </if>

        <if test="queryKind == 2">
            DATE_FORMAT(t.rep_time, '%Y-%m') staticTimeStr,
        </if>
        t.park_id plNo,
        max(t.park_name) plName,
        avg(ifnull(t.parking_duration,0)) avgParkDuration,
        sum(CASE WHEN t.parking_duration >= 0 AND t.parking_duration &lt; 15 * 60
        THEN 1
        ELSE 0 END) dataOf1,
        sum(CASE WHEN t.parking_duration >= 15 * 60 AND t.parking_duration &lt; 30 * 60
        THEN 1
        ELSE 0 END) dataOf2,
        sum(CASE WHEN t.parking_duration >= 30 * 60 AND t.parking_duration &lt; 60 * 60
        THEN 1
        ELSE 0 END) dataOf3,
        sum(CASE WHEN t.parking_duration >= 60 * 60 AND t.parking_duration &lt; 6 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf4,
        sum(CASE WHEN t.parking_duration >= 6 * 60 * 60 AND t.parking_duration &lt; 12 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf5,
        sum(CASE WHEN t.parking_duration >= 12 * 60 * 60 AND t.parking_duration &lt; 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf6,
        sum(CASE WHEN t.parking_duration >= 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf7

        FROM td_b_park_duration_rep t

        WHERE
         id in (
              select id from td_b_park_duration_rep t
              where
        t.data_state = 1
        AND t.rep_time >= '${startTime}'
        AND t.rep_time &lt;= '${endTime}'
        AND t.park_id IN
        <foreach collection="plNos" item="plNo" open="(" close=")" index="index" separator=",">
            '${plNo}'
        </foreach>
        )
        GROUP BY staticTimeStr,t.park_id
        ORDER BY staticTimeStr DESC


    </select>

    <select id="queryParkDurationDataForFBECharts" parameterType="com.zteits.clouds.api.dto.clouds.param.ParkDurationRequest"
            resultType="com.zteits.clouds.api.dto.clouds.dto.ParkDurationDataDTO" statementType="STATEMENT">
        SELECT
        <if test="queryKind == 1">
            DATE_FORMAT(t.rep_time, '%Y-%m-%d') staticTimeStr,
        </if>

        <if test="queryKind == 2">
            DATE_FORMAT(t.rep_time, '%Y-%m') staticTimeStr,
        </if>

        avg(ifnull(t.parking_duration,0)) avgParkDuration,
        sum(CASE WHEN t.parking_duration >= 0 AND t.parking_duration &lt; 15 * 60
        THEN 1
        ELSE 0 END) dataOf1,
        sum(CASE WHEN t.parking_duration >= 15 * 60 AND t.parking_duration &lt; 30 * 60
        THEN 1
        ELSE 0 END) dataOf2,
        sum(CASE WHEN t.parking_duration >= 30 * 60 AND t.parking_duration &lt; 60 * 60
        THEN 1
        ELSE 0 END) dataOf3,
        sum(CASE WHEN t.parking_duration >= 60 * 60 AND t.parking_duration &lt; 6 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf4,
        sum(CASE WHEN t.parking_duration >= 6 * 60 * 60 AND t.parking_duration &lt; 12 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf5,
        sum(CASE WHEN t.parking_duration >= 12 * 60 * 60 AND t.parking_duration &lt; 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf6,
        sum(CASE WHEN t.parking_duration >= 24 * 60 * 60
        THEN 1
        ELSE 0 END) dataOf7

        FROM td_b_park_duration_rep t
        WHERE
        t.data_state = 1
        AND t.rep_time >= '${startTime}'
        AND t.rep_time &lt;= '${endTime}'
        AND t.park_id IN
        <foreach collection="plNos" item="plNo" open="(" close=")" index="index" separator=",">
            '${plNo}'
        </foreach>
        GROUP BY staticTimeStr
        ORDER BY staticTimeStr DESC


    </select>

</mapper>