Python+Django框架构建的汽车美容与保养网站:从数据库设计到前端实现全过程

42 阅读4分钟

一、个人简介

  • 💖💖作者:计算机编程果茶熊
  • 💙💙个人简介:曾长期从事计算机专业培训教学,担任过编程老师,同时本人也热爱上课教学,擅长Java、微信小程序、Python、Golang、安卓Android等多个IT方向。会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我!
  • 💛💛想说的话:感谢大家的关注与支持!
  • 💜💜
  • 网站实战项目
  • 安卓/小程序实战项目
  • 💕💕文末获取源码联系计算机编程果茶熊

二、系统介绍

  • 开发语言:Java+Python
  • 数据库:MySQL
  • 系统架构:B/S
  • 后端框架:SpringBoot(Spring+SpringMVC+Mybatis)+Django
  • 前端:Vue+HTML+CSS+JavaScript+jQuery
  • 本《汽车美容与保养网站》系统采用B/S架构,基于Java/Python双版本支持的技术方案,后端分别使用Spring Boot(Spring+SpringMVC+Mybatis)和Django框架,前端采用Vue+ElementUI+HTML技术栈,数据库选用MySQL进行数据存储和管理。系统功能模块完善,包括首页展示、汽车资讯发布、服务类型分类、服务项目详情、保养预约管理、提醒与通知管理以及商品订单处理等核心功能,为用户提供全方位的汽车美容与保养服务体验。用户可通过网站浏览汽车美容与保养相关资讯,了解各类服务项目,根据需求在线预约保养服务,系统会自动发送提醒与通知,确保用户及时获取服务状态信息。同时,系统集成商品订单功能,方便用户购买汽车美容与保养相关产品,实现从信息获取、服务预约到产品购买的一站式服务流程,有效提升用户体验和服务效率,为汽车美容与保养行业提供了一个功能完备、操作便捷的综合服务平台。

三、汽车美容与保养网站-视频解说

Python+Django框架构建的汽车美容与保养网站:从数据库设计到前端实现全过程

四、汽车美容与保养网站-功能展示

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述

五、汽车美容与保养网站-代码展示


// 核心功能1:保养预约管理
@Service
public class AppointmentServiceImpl implements AppointmentService {
    
    @Autowired
    private AppointmentMapper appointmentMapper;
    
    @Autowired
    private NotificationService notificationService;
    
    @Override
    @Transactional
    public AppointmentResponse createAppointment(AppointmentRequest request) {
        // 验证预约时间是否有效
        if (request.getAppointmentTime().before(new Date())) {
            throw new BusinessException("预约时间不能早于当前时间");
        }
        
        // 检查服务项目是否存在
        ServiceItem serviceItem = serviceItemMapper.findById(request.getServiceItemId());
        if (serviceItem == null) {
            throw new BusinessException("所选服务项目不存在");
        }
        
        // 检查当天预约是否已满
        int dailyAppointments = appointmentMapper.countByDateAndServiceType(
                request.getAppointmentTime(), request.getServiceTypeId());
        if (dailyAppointments >= serviceItem.getDailyLimit()) {
            throw new BusinessException("当日预约已满,请选择其他日期");
        }
        
        // 创建预约记录
        Appointment appointment = new Appointment();
        BeanUtils.copyProperties(request, appointment);
        appointment.setStatus(AppointmentStatus.PENDING);
        appointment.setCreateTime(new Date());
        
        // 保存预约信息
        appointmentMapper.insert(appointment);
        
        // 发送预约确认通知
        NotificationDTO notification = new NotificationDTO();
        notification.setUserId(request.getUserId());
        notification.setTitle("预约确认通知");
        notification.setContent("您已成功预约" + serviceItem.getName() + 
                "服务,预约时间:" + DateUtils.formatDateTime(request.getAppointmentTime()));
        notification.setType(NotificationType.APPOINTMENT);
        notificationService.sendNotification(notification);
        
        // 返回预约信息
        AppointmentResponse response = new AppointmentResponse();
        BeanUtils.copyProperties(appointment, response);
        response.setServiceItemName(serviceItem.getName());
        return response;
    }
}

// 核心功能2:提醒与通知管理
@Service
public class NotificationServiceImpl implements NotificationService {

    @Autowired
    private NotificationMapper notificationMapper;
    
    @Autowired
    private UserMapper userMapper;
    
    @Autowired
    private JavaMailSender mailSender;
    
    @Value("${system.notification.email.sender}")
    private String emailSender;
    
