package cn.van.business.repository;

import cn.van.business.model.jd.JDOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * JD订单数据访问层
 */
@Repository
public interface JDOrderRepository extends JpaRepository<JDOrder, Long> {
    /**
     * 根据订单号查询订单
     *
     * @param remark 订单号
     * @return JDOrder 实体
     */
    JDOrder findByRemark(String remark);

    /**
     * 根据下单人查询订单列表
     *
     * @param buyer 下单人
     * @return 订单列表
     */
    List<JDOrder> findByBuyer(String buyer);

    /**
     * 根据分销标记查询订单列表
     *
     * @param distributionMark 分销标记
     * @return 订单列表
     */
    List<JDOrder> findByDistributionMark(String distributionMark);

    List<JDOrder> findByOrderTimeBetween(Date startTime, Date endTime);

    // 并且按日期降序排序
    List<JDOrder> findByAddressOrderByOrderTimeDesc(String address);

    //select * from jd_order jo where jo.address like "%江苏%" or jo.remark like "%150%" or jo.order_id like "%320%" or jo.buyer like "兽"
    @Query("select jo from JDOrder jo where jo.address like %?1% or jo.remark like %?1% or jo.orderId like %?1% or jo.buyer like %?1%")
    List<JDOrder> searchOrder(String order);
}
