package J20250801.homework.demo01;

import java.util.Random;

/**
 * @author WanJl
 * @version 1.0
 * @title Rider
 * @description 消费者---骑手
 * @create 2025/8/1
 */
public class Rider implements Runnable{
    private OrderQueue orderQueue;
    private String name;

    public Rider() {
    }

    public Rider(OrderQueue orderQueue, String name) {
        this.orderQueue = orderQueue;
        this.name = name;
    }
    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()){

            try {
                //取出订单
                Order order = orderQueue.take();
                //根据订单的类型处理订单
                int handleTime=0;
                switch (order.getType()){
                    case "餐饮":
                        handleTime=3000;
                        break;
                    case "生鲜":
                        handleTime=5000;
                        break;
                    case "药品":
                        handleTime=2000;
                        break;
                }
                System.out.println("骑手"+name+"开始处理"+order.getType()+"订单，需要"+handleTime/1000+"秒");
                Thread.sleep(handleTime);
                System.out.println("骑手"+name+"完成处理"+order.getType()+"订单");
            } catch (InterruptedException e) {
                System.out.println("骑手"+name+"已停止工作....");
            }
        }
    }
}
