Thiết kế Hệ thống Quản lý Cửa hàng Điện thoại Doanh nghiệp với SpringBoot và Vue.js

Giới thiệu Hệ thống

Hệ thống quản lý cửa hàng điện thoại doanh nghiệp ứng dụng kiến trúc hiện đại với SpringBoot backend, Vue.js frontend và MyBatis cho tầng truy xuất dữ liệu. Giải pháp này tối ưu khả năng mở rộng, hiệu năng cao và trải nghiệm người dùng, giải quyết các thách thức về tải đồng thời và tính sẵn sàng trong thương mại điện tử.

Thiết kế Cơ sở dữ liệu

Bảng Người dùng

Tên trườngKiểu dữ liệuMô tả
user_idBIGINTĐịnh danh người dùng (PK)
usernameVARCHAR(50)Tên hiển thị
emailVARCHAR(100)Email (duy nhất)
phoneVARCHAR(20)Số điện thoại
password_hashVARCHAR(100)Mật khẩu mã hóa
is_activeTINYINTTrạng thái tài khoản
registered_atDATETIMEThời gian đăng ký

Bảng Sản phẩm

Tên trườngKiểu dữ liệuMô tả
product_idBIGINTĐịnh danh sản phẩm (PK)
nameVARCHAR(100)Tên sản phẩm
categoryVARCHAR(50)Danh mục
priceDECIMAL(10,2)Giá bán
stockINTTồn kho

Bảng Đơn hàng

Tên trườngKiểu dữ liệuMô tả
order_idBIGINTĐịnh danh đơn hàng (PK)
user_idBIGINTID người dùng
total_amountDECIMAL(10,2)Tổng giá trị
statusTINYINTTrạng thái đơn hàng

Kiến trúc Kỹ thuật

Spring Boot Backend

Spring Boot đơn giản hóa phát triển backend với cơ chế tự cấu hình, server nhúng và hỗ trợ monitoring qua Actuator. Cấu trúc module:

@SpringBootApplication
@MapperScan("com.enterprise.dao")
public class ECommerceApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(ECommerceApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(ECommerceApplication.class);
    }
}

Vue.js Frontend

Kiến trúc component-based của Vue.js kết hợp Vuex cho quản lý trạng thái và Vue Router cho điều hướng, tối ưu trải nghiệm người dùng.

Triển khai Chức năng

Điều khiển Người dùng

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/login")
    public Response login(@RequestParam String username, 
                          @RequestParam String password) {
        Customer user = customerService.authenticate(username, password);
        String token = tokenService.generateToken(user.getId());
        return new Response().setData(token);
    }

    @PostMapping
    public Response register(@RequestBody Customer newUser) {
        if (customerService.usernameExists(newUser.getUsername())) {
            throw new BusinessException("Tài khoản đã tồn tại");
        }
        customerService.createUser(newUser);
        return Response.success();
    }
    
    @GetMapping("/{id}")
    public Response getProfile(@PathVariable Long id) {
        return new Response(customerService.getById(id));
    }
}

Quản lý Phiên

@RestController
@RequestMapping("/session")
public class SessionController {

    @GetMapping("/current")
    public Response getCurrentUser(HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        return new Response(customerService.getById(userId));
    }

    @PostMapping("/logout")
    public Response logout(HttpSession session) {
        session.invalidate();
        return Response.success("Đăng xuất thành công");
    }
}

Thẻ: SpringBoot Vue.js mybatis mysql Thiết kế CSDL

Đăng vào ngày 19 tháng 6 lúc 16:43