fix/status-review-sync-20260409 #1

Merged
long merged 65 commits from fix/status-review-sync-20260409 into main 2026-04-18 15:05:51 +00:00
2 changed files with 8 additions and 4 deletions
Showing only changes of commit 32a3d4c9e0 - Show all commits

View File

@@ -275,8 +275,9 @@ func (r *DeviceRepository) ListAllCursor(ctx context.Context, params *ListDevice
query = query.Where("is_trusted = ?", *params.IsTrusted)
}
if params.Keyword != "" {
search := "%" + params.Keyword + "%"
query = query.Where("device_name LIKE ? OR ip LIKE ? OR location LIKE ?", search, search, search)
escapedKeyword := escapeLikePattern(params.Keyword)
pattern := "%" + escapedKeyword + "%"
query = query.Where("device_name LIKE ? ESCAPE '\\' OR ip LIKE ? ESCAPE '\\' OR location LIKE ? ESCAPE '\\'", pattern, pattern, pattern)
}
// Apply cursor condition for keyset navigation

View File

@@ -101,9 +101,12 @@ func (r *OperationLogRepository) DeleteOlderThan(ctx context.Context, days int)
func (r *OperationLogRepository) Search(ctx context.Context, keyword string, offset, limit int) ([]*domain.OperationLog, int64, error) {
var logs []*domain.OperationLog
var total int64
// 转义 LIKE 特殊字符,防止搜索被意外干扰
escapedKeyword := escapeLikePattern(keyword)
pattern := "%" + escapedKeyword + "%"
query := r.db.WithContext(ctx).Model(&domain.OperationLog{}).
Where("operation_name LIKE ? OR request_path LIKE ? OR operation_type LIKE ?",
"%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
Where("operation_name LIKE ? ESCAPE '\\' OR request_path LIKE ? ESCAPE '\\' OR operation_type LIKE ? ESCAPE '\\'",
pattern, pattern, pattern)
if err := query.Count(&total).Error; err != nil {
return nil, 0, err
}