- 新增 03-02-SUMMARY.md,记录 updateDeviceFromSyncInfo 实现细节 - STATE.md:Phase 3 完成标记,追加 DEVICE-04 决策,Next Action 更新为 Phase 4 - ROADMAP.md:Phase 3 进度更新为 Complete(2/2 plans) - REQUIREMENTS.md:DEVICE-04 标记完成
3.7 KiB
3.7 KiB
phase, plan, subsystem, tags, dependency_graph, tech_stack, key_files, decisions, metrics
| phase | plan | subsystem | tags | dependency_graph | tech_stack | key_files | decisions | metrics | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 03-device-system | 02 | device |
|
|
|
|
|
|
Phase 03 Plan 02: Gateway sync-info 接入 Refresh 流程 Summary
一句话总结: 在设备 Refresh 流程末尾接入 Gateway SyncDeviceInfo,通过 updateDeviceFromSyncInfo 原子更新在线状态、固件版本等 5 个设备字段及 is_current 当前卡标识(DEVICE-04)。
Tasks Completed
| Task | Name | Commit | Files |
|---|---|---|---|
| 1 | DeviceSimBindingStore 新增 UpdateIsCurrentByDeviceID 方法 | ba1886c |
device_sim_binding_store.go |
| 2 | Asset Service 注入 gatewayClient + 实现 updateDeviceFromSyncInfo + Refresh 接入 sync-info | 15dbf8d |
service.go, services.go |
Artifacts Delivered
Store 层
- UpdateIsCurrentByDeviceID:事务两步原子更新。第一步将设备所有活跃绑定的
is_current清为 false;第二步通过子查询定位current_iccid对应的iot_card_id,将该绑定设为is_current = true。currentIccid为空时仅清空。
Service 层
- Service 结构体:新增
gatewayClient *gateway.Client字段(允许 nil) - New() 构造函数:新增
gatewayClient *gateway.Client参数 - Refresh device 分支:在设置冷却 Key 之后、
GetRealtimeStatus返回之前,增加 sync-info 调用逻辑(nil guard 保护,失败只记 Warn 日志) - updateDeviceFromSyncInfo 私有函数:
- 解析
last_online_time(ISO 8601 →*time.Time,time.RFC3339) - GORM Updates 更新 5 个字段:
online_status、software_version、switch_mode、last_gateway_sync_at、last_online_time(非空时) - 调用
UpdateIsCurrentByDeviceID原子更新is_current
- 解析
Bootstrap 层
- services.go:
asset.New()调用末尾追加deps.GatewayClient参数
Deviations from Plan
None — 计划完全按预期执行。
Verification
- ✅
go build ./...零新增编译错误 - ✅
updateDeviceFromSyncInfo方法存在于internal/service/asset/service.go - ✅
Refreshdevice 分支含gatewayClient.SyncDeviceInfo()调用(nil guard + Warn 日志) - ✅
UpdateIsCurrentByDeviceID存在于internal/store/postgres/device_sim_binding_store.go - ✅
internal/bootstrap/services.goasset.New() 传入了deps.GatewayClient - ✅ sync-info 失败时只记录 Warn,不影响 Refresh 主流程