Hệ thống quản lý mượn sách thư viện là một ứng dụng web hiện đại được xây dựng trên nền tảng Java sử dụng SpringBoot và Vue.js cho giao diện người dùng. Hệ thống này cung cấp các chức năng quản lý hiệu quả cho việc mượn trả sách trong môi trường thư viện.
Công nghệ sử dụng
Framework phía máy chủ SpringBoot
Spring Boot là giải pháp mạnh mẽ để phát triển các ứng dụng độc lập dựa trên framework Spring. Mục tiêu chính của nó là đơn giản hóa quá trình phát triển ứng dụng Spring bằng cách cung cấp các tính năng sẵn sàng sử dụng, đồng thời duy trì sự mạnh mẽ và linh hoạt của lõi hệ thống.
Spring Boot áp dụng nguyên tắc "quy ước hơn cấu hình", giúp các nhà phát triển tập trung vào logic nghiệp vụ thay vì các tệp cấu hình phức tạp. Nó tích hợp sẵn các máy chủ web nhúng như Tomcat, Undertow hoặc Jetty, cho phép đóng gói ứng dụng thành file JAR thực thi.
Framework phía giao diện Vue.js
Vue.js là framework JavaScript phổ biến dùng để xây dựng giao diện người dùng và ứng dụng trang đơn (SPA). Được tạo ra bởi Evan You vào năm 2014, đây là framework nhẹ, dễ học và linh hoạt.
Ưu điểm cốt lõi của Vue.js là hệ thống ràng buộc dữ liệu phản hồi, giúp quản lý dễ dàng sự thay đổi giữa view và dữ liệu. Mô hình phát triển component cho phép chia nhỏ ứng dụng thành các thành phần độc lập, tăng khả năng tái sử dụng mã nguồn và dễ bảo trì.
Mã nguồn chính
package com.library;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
@MapperScan(basePackages = {"com.repository"})
public class LibrarySystemApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(LibrarySystemApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(LibrarySystemApplication.class);
}
}
package com.controller;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidationUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.UserEntity;
import com.entity.view.UserView;
import com.service.UserService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.ResponseUtil;
import com.utils.MPUtil;
import com.utils.MapUtils;
import com.utils.CommonUtil;
import java.io.IOException;
/**
* Người dùng
* API phía máy chủ
* @author
* @email
* @date 2024-04-24 18:00:00
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private TokenService tokenService;
/**
* Đăng nhập
*/
@IgnoreAuth
@RequestMapping(value = "/authenticate")
public ResponseUtil authenticate(String username, String password, String captcha, HttpServletRequest request) {
UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
if(user == null || !user.getPassword().equals(password)) {
return ResponseUtil.error("Tên đăng nhập hoặc mật khẩu không đúng");
}
String token = tokenService.createToken(user.getId(), username, "user", "Người dùng");
return ResponseUtil.success().put("token", token);
}
/**
* Đăng ký
*/
@IgnoreAuth
@RequestMapping("/signup")
public ResponseUtil signup(@RequestBody UserEntity userEntity){
UserEntity existingUser = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", userEntity.getUsername()));
if(existingUser != null) {
return ResponseUtil.error("Tài khoản đã tồn tại");
}
Long userId = new Date().getTime();
userEntity.setId(userId);
userService.insert(userEntity);
return ResponseUtil.success();
}
/**
* Đăng xuất
*/
@RequestMapping("/signout")
public ResponseUtil signout(HttpServletRequest request) {
request.getSession().invalidate();
return ResponseUtil.success("Đăng xuất thành công");
}
/**
* Lấy thông tin người dùng từ session
*/
@RequestMapping("/profile")
public ResponseUtil getCurrentUserProfile(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
UserEntity user = userService.selectById(id);
return ResponseUtil.success().put("data", user);
}
/**
* Đặt lại mật khẩu
*/
@IgnoreAuth
@RequestMapping(value = "/passwordReset")
public ResponseUtil passwordReset(String username, HttpServletRequest request){
UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
if(user == null) {
return ResponseUtil.error("Tài khoản không tồn tại");
}
user.setPassword("123456");
userService.updateById(user);
return ResponseUtil.success("Mật khẩu đã được đặt lại thành: 123456");
}
/**
* Danh sách backend
*/
@RequestMapping("/pagination")
public ResponseUtil pagination(@RequestParam Map parameters, UserEntity user,
HttpServletRequest request){
EntityWrapper<UserEntity> wrapper = new EntityWrapper<UserEntity>();
PageUtils pageResult = userService.queryPage(parameters, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(wrapper, user), parameters), parameters));
return ResponseUtil.success().put("data", pageResult);
}
/**
* Danh sách frontend
*/
@IgnoreAuth
@RequestMapping("/items")
public ResponseUtil items(@RequestParam Map parameters, UserEntity user,
HttpServletRequest request){
EntityWrapper<UserEntity> wrapper = new EntityWrapper<UserEntity>();
PageUtils pageResult = userService.queryPage(parameters, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(wrapper, user), parameters), parameters));
return ResponseUtil.success().put("data", pageResult);
}
/**
* Danh sách
*/
@RequestMapping("/collections")
public ResponseUtil collections(UserEntity userEntity){
EntityWrapper<UserEntity> wrapper = new EntityWrapper<UserEntity>();
wrapper.allEq(MPUtil.allEQMapPre(userEntity, "user"));
return ResponseUtil.success().put("data", userService.selectListView(wrapper));
}
/**
* Truy vấn
*/
@RequestMapping("/search")
public ResponseUtil search(UserEntity userEntity){
EntityWrapper<UserEntity> wrapper = new EntityWrapper<UserEntity>();
wrapper.allEq(MPUtil.allEQMapPre(userEntity, "user"));
UserView userView = userService.selectView(wrapper);
return ResponseUtil.success("Truy vấn người dùng thành công").put("data", userView);
}
/**
* Chi tiết backend
*/
@RequestMapping("/details/{id}")
public ResponseUtil details(@PathVariable("id") Long id){
UserEntity user = userService.selectById(id);
return ResponseUtil.success().put("data", user);
}
/**
* Chi tiết frontend
*/
@IgnoreAuth
@RequestMapping("/view/{id}")
public ResponseUtil view(@PathVariable("id") Long id){
UserEntity user = userService.selectById(id);
return ResponseUtil.success().put("data", user);
}
/**
* Lưu backend
*/
@RequestMapping("/store")
public ResponseUtil store(@RequestBody UserEntity user, HttpServletRequest request){
if(userService.selectCount(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) > 0) {
return ResponseUtil.error("Tài khoản người dùng đã tồn tại");
}
user.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
UserEntity existingUser = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername()));
if(existingUser != null) {
return ResponseUtil.error("Người dùng đã tồn tại");
}
user.setId(new Date().getTime());
userService.insert(user);
return ResponseUtil.success();
}
/**
* Lưu frontend
*/
@RequestMapping("/create")
public ResponseUtil create(@RequestBody UserEntity user, HttpServletRequest request){
if(userService.selectCount(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) > 0) {
return ResponseUtil.error("Tài khoản người dùng đã tồn tại");
}
user.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
UserEntity existingUser = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername()));
if(existingUser != null) {
return ResponseUtil.error("Người dùng đã tồn tại");
}
user.setId(new Date().getTime());
userService.insert(user);
return ResponseUtil.success();
}
/**
* Cập nhật
*/
@RequestMapping("/modify")
@Transactional
public ResponseUtil modify(@RequestBody UserEntity user, HttpServletRequest request){
if(userService.selectCount(new EntityWrapper<UserEntity>().ne("id", user.getId()).eq("username", user.getUsername())) > 0) {
return ResponseUtil.error("Tài khoản người dùng đã tồn tại");
}
userService.updateById(user);
return ResponseUtil.success();
}
/**
* Xóa
*/
@RequestMapping("/remove")
public ResponseUtil remove(@RequestBody Long[] ids){
userService.deleteBatchIds(Arrays.asList(ids));
return ResponseUtil.success();
}
}
Thử nghiệm hệ thống
Việc thử nghiệm hệ thống từ nhiều góc độ khác nhau nhằm tìm ra các vấn đề tồn tại trong hệ thống là mục đích chính của quá trình thử nghiệm. Qua thử nghiệm chức năng, chúng ta có thể tìm kiếm và sửa chữa các lỗi hệ thống, đảm bảo hệ thống hoạt động ổn định. Trong quá trình thử nghiệm, cần chứng minh rằng hệ thống đáp ứng yêu cầu của khách hàng, phát hiện và khắc phục kịp thời các vấn đề và thiếu sót.
Mục tiêu thử nghiệm hệ thống
Trong chu kỳ phát triển hệ thống thư viện, thử nghiệm hệ thống là quá trình không thể thiếu và đòi hỏi sự kiên nhẫn. Tầm quan trọng của nó nằm ở chỗ đây là bước cuối cùng đảm bảo chất lượng và độ tin cậy của hệ thống, đồng thời là lần kiểm tra cuối cùng trong toàn bộ quá trình phát triển.
Thử nghiệm hệ thống chủ yếu nhằm tránh các vấn đề khi người dùng sử dụng, tăng trải nghiệm người dùng. Để không ảnh hưởng đến trải nghiệm người dùng, chúng ta cần xem xét từ nhiều góc độ và tư duy khác nhau về các vấn đề hệ thống có thể gặp phải, thông qua các kịch bản mô phỏng khác nhau để phát hiện và giải quyết lỗi.
Thử nghiệm chức năng hệ thống
Thử nghiệm các module chức năng của hệ thống thông qua các phương pháp như click, nhập giá trị biên giới và xác thực các trường bắt buộc/không bắt buộc - đây là một loạt thử nghiệm hộp đen. Bằng cách viết các ca thử nghiệm và thực hiện theo nội dung trong đó, cuối cùng đưa ra kết luận thử nghiệm.
Kết luận thử nghiệm hệ thống
Hệ thống chủ yếu sử dụng thử nghiệm hộp đen, thông qua mô phỏng người dùng sử dụng hệ thống để thực hiện các chức năng khác nhau, viết và thực hiện các ca thử nghiệm để đảm bảo quy trình hệ thống chính xác. Thử nghiệm hệ thống là bước không thể thiếu, giúp hệ thống hoàn thiện hơn và tăng tính sử dụng.
Thử nghiệm hệ thống nhằm mục đích xác minh các module chức năng có đáp ứng thiết kế ban đầu hay không, kiểm tra logic của từng module chức năng có chính xác không. Hệ thống không yêu cầu xử lý logic quá phức tạp để thuận tiện cho người dùng thao tác.