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ường | Kiểu dữ liệu | Mô tả |
|---|---|---|
| user_id | BIGINT | Định danh người dùng (PK) |
| username | VARCHAR(50) | Tên hiển thị |
| VARCHAR(100) | Email (duy nhất) | |
| phone | VARCHAR(20) | Số điện thoại |
| password_hash | VARCHAR(100) | Mật khẩu mã hóa |
| is_active | TINYINT | Trạng thái tài khoản |
| registered_at | DATETIME | Thời gian đăng ký |
Bảng Sản phẩm
| Tên trường | Kiểu dữ liệu | Mô tả |
|---|---|---|
| product_id | BIGINT | Định danh sản phẩm (PK) |
| name | VARCHAR(100) | Tên sản phẩm |
| category | VARCHAR(50) | Danh mục |
| price | DECIMAL(10,2) | Giá bán |
| stock | INT | Tồn kho |
Bảng Đơn hàng
| Tên trường | Kiểu dữ liệu | Mô tả |
|---|---|---|
| order_id | BIGINT | Định danh đơn hàng (PK) |
| user_id | BIGINT | ID người dùng |
| total_amount | DECIMAL(10,2) | Tổng giá trị |
| status | TINYINT | Trạ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");
}
}