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

<!-- 实现哪个Dao -->
<mapper namespace="com.wyz.demo.dao.OrderRepository">

    <resultMap id="OrderMap" type="com.wyz.demo.po.OrderPO">
        <id property="id" column="id" />
        <result property="senderId" column="sender_id"/>
        <result property="receiverId" column="receiver_id"/>
    </resultMap>

    <insert id="addOrder">
        insert into `order`
        (`description`,`when`,`location`,`sender_id`,`receiver_id`,
         `price`,`status`,`comment`,`timestamp`)
        values
        (#{description},#{when},#{location},#{senderId},null,
         #{price},"待接单",#{comment},now())
    </insert>


    <update id="pickOrder">
        update `order` set `receiver_id`=#{receiver_id},`status`="已接单"  where id=#{id}
    </update>


    <select id="getOrdersByUserId" resultMap="OrderMap" parameterType="int">
        select * from `order` where sender_id = #{sender_id}
    </select>


    <select id="getAllUnpickOrders" resultMap="OrderMap">
        select * from `order` where `status` = "待接单"
    </select>

    <select id="getOrderById" resultMap="OrderMap">
        select * from `order` where id = #{id}
    </select>





</mapper>