<?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.jpsoft.shinestar.modules.base.dao.ParkingRecordDAO">

    <sql id="Base_Column_List">
	id_,
	create_by,
	create_time,
	update_by,
	update_time,
	del_flag,
	serial_number,
	total_amount,
	reduce_amount,
	pay_amount,
	pay_type,
	park_id,
	car_num,
	parking_time,
	in_parking_time,
	payment_time,
	pay_status,
	open_id,
	transaction_number,
	product_theme,
	car_type,
    c_type,
    order_number,
    in_channel_id,
    in_channel,
    out_channel_id,
    out_channel,
    in_image,
    out_image,
    out_parking_time
</sql>
    <resultMap id="ParkingRecordMap" type="com.jpsoft.shinestar.modules.base.entity.ParkingRecord">
        <id property="id" column="id_" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="delFlag" column="del_flag" />
        <result property="serialNumber" column="serial_number" />
        <result property="totalAmount" column="total_amount"/>
        <result property="reduceAmount" column="reduce_amount"/>
        <result property="payAmount" column="pay_amount" />
        <result property="payType" column="pay_type" />
        <result property="parkId" column="park_id" />
        <result property="carNum" column="car_num" />
        <result property="parkingTime" column="parking_time" />
        <result property="inParkingTime" column="in_parking_time" />
        <result property="paymentTime" column="payment_time" />
        <result property="payStatus" column="pay_status" />
        <result property="openId" column="open_id" />
        <result property="transactionNumber" column="transaction_number" />
        <result property="productTheme" column="product_theme"/>
        <result property="carType" column="car_type"/>
        <result property="cType" column="c_type"/>
        <result property="orderNumber" column="order_number"/>
        <result property="inChannelId" column="in_channel_id"/>
        <result property="inChannel" column="in_channel"/>
        <result property="outChannelId" column="out_channel_id"/>
        <result property="outChannel" column="out_channel"/>
        <result property="inImage" column="in_image"/>
        <result property="outImage" column="out_image"/>
        <result property="outParkingTime" column="out_parking_time"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.ParkingRecord">

        <![CDATA[
		insert into base_parking_record
	    (id_,create_by,create_time,update_by,update_time,del_flag,serial_number,total_amount,reduce_amount,pay_amount,pay_type,park_id,car_num,
	    parking_time,in_parking_time,payment_time,pay_status,open_id,transaction_number,product_theme,car_type,c_type,order_number,in_channel_id,in_channel,out_channel_id,out_channel,in_image,out_image,out_parking_time
	    )
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{delFlag,jdbcType= NUMERIC }
			,#{serialNumber,jdbcType=VARCHAR}
            ,#{totalAmount,jdbcType=DECIMAL}
            ,#{reduceAmount,jdbcType=DECIMAL}
			,#{payAmount,jdbcType= DECIMAL }
			,#{payType,jdbcType= VARCHAR }
			,#{parkId,jdbcType=BIGINT}
			,#{carNum,jdbcType=VARCHAR}
			,#{parkingTime,jdbcType=DECIMAL}
			,#{inParkingTime,jdbcType=TIMESTAMP}
			,#{paymentTime,jdbcType=TIMESTAMP}
			,#{payStatus,jdbcType=VARCHAR}
			,#{openId,jdbcType=VARCHAR}
			,#{transactionNumber,jdbcType=VARCHAR}
			,#{productTheme,jdbcType=VARCHAR}
            ,#{carType,jdbcType=VARCHAR}
            ,#{cType,jdbcType=VARCHAR}
            ,#{orderNumber,jdbcType=VARCHAR}
            ,#{inChannelId,jdbcType=VARCHAR}
            ,#{inChannel,jdbcType=VARCHAR}
            ,#{outChannelId,jdbcType=VARCHAR}
            ,#{outChannel,jdbcType=VARCHAR}
            ,#{inImage,jdbcType=VARCHAR}
            ,#{outImage,jdbcType=VARCHAR}
            ,#{outParkingTime,jdbcType=TIMESTAMP}
		)
	]]>
    </insert>

