This commit is contained in:
oneao committed 2026-01-18 21:20:51 +08:00
1 parent 78c7a812be
commit 1934225c53
24 files changed
+711 -654

No files matched your search

@@ -1,11 +1,6 @@
-- name: FindUserMoneyRecords :many
SELECT
mr.*,
muc.name AS category_name,
muc.icon AS category_icon,
muc.type AS category_type
SELECT mr.*
FROM money_record mr
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
WHERE mr.user_id = $1
AND mr.record_time BETWEEN $2 AND $3
ORDER BY mr.record_time DESC, mr.create_time DESC;
@@ -13,17 +8,17 @@ ORDER BY mr.record_time DESC, mr.create_time DESC;
-- name: FindMoneyRecordsBySpace :many
SELECT
mr.*,
u.username AS username,
muc.name AS category_name,
muc.icon AS category_icon,
muc.type AS category_type
u.username AS username
FROM money_record mr
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
INNER JOIN space_user su ON mr.user_id = su.user_id AND su.space_id = $1
LEFT JOIN user_info u ON mr.user_id = u.id
INNER JOIN space_user su
ON mr.user_id = su.user_id
AND su.space_id = $1
LEFT JOIN user_info u
ON mr.user_id = u.id
WHERE mr.record_time BETWEEN $2 AND $3
ORDER BY mr.record_time DESC, mr.create_time DESC;
-- name: InsertMoneyRecord :one
INSERT INTO money_record (
id,
@@ -21,10 +21,10 @@ DELETE FROM money_user_category
WHERE user_id = $1;
-- name: InsertMoneyUserCategory :exec
INSERT INTO money_user_category (id, user_id, name, icon, type, sort_number)
VALUES ($1, $2, $3, $4, $5, $6);
INSERT INTO money_user_category (id, user_id, name, icon, type, sort_number,create_time,update_time)
VALUES ($1, $2, $3, $4, $5, $6,NOW(),NOW());
-- name: UpdateMoneyCategory :exec
UPDATE money_user_category
SET icon = $2,name = $3
SET icon = $2,name = $3,update_time = NOW()
WHERE id = $1;
+1 -1
View File
@@ -14,7 +14,7 @@ type MoneyRecord struct {
UserID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Timestamp
RecordTime pgtype.Date
CreateTime pgtype.Timestamp
UpdateTime pgtype.Timestamp
}
@@ -23,37 +23,33 @@ func (q *Queries) DeleteMoneyRecord(ctx context.Context, id int64) error {
const findMoneyRecordsBySpace = `-- name: FindMoneyRecordsBySpace :many
SELECT
mr.id, mr.category_id, mr.user_id, mr.amount, mr.remark, mr.record_time, mr.create_time, mr.update_time,
u.username AS username,
muc.name AS category_name,
muc.icon AS category_icon,
muc.type AS category_type
u.username AS username
FROM money_record mr
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
INNER JOIN space_user su ON mr.user_id = su.user_id AND su.space_id = $1
LEFT JOIN user_info u ON mr.user_id = u.id
INNER JOIN space_user su
ON mr.user_id = su.user_id
AND su.space_id = $1
LEFT JOIN user_info u
ON mr.user_id = u.id
WHERE mr.record_time BETWEEN $2 AND $3
ORDER BY mr.record_time DESC, mr.create_time DESC
`
type FindMoneyRecordsBySpaceParams struct {
SpaceID int64
RecordTime pgtype.Timestamp
RecordTime_2 pgtype.Timestamp
RecordTime pgtype.Date
RecordTime_2 pgtype.Date
}
type FindMoneyRecordsBySpaceRow struct {
ID int64
CategoryID int64
UserID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Timestamp
CreateTime pgtype.Timestamp
UpdateTime pgtype.Timestamp
Username pgtype.Text
CategoryName pgtype.Text
CategoryIcon pgtype.Text
CategoryType pgtype.Int4
ID int64
CategoryID int64
UserID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Date
CreateTime pgtype.Timestamp
UpdateTime pgtype.Timestamp
Username pgtype.Text
}
func (q *Queries) FindMoneyRecordsBySpace(ctx context.Context, arg FindMoneyRecordsBySpaceParams) ([]FindMoneyRecordsBySpaceRow, error) {
@@ -75,9 +71,6 @@ func (q *Queries) FindMoneyRecordsBySpace(ctx context.Context, arg FindMoneyReco
&i.CreateTime,
&i.UpdateTime,
&i.Username,
&i.CategoryName,
&i.CategoryIcon,
&i.CategoryType,
); err != nil {
return nil, err
}
@@ -90,13 +83,8 @@ func (q *Queries) FindMoneyRecordsBySpace(ctx context.Context, arg FindMoneyReco
}
const findUserMoneyRecords = `-- name: FindUserMoneyRecords :many
SELECT
mr.id, mr.category_id, mr.user_id, mr.amount, mr.remark, mr.record_time, mr.create_time, mr.update_time,
muc.name AS category_name,
muc.icon AS category_icon,
muc.type AS category_type
SELECT mr.id, mr.category_id, mr.user_id, mr.amount, mr.remark, mr.record_time, mr.create_time, mr.update_time
FROM money_record mr
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
WHERE mr.user_id = $1
AND mr.record_time BETWEEN $2 AND $3
ORDER BY mr.record_time DESC, mr.create_time DESC
@@ -104,33 +92,19 @@ ORDER BY mr.record_time DESC, mr.create_time DESC
type FindUserMoneyRecordsParams struct {
UserID int64
RecordTime pgtype.Timestamp
RecordTime_2 pgtype.Timestamp
RecordTime pgtype.Date
RecordTime_2 pgtype.Date
}
type FindUserMoneyRecordsRow struct {
ID int64
CategoryID int64
UserID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Timestamp
CreateTime pgtype.Timestamp
UpdateTime pgtype.Timestamp
CategoryName pgtype.Text
CategoryIcon pgtype.Text
CategoryType pgtype.Int4
}
func (q *Queries) FindUserMoneyRecords(ctx context.Context, arg FindUserMoneyRecordsParams) ([]FindUserMoneyRecordsRow, error) {
func (q *Queries) FindUserMoneyRecords(ctx context.Context, arg FindUserMoneyRecordsParams) ([]MoneyRecord, error) {
rows, err := q.db.Query(ctx, findUserMoneyRecords, arg.UserID, arg.RecordTime, arg.RecordTime_2)
if err != nil {
return nil, err
}
defer rows.Close()
var items []FindUserMoneyRecordsRow
var items []MoneyRecord
for rows.Next() {
var i FindUserMoneyRecordsRow
var i MoneyRecord
if err := rows.Scan(
&i.ID,
&i.CategoryID,
@@ -140,9 +114,6 @@ func (q *Queries) FindUserMoneyRecords(ctx context.Context, arg FindUserMoneyRec
&i.RecordTime,
&i.CreateTime,
&i.UpdateTime,
&i.CategoryName,
&i.CategoryIcon,
&i.CategoryType,
); err != nil {
return nil, err
}
@@ -196,7 +167,7 @@ type InsertMoneyRecordParams struct {
UserID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Timestamp
RecordTime pgtype.Date
}
func (q *Queries) InsertMoneyRecord(ctx context.Context, arg InsertMoneyRecordParams) (MoneyRecord, error) {
@@ -239,7 +210,7 @@ type UpdateMoneyRecordParams struct {
CategoryID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Timestamp
RecordTime pgtype.Date
}
func (q *Queries) UpdateMoneyRecord(ctx context.Context, arg UpdateMoneyRecordParams) error {
@@ -73,8 +73,8 @@ func (q *Queries) FindUserMoneyCategoriesByUserID(ctx context.Context, userID in
}
const insertMoneyUserCategory = `-- name: InsertMoneyUserCategory :exec
INSERT INTO money_user_category (id, user_id, name, icon, type, sort_number)
VALUES ($1, $2, $3, $4, $5, $6)
INSERT INTO money_user_category (id, user_id, name, icon, type, sort_number,create_time,update_time)
VALUES ($1, $2, $3, $4, $5, $6,NOW(),NOW())
`
type InsertMoneyUserCategoryParams struct {
@@ -97,3 +97,20 @@ func (q *Queries) InsertMoneyUserCategory(ctx context.Context, arg InsertMoneyUs
)
return err
}
const updateMoneyCategory = `-- name: UpdateMoneyCategory :exec
UPDATE money_user_category
SET icon = $2,name = $3,update_time = NOW()
WHERE id = $1
`
type UpdateMoneyCategoryParams struct {
ID int64
Icon string
Name string
}
func (q *Queries) UpdateMoneyCategory(ctx context.Context, arg UpdateMoneyCategoryParams) error {
_, err := q.db.Exec(ctx, updateMoneyCategory, arg.ID, arg.Icon, arg.Name)
return err
}
+3 -3
View File
@@ -18,9 +18,9 @@ CREATE TABLE money_record(
user_id BIGINT NOT NULL,
amount NUMERIC(12,2) NOT NULL,
remark VARCHAR(255) DEFAULT '',
record_time timestamp NOT NULL,
create_time timestamp DEFAULT CURRENT_TIMESTAMP,
update_time timestamp DEFAULT CURRENT_TIMESTAMP
record_time DATE NOT NULL,
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE money_sys_category(