# 农机保养周期功能说明 ## 📋 功能概述 为农机全生命周期档案新增了**保养周期**字段,支持按天、月、年设置设备的保养周期,用于自动提醒和维护计划管理。 ## 🎯 更新内容 ### 1. 类型定义更新 (`/types/machinery.ts`) 在 `MachineryRecord` 接口中新增了保养周期相关字段: ```typescript export interface MachineryRecord { // ... 其他字段 // 保养信息 maintenanceCycle?: number; // 保养周期数值 maintenanceCycleUnit?: 'day' | 'month' | 'year'; // 保养周期单位 // ... 其他字段 } ``` **字段说明:** - `maintenanceCycle`: 保养周期数值(可选,正整数) - `maintenanceCycleUnit`: 保养周期单位(可选,'day' | 'month' | 'year') - `day`: 天 - `month`: 月 - `year`: 年 ### 2. 表单组件更新 (`/components/machinery/MachineryForm.tsx`) 在基本信息标签页中添加了保养周期输入区域: ```tsx {/* 保养周期 */}

设置设备的保养周期,用于自动提醒

``` **功能特点:** - ✅ 数字输入框,最小值为1 - ✅ 下拉选择单位(天/月/年) - ✅ 默认单位为"月" - ✅ 提供友好的提示文本 ### 3. 详情组件更新 (`/components/machinery/MachineryDetails.tsx`) 在农机详情的"使用信息"部分显示保养周期: ```tsx // 格式化保养周期 const formatMaintenanceCycle = () => { if (!machinery.maintenanceCycle) return '-'; const unitMap = { day: '天', month: '月', year: '年' }; const unit = machinery.maintenanceCycleUnit || 'month'; return `${machinery.maintenanceCycle} ${unitMap[unit]}`; }; // 在使用信息中显示 ``` **显示效果:** - 3月 → "3 月" - 50天 → "50 天" - 1年 → "1 年" - 未设置 → "-" ### 4. 变更追踪更新 (`/lib/changeTracker.ts`) 添加了保养周期字段的变更追踪: ```typescript export const FIELD_LABELS: Record = { // ... 其他字段 // 保养信息 maintenanceCycle: '保养周期', maintenanceCycleUnit: '保养周期单位', // ... 其他字段 }; // 格式化保养周期单位显示 if (fieldName === 'maintenanceCycleUnit') { const unitMap: Record = { day: '天', month: '月', year: '年' }; return unitMap[value] || String(value); } ``` **变更历史示例:** ``` 字段: 保养周期 修改前: 3 修改后: 6 操作人: 系统管理员 时间: 2025-10-16 10:30:00 字段: 保养周期单位 修改前: 月 修改后: 天 操作人: 系统管理员 时间: 2025-10-16 10:30:15 ``` ### 5. 示例数据更新 (`/lib/mockData.ts`) 为所有示例农机添加了保养周期数据: | 设备名称 | 保养周期 | 周期单位 | 说明 | |---------|---------|---------|------| | 约翰迪尔拖拉机 | 3 | 月 | 大型耕地机械,季度保养 | | 久保田收割机 | 50 | 天 | 收获机械,作业季频繁保养 | | 丰疆播种机 | 1 | 月 | 精密播种设备,月度保养 | | 大疆植保无人机 | 15 | 天 | 高频使用设备,半月保养 | | 雷沃拖拉机 | 6 | 月 | 大型机械,半年保养 | ## 📝 使用场景 ### 1. 新增农机时设置保养周期 ``` 步骤: 1. 点击"新增农机"按钮 2. 填写基本信息 3. 在"保养周期"字段输入数值(如:3) 4. 选择单位(如:月) 5. 保存 ``` ### 2. 编辑农机时修改保养周期 ``` 步骤: 1. 在农机列表点击"编辑" 2. 修改保养周期数值或单位 3. 保存 4. 系统自动记录变更历史 ``` ### 3. 查看农机详情中的保养周期 ``` 步骤: 1. 点击农机卡片查看详情 2. 在"档案信息"标签页 3. "使用信息"部分查看保养周期 ``` ### 4. 追踪保养周期的变更历史 ``` 步骤: 1. 打开农机详情 2. 切换到"变更历史"标签 3. 筛选或查找"保养周期"相关变更 4. 查看修改记录和操作人 ``` ## 🎨 界面展示 ### 新增/编辑表单 ``` ┌─────────────────────────────────────────────┐ │ 保养周期 │ ├─────────────────────────────────────────────┤ │ ┌────────────────────┐ ┌──────────────┐ │ │ │ 输入周期 │ │ 月 ▼ │ │ │ │ 3 │ │ │ │ │ └────────────────────┘ └──────────────┘ │ │ 设置设备的保养周期,用于自动提醒 │ └─────────────────────────────────────────────┘ ``` ### 详情页显示 ``` ┌─────────────────────────────────────────────┐ │ 使用信息 │ ├─────────────────────────────────────────────┤ │ 设备状态 正常 │ │ 当前位置 1号地块 │ │ 保养周期 3 月 │ │ 创建时间 2024/04/01 │ │ 创建人 系统管理员 │ └─────────────────────────────────────────────┘ ``` ## 💡 应用价值 ### 1. 维护提醒 根据保养周期自动计算下次维护时间: ```typescript // 计算下次保养日期 function calculateNextMaintenance( lastMaintenanceDate: Date, cycle: number, unit: 'day' | 'month' | 'year' ): Date { const next = new Date(lastMaintenanceDate); switch (unit) { case 'day': next.setDate(next.getDate() + cycle); break; case 'month': next.setMonth(next.getMonth() + cycle); break; case 'year': next.setFullYear(next.getFullYear() + cycle); break; } return next; } ``` ### 2. 维护计划 基于保养周期生成维护计划: ```typescript // 生成年度维护计划 function generateMaintenancePlan( machinery: MachineryRecord, startDate: Date, endDate: Date ): Date[] { if (!machinery.maintenanceCycle || !machinery.maintenanceCycleUnit) { return []; } const plan: Date[] = []; let currentDate = new Date(startDate); while (currentDate <= endDate) { plan.push(new Date(currentDate)); currentDate = calculateNextMaintenance( currentDate, machinery.maintenanceCycle, machinery.maintenanceCycleUnit ); } return plan; } ``` ### 3. 成本预测 根据保养周期预测年度维护成本: ```typescript // 预测年度维护成本 function predictAnnualMaintenanceCost( machinery: MachineryRecord, avgCostPerMaintenance: number ): number { if (!machinery.maintenanceCycle || !machinery.maintenanceCycleUnit) { return 0; } // 转换为年度维护次数 let timesPerYear = 0; switch (machinery.maintenanceCycleUnit) { case 'day': timesPerYear = 365 / machinery.maintenanceCycle; break; case 'month': timesPerYear = 12 / machinery.maintenanceCycle; break; case 'year': timesPerYear = 1 / machinery.maintenanceCycle; break; } return Math.round(timesPerYear * avgCostPerMaintenance); } ``` ### 4. 到期提醒 提前提醒即将到期的保养: ```typescript // 获取需要提醒的设备 function getMaintenanceReminders( machineryList: MachineryRecord[], daysBeforeReminder: number = 7 ): MachineryRecord[] { const reminders: MachineryRecord[] = []; const now = new Date(); machineryList.forEach(machinery => { if (!machinery.maintenanceCycle || !machinery.maintenanceCycleUnit) { return; } // 获取最后一次维护记录 const lastMaintenance = getLastMaintenanceRecord(machinery.id); if (!lastMaintenance) return; // 计算下次维护日期 const nextDate = calculateNextMaintenance( new Date(lastMaintenance.endTime), machinery.maintenanceCycle, machinery.maintenanceCycleUnit ); // 检查是否需要提醒 const daysUntilMaintenance = Math.floor( (nextDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24) ); if (daysUntilMaintenance <= daysBeforeReminder && daysUntilMaintenance >= 0) { reminders.push(machinery); } }); return reminders; } ``` ## 📊 数据示例 ### 不同类型设备的保养周期建议 | 设备类型 | 建议周期 | 单位 | 说明 | |---------|---------|------|------| | 大型拖拉机 | 3-6 | 月 | 根据使用强度调整 | | 收割机 | 30-60 | 天 | 作业季节加密保养 | | 播种机 | 1-2 | 月 | 精密设备需频繁检查 | | 植保无人机 | 7-15 | 天 | 高频使用,短周期保养 | | 灌溉设备 | 3-6 | 月 | 根据灌溉季节调整 | | 运输车辆 | 1-3 | 月 | 参照车辆保养标准 | ### 保养周期与维护成本的关系 ``` 周期越短 → 维护次数越多 → 单次成本低 → 总成本可能高 周期适中 → 维护次数适当 → 预防性保养 → 总成本最优 周期过长 → 维护次数少 → 故障率高 → 维修成本高 ``` ## ✅ 最佳实践 ### 1. 设置保养周期的原则 ``` ✅ 参考厂家建议的保养周期 ✅ 结合实际使用强度调整 ✅ 考虑作业环境和条件 ✅ 新设备前期适当缩短周期 ✅ 定期评估并优化周期设置 ``` ### 2. 周期单位的选择 ``` 选择"天": - 高频使用设备(如无人机) - 需要每日或每周检查的设备 - 短期租赁或临时使用的设备 选择"月": - 大多数农机设备 - 平衡维护成本和设备可靠性 - 便于制定月度维护计划 选择"年": - 使用频率低的设备 - 年度大修或年检 - 长期存放的备用设备 ``` ### 3. 与维护记录的配合 ``` 记录维护时: 1. 检查当前保养周期是否合理 2. 根据设备状况调整周期 3. 在维护记录中注明调整原因 4. 更新保养周期设置 下次维护时间: 1. 在维护记录中设置下次维护时间 2. 系统根据保养周期自动计算 3. 结合实际情况手动微调 4. 提前7天发送提醒 ``` ## 🔄 未来扩展 ### 1. 智能推荐 ```typescript // 基于历史数据推荐最优保养周期 function recommendMaintenanceCycle( machineryId: string ): { cycle: number; unit: 'day' | 'month' | 'year' } { const records = getMaintenanceRecords(machineryId); // 分析维护间隔 // 计算故障率 // 评估维护成本 // 推荐最优周期 return { cycle: 3, unit: 'month' }; } ``` ### 2. 动态调整 ```typescript // 根据使用情况动态调整周期 function adjustMaintenanceCycle( machinery: MachineryRecord, usageIntensity: number ): void { // usageIntensity: 0-1之间,表示使用强度 const baseCycle = machinery.maintenanceCycle || 3; const adjustedCycle = Math.max(1, Math.round(baseCycle * (1 - usageIntensity * 0.5))); // 更新保养周期 updateMachinery(machinery.id, { maintenanceCycle: adjustedCycle }); } ``` ### 3. 维护提醒系统 ```typescript // 完整的维护提醒系统 interface MaintenanceReminder { machineryId: string; machineryName: string; nextMaintenanceDate: Date; daysRemaining: number; urgency: 'normal' | 'warning' | 'urgent'; } function getMaintenanceRemindersList(): MaintenanceReminder[] { // 获取所有设备 // 计算下次维护日期 // 计算剩余天数 // 判断紧急程度 // 返回提醒列表 } ``` ## 📋 总结 保养周期功能的添加为农机管理系统带来了: 1. **更科学的维护管理** - 明确的保养计划 - 规范的维护周期 - 系统的提醒机制 2. **更精准的成本控制** - 预测维护成本 - 优化保养周期 - 降低故障率 3. **更完整的数据追溯** - 记录周期变更 - 分析优化效果 - 持续改进管理 该功能与现有的维护记录、变更历史等功能完美结合,形成了完整的农机全生命周期管理体系。 --- **更新时间**: 2025年10月16日 **版本**: 1.0.0 **状态**: ✅ 已完成