From d495ab4c732aa47c884fc2de733ddbde937e1365 Mon Sep 17 00:00:00 2001 From: lucas Date: Sun, 1 Nov 2026 17:29:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=B7=A8=E6=9C=88=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=20=E6=95=B0=E6=8D=AE=E5=8F=AF=E8=83=BD=E5=8D=A1?= =?UTF-8?q?=E4=BD=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumers/consumerSinoGnssMySQL.go | 31 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/consumers/consumerSinoGnssMySQL.go b/consumers/consumerSinoGnssMySQL.go index 07c064a..bb77d08 100644 --- a/consumers/consumerSinoGnssMySQL.go +++ b/consumers/consumerSinoGnssMySQL.go @@ -90,16 +90,33 @@ func (the *consumerSinoGnssMySQL) onData() { log.Printf("读取 缓存异常,err=%v", err.Error()) return } + // 先切换月表,避免旧表查空或查询失败后一直无法切表。 + newTableName := tableNameNow() + if recordInfo.TableName != newTableName { + log.Printf("跨月切表: %s => %s, id重置为0", recordInfo.TableName, newTableName) + recordInfo.TableName = newTableName + recordInfo.Id = 0 + cacheStr, _ := json.Marshal(recordInfo) + if err := utils.SaveCache2File(string(cacheStr), "cache.inout"); err != nil { + log.Printf("保存跨月游标失败: %v", err) + return + } + } sql := fmt.Sprintf(`select d.id,d.station_name,p.group_name,d.time,d.x,d.y,d.h from %s as d LEFT JOIN datasolution as p ON d.station_name=p.sn where p.group_name is not null -and d.id > %d and d.id <= %d -ORDER BY p.group_name;`, recordInfo.TableName, recordInfo.Id, recordInfo.Id+200) +and d.id > %d +ORDER BY d.id +LIMIT 200;`, recordInfo.TableName, recordInfo.Id) var GnssDatas []SinoGnssMySQL.GnssData err = the.InDB.Query(&GnssDatas, sql) - if err != nil || len(GnssDatas) == 0 { - log.Printf("当前批次无数据,跳过") + if err != nil { + log.Printf("查询GNSS数据失败, table=%s, id=%d, err=%v", recordInfo.TableName, recordInfo.Id, err) + return + } + if len(GnssDatas) == 0 { + log.Printf("当前批次无数据, table=%s, id=%d", recordInfo.TableName, recordInfo.Id) return } maxId := MaxId(GnssDatas) @@ -111,12 +128,6 @@ ORDER BY p.group_name;`, recordInfo.TableName, recordInfo.Id, recordInfo.Id+200) the.ch <- needPush } fileName := "cache.inout" - //发现新月新纪录 - newTableName := tableNameNow() - if recordInfo.TableName != newTableName { - recordInfo.TableName = newTableName - recordInfo.Id = 0 - } cacheStr, _ := json.Marshal(recordInfo) err = utils.SaveCache2File(string(cacheStr), fileName) if err != nil {