updated hierarchy select
This commit is contained in:
parent
d4309ecf73
commit
3ed876fe2d
|
|
@ -236,6 +236,7 @@ func (u *UserHierarchyDB) GetApproversDB(ctx context.Context, subordinateID, dep
|
|||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (u *UserHierarchyDB) GetHierarchiesWithRelations(ctx context.Context, opts typescore.ListDbOptions) ([]*typescore.UserHierarchy, uint64, error) {
|
||||
options, filter, err := dbutils.GetOptionsDB[typescore.UserHierarchy](opts)
|
||||
if err != nil {
|
||||
|
|
@ -243,7 +244,6 @@ func (u *UserHierarchyDB) GetHierarchiesWithRelations(ctx context.Context, opts
|
|||
}
|
||||
|
||||
query := squirrel.Select(
|
||||
// Основные поля таблицы user_hierarchy (в порядке сканирования)
|
||||
"uh.id",
|
||||
"uh.subordinate_id",
|
||||
"uh.approver_id",
|
||||
|
|
@ -253,25 +253,13 @@ func (u *UserHierarchyDB) GetHierarchiesWithRelations(ctx context.Context, opts
|
|||
"uh.priority",
|
||||
"uh.created_at",
|
||||
"uh.updated_at",
|
||||
// Поля Subordinate
|
||||
"sub.id",
|
||||
"sub.full_name",
|
||||
"sub.username",
|
||||
// Поля Approver
|
||||
"app.id",
|
||||
"app.full_name",
|
||||
"app.username",
|
||||
// Поля Department
|
||||
"dep.id",
|
||||
"dep.name",
|
||||
// Поля Category
|
||||
"cat.id",
|
||||
"cat.name",
|
||||
// Поля Topic
|
||||
"top.id",
|
||||
"top.name",
|
||||
// Общее количество записей для пагинации
|
||||
"COUNT(*) OVER() AS total_count").
|
||||
"sub.id", "sub.full_name", "sub.username",
|
||||
"app.id", "app.full_name", "app.username",
|
||||
"dep.id", "dep.name",
|
||||
"cat.id", "cat.name",
|
||||
"top.id", "top.name",
|
||||
"COUNT(*) OVER() AS total_count",
|
||||
).
|
||||
From("user_hierarchy uh").
|
||||
LeftJoin("users sub ON uh.subordinate_id = sub.id").
|
||||
LeftJoin("users app ON uh.approver_id = app.id").
|
||||
|
|
@ -280,7 +268,24 @@ func (u *UserHierarchyDB) GetHierarchiesWithRelations(ctx context.Context, opts
|
|||
LeftJoin("approval_topics top ON uh.topic_id = top.id")
|
||||
|
||||
query = dbutils.SetterLimitAndOffsetQuery(query, options.Offset, options.Limit)
|
||||
query = dbutils.ApplyFilters(query, filter, options.LikeFields, "uh")
|
||||
|
||||
// Явная обработка фильтров
|
||||
if filter.SubordinateID != nil {
|
||||
query = query.Where(squirrel.Eq{"uh.subordinate_id": *filter.SubordinateID})
|
||||
}
|
||||
if filter.ApproverID != nil {
|
||||
query = query.Where(squirrel.Eq{"uh.approver_id": *filter.ApproverID})
|
||||
}
|
||||
if filter.DepartmentID != nil {
|
||||
query = query.Where(squirrel.Eq{"uh.department_id": *filter.DepartmentID})
|
||||
}
|
||||
if filter.TopicCategoryID != nil {
|
||||
query = query.Where(squirrel.Eq{"uh.topic_category_id": *filter.TopicCategoryID})
|
||||
}
|
||||
if filter.TopicID != nil {
|
||||
query = query.Where(squirrel.Eq{"uh.topic_id": *filter.TopicID})
|
||||
}
|
||||
|
||||
query = query.OrderBy("uh.created_at DESC")
|
||||
|
||||
sql, args, err := query.PlaceholderFormat(squirrel.Dollar).ToSql()
|
||||
|
|
@ -306,34 +311,13 @@ func (u *UserHierarchyDB) GetHierarchiesWithRelations(ctx context.Context, opts
|
|||
h.Topic = &typescore.ApprovalTopic{}
|
||||
|
||||
err := rows.Scan(
|
||||
// Основные поля (9 полей)
|
||||
&h.ID,
|
||||
&h.SubordinateID,
|
||||
&h.ApproverID,
|
||||
&h.DepartmentID,
|
||||
&h.TopicCategoryID,
|
||||
&h.TopicID,
|
||||
&h.Priority,
|
||||
&h.CreatedAt,
|
||||
&h.UpdatedAt,
|
||||
// Subordinate (3 поля)
|
||||
&h.Subordinate.ID,
|
||||
&h.Subordinate.FullName,
|
||||
&h.Subordinate.Username,
|
||||
// Approver (3 поля)
|
||||
&h.Approver.ID,
|
||||
&h.Approver.FullName,
|
||||
&h.Approver.Username,
|
||||
// Department (2 поля)
|
||||
&h.Department.ID,
|
||||
&h.Department.Name,
|
||||
// TopicCategory (2 поля)
|
||||
&h.TopicCategory.ID,
|
||||
&h.TopicCategory.Name,
|
||||
// Topic (2 поля)
|
||||
&h.Topic.ID,
|
||||
&h.Topic.Name,
|
||||
// Общее количество
|
||||
&h.ID, &h.SubordinateID, &h.ApproverID, &h.DepartmentID,
|
||||
&h.TopicCategoryID, &h.TopicID, &h.Priority, &h.CreatedAt, &h.UpdatedAt,
|
||||
&h.Subordinate.ID, &h.Subordinate.FullName, &h.Subordinate.Username,
|
||||
&h.Approver.ID, &h.Approver.FullName, &h.Approver.Username,
|
||||
&h.Department.ID, &h.Department.Name,
|
||||
&h.TopicCategory.ID, &h.TopicCategory.Name,
|
||||
&h.Topic.ID, &h.Topic.Name,
|
||||
&totalCount,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue