first commit

This commit is contained in:
2025-03-21 11:05:42 +08:00
commit 7dffc94035
1717 changed files with 724764 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
-- name: CreateBudget :one
INSERT INTO budgets (project_id, name, budget_type, category, start_at, end_at, amount, used_amount, remaining_amount, remark, created_user_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
RETURNING *;
-- name: GetBudget :one
SELECT *
FROM budgets
WHERE id = $1
LIMIT 1;
-- name: UpdateBudget :one
UPDATE budgets
SET
project_id = COALESCE(sqlc.narg(project_id), project_id),
name = COALESCE(sqlc.narg(name), name),
budget_type = COALESCE(sqlc.narg(budget_type), budget_type),
category = COALESCE(sqlc.narg(category), category),
start_at = COALESCE(sqlc.narg(start_at), start_at),
end_at = COALESCE(sqlc.narg(end_at), end_at),
amount = COALESCE(sqlc.narg(amount), amount),
used_amount = COALESCE(sqlc.narg(used_amount), used_amount),
remaining_amount = COALESCE(sqlc.narg(remaining_amount), remaining_amount),
remark = COALESCE(sqlc.narg(remark), remark),
status = COALESCE(sqlc.narg(status), status),
updated_user_id = COALESCE(sqlc.narg(updated_user_id), updated_user_id),
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: ListBudgets :many
SELECT *
FROM budgets
WHERE project_id = $1
ORDER BY id;

View File

@@ -0,0 +1,84 @@
-- name: CreateCategory :one
INSERT INTO categories (
name,
icon,
description,
letter,
parent_id,
parent_path,
status,
sort
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;
-- name: UpdateCategory :one
UPDATE categories
SET
name = COALESCE(sqlc.narg(name), name),
icon = COALESCE(sqlc.narg(icon), icon),
description = COALESCE(sqlc.narg(description), description),
letter = COALESCE(sqlc.narg(letter), letter),
parent_id = COALESCE(sqlc.narg(parent_id), parent_id),
parent_path = COALESCE(sqlc.narg(parent_path), parent_path),
sort = COALESCE(sqlc.narg(sort), sort),
status = COALESCE(sqlc.narg(status), status),
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: GetCategory :one
SELECT *
FROM categories
WHERE id = $1
LIMIT 1;
-- name: ListCategories :many
SELECT * FROM categories
WHERE status = 0;
-- name: ListCategoriesByPath :many
SELECT * FROM categories
WHERE parent_path LIKE $1
AND status = 0
ORDER BY sort DESC, id ASC;
-- name: CountCategoriesCondition :one
SELECT COUNT(*) FROM categories
WHERE (NOT @is_status::Boolean OR status = @status)
AND (NOT @is_id::Boolean OR id = @id)
AND (NOT @is_parent_id::Boolean OR parent_id = @parent_id)
AND (@name::text = '' OR name ILIKE '%' || @name || '%');
-- name: ListCategoriesCondition :many
SELECT * FROM categories
WHERE (NOT @is_status::Boolean OR status = @status)
AND (NOT @is_id::Boolean OR id = @id)
AND (NOT @is_parent_id::Boolean OR parent_id = @parent_id)
AND (@name::text = '' OR name ILIKE '%' || @name || '%')
ORDER BY sort DESC, id ASC
OFFSET @skip
LIMIT @size;
-- name: AllCategories :many
SELECT * FROM categories
WHERE status = 0
ORDER BY sort DESC, id ASC;
-- name: ExistsCategories :one
SELECT EXISTS (
SELECT 1 FROM categories
);
-- name: ListCategoriesRecursive :many
WITH RECURSIVE dist AS (SELECT categories.*
FROM categories
WHERE status = 0
UNION ALL
SELECT categories.*
FROM categories,
dist
WHERE categories.id = dist.parent_id)
SELECT DISTINCT *
FROM dist
ORDER BY sort DESC, id ASC;

View File

@@ -0,0 +1,42 @@
-- name: CreateCustomer :one
INSERT INTO customers (id, name, category, source, address, contact_name, contact_phone, created_by)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;
-- name: UpdateCustomer :one
UPDATE customers
SET
name = COALESCE(sqlc.narg(name), name),
category = COALESCE(sqlc.narg(category), category),
source = COALESCE(sqlc.narg(source), source),
address = COALESCE(sqlc.narg(address), address),
contact_name = COALESCE(sqlc.narg(contact_name), contact_name),
contact_phone = COALESCE(sqlc.narg(contact_phone), contact_phone),
status = COALESCE(sqlc.narg(status), status),
updated_by = COALESCE(sqlc.narg(updated_by), updated_by),
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: GetCustomer :one
SELECT *
FROM customers
WHERE id = $1
LIMIT 1;
-- name: AllCustomers :many
SELECT * FROM customers
WHERE status = 0
ORDER BY id DESC;
-- name: CountCustomers :one
SELECT COUNT(1)
FROM customers
WHERE status = 0;
-- name: ListCustomers :many
SELECT *
FROM customers
WHERE status = 0
ORDER BY id DESC
LIMIT $1 OFFSET $2;

View File

@@ -0,0 +1,47 @@
-- name: CreateExpense :one
INSERT INTO expenses (project_id, budget_id, amount, expenses_at, expenses_type, remark, status, created_user_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;
-- name: UpdateExpense :one
UPDATE expenses
SET
project_id = COALESCE(sqlc.narg(project_id), project_id),
budget_id = COALESCE(sqlc.narg(budget_id), budget_id),
amount = COALESCE(sqlc.narg(amount), amount),
expenses_at = COALESCE(sqlc.narg(expenses_at), expenses_at),
expenses_type = COALESCE(sqlc.narg(expenses_type), expenses_type),
remark = COALESCE(sqlc.narg(remark), remark),
status = COALESCE(sqlc.narg(status), status),
updated_user_id = COALESCE(sqlc.narg(updated_user_id), updated_user_id),
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: GetExpense :one
SELECT *
FROM expenses
WHERE id = $1
LIMIT 1;
-- name: SumExpense :one
SELECT SUM(amount)::numeric
FROM expenses;
-- name: SumExpenseByProjectID :one
SELECT SUM(amount)::numeric
FROM expenses
WHERE project_id = $1;
-- name: StatisticsExpense :many
SELECT SUM(amount)::numeric as total_amount,
(select name from categories where id = expenses.expenses_type) expenses_type_name
FROM expenses
GROUP BY expenses_type;
-- name: StatisticsExpenseByProjectID :many
SELECT SUM(amount)::numeric as total_amount,
(select name from categories where id = expenses.expenses_type) expenses_type_name
FROM expenses
WHERE project_id = $1
GROUP BY expenses_type;

View File

@@ -0,0 +1,48 @@
-- name: CreateIncome :one
INSERT INTO incomes (project_id, budget_id, amount, income_at, income_type, income_bank, remark, status, created_user_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING *;
-- name: UpdateIncome :one
UPDATE incomes
SET
project_id = COALESCE(sqlc.narg(project_id), project_id),
budget_id = COALESCE(sqlc.narg(budget_id), budget_id),
amount = COALESCE(sqlc.narg(amount), amount),
income_at = COALESCE(sqlc.narg(income_at), income_at),
income_type = COALESCE(sqlc.narg(income_type), income_type),
income_bank = COALESCE(sqlc.narg(income_bank), income_bank),
remark = COALESCE(sqlc.narg(remark), remark),
status = COALESCE(sqlc.narg(status), status),
updated_user_id = COALESCE(sqlc.narg(updated_user_id), updated_user_id),
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: GetIncome :one
SELECT *
FROM incomes
WHERE id = $1
LIMIT 1;
-- name: SumIncome :one
SELECT SUM(amount)::numeric
FROM incomes;
-- name: SumIncomeByProjectID :one
SELECT SUM(amount)::numeric
FROM incomes
WHERE project_id = $1;
-- name: StatisticsIncome :many
SELECT SUM(amount)::numeric as total_amount,
(select name from categories where id = incomes.income_type) income_type_name
FROM incomes
GROUP BY income_type;
-- name: StatisticsIncomeByProjectID :many
SELECT SUM(amount)::numeric as total_amount,
(select name from categories where id = incomes.income_type) income_type_name
FROM incomes
WHERE project_id = $1
GROUP BY income_type;

View File

@@ -0,0 +1,59 @@
-- name: CreateProject :one
INSERT INTO projects (id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, created_user_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
RETURNING *;
-- name: UpdateProject :one
UPDATE projects
SET
name = COALESCE(sqlc.narg(name), name),
start_at = COALESCE(sqlc.narg(start_at), start_at),
end_at = COALESCE(sqlc.narg(end_at), end_at),
customer_id = COALESCE(sqlc.narg(customer_id), customer_id),
total_money = COALESCE(sqlc.narg(total_money), total_money),
description = COALESCE(sqlc.narg(description), description),
apply_at = COALESCE(sqlc.narg(apply_at), apply_at),
apply_user_id = COALESCE(sqlc.narg(apply_user_id), apply_user_id),
manager_id = COALESCE(sqlc.narg(manager_id), manager_id),
members = COALESCE(sqlc.narg(members), members),
status = COALESCE(sqlc.narg(status), status),
updated_user_id = COALESCE(sqlc.narg(updated_user_id), updated_user_id),
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: GetProject :one
SELECT *
FROM projects
WHERE id = $1
LIMIT 1;
-- name: AllProjects :many
SELECT * FROM projects
WHERE status > -1
ORDER BY id DESC;
-- name: CountProjects :one
SELECT COUNT(1)
FROM projects
WHERE status = $1;
-- name: ListProjects :many
SELECT *
FROM projects
WHERE status = $1
ORDER BY id DESC
LIMIT $1 OFFSET $2;
-- name: StatisticsProjects :many
select name,
(select sum(amount)::numeric from incomes where project_id = projects.id) income,
(select sum(amount)::numeric from expenses where project_id = projects.id) expense
from projects;
-- name: StatisticsProjectItem :one
select name,
(select sum(amount)::numeric from incomes where project_id = projects.id) income,
(select sum(amount)::numeric from expenses where project_id = projects.id) expense
from projects
where projects.id = $1;

View File

@@ -0,0 +1,14 @@
-- name: CreateProjectFile :one
INSERT INTO project_files (id, name, path, project_id, created_user_id)
VALUES($1, $2, $3, $4, $5)
RETURNING *;
-- name: DeleteProjectFile :exec
DELETE FROM project_files
WHERE project_id = $1;
-- name: ListProjectFiles :many
SELECT *
FROM project_files
WHERE project_id = $1
ORDER BY id;

View File

@@ -0,0 +1,32 @@
-- name: CreateSysAuditLog :exec
INSERT INTO sys_audit_log (created_at,
email,
username,
user_uuid,
start_at,
end_at,
duration,
url,
method,
parameters,
referer_url,
os,
ip,
browser,
remark)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);
-- name: CountSysAuditLogCondition :one
SELECT COUNT(*) FROM sys_audit_log
WHERE created_at BETWEEN @start_at AND @end_at
AND (@email::text = '' OR email ILIKE '%' || @email || '%')
AND (@username::text = '' OR username ILIKE '%' || @username || '%');
-- name: ListSysAuditLogCondition :many
SELECT * FROM sys_audit_log
WHERE created_at BETWEEN @start_at AND @end_at
AND (@email::text = '' OR email ILIKE '%' || @email || '%')
AND (@username::text = '' OR username ILIKE '%' || @username || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;

View File

@@ -0,0 +1,41 @@
-- name: CreateSysConfig :exec
INSERT INTO sys_config (
key,
value
) VALUES (
$1, $2
);
-- name: GetSysConfig :one
SELECT *
FROM sys_config
WHERE id = $1
LIMIT 1;
-- name: GetSysConfigByKey :one
SELECT *
FROM sys_config
WHERE key = $1
LIMIT 1;
-- name: UpdateSysConfigByKey :exec
UPDATE sys_config
SET value = $2
WHERE key = $1;
-- name: ExistsSysConfigByKey :one
SELECT EXISTS (
SELECT 1 FROM sys_config WHERE key = $1
);
-- name: CountSysConfigCondition :one
SELECT COUNT(*) FROM sys_config
WHERE (@key::text = '' OR key ILIKE '%' || @key || '%');
-- name: ListSysConfigCondition :many
SELECT *
FROM sys_config
WHERE (@key::text = '' OR key ILIKE '%' || @key || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;

View File

@@ -0,0 +1,71 @@
-- 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 *;
-- 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 *;
-- name: GetSysDepartment :one
SELECT * FROM sys_department
WHERE id = $1 LIMIT 1;
-- name: ListSysDepartment :many
SELECT * FROM sys_department
WHERE status = 0;
-- name: CountSysDepartmentCondition :one
SELECT COUNT(*) FROM sys_department
WHERE (NOT @is_status::Boolean OR status = @status)
AND (NOT @is_id::Boolean OR id = @id)
AND (NOT @is_parent_id::Boolean OR parent_id = @parent_id)
AND (@name::text = '' OR name ILIKE '%' || @name || '%');
-- name: ListSysDepartmentCondition :many
SELECT * FROM sys_department
WHERE (NOT @is_status::Boolean OR status = @status)
AND (NOT @is_id::Boolean OR id = @id)
AND (NOT @is_parent_id::Boolean OR parent_id = @parent_id)
AND (@name::text = '' OR name ILIKE '%' || @name || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;
-- name: AllSysDepartment :many
SELECT * FROM sys_department
WHERE status = 0
ORDER BY sort DESC;
-- name: ExistsSysDepartment :one
SELECT EXISTS (
SELECT 1 FROM sys_department
);
-- name: ListSysDepartmentRecursive :many
WITH RECURSIVE dist AS (SELECT sys_department.*
FROM sys_department
WHERE status = 0
UNION ALL
SELECT sys_department.*
FROM sys_department,
dist
WHERE sys_department.id = dist.parent_id)
SELECT DISTINCT *
FROM dist
ORDER BY sort DESC;

View File

@@ -0,0 +1,97 @@
-- name: CreateSysMenu :one
INSERT INTO sys_menu (
name,
display_name,
url,
type,
parent_id,
parent_path,
avatar,
style,
visible,
is_list,
status,
sort,
created_at,
updated_at
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14
) RETURNING *;
-- name: UpdateSysMenu :one
UPDATE sys_menu
SET name = $2,
display_name = $3,
url = $4,
type = $5,
parent_id = $6,
parent_path = $7,
avatar = $8,
style = $9,
visible = $10,
is_list = $11,
status = $12,
sort = $13,
updated_at = $14
WHERE id = $1
RETURNING *;
-- name: GetSysMenu :one
SELECT * FROM sys_menu
WHERE id = $1 LIMIT 1;
-- name: GetSysMenuByUrl :one
SELECT * FROM sys_menu
WHERE url = $1 LIMIT 1;
-- name: AllSysMenu :many
SELECT * FROM sys_menu
WHERE status = 0
ORDER BY sort DESC;
-- name: ListSysMenuByRoleID :many
SELECT * FROM sys_menu
WHERE id IN (SELECT menu_id
FROM sys_role_menu
WHERE role_id = $1);
-- name: ListSysMenuIDByRoleID :many
SELECT menu_id
FROM sys_role_menu
WHERE role_id = $1;
-- name: ExistsMenu :one
SELECT EXISTS (
SELECT 1 FROM sys_menu
);
-- name: RecursiveSysMenus :many
WITH RECURSIVE dist AS (SELECT sys_menu.*
FROM sys_menu
WHERE status = 0
AND is_list = true
UNION ALL
SELECT sys_menu.*
FROM sys_menu,
dist
WHERE sys_menu.id = dist.parent_id)
SELECT *
FROM dist
ORDER BY dist.sort DESC, dist.id ASC;
-- name: RecursiveSysMenusByRoleID :many
WITH RECURSIVE dist AS (SELECT sys_menu.*
FROM sys_menu
WHERE status = 0
AND is_list = true
AND id IN (SELECT menu_id
FROM sys_role_menu
WHERE role_id = $1)
UNION ALL
SELECT sys_menu.*
FROM sys_menu,
dist
WHERE sys_menu.id = dist.parent_id)
SELECT *
FROM dist
ORDER BY dist.sort DESC, dist.id ASC;

View File

@@ -0,0 +1,76 @@
-- name: CreateSysRole :one
INSERT INTO sys_role (
name,
display_name,
vip,
parent_id,
parent_path,
status,
created_at,
updated_at
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8
) RETURNING *;
-- name: UpdateSysRole :one
UPDATE sys_role
SET display_name = $2,
status = $3,
parent_id = $4,
parent_path = $5,
sort = $6,
updated_at = $7
WHERE id = $1
RETURNING *;
-- name: GetSysRole :one
SELECT * FROM sys_role
WHERE id = $1 LIMIT 1;
-- name: CountSysRole :one
SELECT count(*) FROM sys_role
WHERE status = 0;
-- name: ListSysRole :many
SELECT * FROM sys_role
WHERE status = 0;
-- name: AllSysRole :many
SELECT * FROM sys_role
WHERE status = 0
ORDER BY sort DESC;
-- name: GetSysRoleByUserID :one
SELECT * FROM sys_role
WHERE id = (SELECT role_id
FROM sys_user
WHERE sys_user.id = $1);
-- name: ExistsVipRole :one
SELECT EXISTS (
SELECT 1 FROM sys_role
WHERE vip = true
);
-- name: GetFirstVipRole :one
SELECT * FROM sys_role
WHERE vip = true
ORDER BY id ASC
LIMIT 1;
-- name: CountSysRoleCondition :one
SELECT COUNT(*) FROM sys_role
WHERE (NOT @is_status::Boolean OR status = @status)
AND (NOT @is_id::Boolean OR id = @id)
AND (NOT @is_parent_id::Boolean OR parent_id = @parent_id)
AND (@display_name::text = '' OR display_name ILIKE '%' || @display_name || '%');
-- name: ListSysRoleCondition :many
SELECT * FROM sys_role
WHERE (NOT @is_status::Boolean OR status = @status)
AND (NOT @is_id::Boolean OR id = @id)
AND (NOT @is_parent_id::Boolean OR parent_id = @parent_id)
AND (@display_name::text = '' OR display_name ILIKE '%' || @display_name || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;

View File

@@ -0,0 +1,11 @@
-- name: DeleteRoleMneuByRoleID :exec
DELETE FROM sys_role_menu
WHERE role_id = $1;
-- name: CreateRoleMenu :exec
INSERT INTO sys_role_menu (
role_id,
menu_id
) VALUES (
$1, $2
);

View File

@@ -0,0 +1,76 @@
-- name: CreateSysUser :one
INSERT INTO sys_user (
uuid,
email,
username,
hashed_password,
salt,
avatar,
gender,
department_id,
role_id,
status,
change_password_at,
created_at,
updated_at
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
) RETURNING *;
-- name: UpdateSysUser :one
UPDATE sys_user
SET username = $2,
hashed_password = $3,
avatar = $4,
gender = $5,
department_id = $6,
role_id = $7,
status = $8,
change_password_at = $9,
updated_at = $10
WHERE id = $1
RETURNING *;
-- name: GetSysUser :one
SELECT * FROM sys_user
WHERE id = $1 LIMIT 1;
-- name: GetSysUserByEmail :one
SELECT * FROM sys_user
WHERE email = $1 LIMIT 1;
-- name: CountSysUser :one
SELECT COUNT(*) FROM sys_user
WHERE status = 0;
-- name: ListSysUser :many
SELECT * FROM sys_user
WHERE status = 0
ORDER BY created_at DESC;
-- name: CountSysUserCondition :one
SELECT COUNT(*) FROM sys_user
WHERE (NOT @is_status::Boolean OR status = @status)
AND (@username::text = '' OR username ILIKE '%' || @username || '%');
-- name: ListSysUserCondition :many
SELECT id, uuid, email, username, avatar, gender, department_id, role_id, status, change_password_at, created_at, updated_at,
(SELECT name FROM sys_department WHERE ID = sys_user.department_id) AS department_name,
(SELECT display_name
FROM sys_role
WHERE id = sys_user.role_id) AS role_name
FROM sys_user
WHERE (NOT @is_status::Boolean OR sys_user.status = @status)
AND (@username::text = '' OR username ILIKE '%' || @username || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;
-- name: ExistsSysUser :one
SELECT EXISTS (
SELECT 1 FROM sys_user
);
-- name: ListSysUserByIds :many
SELECT * FROM sys_user
WHERE id = ANY($1::int[]);

View File

@@ -0,0 +1,28 @@
-- name: CreateSysUserLoginLog :exec
INSERT INTO sys_user_login_log (created_at,
email,
username,
user_uuid,
is_success,
message,
referer_url,
url,
os,
ip,
browser)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
-- name: CountSysUserLoginLogCondition :one
SELECT COUNT(*) FROM sys_user_login_log
WHERE created_at BETWEEN @start_at AND @end_at
AND (@email::text = '' OR email ILIKE '%' || @email || '%')
AND (@username::text = '' OR username ILIKE '%' || @username || '%');
-- name: ListSysUserLoginLogCondition :many
SELECT * FROM sys_user_login_log
WHERE created_at BETWEEN @start_at AND @end_at
AND (@email::text = '' OR email ILIKE '%' || @email || '%')
AND (@username::text = '' OR username ILIKE '%' || @username || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;