<?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.IInvoiceMapper">

    <select id="getListByParam"  resultType="com.fdkankan.platform.order.entity.Invoice">
        SELECT i.* FROM t_invoice i LEFT JOIN t_camera c on i.camera_id = c.id
        <if test="param.searchKey != null and param.searchKey !='' " >
        LEFT JOIN t_user u on i.user_id = u.id  LEFT JOIN t_order o on i.order_id = o.id
        </if>
        WHERE i.rec_status = 'A' AND i.consume_type = 1 AND c.child_name IS NOT NULL
        <if test="param.searchKey != null and param.searchKey !='' " >
        AND ((u.user_name like CONCAT('%',#{param.searchKey},'%')) or (o.order_sn like CONCAT('%',#{param.searchKey},'%')))
        </if>
        <if test="param.startDate != null and param.startDate !='' " >
        and i.create_time &gt;= ${param.startDate} '00:00:00'
        </if>
        <if test=" param.endDate != null and param.endDate !='' " >
         and i.create_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_invoice i LEFT JOIN t_camera c on i.camera_id = c.id
        <if test="param.searchKey != null and param.searchKey !='' " >
            LEFT JOIN t_user u on i.user_id = u.id  LEFT JOIN t_order o on i.order_id = o.id
        </if>
        WHERE i.rec_status = 'A' AND i.consume_type = 1 AND c.child_name IS NOT NULL
        <if test="param.searchKey != null and param.searchKey !='' " >
            AND ((u.user_name like CONCAT('%',#{param.searchKey},'%')) or (o.order_sn like CONCAT('%',#{param.searchKey},'%')))
        </if>
        <if test="param.startDate != null and param.startDate !='' " >
            and i.create_time &gt;= ${param.startDate} '00:00:00'
        </if>
        <if test=" param.endDate != null and param.endDate !='' " >
            and i.create_time &lt;= ${param.endDate} '23:59:59'
        </if>
    </select>
</mapper>
