- 创建 03.1-01-SUMMARY.md:记录 3 个任务完成情况、6 个文件修改、SwitchMode 类型偏差修复 - 更新 STATE.md:追加执行日志、补充 B/C 端独立 DTO 结构决策
7.3 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.1-sync-info-phase-3-dto | 01 | asset/device |
|
|
|
|
|
|
Phase 03.1 Plan 01: 设备读取链路修复 + DTO 映射补全 Summary
一句话总结: 补全 Phase 3 设备数据写入链路的读取侧缺口——6 个字段映射缺口修复 + Gateway sync-info 实时调用链路建立 + C端 mock 数据替换。
完成的任务
Task 1:补全 Gateway 模型和 B 端 DTO 契约
internal/gateway/models.go(第 162-183 行):
SyncDeviceInfoResp 新增 15 个缺失字段:
- 信号:
Rsrp、Rsrq、Sinr - WiFi:
WifiPassword - 网络:
IPAddress、WANIP、LANIP - 连接:
MaxClients、ConnectTime - 设备:
Status、IMSI、ULStats、DLStats、LimitSpeed、SyncInterval
internal/model/dto/asset_dto.go:
- 新增
DeviceGatewayInfo结构体(第 138-188 行),49 字段,全部含descriptiontag(per D-08/D-09) AssetRealtimeStatusResponse新增DeviceRealtime *DeviceGatewayInfo字段(第 77 行)(per D-07/D-08)AssetResolveResponse新增 5 个设备 DB 缓存字段(第 44-49 行)(per D-12):OnlineStatus、LastOnlineTime、SoftwareVersion、SwitchMode、LastGatewaySyncAt
Task 2:修复静态 DTO 映射缺口
internal/service/device/service.go(toDeviceResponse(),第 559-563 行):
补全 5 个 DB 缓存字段赋值:
OnlineStatus: device.OnlineStatus,
LastOnlineTime: device.LastOnlineTime,
SoftwareVersion: device.SoftwareVersion,
SwitchMode: device.SwitchMode,
LastGatewaySyncAt: device.LastGatewaySyncAt,
internal/service/device/binding.go(ListBindings(),第 60 行):
IsCurrent: binding.IsCurrent,
internal/service/asset/service.go(两处修复):
buildDeviceResolveResponse()(第 124-128 行):新增isCurrentMap+IsCurrent+ 5 个 DB 缓存字段GetRealtimeStatus()device case(第 274-279 行):新增isCurrentMap+IsCurrent
两处均采用与现有 slotMap 同构的 isCurrentMap 模式:
isCurrentMap := make(map[uint]bool, len(bindings))
// ...
isCurrentMap[b.IotCardID] = b.IsCurrent
// ...
IsCurrent: isCurrentMap[c.ID],
Task 3:建立设备实时 Gateway 调用链路
internal/service/asset/service.go:
-
GetRealtimeStatus()device case 末尾(第 291-312 行)新增 Gateway 实时调用:gatewayClient != nil安全检查- IMEI 优先,无则用 SN(与 Refresh 逻辑一致)
- 调用
s.gatewayClient.SyncDeviceInfo(ctx, &gateway.SyncDeviceInfoReq{CardNo: cardNo}) - 成功时调用
mapSyncRespToDeviceGatewayInfo(syncResp)填充resp.DeviceRealtime - 失败时仅记录 Warn 日志,
DeviceRealtime保持 nil(per D-06)
-
新增
mapSyncRespToDeviceGatewayInfo()(第 330-369 行):Gateway resp → B端 DTO 映射 -
新增
strPtr()(第 371-378 行):辅助函数,将空字符串转为 nil 指针
internal/handler/app/client_asset.go:
-
GetAssetInfo()(第 188-197 行):删除buildMockDeviceRealtime()调用,替换为:realtimeResp, realtimeErr := h.assetService.GetRealtimeStatus( c.UserContext(), "device", resp.AssetID, ) if realtimeErr == nil && realtimeResp.DeviceRealtime != nil { resp.DeviceRealtime = mapDeviceGatewayInfoToClientInfo(realtimeResp.DeviceRealtime) } -
删除
buildMockDeviceRealtime()函数(原第 595-635 行) -
新增
mapDeviceGatewayInfoToClientInfo()(第 595-660 行):B端 DeviceGatewayInfo → C端 DeviceRealtimeInfo 映射
编译验证
go build ./... → 全量编译通过
go vet ./internal/gateway/... ./internal/model/dto/... ./internal/service/asset/... ./internal/service/device/... ./internal/handler/app/... → 无新增错误
Deviations from Plan
Auto-fixed Issues
1. [Rule 1 - Bug] SwitchMode 类型不匹配
- Found during: Task 3
- Issue: 计划中
mapDeviceGatewayInfoToClientInfo的SwitchMode转换代码为v := int(*g.SwitchMode),但g.SwitchMode是*string(B端 Gateway DTO 定义),DeviceRealtimeInfo.SwitchMode是*int(C端 DTO),直接转换会编译报错 - Fix: 使用
strconv.Atoi(*g.SwitchMode)进行字符串→整型安全转换,解析失败时忽略(SwitchMode保持 nil) - Files modified:
internal/handler/app/client_asset.go - Commit:
a202b2d
Self-Check: PASSED
| 检查项 | 结果 |
|---|---|
internal/gateway/models.go 存在 |
✅ FOUND |
internal/model/dto/asset_dto.go 存在 |
✅ FOUND |
internal/service/device/service.go 存在 |
✅ FOUND |
internal/service/device/binding.go 存在 |
✅ FOUND |
internal/service/asset/service.go 存在 |
✅ FOUND |
internal/handler/app/client_asset.go 存在 |
✅ FOUND |
提交 00dba42 存在 |
✅ FOUND |
提交 3b54850 存在 |
✅ FOUND |
提交 a202b2d 存在 |
✅ FOUND |
go build ./... 编译通过 |
✅ 通过 |