package J20250801.homework.demo01;

import java.util.Random;

/**
 * @author WanJl
 * @version 1.0
 * @title Restaurant
 * @description 生产者--商家
 * @create 2025/8/1
 */
public class Restaurant implements Runnable{
    private OrderQueue orderQueue;
    private String name;
    private String[] orderTypes={"餐饮","生鲜","药品"};
    private Random ran=new Random();

    public Restaurant() {
    }

    public Restaurant(OrderQueue orderQueue, String name) {
        this.orderQueue = orderQueue;
        this.name = name;
    }

    @Override
    public void run() {
        try {
            while (!Thread.currentThread().isInterrupted()){
                //随机生成订单类型
                String type = orderTypes[ran.nextInt(orderTypes.length)];
                Order order=new Order(type);
                //把订单放入队列
                orderQueue.put(order);
                System.out.println("商家"+name+"生产了"+type+"订单");
                //休息1-3秒
                Thread.sleep(1000+ran.nextInt(3000));
            }
        } catch (InterruptedException e) {
            System.out.println("商家"+name+"停止生产");
        }
    }
}
