<?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.example.hotel.mapper.OrderMapper">

    <resultMap id="BaseResultMap" type="com.example.hotel.entity.Order">
        <id column="id" property="id"></id>
        <result column="post_id" property="postId"></result>
        <result column="user_id" property="userId"></result>
        <result column="quantity" property="quantity"></result>
        <result column="status" property="status"></result>
        <result column="start_date" property="startDate"></result>
        <result column="name" property="name"></result>
        <result column="phone" property="phone"></result>
        <result column="id_card" property="idCard"></result>
        <result column="price" property="price"></result>
        <result column="total_price" property="totalPrice"></result>
        <result column="post_title" property="postTitle"></result>
        <result column="post_number" property="postNumber"></result>
        <result column="create_time" property="createTime"></result>
    </resultMap>

    <select id="findAll" resultMap="BaseResultMap">
        SELECT
            id, post_id, user_id, quantity, status, start_date, name, phone, id_card, price, total_price, post_title, post_number, create_time
        FROM
            t_order
        WHERE
        <if test="startDate != null">
            create_time >= STR_TO_DATE( #{startDate}, "%Y-%m-%d" ) AND
        </if>
        <if test="endDate != null">
            create_time &lt;= STR_TO_DATE( #{endDate}, "%Y-%m-%d" )+1 AND
        </if>
        del_flag = 0
    </select>

    <select id="getTotalPriceSum" resultType="java.lang.Integer">
        SELECT
            sum(total_price)
        FROM
            t_order
        <where>
        <if test="startDate != null">
            create_time >= STR_TO_DATE( #{startDate}, "%Y-%m-%d" ) AND
        </if>
        <if test="endDate != null">
            create_time &lt;= STR_TO_DATE( #{endDate}, "%Y-%m-%d" )+1 AND
        </if>
         del_flag = 0
        </where>
    </select>


</mapper>