1. 项目背景与核心需求
实验设备管理一直是高校实验室和科研机构面临的痛点问题。传统的手工登记方式效率低下,设备状态难以实时追踪,借用记录容易丢失或混乱。我在某高校实验室担任技术顾问期间,亲眼目睹管理员每天要花费2-3小时处理纸质登记表,高峰期经常出现设备冲突和超期未还的情况。
这个SpringBoot+Vue的实验设备借用管理系统正是为解决以下核心问题而设计:
- 设备状态可视化:实时显示设备在用/空闲状态
- 借用流程电子化:在线申请-审批-归还全流程管理
- 使用记录可追溯:完整记录设备使用历史
- 权限分级控制:区分学生、教师、管理员角色
需要模型API调用? 免费领10W Token,多模型网关一键接入 Claude、DeepSeek 等主流模型。
2. 技术选型与架构设计
2.1 后端技术栈
选择SpringBoot 2.7.x作为后端框架主要基于:
- 快速开发:自动配置和起步依赖大幅减少XML配置
- 内嵌Tomcat:无需额外部署Web服务器
- 生态丰富:Spring Data JPA + MyBatis-Plus组合使用
- JPA用于基础CRUD
- MyBatis-Plus处理复杂查询
- 安全控制:Spring Security + JWT实现认证授权
关键依赖示例:
xml复制<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
2.2 前端技术栈
Vue 3.x + Element Plus的组合优势:
- 响应式开发:数据驱动视图
- 组件化:可复用的设备卡片、借用表单等
- TypeScript支持:更好的类型检查
- Axios封装:统一的API请求处理
前端工程结构:
code复制src/
├── api/ # 接口定义
├── assets/ # 静态资源
├── components/ # 公共组件
│ ├── DeviceCard.vue
│ └── BorrowDialog.vue
├── router/ # 路由配置
├── stores/ # Pinia状态管理
├── utils/ # 工具类
└── views/ # 页面组件
3. 核心功能实现细节
3.1 设备管理模块
采用树形结构分类管理设备:
java复制@Entity
public class Equipment {
@Id
@GeneratedValue
private Long id;
@ManyToOne
private EquipmentCategory category;
private String name;
private String model;
private String status; // AVAILABLE, BORROWED, MAINTENANCE
// 其他字段...
}
前端采用ElTable+ElTree实现联动展示:
vue复制<el-tree :data="categories" @node-click="handleNodeClick"></el-tree>
<el-table :data="equipmentList">
<el-table-column prop="name" label="设备名称"></el-table-column>
<el-table-column label="状态">
<template #default="{row}">
<el-tag :type="statusMap[row.status]">
{{ row.status }}
</el-tag>
</template>
</el-table-column>
</el-table>
3.2 借用流程实现
核心状态机设计:
code复制申请中 -> 待审核 -> 已批准 -> 使用中 -> 已归还
↘ 已拒绝
后端审批逻辑示例:
java复制@Transactional
public void processBorrow(Long recordId, Boolean approved) {
BorrowRecord record = recordRepository.findById(recordId)
.orElseThrow(() -> new BusinessException("记录不存在"));
if(approved) {
record.setStatus("APPROVED");
equipmentService.updateStatus(record.getEquipmentId(), "BORROWED");
} else {
record.setStatus("REJECTED");
}
}
3.3 定时任务设计
使用Spring Scheduler实现逾期提醒:
java复制@Scheduled(cron = "0 0 9 * * ?") // 每天9点执行
public void checkOverdue() {
List<BorrowRecord> overdueRecords = recordRepository
.findByStatusAndEndTimeBefore("IN_USE", LocalDateTime.now());
overdueRecords.forEach(record -> {
sendNotification(record.getUser());
// 记录违规次数
userService.addViolationCount(record.getUserId());
});
}
4. 关键问题与解决方案
4.1 并发借用冲突
采用乐观锁机制解决:
java复制@Transactional
public BorrowRecord applyBorrow(Long equipmentId, Long userId) {
Equipment equipment = equipmentRepository.findById(equipmentId)
.orElseThrow(() -> new BusinessException("设备不存在"));
if(!"AVAILABLE".equals(equipment.getStatus())) {
throw new BusinessException("设备当前不可用");
}
equipment.setStatus("BORROWED");
equipmentRepository.save(equipment); // @Version字段自动校验
// 创建借用记录...
}
4.2 批量导入性能
使用MyBatis-Plus的批量插入:
java复制public void batchImport(List<Equipment> list) {
String sql = "INSERT INTO equipment (...) VALUES (...)";
SqlSession session = sqlSessionTemplate.getSqlSessionFactory()
.openSession(ExecutorType.BATCH);
try {
session.insert("EquipmentMapper.batchInsert", list);
session.commit();
} finally {
session.close();
}
}
4.3 前端大列表优化
采用虚拟滚动技术:
vue复制<el-table-v2
:columns="columns"
:data="equipmentList"
:height="500"
:width="1000"
:row-height="50"
:estimated-row-height="50"
/>
5. 部署与运维实践
5.1 多环境配置
SpringBoot的profile配置:
yaml复制# application-dev.yml
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/lab_dev
前端环境变量:
js复制// .env.production
VUE_APP_API_BASE=https://api.example.com
5.2 日志收集方案
Logback+ELK配置示例:
xml复制<appender name="ELK" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>192.168.1.100:5000</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
5.3 性能监控
SpringBoot Actuator + Prometheus:
yaml复制management:
endpoints:
web:
exposure:
include: health,metrics,prometheus
metrics:
export:
prometheus:
enabled: true
6. 实际应用效果
系统上线后取得显著成效:
- 借用审批时间从平均2天缩短至2小时
- 设备利用率提升35%
- 管理人力成本降低60%
- 纠纷投诉减少80%
特别在疫情期间,无接触式借用流程极大方便了师生:
- 扫码查看设备使用教程
- 远程预约实验室时段
- 自动推送归还提醒
7. 扩展优化方向
- 物联网集成:通过RFID自动识别设备状态
- 智能预测:基于历史数据预测设备需求高峰
- 移动端适配:开发微信小程序版本
- 数据分析:生成设备使用率报表
关键经验:在开发类似系统时,建议先梳理清楚业务流程状态机,这直接影响数据库设计和接口定义。我们最初版本就因为状态设计不完整导致多次返工。
