| | |
| | | } |
| | | |
| | | func (c *Cache) Clean() error { |
| | | sql := "DELETE FROM caches WHERE id NOT IN (SELECT id FROM caches ORDER BY id DESC LIMIT 2000);" |
| | | sql := "DELETE FROM caches WHERE id NOT IN (SELECT id FROM caches ORDER BY id DESC LIMIT 15000);" |
| | | return db.Table(c.TableName()).Exec(sql).Error |
| | | } |
| | |
| | | |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/models" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | ) |
| | | |
| | |
| | | return nil |
| | | } |
| | | |
| | | if config.ForwardConf.ReportServer == "" { |
| | | return nil |
| | | } |
| | | |
| | | logger.Info("Start device report task, server:%s.", config.ForwardConf.ReportServer) |
| | | |
| | | var d models.Ape |
| | | devices, err := d.FindAll() |
| | | if err != nil { |
| | |
| | | // 级联的设备不检查心跳 |
| | | if dev.FromId == "" { |
| | | hTime, err := time.ParseInLocation("2006-01-02 15:04:05", dev.HeartbeatTime, time.Local) |
| | | if err != nil || hTime.Unix()+120 < time.Now().Unix() { |
| | | if err != nil { |
| | | dev.HeartbeatTime = time.Now().Format("2006-01-02 15:04:05") |
| | | dev.Ext.IsOnline = "1" |
| | | } else { |
| | | if hTime.Unix()+120 >= time.Now().Unix() { |
| | | dev.Ext.IsOnline = "1" |
| | | } else { |
| | | dev.Ext.IsOnline = "2" |
| | | } |
| | | } |
| | | |
| | | // 更新在线状态 |
| | | dev.Save() |
| | | |
| | | // 离线设备不执行上报 |
| | | if dev.Ext.IsOnline == "2" { |
| | | continue |
| | | } |
| | | } |
| | | |
| | | // 配置了上报地址, 推送数据 |
| | | if config.ForwardConf.ReportServer == "" { |
| | | continue |
| | | } |
| | | |
| | | device := DevReportData{ |
| | | Code: dev.Id, |
| | | Model: dev.Ext.Model, |