ParkInOutRecordSMapper.xml 15.3 KB
<?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.ParkInOutRecordSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.park.domain.ParkInOutRecord">
        <id column="order_id" jdbcType="VARCHAR" property="orderId" />
        <result column="record_id" jdbcType="VARCHAR" property="recordId" />
        <result column="park_order_type" jdbcType="INTEGER" property="parkOrderType" />
        <result column="park_detail_type" jdbcType="INTEGER" property="parkDetailType" />
        <result column="park_state" jdbcType="INTEGER" property="parkState" />
        <result column="order_state" jdbcType="INTEGER" property="orderState" />
        <result column="terminal_source" jdbcType="INTEGER" property="terminalSource" />
        <result column="source_type" jdbcType="INTEGER" property="sourceType" />
        <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
        <result column="order_dicount_fee" jdbcType="BIGINT" property="orderDicountFee" />
        <result column="order_act_fee" jdbcType="BIGINT" property="orderActFee" />
        <result column="order_total_fee" jdbcType="BIGINT" property="orderTotalFee" />
        <result column="top_org_id" jdbcType="BIGINT" property="topOrgId" />
        <result column="pl_name" jdbcType="VARCHAR" property="plName" />
        <result column="pl_type" jdbcType="INTEGER" property="plType" />
        <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="car_number" jdbcType="VARCHAR" property="carNumber" />
        <result column="car_type" jdbcType="INTEGER" property="carType" />
        <result column="car_number_color" jdbcType="VARCHAR" property="carNumberColor" />
        <result column="park_in_time" jdbcType="TIMESTAMP" property="parkInTime" />
        <result column="park_out_time" jdbcType="TIMESTAMP" property="parkOutTime" />
        <result column="parking_duration" jdbcType="BIGINT" property="parkingDuration" />
        <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="in_free_berths" jdbcType="INTEGER" property="inFreeBerths" />
        <result column="out_free_berths" jdbcType="INTEGER" property="outFreeBerths" />
        <result column="pl_berth_num" jdbcType="INTEGER" property="plBerthNum" />
        <result column="cust_type" jdbcType="INTEGER" property="custType" />
        <result column="cust_id" jdbcType="VARCHAR" property="custId" />
        <result column="data_state" jdbcType="INTEGER" property="dataState" />
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        order_id, record_id, park_order_type, park_detail_type, park_state, order_state,
    terminal_source, source_type, pl_no, order_dicount_fee, order_act_fee, order_total_fee,
    top_org_id, pl_name, pl_type, berth_range_no, berth_range_name, berth_no, car_number,
    car_type, car_number_color, park_in_time, park_out_time, parking_duration, park_in_source_code,
    park_in_source_name, park_out_source_code, park_out_source_name, in_free_berths,
    out_free_berths, pl_berth_num, cust_type, cust_id, data_state, create_date
    </sql>

    <select id="queryCarInOutNum" resultType="com.zteits.park.domain.ParkingRunningStatistic">
        SELECT
        inInfo.pl_no plNo,
        IFNULL(inInfo.park_in_count,0) parkInCount,
        IFNULL(inInfo.vip_in_count,0) vipInCount,
        IFNULL(outInfo.vip_out_count,0) vipOutCount,
        IFNULL(outInfo.park_out_count,0) parkOutCount,
        IFNULL(outInfo.parking_duration,0) allParkingDuration
        FROM (

        SELECT
        t.pl_no,
        sum(CASE park_order_type
        WHEN 300
        THEN 1
        WHEN 500
        THEN 1
        ELSE 0 END) vip_in_count,
        count(*) park_in_count

        FROM park_in_out_record t
        WHERE
        t.data_state = 1
        AND t.pl_no = #{plNo}
        AND t.park_in_time &gt; #{startTime}
        AND t.park_in_time &lt;= #{endTime}) inInfo,
        (
        SELECT
        t.pl_no,
        sum(CASE park_order_type
        WHEN 300
        THEN 1
        WHEN 500
        THEN 1
        ELSE 0 END) vip_out_count,
        count(*) park_out_count,
		sum(t.parking_duration) parking_duration
        FROM park_in_out_record t
        WHERE
        t.data_state = 1
        AND t.pl_no = #{plNo}
        AND t.park_state = 20
        AND t.park_out_time &gt; #{startTime}
        AND t.park_out_time &lt;= #{endTime}) outInfo
        WHERE inInfo.pl_no = outInfo.pl_no;
    </select>


    <select id="queryCarInInfo" resultType="com.zteits.park.domain.ParkingRunningStatistic">
        SELECT
            inInfo.pl_no AS plNo,
            IFNULL(inInfo.vip_in_count, 0) AS vipInCount,
            IFNULL(inInfo.park_in_count, 0) AS parkInCount
        FROM (
                 SELECT
                     t.pl_no,
                     SUM(CASE WHEN t.park_order_type IN (300, 500) THEN 1 ELSE 0 END) AS vip_in_count,
                     COUNT(*) AS park_in_count
                 FROM park_in_out_record t
                 WHERE
                     t.data_state = 1
                   AND t.pl_no = #{plNo}
                   AND t.park_in_time BETWEEN #{startTime} AND #{endTime}
                 GROUP BY t.pl_no
             ) inInfo

    </select>


    <select id="queryCarOutInfo" resultType="com.zteits.park.domain.ParkingRunningStatistic">
        SELECT outInfo.pl_no                       AS plNo,
        IFNULL(outInfo.vip_out_count, 0)    AS vipOutCount,
        IFNULL(outInfo.park_out_count, 0)   AS parkOutCount,
        IFNULL(outInfo.parking_duration, 0) AS allParkingDuration
        FROM (SELECT pl_no,
        SUM(CASE WHEN park_order_type IN (300, 500) THEN 1 ELSE 0 END) AS vip_out_count,
        COUNT(*)                                                       AS park_out_count,
        SUM(parking_duration)                                          AS parking_duration
        FROM park_in_out_record
        WHERE data_state = 1
        AND pl_no =          #{plNo}
        AND park_state = 20
        AND park_out_time BETWEEN #{startTime} AND #{endTime}
        GROUP BY pl_no) outInfo

    </select>


    <select id="queryFreeBerthsRencentTime" resultType="java.lang.Integer">
        SELECT tmp.freeBerth,
               tmp.parkTime
        FROM (
                 select *
                 from (
                          SELECT in_free_berths freeBerth,
                                 park_in_time   parkTime
                          FROM park_in_out_record
                          WHERE data_state = 1
                            AND park_in_time &lt;= #{endTime}
                            AND pl_no = #{plNo}
                          ORDER BY order_id DESC
                          LIMIT 1) a
                 UNION ALL
                 select *
                 from (
                          SELECT out_free_berths freeBerth,
                                 park_out_time   parkTime
                          FROM park_in_out_record
                          WHERE data_state = 1
                            AND park_out_time &lt;= #{endTime}
                            AND pl_no = #{plNo}
                          ORDER BY order_id DESC
                          LIMIT 1) b
             ) tmp
        ORDER BY tmp.parkTime DESC
        LIMIT 1
    </select>
	<!-- 违法车辆停车场记录 -->
	<select id="queryPageIllegalCarParkOrder" resultMap="BaseResultMap">
	    SELECT
			p.order_id,
			p.car_number,
			p.park_state,
			p.pl_no,
			p.pl_name,
			p.park_in_time,
			p.park_out_time,
			p.parking_duration
		FROM
			illegal_car_info i
			JOIN park_in_out_record p ON i.car_number = p.car_number
			where i.data_state=1 and p.data_state=1
	        <if test="carNumber!=null and carNumber!=''">
	            AND i.car_number like CONCAT("%",#{carNumber},"%")
	        </if>
	        <if test="parkState!=null and parkState!=''">
	            AND p.park_state = #{parkState}
	        </if>
	        <if test="beginInTime!=null">
	        	AND p.park_in_time between #{beginInTime} and #{endInTime}
	        </if>
	        <if test="beginOutTime!=null">
	        	AND p.park_out_time between #{beginOutTime} and #{endOutTime}
	        </if>
        ORDER BY p.park_in_time desc ,p.park_out_time desc
    </select>

    <select id="queryParkInsideCarNum" resultType="com.zteits.park.domain.bean.ParkInsideCarNumBean">
        SELECT
        t.pl_no         plNo,
        sum(CASE park_order_type
        WHEN 300
        THEN 1
        WHEN 500
        THEN 1
        ELSE 0 END) insideVipCarNum,
        count(*)        insideCarNum

        FROM park_in_out_record t
        WHERE t.pl_no = #{plNo}

        AND t.park_state = 10
        AND t.park_in_time &gt;= #{startTime}
        AND t.park_in_time &lt;= #{endTime}
        GROUP BY pl_no;

    </select>


    <!-- 通过记录第三方订单id(主键)和车牌号,查询订单id -->
    <select id="queryOrderIdByRecordIdAndCarNumber" resultType="java.lang.String">
        select
            order_id
        from
            park_in_out_record
        where
            record_id=#{recordId} and car_number=#{carNumber} limit 1
    </select>
    <select id="statisticParkInOutRecord"
            resultType="com.zteits.clouds.api.dto.park.dto.ParkInOutRecordStatisticDTO">

        select t.park_order_type                  parkOrderType,
               count(*)                           num,
               sum(ifnull(t.order_total_fee, 0))  sumTotalFee,
               sum(ifnull(t.parking_duration, 0)) sumParkDuration
        from park_in_out_record t
        where t.data_state = 1
        <if test="req.plNos !=null and req.plNos.size > 0 ">
            and t.pl_no in
            <foreach collection="req.plNos" item="plNo" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="req.parkOrderTypes != null and req.parkOrderTypes.size > 0">
            and t.park_order_type in
            <foreach collection="req.parkOrderTypes" item="parkOrderType" open="(" close=")" separator=",">
                #{parkOrderType}
            </foreach>
        </if>
        <if test="req.parkState != null">
            and t.park_state = #{req.parkState}
        </if>
        <if test="req.parkOutTimeStart != null">
            and t.park_out_time >= #{req.parkOutTimeStart}
        </if>
        <if test="req.parkOutTimeEnd != null">
            and t.park_out_time &lt;= #{req.parkOutTimeEnd}
        </if>

        <if test="req.topOrgId != null ">
            and t.top_org_id  = #{req.topOrgId}
        </if>
        group by t.park_order_type

    </select>
    <select id="pageQueryParkInOutRecord" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from park_in_out_record t
        where  t.data_state = 1
        <if test="req.plNos !=null and req.plNos.size > 0 ">
            and t.pl_no in
            <foreach collection="req.plNos" item="plNo" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="req.parkOrderTypes != null and req.parkOrderTypes.size > 0">
            and t.park_order_type in
            <foreach collection="req.parkOrderTypes" item="parkOrderType" open="(" close=")" separator=",">
                #{parkOrderType}
            </foreach>
        </if>
        <if test="req.parkState != null">
            and t.park_state = #{req.parkState}
        </if>
        <if test="req.parkOutTimeStart != null">
            and t.park_out_time >= #{req.parkOutTimeStart}
        </if>
        <if test="req.parkOutTimeEnd != null">
            and t.park_out_time &lt;= #{req.parkOutTimeEnd}
        </if>

        <if test="req.topOrgId != null ">
            and t.top_org_id  = #{req.topOrgId}
        </if>

        order by t.park_out_time desc

    </select>
</mapper>