<!--auto generated by MybatisCodeHelper on 2020-04-14-->
    <select id="findById" resultMap="ParkingRecordMap">
        select
        <include refid="Base_Column_List"/>
        from base_parking_record
        where id_=#{id} and del_flag is false
    </select>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.ParkingRecord">
        update base_parking_record
        <set>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="serialNumber!=null">
                serial_number=#{serialNumber,jdbcType=VARCHAR},
            </if>
            <if test="totalAmount !=null">
                total_amount=#{totalAmount,jdbcType=DECIMAL},
            </if>
            <if test="reduceAmount !=null">
                reduce_amount=#{reduceAmount,jdbcType=DECIMAL},
            </if>
            <if test="payAmount !=null">
                pay_amount=#{payAmount,jdbcType=DECIMAL},
            </if>
            <if test="payType !=null">
                pay_type=#{payType,jdbcType=VARCHAR},
            </if>
            <if test="parkId !=null">
                park_id=#{parkId,jdbcType=BIGINT},
            </if>
            <if test="carNum !=null">
                car_num=#{carNum,jdbcType=VARCHAR},
            </if>
            <if test="parkingTime !=null">
                parking_time=#{parkingTime,jdbcType=DECIMAL},
            </if>
            <if test="inParkingTime !=null">
                in_parking_time=#{inParkingTime,jdbcType=TIMESTAMP},
            </if>
            <if test="paymentTime !=null">
                payment_time=#{paymentTime,jdbcType=TIMESTAMP},
            </if>
            <if test="payStatus !=null">
                pay_status=#{payStatus,jdbcType=VARCHAR},
            </if>
            <if test="openId !=null">
                open_id=#{openId,jdbcType=VARCHAR},
            </if>
            <if test="transactionNumber !=null">
                transaction_number=#{transactionNumber,jdbcType=VARCHAR},
            </if>
            <if test="productTheme !=null">
                product_theme=#{productTheme,jdbcType=VARCHAR},
            </if>
            <if test="carType !=null">
                car_type=#{carType,jdbcType=VARCHAR},
            </if>
            <if test="cType !=null">
                c_type=#{cType,jdbcType=VARCHAR},
            </if>
            <if test="orderNumber !=null">
                order_number=#{orderNumber,jdbcType=VARCHAR},
            </if>
            <if test="inChannelId !=null">
                in_channel_id=#{inChannelId,jdbcType=VARCHAR},
            </if>
            <if test="inChannel !=null">
                in_channel=#{inChannel,jdbcType=VARCHAR},
            </if>
            <if test="outChannelId !=null">
                out_channel_id=#{outChannelId,jdbcType=VARCHAR},
            </if>
            <if test="outChannel !=null">
                out_channel=#{outChannel,jdbcType=VARCHAR},
            </if>
            <if test="inImage !=null">
                in_image=#{inImage,jdbcType=VARCHAR},
            </if>
            <if test="outImage !=null">
                out_image=#{outImage,jdbcType=VARCHAR},
            </if>
            <if test="outParkingTime !=null">
                out_parking_time=#{outParkingTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id_=#{id}
    </update>

<!--auto generated by MybatisCodeHelper on 2020-04-14-->
    <select id="findBySerialNumber" resultMap="ParkingRecordMap">
        select
        <include refid="Base_Column_List"/>
        from base_parking_record
        where serial_number=#{serialNumber} and del_flag is false
    </select>

    <select id="findByOrderNumber" resultMap="ParkingRecordMap">
        <![CDATA[
        select * from base_parking_record
        where del_flag = 0
        and order_number = #{orderNumber}
        limit 1
        ]]>
    </select>


    <select id="search" parameterType="hashmap" resultMap="ParkingRecordMap">
        <![CDATA[
			SELECT a.* FROM base_parking_record a
			inner join base_parking_info b on a.park_id = b.park_id
	        INNER JOIN base_company_info c ON b.company_id = c.id_
		]]>
        <where>
            a.del_flag = 0 and b.del_flag = 0
            <if test="searchParams.carNum != null">
                and a.car_num like #{searchParams.carNum}
            </if>
            <if test="searchParams.companyId != null">
                and b.company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.carType != null">
                and a.car_type = #{searchParams.carType}
            </if>
            <if test="searchParams.payType != null">
                and a.pay_type = #{searchParams.payType}
            </if>
            <if test="searchParams.outParkingTime != null">
                <if test="searchParams.outParkingTime == 0">
                    and a.out_parking_time is null
                </if>
                <if test="searchParams.outParkingTime == 1">
                    and a.out_parking_time is not null
                </if>
            </if>
            <if test='searchParams.paymentStartTime!=null'>
                <![CDATA[
                    and a.payment_time >= #{searchParams.paymentStartTime}
                ]]>
            </if>
            <if test='searchParams.paymentEndTime!=null'>
                <![CDATA[
                    and a.payment_time <= #{searchParams.paymentEndTime}
                ]]>
            </if>

            <if test='searchParams.inParkingStartTime!=null'>
            <![CDATA[
                    and a.in_parking_time >= #{searchParams.inParkingStartTime}
                ]]>
        </if>
            <if test='searchParams.inParkingEndTime!=null'>
                <![CDATA[
                    and a.in_parking_time <= #{searchParams.inParkingEndTime}
                ]]>
            </if>

            <if test='searchParams.outParkingStartTime!=null'>
                <![CDATA[
                    and a.out_parking_time >= #{searchParams.outParkingStartTime}
                ]]>
            </if>
            <if test='searchParams.outParkingEndTime!=null'>
                <![CDATA[
                    and a.out_parking_time <= #{searchParams.outParkingEndTime}
                ]]>
            </if>
            <if test="searchParams.parentCompanyCode != null">
                and c.code_ like #{searchParams.parentCompanyCode}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

</mapper>
