feat: update order s

This commit is contained in:
yanghao05
2025-04-18 22:55:37 +08:00
parent 6ca359ec1e
commit 75bbca00cf
4 changed files with 111 additions and 16 deletions

View File

@@ -256,3 +256,30 @@ func (m *usersModel) GetUserByOpenID(ctx context.Context, openID string) (*model
return &user, nil
}
// GetUsersMapByIDs
func (m *usersModel) GetUsersMapByIDs(ctx context.Context, ids []int64) (map[int64]model.Users, error) {
if len(ids) == 0 {
return nil, nil
}
tbl := table.Users
stmt := tbl.
SELECT(tbl.AllColumns).
WHERE(
tbl.ID.IN(lo.Map(ids, func(id int64, _ int) Expression { return Int64(id) })...),
)
m.log.Infof("sql: %s", stmt.DebugSql())
var users []model.Users = make([]model.Users, 0)
err := stmt.QueryContext(ctx, db, &users)
if err != nil {
m.log.Errorf("error querying users: %v", err)
return nil, err
}
return lo.SliceToMap(users, func(item model.Users) (int64, model.Users) {
return item.ID, item
}), nil
}