基于Spring Boot的宠物店管理系统

1. 简介

宠物店管理系统是一个用于管理宠物店业务的软件系统。它可以帮助宠物店完成宠物信息管理、宠物预约管理、宠物销售管理等功能。本文将介绍一个基于Spring Boot的宠物店管理系统的设计和实现,并提供相关的代码示例。

2. 系统设计

宠物店管理系统主要包含以下几个模块:

  • 宠物信息管理:用于管理宠物的基本信息,包括宠物种类、宠物价格、宠物库存等。
  • 宠物预约管理:用于管理宠物的预约情况,包括预约日期、预约人姓名、联系方式等。
  • 宠物销售管理:用于管理宠物的销售情况,包括销售日期、销售人员、销售价格等。

下面是系统的类图:

classDiagram
    class Pet {
        - String name
        - String breed
        - double price
        - int stock
        + String getName()
        + void setName(String name)
        + String getBreed()
        + void setBreed(String breed)
        + double getPrice()
        + void setPrice(double price)
        + int getStock()
        + void setStock(int stock)
    }

    class Appointment {
        - LocalDate date
        - String customerName
        - String contact
        + LocalDate getDate()
        + void setDate(LocalDate date)
        + String getCustomerName()
        + void setCustomerName(String customerName)
        + String getContact()
        + void setContact(String contact)
    }

    class Sale {
        - LocalDate date
        - String salesperson
        - double price
        + LocalDate getDate()
        + void setDate(LocalDate date)
        + String getSalesperson()
        + void setSalesperson(String salesperson)
        + double getPrice()
        + void setPrice(double price)
    }

    class PetService {
        + Pet getPetById(int id)
        + List<Pet> getAllPets()
        + void savePet(Pet pet)
        + void deletePet(int id)
    }

    class AppointmentService {
        + Appointment getAppointmentById(int id)
        + List<Appointment> getAllAppointments()
        + void saveAppointment(Appointment appointment)
        + void deleteAppointment(int id)
    }

    class SaleService {
        + Sale getSaleById(int id)
        + List<Sale> getAllSales()
        + void saveSale(Sale sale)
        + void deleteSale(int id)
    }

    PetService -- Pet
    AppointmentService -- Appointment
    SaleService -- Sale

3. 代码实现

3.1 宠物信息管理

首先,我们先来实现宠物信息管理模块的功能。宠物信息由Pet类表示,我们可以通过PetService来对宠物信息进行增删改查操作。下面是Pet类的代码示例:

public class Pet {
    private String name;
    private String breed;
    private double price;
    private int stock;

    // 省略构造方法和getter/setter方法
}

接下来是PetService的代码示例:

@Service
public class PetService {
    private List<Pet> pets = new ArrayList<>();

    public Pet getPetById(int id) {
        for (Pet pet : pets) {
            if (pet.getId() == id) {
                return pet;
            }
        }
        return null;
    }

    public List<Pet> getAllPets() {
        return pets;
    }

    public void savePet(Pet pet) {
        pets.add(pet);
    }

    public void deletePet(int id) {
        for (Iterator<Pet> iterator = pets.iterator(); iterator.hasNext();) {
            Pet pet = iterator.next();
            if (pet.getId() == id) {
                iterator.remove();
            }
        }
    }
}

3.2 宠物预约管理

接下来,我们实现宠物预约管理模块的功能。宠物预约由Appointment类表示,我们可以通过AppointmentService来对宠物预约信息进行增删改查操作。下面是Appointment类的代码示例:

public class Appointment {
    private LocalDate date;
    private String customerName;
    private String contact;

    // 省略构造方法和getter/setter方法
}

接下来是AppointmentService的代码示例:

@Service
public class AppointmentService {
    private List<Appointment> appointments = new ArrayList<>();

    public Appointment getAppointmentById(int id) {
        for (Appointment appointment : appointments) {
            if (appointment.getId() == id) {
                return appointment;
            }