ParkingLotUseStatisticSMapper.xml 31.1 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
<?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.park.mapper.smapper.ParkingLotUseStatisticSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.park.domain.ParkingLotUseStatistic">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="pl_no" jdbcType="VARCHAR" property="plNo"/>
        <result column="free_ratio" jdbcType="DOUBLE" property="freeRatio"/>
        <result column="statistic_type" jdbcType="INTEGER" property="statisticType"/>
        <result column="turnover_ratio" jdbcType="DOUBLE" property="turnoverRatio"/>
        <result column="tmp_vehicle_flow" jdbcType="INTEGER" property="tmpVehicleFlow"/>
        <result column="vehicle_flow" jdbcType="INTEGER" property="vehicleFlow"/>
        <result column="fix_vehicle_flow" jdbcType="INTEGER" property="fixVehicleFlow"/>
        <result column="statistic_begin_time" jdbcType="TIMESTAMP" property="statisticBeginTime"/>
        <result column="statistic_end_time" jdbcType="TIMESTAMP" property="statisticEndTime"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="data_status" jdbcType="INTEGER" property="dataStatus"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, pl_no, free_ratio, statistic_type, turnover_ratio, tmp_vehicle_flow, vehicle_flow,
        fix_vehicle_flow, statistic_begin_time, statistic_end_time, create_time, data_status
    </sql>

    <!-- 查询停车场数据统计总车流量 -->
    <select id="QueryVehicleFlowStatisticMaxAndMin" resultType="com.zteits.park.domain.ParkingLotUseStatisticMaxAndMin">
        select max(vehicle_flow) maxVehicleFlow,max(tmp_vehicle_flow) maxTmpVehicleFlow,max(fix_vehicle_flow)
        maxFixVehicleFlow,
        min(vehicle_flow) minVehicleFlow,min(tmp_vehicle_flow) minTmpVehicleFlow,min(fix_vehicle_flow) minFixVehicleFlow
        from parking_lot_use_statistic
        where data_status =1
        <if test="beginTime != null and endTime !=null">
            and statistic_begin_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="statisticType != null">
            and statistic_type = #{statisticType,jdbcType=INTEGER}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
    </select>

    <!-- 查询停车场数据统计周转率和空置率 -->
    <select id="QueryBerthUseStatisticMaxAndMin" resultType="com.zteits.park.domain.ParkingLotUseStatisticMaxAndMin">
        select max(free_ratio) maxFreeRatio,max(turnover_ratio) maxTurnoverRatio,
        min(free_ratio) minFreeRatio,min(turnover_ratio) minTurnoverRatio
        from parking_lot_use_statistic
        where data_status =1
        <if test="beginTime != null and endTime !=null">
            and statistic_begin_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="statisticType != null">
            and statistic_type = #{statisticType,jdbcType=INTEGER}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
    </select>

    <!-- 查询停车场数据统计总进出场数-->
    <select id="QueryInOutParkStatisticSum" resultType="com.zteits.park.domain.ParkingLotUseStatisticSum">
        select sum(tmp_vehicle_flow) inParkSum,sum(out_park_count) outParkSum
        from parking_lot_use_statistic
        where data_status =1
        <if test="beginTime != null and endTime !=null">
            and statistic_begin_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="statisticType != null">
            and statistic_type = #{statisticType,jdbcType=INTEGER}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
    </select>


    <insert id="batchSave" parameterType="java.util.List">

        insert into parking_lot_use_statistic (pl_no, free_ratio, statistic_type,
        turnover_ratio, tmp_vehicle_flow, vehicle_flow,
        fix_vehicle_flow, statistic_begin_time, statistic_end_time,
        create_time, data_status, out_park_count,
        total_free_berths, pl_name, total_berths
        )
        values
        <foreach collection="records" separator="," item="item" index="index">

            (
            #{item.plNo,jdbcType=VARCHAR}, #{item.freeRatio,jdbcType=DOUBLE}, #{item.statisticType,jdbcType=INTEGER},
            #{item.turnoverRatio,jdbcType=DOUBLE}, #{item.tmpVehicleFlow,jdbcType=INTEGER},
            #{item.vehicleFlow,jdbcType=INTEGER},
            #{item.fixVehicleFlow,jdbcType=INTEGER}, #{item.statisticBeginTime,jdbcType=TIMESTAMP},
            #{item.statisticEndTime,jdbcType=TIMESTAMP},
            #{item.createTime,jdbcType=TIMESTAMP}, #{item.dataStatus,jdbcType=INTEGER},
            #{item.outParkCount,jdbcType=INTEGER},
            #{item.totalFreeBerths,jdbcType=INTEGER}, #{item.plName,jdbcType=VARCHAR},
            #{item.totalBerths,jdbcType=INTEGER}
            )
        </foreach>
    </insert>


    <select id="queryTodayVehicleFlowOccupyRateAndTurnOver"
            resultType="com.zteits.clouds.api.dto.park.dto.TodayVehicleFlowOccupyRateAndTurnOverDTO">
        SELECT sum(tmp_vehicle_flow) inCount ,AVG(turnover_ratio) avgTurnoverRate,
        AVG((1-t.free_ratio)) avgOccupyRate,sum(out_park_count) outCount,
        hour(t.statistic_end_time) hour
        FROM parking_lot_use_statistic t
        WHERE t.statistic_type = #{statisticType} AND t.statistic_end_time &gt;= #{beginTime} AND
        t.statistic_end_time &lt;= #{endTime} AND t.pl_no IN
        <foreach collection="plNos" item="plNo" open="(" close=")" separator="," index="index">
            #{plNo}
        </foreach>
        GROUP BY t.statistic_end_time ORDER BY t.statistic_end_time ASC;
    </select>


    <!-- langlw 2017-8-25 Monthly parking volume, vacancy rate and turnover rate are examined
    		按月统计进出场车流量和占用率和周转率 -->
    <select id="queryMonthVehicleFlowAndVacancyRateAndTurnover"
            resultType="com.zteits.clouds.api.dto.park.dto.MonthVehicleFlowAndVacancyRateAndTurnoverDTO">
        SELECT DATE_FORMAT(statistic_end_time,'%Y-%m') as statisticTime,
        pl_name as plName,pl_no as plNo,
        sum(tmp_vehicle_flow) as sumInVehicleflow,
        sum(out_park_count) as sumOutVehicleflow,
        avg((1-free_ratio)) as avgOccupyRatio,
        avg(turnover_ratio) as avgTurnoverRatio
        from parking_lot_use_statistic
        where statistic_type=3
        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        group by statisticTime,plName,plNo
        ORDER BY statisticTime DESC
    </select>


    <!-- 查询24小时停车场占用率 -->
    <select id="queryTwentyFourHoursOccupyRate"
            parameterType="com.zteits.clouds.api.dto.govclouds.param.QueryParkingOccupyRequest"
            resultType="com.zteits.park.domain.ParkingOccupyDO">
        SELECT
        avg(total_free_berths) AS totalfreeBerths,
        avg(total_berths) AS totalBerths,
        1 - avg(free_ratio) AS occupyRate,
        pl_type AS plType,
        statistic_end_time AS statisticTime

        FROM
        parking_lot_use_statistic
        WHERE
        1 = 1
        <if test="statisticType != null">
            and statistic_type = #{statisticType}
        </if>
        <if test="dataStatus != null">
            and data_status = #{dataStatus}
        </if>
        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        group by pl_type,statistic_end_time
    </select>


    <select id="statistic20MinData">

        INSERT INTO parking_lot_use_statistic (

        turnover_ratio,
        free_ratio,
        pl_no,
        pl_name,
        tmp_vehicle_flow,
        fix_vehicle_flow,
        vehicle_flow,
        total_free_berths,
        statistic_type,
        statistic_begin_time,
        statistic_end_time,
        create_time,
        total_berths,
        data_status,
        out_park_count,
        pl_type
        )
        SELECT

        CASE WHEN IFNULL(inData.turnover_ratio, 0) = 0
        THEN IFNULL(ssInfo.ssTurnoverRatio, 0)
        ELSE inData.turnover_ratio / plInfo.pl_berth_num END turnover_ratio,
        IFNULL(plInfo.free_berth/plInfo.pl_berth_num,0) free_ratio,
        plInfo.pl_no pl_no,
        plInfo.pl_name pl_name,
        IFNULL(inData.tmp_vehicle_flow, 0) tmp_vehicle_flow,
        IFNULL(inData.fix_vehicle_flow, 0) fix_vehicle_flow,
        IFNULL(inData.vehicle_flow, 0) vehicle_flow,
        IFNULL(inData.total_free_berths, 0) total_free_berths,
        1 statistic_type,
        #{startDate} statistic_begin_time,
        #{endDate} statistic_end_time,
        now() create_time,
        plInfo.pl_berth_num total_berths,
        1 data_status,
        IFNULL(outData.out_park_count,0) out_park_count,
        plInfo.pl_type pl_type
        FROM (
        SELECT DISTINCT
        a.data_status,
        a.state,
        a.pl_no pl_no,
        a.pl_name pl_name,
        CASE WHEN a.pl_berth_num=0
        THEN 1 ELSE IFNULL(a.pl_berth_num,1) END pl_berth_num,
        a.pl_type pl_type,
        b.free_berth free_berth
        FROM parking_lot a LEFT JOIN park_free_berth b ON a.pl_no = b.pl_no WHERE 1=1
        <if test="states != null and states.size >0">
            and a.state in
            <foreach collection="states" open="(" close=")" item="state"
                     separator=",">
                #{state}
            </foreach>
        </if>

        AND a.data_status = 1
        ) plInfo
        LEFT JOIN

        (
        SELECT
        pl_no inPlNo,
        count(1) turnover_ratio,
        -- 周转率
        avg(free_berths) free_ratio,
        -- 空置率
        count(1) tmp_vehicle_flow,
        -- 临时车流量(入场次数)停车次数
        0 fix_vehicle_flow,
        -- 固定车流量
        count(1) vehicle_flow,
        -- 总车流量
        sum(free_berths) total_free_berths


        FROM inpark_log
        WHERE in_time &gt;= #{startDate} AND in_time &lt;= #{endDate}
        GROUP BY pl_no
        ) inData ON plInfo.pl_no = inData.inPlNo
        LEFT JOIN
        (
        SELECT
        pl_no outPlNO,
        count(1) out_park_count

        FROM outpark_log
        WHERE out_time &gt;= #{startDate} AND out_time &lt;= #{endDate}
        GROUP BY pl_no
        ) outData ON plInfo.pl_no = outData.outPlNO
        LEFT JOIN
        (
        SELECT
        b.pl_no ssPlNO,
        b.free_ratio ssFreeRatio,
        b.turnover_ratio ssTurnoverRatio
        FROM parking_lot_use_statistic b,
        (SELECT
        a.pl_no,
        max(a.id) AS maxID
        FROM
        parking_lot_use_statistic a
        WHERE statistic_type = 1
        GROUP BY a.pl_no) c
        WHERE b.pl_no = c.pl_no AND b.id = c.maxID
        ) ssInfo ON plInfo.pl_no = ssInfo.ssPlNO


    </select>


    <select id="static1HourAnd1DayData">
        INSERT INTO parking_lot_use_statistic (
        turnover_ratio,
        free_ratio,
        pl_no,
        pl_name,
        tmp_vehicle_flow,
        fix_vehicle_flow,
        vehicle_flow,
        total_free_berths,
        statistic_type,
        statistic_begin_time,
        statistic_end_time,
        create_time,
        total_berths,
        data_status,
        out_park_count,
        pl_type
        )

        SELECT
        IFNULL(m.turnover_ratio,0)/CASE WHEN n.pl_berth_num=0 THEN 1 ELSE IFNULL(n.pl_berth_num,1) END turnover_ratio,
        m.free_ratio,
        m.pl_no,
        n.pl_name,
        m.tmp_vehicle_flow,
        m.fix_vehicle_flow,
        m.vehicle_flow,
        m.total_free_berths,
        m.statistic_type,
        m.statistic_begin_time,
        m.statistic_end_time,
        now(),
        n.pl_berth_num total_berths,
        m.data_status,
        m.out_park_count,
        n.pl_type
        FROM
        (
        SELECT
        sum(tmp_vehicle_flow)    turnover_ratio,
        avg(free_ratio)        free_ratio,
        pl_no,
        sum(tmp_vehicle_flow)  tmp_vehicle_flow,
        sum(fix_vehicle_flow)  fix_vehicle_flow,
        sum(vehicle_flow)      vehicle_flow,
        sum(total_free_berths) total_free_berths,
        #{type}                      statistic_type,
        #{startDate}  statistic_begin_time,
        #{endDate}  statistic_end_time,
        1                      data_status,
        sum(out_park_count)    out_park_count
        FROM parking_lot_use_statistic
        WHERE statistic_end_time &gt;=  #{startDate}
        AND statistic_end_time &lt;= #{endDate}
        AND statistic_type = 1
        GROUP BY pl_no) m, parking_lot n
        WHERE m.pl_no = n.pl_no;

    </select>


    <select id="queryCarFlowByMonthForPage"
            parameterType="com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest"
            resultType="com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticDTO">


        SELECT
        pl_no plNo,
        max(pl_name) plName,
        DATE_FORMAT(statistic_end_time, '%Y-%m') staticTimeStr,
        avg(free_ratio) freeRatio,
        avg(turnover_ratio) turnoverRatio,
        4 statisticType,
        sum(tmp_vehicle_flow) tmpVehicleFlow,
        sum(out_park_count) outParkCount,
        sum(vehicle_flow) vehicleFlow,
        sum(fix_vehicle_flow) fixVehicleFlow

        FROM parking_lot_use_statistic
        WHERE statistic_type = 3
        AND data_status = 1
        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        GROUP BY DATE_FORMAT(statistic_end_time, '%Y-%m'), pl_no, pl_name
        ORDER BY staticTimeStr DESC


    </select>


    <select id="queryCarFlowChartByDay"
            parameterType="com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest"
            resultType="com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticDTO">

        SELECT
        DATE_FORMAT(statistic_end_time, '%Y-%m-%d') staticTimeStr,
        avg(free_ratio) freeRatio,
        avg(turnover_ratio) turnoverRatio,
        3 statisticType,
        sum(tmp_vehicle_flow) tmpVehicleFlow,
        sum(out_park_count) outParkCount,
        sum(vehicle_flow) vehicleFlow,
        sum(fix_vehicle_flow) fixVehicleFlow

        FROM parking_lot_use_statistic
        WHERE statistic_type = 3
        AND data_status = 1
        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        GROUP BY DATE_FORMAT(statistic_end_time, '%Y-%m-%d')
        ORDER BY staticTimeStr



    </select>

    <select id="queryCarFlowChartByMonth"
            parameterType="com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest"
            resultType="com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticDTO">

        SELECT
        DATE_FORMAT(statistic_end_time, '%Y-%m') staticTimeStr,
        avg(free_ratio) freeRatio,
        avg(turnover_ratio) turnoverRatio,
        4 statisticType,
        sum(tmp_vehicle_flow) tmpVehicleFlow,
        sum(out_park_count) outParkCount,
        sum(vehicle_flow) vehicleFlow,
        sum(fix_vehicle_flow) fixVehicleFlow

        FROM parking_lot_use_statistic
        WHERE statistic_type = 3
        AND data_status = 1
        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        GROUP BY DATE_FORMAT(statistic_end_time, '%Y-%m')
        ORDER BY staticTimeStr



    </select>



    <!-- 查询周转率新的 langlw 2018-1-6-->
    <select id="queryTurnoverRatioNew" resultType="com.zteits.clouds.api.dto.clouds.dto.TurnoverRatioDTO"
            parameterType="com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest">
        SELECT

        <if test="timeType == 1">
            DATE_FORMAT(statistic_end_time,'%Y-%m-%d') as statisticTime,
        </if>
        <if test="timeType == 2">
            DATE_FORMAT(statistic_end_time,'%Y-%m') as statisticTime,
        </if>

        pl_name as plName,pl_no as plNo,
        pl_type as plType,
        max(turnover_ratio) as maxTurnoverRatio,
        min(turnover_ratio) as minTurnoverRatio,
        avg(turnover_ratio) as avgTurnoverRatio
        from parking_lot_use_statistic
        where data_status = 1
        <if test="timeType == 1">
            and statistic_type=2
        </if>
        <if test="timeType == 2">
            and statistic_type=3
        </if>

        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        group by statisticTime,plName,plNo,plType
        ORDER BY statisticTime DESC

    </select>



    <!-- 查询周转率新的图表 langlw 2018-1-6-->
    <select id="queryTurnoverRatioNewForChart" resultType="com.zteits.clouds.api.dto.clouds.dto.TurnoverRatioDTO"
            parameterType="com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest">
        SELECT

        <if test="timeType == 1">
            DATE_FORMAT(statistic_end_time,'%Y-%m-%d') as statisticTime,
        </if>
        <if test="timeType == 2">
            DATE_FORMAT(statistic_end_time,'%Y-%m') as statisticTime,
        </if>
        pl_type as plType,
        max(turnover_ratio) as maxTurnoverRatio,
        min(turnover_ratio) as minTurnoverRatio,
        avg(turnover_ratio) as avgTurnoverRatio
        from parking_lot_use_statistic
        where data_status = 1
        <if test="timeType == 1">
            and statistic_type=2
        </if>
        <if test="timeType == 2">
            and statistic_type=3
        </if>

        <if test="beginTime != null and endTime !=null">
            and statistic_end_time between #{beginTime} and #{endTime}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        group by statisticTime,pl_type
        ORDER BY statisticTime DESC

    </select>


    <select id="statistic20MinDataForSelect" resultType="com.zteits.park.domain.ParkingLotUseStatistic">

        SELECT
        CASE WHEN IFNULL(inData.turnover_ratio, 0) = 0
        THEN IFNULL(ssInfo.ssTurnoverRatio, 0)
        ELSE inData.turnover_ratio / plInfo.pl_berth_num END turnoverRatio,
        IFNULL(plInfo.free_berth/plInfo.pl_berth_num,0) freeRatio,
        plInfo.pl_no plNo,
        plInfo.pl_name plName,
        IFNULL(inData.tmp_vehicle_flow, 0) tmpVehicleFlow,
        IFNULL(inData.fix_vehicle_flow, 0) fixVehicleFlow,
        IFNULL(inData.vehicle_flow, 0) vehicleFlow,
        IFNULL(inData.total_free_berths, 0) totalFreeBerths,
        1 statisticType,
        #{startDate} statisticBeginTime,
        #{endDate} statisticEndTime,
        now() createTime,
        plInfo.pl_berth_num totalBerths,
        1 dataStatus,
        IFNULL(outData.out_park_count,0) outParkCount,
        plInfo.pl_type plType
        FROM (
        SELECT DISTINCT
        a.data_status,
        a.state,
        a.pl_no pl_no,
        a.pl_name pl_name,
        CASE WHEN a.pl_berth_num=0
        THEN 1 ELSE IFNULL(a.pl_berth_num,1) END pl_berth_num,
        a.pl_type pl_type,
        b.free_berth free_berth
        FROM parking_lot a LEFT JOIN park_free_berth b ON a.pl_no = b.pl_no WHERE 1=1
        <if test="states != null and states.size >0">
            and a.state in
            <foreach collection="states" open="(" close=")" item="state"
                     separator=",">
                #{state}
            </foreach>
        </if>

        AND a.data_status = 1
        ) plInfo
        LEFT JOIN

        (
        SELECT
        pl_no inPlNo,
        count(1) turnover_ratio,
        -- 周转率
        avg(free_berths) free_ratio,
        -- 空置率
        count(1) tmp_vehicle_flow,
        -- 临时车流量(入场次数)停车次数
        0 fix_vehicle_flow,
        -- 固定车流量
        count(1) vehicle_flow,
        -- 总车流量
        sum(free_berths) total_free_berths


        FROM inpark_log
        WHERE in_time &gt;= #{startDate} AND in_time &lt;= #{endDate}
        GROUP BY pl_no
        ) inData ON plInfo.pl_no = inData.inPlNo
        LEFT JOIN
        (
        SELECT
        pl_no outPlNO,
        count(1) out_park_count

        FROM outpark_log
        WHERE out_time &gt;= #{startDate} AND out_time &lt;= #{endDate}
        GROUP BY pl_no
        ) outData ON plInfo.pl_no = outData.outPlNO
        LEFT JOIN
        (
        SELECT
        b.pl_no ssPlNO,
        b.free_ratio ssFreeRatio,
        b.turnover_ratio ssTurnoverRatio
        FROM parking_lot_use_statistic b,
        (SELECT
        a.pl_no,
        max(a.id) AS maxID
        FROM
        parking_lot_use_statistic a
        WHERE statistic_type = 1
        GROUP BY a.pl_no) c
        WHERE b.pl_no = c.pl_no AND b.id = c.maxID
        ) ssInfo ON plInfo.pl_no = ssInfo.ssPlNO


    </select>


    <!--路侧停车场 路侧停车场从地磁上报记录上取数据-->
    <select id="statistic20MinDataForSelectByLCPark" resultType="com.zteits.park.domain.ParkingLotUseStatistic" statementType="STATEMENT">

        SELECT
        CASE WHEN IFNULL(inoutInfo.turnover_ratio, 0) = 0
        THEN IFNULL(ssInfo.ssTurnoverRatio, 0)
        ELSE inoutInfo.turnover_ratio / plInfo.pl_berth_num END turnoverRatio,
        IFNULL(plInfo.free_berth / plInfo.pl_berth_num, 0)      freeRatio,
        plInfo.pl_no                                            plNo,
        plInfo.pl_name                                          plName,
        IFNULL(inoutInfo.tmp_vehicle_flow, 0)                   tmpVehicleFlow,
        IFNULL(inoutInfo.fix_vehicle_flow, 0)                   fixVehicleFlow,
        IFNULL(inoutInfo.vehicle_flow, 0)                       vehicleFlow,
        IFNULL(inoutInfo.free_ratio, 0)                         totalFreeBerths,
        1                                                       statisticType,
        now()                                                   createTime,
        plInfo.pl_berth_num                                     totalBerths,
        1                                                       dataStatus,
        '${startDate}' statisticBeginTime,
        '${endDate}' statisticEndTime,
        IFNULL(inoutInfo.out_park_count, 0)                     outParkCount,
        plInfo.pl_type                                          plType
        FROM (
        SELECT DISTINCT
        a.data_status,
        a.state,
        a.pl_no                            pl_no,
        a.pl_name                          pl_name,
        CASE WHEN a.pl_berth_num = 0
        THEN 1
        ELSE IFNULL(a.pl_berth_num, 1) END pl_berth_num,
        a.pl_type                          pl_type,
        b.free_berth                       free_berth
        FROM parking_lot a LEFT JOIN park_free_berth b ON a.pl_no = b.pl_no
        WHERE 1 = 1
        <if test="states != null and states.size >0">
            and a.state in
            <foreach collection="states" open="(" close=")" item="state"
                     separator=",">
                ${state}
            </foreach>
        </if>

        AND a.data_status = 1 AND a.pl_type = 1

        AND a.data_status = 1
        ) plInfo
        LEFT JOIN
        (
        SELECT
        eqpInfo.pl_no          plNo,
        inNum.tmp_vehicle_flow vehicle_flow,
        0                      fix_vehicle_flow,
        inNum.tmp_vehicle_flow turnover_ratio,
        eqpInfo.freeNum        free_ratio,
        inNum.tmp_vehicle_flow tmp_vehicle_flow,
        outNum.out_park_count
        FROM (
        SELECT
        m.pl_no,
        sum(CASE WHEN m.is_occupy = 2
        THEN 1
        ELSE 0 END) freeNum,
        sum(CASE WHEN m.is_occupy = 1
        THEN 1
        ELSE 0 END) occupy,
        count(0)        berthNum

        FROM tp_p_berths m, tp_p_eqp n
        WHERE m.berth_no = n.berth_no AND m.pl_no = n.pl_no
        GROUP BY m.pl_no) eqpInfo,
        (SELECT
        COUNT(*) tmp_vehicle_flow,
        pl_no
        FROM tp_p_eqp_inout_record${recordDateStr}
        WHERE eqp_in_time &gt;= '${startDate}'
        AND  eqp_in_time &lt;= '${endDate}'
        GROUP BY pl_no) inNum,

        (SELECT
        COUNT(*) out_park_count,
        pl_no
        FROM tp_p_eqp_inout_record${recordDateStr}
        WHERE eqp_out_time &lt;= '${endDate}'
        AND  eqp_out_time &gt;= '${startDate}'
        GROUP BY pl_no) outNum
        WHERE eqpInfo.pl_no = inNum.pl_no AND eqpInfo.pl_no = outNum.pl_no
        ) inoutInfo ON plInfo.pl_no = inoutInfo.plNO

        LEFT JOIN
        (
        SELECT
        b.pl_no          ssPlNO,
        b.free_ratio     ssFreeRatio,
        b.turnover_ratio ssTurnoverRatio
        FROM parking_lot_use_statistic b,
        (SELECT
        a.pl_no,
        max(a.id) AS maxID
        FROM
        parking_lot_use_statistic a
        WHERE statistic_type = 1
        GROUP BY a.pl_no) c
        WHERE b.pl_no = c.pl_no AND b.id = c.maxID
        ) ssInfo ON plInfo.pl_no = ssInfo.ssPlNO


    </select>



    <!--封闭停车场-->
    <select id="statistic20MinDataForSelectByFBPark" resultType="com.zteits.park.domain.ParkingLotUseStatistic">

        SELECT
        CASE WHEN IFNULL(inData.turnover_ratio, 0) = 0
        THEN IFNULL(ssInfo.ssTurnoverRatio, 0)
        ELSE inData.turnover_ratio / plInfo.pl_berth_num END turnoverRatio,
        IFNULL(plInfo.free_berth/plInfo.pl_berth_num,0) freeRatio,
        plInfo.pl_no plNo,
        plInfo.pl_name plName,
        IFNULL(inData.tmp_vehicle_flow, 0) tmpVehicleFlow,
        IFNULL(inData.fix_vehicle_flow, 0) fixVehicleFlow,
        IFNULL(inData.vehicle_flow, 0) vehicleFlow,
        IFNULL(inData.total_free_berths, 0) totalFreeBerths,
        1 statisticType,
        #{startDate} statisticBeginTime,
        #{endDate} statisticEndTime,
        now() createTime,
        plInfo.pl_berth_num totalBerths,
        1 dataStatus,
        IFNULL(outData.out_park_count,0) outParkCount,
        plInfo.pl_type plType
        FROM (
        SELECT DISTINCT
        a.data_status,
        a.state,
        a.pl_no pl_no,
        a.pl_name pl_name,
        CASE WHEN a.pl_berth_num=0
        THEN 1 ELSE IFNULL(a.pl_berth_num,1) END pl_berth_num,
        a.pl_type pl_type,
        b.free_berth free_berth
        FROM parking_lot a LEFT JOIN park_free_berth b ON a.pl_no = b.pl_no WHERE 1=1
        <if test="states != null and states.size >0">
            and a.state in
            <foreach collection="states" open="(" close=")" item="state"
                     separator=",">
                #{state}
            </foreach>
        </if>

        AND a.data_status = 1 AND a.pl_type = 2
        ) plInfo
        LEFT JOIN

        (
        SELECT
        pl_no inPlNo,
        count(1) turnover_ratio,
        -- 周转率
        avg(free_berths) free_ratio,
        -- 空置率
        count(1) tmp_vehicle_flow,
        -- 临时车流量(入场次数)停车次数
        0 fix_vehicle_flow,
        -- 固定车流量
        count(1) vehicle_flow,
        -- 总车流量
        sum(free_berths) total_free_berths


        FROM inpark_log
        WHERE in_time &gt;= #{startDate} AND in_time &lt;= #{endDate}
        GROUP BY pl_no
        ) inData ON plInfo.pl_no = inData.inPlNo
        LEFT JOIN
        (
        SELECT
        pl_no outPlNO,
        count(1) out_park_count

        FROM outpark_log
        WHERE out_time &gt;= #{startDate} AND out_time &lt;= #{endDate}
        GROUP BY pl_no
        ) outData ON plInfo.pl_no = outData.outPlNO
        LEFT JOIN
        (
        SELECT
        b.pl_no ssPlNO,
        b.free_ratio ssFreeRatio,
        b.turnover_ratio ssTurnoverRatio
        FROM parking_lot_use_statistic b,
        (SELECT
        a.pl_no,
        max(a.id) AS maxID
        FROM
        parking_lot_use_statistic a
        WHERE statistic_type = 1
        GROUP BY a.pl_no) c
        WHERE b.pl_no = c.pl_no AND b.id = c.maxID
        ) ssInfo ON plInfo.pl_no = ssInfo.ssPlNO


    </select>



    <select id="statistic20MinDataForInsert">

        INSERT INTO parking_lot_use_statistic (

        turnover_ratio,
        free_ratio,
        pl_no,
        pl_name,
        tmp_vehicle_flow,
        fix_vehicle_flow,
        vehicle_flow,
        total_free_berths,
        statistic_type,
        statistic_begin_time,
        statistic_end_time,
        create_time,
        total_berths,
        data_status,
        out_park_count,
        pl_type
        )
        values
        <foreach collection="parkingLotUseStatistics" item="item" index="index" separator="," >
            (#{item.turnoverRatio},#{item.freeRatio},#{item.plNo},#{item.plName},#{item.tmpVehicleFlow},
            #{item.fixVehicleFlow},#{item.vehicleFlow},#{item.totalFreeBerths},#{item.statisticType},#{item.statisticBeginTime},
            #{item.statisticEndTime},#{item.createTime},#{item.totalBerths},#{item.dataStatus},#{item.outParkCount},#{item.plType})
        </foreach>


    </select>

    <select id="query20MinNewDataGroupByPlNO" resultMap="BaseResultMap">
        SELECT m.*
            FROM parking_lot_use_statistic m, (SELECT
                                     pl_no,
                                     max(id) id
                                   FROM parking_lot_use_statistic
                                   GROUP BY pl_no) n
            WHERE m.id = n.id and m.pl_type = 2

    </select>
</mapper>