From 0187d2f5c118b124a7ce038e9b95d1da634271a9 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 1 Jun 2023 22:04:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ssh=20=E7=99=BB=E5=BD=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=97=B6=E5=8C=BA=E4=BF=AE=E6=94=B9=20(#1223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/ssh.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index 1c8853108..c07214070 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -6,7 +6,6 @@ import ( "os/user" "path" "path/filepath" - "sort" "strings" "time" @@ -252,24 +251,23 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { } } data.SuccessfulCount = data.TotalCount - data.FailedCount + if len(data.Logs) < 1 { + return nil, nil + } timeNow := time.Now() nyc, _ := time.LoadLocation(common.LoadTimeZone()) - qqWry, err := qqwry.NewQQwry() if err != nil { global.LOG.Errorf("load qqwry datas failed: %s", err) } - for i := 0; i < len(data.Logs); i++ { + var itemLogs []dto.SSHHistory + for i := len(data.Logs) - 1; i >= 0; i-- { data.Logs[i].Area = qqWry.Find(data.Logs[i].Address).Area data.Logs[i].Date, _ = time.ParseInLocation("2006 Jan 2 15:04:05", fmt.Sprintf("%d %s", timeNow.Year(), data.Logs[i].DateStr), nyc) - if data.Logs[i].Date.After(timeNow) { - data.Logs[i].Date = data.Logs[i].Date.AddDate(-1, 0, 0) - } + itemLogs = append(itemLogs, data.Logs[i]) } - sort.Slice(data.Logs, func(i, j int) bool { - return data.Logs[i].Date.After(data.Logs[j].Date) - }) + data.Logs = itemLogs var itemDatas []dto.SSHHistory total, start, end := len(data.Logs), (req.Page-1)*req.PageSize, req.Page*req.PageSize