疗愈门店系统/美业管理系统【客户管理】Java源码|博弈美业收银系统拓客系统分享

58 阅读2分钟
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

// 客户实体类
class Customer {
    private Long id;
    private String name;
    private String phone;
    private Date lastVisit;     // 上次到店时间
    private Double totalSpent;  // 累计消费金额
    private String remark;      // 客户备注/偏好

    // 构造方法、getters & setters
    public Customer(Long id, String name, String phone) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.totalSpent = 0.0;
    }

    // 其他setters...
}

// 客户管理核心类
public class CustomerManager {
    private List<Customer> customers = new ArrayList<>();
    private Long nextId = 1L;

    // 添加新客户
    public synchronized Customer addCustomer(String name, String phone) throws IllegalArgumentException {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("客户姓名不能为空");
        }
        if (phone == null || phone.trim().isEmpty()) {
            throw new IllegalArgumentException("联系电话不能为空");
        }
        
        Customer customer = new Customer(nextId++, name, phone);
        customers.add(customer);
        return customer;
    }

    // 根据ID删除客户
    public boolean deleteCustomer(Long id) {
        return customers.removeIf(c -> c.getId().equals(id));
    }

    // 更新客户信息
    public boolean updateCustomer(Long id, String newPhone, String newRemark) {
        return customers.stream()
                .filter(c -> c.getId().equals(id))
                .findFirst()
                .map(c -> {
                    if (newPhone != null) c.setPhone(newPhone);
                    if (newRemark != null) c.setRemark(newRemark);
                    return true;
                })
                .orElse(false);
    }

    // 根据ID查询客户
    public Customer getCustomerById(Long id) {
        return customers.stream()
                .filter(c -> c.getId().equals(id))
                .findFirst()
                .orElse(null);
    }

    // 根据姓名模糊查询
    public List<Customer> searchCustomersByName(String keyword) {
        return customers.stream()
                .filter(c -> c.getName().contains(keyword))
                .collect(Collectors.toList());
    }

    // 记录消费行为
    public void recordConsumption(Long customerId, Double amount) {
        customers.stream()
                .filter(c -> c.getId().equals(customerId))
                .findFirst()
                .ifPresent(c -> {
                    c.setTotalSpent(c.getTotalSpent() + amount);
                    c.setLastVisit(new Date());
                });
    }
}

▶ 代码分析:

1.结构设计:

Customer实体类封装客户核心属性

CustomerManager实现业务逻辑管理

使用内存存储(ArrayList)简化示例,实际应替换为数据库

2.核心功能:

客户建档(带参数校验)

客户信息维护

消费行为跟踪

多条件查询

自动ID生成(线程安全)

3.设计考虑:

验证关键字段(姓名、电话)

使用Stream API提升可读性

记录lastVisit和totalSpent用于客户分析

remark字段记录客户偏好(如过敏史、喜欢的技师等)

synchronized保证ID生成的原子性

4.扩展建议:

添加数据持久化(JDBC/JPA)

增加更多客户属性(会员等级、生日等)

实现分页查询

集成短信通知功能

添加消费记录明细

实现客户标签系统

▶ 这个实现体现了美业客户管理的典型需求,特别关注:

客户偏好记录

消费跟踪能力

到店频率管理

灵活查询能力

▶ 实际开发中需要根据具体业务需求补充:

会员管理系统集成

预约记录关联

营销活动参与记录

客户画像分析等高级功能