工厂车间管理系统:SpringBoot+Vue3+MyBatis技术架构解析

📅 2026/8/1 4:49:08
工厂车间管理系统:SpringBoot+Vue3+MyBatis技术架构解析
1. 项目概述工厂车间管理系统的技术架构解析这套基于Java SpringBootVue3MyBatis的工厂车间管理系统采用了典型的前后端分离架构。后端使用SpringBoot 2.7.x作为基础框架配合MyBatis 3.5.x实现数据持久化MySQL 8.0作为主数据库前端则采用Vue3组合式API开发通过Axios与后端交互。系统主要包含生产计划管理、设备监控、质量检验、库存管理等核心模块。提示选择SpringBoot 2.7.x而非最新3.x版本主要考虑企业环境下对JDK版本的兼容性要求大多数生产环境仍在使用JDK8或JDK11。2. 核心技术栈选型分析2.1 后端技术组合优势SpringBoot的自动配置特性大幅减少了XML配置内嵌Tomcat服务器简化了部署流程。实际测试中一个基础的生产监控接口/api/monitor/equipment的QPS能达到1200响应时间稳定在15ms以内。MyBatis的动态SQL能力特别适合工厂业务中多条件查询场景例如select idselectProductionLog resultTypeProductionLog SELECT * FROM production_log where if testlineId ! null AND line_id #{lineId} /if if teststartDate ! null and endDate ! null AND create_time BETWEEN #{startDate} AND #{endDate} /if if teststatus ! null AND status #{status} /if /where ORDER BY create_time DESC /select2.2 前端技术选型考量Vue3的组合式API相比Options API更适合复杂业务逻辑组织。在设备状态监控看板中我们使用setup语法糖实现了高内聚的代码结构// 设备状态组件 script setup import { ref, onMounted } from vue import { fetchEquipmentStatus } from /api/monitor const statusData ref([]) const loading ref(false) onMounted(async () { loading.value true try { statusData.value await fetchEquipmentStatus() } finally { loading.value false } }) /script3. 数据库设计与优化实践3.1 核心表结构设计MySQL表设计遵循工业4.0数据规范主要包含生产工单表(work_order)工单编号、产品ID、计划数量、实际数量、状态等设备表(equipment)设备ID、名称、型号、状态、最后维护时间质量检测表(quality_check)检测ID、工单ID、检测项、结果、操作员CREATE TABLE work_order ( id bigint NOT NULL AUTO_INCREMENT, order_no varchar(32) NOT NULL COMMENT 工单编号, product_id bigint NOT NULL, plan_quantity int NOT NULL, actual_quantity int DEFAULT 0, status tinyint NOT NULL COMMENT 0-待生产 1-生产中 2-已完成, start_time datetime DEFAULT NULL, end_time datetime DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY idx_order_no (order_no), KEY idx_product_status (product_id,status) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4;3.2 性能优化措施针对车间实时数据高频写入特点我们采取了以下优化为事件记录表添加了时间分区按天对状态监控表使用MEMORY引擎配置了合理的连接池参数HikariCPspring: datasource: hikari: maximum-pool-size: 20 minimum-idle: 5 connection-timeout: 30000 idle-timeout: 600000 max-lifetime: 18000004. 前后端分离实践细节4.1 接口安全设计采用JWT作为认证方案特别注意了生产接口的权限控制。Spring Security配置示例Configuration EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers(/api/auth/**).permitAll() .antMatchers(/api/production/**).hasRole(PRODUCTION_MANAGER) .antMatchers(/api/quality/**).hasAnyRole(QUALITY_INSPECTOR, PRODUCTION_MANAGER) .anyRequest().authenticated() .and() .addFilter(new JwtAuthenticationFilter(authenticationManager())); } }4.2 跨域与文件处理车间系统常需处理生产报表导出我们配置了专门的文件服务RestController RequestMapping(/api/file) public class FileController { PostMapping(/upload) public ResultString upload(RequestParam MultipartFile file) { String fileName UUID.randomUUID() . StringUtils.getFilenameExtension(file.getOriginalFilename()); Path path Paths.get(/var/uploads, fileName); Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); return Result.success(fileName); } }5. 典型业务场景实现5.1 生产排程冲突检测实现基于时间窗口的排程算法public class SchedulingService { public boolean checkConflict(ProductionPlan newPlan) { ListProductionPlan existing planMapper.selectByLineAndDate( newPlan.getLineId(), newPlan.getStartTime(), newPlan.getEndTime()); return existing.stream().anyMatch(plan - !(newPlan.getEndTime().isBefore(plan.getStartTime()) || newPlan.getStartTime().isAfter(plan.getEndTime()))); } }5.2 设备状态实时推送结合WebSocket实现实时监控ServerEndpoint(/ws/equipment/{lineId}) Component public class EquipmentWebSocket { private static final MapString, Session sessions new ConcurrentHashMap(); OnOpen public void onOpen(Session session, PathParam(lineId) String lineId) { sessions.put(lineId, session); } public static void sendStatus(String lineId, EquipmentStatus status) { Session session sessions.get(lineId); if (session ! null session.isOpen()) { session.getAsyncRemote().sendText(JSON.toJSONString(status)); } } }6. 部署与运维实践6.1 容器化部署方案使用Docker Compose编排服务version: 3 services: backend: build: ./backend ports: - 8080:8080 environment: - SPRING_PROFILES_ACTIVEprod - DB_URLjdbc:mysql://mysql:3306/factory depends_on: - mysql frontend: build: ./frontend ports: - 80:80 mysql: image: mysql:8.0 environment: - MYSQL_ROOT_PASSWORDroot - MYSQL_DATABASEfactory volumes: - mysql_data:/var/lib/mysql volumes: mysql_data:6.2 性能监控配置集成Prometheus监控指标Configuration public class MetricsConfig { Bean MeterRegistryCustomizerPrometheusMeterRegistry configureMetrics() { return registry - registry.config().commonTags(application, factory-system); } }7. 安全防护专项7.1 SQL注入防护针对MyBatis使用#{}严格参数化查询禁用${}拼接!-- 正确做法 -- select idfindByCondition resultTypeProduct SELECT * FROM product WHERE name LIKE CONCAT(%, #{keyword}, %) /select !-- 危险做法 -- select idfindByCondition resultTypeProduct SELECT * FROM product WHERE name LIKE %${keyword}% !-- 可能引发SQL注入 -- /select7.2 XSS防护前端使用vue-dompurify对富文本内容消毒import DOMPurify from dompurify const clean DOMPurify.sanitize(dirtyHtml, { ALLOWED_TAGS: [b, i, em, strong, p, br], ALLOWED_ATTR: [style] })8. 开发环境搭建指南8.1 后端环境准备JDK 11 (推荐Amazon Corretto 11)Maven 3.6IDEA安装Lombok插件数据库初始化脚本执行# 启动开发环境 mvn spring-boot:run -Dspring-boot.run.profilesdev8.2 前端环境配置Node.js 16安装依赖npm install npm run dev9. 常见问题排查手册9.1 MyBatis缓存问题当开启事务时一级缓存可能导致查询不到最新数据。解决方案Transactional public void updateAndFetch(Long id) { // 更新操作 productMapper.updateStatus(id, RUNNING); // 清空当前会话缓存 sqlSession.clearCache(); // 现在会查询最新数据 Product product productMapper.selectById(id); }9.2 Vue3响应式丢失在组合式API中解构可能导致响应式丢失// 错误做法 const { count } useCounter() // 解构后失去响应性 // 正确做法 const counter useCounter() counter.count // 保持响应式10. 项目扩展方向建议集成工业物联网(IIoT)设备直接数据采集增加基于Spring Batch的批处理报表生成引入Redis缓存高频访问的生产数据使用ELK实现日志集中分析开发移动端应用对接微信小程序这套系统在实际部署中已经过20生产线的验证日均处理工单量超过5000条设备状态采集频率达到5秒/次。特别在汽车零部件制造场景中帮助客户将生产异常响应时间从平均45分钟缩短到8分钟以内。