358 lines
		
	
	
		
			8.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			358 lines
		
	
	
		
			8.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Code generated by sqlc. DO NOT EDIT.
 | |
| // versions:
 | |
| //   sqlc v1.28.0
 | |
| // source: sys_department.sql
 | |
| 
 | |
| package db
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| const allSysDepartment = `-- name: AllSysDepartment :many
 | |
| SELECT id, name, parent_id, parent_path, status, sort, created_at, updated_at FROM sys_department 
 | |
| WHERE status = 0
 | |
| ORDER BY sort DESC
 | |
| `
 | |
| 
 | |
| func (q *Queries) AllSysDepartment(ctx context.Context) ([]*SysDepartment, error) {
 | |
| 	rows, err := q.db.Query(ctx, allSysDepartment)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*SysDepartment{}
 | |
| 	for rows.Next() {
 | |
| 		var i SysDepartment
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const countSysDepartmentCondition = `-- name: CountSysDepartmentCondition :one
 | |
| SELECT COUNT(*) FROM sys_department
 | |
| WHERE (NOT $1::Boolean OR status = $2)
 | |
|     AND (NOT $3::Boolean OR id = $4)
 | |
|     AND (NOT $5::Boolean OR parent_id = $6)
 | |
|     AND ($7::text = '' OR name ILIKE '%' || $7 || '%')
 | |
| `
 | |
| 
 | |
| type CountSysDepartmentConditionParams struct {
 | |
| 	IsStatus   bool   `json:"is_status"`
 | |
| 	Status     int32  `json:"status"`
 | |
| 	IsID       bool   `json:"is_id"`
 | |
| 	ID         int32  `json:"id"`
 | |
| 	IsParentID bool   `json:"is_parent_id"`
 | |
| 	ParentID   int32  `json:"parent_id"`
 | |
| 	Name       string `json:"name"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) CountSysDepartmentCondition(ctx context.Context, arg *CountSysDepartmentConditionParams) (int64, error) {
 | |
| 	row := q.db.QueryRow(ctx, countSysDepartmentCondition,
 | |
| 		arg.IsStatus,
 | |
| 		arg.Status,
 | |
| 		arg.IsID,
 | |
| 		arg.ID,
 | |
| 		arg.IsParentID,
 | |
| 		arg.ParentID,
 | |
| 		arg.Name,
 | |
| 	)
 | |
| 	var count int64
 | |
| 	err := row.Scan(&count)
 | |
| 	return count, err
 | |
| }
 | |
| 
 | |
| const createSysDepartment = `-- name: CreateSysDepartment :one
 | |
| INSERT INTO sys_department (
 | |
|   name,
 | |
|   parent_id,
 | |
|   parent_path,
 | |
|   status,
 | |
|   sort,
 | |
|   created_at,
 | |
|   updated_at
 | |
| ) VALUES (
 | |
|   $1, $2, $3, $4, $5, $6, $7
 | |
| ) RETURNING id, name, parent_id, parent_path, status, sort, created_at, updated_at
 | |
| `
 | |
| 
 | |
| type CreateSysDepartmentParams struct {
 | |
| 	Name       string    `json:"name"`
 | |
| 	ParentID   int32     `json:"parent_id"`
 | |
| 	ParentPath string    `json:"parent_path"`
 | |
| 	Status     int32     `json:"status"`
 | |
| 	Sort       int32     `json:"sort"`
 | |
| 	CreatedAt  time.Time `json:"created_at"`
 | |
| 	UpdatedAt  time.Time `json:"updated_at"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) CreateSysDepartment(ctx context.Context, arg *CreateSysDepartmentParams) (*SysDepartment, error) {
 | |
| 	row := q.db.QueryRow(ctx, createSysDepartment,
 | |
| 		arg.Name,
 | |
| 		arg.ParentID,
 | |
| 		arg.ParentPath,
 | |
| 		arg.Status,
 | |
| 		arg.Sort,
 | |
| 		arg.CreatedAt,
 | |
| 		arg.UpdatedAt,
 | |
| 	)
 | |
| 	var i SysDepartment
 | |
| 	err := row.Scan(
 | |
| 		&i.ID,
 | |
| 		&i.Name,
 | |
| 		&i.ParentID,
 | |
| 		&i.ParentPath,
 | |
| 		&i.Status,
 | |
| 		&i.Sort,
 | |
| 		&i.CreatedAt,
 | |
| 		&i.UpdatedAt,
 | |
| 	)
 | |
| 	return &i, err
 | |
| }
 | |
| 
 | |
| const existsSysDepartment = `-- name: ExistsSysDepartment :one
 | |
| SELECT EXISTS (
 | |
|     SELECT 1 FROM sys_department
 | |
| )
 | |
| `
 | |
| 
 | |
| func (q *Queries) ExistsSysDepartment(ctx context.Context) (bool, error) {
 | |
| 	row := q.db.QueryRow(ctx, existsSysDepartment)
 | |
| 	var exists bool
 | |
| 	err := row.Scan(&exists)
 | |
| 	return exists, err
 | |
| }
 | |
| 
 | |
| const getSysDepartment = `-- name: GetSysDepartment :one
 | |
| SELECT id, name, parent_id, parent_path, status, sort, created_at, updated_at FROM sys_department 
 | |
| WHERE id = $1 LIMIT 1
 | |
| `
 | |
| 
 | |
| func (q *Queries) GetSysDepartment(ctx context.Context, id int32) (*SysDepartment, error) {
 | |
| 	row := q.db.QueryRow(ctx, getSysDepartment, id)
 | |
| 	var i SysDepartment
 | |
| 	err := row.Scan(
 | |
| 		&i.ID,
 | |
| 		&i.Name,
 | |
| 		&i.ParentID,
 | |
| 		&i.ParentPath,
 | |
| 		&i.Status,
 | |
| 		&i.Sort,
 | |
| 		&i.CreatedAt,
 | |
| 		&i.UpdatedAt,
 | |
| 	)
 | |
| 	return &i, err
 | |
| }
 | |
| 
 | |
| const listSysDepartment = `-- name: ListSysDepartment :many
 | |
| SELECT id, name, parent_id, parent_path, status, sort, created_at, updated_at FROM sys_department 
 | |
| WHERE status = 0
 | |
| `
 | |
| 
 | |
| func (q *Queries) ListSysDepartment(ctx context.Context) ([]*SysDepartment, error) {
 | |
| 	rows, err := q.db.Query(ctx, listSysDepartment)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*SysDepartment{}
 | |
| 	for rows.Next() {
 | |
| 		var i SysDepartment
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const listSysDepartmentCondition = `-- name: ListSysDepartmentCondition :many
 | |
| SELECT id, name, parent_id, parent_path, status, sort, created_at, updated_at FROM sys_department
 | |
| WHERE (NOT $1::Boolean OR status = $2)
 | |
|     AND (NOT $3::Boolean OR id = $4)
 | |
|     AND (NOT $5::Boolean OR parent_id = $6)
 | |
|     AND ($7::text = '' OR name ILIKE '%' || $7 || '%')
 | |
| ORDER BY created_at DESC
 | |
| OFFSET $8
 | |
| LIMIT $9
 | |
| `
 | |
| 
 | |
| type ListSysDepartmentConditionParams struct {
 | |
| 	IsStatus   bool   `json:"is_status"`
 | |
| 	Status     int32  `json:"status"`
 | |
| 	IsID       bool   `json:"is_id"`
 | |
| 	ID         int32  `json:"id"`
 | |
| 	IsParentID bool   `json:"is_parent_id"`
 | |
| 	ParentID   int32  `json:"parent_id"`
 | |
| 	Name       string `json:"name"`
 | |
| 	Skip       int32  `json:"skip"`
 | |
| 	Size       int32  `json:"size"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) ListSysDepartmentCondition(ctx context.Context, arg *ListSysDepartmentConditionParams) ([]*SysDepartment, error) {
 | |
| 	rows, err := q.db.Query(ctx, listSysDepartmentCondition,
 | |
| 		arg.IsStatus,
 | |
| 		arg.Status,
 | |
| 		arg.IsID,
 | |
| 		arg.ID,
 | |
| 		arg.IsParentID,
 | |
| 		arg.ParentID,
 | |
| 		arg.Name,
 | |
| 		arg.Skip,
 | |
| 		arg.Size,
 | |
| 	)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*SysDepartment{}
 | |
| 	for rows.Next() {
 | |
| 		var i SysDepartment
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const listSysDepartmentRecursive = `-- name: ListSysDepartmentRecursive :many
 | |
| WITH RECURSIVE dist AS (SELECT sys_department.id, sys_department.name, sys_department.parent_id, sys_department.parent_path, sys_department.status, sys_department.sort, sys_department.created_at, sys_department.updated_at
 | |
|                         FROM sys_department
 | |
|                         WHERE status = 0
 | |
|                         UNION ALL
 | |
|                         SELECT sys_department.id, sys_department.name, sys_department.parent_id, sys_department.parent_path, sys_department.status, sys_department.sort, sys_department.created_at, sys_department.updated_at
 | |
|                         FROM sys_department,
 | |
|                              dist
 | |
|                         WHERE sys_department.id = dist.parent_id)
 | |
| SELECT DISTINCT id, name, parent_id, parent_path, status, sort, created_at, updated_at
 | |
| FROM dist
 | |
| ORDER BY sort DESC
 | |
| `
 | |
| 
 | |
| type ListSysDepartmentRecursiveRow struct {
 | |
| 	ID         int32     `json:"id"`
 | |
| 	Name       string    `json:"name"`
 | |
| 	ParentID   int32     `json:"parent_id"`
 | |
| 	ParentPath string    `json:"parent_path"`
 | |
| 	Status     int32     `json:"status"`
 | |
| 	Sort       int32     `json:"sort"`
 | |
| 	CreatedAt  time.Time `json:"created_at"`
 | |
| 	UpdatedAt  time.Time `json:"updated_at"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) ListSysDepartmentRecursive(ctx context.Context) ([]*ListSysDepartmentRecursiveRow, error) {
 | |
| 	rows, err := q.db.Query(ctx, listSysDepartmentRecursive)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*ListSysDepartmentRecursiveRow{}
 | |
| 	for rows.Next() {
 | |
| 		var i ListSysDepartmentRecursiveRow
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const updateSysDepartment = `-- name: UpdateSysDepartment :one
 | |
| UPDATE sys_department 
 | |
| SET name = $2,
 | |
|     parent_id = $3,
 | |
|     parent_path = $4,
 | |
|     status = $5,
 | |
|     sort = $6,
 | |
|     updated_at = $7
 | |
| WHERE id = $1
 | |
| RETURNING id, name, parent_id, parent_path, status, sort, created_at, updated_at
 | |
| `
 | |
| 
 | |
| type UpdateSysDepartmentParams struct {
 | |
| 	ID         int32     `json:"id"`
 | |
| 	Name       string    `json:"name"`
 | |
| 	ParentID   int32     `json:"parent_id"`
 | |
| 	ParentPath string    `json:"parent_path"`
 | |
| 	Status     int32     `json:"status"`
 | |
| 	Sort       int32     `json:"sort"`
 | |
| 	UpdatedAt  time.Time `json:"updated_at"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) UpdateSysDepartment(ctx context.Context, arg *UpdateSysDepartmentParams) (*SysDepartment, error) {
 | |
| 	row := q.db.QueryRow(ctx, updateSysDepartment,
 | |
| 		arg.ID,
 | |
| 		arg.Name,
 | |
| 		arg.ParentID,
 | |
| 		arg.ParentPath,
 | |
| 		arg.Status,
 | |
| 		arg.Sort,
 | |
| 		arg.UpdatedAt,
 | |
| 	)
 | |
| 	var i SysDepartment
 | |
| 	err := row.Scan(
 | |
| 		&i.ID,
 | |
| 		&i.Name,
 | |
| 		&i.ParentID,
 | |
| 		&i.ParentPath,
 | |
| 		&i.Status,
 | |
| 		&i.Sort,
 | |
| 		&i.CreatedAt,
 | |
| 		&i.UpdatedAt,
 | |
| 	)
 | |
| 	return &i, err
 | |
| }
 |