|
5 | 5 | "shadmin/domain" |
6 | 6 | "shadmin/ent" |
7 | 7 | "shadmin/ent/loginlog" |
| 8 | + "shadmin/ent/predicate" |
8 | 9 | ) |
9 | 10 |
|
10 | 11 | // Helper function to convert domain status string to ent status enum |
@@ -62,29 +63,30 @@ func (lr *entLoginLogRepository) Create(c context.Context, log *domain.LoginLog) |
62 | 63 |
|
63 | 64 | func (lr *entLoginLogRepository) Query(c context.Context, filter domain.LoginLogQueryFilter) (*domain.LoginLogPagedResult, error) { |
64 | 65 | // 构建基础查询 |
65 | | - baseQuery := lr.client.LoginLog.Query() |
66 | | - |
| 66 | + // 构建查询条件 |
| 67 | + var predicates []predicate.LoginLog |
67 | 68 | if filter.Username != "" { |
68 | | - baseQuery = baseQuery.Where(loginlog.UsernameContains(filter.Username)) |
| 69 | + predicates = append(predicates, loginlog.UsernameContains(filter.Username)) |
69 | 70 | } |
70 | 71 | if filter.LoginIP != "" { |
71 | | - baseQuery = baseQuery.Where(loginlog.LoginIPContains(filter.LoginIP)) |
| 72 | + predicates = append(predicates, loginlog.LoginIPContains(filter.LoginIP)) |
72 | 73 | } |
73 | 74 | if filter.Status != "" { |
74 | | - baseQuery = baseQuery.Where(loginlog.StatusEQ(domainStatusToEntLoginLogStatus(filter.Status))) |
| 75 | + predicates = append(predicates, loginlog.StatusEQ(domainStatusToEntLoginLogStatus(filter.Status))) |
75 | 76 | } |
76 | 77 | if filter.Browser != "" { |
77 | | - baseQuery = baseQuery.Where(loginlog.BrowserContains(filter.Browser)) |
| 78 | + predicates = append(predicates, loginlog.BrowserContains(filter.Browser)) |
78 | 79 | } |
79 | 80 | if filter.OS != "" { |
80 | | - baseQuery = baseQuery.Where(loginlog.OsContains(filter.OS)) |
| 81 | + predicates = append(predicates, loginlog.OsContains(filter.OS)) |
81 | 82 | } |
82 | 83 | if filter.StartTime != nil { |
83 | | - baseQuery = baseQuery.Where(loginlog.LoginTimeGTE(*filter.StartTime)) |
| 84 | + predicates = append(predicates, loginlog.LoginTimeGTE(*filter.StartTime)) |
84 | 85 | } |
85 | 86 | if filter.EndTime != nil { |
86 | | - baseQuery = baseQuery.Where(loginlog.LoginTimeLTE(*filter.EndTime)) |
| 87 | + predicates = append(predicates, loginlog.LoginTimeLTE(*filter.EndTime)) |
87 | 88 | } |
| 89 | + baseQuery := lr.client.LoginLog.Query().Where(predicates...) |
88 | 90 |
|
89 | 91 | // 获取总数 |
90 | 92 | total, err := baseQuery.Clone().Count(c) |
|
0 commit comments