feat(device): 增加设备信息持久化和OTA升级功能

- 新增设备持久化定时任务,每5分钟将Redis中采集的设备信息同步数据库
- 新增UserDevice和UserActive模型及相应数据库表和操作接口
- 设备信息上报中获取客户端公网IP,替代原X-Forwarded-For头部
- 新建OTA功能模块,实现OTA固件升级信息查询接口
- 支持OTA黑名单过滤与定向升级设备判断
- 设计OTA相关数据库结构:ota、black_list、ota_target_device表
- 缓存预热新增按品牌分组预热型号缓存
- 依赖注入新增OTA Repository及Handler路由配置
- 实现客户端公网IP提取逻辑,支持多种代理头部优先级识别
This commit is contained in:
yangy
2026-05-28 18:26:20 +08:00
parent b2c11adeba
commit f3e3e82f52
16 changed files with 1078 additions and 9 deletions
+6 -8
View File
@@ -7,6 +7,7 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/luxsin/app-api/pkg/encode"
"github.com/redis/go-redis/v9"
"go.uber.org/zap"
)
@@ -27,7 +28,7 @@ func (h *DeviceHandler) ReportDevInfo(c *gin.Context) {
mac := strings.TrimSpace(c.Query("mac"))
model := strings.TrimSpace(c.Query("model"))
ver := strings.TrimSpace(c.Query("ver"))
xForwardedFor := c.GetHeader("X-Forwarded-For")
clientIP := encode.ClientPublicIP(c)
if mac == "" || model == "" {
c.JSON(http.StatusOK, gin.H{
@@ -40,20 +41,17 @@ func (h *DeviceHandler) ReportDevInfo(c *gin.Context) {
if ver == "" {
ver = ""
}
if xForwardedFor == "" {
xForwardedFor = ""
}
h.log.Info("report dev info",
zap.String("remote_ip", xForwardedFor),
zap.String("time", time.Now().Format("yyyy-MM-dd HH:mm:ss")),
zap.String("remote_ip", clientIP),
zap.String("time", time.Now().Format("2006-01-02 15:04:05")),
)
deviceInfo := map[string]string{
"mac_addr": mac,
"model": model,
"active_date": time.Now().Format("yyyy-MM-dd"),
"ip_addr": xForwardedFor,
"active_date": time.Now().Format("2006-01-02"),
"ip_addr": clientIP,
"ver": ver,
}