<?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.fdkankan.platform.order.mapper.IVirtualOrderMapper">

    <select id="getAllByParam" resultType="com.fdkankan.platform.order.entity.VirtualOrder">
        select t.status, t.points, t.amount from t_virtual_order t left join t_camera d on t.camera_id = d.id
        where t.rec_status = 'A' and t.pay_status = 1
        <if test="startDate != null and startDate !='' " >
            and t.trade_time &gt;= ${startDate}
        </if>
        <if test=" endDate != null and endDate !='' " >
            and t.trade_time &lt;= ${endDate}
        </if>
        <if test=" childName != null and childName !='' " >
            and c.child_name like concat('%',#{childName},'%')
        </if>
        <if test=" type != null and type !='' " >
            and and t.status  = ${type}
        </if>
        <if test="orderBy != null">
            order by ${orderBy}
        </if>
        <if test="start != null and pageSize !=null">
            limit ${start}, ${pageSize}
        </if>
    </select>

    <select id="getChargeListByParam" resultType="com.fdkankan.platform.user.vo.ResponseVirtualOrder">
        SELECT o.id, o.order_sn, o.points, c.child_name, o.pay_type, o.body, o.trade_time, o.status from t_virtual_order o
        LEFT JOIN t_camera c on o.camera_id = c.id  WHERE o.rec_status = 'A' and o.pay_status = 1   and o.pay_type = 0
        <if test=" userId != null and userId !='' " >
            and o.user_id = ${userId}
        </if>
        <if test=" status != null and status !='' " >
            and o.status = ${status}
        </if>
        <if test=" childName != null and childName !='' " >
            and c.child_name like concat('%',#{childName},'%')
        </if>
        <if test=" cameraId != null and cameraId !='' " >
            and o.camera_id = ${cameraId}
        </if>
        <if test="orderBy != null">
            order by ${orderBy}
        </if>
        <if test="start != null and pageSize !=null">
            limit ${start}, ${pageSize}
        </if>
    </select>


    <select id="getChargeCountByParam" resultType="integer">
        SELECT count(*) from t_virtual_order o WHERE o.rec_status = 'A' and o.pay_status = 1   and o.pay_type = 0
        <if test=" userId != null and userId !='' " >
            and o.user_id = ${userId}
        </if>
        <if test=" status != null and status !='' " >
            and o.status = ${status}
        </if>
        <if test=" childName != null and childName !='' " >
            and c.child_name like concat('%',#{childName},'%')
        </if>
        <if test=" cameraId != null and cameraId !='' " >
            and o.camera_id = ${cameraId}
        </if>
    </select>

    <select id="getListByParam" resultType="com.fdkankan.platform.user.vo.ResponseVirtualOrder">
        SELECT o.* FROM t_virtual_order o
        <if test=" param.searchKey != null and param.searchKey !='' " >
            LEFT JOIN t_user u on o.user_id = u.id
            LEFT JOIN t_camera c on o.camera_id = c.id
        </if>
        where o.rec_status = 'A' and o.pay_status = 1
        <if test=" param.type != null and param.type =1 " >
            and ((o.status = 0) or (o.status = 1) or (o.status = -2))
        </if>
        <if test=" param.type != null and param.type = 2 " >
            and o.status = -1
        </if>
        <if test=" param.searchKey != null and param.searchKey !='' " >
            and ((u.user_name like CONCAT('%',#{param.searchKey},'%')) or (c.child_name like CONCAT('%',#{param.searchKey},'%')) or (o.order_sn like CONCAT('%',#{param.searchKey},'%')))
        </if>

        <if test="param.startDate != null and param.startDate !='' " >
            and o.trade_time &gt;= ${param.startDate} '00:00:00'
        </if>
        <if test=" param.endDate != null and param.endDate !='' " >
            and o.trade_time &lt;= ${param.endDate} '23:59:59'
        </if>

        <if test="orderBy != null">
            order by ${orderBy}
        </if>
        <if test="start != null and pageSize!=null">
            limit ${start}, ${pageSize}
        </if>
    </select>


    <select id="getCountByParam" resultType="integer">
        SELECT count(*) FROM t_virtual_order o
        <if test=" param.searchKey != null and param.searchKey !='' " >
            LEFT JOIN t_user u on o.user_id = u.id
            LEFT JOIN t_camera c on o.camera_id = c.id
        </if>
        where o.rec_status = 'A' and o.pay_status = 1
        <if test=" param.type != null and param.type =1 " >
            and ((o.status = 0) or (o.status = 1) or (o.status = -2))
        </if>
        <if test=" param.type != null and param.type = 2 " >
            and o.status = -1
        </if>
        <if test=" param.searchKey != null and param.searchKey !='' " >
            and ((u.user_name like CONCAT('%',#{param.searchKey},'%')) or (c.child_name like CONCAT('%',#{param.searchKey},'%')) or (o.order_sn like CONCAT('%',#{param.searchKey},'%')))
        </if>

        <if test="param.startDate != null and param.startDate !='' " >
            and o.trade_time &gt;= ${param.startDate} '00:00:00'
        </if>
        <if test=" param.endDate != null and param.endDate !='' " >
            and o.trade_time &lt;= ${param.endDate} '23:59:59'
        </if>
    </select>
</mapper>