    @Override
    public void sendNotification(NotificationDTO notificationDTO) {
        // 保存通知到数据库
        Notification notification = new Notification();
        BeanUtils.copyProperties(notificationDTO, notification);
        notification.setCreateTime(new Date());
        notification.setIsRead(false);
        notificationMapper.insert(notification);
        
        // 获取用户联系方式
        User user = userMapper.findById(notificationDTO.getUserId());
        if (user == null) {
            throw new BusinessException("用户不存在");
        }
        
        // 根据通知类型选择不同的发送方式
        switch (notificationDTO.getType()) {
            case APPOINTMENT:
                // 预约通知同时发送邮件和系统消息
                sendEmail(user.getEmail(), notificationDTO.getTitle(), notificationDTO.getContent());
                break;
            case MAINTENANCE:
                // 保养提醒通知,优先级高,发送邮件和短信
                sendEmail(user.getEmail(), notificationDTO.getTitle(), notificationDTO.getContent());
                if (StringUtils.isNotBlank(user.getPhone())) {
                    sendSMS(user.getPhone(), notificationDTO.getContent());
                }
                break;
            case PROMOTION:
                // 促销信息仅发送系统消息
                break;
            default:
                break;
        }
        
        // 记录通知发送日志
        NotificationLog log = new NotificationLog();
        log.setNotificationId(notification.getId());
        log.setSendTime(new Date());
        log.setStatus(NotificationStatus.SENT);
        notificationLogMapper.insert(log);
    }
    
    private void sendEmail(String to, String subject, String content) {
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(emailSender);
            message.setTo(to);
            message.setSubject(subject);
            message.setText(content);
            mailSender.send(message);
        } catch (Exception e) {
            log.error("发送邮件通知失败: {}", e.getMessage());
            throw new BusinessException("发送邮件通知失败");
        }
    }
}

// 核心功能3:商品订单处理
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;
    
    @Autowired
    private OrderItemMapper orderItemMapper;
    
    @Autowired
    private ProductMapper productMapper;
    
    @Autowired
    private PaymentService paymentService;
    
    @Override
    @Transactional
    public OrderResponse createOrder(OrderRequest orderRequest) {
        // 验证订单信息
        if (CollectionUtils.isEmpty(orderRequest.getItems())) {
            throw new BusinessException("订单商品不能为空");
        }
        
        // 创建订单主信息
        Order order = new Order();
        order.setUserId(orderRequest.getUserId());
        order.setOrderNo(generateOrderNo());
        order.setStatus(OrderStatus.PENDING);
        order.setCreateTime(new Date());
        order.setAddress(orderRequest.getAddress());
        order.setContactPhone(orderRequest.getContactPhone());
        
        // 计算订单总金额
        BigDecimal totalAmount = BigDecimal.ZERO;
        List<OrderItem> orderItems = new ArrayList<>();
        
        for (OrderItemRequest itemRequest : orderRequest.getItems()) {
            // 查询商品信息
            Product product = productMapper.findById(itemRequest.getProductId());
            if (product == null) {
                throw new BusinessException("商品不存在: " + itemRequest.getProductId());
            }
            
            // 检查库存
            if (product.getStock() < itemRequest.getQuantity()) {
                throw new BusinessException("商品库存不足: " + product.getName());
            }
            
            // 计算商品金额
            BigDecimal itemAmount = product.getPrice().multiply(new BigDecimal(itemRequest.getQuantity()));
            totalAmount = totalAmount.add(itemAmount);
            
            // 创建订单项
            OrderItem orderItem = new OrderItem();
            orderItem.setProductId(product.getId());
            orderItem.setProductName(product.getName());
            orderItem.setProductPrice(product.getPrice());
            orderItem.setQuantity(itemRequest.getQuantity());
            orderItem.setAmount(itemAmount);
            orderItems.add(orderItem);
            
            // 更新商品库存
            product.setStock(product.getStock() - itemRequest.getQuantity());
            productMapper.updateStock(product);
        }
        
        // 设置订单总金额
        order.setTotalAmount(totalAmount);
        
        // 保存订单
        orderMapper.insert(order);
        
        // 保存订单项
        for (OrderItem item : orderItems) {
            item.setOrderId(order.getId());
            orderItemMapper.insert(item);
        }
        
        // 创建支付信息
        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.setOrderId(order.getId());
        paymentRequest.setOrderNo(order.getOrderNo());
        paymentRequest.setAmount(totalAmount);
        paymentRequest.setPaymentMethod(orderRequest.getPaymentMethod());
        PaymentResponse paymentResponse = paymentService.createPayment(paymentRequest);
        
        // 构建返回结果
        OrderResponse response = new OrderResponse();
        response.setOrderId(order.getId());
        response.setOrderNo(order.getOrderNo());
        response.setTotalAmount(totalAmount);
        response.setStatus(order.getStatus());
        response.setPaymentUrl(paymentResponse.getPaymentUrl());
        
        return response;
    }
    
    private String generateOrderNo() {
        return "ORD" + System.currentTimeMillis() + RandomStringUtils.randomNumeric(4);
    }
}

六、汽车美容与保养网站-文档展示

部分文档

七、END

致谢

💕💕文末获取源码联系计算机编程果茶熊