From f9d7f0ea682bbb768e84469fccf00da52abcd5d8 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Sun, 21 Dec 2025 18:22:07 +0000 Subject: [PATCH] =?UTF-8?q?"chore(data):=20=E7=A7=BB=E9=99=A4b.csv?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E6=96=87=E4=BB=B6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- b.csv => help/b.csv | 0 gotidy.sh => help/gotidy.sh | 0 gowork.sh => help/gowork.sh | 0 help/mock生成用户.sql | 31 +++++++++++++++++++++++++++++++ report.md => help/report.md | 0 help/查询在线时长.sql | 10 ++++++++++ help/给经验池增加.sql | 9 +++++++++ 7 files changed, 50 insertions(+) rename b.csv => help/b.csv (100%) rename gotidy.sh => help/gotidy.sh (100%) rename gowork.sh => help/gowork.sh (100%) create mode 100644 help/mock生成用户.sql rename report.md => help/report.md (100%) create mode 100644 help/查询在线时长.sql create mode 100644 help/给经验池增加.sql diff --git a/b.csv b/help/b.csv similarity index 100% rename from b.csv rename to help/b.csv diff --git a/gotidy.sh b/help/gotidy.sh similarity index 100% rename from gotidy.sh rename to help/gotidy.sh diff --git a/gowork.sh b/help/gowork.sh similarity index 100% rename from gowork.sh rename to help/gowork.sh diff --git a/help/mock生成用户.sql b/help/mock生成用户.sql new file mode 100644 index 000000000..532022315 --- /dev/null +++ b/help/mock生成用户.sql @@ -0,0 +1,31 @@ +INSERT INTO base_sys_user ( + "createTime", + "updateTime", + deleted_at, + "departmentId", + username, + password, + "headImg", + email, + remark +) SELECT + -- 过去90天内的随机创建时间 + CURRENT_TIMESTAMP - (random() * 90 * 86400 || ' seconds')::interval, + -- updateTime初始与createTime一致 + CURRENT_TIMESTAMP - (random() * 90 * 86400 || ' seconds')::interval, + NULL, -- 未删除 + -- 随机部门ID(1-100) + floor(random() * 100) + 1, + -- 随机用户名(mock_前缀+8位随机串) + CONCAT('mock_', SUBSTRING(md5(random()::text), 1, 8)), + md5('123456'), -- 固定密码 + 'https://example.com/headimg/default.png', -- 统一默认头像 + -- 随机邮箱(mock_前缀+8位随机串+随机域名) + CONCAT( + 'mock_', + SUBSTRING(md5(random()::text), 1, 8), + '@', + (array['qq.com', '163.com', 'gmail.com'])[floor(random()*3)+1] + ), + '批量生成的测试用户' +FROM generate_series(1, 1000); -- 10万条 \ No newline at end of file diff --git a/report.md b/help/report.md similarity index 100% rename from report.md rename to help/report.md diff --git a/help/查询在线时长.sql b/help/查询在线时长.sql new file mode 100644 index 000000000..151dcc5c8 --- /dev/null +++ b/help/查询在线时长.sql @@ -0,0 +1,10 @@ +SELECT + player_id, + (data->>'online_time')::int AS online_time +FROM "player_info" +-- 替换?操作符,用jsonb_exists函数判断online_time字段是否存在 +WHERE + jsonb_exists(data, 'online_time') -- 等价于 data ? 'online_time',无占位符冲突 + AND (data->>'online_time')::int > 0 +-- 按在线时间降序排序 +ORDER BY online_time DESC; \ No newline at end of file diff --git a/help/给经验池增加.sql b/help/给经验池增加.sql new file mode 100644 index 000000000..754f45814 --- /dev/null +++ b/help/给经验池增加.sql @@ -0,0 +1,9 @@ +UPDATE "player_info" +SET data = jsonb_set( + data, + '{exp_pool}', + -- 直接复用查询中的计算逻辑,确保结果一致 + to_jsonb(COALESCE((data->>'exp_pool')::int, 0) + 50000000), + true -- 字段不存在时自动初始化为10 +) +WHERE player_id = 10001; \ No newline at end of file