<?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.yijia.station.mapper.PayOrderMapper">

    <resultMap type="PayOrder" id="PayOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="oilGun"    column="oil_gun"    />
        <result property="oilName"    column="oil_name"    />
        <result property="consumerId"    column="consumer_id"    />
        <result property="consumer"    column="consumer"    />
        <result property="amt"    column="amt"    />
        <result property="stationId"    column="station_id"    />
        <result property="status"    column="status"    />
        <result property="orderLiters"    column="order_liters"    />
        <result property="payType"    column="pay_type"    />
        <result property="payWay"    column="pay_way"    />
        <result property="payDate"    column="pay_date"    />
        <result property="oilPersonnel"    column="oil_personnel"    />
        <result property="createdDate"    column="created_date"    />
        <result property="orderType"    column="order_type"    />
    </resultMap>

    <sql id="selectPayOrderVo">
        select order_id, order_no, oil_gun, oil_name, consumer_id, consumer, amt, station_id, status, order_liters, pay_type, pay_way, pay_date, oil_personnel, created_date, order_type from pay_order
    </sql>

    <select id="selectPayOrderList" parameterType="PayOrder" resultMap="PayOrderResult">
        <include refid="selectPayOrderVo"/>
        <where>
            <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="oilGun != null  and oilGun != ''"> and oil_gun = #{oilGun}</if>
            <if test="oilName != null  and oilName != ''"> and oil_name like concat('%', #{oilName}, '%')</if>
            <if test="consumerId != null "> and consumer_id = #{consumerId}</if>
            <if test="consumer != null  and consumer != ''"> and consumer = #{consumer}</if>
            <if test="amt != null  and amt != ''"> and amt = #{amt}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="orderLiters != null  and orderLiters != ''"> and order_liters = #{orderLiters}</if>
            <if test="payType != null  and payType != ''"> and pay_type = #{payType}</if>
            <if test="payWay != null  and payWay != ''"> and pay_way = #{payWay}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(created_date,'%y-%m-%d %H:%i:%s') &gt;= date_format(#{beginTime},'%y-%m-%d %H:%i:%s')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(created_date,'%y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%y-%m-%d %H:%i:%s')
            </if>
<!--            <if test="payDate != null "> and pay_date = #{payDate}</if>-->
            <if test="oilPersonnel != null  and oilPersonnel != ''"> and oil_personnel = #{oilPersonnel}</if>
<!--            <if test="createdDate != null "> and created_date = #{createdDate}</if>-->
            <if test="orderType != null  and orderType != ''"> and order_type = #{orderType}</if>
        </where>
        ORDER BY created_date DESC
    </select>

    <select id="selectPayOrderById" parameterType="Long" resultMap="PayOrderResult">
        <include refid="selectPayOrderVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertPayOrder" parameterType="PayOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into pay_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">order_no,</if>
            <if test="oilGun != null">oil_gun,</if>
            <if test="oilName != null">oil_name,</if>
            <if test="consumerId != null">consumer_id,</if>
            <if test="consumer != null">consumer,</if>
            <if test="amt != null">amt,</if>
            <if test="stationId != null">station_id,</if>
            <if test="status != null">status,</if>
            <if test="orderLiters != null">order_liters,</if>
            <if test="payType != null">pay_type,</if>
            <if test="payWay != null">pay_way,</if>
            <if test="payDate != null">pay_date,</if>
            <if test="oilPersonnel != null">oil_personnel,</if>
            <if test="createdDate != null">created_date,</if>
            <if test="orderType != null">order_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">#{orderNo},</if>
            <if test="oilGun != null">#{oilGun},</if>
            <if test="oilName != null">#{oilName},</if>
            <if test="consumerId != null">#{consumerId},</if>
            <if test="consumer != null">#{consumer},</if>
            <if test="amt != null">#{amt},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="status != null">#{status},</if>
            <if test="orderLiters != null">#{orderLiters},</if>
            <if test="payType != null">#{payType},</if>
            <if test="payWay != null">#{payWay},</if>
            <if test="payDate != null">#{payDate},</if>
            <if test="oilPersonnel != null">#{oilPersonnel},</if>
            <if test="createdDate != null">#{createdDate},</if>
            <if test="orderType != null">#{orderType},</if>
         </trim>
    </insert>

    <update id="updatePayOrder" parameterType="PayOrder">
        update pay_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="oilGun != null">oil_gun = #{oilGun},</if>
            <if test="oilName != null">oil_name = #{oilName},</if>
            <if test="consumerId != null">consumer_id = #{consumerId},</if>
            <if test="consumer != null">consumer = #{consumer},</if>
            <if test="amt != null">amt = #{amt},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="orderLiters != null">order_liters = #{orderLiters},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="payWay != null">pay_way = #{payWay},</if>
            <if test="payDate != null">pay_date = #{payDate},</if>
            <if test="oilPersonnel != null">oil_personnel = #{oilPersonnel},</if>
            <if test="createdDate != null">created_date = #{createdDate},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deletePayOrderById" parameterType="Long">
        delete from pay_order where order_id = #{orderId}
    </delete>

    <delete id="deletePayOrderByIds" parameterType="String">
        delete from pay_order where order_id in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>

</mapper>
